Changeset 3182923
- Timestamp:
- 11/06/2024 07:50:38 AM (17 months ago)
- Location:
- woocommerce-sequential-order-numbers/trunk
- Files:
-
- 1 deleted
- 3 edited
-
build (deleted)
-
i18n/languages/woocommerce-sequential-order-numbers.pot (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
woocommerce-sequential-order-numbers.php (modified) (47 diffs)
Legend:
- Unmodified
- Added
- Removed
-
woocommerce-sequential-order-numbers/trunk/i18n/languages/woocommerce-sequential-order-numbers.pot
r2962740 r3182923 1 # Copyright (C) 202 3SkyVerge1 # Copyright (C) 2024 SkyVerge 2 2 # This file is distributed under the GNU General Public License v3.0. 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: Sequential Order Numbers for WooCommerce 1.10.1\n" 6 "Report-Msgid-Bugs-To: " 7 "https://woocommerce.com/my-account/marketplace-ticket-form/\n" 8 "POT-Creation-Date: 2023-09-05 03:53:24+00:00\n" 9 "MIME-Version: 1.0\n" 10 "Content-Type: text/plain; charset=utf-8\n" 11 "Content-Transfer-Encoding: 8bit\n" 12 "PO-Revision-Date: 2023-MO-DA HO:MI+ZONE\n" 5 "Project-Id-Version: Sequential Order Numbers for WooCommerce 1.11.0\n" 6 "Report-Msgid-Bugs-To: https://woocommerce.com/my-account/marketplace-ticket-form/\n" 13 7 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" 14 8 "Language-Team: LANGUAGE <LL@li.org>\n" 9 "MIME-Version: 1.0\n" 10 "Content-Type: text/plain; charset=UTF-8\n" 11 "Content-Transfer-Encoding: 8bit\n" 12 "POT-Creation-Date: 2024-11-06T07:50:23+00:00\n" 13 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 14 "X-Generator: WP-CLI 2.6.0\n" 15 "X-Domain: woocommerce-sequential-order-numbers\n" 15 16 16 #: woocommerce-sequential-order-numbers.php:136 17 #. Plugin Name of the plugin 18 msgid "Sequential Order Numbers for WooCommerce" 19 msgstr "" 20 21 #. Plugin URI of the plugin 22 msgid "http://www.skyverge.com/blog/woocommerce-sequential-order-numbers/" 23 msgstr "" 24 25 #. Description of the plugin 26 msgid "Provides sequential order numbers for WooCommerce orders" 27 msgstr "" 28 29 #. Author of the plugin 30 msgid "SkyVerge" 31 msgstr "" 32 33 #. Author URI of the plugin 34 msgid "http://www.skyverge.com" 35 msgstr "" 36 17 37 #. translators: Placeholders: %s - plugin name 38 #: woocommerce-sequential-order-numbers.php:139 18 39 msgid "You cannot clone instances of %s." 19 40 msgstr "" 20 41 21 #: woocommerce-sequential-order-numbers.php:14822 42 #. translators: Placeholders: %s - plugin name 43 #: woocommerce-sequential-order-numbers.php:151 23 44 msgid "You cannot unserialize instances of %s." 24 45 msgstr "" 25 46 26 #: woocommerce-sequential-order-numbers.php:678 27 #. translators: Placeholders: %1$s - plugin name; %2$s - WooCommerce version; 28 #. %3$s, %5$s - <a> tags; %4$s - </a> tag 29 msgid "" 30 "%1$s is inactive because it requires WooCommerce %2$s or newer. Please " 31 "%3$supdate WooCommerce%4$s or run the %5$sWooCommerce database upgrade%4$s." 47 #: woocommerce-sequential-order-numbers.php:489 48 msgid "Allows filtering of orders by custom order number. Example: /wp-json/wc/v3/orders/?number=240222-45" 32 49 msgstr "" 33 50 34 #: woocommerce-sequential-order-numbers.php:728 35 msgid "" 36 "Error activating and installing <strong>Sequential Order Numbers for " 37 "WooCommerce</strong>: %s" 51 #. translators: Placeholders: %1$s - plugin name; %2$s - WooCommerce version; %3$s, %5$s - <a> tags; %4$s - </a> tag 52 #: woocommerce-sequential-order-numbers.php:731 53 msgid "%1$s is inactive because it requires WooCommerce %2$s or newer. Please %3$supdate WooCommerce%4$s or run the %5$sWooCommerce database upgrade%4$s." 38 54 msgstr "" 39 55 40 #: woocommerce-sequential-order-numbers.php:730 56 #: woocommerce-sequential-order-numbers.php:783 57 msgid "Error activating and installing <strong>Sequential Order Numbers for WooCommerce</strong>: %s" 58 msgstr "" 59 60 #: woocommerce-sequential-order-numbers.php:785 41 61 msgid "« Go Back" 42 62 msgstr "" 43 44 #. Plugin Name of the plugin/theme45 msgid "Sequential Order Numbers for WooCommerce"46 msgstr ""47 48 #. Plugin URI of the plugin/theme49 msgid "http://www.skyverge.com/blog/woocommerce-sequential-order-numbers/"50 msgstr ""51 52 #. Description of the plugin/theme53 msgid "Provides sequential order numbers for WooCommerce orders"54 msgstr ""55 56 #. Author of the plugin/theme57 msgid "SkyVerge"58 msgstr ""59 60 #. Author URI of the plugin/theme61 msgid "http://www.skyverge.com"62 msgstr "" -
woocommerce-sequential-order-numbers/trunk/readme.txt
r2962740 r3182923 3 3 Tags: woocommerce, order number, sequential order number, woocommerce orders 4 4 Requires at least: 5.6 5 Tested up to: 6. 3.15 Tested up to: 6.6.2 6 6 Requires PHP: 7.4 7 Stable tag: 1.1 0.17 Stable tag: 1.11.0 8 8 9 9 This plugin extends WooCommerce by setting sequential order numbers for new orders. … … 103 103 == Changelog == 104 104 105 - 2024.11.06 - version 1.11.0 = 106 * Misc - Code clean up and optimization 107 * Misc - Add compatibility for WooCommerce Checkout block 108 * Misc - Register REST API custom order number filter 109 105 110 - 2023.09.05 - version 1.10.1 = 106 111 * Fix - Call save order method only in HPOS installs to avoid setting the same order number meta twice in CPT installations -
woocommerce-sequential-order-numbers/trunk/woocommerce-sequential-order-numbers.php
r2962740 r3182923 6 6 * Author: SkyVerge 7 7 * Author URI: http://www.skyverge.com 8 * Version: 1.1 0.18 * Version: 1.11.0 9 9 * Text Domain: woocommerce-sequential-order-numbers 10 10 * Domain Path: /i18n/languages/ … … 20 20 * 21 21 * WC requires at least: 3.9.4 22 * WC tested up to: 8.0.322 * WC tested up to: 9.3.3 23 23 */ 24 25 use Automattic\WooCommerce\Utilities\FeaturesUtil; 26 use Automattic\WooCommerce\Utilities\OrderUtil; 24 27 25 28 defined( 'ABSPATH' ) or exit; … … 33 36 34 37 35 /** version number */36 const VERSION = '1.10.1';37 38 /** minimum required wc version */39 const MINIMUM_WC_VERSION = '3.9.4';40 41 /** @var \WC_Seq_Order_Number single instance of this plugin */42 protected static $instance;38 /** Version number */ 39 public const VERSION = '1.11.0'; 40 41 /** Minimum required wc version */ 42 public const MINIMUM_WC_VERSION = '3.9.4'; 43 44 /** @var WC_Seq_Order_Number single instance of this plugin */ 45 protected static WC_Seq_Order_Number $instance; 43 46 44 47 /** version option name */ 45 const VERSION_OPTION_NAME = 'woocommerce_seq_order_number_db_version';48 public const VERSION_OPTION_NAME = 'woocommerce_seq_order_number_db_version'; 46 49 47 50 … … 54 57 55 58 add_action( 'plugins_loaded', [ $this, 'initialize' ] ); 56 add_action( 'init', [ $this, 'load_translation' ] );59 add_action( 'init', [ $this, 'load_translation' ] ); 57 60 58 61 // handle HPOS compatibility … … 70 73 * @return void 71 74 */ 72 public function handle_hpos_compatibility() 73 { 74 if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {75 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', plugin_basename( __FILE__ ), true );75 public function handle_hpos_compatibility() : void { 76 77 if ( class_exists( FeaturesUtil::class ) ) { 78 FeaturesUtil::declare_compatibility( 'custom_order_tables', plugin_basename( __FILE__ ), true ); 76 79 } 77 80 } … … 85 88 * @return bool 86 89 */ 87 protected function is_hpos_enabled() {88 89 return class_exists( \Automattic\WooCommerce\Utilities\OrderUtil::class )90 && \Automattic\WooCommerce\Utilities\OrderUtil::custom_orders_table_usage_is_enabled();90 protected function is_hpos_enabled() : bool { 91 92 return class_exists( OrderUtil::class ) 93 && OrderUtil::custom_orders_table_usage_is_enabled(); 91 94 } 92 95 … … 99 102 * @return bool 100 103 */ 101 protected function is_orders_screen() {102 103 $current_screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;104 protected function is_orders_screen() : bool { 105 106 $current_screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; 104 107 105 108 if ( ! $current_screen ) { … … 113 116 } 114 117 115 if ( is_callable( \Automattic\WooCommerce\Utilities\OrderUtil::class . '::get_order_admin_screen' ) ) {116 $orders_screen_id = \Automattic\WooCommerce\Utilities\OrderUtil::get_order_admin_screen();118 if ( is_callable( OrderUtil::class . '::get_order_admin_screen' ) ) { 119 $orders_screen_id = OrderUtil::get_order_admin_screen(); 117 120 } else { 118 121 $orders_screen_id = function_exists( 'wc_get_page_screen_id' ) ? wc_get_page_screen_id( 'shop-order' ) : null; … … 120 123 121 124 return $orders_screen_id === $current_screen->id 122 && isset( $_GET['page'] )123 && $_GET['page'] === 'wc-orders'124 && ( ! isset( $_GET['action'] ) || ! in_array( $_GET['action'], [ 'new', 'edit' ], true ) );125 && isset( $_GET['page'] ) 126 && $_GET['page'] === 'wc-orders' 127 && ( ! isset( $_GET['action'] ) || ! in_array( $_GET['action'], [ 'new', 'edit' ], true ) ); 125 128 } 126 129 … … 159 162 * @since 1.3.2 160 163 */ 161 public function initialize() {162 163 if ( ! $this->minimum_ wc_version_met() ) {164 public function initialize() : void { 165 166 if ( ! $this->minimum_php_version_met() || ! $this->minimum_wc_version_met() ) { 164 167 // halt functionality 165 168 return; … … 171 174 } else { 172 175 add_action( 'woocommerce_checkout_update_order_meta', [ $this, 'set_sequential_order_number' ], 10, 2 ); 173 add_action( 'woocommerce_process_shop_order_meta', [ $this, 'set_sequential_order_number' ], 35, 2 );176 add_action( 'woocommerce_process_shop_order_meta', [ $this, 'set_sequential_order_number' ], 35, 2 ); 174 177 add_action( 'woocommerce_before_resend_order_emails', [ $this, 'set_sequential_order_number' ] ); 175 178 } … … 179 182 180 183 // return our custom order number for display 181 add_filter( 'woocommerce_order_number', array( $this, 'get_order_number' ), 10, 2 );184 add_filter( 'woocommerce_order_number', [ $this, 'get_order_number' ], 10, 2 ); 182 185 183 186 // order tracking page search by order number 184 add_filter( 'woocommerce_shortcode_order_tracking_order_id', array( $this, 'find_order_by_order_number' ));187 add_filter( 'woocommerce_shortcode_order_tracking_order_id', [ $this, 'find_order_by_order_number' ] ); 185 188 186 189 // WC Subscriptions support 187 190 add_filter( 'wc_subscriptions_renewal_order_data', [ $this, 'subscriptions_remove_renewal_order_meta' ] ); 188 add_filter( 'wcs_renewal_order_created', [ $this, 'subscriptions_set_sequential_order_number' ], 10, 2);191 add_filter( 'wcs_renewal_order_created', [ $this, 'subscriptions_set_sequential_order_number' ] ); 189 192 190 193 // WooCommerce Admin support 191 194 if ( class_exists( 'Automattic\WooCommerce\Admin\Install', false ) || class_exists( 'WC_Admin_Install', false ) ) { 192 add_filter( 'woocommerce_rest_orders_prepare_object_query', array( $this, 'wc_admin_order_number_api_param' ), 10, 2 );195 add_filter( 'woocommerce_rest_orders_prepare_object_query', [ $this, 'wc_admin_order_number_api_param' ], 10, 2 ); 193 196 } 194 197 … … 204 207 // ensure that admin order table search by order number works 205 208 add_filter( 'woocommerce_shop_order_search_fields', [ $this, 'custom_search_fields' ] ); 206 add_filter( 'woocommerce_order_table_search_query_meta_keys', [ $this, 'custom_search_fields' ] );209 add_filter( 'woocommerce_order_table_search_query_meta_keys', [ $this, 'custom_search_fields' ] ); 207 210 208 211 // sort by underlying _order_number on the Pre-Orders table 209 add_filter( 'wc_pre_orders_edit_pre_orders_request', array( $this, 'custom_orderby' ));210 add_filter( 'wc_pre_orders_search_fields', array( $this, 'custom_search_fields' ));212 add_filter( 'wc_pre_orders_edit_pre_orders_request', [ $this, 'custom_orderby' ] ); 213 add_filter( 'wc_pre_orders_search_fields', [ $this, 'custom_search_fields' ] ); 211 214 212 215 } … … 216 219 add_action( 'admin_init', [ $this, 'install' ] ); 217 220 } 221 222 // Register REST API custom order number filter 223 add_filter( 'woocommerce_rest_orders_collection_params', [ $this, 'add_rest_custom_order_number_query_param' ] ); 218 224 } 219 225 … … 226 232 * @since 1.3.3 227 233 */ 228 public function load_translation() {234 public function load_translation() : void { 229 235 230 236 // localization … … 238 244 * @since 1.0.0 239 245 * 240 * @param string $order_number order number to search for246 * @param string|int $order_number order number to search for 241 247 * @return int $order_id for the order identified by $order_number, or 0 242 248 */ 243 public function find_order_by_order_number( $order_number ) {249 public function find_order_by_order_number( $order_number ) : int { 244 250 245 251 // search for the order by custom order number 246 252 if ( $this->is_hpos_enabled() ) { 247 $orders = wc_get_orders( [253 $orders = wc_get_orders( [ 248 254 'return' => 'ids', 249 255 'limit' => 1, … … 252 258 'key' => '_order_number', 253 259 'value' => $order_number, 254 'comparison' => '=' 260 'comparison' => '=', 255 261 ], 256 262 ], 257 ] );263 ] ); 258 264 } else { 259 265 $orders = get_posts( [ … … 267 273 } 268 274 269 $order_id = $orders ? current( $orders) : null;275 $order_id = $orders ? current( $orders ) : null; 270 276 271 277 // order was found … … 297 303 * @since 1.0.0 298 304 * 299 * @param int|\WC_Order $order_id order identifier or order object 300 * @param \WP_Post|\WC_Order|array<string, mixed>|null $object $object order or post object or post data (depending on HPOS and hook in use) 301 */ 302 public function set_sequential_order_number( $order_id = null, $object = null ) { 305 * @param int|WC_Order $order_id order identifier or order object 306 * @param WP_Post|WC_Order|array<string, mixed>|null $object $object order or post object or post data (depending on HPOS and hook in use) 307 */ 308 public function set_sequential_order_number( $order_id = null, $object = null ) : void { 309 303 310 global $wpdb; 304 311 305 312 $using_hpos = $this->is_hpos_enabled(); 306 313 307 if ( $object instanceof \WP_Post ) {314 if ( $object instanceof WP_Post ) { 308 315 309 316 $is_order = 'shop_order' === $object->post_type; … … 312 319 $order_status = $object->post_status; 313 320 321 } else if ( $order_id instanceof WC_Order ) { 322 323 $is_order = true; 324 $order = $order_id; 325 $order_id = $order->get_id(); 326 $order_status = $order->get_status(); 327 314 328 } else { 315 329 316 $order = $object instanceof \WC_Order ? $object : wc_get_order( (int) $order_id );317 $is_order = $order instanceof \WC_Order && 'shop_order' === $order->get_type();330 $order = $object instanceof WC_Order ? $object : wc_get_order( (int) $order_id ); 331 $is_order = $order instanceof WC_Order && 'shop_order' === $order->get_type(); 318 332 $order_id = ! $order_id && $order ? $order->get_id() : (int) $order_id; 319 333 $order_status = $order ? $order->get_status() : ''; … … 367 381 * @since 1.0.0 368 382 * 369 * @param string $order_number the order id with a leading hash370 * @param \WC_Order$order the order object383 * @param string|int $order_number the order id with a leading hash 384 * @param WC_Order|WC_Subscription $order the order object 371 385 * @return string custom order number 372 386 */ … … 374 388 375 389 // don't display an order number for subscription objects 376 if ( $order instanceof \WC_Subscription ) {390 if ( class_exists( WC_Subscription::class ) && $order instanceof WC_Subscription ) { 377 391 return $order_number; 378 392 } 379 393 380 if ( $sequential_order_number = $order->get_meta( '_order_number', true, 'edit' ) ) {394 if ( $sequential_order_number = (string) $order->get_meta( '_order_number', true, 'edit' ) ) { 381 395 $order_number = $sequential_order_number; 382 396 } … … 396 410 * @since 1.3 397 411 * 398 * @param array $vars associative array of orderby parameters399 * @return array associative array of orderby parameters412 * @param array|mixed $vars associative array of orderby parameters 413 * @return array|mixed associative array of orderby parameters 400 414 */ 401 415 public function woocommerce_custom_shop_order_orderby( $vars ) { 416 402 417 global $typenow; 403 418 … … 431 446 * @return array associative array of orderby parameters 432 447 */ 433 public function custom_orderby( $args ){448 public function custom_orderby( array $args ) : array { 434 449 435 450 // sorting 436 if ( isset( $args['orderby'] ) && 'ID' == $args['orderby'] ) {451 if ( isset( $args['orderby'] ) && 'ID' === $args['orderby'] ) { 437 452 438 453 $args = array_merge( $args, [ … … 456 471 * @return string[] of order meta fields to search by 457 472 */ 458 public function custom_search_fields( $search_fields ) { 459 460 return array_merge( (array) $search_fields, [ '_order_number' ] ); 461 } 462 473 public function custom_search_fields( array $search_fields ) : array { 474 475 return array_merge( $search_fields, [ '_order_number' ] ); 476 } 477 478 479 /** 480 * Register a custom query parameter for WooCommerce orders REST API to filter by custom order number. 481 */ 482 public function add_rest_custom_order_number_query_param( array $args ) : array { 483 484 if ( array_key_exists( 'number', $args ) ) { 485 return $args; 486 } 487 488 $args['number'] = [ 489 'description' => __( 'Allows filtering of orders by custom order number. Example: /wp-json/wc/v3/orders/?number=240222-45', 'woocommerce-sequential-order-numbers' ), 490 'sanitize_callback' => 'rest_sanitize_request_arg', 491 'type' => 'string', 492 'validate_callback' => 'rest_validate_request_arg', 493 ]; 494 495 return $args; 496 } 463 497 464 498 /** 3rd Party Plugin Support ******************************************************/ … … 472 506 * @internal 473 507 * 474 * @param \WC_Order $renewal_order the new renewal order object 475 * @param \WC_Subscription $subscription ID of a 'shop_subscription' object, or instance of a WC_Subscription object 476 * @return \WC_Order renewal order instance 477 */ 478 public function subscriptions_set_sequential_order_number( $renewal_order, $subscription ) { 479 480 if ( $renewal_order instanceof \WC_Order ) { 508 * @param WC_Order|mixed $renewal_order the new renewal order object 509 * @return WC_Order|mixed renewal order instance 510 */ 511 public function subscriptions_set_sequential_order_number( $renewal_order ) { 512 513 if ( $renewal_order instanceof WC_Order ) { 481 514 482 515 $order = wc_get_order( $renewal_order->get_id() ); … … 501 534 * 502 535 * @param string[]|mixed $order_data 503 * @return string[] mixed536 * @return string[]|mixed 504 537 */ 505 538 public function subscriptions_remove_renewal_order_meta( $order_data ) { … … 514 547 } 515 548 549 516 550 /** 517 551 * Hook WooCommerce Admin order number search to the meta value. … … 521 555 * @internal 522 556 * 523 * @param array $args Arguments to be passed to WC_Order_Query.524 * @param WP_REST_Request $request REST API request being made.525 * @return array Arguments to be passed to WC_Order_Query.557 * @param array|mixed $args Arguments to be passed to WC_Order_Query. 558 * @param WP_REST_Request|mixed $request REST API request being made. 559 * @return array|mixed Arguments to be passed to WC_Order_Query. 526 560 */ 527 561 public function wc_admin_order_number_api_param( $args, $request ) { 562 563 if ( ! is_array( $args ) || ! $request instanceof WP_REST_Request ) { 564 return $args; 565 } 566 528 567 global $wpdb; 529 568 … … 533 572 $number_search = trim( $request['number'] ); 534 573 $order_sql = esc_sql( $args['order'] ); // Order defaults to DESC. 535 $limit = intval( $args['posts_per_page'] ); // Posts per page defaults to 10.536 537 $using_hpos = $this->is_hpos_enabled();574 $limit = (int) $args['posts_per_page']; // Posts per page defaults to 10. 575 576 $using_hpos = $this->is_hpos_enabled(); 538 577 $order_meta_table = $using_hpos ? $wpdb->prefix . 'wc_orders_meta' : $wpdb->postmeta; 539 $order_id_column = $using_hpos ? 'order_id' : 'post_id';578 $order_id_column = $using_hpos ? 'order_id' : 'post_id'; 540 579 541 580 // Search Order number meta value instead of Post ID. … … 552 591 553 592 if ( $using_hpos ) { 554 $args['order__in'] = empty( $order_ids ) ? array( 0 ): $order_ids;593 $args['order__in'] = empty( $order_ids ) ? [ 0 ] : $order_ids; 555 594 } else { 556 $args['post__in'] = empty( $order_ids ) ? array( 0 ): $order_ids;595 $args['post__in'] = empty( $order_ids ) ? [ 0 ] : $order_ids; 557 596 } 558 597 … … 570 609 * Main Sequential Order Numbers Instance, ensures only one instance is/can be loaded. 571 610 * 611 * @since 1.7.0 612 * 613 * @return WC_Seq_Order_Number 572 614 * @see wc_sequential_order_numbers() 573 615 * 574 * @since 1.7.0 575 * 576 * @return \WC_Seq_Order_Number 577 */ 578 public static function instance() { 579 580 if ( null === self::$instance ) { 581 self::$instance = new self(); 582 } 583 584 return self::$instance; 616 */ 617 public static function instance() : WC_Seq_Order_Number { 618 619 return self::$instance ??= new self(); 585 620 } 586 621 … … 594 629 * @return boolean true if the named plugin is installed and active 595 630 */ 596 public static function is_plugin_active( $plugin_name ){597 598 $active_plugins = (array) get_option( 'active_plugins', array());631 public static function is_plugin_active( string $plugin_name ) : bool { 632 633 $active_plugins = (array) get_option( 'active_plugins', [] ); 599 634 600 635 if ( is_multisite() ) { 601 $active_plugins = array_merge( $active_plugins, array_keys( get_site_option( 'active_sitewide_plugins', array()) ) );602 } 603 604 $plugin_filenames = array();636 $active_plugins = array_merge( $active_plugins, array_keys( get_site_option( 'active_sitewide_plugins', [] ) ) ); 637 } 638 639 $plugin_filenames = []; 605 640 606 641 foreach ( $active_plugins as $plugin ) { … … 609 644 610 645 // normal plugin name (plugin-dir/plugin-filename.php) 611 list( , $filename )= explode( '/', $plugin );646 [ , $filename ] = explode( '/', $plugin ); 612 647 613 648 } else { … … 620 655 } 621 656 622 return in_array( $plugin_name, $plugin_filenames );657 return in_array( $plugin_name, $plugin_filenames, true ); 623 658 } 624 659 … … 634 669 * @return string woocommerce version number or null 635 670 */ 636 private static function get_wc_version() { 671 private static function get_wc_version() : ?string { 672 637 673 return defined( 'WC_VERSION' ) && WC_VERSION ? WC_VERSION : null; 638 674 } … … 646 682 * @return bool 647 683 */ 648 private function minimum_wc_version_met() {684 private function minimum_wc_version_met() : bool { 649 685 650 686 $version_met = true; 651 687 688 if ( ! $wc_version = self::get_wc_version() ) { 689 return false; 690 } 691 652 692 // if a plugin defines a minimum WC version, render a notice and skip loading the plugin 653 if ( defined( 'self::MINIMUM_WC_VERSION' ) && version_compare( self::get_wc_version(), self::MINIMUM_WC_VERSION, '<' ) ) {654 655 if ( is_admin() && ! wp_doing_ajax() && ! has_action( 'admin_notices', array( $this, 'render_update_notices' )) ) {656 657 add_action( 'admin_notices', array( $this, 'render_update_notices' ));693 if ( version_compare( $wc_version, self::MINIMUM_WC_VERSION, '<' ) ) { 694 695 if ( is_admin() && ! wp_doing_ajax() && ! has_action( 'admin_notices', [ $this, 'render_update_notices' ] ) ) { 696 697 add_action( 'admin_notices', [ $this, 'render_update_notices' ] ); 658 698 } 659 699 … … 666 706 667 707 /** 708 * Performs a minimum PHP version check. 709 * 710 * @since 1.11.0 711 * 712 * @return bool 713 */ 714 private function minimum_php_version_met() : bool { 715 716 return PHP_VERSION_ID >= 70400; 717 } 718 719 720 /** 668 721 * Renders a notice to update WooCommerce if needed 669 722 * … … 672 725 * @since 1.3.2 673 726 */ 674 public function render_update_notices() {727 public function render_update_notices() : void { 675 728 676 729 $message = sprintf( 677 /* translators: Placeholders: %1$s - plugin name; %2$s - WooCommerce version; %3$s, %5$s - <a> tags; %4$s - </a> tag */730 /* translators: Placeholders: %1$s - plugin name; %2$s - WooCommerce version; %3$s, %5$s - <a> tags; %4$s - </a> tag */ 678 731 esc_html__( '%1$s is inactive because it requires WooCommerce %2$s or newer. Please %3$supdate WooCommerce%4$s or run the %5$sWooCommerce database upgrade%4$s.', 'woocommerce-sequential-order-numbers' ), 679 732 'Sequential Order Numbers', … … 692 745 693 746 /** 694 * Run every time. Used since the activation hook is not executed when updating a plugin 747 * Run every time 748 * 749 * Used since the activation hook is not executed when updating a plugin 695 750 * 696 751 * @internal … … 698 753 * @since 1.0.0 699 754 */ 700 public function install() {701 702 $installed_version = get_option( WC_Seq_Order_Number::VERSION_OPTION_NAME );755 public function install() : void { 756 757 $installed_version = get_option( self::VERSION_OPTION_NAME ); 703 758 704 759 if ( ! $installed_version ) { … … 715 770 'type' => 'shop_order', 716 771 'offset' => $offset, 717 'limit' => $orders_par_page 772 'limit' => $orders_par_page, 718 773 ] ); 719 774 … … 725 780 wp_die( 726 781 sprintf( 727 /** translators: Placeholder: %s - error message(s) */782 /** translators: Placeholder: %s - error message(s) */ 728 783 __( 'Error activating and installing <strong>Sequential Order Numbers for WooCommerce</strong>: %s', 'woocommerce-sequential-order-numbers' ), 729 784 '<ul><li>' . implode( '</li><li>', $orders->get_error_messages() ) . '</li></ul>' … … 733 788 } elseif ( is_array( $orders ) ) { 734 789 735 foreach ( $orders as $order ) {736 737 if ( '' === $order->get_meta( '_order_number' , true) ) {738 $order->add_meta_data( '_order_number', (string) $order->get_id() );790 foreach ( $orders as $order ) { 791 792 if ( '' === $order->get_meta( '_order_number' ) ) { 793 $order->add_meta_data( '_order_number', (string) $order->get_id() ); 739 794 $order->save_meta_data(); 740 795 } … … 750 805 } 751 806 752 if ( $installed_version !== WC_Seq_Order_Number::VERSION ) {807 if ( $installed_version !== self::VERSION ) { 753 808 754 809 $this->upgrade( $installed_version ); 755 810 756 811 // new version number 757 update_option( WC_Seq_Order_Number::VERSION_OPTION_NAME, WC_Seq_Order_Number::VERSION );812 update_option( self::VERSION_OPTION_NAME, self::VERSION ); 758 813 } 759 814 } … … 767 822 * @param string $installed_version 768 823 */ 769 private function upgrade( $installed_version ){824 private function upgrade( string $installed_version ) : void { 770 825 // upgrade code goes here 771 826 } … … 780 835 * @since 1.7.0 781 836 * 782 * @return \WC_Seq_Order_Number837 * @return WC_Seq_Order_Number 783 838 */ 784 function wc_sequential_order_numbers() { 839 function wc_sequential_order_numbers() : WC_Seq_Order_Number { 840 785 841 return WC_Seq_Order_Number::instance(); 786 842 }
Note: See TracChangeset
for help on using the changeset viewer.