plugin updates

This commit is contained in:
Tony Volpe
2024-06-17 14:48:11 -04:00
parent ecc5fbf831
commit 3751a5a1a6
1318 changed files with 91130 additions and 52250 deletions

View File

@@ -264,7 +264,7 @@ class WC_Admin_Marketplace_Promotions {
&& $promotion['menu_item_id'] === $menu_item['id']
) {
$bubble_text = $promotion['content'][ self::$locale ] ?? ( $promotion['content']['en_US'] ?? __( 'Sale', 'woocommerce' ) );
$menu_items[ $index ]['title'] = $menu_item['title'] . self::append_bubble( $bubble_text );
$menu_items[ $index ]['title'] = self::append_bubble( $menu_item['title'], $bubble_text );
break;
}
@@ -274,26 +274,21 @@ class WC_Admin_Marketplace_Promotions {
}
/**
* Return the markup for a menu item bubble with a given text and optional additional attributes.
* Return the markup for a menu item bubble with a given text.
*
* @param string $bubble_text Text of bubble.
* @param array $attributes Optional. Additional attributes for the bubble, such as class or style.
* @param string $menu_item_text Text of menu item we want to change.
* @param string $bubble_text Text of bubble.
*
* @return string
*/
private static function append_bubble( $bubble_text, $attributes = array() ) {
$default_attributes = array(
'class' => 'awaiting-mod update-plugins remaining-tasks-badge woocommerce-task-list-remaining-tasks-badge',
'style' => '',
);
private static function append_bubble( string $menu_item_text, string $bubble_text ): string {
// Strip out update count bubble added by Marketplace::get_marketplace_update_count_html.
$menu_item_text = preg_replace( '|<span class="update-plugins count-[\d]+">[A-z0-9 <>="-]+</span>|', '', $menu_item_text );
$attributes = wp_parse_args( $attributes, $default_attributes );
$class_attr = ! empty( $attributes['class'] ) ? sprintf( 'class="%s"', esc_attr( $attributes['class'] ) ) : '';
$style_attr = ! empty( $attributes['style'] ) ? sprintf( 'style="%s"', esc_attr( $attributes['style'] ) ) : '';
$bubble_html = sprintf( ' <span %s %s>%s</span>', $class_attr, $style_attr, esc_html( $bubble_text ) );
return $bubble_html;
return $menu_item_text
. '<span class="awaiting-mod update-plugins remaining-tasks-badge woocommerce-task-list-remaining-tasks-badge">'
. esc_html( $bubble_text )
. '</span>';
}
/**

View File

@@ -10,6 +10,7 @@ use Automattic\Jetpack\Constants;
use Automattic\WooCommerce\Internal\Traits\AccessiblePrivateMethods;
use Automattic\WooCommerce\Internal\Utilities\Users;
use Automattic\WooCommerce\Internal\Utilities\WebhookUtil;
use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
defined( 'ABSPATH' ) || exit;
@@ -217,7 +218,7 @@ class WC_Admin_Notices {
* or if the Legacy REST API extension is installed, and remove the notice about Legacy webhooks
* if no such webhooks exist anymore or if the Legacy REST API extension is installed.
*
* TODO: Change this method in WooCommerce 9.0 so that the notice gets removed if the Legacy REST API extension is installed and active.
* TODO: Change this method in WooCommerce 9.0 so that the notice get removed if the Legacy REST API extension is installed and active.
*/
private static function maybe_remove_legacy_api_removal_notice() {
$plugin_is_active = is_plugin_active( 'woocommerce-legacy-rest-api/woocommerce-legacy-rest-api.php' );
@@ -229,6 +230,11 @@ class WC_Admin_Notices {
if ( self::has_notice( 'legacy_webhooks_unsupported_in_woo_90' ) && ( $plugin_is_active || 0 === wc_get_container()->get( WebhookUtil::class )->get_legacy_webhooks_count() ) ) {
self::remove_notice( 'legacy_webhooks_unsupported_in_woo_90' );
}
if ( self::has_notice( 'legacy_rest_api_is_incompatible_with_hpos' ) &&
! ( 'yes' === get_option( 'woocommerce_api_enabled' ) && 'yes' === get_option( CustomOrdersTableController::CUSTOM_ORDERS_TABLE_USAGE_ENABLED_OPTION ) ) ) {
self::remove_notice( 'legacy_rest_api_is_incompatible_with_hpos' );
}
}
// phpcs:enable Generic.Commenting.Todo.TaskFound

View File

@@ -57,6 +57,9 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) :
$settings[] = include __DIR__ . '/settings/class-wc-settings-accounts.php';
$settings[] = include __DIR__ . '/settings/class-wc-settings-emails.php';
$settings[] = include __DIR__ . '/settings/class-wc-settings-integrations.php';
if ( \Automattic\WooCommerce\Admin\Features\Features::is_enabled( 'launch-your-store' ) ) {
$settings[] = include __DIR__ . '/settings/class-wc-settings-site-visibility.php';
}
$settings[] = include __DIR__ . '/settings/class-wc-settings-advanced.php';
self::$settings = apply_filters( 'woocommerce_get_settings_pages', $settings );

View File

@@ -50,6 +50,8 @@ class WC_Helper_Admin {
$installed_products
);
$woo_connect_notice_type = WC_Helper_Updater::get_woo_connect_notice_type();
$settings['wccomHelper'] = array(
'isConnected' => WC_Helper::is_site_connected(),
'connectURL' => self::get_connection_url(),
@@ -63,6 +65,7 @@ class WC_Helper_Admin {
'wooUpdateManagerInstallUrl' => WC_Woo_Update_Manager_Plugin::generate_install_url(),
'wooUpdateManagerPluginSlug' => WC_Woo_Update_Manager_Plugin::WOO_UPDATE_MANAGER_SLUG,
'wooUpdateCount' => WC_Helper_Updater::get_updates_count_based_on_site_status(),
'woocomConnectNoticeType' => $woo_connect_notice_type,
);
return $settings;

View File

@@ -33,7 +33,7 @@ class WC_Helper_Updater {
* Add the hook for modifying default WPCore update notices on the plugins management page.
*/
public static function add_hook_for_modifying_update_notices() {
if ( ! WC_Woo_Update_Manager_Plugin::is_plugin_active() ) {
if ( ! WC_Woo_Update_Manager_Plugin::is_plugin_active() || ! WC_Helper::is_site_connected() ) {
add_action( 'load-plugins.php', array( __CLASS__, 'setup_update_plugins_messages' ), 11 );
}
}
@@ -155,12 +155,47 @@ class WC_Helper_Updater {
* @return void.
*/
public static function setup_update_plugins_messages() {
$is_site_connected = WC_Helper::is_site_connected();
foreach ( WC_Helper::get_local_woo_plugins() as $plugin ) {
$filename = $plugin['_filename'];
add_action( 'in_plugin_update_message-' . $filename, array( __CLASS__, 'add_install_marketplace_plugin_message' ), 10, 2 );
if ( $is_site_connected ) {
add_action( 'in_plugin_update_message-' . $filename, array( __CLASS__, 'add_install_marketplace_plugin_message' ), 10, 2 );
} else {
add_action( 'in_plugin_update_message-' . $filename, array( __CLASS__, 'add_connect_woocom_plugin_message' ) );
}
}
}
/**
* Runs on in_plugin_update_message-{file-name}, show a message to connect to woocommerce.com for unconnected stores
*
* @return void.
*/
public static function add_connect_woocom_plugin_message() {
$connect_page_url = add_query_arg(
array(
'page' => 'wc-admin',
'tab' => 'my-subscriptions',
'path' => rawurlencode( '/extensions' ),
),
admin_url( 'admin.php' )
);
printf(
wp_kses(
/* translators: 1: Woo Update Manager plugin install URL */
__( ' <a href="%1$s" class="woocommerce-connect-your-store">Connect your store</a> to woocommerce.com to update.', 'woocommerce' ),
array(
'a' => array(
'href' => array(),
'class' => array(),
),
)
),
esc_url( $connect_page_url ),
);
}
/**
* Runs on in_plugin_update_message-{file-name}, show a message to install the Woo Marketplace plugin, on plugin update notification,
* if the Woo Marketplace plugin isn't already installed.
@@ -404,6 +439,9 @@ class WC_Helper_Updater {
* @return array Update data for each requested product.
*/
private static function _update_check( $payload ) {
if ( empty( $payload ) ) {
return array();
}
ksort( $payload );
$hash = md5( wp_json_encode( $payload ) );
@@ -422,13 +460,22 @@ class WC_Helper_Updater {
'errors' => array(),
);
$request = WC_Helper_API::post(
'update-check',
array(
'body' => wp_json_encode( array( 'products' => $payload ) ),
'authenticated' => true,
)
);
if ( WC_Helper::is_site_connected() ) {
$request = WC_Helper_API::post(
'update-check',
array(
'body' => wp_json_encode( array( 'products' => $payload ) ),
'authenticated' => true,
)
);
} else {
$request = WC_Helper_API::post(
'update-check-public',
array(
'body' => wp_json_encode( array( 'products' => $payload ) ),
)
);
}
if ( wp_remote_retrieve_response_code( $request ) !== 200 ) {
$data['errors'][] = 'http-error';
@@ -503,7 +550,7 @@ class WC_Helper_Updater {
*/
public static function get_updates_count_based_on_site_status() {
if ( ! WC_Helper::is_site_connected() ) {
return 1;
return 0;
}
$count = self::get_updates_count() ?? 0;
@@ -514,6 +561,45 @@ class WC_Helper_Updater {
return $count;
}
/**
* Get the type of woo connect notice to be shown in the WC Settings and Marketplace pages.
* - If a store is connected to woocommerce.com or has no installed woo plugins, return 'none'.
* - If a store has installed woo plugins but no updates, return 'short'.
* - If a store has an installed woo plugin with update, return 'long'.
*
* @return string The notice type, 'none', 'short', or 'long'.
*/
public static function get_woo_connect_notice_type() {
if ( WC_Helper::is_site_connected() ) {
return 'none';
}
$woo_plugins = WC_Helper::get_local_woo_plugins();
if ( empty( $woo_plugins ) ) {
return 'none';
}
$update_data = self::get_update_data();
if ( empty( $update_data ) ) {
return 'short';
}
// Scan local plugins.
foreach ( $woo_plugins as $plugin ) {
if ( empty( $update_data[ $plugin['_product_id'] ] ) ) {
continue;
}
if ( version_compare( $plugin['Version'], $update_data[ $plugin['_product_id'] ]['version'], '<' ) ) {
return 'long';
}
}
return 'short';
}
/**
* Return the updates count markup.
*

View File

@@ -5,6 +5,8 @@
* @package WooCommerce\Admin
*/
use Automattic\WooCommerce\Admin\Features\Features;
defined( 'ABSPATH' ) || exit;
/**

View File

@@ -217,11 +217,6 @@ class WC_Settings_General extends WC_Settings_Page {
'id' => 'general_options',
),
array(
'id' => 'wc_settings_general_site_visibility_slotfill',
'type' => 'slotfill_placeholder',
),
array(
'title' => __( 'Currency options', 'woocommerce' ),
'type' => 'title',

View File

@@ -0,0 +1,52 @@
<?php
/**
* WooCommerce site visibility settings
*
* @package WooCommerce\Admin
*/
defined( 'ABSPATH' ) || exit;
/**
* Settings for API.
*/
if ( class_exists( 'WC_Settings_Site_Visibility', false ) ) {
return new WC_Settings_Site_Visibility();
}
/**
* WC_Settings_Advanced.
*/
class WC_Settings_Site_Visibility extends WC_Settings_Page {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'site-visibility';
$this->label = __( 'Site visibility', 'woocommerce' );
parent::__construct();
}
/**
* Get settings for the default section.
*
* @return array
*/
protected function get_settings_for_default_section() {
$settings =
array(
array(
'id' => 'wc_settings_site_visibility_slotfill',
'type' => 'slotfill_placeholder',
),
);
return $settings;
}
}
return new WC_Settings_Site_Visibility();

View File

@@ -741,11 +741,6 @@ if ( 0 < $mu_plugins_count ) :
<td><?php echo $settings['enforce_approved_download_dirs'] ? '<mark class="yes"><span class="dashicons dashicons-yes"></span></mark>' : '<mark class="no">&ndash;</mark>'; ?></td>
</tr>
<tr>
<td data-export-label="HPOS feature screen enabled"><?php esc_html_e( 'HPOS feature screen enabled:', 'woocommerce' ); ?></td>
<td class="help"><?php echo wc_help_tip( esc_html__( 'Is HPOS feature screen enabled?', 'woocommerce' ) ); ?></td>
<td><?php echo $settings['HPOS_feature_screen_enabled'] ? '<mark class="yes"><span class="dashicons dashicons-yes"></span></mark>' : '<mark class="no">&ndash;</mark>'; ?></td>
</tr>
<tr>
<td data-export-label="HPOS feature enabled"><?php esc_html_e( 'HPOS enabled:', 'woocommerce' ); ?></td>
<td class="help"><?php echo wc_help_tip( esc_html__( 'Is HPOS enabled?', 'woocommerce' ) ); ?></td>