Changeset 3086929
- Timestamp:
- 05/15/2024 08:20:18 AM (19 months ago)
- Location:
- woocommerce-legacy-rest-api/trunk
- Files:
-
- 6 edited
-
includes/class-wc-legacy-rest-api-plugin.php (modified) (5 diffs)
-
includes/legacy/api/v1/class-wc-api-server.php (modified) (1 diff)
-
includes/legacy/api/v2/class-wc-api-server.php (modified) (1 diff)
-
includes/legacy/api/v3/class-wc-api-server.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
woocommerce-legacy-rest-api.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
woocommerce-legacy-rest-api/trunk/includes/class-wc-legacy-rest-api-plugin.php
r3022200 r3086929 16 16 * Plugin initialization, to be invoked inside the woocommerce_init hook. 17 17 */ 18 private static function init() { 19 require_once __DIR__ . '/legacy/class-wc-legacy-api.php'; 20 require_once __DIR__ . '/class-wc-api.php'; 18 public static function on_woocommerce_init() { 19 if( ! self::legacy_api_still_in_woocommerce() ) { 20 require_once __DIR__ . '/legacy/class-wc-legacy-api.php'; 21 require_once __DIR__ . '/class-wc-api.php'; 21 22 22 WC()->api = new WC_API(); 23 WC()->api->init(); 24 WC()->api->add_endpoint(); 23 WC()->api = new WC_API(); 24 WC()->api->init(); 25 WC()->api->add_endpoint(); 26 } 27 28 if( ! self::maybe_add_hpos_incompatibility_admin_notice() ) { 29 self::maybe_remove_hpos_incompatibility_admin_notice(); 30 } 25 31 } 26 32 … … 50 56 */ 51 57 public static function on_plugin_activated() { 58 if( ! self::woocommerce_is_active() ) { 59 return; 60 } 61 52 62 if( ! self::legacy_api_still_in_woocommerce() ) { 53 63 require_once __DIR__ . '/legacy/class-wc-legacy-api.php'; … … 60 70 61 71 /** 72 * Add the "legacy REST API and HPOS are incompatible" admin notice if needed. 73 * 74 * @returns bool True if the notice has been added, false otherwise. 75 */ 76 private static function maybe_add_hpos_incompatibility_admin_notice() { 77 if( ! self::hpos_is_enabled() || self::user_has_dismissed_admin_notice( 'legacy_rest_api_is_incompatible_with_hpos' ) ) { 78 return false; 79 } 80 81 if ( ! WC_Admin_Notices::has_notice( 'legacy_rest_api_is_incompatible_with_hpos' ) ) { 82 $features_page_url = admin_url( 'admin.php?page=wc-settings&tab=advanced§ion=features' ); 83 WC_Admin_Notices::add_custom_notice( 84 'legacy_rest_api_is_incompatible_with_hpos', 85 sprintf( 86 wpautop( __( '⚠ <b>The Legacy REST API plugin and HPOS are both active on this site.</b><br/><br/>Please be aware that the WooCommerce Legacy REST API is <b>not</b> compatible with HPOS. <a target="_blank" href="%s">Manage features</a>', 'woocommerce-legacy-rest-api' ) ), 87 $features_page_url 88 ) 89 ); 90 91 return true; 92 } 93 94 return false; 95 } 96 97 /** 98 * Check if HPOS is currently in use. 99 * 100 * @returns bool True if HPOS is currently in use. 101 */ 102 private function hpos_is_enabled(): bool { 103 return class_exists( '\Automattic\WooCommerce\Utilities\OrderUtil' ) && \Automattic\WooCommerce\Utilities\OrderUtil::custom_orders_table_usage_is_enabled(); 104 } 105 106 /** 107 * Remove the "legacy REST API and HPOS are incompatible" admin notice if needed. 108 */ 109 private static function maybe_remove_hpos_incompatibility_admin_notice() { 110 if ( WC_Admin_Notices::has_notice( 'legacy_rest_api_is_incompatible_with_hpos' ) && ! self::hpos_is_enabled() ) { 111 self::remove_notice( 'legacy_rest_api_is_incompatible_with_hpos' ); 112 } 113 } 114 115 /** 62 116 * Act on plugin deactivation/uninstall. 63 117 */ 64 118 public static function on_plugin_deactivated() { 119 if( ! self::woocommerce_is_active() ) { 120 return; 121 } 122 65 123 if( ! self::legacy_api_still_in_woocommerce() ) { 66 124 update_option( 'woocommerce_api_enabled', 'no' ); 67 125 flush_rewrite_rules(); 126 } 127 128 if ( WC_Admin_Notices::has_notice( 'legacy_rest_api_is_incompatible_with_hpos' ) ) { 129 self::remove_notice( 'legacy_rest_api_is_incompatible_with_hpos' ); 68 130 } 69 131 } … … 75 137 if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) { 76 138 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', self::$plugin_filename, false ); 77 }78 }79 80 /**81 * Handler for the before_woocommerce_init hook, needed to initialize the plugin.82 */83 public static function on_woocommerce_init() {84 if( ! self::legacy_api_still_in_woocommerce() ) {85 self::init();86 139 } 87 140 } … … 102 155 return $all_plugins; 103 156 } 157 158 /** 159 * Check if WooCommerce itself is active in the site. 160 */ 161 private static function woocommerce_is_active() { 162 return class_exists( 'WooCommerce' ); 163 } 164 165 /** 166 * Check if the current user has dismissed an admin notice. 167 * 168 * @param string $notice_id Id of the notice. 169 */ 170 private static function user_has_dismissed_admin_notice( $notice_id ) { 171 return '' !== get_user_meta( get_current_user_id(), "dismissed_${notice_id}_notice", true ); 172 } 104 173 } -
woocommerce-legacy-rest-api/trunk/includes/legacy/api/v1/class-wc-api-server.php
r3022200 r3086929 279 279 // Normalise the endpoints 280 280 foreach ( $endpoints as $route => &$handlers ) { 281 if ( count( $handlers ) <= 2 && isset( $handlers[1] ) && ! is_array( $handlers[1] ) ) {281 if ( is_array( $handlers ) && count( $handlers ) <= 2 && isset( $handlers[1] ) && ! is_array( $handlers[1] ) ) { 282 282 $handlers = array( $handlers ); 283 283 } -
woocommerce-legacy-rest-api/trunk/includes/legacy/api/v2/class-wc-api-server.php
r3022200 r3086929 277 277 // Normalise the endpoints 278 278 foreach ( $endpoints as $route => &$handlers ) { 279 if ( count( $handlers ) <= 2 && isset( $handlers[1] ) && ! is_array( $handlers[1] ) ) {279 if ( is_array( $handlers ) && count( $handlers ) <= 2 && isset( $handlers[1] ) && ! is_array( $handlers[1] ) ) { 280 280 $handlers = array( $handlers ); 281 281 } -
woocommerce-legacy-rest-api/trunk/includes/legacy/api/v3/class-wc-api-server.php
r3022200 r3086929 277 277 // Normalise the endpoints 278 278 foreach ( $endpoints as $route => &$handlers ) { 279 if ( count( $handlers ) <= 2 && isset( $handlers[1] ) && ! is_array( $handlers[1] ) ) {279 if ( is_array( $handlers ) && count( $handlers ) <= 2 && isset( $handlers[1] ) && ! is_array( $handlers[1] ) ) { 280 280 $handlers = array( $handlers ); 281 281 } -
woocommerce-legacy-rest-api/trunk/readme.txt
r3022200 r3086929 5 5 Tested up to: 6.3 6 6 Requires PHP: 7.4 7 Stable tag: 1.0. 17 Stable tag: 1.0.2 8 8 License: GPLv3 9 9 License URI: https://www.gnu.org/licenses/gpl-3.0.html … … 41 41 - Replace the text domain for human-readable strings from 'woocommerce' to 'woocommerce-legacy-rest-api'. 42 42 - Add sanitization for data received via query string arguments and the $_SERVER array. 43 44 45 = 1.0.2 2024-05-01 46 47 Add a dismissable admin notice indicating that the Legacy REST API is not compatible with HPOS. 48 The notice will appear if the orders table is (or has been) selected as the orders data store in the WooCommerce features settings page, 49 and will disappear when that ceases to be true. Once the notice is dismissed it will never appear again. -
woocommerce-legacy-rest-api/trunk/woocommerce-legacy-rest-api.php
r3022200 r3086929 4 4 * Plugin URI: https://github.com/woocommerce/woocommerce-legacy-rest-api 5 5 * Description: The legacy WooCommerce REST API, which used to be part of WooCommerce itself but is removed as of WooCommerce 9.0. 6 * Version: 1.0. 16 * Version: 1.0.2 7 7 * Author: WooCommerce 8 8 * Author URI: https://woocommerce.com
Note: See TracChangeset
for help on using the changeset viewer.