Merge pull request #26932 from woocommerce/fix/25442

Show community forum link if wccom is not connected
This commit is contained in:
Vedanshu Jain 2020-07-16 00:14:52 +05:30 committed by GitHub
commit a34835e489
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 89 additions and 9 deletions

View File

@ -7,6 +7,7 @@
*/
use Automattic\Jetpack\Constants;
use Automattic\WooCommerce\Internal\WCCom\ConnectionHelper as WCConnectionHelper;
defined( 'ABSPATH' ) || exit;
@ -1365,17 +1366,21 @@ CREATE TABLE {$wpdb->prefix}wc_reserved_stock (
* @return array
*/
public static function plugin_row_meta( $links, $file ) {
if ( WC_PLUGIN_BASENAME === $file ) {
$row_meta = array(
'docs' => '<a href="' . esc_url( apply_filters( 'woocommerce_docs_url', 'https://docs.woocommerce.com/documentation/plugins/woocommerce/' ) ) . '" aria-label="' . esc_attr__( 'View WooCommerce documentation', 'woocommerce' ) . '">' . esc_html__( 'Docs', 'woocommerce' ) . '</a>',
'apidocs' => '<a href="' . esc_url( apply_filters( 'woocommerce_apidocs_url', 'https://docs.woocommerce.com/wc-apidocs/' ) ) . '" aria-label="' . esc_attr__( 'View WooCommerce API docs', 'woocommerce' ) . '">' . esc_html__( 'API docs', 'woocommerce' ) . '</a>',
'support' => '<a href="' . esc_url( apply_filters( 'woocommerce_support_url', 'https://woocommerce.com/my-account/tickets/' ) ) . '" aria-label="' . esc_attr__( 'Visit premium customer support', 'woocommerce' ) . '">' . esc_html__( 'Premium support', 'woocommerce' ) . '</a>',
);
return array_merge( $links, $row_meta );
if ( WC_PLUGIN_BASENAME !== $file ) {
return $links;
}
return (array) $links;
$row_meta = array(
'docs' => '<a href="' . esc_url( apply_filters( 'woocommerce_docs_url', 'https://docs.woocommerce.com/documentation/plugins/woocommerce/' ) ) . '" aria-label="' . esc_attr__( 'View WooCommerce documentation', 'woocommerce' ) . '">' . esc_html__( 'Docs', 'woocommerce' ) . '</a>',
'apidocs' => '<a href="' . esc_url( apply_filters( 'woocommerce_apidocs_url', 'https://docs.woocommerce.com/wc-apidocs/' ) ) . '" aria-label="' . esc_attr__( 'View WooCommerce API docs', 'woocommerce' ) . '">' . esc_html__( 'API docs', 'woocommerce' ) . '</a>',
'support' => '<a href="' . esc_url( apply_filters( 'woocommerce_community_support_url', 'https://wordpress.org/support/plugin/woocommerce/' ) ) . '" aria-label="' . esc_attr__( 'Visit community forums', 'woocommerce' ) . '">' . esc_html__( 'Community support', 'woocommerce' ) . '</a>',
);
if ( WCConnectionHelper::is_connected() ) {
$row_meta['premium_support'] = '<a href="' . esc_url( apply_filters( 'woocommerce_support_url', 'https://woocommerce.com/my-account/tickets/' ) ) . '" aria-label="' . esc_attr__( 'Visit premium customer support', 'woocommerce' ) . '">' . esc_html__( 'Premium support', 'woocommerce' ) . '</a>';
}
return array_merge( $links, $row_meta );
}
/**

View File

@ -0,0 +1,31 @@
<?php
/**
* Helpers for managing connection to WooCommerce.com.
*
* @package Automattic\WooCommerce\Internals\WCCom
*/
namespace Automattic\WooCommerce\Internal\WCCom;
defined( 'ABSPATH' ) || exit;
/**
* Class WCConnectionHelper.
*
* Helpers for managing connection to WooCommerce.com.
*/
final class ConnectionHelper {
/**
* Check if WooCommerce.com account is connected.
*
* @since 4.4.0
* @return bool Whether account is connected.
*/
public static function is_connected() {
$helper_options = get_option( 'woocommerce_helper_data', array() );
if ( array_key_exists( 'auth', $helper_options ) && ! empty( $helper_options['auth'] ) ) {
return true;
}
return false;
}
}

View File

@ -89,4 +89,19 @@ class WCInstallTest extends \WC_Unit_Test_Case {
$this->assertNotContains( 'base_tables_missing', \WC_Admin_Notices::get_notices() );
}
/**
* Test that premium support link is shown only when wccom is connected.
*/
public function test_plugin_row_meta() {
// Simulate connection break.
delete_option( 'woocommerce_helper_data' );
$plugin_row_data = \WC_Install::plugin_row_meta( array(), WC_PLUGIN_BASENAME );
$this->assertNotContains( 'premium_support', array_keys( $plugin_row_data ) );
update_option( 'woocommerce_helper_data', array( 'auth' => 'random token' ) );
$plugin_row_data = \WC_Install::plugin_row_meta( array(), WC_PLUGIN_BASENAME );
$this->assertContains( 'premium_support', array_keys( $plugin_row_data ) );
}
}

View File

@ -0,0 +1,29 @@
<?php
/**
* Tests for ConnectionHelper for WCCom
*
* @package WooCommerce|Tests|Internal|WCCom.
*/
namespace Automattic\WooCommerce\Tests\Internal;
use Automattic\WooCommerce\Internal\WCCom\ConnectionHelper;
/**
* Class ConnectionHelperTest.
*
* @package Automattic\WooCommerce\Tests\Internal.
*/
class ConnectionHelperTest extends \WC_Unit_Test_Case {
/**
* Test is_connected method based on option value.
*/
public function test_is_connected() {
delete_option( 'woocommerce_helper_data' );
$this->assertEquals( false, ConnectionHelper::is_connected() );
update_option( 'woocommerce_helper_data', array( 'auth' => 'random token' ) );
$this->assertEquals( true, ConnectionHelper::is_connected() );
}
}