diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 3377181..dd98403 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -61,7 +61,7 @@ "postCreateCommand": "chmod +x .devcontainer/setup.sh && .devcontainer/setup.sh", // Use 'postStartCommand' to run commands after the container has started. - "postStartCommand": "cd /app && wp plugin activate woocommerce-local-pickup-time-select", + "postStartCommand": "cd /app && wp --quiet plugin activate woocommerce-local-pickup-time-select", // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. "remoteUser": "wp_php", diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh index 6a8db08..7b49b58 100755 --- a/.devcontainer/setup.sh +++ b/.devcontainer/setup.sh @@ -44,7 +44,7 @@ fi if wp core is-installed 2>/dev/null; then echo "Activating required development plugins.." - wp plugin activate \ + wp --quiet plugin activate \ action-scheduler \ debug-bar \ debug-bar-actions-and-filters-addon \ @@ -57,8 +57,8 @@ if wp core is-installed 2>/dev/null; then wordpress-importer \ wp-mail-logging - echo "Activating required development plugins.." - wp theme activate storefront + echo "Activating required development theme.." + wp --quiet theme activate storefront fi echo "Done!" diff --git a/.github/workflows/i18n.yml b/.github/workflows/i18n.yml index c9103b6..616c004 100644 --- a/.github/workflows/i18n.yml +++ b/.github/workflows/i18n.yml @@ -10,8 +10,8 @@ on: - 'fix/**' env: + ACTION_VERSION: 3 WP_MULTISITE: 0 - ACTION_VERSION: 2 jobs: check_i18n: diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index e6d32f0..dec37a1 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -10,10 +10,10 @@ on: - 'fix/**' env: - PHP_VERSION: '7.4' + ACTION_VERSION: 3 + PHP_VERSION: '8.1' + COMPOSER_VERSION: '2.5' WP_MULTISITE: 0 - COMPOSER_VERSION: '2.2' - ACTION_VERSION: 2 jobs: check_linting: diff --git a/.github/workflows/pr-unit-testing.yml b/.github/workflows/pr-unit-testing.yml index 5593408..2d37225 100644 --- a/.github/workflows/pr-unit-testing.yml +++ b/.github/workflows/pr-unit-testing.yml @@ -7,12 +7,12 @@ on: pull_request: env: - PHP_VERSION: '7.4' - WP_VERSION: '5.9.*' + ACTION_VERSION: 4 + PHP_VERSION: '8.1' + COMPOSER_VERSION: '2.5' + WP_VERSION: '6.5.*' WP_MULTISITE: 0 - WC_VERSION: '6.4.*' - COMPOSER_VERSION: '2.2' - ACTION_VERSION: 3 + WC_VERSION: '8.7.*' jobs: pr_unit_testing: @@ -41,13 +41,6 @@ jobs: restore-keys: | ${{ runner.os }}-build-${{ env.composer-cache-name }}-wp-${{ env.WP_VERSION }}-wc-${{ env.WC_VERSION }}-v${{ env.ACTION_VERSION }}- - - name: Setup Node Environment - # https://github.com/marketplace/actions/setup-node-js-environment - uses: actions/setup-node@v2 - with: - node-version-file: '.nvmrc' - cache: ${{ !env.ACT && 'npm' || '' }} - - name: Setup PHP & Composer Environment # https://github.com/marketplace/actions/setup-php-action uses: shivammathur/setup-php@v2 @@ -64,8 +57,5 @@ jobs: - name: Install Composer Dependencies run: composer install --prefer-dist - - name: NPM Setup - run: npm ci - - name: Unit Tests - run: npm run test + run: composer test diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5a5b4ac..39051b8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,8 +5,8 @@ on: types: [published] env: + ACTION_VERSION: 3 WP_MULTISITE: 0 - ACTION_VERSION: 2 jobs: release: @@ -21,10 +21,11 @@ jobs: uses: actions/checkout@v2 - name: Setup Node Environment - uses: actions/setup-node@v1 # https://github.com/marketplace/actions/setup-node-js-environment + uses: actions/setup-node@v2 with: - node-version: 14.x + node-version-file: '.nvmrc' + cache: ${{ !env.ACT && 'npm' || '' }} - name: Get NPM Cache Directory id: npm-cache diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 12ab5c1..66fe9f9 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -10,10 +10,10 @@ on: - 'fix/**' env: - PHP_VERSION: '7.4' + ACTION_VERSION: 3 + PHP_VERSION: '8.1' + COMPOSER_VERSION: '2.5' WP_MULTISITE: 0 - COMPOSER_VERSION: '2.2' - ACTION_VERSION: 2 jobs: check_static_analysis: @@ -57,4 +57,4 @@ jobs: run: composer install - name: Perform Static Analysis - run: composer run-script analyze + run: composer analyze diff --git a/.github/workflows/unit-testing.yml b/.github/workflows/unit-testing.yml index 245e928..ffe7602 100644 --- a/.github/workflows/unit-testing.yml +++ b/.github/workflows/unit-testing.yml @@ -9,8 +9,8 @@ on: - 'release/**' env: - COMPOSER_VERSION: '2.2' - ACTION_VERSION: 3 + ACTION_VERSION: 4 + COMPOSER_VERSION: '2.5' jobs: matrix_unit_testing: @@ -21,24 +21,24 @@ jobs: fail-fast: false matrix: job-name: ['Unit Test'] - php-version: ['7.4','8.0'] - wordpress-version: ['5.7.*','5.8.*','5.9.*'] - woocommerce-version: ['4.*','5.0.*','5.*','6.0.*','6.4.*'] + php-version: ['7.4','8.0','8.1'] + wordpress-version: ['5.9.*','6.4.*','6.5.*'] + woocommerce-version: ['4.*','5.*','6.*','7.*','8.*'] wp-multisite-mode: [0] bleeding-edge: [false] include: - job-name: 'Unit Test Bleeding Edge Requirements' bleeding-edge: true - php-version: '8.1' + php-version: '8.3' wordpress-version: 'dev-master' wp-multisite-mode: 0 woocommerce-version: 'dev-trunk' - job-name: 'Unit Test Multisite Compatibility Requirements' bleeding-edge: false - php-version: '8.0' - wordpress-version: '5.9.*' + php-version: '8.1' + wordpress-version: '6.5.*' wp-multisite-mode: 1 - woocommerce-version: '6.4.*' + woocommerce-version: '8.7.*' name: '${{ matrix.job-name }} (PHP:${{ matrix.php-version }}/WP:${{ matrix.wordpress-version }}/WC:${{ matrix.woocommerce-version }})' @@ -63,13 +63,6 @@ jobs: restore-keys: | ${{ runner.os }}-build-${{ env.composer-cache-name }}-wp-${{ matrix.wordpress-version }}-wc-${{ matrix.woocommerce-version }}-v${{ env.ACTION_VERSION }}- - - name: Setup Node Environment - # https://github.com/marketplace/actions/setup-node-js-environment - uses: actions/setup-node@v2 - with: - node-version-file: '.nvmrc' - cache: ${{ !env.ACT && 'npm' || '' }} - - name: Setup PHP & Composer Environment # https://github.com/marketplace/actions/setup-php-action uses: shivammathur/setup-php@v2 @@ -110,10 +103,7 @@ jobs: if: matrix.php-version != '8.0' && matrix.php-version != '8.1' run: composer install --prefer-dist - - name: NPM Setup - run: npm ci - - name: Unit Tests env: WP_MULTISITE: ${{ matrix.wp-multisite-mode }} - run: npm run test + run: composer test diff --git a/admin/class-local-pickup-time-admin.php b/admin/class-local-pickup-time-admin.php index 5a6ee02..4a519e1 100644 --- a/admin/class-local-pickup-time-admin.php +++ b/admin/class-local-pickup-time-admin.php @@ -68,8 +68,8 @@ private function __construct() { add_action( 'init', array( $this, 'register_post_status' ) ); add_filter( 'wc_order_statuses', array( $this, 'wc_order_statuses' ), 10, 1 ); add_filter( 'bulk_actions-edit-shop_order', array( $this, 'add_bulk_actions_edit_shop_order' ), 50, 1 ); - add_action( 'woocommerce_email_actions', array( $this, 'woocommerce_email_actions' ) ); - add_action( 'woocommerce_email_classes', array( $this, 'woocommerce_email_classes' ) ); + add_filter( 'woocommerce_email_actions', array( $this, 'woocommerce_email_actions' ) ); + add_filter( 'woocommerce_email_classes', array( $this, 'woocommerce_email_classes' ) ); /* * Show Pickup Time in the Order Details in the Admin Screen @@ -82,9 +82,8 @@ private function __construct() { */ add_filter( 'manage_edit-shop_order_columns', array( $this, 'add_orders_list_pickup_date_column_header' ) ); add_action( 'manage_shop_order_posts_custom_column', array( $this, 'add_orders_list_pickup_date_column_content' ) ); - add_action( 'manage_edit-shop_order_sortable_columns', array( $this, 'add_orders_list_pickup_date_column_sorting' ) ); - add_action( 'pre_get_posts', array( $this, 'filter_orders_list_by_pickup_date' ) ); - + add_filter( 'manage_edit-shop_order_sortable_columns', array( $this, 'add_orders_list_pickup_date_column_sorting' ) ); + add_filter( 'pre_get_posts', array( $this, 'filter_orders_list_by_pickup_date' ) ); } /** @@ -122,7 +121,6 @@ public function plugin_action_links( $actions ) { array_unshift( $actions, $settings_link ); return $actions; - } /** @@ -141,7 +139,6 @@ public function plugin_add_settings_section( $sections ) { $sections[ $this->plugin->get_plugin_slug() ] = __( 'Local Pickup Time settings', 'woocommerce-local-pickup-time-select' ); return $sections; - } /** @@ -424,7 +421,6 @@ public function plugin_settings( $settings, $current_section ) { } return $settings; - } /** @@ -447,7 +443,6 @@ public function shipping_methods_settings_override( $shipping_methods ) { } return $shipping_methods; - } /** @@ -472,7 +467,6 @@ public function shipping_instance_form_add_extra_fields( $fields ) { ); return $fields; - } /** @@ -496,7 +490,6 @@ public function shipping_method_add_rate_pickup_time_args( $args, $shipping_meth } return $args; - } /** @@ -535,7 +528,6 @@ public function wc_order_statuses( $order_statuses ) { $order_statuses['wc-ready-for-pickup'] = _x( 'Ready for Pickup', 'Order status', 'woocommerce-local-pickup-time-select' ); return $order_statuses; - } /** @@ -552,7 +544,6 @@ public function add_bulk_actions_edit_shop_order( $actions ) { $actions['mark_ready-for-pickup'] = __( 'Change status to ready for pickup', 'woocommerce-local-pickup-time-select' ); return $actions; - } /** @@ -569,7 +560,6 @@ public function woocommerce_email_actions( $email_actions ) { $email_actions[] = 'woocommerce_order_status_ready-for-pickup'; return $email_actions; - } /** @@ -586,7 +576,6 @@ public function woocommerce_email_classes( $email_classes ) { $email_classes['WC_Email_Customer_Ready_For_Pickup_Order'] = include __DIR__ . '/emails/class-wc-email-customer-ready-for-pickup-order.php'; return $email_classes; - } /** @@ -601,7 +590,10 @@ public function woocommerce_email_classes( $email_classes ) { public function show_metabox( $order ) { $order_meta = get_post_custom( $order->get_id() ); - $pickup_time = $order_meta[ $this->plugin->get_order_meta_key() ][0]; + $pickup_time = ''; + if ( is_array( $order_meta ) ) { + $pickup_time = $order_meta[ $this->plugin->get_order_meta_key() ][0]; + } $allowed_html = array( 'p' => array(), @@ -609,7 +601,6 @@ public function show_metabox( $order ) { ); echo wp_kses( '

' . __( 'Pickup Time:', 'woocommerce-local-pickup-time-select' ) . ' ' . esc_html( $this->pickup_time_select_translatable( $pickup_time ) ) . '

', $allowed_html ); - } /** @@ -634,7 +625,6 @@ public function add_orders_list_pickup_date_column_header( $columns ) { } return $new_columns; - } /** @@ -653,7 +643,6 @@ public function add_orders_list_pickup_date_column_content( $column ) { if ( $this->plugin->get_order_meta_key() === $column ) { echo esc_html( $this->pickup_time_select_translatable( $the_order->get_meta( $this->plugin->get_order_meta_key() ) ) ); } - } /** @@ -670,7 +659,6 @@ public function add_orders_list_pickup_date_column_sorting( $columns ) { $new_columns[ $this->plugin->get_order_meta_key() ] = 'pickup_time'; return wp_parse_args( $new_columns, $columns ); - } /** @@ -691,7 +679,6 @@ public function filter_orders_list_by_pickup_date( $query ) { } return $query; - } /** @@ -705,7 +692,6 @@ public function filter_orders_list_by_pickup_date( $query ) { public function woocommerce_admin_order_preview_get_order_details( $order_details ) { return $order_details; - } /** @@ -723,7 +709,5 @@ public function pickup_time_select_translatable( $value ) { // Call the Public plugin instance of this method to reduce code redundancy. return $plugin->pickup_time_select_translatable( $value ); - } - } diff --git a/admin/emails/class-wc-email-customer-ready-for-pickup-order.php b/admin/emails/class-wc-email-customer-ready-for-pickup-order.php index 978fc62..0eef819 100644 --- a/admin/emails/class-wc-email-customer-ready-for-pickup-order.php +++ b/admin/emails/class-wc-email-customer-ready-for-pickup-order.php @@ -47,28 +47,26 @@ public function __construct() { /** * Trigger the sending of this email. * - * @param int $order_id The order ID. - * @param object|WC_Order|string $order Order object. + * @param int $order_id The order ID. + * @param object|WC_Order|null $order Order object. * * @return void */ - public function trigger( $order_id, $order = '' ) { + public function trigger( $order_id, $order = null ) { $this->setup_locale(); - if ( $order_id && ! is_a( $order, 'WC_Order' ) ) { + if ( ! empty( $order_id ) && empty( $order ) ) { $order = wc_get_order( $order_id ); } - /* @phpstan-ignore-next-line */ - if ( is_a( $order, 'WC_Order' ) ) { + if ( ! empty( $order ) && is_object( $order ) && is_a( $order, 'WC_Order' ) ) { $this->object = $order; $this->recipient = $this->object->get_billing_email(); - /* @phpstan-ignore-next-line */ - $this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() ); + $this->placeholders['{order_date}'] = ! empty( $this->object->get_date_created() ) ? wc_format_datetime( $this->object->get_date_created() ) : 'Unknown'; $this->placeholders['{order_number}'] = $this->object->get_order_number(); } - if ( $this->is_enabled() && $this->get_recipient() ) { + if ( is_object( $order ) && $this->is_enabled() && $this->get_recipient() ) { $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() ); } diff --git a/composer.json b/composer.json index 7dea874..a129049 100644 --- a/composer.json +++ b/composer.json @@ -49,37 +49,36 @@ }, "require-dev": { "php": ">=7.4", - "brain/monkey": "^2.6", - "dealerdirect/phpcodesniffer-composer-installer": "^1.0", - "johnpbloch/wordpress-core": "~6.2.0", - "johnpbloch/wordpress-core-installer": "^2.0", - "mockery/mockery": "^1.5", - "php-stubs/woocommerce-stubs": "~6.5.0", - "php-stubs/wordpress-stubs": "~6.2.0", - "phpro/grumphp": "^1.16", - "phpstan/extension-installer": "^1.3", - "phpstan/phpstan": "^1.10", - "phpstan/phpstan-deprecation-rules": "^1.1", - "phpunit/phpunit": "^9.6.0", - "roave/security-advisories": "dev-master", - "squizlabs/php_codesniffer": "^3.7", - "szepeviktor/phpstan-wordpress": "^1.3", + "brain/monkey": "^2.6", + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", + "johnpbloch/wordpress-core": "~6.5.0", + "johnpbloch/wordpress-core-installer": "^2.0", + "mockery/mockery": "^1.5", + "php-stubs/woocommerce-stubs": "~8.7.0", + "php-stubs/wordpress-stubs": "~6.5.0", + "phpro/grumphp": "^1.16", + "phpstan/extension-installer": "^1.3", + "phpstan/phpstan": "^1.10", + "phpstan/phpstan-deprecation-rules": "^1.1", + "phpunit/phpunit": "^9.6.0", + "roave/security-advisories": "dev-master", + "squizlabs/php_codesniffer": "^3.7", + "szepeviktor/phpstan-wordpress": "^1.3", "woocommerce/action-scheduler": "^3.5.0", - "woocommerce/woocommerce-sniffs": "^1.0.0", - "wp-coding-standards/wpcs": "^3.0.0", - "wp-phpunit/wp-phpunit": "~6.2.0", - "wpackagist-plugin/debug-bar": "*", - "wpackagist-plugin/debug-bar-actions-and-filters-addon": "*", - "wpackagist-plugin/display-environment-type": "*", - "wpackagist-plugin/health-check": "*", - "wpackagist-plugin/query-monitor": "*", - "wpackagist-plugin/transients-manager": "*", - "wpackagist-plugin/woo-order-test": "*", - "wpackagist-plugin/woocommerce": "~6.5.0", + "wp-coding-standards/wpcs": "^3.0.0", + "wp-phpunit/wp-phpunit": "~6.5.0", + "wpackagist-plugin/debug-bar": "*", + "wpackagist-plugin/debug-bar-actions-and-filters-addon": "*", + "wpackagist-plugin/display-environment-type": "*", + "wpackagist-plugin/health-check": "*", + "wpackagist-plugin/query-monitor": "*", + "wpackagist-plugin/transients-manager": "*", + "wpackagist-plugin/woo-order-test": "*", + "wpackagist-plugin/woocommerce": "~8.7.0", "wpackagist-plugin/wordpress-importer": "*", "wpackagist-plugin/wp-mail-logging": "*", - "wpackagist-theme/storefront": "*", - "yoast/phpunit-polyfills": "^2.0" + "wpackagist-theme/storefront": "*", + "yoast/phpunit-polyfills": "^2.0" }, "autoload": { "classmap": [ diff --git a/composer.lock b/composer.lock index 4f162d9..f158724 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4086a06c6f1a576c14fee1940e4a7118", + "content-hash": "3f5bfc58edce73e7a77dfa65487e5a14", "packages": [ { "name": "composer/installers", @@ -1211,24 +1211,24 @@ }, { "name": "johnpbloch/wordpress-core", - "version": "6.2.5", + "version": "6.5.2", "source": { "type": "git", "url": "https://github.com/johnpbloch/wordpress-core.git", - "reference": "9bc1c0ae593883f474021291b8b10b693e3fc153" + "reference": "bf083fe2944a4683461d496086ec22319cd8bdf1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/johnpbloch/wordpress-core/zipball/9bc1c0ae593883f474021291b8b10b693e3fc153", - "reference": "9bc1c0ae593883f474021291b8b10b693e3fc153", + "url": "https://api.github.com/repos/johnpbloch/wordpress-core/zipball/bf083fe2944a4683461d496086ec22319cd8bdf1", + "reference": "bf083fe2944a4683461d496086ec22319cd8bdf1", "shasum": "" }, "require": { "ext-json": "*", - "php": ">=5.6.20" + "php": ">=7.0.0" }, "provide": { - "wordpress/core-implementation": "6.2.5" + "wordpress/core-implementation": "6.5.2" }, "type": "wordpress-core", "notification-url": "https://packagist.org/downloads/", @@ -1255,7 +1255,7 @@ "source": "https://core.trac.wordpress.org/browser", "wiki": "https://codex.wordpress.org/" }, - "time": "2024-04-09T21:31:01+00:00" + "time": "2024-04-09T21:20:55+00:00" }, { "name": "johnpbloch/wordpress-core-installer", @@ -1871,16 +1871,16 @@ }, { "name": "php-stubs/woocommerce-stubs", - "version": "v6.5.1", + "version": "v8.7.0", "source": { "type": "git", "url": "https://github.com/php-stubs/woocommerce-stubs.git", - "reference": "1474a66c59695acf9f8e6bd16ed626930c4eaa03" + "reference": "1bab3a764a91ed037f420dc38124e2516b29e6b8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-stubs/woocommerce-stubs/zipball/1474a66c59695acf9f8e6bd16ed626930c4eaa03", - "reference": "1474a66c59695acf9f8e6bd16ed626930c4eaa03", + "url": "https://api.github.com/repos/php-stubs/woocommerce-stubs/zipball/1bab3a764a91ed037f420dc38124e2516b29e6b8", + "reference": "1bab3a764a91ed037f420dc38124e2516b29e6b8", "shasum": "" }, "require": { @@ -1909,35 +1909,37 @@ ], "support": { "issues": "https://github.com/php-stubs/woocommerce-stubs/issues", - "source": "https://github.com/php-stubs/woocommerce-stubs/tree/v6.5.1" + "source": "https://github.com/php-stubs/woocommerce-stubs/tree/v8.7.0" }, - "time": "2022-09-14T01:17:16+00:00" + "time": "2024-03-19T16:55:16+00:00" }, { "name": "php-stubs/wordpress-stubs", - "version": "v6.2.1", + "version": "v6.5.2", "source": { "type": "git", "url": "https://github.com/php-stubs/wordpress-stubs.git", - "reference": "0009429e639b748eef1c955200ea0d4e5ad5627d" + "reference": "379f17a90c01498d4c99a0d15aab6e7aa6a2c840" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-stubs/wordpress-stubs/zipball/0009429e639b748eef1c955200ea0d4e5ad5627d", - "reference": "0009429e639b748eef1c955200ea0d4e5ad5627d", + "url": "https://api.github.com/repos/php-stubs/wordpress-stubs/zipball/379f17a90c01498d4c99a0d15aab6e7aa6a2c840", + "reference": "379f17a90c01498d4c99a0d15aab6e7aa6a2c840", "shasum": "" }, "require-dev": { - "nikic/php-parser": "< 4.12.0", - "php": "~7.3 || ~8.0", + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", + "nikic/php-parser": "^4.13", + "php": "^7.4 || ~8.0.0", "php-stubs/generator": "^0.8.3", - "phpdocumentor/reflection-docblock": "^5.3", - "phpstan/phpstan": "^1.10.12", - "phpunit/phpunit": "^9.5" + "phpdocumentor/reflection-docblock": "5.3", + "phpstan/phpstan": "^1.10.49", + "phpunit/phpunit": "^9.5", + "szepeviktor/phpcs-psr-12-neutron-hybrid-ruleset": "^0.11" }, "suggest": { "paragonie/sodium_compat": "Pure PHP implementation of libsodium", - "symfony/polyfill-php73": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", + "symfony/polyfill-php80": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", "szepeviktor/phpstan-wordpress": "WordPress extensions for PHPStan" }, "type": "library", @@ -1954,183 +1956,9 @@ ], "support": { "issues": "https://github.com/php-stubs/wordpress-stubs/issues", - "source": "https://github.com/php-stubs/wordpress-stubs/tree/v6.2.1" + "source": "https://github.com/php-stubs/wordpress-stubs/tree/v6.5.2" }, - "time": "2023-05-18T04:35:23+00:00" - }, - { - "name": "phpcompatibility/php-compatibility", - "version": "9.3.5", - "source": { - "type": "git", - "url": "https://github.com/PHPCompatibility/PHPCompatibility.git", - "reference": "9fb324479acf6f39452e0655d2429cc0d3914243" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibility/zipball/9fb324479acf6f39452e0655d2429cc0d3914243", - "reference": "9fb324479acf6f39452e0655d2429cc0d3914243", - "shasum": "" - }, - "require": { - "php": ">=5.3", - "squizlabs/php_codesniffer": "^2.3 || ^3.0.2" - }, - "conflict": { - "squizlabs/php_codesniffer": "2.6.2" - }, - "require-dev": { - "phpunit/phpunit": "~4.5 || ^5.0 || ^6.0 || ^7.0" - }, - "suggest": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically.", - "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." - }, - "type": "phpcodesniffer-standard", - "notification-url": "https://packagist.org/downloads/", - "license": [ - "LGPL-3.0-or-later" - ], - "authors": [ - { - "name": "Wim Godden", - "homepage": "https://github.com/wimg", - "role": "lead" - }, - { - "name": "Juliette Reinders Folmer", - "homepage": "https://github.com/jrfnl", - "role": "lead" - }, - { - "name": "Contributors", - "homepage": "https://github.com/PHPCompatibility/PHPCompatibility/graphs/contributors" - } - ], - "description": "A set of sniffs for PHP_CodeSniffer that checks for PHP cross-version compatibility.", - "homepage": "http://techblog.wimgodden.be/tag/codesniffer/", - "keywords": [ - "compatibility", - "phpcs", - "standards" - ], - "support": { - "issues": "https://github.com/PHPCompatibility/PHPCompatibility/issues", - "source": "https://github.com/PHPCompatibility/PHPCompatibility" - }, - "time": "2019-12-27T09:44:58+00:00" - }, - { - "name": "phpcompatibility/phpcompatibility-paragonie", - "version": "1.3.2", - "source": { - "type": "git", - "url": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie.git", - "reference": "bba5a9dfec7fcfbd679cfaf611d86b4d3759da26" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityParagonie/zipball/bba5a9dfec7fcfbd679cfaf611d86b4d3759da26", - "reference": "bba5a9dfec7fcfbd679cfaf611d86b4d3759da26", - "shasum": "" - }, - "require": { - "phpcompatibility/php-compatibility": "^9.0" - }, - "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.7", - "paragonie/random_compat": "dev-master", - "paragonie/sodium_compat": "dev-master" - }, - "suggest": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", - "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." - }, - "type": "phpcodesniffer-standard", - "notification-url": "https://packagist.org/downloads/", - "license": [ - "LGPL-3.0-or-later" - ], - "authors": [ - { - "name": "Wim Godden", - "role": "lead" - }, - { - "name": "Juliette Reinders Folmer", - "role": "lead" - } - ], - "description": "A set of rulesets for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by the Paragonie polyfill libraries.", - "homepage": "http://phpcompatibility.com/", - "keywords": [ - "compatibility", - "paragonie", - "phpcs", - "polyfill", - "standards", - "static analysis" - ], - "support": { - "issues": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie/issues", - "source": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie" - }, - "time": "2022-10-25T01:46:02+00:00" - }, - { - "name": "phpcompatibility/phpcompatibility-wp", - "version": "2.1.4", - "source": { - "type": "git", - "url": "https://github.com/PHPCompatibility/PHPCompatibilityWP.git", - "reference": "b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityWP/zipball/b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5", - "reference": "b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5", - "shasum": "" - }, - "require": { - "phpcompatibility/php-compatibility": "^9.0", - "phpcompatibility/phpcompatibility-paragonie": "^1.0" - }, - "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.7" - }, - "suggest": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", - "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." - }, - "type": "phpcodesniffer-standard", - "notification-url": "https://packagist.org/downloads/", - "license": [ - "LGPL-3.0-or-later" - ], - "authors": [ - { - "name": "Wim Godden", - "role": "lead" - }, - { - "name": "Juliette Reinders Folmer", - "role": "lead" - } - ], - "description": "A ruleset for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by WordPress.", - "homepage": "http://phpcompatibility.com/", - "keywords": [ - "compatibility", - "phpcs", - "standards", - "static analysis", - "wordpress" - ], - "support": { - "issues": "https://github.com/PHPCompatibility/PHPCompatibilityWP/issues", - "source": "https://github.com/PHPCompatibility/PHPCompatibilityWP" - }, - "time": "2022-10-24T09:00:36+00:00" + "time": "2024-04-14T17:30:14+00:00" }, { "name": "phpcsstandards/phpcsextra", @@ -6770,45 +6598,6 @@ }, "time": "2024-04-05T14:42:07+00:00" }, - { - "name": "woocommerce/woocommerce-sniffs", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/woocommerce/woocommerce-sniffs.git", - "reference": "3a65b917ff5ab5e65609e5dcb7bc62f9455bbef8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/woocommerce/woocommerce-sniffs/zipball/3a65b917ff5ab5e65609e5dcb7bc62f9455bbef8", - "reference": "3a65b917ff5ab5e65609e5dcb7bc62f9455bbef8", - "shasum": "" - }, - "require": { - "dealerdirect/phpcodesniffer-composer-installer": "^1.0.0", - "php": ">=7.0", - "phpcompatibility/phpcompatibility-wp": "^2.1.0", - "wp-coding-standards/wpcs": "^3.0.0" - }, - "type": "phpcodesniffer-standard", - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "WooCommerce sniffs", - "keywords": [ - "phpcs", - "standards", - "static analysis", - "woocommerce", - "wordpress" - ], - "support": { - "issues": "https://github.com/woocommerce/woocommerce-sniffs/issues", - "source": "https://github.com/woocommerce/woocommerce-sniffs/tree/1.0.0" - }, - "time": "2023-09-29T13:52:33+00:00" - }, { "name": "wp-coding-standards/wpcs", "version": "3.1.0", @@ -6877,16 +6666,16 @@ }, { "name": "wp-phpunit/wp-phpunit", - "version": "6.2.5", + "version": "6.5.2", "source": { "type": "git", "url": "https://github.com/wp-phpunit/wp-phpunit.git", - "reference": "3b7ab767dde017dec9327cc024e9f26fd776a57b" + "reference": "4368fd1dd37d0314cbaa9040be39d835616aeb17" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/wp-phpunit/wp-phpunit/zipball/3b7ab767dde017dec9327cc024e9f26fd776a57b", - "reference": "3b7ab767dde017dec9327cc024e9f26fd776a57b", + "url": "https://api.github.com/repos/wp-phpunit/wp-phpunit/zipball/4368fd1dd37d0314cbaa9040be39d835616aeb17", + "reference": "4368fd1dd37d0314cbaa9040be39d835616aeb17", "shasum": "" }, "type": "library", @@ -6921,7 +6710,7 @@ "issues": "https://github.com/wp-phpunit/issues", "source": "https://github.com/wp-phpunit/wp-phpunit" }, - "time": "2023-03-30T01:15:51+00:00" + "time": "2024-04-03T00:33:03+00:00" }, { "name": "wpackagist-plugin/debug-bar", @@ -7051,15 +6840,15 @@ }, { "name": "wpackagist-plugin/woocommerce", - "version": "6.5.1", + "version": "8.7.0", "source": { "type": "svn", "url": "https://plugins.svn.wordpress.org/woocommerce/", - "reference": "tags/6.5.1" + "reference": "tags/8.7.0" }, "dist": { "type": "zip", - "url": "https://downloads.wordpress.org/plugin/woocommerce.6.5.1.zip" + "url": "https://downloads.wordpress.org/plugin/woocommerce.8.7.0.zip" }, "require": { "composer/installers": "^1.0 || ^2.0" diff --git a/grumphp.yml.dist b/grumphp.yml.dist index c089868..7c0108b 100644 --- a/grumphp.yml.dist +++ b/grumphp.yml.dist @@ -27,8 +27,8 @@ grumphp: git_commit_message: allow_empty_message: false enforce_capitalized_subject: false - max_body_width: 160 - max_subject_width: 120 + max_body_width: 160 + max_subject_width: 120 phpcs: standard: './phpcs.xml.dist' report: 'summary' diff --git a/languages/index.php b/languages/index.php index 324e337..187c386 100755 --- a/languages/index.php +++ b/languages/index.php @@ -6,4 +6,3 @@ */ // Last line. - diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 8ec4206..43a87ee 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -22,7 +22,7 @@ --> - + @@ -33,7 +33,10 @@ - + + + + @@ -41,10 +44,8 @@ */dist/* */node_modules/* - */tests/* */tools/* */vendor/* - */wordpress/* - + - + @@ -88,11 +89,11 @@ - + - + - + diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 2ee4287..b1b8daf 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,45 +1,33 @@ -#$ composer update --optimize-autoloader -#$ vendor/bin/phpstan analyze - -includes: - # @see https://github.com/phpstan/phpstan-src/blob/master/conf/bleedingEdge.neon - - phar://phpstan.phar/conf/bleedingEdge.neon - # Include this extension - # - vendor/szepeviktor/phpstan-wordpress/extension.neon parameters: level: max inferPrivatePropertyTypeFromConstructor: true reportUnmatchedIgnoredErrors: false + bootstrapFiles: - tests/phpstan-bootstrap.php - %rootDir%/../../php-stubs/wordpress-stubs/wordpress-stubs.php - %rootDir%/../../php-stubs/woocommerce-stubs/woocommerce-stubs.php - # autoload_files: - # Missing constants, function and class stubs - # - tests/phpstan/bootstrap.php - # Plugin stubs - # - tests/phpstan/PLUGIN-stubs.php - # Procedural code - # - myplugin-functions.php - # autoload_directories: - # - inc/ + paths: + - ./ - admin/ - public/ - - ./ + excludePaths: analyse: - node_modules/ - scripts/ - tests/ - - tools/ - vendor/ - - wordpress/ analyseAndScan: - - wordpress/wp-content/uploads/ + - tools/ + + dynamicConstantNames: + - DOING_AJAX + ignoreErrors: # Uses func_get_args() - - '#^Function apply_filters(_ref_array)? invoked with [34567] parameters, 2 required\.$#' + # - '#^Function apply_filters(_ref_array)? invoked with [34567] parameters, 2 required\.$#' # Fixed in WordPress 5.3 # - '#^Function do_action(_ref_array)? invoked with [3456] parameters, 1-2 required\.$#' # - '#^Function current_user_can invoked with 2 parameters, 1 required\.$#' diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 76f4eeb..253ea48 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,6 +1,6 @@ - + diff --git a/public/class-local-pickup-time.php b/public/class-local-pickup-time.php index 085223b..e9b2cf1 100644 --- a/public/class-local-pickup-time.php +++ b/public/class-local-pickup-time.php @@ -166,18 +166,18 @@ class Local_Pickup_Time { private function __construct() { // Load WordPress date/time formats. - $this->date_format = strval( get_option( 'date_format', $this->date_format ) ); - $this->time_format = strval( get_option( 'time_format', $this->time_format ) ); - $this->gmt_offset = intval( get_option( 'gmt_offset', $this->gmt_offset ) ); - $this->timezone = strval( get_option( 'timezone_string', $this->timezone ) ); - $this->checkout_time_req = strval( get_option( 'checkout_time_req', $this->checkout_time_req ) ); - $this->local_pickup_only = strval( get_option( 'local_pickup_only', $this->local_pickup_only ) ); + $this->date_format = strval( $this->get_value( 'option', 'date_format', $this->date_format ) ); + $this->time_format = strval( $this->get_value( 'option', 'time_format', $this->time_format ) ); + $this->gmt_offset = intval( $this->get_value( 'option', 'gmt_offset', $this->gmt_offset ) ); + $this->timezone = strval( $this->get_value( 'option', 'timezone_string', $this->timezone ) ); + $this->checkout_time_req = strval( $this->get_value( 'option', 'checkout_time_req', $this->checkout_time_req ) ); + $this->local_pickup_only = strval( $this->get_value( 'option', 'local_pickup_only', $this->local_pickup_only ) ); // Make sure we have a time zone set. if ( empty( $this->timezone ) ) { $tz_name = timezone_name_from_abbr( '', $this->get_gmt_offset() * 3600, 1 ) ? timezone_name_from_abbr( '', $this->get_gmt_offset() * 3600, 1 ) : timezone_name_from_abbr( '', $this->get_gmt_offset() * 3600, 0 ); - $this->timezone = ( ! empty( $tz_name ) ) ? (string) $tz_name : $this->timezone; + $this->timezone = ( ! empty( $tz_name ) ) ? strval( $tz_name ) : $this->timezone; } @@ -208,7 +208,48 @@ private function __construct() { // Add local pickup time field to order emails. add_filter( 'woocommerce_email_order_meta_fields', array( $this, 'update_order_email_fields' ), 10, 3 ); + } + /** + * Return non-mixed option value. + * + * @link https://developer.wordpress.org/reference/functions/get_option/ + * @link https://woocommerce.github.io/code-reference/namespaces/default.html#function_wc_get_post_data_by_key + * @link https://developer.wordpress.org/reference/functions/get_post_meta/ + * + * @param string $type The type of data to retrieve (e.g. option|post_data_by_key|post_meta). + * @param string $key Name of the key to retrieve. + * @param string|int $default_value Default value to return if the option does not exist. + * @param int $post_id The ID of the post (Default 0). + * @param bool $single Flag that indicates whether to return a single value. + * + * @return bool|float|int|resource|string|null + */ + private function get_value( string $type, string $key, string|int $default_value = '', int $post_id = 0, bool $single = false ) { + switch ( $type ) { + case 'option': + $value = get_option( $key, $default_value ); + break; + case 'post_data_by_key': + $value = wc_get_post_data_by_key( $key, strval( $default_value ) ); + break; + case 'post_meta': + $value = get_post_meta( $post_id, $key, $single ); + break; + default: + return null; + } + + switch ( true ) { + case is_bool( $value ): + case is_float( $value ): + case is_int( $value ): + case is_resource( $value ): + case is_string( $value ): + return $value; + default: + return null; + } } /** @@ -221,7 +262,6 @@ private function __construct() { public function get_plugin_slug() { return $this->plugin_slug; - } /** @@ -251,7 +291,6 @@ public static function get_instance() { public function get_date_format() { return $this->date_format; - } /** @@ -264,7 +303,6 @@ public function get_date_format() { public function get_time_format() { return $this->time_format; - } /** @@ -277,7 +315,6 @@ public function get_time_format() { public function get_gmt_offset() { return $this->gmt_offset; - } /** @@ -290,7 +327,6 @@ public function get_gmt_offset() { public function get_timezone() { return $this->timezone; - } /** @@ -303,7 +339,6 @@ public function get_timezone() { public function get_wp_timezone() { return $this->wp_timezone; - } /** @@ -316,7 +351,6 @@ public function get_wp_timezone() { public function get_checkout_time_required() { return $this->checkout_time_req; - } /** @@ -329,7 +363,6 @@ public function get_checkout_time_required() { public function get_local_pickup_only() { return $this->local_pickup_only; - } /** Return the plugin checkout pickup time legacy display flag. @@ -341,7 +374,6 @@ public function get_local_pickup_only() { public function get_is_legacy_local_pickup_display() { return $this->is_legacy_local_pickup_display; - } /** @@ -354,7 +386,6 @@ public function get_is_legacy_local_pickup_display() { public function get_order_meta_key() { return $this->order_meta_key; - } /** @@ -367,7 +398,6 @@ public function get_order_meta_key() { public function get_order_post_key() { return $this->order_post_key; - } /** @@ -380,7 +410,6 @@ public function get_order_post_key() { public function get_order_pickup_time_nonce_key() { return $this->order_pickup_time_nonce_key; - } /** @@ -394,7 +423,6 @@ public function get_order_pickup_time_nonce_key() { public function get_order_pickup_time_action_key() { return $this->order_pickup_time_action_key; - } /** @@ -432,7 +460,6 @@ public static function activate( $network_wide ) { } else { self::single_activate(); } - } /** @@ -471,7 +498,6 @@ public static function deactivate( $network_wide ) { } else { self::single_deactivate(); } - } /** @@ -492,7 +518,6 @@ public function activate_new_site( $blog_id ) { switch_to_blog( $blog_id ); self::single_activate(); restore_current_blog(); - } /** @@ -515,7 +540,6 @@ private static function get_blog_ids() { WHERE archived = '0' AND spam = '0' AND deleted = '0'" ); - } /** @@ -531,7 +555,6 @@ private static function single_activate() { if ( ! self::plugin_version_check() ) { update_option( self::DB_VERSION_META_KEY, self::VERSION, true ); } - } /** @@ -558,8 +581,7 @@ public function load_plugin_textdomain() { $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '/' . $domain . '-' . $locale . '.mo' ); - load_plugin_textdomain( $domain, false, basename( plugin_dir_path( dirname( __FILE__ ) ) ) . '/languages/' ); - + load_plugin_textdomain( $domain, false, basename( plugin_dir_path( __DIR__ ) ) . '/languages/' ); } /** @@ -570,9 +592,7 @@ public function load_plugin_textdomain() { * @return boolean Returns TRUE if the plugin and database versions match, otherwise FALSE if the values don't match. */ public static function plugin_version_check() { - - return version_compare( self::VERSION, strval( get_option( self::DB_VERSION_META_KEY ) ), '>=' ); - + return version_compare( self::VERSION, strval( self::get_instance()->get_value( 'option', self::DB_VERSION_META_KEY ) ), '>=' ); } /** @@ -584,15 +604,21 @@ public static function plugin_version_check() { */ public function get_pickup_time_options() { - // Get dates closed from settings and explode into an array. - $dates_closed = preg_replace( '/\v(?:[\v\h]+)/', "\n", trim( strval( get_option( 'local_pickup_hours_closings', '' ) ) ) ); + /** + * Get dates closed from settings and explode into an array. + * + * @var string $dates_closed + */ + $dates_closed = $this->get_value( 'option', 'local_pickup_hours_closings', '' ); + $dates_closed = preg_replace( '/\v(?:[\v\h]+)/', "\n", trim( strval( $dates_closed ) ) ); $dates_closed = ( ! empty( $dates_closed ) ) ? $dates_closed : ''; + // @var string[] $dates_closed $dates_closed = explode( "\n", $dates_closed ); // Get delay, interval, and number of days ahead settings. - $delay_minutes = get_option( 'local_pickup_delay_minutes', 60 ); - $minutes_interval = get_option( 'local_pickup_hours_interval', 30 ); - $num_days_ahead = get_option( 'local_pickup_days_ahead', 1 ); + $delay_minutes = $this->get_value( 'option', 'local_pickup_delay_minutes', 60 ); + $minutes_interval = $this->get_value( 'option', 'local_pickup_hours_interval', 30 ); + $num_days_ahead = $this->get_value( 'option', 'local_pickup_days_ahead', 1 ); // Translateble days. __( 'Monday', 'woocommerce-local-pickup-time-select' ); @@ -639,8 +665,8 @@ public function get_pickup_time_options() { // Get the day's opening and closing times. $pickup_day_name = strtolower( $pickup_datetime->format( 'l' ) ); - $pickup_day_open_time = get_option( 'local_pickup_hours_' . $pickup_day_name . '_start', '' ); - $pickup_day_close_time = get_option( 'local_pickup_hours_' . $pickup_day_name . '_end', '' ); + $pickup_day_open_time = strval( $this->get_value( 'option', 'local_pickup_hours_' . $pickup_day_name . '_start', '' ) ); + $pickup_day_close_time = strval( $this->get_value( 'option', 'local_pickup_hours_' . $pickup_day_name . '_end', '' ) ); if ( ! in_array( $pickup_datetime->format( 'm/d/Y' ), $dates_closed, true ) && @@ -684,7 +710,6 @@ public function get_pickup_time_options() { } return $pickup_options; - } /** @@ -750,7 +775,6 @@ public function get_pickup_time_intervals( $pickup_timestamp, $minutes_interval, } return ! empty( $pickup_day_options ) ? $pickup_day_options : array(); // Return an empty array if there were now DatePeriod iterations. - } /** @@ -788,7 +812,6 @@ public function time_select( $checkout ) { } $this->add_checkout_local_pickup_time( $checkout_shipping_method ); - } /** @@ -870,7 +893,6 @@ public function add_checkout_local_pickup_time( $rate ) { wp_nonce_field( $this->get_order_pickup_time_action_key(), $this->get_order_pickup_time_nonce_key() ); echo ''; - } /** @@ -882,7 +904,7 @@ public function add_checkout_local_pickup_time( $rate ) { */ public function field_process() { - $nonce = strval( wc_get_post_data_by_key( $this->get_order_pickup_time_nonce_key() ) ); + $nonce = strval( $this->get_value( 'post_data_by_key', $this->get_order_pickup_time_nonce_key() ) ); if ( ! empty( $nonce ) ) { if ( ! wp_verify_nonce( $nonce, $this->get_order_pickup_time_action_key() ) ) { wc_add_notice( __( 'Expired or invalid submission!.', 'woocommerce-local-pickup-time-select' ), 'error' ); @@ -890,11 +912,10 @@ public function field_process() { } // Check if the Pickup Time is set, if it's not set add an error. - if ( empty( wc_get_post_data_by_key( $this->get_order_post_key() ) ) ) { + if ( empty( $this->get_value( 'post_data_by_key', $this->get_order_post_key() ) ) ) { wc_add_notice( __( 'Please select a pickup time.', 'woocommerce-local-pickup-time-select' ), 'error' ); } } - } /** @@ -908,7 +929,7 @@ public function field_process() { */ public function update_order_meta( $order_id ) { - $nonce = strval( wc_get_post_data_by_key( $this->get_order_pickup_time_nonce_key() ) ); + $nonce = strval( $this->get_value( 'post_data_by_key', $this->get_order_pickup_time_nonce_key() ) ); if ( ! empty( $nonce ) ) { if ( ! wp_verify_nonce( $nonce, $this->get_order_pickup_time_action_key() ) ) { wc_add_notice( __( 'Expired or invalid submission!.', 'woocommerce-local-pickup-time-select' ), 'error' ); @@ -916,11 +937,10 @@ public function update_order_meta( $order_id ) { } // Update the order pickup time if set. - if ( ! empty( wc_get_post_data_by_key( $this->get_order_post_key() ) ) ) { - update_post_meta( $order_id, $this->get_order_meta_key(), wc_get_post_data_by_key( $this->get_order_post_key() ) ); + if ( ! empty( $this->get_value( 'post_data_by_key', $this->get_order_post_key() ) ) ) { + update_post_meta( $order_id, $this->get_order_meta_key(), $this->get_value( 'post_data_by_key', $this->get_order_post_key() ) ); } } - } /** @@ -929,14 +949,17 @@ public function update_order_meta( $order_id ) { * @since 1.3.0 * * @param array $fields The array of pickup time fields. - * @param boolean $sent_to_admin Flag that indicates whether the email is being sent to an admin user or not. + * @param bool $sent_to_admin Flag that indicates whether the email is being sent to an admin user or not. * @param WC_Order $order The order object that holds all the order attributes. * * @return array The array of order email fields including the pickup time field. */ - public function update_order_email_fields( $fields, $sent_to_admin, $order ) { + public function update_order_email_fields( array $fields, bool $sent_to_admin = true, WC_Order $order = null ) { + if ( is_null( $order ) ) { + return $fields; + } - $value = $this->pickup_time_select_translatable( strval( get_post_meta( $order->get_id(), $this->get_order_meta_key(), true ) ) ); + $value = $this->pickup_time_select_translatable( strval( $this->get_value( 'post_meta', $this->get_order_meta_key(), '', $order->get_id(), true ) ) ); $fields['meta_key'] = array( 'label' => __( 'Pickup Time', 'woocommerce-local-pickup-time-select' ), 'value' => $value, @@ -980,7 +1003,5 @@ public function pickup_time_select_translatable( $value, $separator = ' ' ) { } return $value; - } - } diff --git a/tests/phpunit/admin/class-local-pickup-time-admin_test.php b/tests/phpunit/admin/class-local-pickup-time-admin_test.php index 4f57e65..58888fe 100644 --- a/tests/phpunit/admin/class-local-pickup-time-admin_test.php +++ b/tests/phpunit/admin/class-local-pickup-time-admin_test.php @@ -16,7 +16,6 @@ class Local_Pickup_Time_Admin_Test extends WC_Unit_Test_Case { public function setUp() { parent::setUp(); - } /** @@ -25,7 +24,6 @@ public function setUp() { public function tearDown() { parent::tearDown(); - } /** @@ -42,7 +40,5 @@ public function test_plugin_admin_returns_valid_instance() { */ $this->assertTrue( true, 'Needs Unit Tests.' ); - } - } diff --git a/tests/phpunit/bootstrap.php b/tests/phpunit/bootstrap.php index 1e61538..5c8f13e 100644 --- a/tests/phpunit/bootstrap.php +++ b/tests/phpunit/bootstrap.php @@ -10,10 +10,13 @@ require_once getenv( 'WP_PHPUNIT__DIR' ) . '/includes/functions.php'; // @phpstan-ignore-next-line -tests_add_filter( 'muplugins_loaded', function() { - // test set up, plugin activation, etc. - require dirname( __DIR__ ) . '/../woocommerce-local-pickup-time.php'; -} ); +tests_add_filter( + 'muplugins_loaded', + function () { + // test set up, plugin activation, etc. + require dirname( __DIR__ ) . '/../woocommerce-local-pickup-time.php'; + } +); // Start up the WP testing environment. require getenv( 'WP_PHPUNIT__DIR' ) . '/includes/bootstrap.php'; diff --git a/tests/phpunit/public/class-local-pickup-time_test.php b/tests/phpunit/public/class-local-pickup-time_test.php index 2ffebd3..a0a3b36 100644 --- a/tests/phpunit/public/class-local-pickup-time_test.php +++ b/tests/phpunit/public/class-local-pickup-time_test.php @@ -16,7 +16,6 @@ class Local_Pickup_Time_Test extends WC_Unit_Test_Case { public function setUp() { parent::setUp(); - } /** @@ -25,7 +24,6 @@ public function setUp() { public function tearDown() { parent::tearDown(); - } /** @@ -42,7 +40,5 @@ public function test_plugin_returns_valid_instance() { */ $this->assertTrue( true, 'Needs Unit Tests.' ); - } - } diff --git a/tests/phpunit/wp-tests-config.php b/tests/phpunit/wp-tests-config.php index bb94c4d..e0cc3e5 100644 --- a/tests/phpunit/wp-tests-config.php +++ b/tests/phpunit/wp-tests-config.php @@ -1,16 +1,16 @@