Plugin Directory

Changeset 3182923


Ignore:
Timestamp:
11/06/2024 07:50:38 AM (17 months ago)
Author:
SkyVerge
Message:

Committing 1.11.0 to trunk

Location:
woocommerce-sequential-order-numbers/trunk
Files:
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • woocommerce-sequential-order-numbers/trunk/i18n/languages/woocommerce-sequential-order-numbers.pot

    r2962740 r3182923  
    1 # Copyright (C) 2023 SkyVerge
     1# Copyright (C) 2024 SkyVerge
    22# This file is distributed under the GNU General Public License v3.0.
    33msgid ""
    44msgstr ""
    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"
    137"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
    148"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"
    1516
    16 #: woocommerce-sequential-order-numbers.php:136
     17#. Plugin Name of the plugin
     18msgid "Sequential Order Numbers for WooCommerce"
     19msgstr ""
     20
     21#. Plugin URI of the plugin
     22msgid "http://www.skyverge.com/blog/woocommerce-sequential-order-numbers/"
     23msgstr ""
     24
     25#. Description of the plugin
     26msgid "Provides sequential order numbers for WooCommerce orders"
     27msgstr ""
     28
     29#. Author of the plugin
     30msgid "SkyVerge"
     31msgstr ""
     32
     33#. Author URI of the plugin
     34msgid "http://www.skyverge.com"
     35msgstr ""
     36
    1737#. translators: Placeholders: %s - plugin name
     38#: woocommerce-sequential-order-numbers.php:139
    1839msgid "You cannot clone instances of %s."
    1940msgstr ""
    2041
    21 #: woocommerce-sequential-order-numbers.php:148
    2242#. translators: Placeholders: %s - plugin name
     43#: woocommerce-sequential-order-numbers.php:151
    2344msgid "You cannot unserialize instances of %s."
    2445msgstr ""
    2546
    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
     48msgid "Allows filtering of orders by custom order number. Example: /wp-json/wc/v3/orders/?number=240222-45"
    3249msgstr ""
    3350
    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
     53msgid "%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."
    3854msgstr ""
    3955
    40 #: woocommerce-sequential-order-numbers.php:730
     56#: woocommerce-sequential-order-numbers.php:783
     57msgid "Error activating and installing <strong>Sequential Order Numbers for WooCommerce</strong>: %s"
     58msgstr ""
     59
     60#: woocommerce-sequential-order-numbers.php:785
    4161msgid "&laquo; Go Back"
    4262msgstr ""
    43 
    44 #. Plugin Name of the plugin/theme
    45 msgid "Sequential Order Numbers for WooCommerce"
    46 msgstr ""
    47 
    48 #. Plugin URI of the plugin/theme
    49 msgid "http://www.skyverge.com/blog/woocommerce-sequential-order-numbers/"
    50 msgstr ""
    51 
    52 #. Description of the plugin/theme
    53 msgid "Provides sequential order numbers for WooCommerce orders"
    54 msgstr ""
    55 
    56 #. Author of the plugin/theme
    57 msgid "SkyVerge"
    58 msgstr ""
    59 
    60 #. Author URI of the plugin/theme
    61 msgid "http://www.skyverge.com"
    62 msgstr ""
  • woocommerce-sequential-order-numbers/trunk/readme.txt

    r2962740 r3182923  
    33Tags: woocommerce, order number, sequential order number, woocommerce orders
    44Requires at least: 5.6
    5 Tested up to: 6.3.1
     5Tested up to: 6.6.2
    66Requires PHP: 7.4
    7 Stable tag: 1.10.1
     7Stable tag: 1.11.0
    88
    99This plugin extends WooCommerce by setting sequential order numbers for new orders.
     
    103103== Changelog ==
    104104
     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
    105110- 2023.09.05 - version 1.10.1 =
    106111 * 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  
    66 * Author: SkyVerge
    77 * Author URI: http://www.skyverge.com
    8  * Version: 1.10.1
     8 * Version: 1.11.0
    99 * Text Domain: woocommerce-sequential-order-numbers
    1010 * Domain Path: /i18n/languages/
     
    2020 *
    2121 * WC requires at least: 3.9.4
    22  * WC tested up to: 8.0.3
     22 * WC tested up to: 9.3.3
    2323 */
     24
     25use Automattic\WooCommerce\Utilities\FeaturesUtil;
     26use Automattic\WooCommerce\Utilities\OrderUtil;
    2427
    2528defined( 'ABSPATH' ) or exit;
     
    3336
    3437
    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;
    4346
    4447    /** 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';
    4649
    4750
     
    5457
    5558        add_action( 'plugins_loaded', [ $this, 'initialize' ] );
    56         add_action( 'init',           [ $this, 'load_translation' ] );
     59        add_action( 'init', [ $this, 'load_translation' ] );
    5760
    5861        // handle HPOS compatibility
     
    7073     * @return void
    7174     */
    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 );
    7679        }
    7780    }
     
    8588     * @return bool
    8689     */
    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();
    9194    }
    9295
     
    99102     * @return bool
    100103     */
    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;
    104107
    105108        if ( ! $current_screen ) {
     
    113116        }
    114117
    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();
    117120        } else {
    118121            $orders_screen_id = function_exists( 'wc_get_page_screen_id' ) ? wc_get_page_screen_id( 'shop-order' ) : null;
     
    120123
    121124        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 ) );
    125128    }
    126129
     
    159162     * @since 1.3.2
    160163     */
    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() ) {
    164167            // halt functionality
    165168            return;
     
    171174        } else {
    172175            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 );
    174177            add_action( 'woocommerce_before_resend_order_emails', [ $this, 'set_sequential_order_number' ] );
    175178        }
     
    179182
    180183        // 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 );
    182185
    183186        // 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' ] );
    185188
    186189        // WC Subscriptions support
    187190        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' ] );
    189192
    190193        // WooCommerce Admin support
    191194        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 );
    193196        }
    194197
     
    204207            // ensure that admin order table search by order number works
    205208            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' ] );
    207210
    208211            // 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' ] );
    211214
    212215        }
     
    216219            add_action( 'admin_init', [ $this, 'install' ] );
    217220        }
     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' ] );
    218224    }
    219225
     
    226232     * @since 1.3.3
    227233     */
    228     public function load_translation() {
     234    public function load_translation() : void {
    229235
    230236        // localization
     
    238244     * @since 1.0.0
    239245     *
    240      * @param string $order_number order number to search for
     246     * @param string|int $order_number order number to search for
    241247     * @return int $order_id for the order identified by $order_number, or 0
    242248     */
    243     public function find_order_by_order_number( $order_number ) {
     249    public function find_order_by_order_number( $order_number ) : int {
    244250
    245251        // search for the order by custom order number
    246252        if ( $this->is_hpos_enabled() ) {
    247             $orders = wc_get_orders([
     253            $orders = wc_get_orders( [
    248254                'return'     => 'ids',
    249255                'limit'      => 1,
     
    252258                        'key'        => '_order_number',
    253259                        'value'      => $order_number,
    254                         'comparison' => '='
     260                        'comparison' => '=',
    255261                    ],
    256262                ],
    257             ]);
     263            ] );
    258264        } else {
    259265            $orders = get_posts( [
     
    267273        }
    268274
    269         $order_id = $orders ? current($orders) : null;
     275        $order_id = $orders ? current( $orders ) : null;
    270276
    271277        // order was found
     
    297303     * @since 1.0.0
    298304     *
    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
    303310        global $wpdb;
    304311
    305312        $using_hpos = $this->is_hpos_enabled();
    306313
    307         if ( $object instanceof \WP_Post ) {
     314        if ( $object instanceof WP_Post ) {
    308315
    309316            $is_order     = 'shop_order' === $object->post_type;
     
    312319            $order_status = $object->post_status;
    313320
     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
    314328        } else {
    315329
    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();
    318332            $order_id     = ! $order_id && $order ? $order->get_id() : (int) $order_id;
    319333            $order_status = $order ? $order->get_status() : '';
     
    367381     * @since 1.0.0
    368382     *
    369      * @param string $order_number the order id with a leading hash
    370      * @param \WC_Order $order the order object
     383     * @param string|int $order_number the order id with a leading hash
     384     * @param WC_Order|WC_Subscription $order the order object
    371385     * @return string custom order number
    372386     */
     
    374388
    375389        // 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 ) {
    377391            return $order_number;
    378392        }
    379393
    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' ) ) {
    381395            $order_number = $sequential_order_number;
    382396        }
     
    396410     * @since 1.3
    397411     *
    398      * @param array $vars associative array of orderby parameters
    399      * @return array associative array of orderby parameters
     412     * @param array|mixed $vars associative array of orderby parameters
     413     * @return array|mixed associative array of orderby parameters
    400414     */
    401415    public function woocommerce_custom_shop_order_orderby( $vars ) {
     416
    402417        global $typenow;
    403418
     
    431446     * @return array associative array of orderby parameters
    432447     */
    433     public function custom_orderby( $args ) {
     448    public function custom_orderby( array $args ) : array {
    434449
    435450        // sorting
    436         if ( isset( $args['orderby'] ) && 'ID' == $args['orderby'] ) {
     451        if ( isset( $args['orderby'] ) && 'ID' === $args['orderby'] ) {
    437452
    438453            $args = array_merge( $args, [
     
    456471     * @return string[] of order meta fields to search by
    457472     */
    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    }
    463497
    464498    /** 3rd Party Plugin Support ******************************************************/
     
    472506     * @internal
    473507     *
    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 ) {
    481514
    482515            $order = wc_get_order( $renewal_order->get_id() );
     
    501534     *
    502535     * @param string[]|mixed $order_data
    503      * @return string[]mixed
     536     * @return string[]|mixed
    504537     */
    505538    public function subscriptions_remove_renewal_order_meta( $order_data ) {
     
    514547    }
    515548
     549
    516550    /**
    517551     * Hook WooCommerce Admin  order number search to the meta value.
     
    521555     * @internal
    522556     *
    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.
    526560     */
    527561    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
    528567        global $wpdb;
    529568
     
    533572            $number_search = trim( $request['number'] );
    534573            $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();
    538577            $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';
    540579
    541580            // Search Order number meta value instead of Post ID.
     
    552591
    553592            if ( $using_hpos ) {
    554                 $args['order__in'] = empty( $order_ids ) ? array( 0 ) : $order_ids;
     593                $args['order__in'] = empty( $order_ids ) ? [ 0 ] : $order_ids;
    555594            } else {
    556                 $args['post__in'] = empty( $order_ids ) ? array( 0 ) : $order_ids;
     595                $args['post__in'] = empty( $order_ids ) ? [ 0 ] : $order_ids;
    557596            }
    558597
     
    570609     * Main Sequential Order Numbers Instance, ensures only one instance is/can be loaded.
    571610     *
     611     * @since 1.7.0
     612     *
     613     * @return WC_Seq_Order_Number
    572614     * @see wc_sequential_order_numbers()
    573615     *
    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();
    585620    }
    586621
     
    594629     * @return boolean true if the named plugin is installed and active
    595630     */
    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', [] );
    599634
    600635        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 = [];
    605640
    606641        foreach ( $active_plugins as $plugin ) {
     
    609644
    610645                // normal plugin name (plugin-dir/plugin-filename.php)
    611                 list( , $filename ) = explode( '/', $plugin );
     646                [ , $filename ] = explode( '/', $plugin );
    612647
    613648            } else {
     
    620655        }
    621656
    622         return in_array( $plugin_name, $plugin_filenames );
     657        return in_array( $plugin_name, $plugin_filenames, true );
    623658    }
    624659
     
    634669     * @return string woocommerce version number or null
    635670     */
    636     private static function get_wc_version() {
     671    private static function get_wc_version() : ?string {
     672
    637673        return defined( 'WC_VERSION' ) && WC_VERSION ? WC_VERSION : null;
    638674    }
     
    646682     * @return bool
    647683     */
    648     private function minimum_wc_version_met() {
     684    private function minimum_wc_version_met() : bool {
    649685
    650686        $version_met = true;
    651687
     688        if ( ! $wc_version = self::get_wc_version() ) {
     689            return false;
     690        }
     691
    652692        // 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' ] );
    658698            }
    659699
     
    666706
    667707    /**
     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    /**
    668721     * Renders a notice to update WooCommerce if needed
    669722     *
     
    672725     * @since 1.3.2
    673726     */
    674     public function render_update_notices() {
     727    public function render_update_notices() : void {
    675728
    676729        $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 */
    678731            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' ),
    679732            'Sequential Order Numbers',
     
    692745
    693746    /**
    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
    695750     *
    696751     * @internal
     
    698753     * @since 1.0.0
    699754     */
    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 );
    703758
    704759        if ( ! $installed_version ) {
     
    715770                    'type'   => 'shop_order',
    716771                    'offset' => $offset,
    717                     'limit'  => $orders_par_page
     772                    'limit'  => $orders_par_page,
    718773                ] );
    719774
     
    725780                    wp_die(
    726781                        sprintf(
    727                             /** translators: Placeholder: %s - error message(s) */
     782                        /** translators: Placeholder: %s - error message(s) */
    728783                            __( 'Error activating and installing <strong>Sequential Order Numbers for WooCommerce</strong>: %s', 'woocommerce-sequential-order-numbers' ),
    729784                            '<ul><li>' . implode( '</li><li>', $orders->get_error_messages() ) . '</li></ul>'
     
    733788                } elseif ( is_array( $orders ) ) {
    734789
    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() );
    739794                            $order->save_meta_data();
    740795                        }
     
    750805        }
    751806
    752         if ( $installed_version !== WC_Seq_Order_Number::VERSION ) {
     807        if ( $installed_version !== self::VERSION ) {
    753808
    754809            $this->upgrade( $installed_version );
    755810
    756811            // 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 );
    758813        }
    759814    }
     
    767822     * @param string $installed_version
    768823     */
    769     private function upgrade( $installed_version ) {
     824    private function upgrade( string $installed_version ) : void {
    770825        // upgrade code goes here
    771826    }
     
    780835 * @since 1.7.0
    781836 *
    782  * @return \WC_Seq_Order_Number
     837 * @return WC_Seq_Order_Number
    783838 */
    784 function wc_sequential_order_numbers() {
     839function wc_sequential_order_numbers() : WC_Seq_Order_Number {
     840
    785841    return WC_Seq_Order_Number::instance();
    786842}
Note: See TracChangeset for help on using the changeset viewer.