From e7ec2bff82115d36bb35ae749fc44e770e824d52 Mon Sep 17 00:00:00 2001 From: Stephen Page Date: Tue, 14 Nov 2023 16:30:31 -0500 Subject: [PATCH 1/6] Add phpstan to tribe-common This just adds the working files - no fixes. [TECENG-44] --- .github/workflows/phpstan.yml | 47 +++++++++++++++++++++++++++++++++++ phpstan.neon | 11 ++++++++ 2 files changed, 58 insertions(+) create mode 100644 .github/workflows/phpstan.yml create mode 100644 phpstan.neon diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml new file mode 100644 index 0000000000..df61b74be4 --- /dev/null +++ b/.github/workflows/phpstan.yml @@ -0,0 +1,47 @@ +name: 'PHPStan Tests' +on: + pull_request: + paths: + - 'src/**.php' + - '*.php' +jobs: + phpstan: + strategy: + matrix: + phpVersion: [ + "7.4", + "8.0", + "8.1", + "8.2", + "8.3", + ] + runs-on: ubuntu-20.04 + steps: + - name: Checkout the repository + uses: actions/checkout@v2 + with: + fetch-depth: 1000 + submodules: recursive + # ------------------------------------------------------------------------------ + # Set up PHP and run phpstan + # ------------------------------------------------------------------------------ + - name: Configure PHP environment to run phpstan + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.phpVersion }} + # ------------------------------------------------------------------------------ + # Override composer php version + # ------------------------------------------------------------------------------ + - name: Set php version ${{ matrix.phpVersion }} in composer + run: composer config platform.php ${{ matrix.phpVersion }} + # ------------------------------------------------------------------------------ + # Install dependencies - ignoring php requirements + # ------------------------------------------------------------------------------ + - name: Install dependencies + run: composer i --ignore-platform-req=php+ + # ------------------------------------------------------------------------------ + # Run phpstan + # ------------------------------------------------------------------------------ + - name: Run phpstan + run: ./vendor/bin/phpstan analyse --error-format=table + diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000000..247640e8b2 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,11 @@ +parameters: + level: 0 + paths: + - src + - tribe-common.php + - tribe-autoload.php + scanDirectories: + - vendor/vendor-prefixed + excludePaths: + analyse: + - src/deprecated \ No newline at end of file From b462e39406cf7278602c84c69bfb283619d25919 Mon Sep 17 00:00:00 2001 From: Stephen Page Date: Tue, 14 Nov 2023 16:33:54 -0500 Subject: [PATCH 2/6] Change a php file --- tribe-common.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tribe-common.php b/tribe-common.php index 9ee1d7eb09..cf5b802eb2 100644 --- a/tribe-common.php +++ b/tribe-common.php @@ -9,6 +9,7 @@ License: GPLv2 or later */ + /* Copyright 2009-2015 by The Events Calendar and the contributors From d2f77ebf836e4e16ebf8f358b651733a69972e32 Mon Sep 17 00:00:00 2001 From: Stephen Page Date: Tue, 14 Nov 2023 16:42:43 -0500 Subject: [PATCH 3/6] Forgot the composer file --- composer.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ba745a80cd..15981c3cd8 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,11 @@ "the-events-calendar/coding-standards": "dev-master", "the-events-calendar/tec-testing-facilities": "dev-master", "wp-cli/checksum-command": "1.0.5", - "wp-coding-standards/wpcs": "^2.1" + "wp-coding-standards/wpcs": "^2.1", + "phpstan/phpstan": "^1.10", + "phpstan/phpstan-deprecation-rules": "^1.1", + "phpstan/extension-installer": "^1.3", + "szepeviktor/phpstan-wordpress": "*" }, "repositories": [ { From f558acd99857a3d1699325d87adfeb54d6f092b9 Mon Sep 17 00:00:00 2001 From: Stephen Page Date: Thu, 16 Nov 2023 15:48:15 -0500 Subject: [PATCH 4/6] Update composer --- composer.json | 3 +- composer.lock | 289 +++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 278 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index 15981c3cd8..5d5f710863 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,8 @@ "php": "7.3.33" }, "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true + "dealerdirect/phpcodesniffer-composer-installer": true, + "phpstan/extension-installer": true } }, "require": { diff --git a/composer.lock b/composer.lock index 6897567784..71f51e04c1 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": "43ec74747c68c7396bedc0a710526d75", + "content-hash": "2c108cc81f17a608a75f0b92dd200717", "packages": [ { "name": "firebase/php-jwt", @@ -337,16 +337,16 @@ }, { "name": "stellarwp/db", - "version": "1.0.7", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/stellarwp/db.git", - "reference": "e299e35869cb8092b48143a11509c1574cc33dc0" + "reference": "9c76724be8b60e76b7281118e4ccdf2cc129f257" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/stellarwp/db/zipball/e299e35869cb8092b48143a11509c1574cc33dc0", - "reference": "e299e35869cb8092b48143a11509c1574cc33dc0", + "url": "https://api.github.com/repos/stellarwp/db/zipball/9c76724be8b60e76b7281118e4ccdf2cc129f257", + "reference": "9c76724be8b60e76b7281118e4ccdf2cc129f257", "shasum": "" }, "require-dev": { @@ -387,9 +387,9 @@ "description": "A WPDB wrapper and query builder library.", "support": { "issues": "https://github.com/stellarwp/db/issues", - "source": "https://github.com/stellarwp/db/tree/1.0.7" + "source": "https://github.com/stellarwp/db/tree/1.1.0" }, - "time": "2023-10-23T20:46:29+00:00" + "time": "2023-11-14T12:37:35+00:00" }, { "name": "stellarwp/installer", @@ -2528,6 +2528,53 @@ }, "time": "2017-03-05T17:38:23+00:00" }, + { + "name": "php-stubs/wordpress-stubs", + "version": "v6.4.1", + "source": { + "type": "git", + "url": "https://github.com/php-stubs/wordpress-stubs.git", + "reference": "6d6063cf9464a306ca2a0529705d41312b08500b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-stubs/wordpress-stubs/zipball/6d6063cf9464a306ca2a0529705d41312b08500b", + "reference": "6d6063cf9464a306ca2a0529705d41312b08500b", + "shasum": "" + }, + "require-dev": { + "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", + "szepeviktor/phpcs-psr-12-neutron-hybrid-ruleset": "^0.8" + }, + "suggest": { + "paragonie/sodium_compat": "Pure PHP implementation of libsodium", + "symfony/polyfill-php80": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", + "szepeviktor/phpstan-wordpress": "WordPress extensions for PHPStan" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "WordPress function and class declaration stubs for static analysis.", + "homepage": "https://github.com/php-stubs/wordpress-stubs", + "keywords": [ + "PHPStan", + "static analysis", + "wordpress" + ], + "support": { + "issues": "https://github.com/php-stubs/wordpress-stubs/issues", + "source": "https://github.com/php-stubs/wordpress-stubs/tree/v6.4.1" + }, + "time": "2023-11-10T00:33:47+00:00" + }, { "name": "phpdocumentor/reflection-common", "version": "2.2.0", @@ -2755,6 +2802,50 @@ }, "time": "2020-03-05T15:02:03+00:00" }, + { + "name": "phpstan/extension-installer", + "version": "1.3.1", + "source": { + "type": "git", + "url": "https://github.com/phpstan/extension-installer.git", + "reference": "f45734bfb9984c6c56c4486b71230355f066a58a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/extension-installer/zipball/f45734bfb9984c6c56c4486b71230355f066a58a", + "reference": "f45734bfb9984c6c56c4486b71230355f066a58a", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^2.0", + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^1.9.0" + }, + "require-dev": { + "composer/composer": "^2.0", + "php-parallel-lint/php-parallel-lint": "^1.2.0", + "phpstan/phpstan-strict-rules": "^0.11 || ^0.12 || ^1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "PHPStan\\ExtensionInstaller\\Plugin" + }, + "autoload": { + "psr-4": { + "PHPStan\\ExtensionInstaller\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Composer plugin for automatic installation of PHPStan extensions", + "support": { + "issues": "https://github.com/phpstan/extension-installer/issues", + "source": "https://github.com/phpstan/extension-installer/tree/1.3.1" + }, + "time": "2023-05-24T08:59:17+00:00" + }, { "name": "phpstan/phpdoc-parser", "version": "1.24.2", @@ -2802,6 +2893,116 @@ }, "time": "2023-09-26T12:28:12+00:00" }, + { + "name": "phpstan/phpstan", + "version": "1.10.41", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "c6174523c2a69231df55bdc65b61655e72876d76" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/c6174523c2a69231df55bdc65b61655e72876d76", + "reference": "c6174523c2a69231df55bdc65b61655e72876d76", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", + "type": "tidelift" + } + ], + "time": "2023-11-05T12:57:57+00:00" + }, + { + "name": "phpstan/phpstan-deprecation-rules", + "version": "1.1.4", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan-deprecation-rules.git", + "reference": "089d8a8258ed0aeefdc7b68b6c3d25572ebfdbaa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/089d8a8258ed0aeefdc7b68b6c3d25572ebfdbaa", + "reference": "089d8a8258ed0aeefdc7b68b6c3d25572ebfdbaa", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^1.10.3" + }, + "require-dev": { + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/phpstan-php-parser": "^1.1", + "phpstan/phpstan-phpunit": "^1.0", + "phpunit/phpunit": "^9.5" + }, + "type": "phpstan-extension", + "extra": { + "phpstan": { + "includes": [ + "rules.neon" + ] + } + }, + "autoload": { + "psr-4": { + "PHPStan\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan rules for detecting usage of deprecated classes, methods, properties, constants and traits.", + "support": { + "issues": "https://github.com/phpstan/phpstan-deprecation-rules/issues", + "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/1.1.4" + }, + "time": "2023-08-05T09:02:04+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "5.3.2", @@ -4689,16 +4890,16 @@ }, { "name": "symfony/event-dispatcher-contracts", - "version": "v1.1.13", + "version": "v1.10.0", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher-contracts.git", - "reference": "1d5cd762abaa6b2a4169d3e77610193a7157129e" + "reference": "761c8b8387cfe5f8026594a75fdf0a4e83ba6974" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/1d5cd762abaa6b2a4169d3e77610193a7157129e", - "reference": "1d5cd762abaa6b2a4169d3e77610193a7157129e", + "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/761c8b8387cfe5f8026594a75fdf0a4e83ba6974", + "reference": "761c8b8387cfe5f8026594a75fdf0a4e83ba6974", "shasum": "" }, "require": { @@ -4748,7 +4949,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v1.1.13" + "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v1.10.0" }, "funding": [ { @@ -4764,7 +4965,7 @@ "type": "tidelift" } ], - "time": "2022-01-02T09:41:36+00:00" + "time": "2022-07-20T09:59:04+00:00" }, { "name": "symfony/finder", @@ -5791,6 +5992,68 @@ ], "time": "2022-08-02T15:47:23+00:00" }, + { + "name": "szepeviktor/phpstan-wordpress", + "version": "v1.3.2", + "source": { + "type": "git", + "url": "https://github.com/szepeviktor/phpstan-wordpress.git", + "reference": "b8516ed6bab7ec50aae981698ce3f67f1be2e45a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/szepeviktor/phpstan-wordpress/zipball/b8516ed6bab7ec50aae981698ce3f67f1be2e45a", + "reference": "b8516ed6bab7ec50aae981698ce3f67f1be2e45a", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0", + "php-stubs/wordpress-stubs": "^4.7 || ^5.0 || ^6.0", + "phpstan/phpstan": "^1.10.30", + "symfony/polyfill-php73": "^1.12.0" + }, + "require-dev": { + "composer/composer": "^2.1.14", + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.1", + "phpstan/phpstan-strict-rules": "^1.2", + "phpunit/phpunit": "^8.0 || ^9.0", + "szepeviktor/phpcs-psr-12-neutron-hybrid-ruleset": "^0.8" + }, + "suggest": { + "swissspidy/phpstan-no-private": "Detect usage of internal core functions, classes and methods" + }, + "type": "phpstan-extension", + "extra": { + "phpstan": { + "includes": [ + "extension.neon" + ] + } + }, + "autoload": { + "psr-4": { + "SzepeViktor\\PHPStan\\WordPress\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "WordPress extensions for PHPStan", + "keywords": [ + "PHPStan", + "code analyse", + "code analysis", + "static analysis", + "wordpress" + ], + "support": { + "issues": "https://github.com/szepeviktor/phpstan-wordpress/issues", + "source": "https://github.com/szepeviktor/phpstan-wordpress/tree/v1.3.2" + }, + "time": "2023-10-16T17:23:56+00:00" + }, { "name": "the-events-calendar/coding-standards", "version": "dev-master", From a7180a49c2fe38ddc86031342c50c9d7348192c3 Mon Sep 17 00:00:00 2001 From: Stephen Page Date: Thu, 11 Jan 2024 15:37:01 -0500 Subject: [PATCH 5/6] Fix more tests! --- .../Integrations/Integration_Abstract.php | 8 +- src/Common/Storage/Timed_Option.php | 29 ++-- src/Common/Telemetry/Telemetry.php | 104 +++++++------ src/Tribe/Admin/Activation_Page.php | 7 +- src/Tribe/View_Helpers.php | 146 ++++++++++-------- src/Tribe/Widget/Widget_Abstract.php | 49 ++++-- .../troubleshooting/ea-status/eventbrite.php | 7 +- .../troubleshooting/ea-status/meetup.php | 7 +- src/functions/template-tags/general.php | 137 ++++++++-------- src/functions/utils.php | 32 ++-- src/views/dialog/button.php | 2 +- 11 files changed, 301 insertions(+), 227 deletions(-) diff --git a/src/Common/Integrations/Integration_Abstract.php b/src/Common/Integrations/Integration_Abstract.php index 198bc0dd87..28c77d60c5 100644 --- a/src/Common/Integrations/Integration_Abstract.php +++ b/src/Common/Integrations/Integration_Abstract.php @@ -8,6 +8,7 @@ */ namespace TEC\Common\Integrations; + use TEC\Common\Contracts\Service_Provider; /** @@ -85,9 +86,10 @@ protected function filter_should_load( bool $value ): bool { * * @since 5.1.1 * - * @param bool $value Whether the integration should load. - * @param string $type Type of integration we are loading. - * @param string $slug Slug of the integration we are loading. + * @param bool $value Whether the integration should load. + * @param string $parent Parent of the integration we are loading. + * @param string $type Type of integration we are loading. + * @param string $slug Slug of the integration we are loading. */ $value = apply_filters( 'tec_integration:should_load', $value, $parent, $type, $slug ); diff --git a/src/Common/Storage/Timed_Option.php b/src/Common/Storage/Timed_Option.php index 5b9d51959f..c5740cfae3 100644 --- a/src/Common/Storage/Timed_Option.php +++ b/src/Common/Storage/Timed_Option.php @@ -96,6 +96,7 @@ public function get_option_name( string $key ): string { * @since 5.0.6 * * @param string $option_name Name of the option where all the transient data will live. + * @param string $prefix Prefix for all the Timed Options stored on the database. */ return (string) apply_filters( 'tec_common_timed_option_name', $this->option_name_prefix . $key, $this->option_name_prefix ); } @@ -106,22 +107,22 @@ public function get_option_name( string $key ): string { * @since 5.0.6 * * @param string $key Key for the option we are trying to get. - * @param mixed $default Default value when the option is either expired or not-set. + * @param mixed $default_value Default value when the option is either expired or not-set. * @param bool $force If we should expire cache and fetch from the database. * * @return mixed|null */ - public function get( $key, $default = null, bool $force = false ) { + public function get( $key, $default_value = null, bool $force = false ) { /** * Allows the filtering the default timed_option value. * * @since 5.0.6 * - * @param mixed $default Default value when the option is either expired or not-set. + * @param mixed $default_value Default value when the option is either expired or not-set. * @param string $key Key for the option we are trying to get. * @param bool $force If we should expire cache and fetch from the database. */ - $default = apply_filters( 'tec_common_timed_option_default_value', $default, $key, $force ); + $default_value = apply_filters( 'tec_common_timed_option_default_value', $default_value, $key, $force ); /** * Allows the filtering to short-circuit the whole fetch logic. @@ -130,10 +131,10 @@ public function get( $key, $default = null, bool $force = false ) { * * @param mixed|null $pre If anything diff than null it will short-circuit. * @param string $key Key for the option we are trying to get. - * @param mixed $default Default value when the option is either expired or not-set. + * @param mixed $default_value Default value when the option is either expired or not-set. * @param bool $force If we should expire cache and fetch from the database. */ - $pre = apply_filters( 'tec_common_timed_option_pre_value', null, $key, $default, $force ); + $pre = apply_filters( 'tec_common_timed_option_pre_value', null, $key, $default_value, $force ); if ( null !== $pre ) { return $pre; @@ -155,11 +156,11 @@ public function get( $key, $default = null, bool $force = false ) { * * @param mixed $value If anything diff than null it will short-circuit. * @param string $key Key for the option we are trying to get. - * @param mixed $default Default value when the option is either expired or not-set. + * @param mixed $default_value Default value when the option is either expired or not-set. * @param bool $force If we should expire cache and fetch from the database. * @param bool $cache If the value was pulled from cache. */ - return apply_filters( 'tec_common_timed_option_value', $this->data[ $key ]['value'], $key, $default, $force, true ); + return apply_filters( 'tec_common_timed_option_value', $this->data[ $key ]['value'], $key, $default_value, $force, true ); } $timed_option = null; @@ -179,14 +180,14 @@ public function get( $key, $default = null, bool $force = false ) { $this->set( $key, null, 0 ); } - return $default; + return $default_value; } // Bail with default when expired. if ( $time >= $timed_option['expiration'] ) { $this->delete( $key ); - return $default; + return $default_value; } $this->data[ $key ] = $timed_option; @@ -198,11 +199,11 @@ public function get( $key, $default = null, bool $force = false ) { * * @param mixed $value If anything diff than null it will short-circuit. * @param string $key Key for the option we are trying to get. - * @param mixed $default Default value when the option is either expired or not-set. + * @param mixed $default_value Default value when the option is either expired or not-set. * @param bool $force If we should expire cache and fetch from the database. * @param bool $cache If the value was pulled from cache. */ - return apply_filters( 'tec_common_timed_option_value', $timed_option['value'], $key, $default, $force, false ); + return apply_filters( 'tec_common_timed_option_value', $timed_option['value'], $key, $default_value, $force, false ); } /** @@ -241,7 +242,7 @@ public function delete( $key ): bool { * @since 5.0.6 * * @param string $key Which timed option we are checking. - * @param bool $force Clears the cache before get_option() + * @param bool $force Clears the cache before get_option(). * * @return bool */ @@ -337,4 +338,4 @@ public function set( $key, $value, int $expiration = DAY_IN_SECONDS ): bool { return $updated; } -} \ No newline at end of file +} diff --git a/src/Common/Telemetry/Telemetry.php b/src/Common/Telemetry/Telemetry.php index 3b40f8514d..afe04edafa 100644 --- a/src/Common/Telemetry/Telemetry.php +++ b/src/Common/Telemetry/Telemetry.php @@ -6,6 +6,7 @@ * * @package TEC\Common\Telemetry */ + namespace TEC\Common\Telemetry; use TEC\Common\StellarWP\Telemetry\Core; @@ -68,16 +69,16 @@ final class Telemetry { */ private static $base_parent_slugs = [ 'the-events-calendar', - 'event-tickets' + 'event-tickets', ]; /** * Path to main pugin file - * - * @since 5.1.0 - * - * @var string - */ + * + * @since 5.1.0 + * + * @var string + */ private static $plugin_path = ''; /** @@ -112,18 +113,18 @@ public function boot(): void { Config::set_container( $container ); - static::clean_up(); + self::clean_up(); - self::$tec_slugs = self::get_tec_telemetry_slugs(); - self::$plugin_slug = self::get_parent_plugin_slug(); - self::$plugin_path = \Tribe__Main::instance()->get_parent_plugin_file_path(); - $stellar_slug = self::get_stellar_slug(); + self::$tec_slugs = self::get_tec_telemetry_slugs(); + self::$plugin_slug = self::get_parent_plugin_slug(); + self::$plugin_path = \Tribe__Main::instance()->get_parent_plugin_file_path(); + $stellar_slug = self::get_stellar_slug(); if ( empty( $stellar_slug ) ) { return; } - $telemetry_server = ! defined( 'STELLARWP_TELEMETRY_SERVER' ) ? 'https://telemetry.stellarwp.com/api/v1': STELLARWP_TELEMETRY_SERVER; + $telemetry_server = ! defined( 'STELLARWP_TELEMETRY_SERVER' ) ? 'https://telemetry.stellarwp.com/api/v1' : STELLARWP_TELEMETRY_SERVER; Config::set_server_url( $telemetry_server ); @@ -183,14 +184,17 @@ public function init(): void { * @return void */ public static function clean_up(): void { - $status = static::get_status_object(); + $status = self::get_status_object(); $option = $status->get_option(); - if ( ! empty( $option['plugins'][ 'tec' ] ) && empty( $option['plugins'][ 'tec' ]['wp_slug'] ) ) { + if ( ! empty( $option['plugins']['tec'] ) && empty( $option['plugins']['tec']['wp_slug'] ) ) { $status->remove_plugin( 'tec' ); } } - public static function get_plugin_slug() { + /** + * Get the slug of the plugin. + */ + public static function get_plugin_slug(): string { if ( empty( self::$plugin_slug ) ) { self::$plugin_slug = self::get_parent_plugin_slug(); } @@ -208,7 +212,7 @@ public static function get_plugin_slug() { */ public static function get_parent_plugin_slug(): string { if ( empty( self::$parent_plugin ) ) { - $file = \Tribe__Main::instance()->get_parent_plugin_file_path(); + $file = \Tribe__Main::instance()->get_parent_plugin_file_path(); self::$parent_plugin = substr( $file, ( strrpos( $file, '/' ) + 1 ), @@ -227,7 +231,7 @@ public static function get_parent_plugin_slug(): string { public static function get_stellar_slug(): string { $tec_slugs = self::get_tec_telemetry_slugs(); - foreach( $tec_slugs as $slug => $path ) { + foreach ( $tec_slugs as $slug => $path ) { if ( stripos( self::$plugin_path, $path ) ) { return $slug; } @@ -246,14 +250,7 @@ public static function get_stellar_slug(): string { * @return array */ public function filter_optin_args( $args ): array { - $user_name = esc_html( wp_get_current_user()->display_name ); - - /* - if ET only change logo, name to Event Tickets - if TEC only change logo - If both, use The Events Calendar - */ - + $user_name = esc_html( wp_get_current_user()->display_name ); $optin_args = [ 'plugin_logo' => tribe_resource_url( 'images/logo/tec-brand.svg', false, null, \Tribe__Main::instance() ), 'plugin_logo_width' => 'auto', @@ -267,7 +264,14 @@ public function filter_optin_args( $args ): array { 'privacy_url' => self::get_privacy_url(), 'opted_in_plugins_text' => __( 'See which plugins you have opted in to tracking for', 'tribe-common' ), 'heading' => __( 'We hope you love TEC Common!', 'tribe-common' ), - 'intro' => __( "Hi, {$user_name}! This is an invitation to help our StellarWP community. If you opt-in, some data about your usage of TEC Common and future StellarWP Products will be shared with our teams (so they can work their butts off to improve). We will also share some helpful info on WordPress, and our products from time to time. And if you skip this, that’s okay! Our products still work just fine.", 'tribe-common' ), + 'intro' => sprintf( + /* Translators: %1$s is the user's display name. */ + __( + 'Hi, %1$s! This is an invitation to help our StellarWP community. If you opt-in, some data about your usage of TEC Common and future StellarWP Products will be shared with our teams (so they can work their butts off to improve). We will also share some helpful info on WordPress, and our products from time to time. And if you skip this, that’s okay! Our products still work just fine.', + 'tribe-common' + ), + $user_name + ), ]; /** @@ -389,19 +393,21 @@ public function filter_exit_interview_args( $args ) { * * @since 5.1.0 * + * @param string $slug The slug of the plugin showing the modal. + * * @return void */ - public function show_optin_modal( $slug ): void { + public function show_optin_modal( $slug ): void { /** * Filter allowing disabling of the optin modal. * Returning boolean false will disable the modal * * @since 5.1.0 * - * @param bool $show Whether to show the modal or not. - * + * @param bool $show Whether to show the modal or not. + * @param string $slug The slug of the plugin showing the modal. */ - $show = (bool) apply_filters( 'tec_common_telemetry_show_optin_modal', true, $slug ); + $show = (bool) apply_filters( 'tec_common_telemetry_show_optin_modal', true, $slug ); if ( ! $show ) { return; @@ -435,7 +441,7 @@ public static function get_status_object(): Status { * * @since 5.1.0 * - * @return array An array of plugins in the format [ 'plugin_slug' => 'plugin_path' ] + * @return array An array of plugins in the format ['plugin_slug' => 'plugin_path'] */ public static function get_tec_telemetry_slugs() { /** @@ -445,7 +451,7 @@ public static function get_tec_telemetry_slugs() { * * @since 5.1.0 * - * @param array $slugs An array of plugins in the format [ 'plugin_slug' => 'plugin_path' ] + * @param array $slugs An array of plugins in the format ['plugin_slug' => 'plugin_path'] */ return apply_filters( 'tec_telemetry_slugs', [] ); } @@ -456,9 +462,11 @@ public static function get_tec_telemetry_slugs() { * * @since 5.1.0 * + * @param bool|null $opted Whether to opt in or out. If null, will calculate based on existing status. + * * @return void */ - public function register_tec_telemetry_plugins( $opted = NULL ) { + public function register_tec_telemetry_plugins( $opted = null ) { // Let's reduce the amount this triggers. if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { return; @@ -471,7 +479,7 @@ public function register_tec_telemetry_plugins( $opted = NULL ) { global $pagenow; // Only run on the plugins page, or when we're manually setting an opt-in! - if ( $pagenow !== 'plugins.php' && is_null( $opted ) ) { + if ( 'plugins.php' !== $pagenow && is_null( $opted ) ) { return; } @@ -486,7 +494,7 @@ public function register_tec_telemetry_plugins( $opted = NULL ) { $cached_slugs = tribe( 'cache' )['tec_telemetry_slugs'] ?? null; // We have already run and the slug list hasn't changed since then. Or we are manually running. - if ( is_null( $opted ) && ! empty( $cached_slugs ) && $cached_slugs == $tec_slugs ) { + if ( is_null( $opted ) && ! empty( $cached_slugs ) && $cached_slugs == $tec_slugs ) { return; } @@ -522,9 +530,9 @@ public function register_tec_telemetry_plugins( $opted = NULL ) { } } - $show_modal = static::calculate_modal_status(); + $show_modal = self::calculate_modal_status(); - static::disable_modal( $slug, $show_modal ); + self::disable_modal( $slug, $show_modal ); } } @@ -535,12 +543,12 @@ public function register_tec_telemetry_plugins( $opted = NULL ) { */ public function normalize_optin_status(): void { // If they have opted in to one plugin, opt them in to all TEC ones. - $status_obj = static::get_status_object(); + $status_obj = self::get_status_object(); $stati = []; $status = $this->calculate_optin_status(); $stati = array_filter( $stati ); - foreach ( static::$base_parent_slugs as $slug ) { + foreach ( self::$base_parent_slugs as $slug ) { if ( $status_obj->plugin_exists( $slug ) ) { $status_obj->set_status( (bool) $status, $slug ); } @@ -554,23 +562,23 @@ public function normalize_optin_status(): void { * * @since 6.1.0 * - * @param bool $opted + * @param bool $opted Whether to opt in or out. If null, will calculate based on existing status. * * @return bool $opted */ public function calculate_optin_status( $opted = null ) { - if ( NULL !== $opted ) { + if ( null !== $opted ) { return $opted; } // If they have opted in to one plugin, opt them in to all TEC ones. - $status_obj = static::get_status_object(); + $status_obj = self::get_status_object(); $stati = []; $option = $status_obj->get_option(); - foreach ( static::$base_parent_slugs as $slug ) { + foreach ( self::$base_parent_slugs as $slug ) { if ( $status_obj->plugin_exists( $slug ) ) { - $stati[ $slug ] = $option['plugins'][ $slug ][ 'optin' ]; + $stati[ $slug ] = $option['plugins'][ $slug ]['optin']; } } @@ -593,13 +601,13 @@ public static function calculate_modal_status(): bool { } // If they have already interacted with a modal, find out. - $shows = array_flip( static::$base_parent_slugs ); + $shows = array_flip( self::$base_parent_slugs ); $optin = Config::get_container()->get( Opt_In_Template::class ); - foreach ( static::$base_parent_slugs as $slug ) { + foreach ( self::$base_parent_slugs as $slug ) { $show = get_option( $optin->get_option_name( $slug ), null ); // Remove unset entries from the array. - if ( is_null( $show ) ) { + if ( is_null( $show ) ) { unset( $shows[ $slug ] ); continue; } @@ -614,7 +622,7 @@ public static function calculate_modal_status(): bool { $shows = array_filter( $shows, - function( $val ) { + function ( $val ) { // remove all the truthy values from the array. return ! tribe_is_truthy( $val ); } diff --git a/src/Tribe/Admin/Activation_Page.php b/src/Tribe/Admin/Activation_Page.php index c9db44099d..8782dc82bb 100644 --- a/src/Tribe/Admin/Activation_Page.php +++ b/src/Tribe/Admin/Activation_Page.php @@ -86,8 +86,8 @@ public function hooks() { add_action( 'admin_init', [ $this, 'maybe_redirect' ], 10, 0 ); add_action( 'admin_menu', [ $this, 'register_page' ], 100, 0 ); // Come in after the default page is registered. - add_action( 'update_plugin_complete_actions', [ $this, 'update_complete_actions' ], 15, 2 ); - add_action( 'update_bulk_plugins_complete_actions', [ $this, 'update_complete_actions' ], 15, 2 ); + add_filter( 'update_plugin_complete_actions', [ $this, 'update_complete_actions' ], 15, 2 ); + add_filter( 'update_bulk_plugins_complete_actions', [ $this, 'update_complete_actions' ], 15, 2 ); } /** @@ -169,7 +169,8 @@ public function maybe_redirect() { * * @since 5.0.0 * - * @param $bypass bool + * @param bool $bypass Whether to bypass the update page redirect. + * @param Tribe__Admin__Activation_Page $activation_page The page instance. */ $bypass_update_page = apply_filters( 'tec_admin_update_page_bypass', false, $this ); diff --git a/src/Tribe/View_Helpers.php b/src/Tribe/View_Helpers.php index 0ee74d06e8..c129d7b59a 100755 --- a/src/Tribe/View_Helpers.php +++ b/src/Tribe/View_Helpers.php @@ -3,23 +3,32 @@ * Various helper methods used in views */ -// Don't load directly +// Don't load directly. if ( ! defined( 'ABSPATH' ) ) { die( '-1' ); } +// phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace +// phpcs:disable PEAR.NamingConventions.ValidClassName.Invalid +// phpcs:disable TEC.Classes.ValidClassName.NotSnakeCase +// phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid +// phpcs:disable WordPress.DateTime.RestrictedFunctions.date_date + if ( ! class_exists( 'Tribe__View_Helpers' ) ) { + /** + * Class Tribe__View_Helpers + */ class Tribe__View_Helpers { /** * Get the countries being used and available for the plugin. * - * @param string $postId The post ID. - * @param bool $useDefault Should we use the defaults? + * @param string $post_id The post ID. + * @param bool $use_default If we should use the defaults. * * @return array The countries array. */ - public static function constructCountries( $postId = '', $useDefault = true ) { + public static function constructCountries( $post_id = '', $use_default = true ) { static $cache_var_name = __METHOD__; $countries = tribe_get_var( $cache_var_name, null ); @@ -28,12 +37,12 @@ public static function constructCountries( $postId = '', $useDefault = true ) { return $countries; } - $eventCountries = tribe_get_option( 'tribeEventsCountries' ); + $event_countries = tribe_get_option( 'tribeEventsCountries' ); - if ( $eventCountries != '' ) { + if ( '' !== $event_countries ) { $countries = []; - $country_rows = explode( "\n", $eventCountries ); + $country_rows = explode( "\n", $event_countries ); foreach ( $country_rows as $crow ) { $country = explode( ',', $crow ); if ( isset( $country[0] ) && isset( $country[1] ) ) { @@ -52,25 +61,27 @@ public static function constructCountries( $postId = '', $useDefault = true ) { } // Perform a natural sort: this maintains the key -> index associations but ensures the countries - // are in the expected order, even once translated + // are in the expected order, even once translated. natsort( $countries ); - // Placeholder option ('Select a Country') first by default + // Placeholder option ('Select a Country') first by default. $select_country = [ '' => esc_html__( 'Select a Country:', 'tribe-common' ) ]; - $countries = $select_country + $countries; + $countries = $select_country + $countries; - if ( ( $postId || $useDefault ) ) { - $countryValue = get_post_meta( $postId, '_EventCountry', true ); - if ( $countryValue ) { - $defaultCountry = [ array_search( $countryValue, $countries ), $countryValue ]; + if ( ( $post_id || $use_default ) ) { + $country_value = get_post_meta( $post_id, '_EventCountry', true ); + if ( $country_value ) { + $default_country = [ array_search( $country_value, $countries ), $country_value ]; } else { - $defaultCountry = tribe_get_default_value( 'country' ); + // @TODO: This function lives in TEC, this should not be used here. + $default_country = tribe_get_default_value( 'country' ); } - if ( $defaultCountry && $defaultCountry[0] != '' ) { - $selectCountry = array_shift( $countries ); + + if ( $default_country && '' !== $default_country[0] ) { + $select_country = array_shift( $countries ); asort( $countries ); - $countries = [ $defaultCountry[0] => $defaultCountry[1] ] + $countries; - $countries = [ '' => $selectCountry ] + $countries; + $countries = [ $default_country[0] => $default_country[1] ] + $countries; + $countries = [ '' => $select_country ] + $countries; array_unique( $countries ); } } @@ -101,12 +112,12 @@ public static function loadStates() { /** * Builds a set of options for displaying an hour chooser * - * @param string $date the current date (optional) - * @param bool $isStart + * @param string $date the current date (optional). + * @param bool $is_start if this is the start time. * * @return string a set of HTML options with hours (current hour selected) */ - public static function getHourOptions( $date = '', $isStart = false ) { + public static function getHourOptions( $date = '', $is_start = false ) { $hours = self::hours(); if ( count( $hours ) == 12 ) { @@ -117,28 +128,28 @@ public static function getHourOptions( $date = '', $isStart = false ) { $options = ''; if ( empty( $date ) ) { - $hour = ( $isStart ) ? '08' : ( count( $hours ) == 12 ? '05' : '17' ); + $hour = ( $is_start ) ? '08' : ( count( $hours ) == 12 ? '05' : '17' ); } else { $timestamp = strtotime( $date ); $hour = date( $h, $timestamp ); - // fix hours if time_format has changed from what is saved - if ( preg_match( '(pm|PM)', $timestamp ) && $h == 'H' ) { + // Fix hours if time_format has changed from what is saved. + if ( preg_match( '(pm|PM)', $timestamp ) && 'H' === $h ) { $hour = $hour + 12; } - if ( $hour > 12 && $h == 'h' ) { + if ( $hour > 12 && 'h' === $h ) { $hour = $hour - 12; } } - $hour = apply_filters( 'tribe_get_hour_options', $hour, $date, $isStart ); + $hour = apply_filters( 'tribe_get_hour_options', $hour, $date, $is_start ); - foreach ( $hours as $hourText ) { - if ( $hour == $hourText ) { + foreach ( $hours as $hour_text ) { + if ( $hour == $hour_text ) { $selected = 'selected="selected"'; } else { $selected = ''; } - $options .= "\n"; + $options .= "\n"; } return $options; @@ -147,12 +158,12 @@ public static function getHourOptions( $date = '', $isStart = false ) { /** * Builds a set of options for displaying a minute chooser * - * @param string $date the current date (optional) - * @param bool $isStart + * @param string $date The current date (optional). + * @param bool $is_start If this is the start time. * * @return string a set of HTML options with minutes (current minute selected) */ - public static function getMinuteOptions( $date = '', $isStart = false ) { + public static function getMinuteOptions( $date = '', $is_start = false ) { $options = ''; if ( empty( $date ) ) { @@ -161,16 +172,16 @@ public static function getMinuteOptions( $date = '', $isStart = false ) { $minute = date( 'i', strtotime( $date ) ); } - $minute = apply_filters( 'tribe_get_minute_options', $minute, $date, $isStart ); + $minute = apply_filters( 'tribe_get_minute_options', $minute, $date, $is_start ); $minutes = self::minutes( $minute ); - foreach ( $minutes as $minuteText ) { - if ( $minute == $minuteText ) { + foreach ( $minutes as $minute_text ) { + if ( $minute == $minute_text ) { $selected = 'selected="selected"'; } else { $selected = ''; } - $options .= "\n"; + $options .= "\n"; } return $options; @@ -182,18 +193,18 @@ public static function getMinuteOptions( $date = '', $isStart = false ) { * @return array The hours array. */ private static function hours() { - $hours = []; - $rangeMax = self::is_24hr_format() ? 23 : 12; - $rangeStart = $rangeMax > 12 ? 0 : 1; - foreach ( range( $rangeStart, $rangeMax ) as $hour ) { + $hours = []; + $range_max = self::is_24hr_format() ? 23 : 12; + $range_start = $range_max > 12 ? 0 : 1; + foreach ( range( $range_start, $range_max ) as $hour ) { if ( $hour < 10 ) { $hour = '0' . $hour; } $hours[ $hour ] = $hour; } - // In a 12hr context lets put 12 at the start (so the sequence will run 12, 1, 2, 3 ... 11) - if ( 12 === $rangeMax ) { + // In a 12hr context lets put 12 at the start (so the sequence will run 12, 1, 2, 3 ... 11). + if ( 12 === $range_max ) { array_unshift( $hours, array_pop( $hours ) ); } @@ -207,39 +218,42 @@ private static function hours() { * In inconclusive cases, such as if there are now hour-format characters, 12hr format is * assumed. * - * @param null $format + * @param null $format The format to check. + * * @return bool */ public static function is_24hr_format( $format = null ) { - // Use the provided format or else use the value of the current time_format setting + // Use the provided format or else use the value of the current time_format setting. $format = ( null === $format ) ? get_option( 'time_format', Tribe__Date_Utils::TIMEFORMAT ) : $format; - // Count instances of the H and G symbols + // Count instances of the H and G symbols. $h_symbols = substr_count( $format, 'H' ); $g_symbols = substr_count( $format, 'G' ); - // If none have been found then consider the format to be 12hr - if ( ! $h_symbols && ! $g_symbols ) return false; + // If none have been found then consider the format to be 12hr. + if ( ! $h_symbols && ! $g_symbols ) { + return false; + } - // It's possible H or G have been included as escaped characters + // It's possible H or G have been included as escaped characters. $h_escaped = substr_count( $format, '\H' ); $g_escaped = substr_count( $format, '\G' ); - // Final check, accounting for possibility of escaped values + // Final check, accounting for possibility of escaped values. return ( $h_symbols > $h_escaped || $g_symbols > $g_escaped ); } /** * Helper method to return an array of 00-59 for minutes * - * @param int $exact_minute optionally specify an exact minute to be included (outwith the default intervals) + * @param int $exact_minute optionally specify an exact minute to be included (outwith the default intervals). * * @return array The minutes array. */ private static function minutes( $exact_minute = 0 ) { $minutes = []; - // The exact minute should be an absint between 0 and 59 + // The exact minute should be an absint between 0 and 59. $exact_minute = absint( $exact_minute ); if ( $exact_minute < 0 || $exact_minute > 59 ) { @@ -253,11 +267,11 @@ private static function minutes( $exact_minute = 0 ) { */ $default_increment = apply_filters( 'tribe_minutes_increment', 5 ); - // Unless an exact minute has been specified we can minimize the amount of looping we do + // Unless an exact minute has been specified we can minimize the amount of looping we do. $increment = ( 0 === $exact_minute ) ? $default_increment : 1; for ( $minute = 0; $minute < 60; $minute += $increment ) { - // Skip if this $minute doesn't meet the increment pattern and isn't an additional exact minute + // Skip if this $minute doesn't meet the increment pattern and isn't an additional exact minute. if ( 0 !== $minute % $default_increment && $exact_minute !== $minute ) { continue; } @@ -272,14 +286,14 @@ private static function minutes( $exact_minute = 0 ) { } /** - * Builds a set of options for diplaying a meridian chooser + * Builds a set of options for displaying a meridian chooser * - * @param string $date YYYY-MM-DD HH:MM:SS to select (optional) - * @param bool $isStart + * @param string $date YYYY-MM-DD HH:MM:SS to select (optional). + * @param bool $is_start if this is the start time. * * @return string a set of HTML options with all meridians */ - public static function getMeridianOptions( $date = '', $isStart = false ) { + public static function getMeridianOptions( $date = '', $is_start = false ) { if ( strstr( get_option( 'time_format', Tribe__Date_Utils::TIMEFORMAT ), 'A' ) ) { $a = 'A'; $meridians = [ 'AM', 'PM' ]; @@ -288,12 +302,12 @@ public static function getMeridianOptions( $date = '', $isStart = false ) { $meridians = [ 'am', 'pm' ]; } if ( empty( $date ) ) { - $meridian = ( $isStart ) ? $meridians[0] : $meridians[1]; + $meridian = ( $is_start ) ? $meridians[0] : $meridians[1]; } else { $meridian = date( $a, strtotime( $date ) ); } - $meridian = apply_filters( 'tribe_get_meridian_options', $meridian, $date, $isStart ); + $meridian = apply_filters( 'tribe_get_meridian_options', $meridian, $date, $is_start ); $return = ''; foreach ( $meridians as $m ) { @@ -318,12 +332,12 @@ private static function years() { $years_back = (int) apply_filters( 'tribe_years_to_go_back', 5, $current_year ); $years_forward = (int) apply_filters( 'tribe_years_to_go_forward', 5, $current_year ); $years = []; - for ( $i = $years_back; $i > 0; $i -- ) { + for ( $i = $years_back; $i > 0; $i-- ) { $year = $current_year - $i; $years[] = $year; } $years[] = $current_year; - for ( $i = 1; $i <= $years_forward; $i ++ ) { + for ( $i = 1; $i <= $years_forward; $i++ ) { $year = $current_year + $i; $years[] = $year; } @@ -332,13 +346,15 @@ private static function years() { } /** - * Helper method to return an array of 1-31 for days + * Helper method to return an array of 1-31 for days. + * + * @param int $total_days The total days. * * @return array The days array. */ - public static function days( $totalDays ) { + public static function days( $total_days ) { $days = []; - foreach ( range( 1, $totalDays ) as $day ) { + foreach ( range( 1, $total_days ) as $day ) { $days[ $day ] = $day; } diff --git a/src/Tribe/Widget/Widget_Abstract.php b/src/Tribe/Widget/Widget_Abstract.php index 89c4cd7ae4..1d308c8ed6 100644 --- a/src/Tribe/Widget/Widget_Abstract.php +++ b/src/Tribe/Widget/Widget_Abstract.php @@ -122,12 +122,6 @@ abstract class Widget_Abstract extends \WP_Widget implements Widget_Interface { * {@inheritDoc} */ public function __construct( $id_base = '', $name = '', $widget_options = [], $control_options = [] ) { - /** - * For backwards compatibility purposes alone. - * @todo remove after 2021-08-01 - */ - $this->slug = static::get_widget_slug(); - parent::__construct( $this->parse_id_base( $id_base ), $this->parse_name( $name ), @@ -813,9 +807,9 @@ public function toggle_hooks( $toggle, $location = 'display' ) { * * @since 4.13.0 * - * @param bool $toggle Whether the hooks should be turned on or off. This value is `true` before a widget - * HTML is rendered and `false` after the widget HTML rendered. - * @param static $this The widget object that is toggling the hooks. + * @param bool $toggle Whether the hooks should be turned on or off. This value is `true` before a widget + * HTML is rendered and `false` after the widget HTML rendered. + * @param static $widget_object The widget object that is toggling the hooks. */ do_action( 'tribe_shortcode_toggle_hooks', $toggle, $this ); } @@ -826,9 +820,7 @@ public function toggle_hooks( $toggle, $location = 'display' ) { * * @since 4.13.0 */ - protected function add_hooks() { - - } + protected function add_hooks() {} /** * Toggles on portions of the template that were modified in `add_template_mods()` above. @@ -837,8 +829,39 @@ protected function add_hooks() { * * @since 4.13.0 */ - protected function remove_hooks() { + protected function remove_hooks() {} + + + + /** + * Massages the data before asking tribe_format_field_dependency() to create the dependency attributes. + * + * @since 5.3.0 (in TEC) + * @since TBD Moved into common from TEC Widget Abstract + * + * @param array $field The field info. + * + * @return string The dependency attributes. + */ + public function format_dependency( $field ) { + $deps = Arr::get( $field, 'dependency', false ); + // Sanity check. + if ( empty( $deps ) ) { + return ''; + } + + if ( isset( $deps['ID'] ) ) { + $deps['id'] = $deps['ID']; + } + + // No ID to hook to? Bail. + if ( empty( $deps['id'] ) ) { + return ''; + } + + $deps['id'] = $this->get_field_id( $deps['id'] ); + return tribe_format_field_dependency( $deps ); } /********************** diff --git a/src/admin-views/troubleshooting/ea-status/eventbrite.php b/src/admin-views/troubleshooting/ea-status/eventbrite.php index 98b683b9c6..aeffb04007 100644 --- a/src/admin-views/troubleshooting/ea-status/eventbrite.php +++ b/src/admin-views/troubleshooting/ea-status/eventbrite.php @@ -5,6 +5,9 @@ * @since 4.14.2 * */ + + // @TODO: This class lives in TEC, it should not be used here! + use Tribe__Events__Aggregator__Record__Eventbrite as Eventbrite; ?> @@ -22,7 +25,7 @@ if ( ! tribe( 'events-aggregator.settings' )->has_eb_security_key() ) { $icon = 'warning'; $message = __( 'You have not connected Event Aggregator to Eventbrite', 'tribe-common' ); - $eventbrite_auth_url = Tribe__Events__Aggregator__Record__Eventbrite::get_auth_url( + $eventbrite_auth_url = Eventbrite::get_auth_url( [ 'back' => 'settings' ] ); $notes = '' . esc_html_x( 'Connect to Eventbrite', 'link for connecting eventbrite', 'tribe-common' ) . ''; @@ -45,4 +48,4 @@ - \ No newline at end of file + diff --git a/src/admin-views/troubleshooting/ea-status/meetup.php b/src/admin-views/troubleshooting/ea-status/meetup.php index 4eaad68224..bb1990720b 100644 --- a/src/admin-views/troubleshooting/ea-status/meetup.php +++ b/src/admin-views/troubleshooting/ea-status/meetup.php @@ -6,6 +6,9 @@ * */ +// @TODO: This class lives in TEC, it should not be used here! +use Tribe__Events__Aggregator__Record__Meetup as Meetup; + $icon = 'success'; $notes = ' '; $message = 'Connected'; @@ -14,7 +17,7 @@ if ( ! tribe( 'events-aggregator.settings' )->has_meetup_security_key() ) { $icon = 'warning'; $message = __( 'You have not connected Event Aggregator to Meetup', 'tribe-common' ); - $meetup_auth_url = Tribe__Events__Aggregator__Record__Meetup::get_auth_url( [ 'back' => 'settings' ] ); + $meetup_auth_url = Meetup::get_auth_url( [ 'back' => 'settings' ] ); $notes = '' . esc_html_x( 'Connect to Meetup', 'link for connecting meetup', 'tribe-common' ) . ''; } } else { @@ -36,4 +39,4 @@ - \ No newline at end of file + diff --git a/src/functions/template-tags/general.php b/src/functions/template-tags/general.php index f0ccd1334c..525e63ec13 100755 --- a/src/functions/template-tags/general.php +++ b/src/functions/template-tags/general.php @@ -19,6 +19,7 @@ * Retrieve specific key from options array, optionally provide a default return value * * @category Events + * * @param string $optionName Name of the option to retrieve. * @param string $default Value to return if no such option is found. * @@ -33,7 +34,7 @@ function tribe_get_option( $optionName, $default = '' ) { * * @since 4.0.1 * - * @param mixed $value Value of the option if found. + * @param mixed $value Value of the option if found. * @param string $optionName Name of the option to retrieve. * @param string $default Value to return if no such option is found. */ @@ -44,7 +45,7 @@ function tribe_get_option( $optionName, $default = '' ) { * * @since 4.0.1 * - * @param mixed $value Value of the option if found. + * @param mixed $value Value of the option if found. * @param string $optionName Name of the option to retrieve. * @param string $default Value to return if no such option is found. */ @@ -59,8 +60,9 @@ function tribe_get_option( $optionName, $default = '' ) { * Set specific key from options array, optionally provide a default return value * * @category Events + * * @param string $optionName Name of the option to retrieve. - * @param string $value Value to save + * @param string $value Value to save. * * @return bool */ @@ -76,8 +78,9 @@ function tribe_update_option( $optionName, $value ) { * Remove specific key from options array * * @category Events + * * @param string $optionName Name of the option to retrieve. - * @param string $value Value to save + * @param string $value Value to save. * * @return bool */ @@ -93,6 +96,7 @@ function tribe_remove_option( $optionName ) { * Retrieve specific key from options array, optionally provide a default return value * * @category Events + * * @param string $optionName Name of the option to retrieve. * @param string $default Value to return if no such option is found. * @@ -110,10 +114,10 @@ function tribe_get_network_option( $optionName, $default = '' ) { * * @category Events * - * @param string $resource the filename of the resource - * @param bool $echo whether or not to echo the url - * @param string $root_dir directory to hunt for resource files (null or the actual path) - * @param object $origin Which plugin we are dealing with + * @param string $resource the filename of the resource. + * @param bool $echo whether or not to echo the url. + * @param string $root_dir directory to hunt for resource files (null or the actual path). + * @param object $origin Which plugin we are dealing with. * * @return string **/ @@ -157,8 +161,8 @@ function tribe_resource_url( $resource, $echo = false, $root_dir = null, $origin /** * Filters the resource URL * - * @param $url - * @param $resource + * @param string $url The URL to the resource. + * @param string $resource The filename of the resource. */ $url = apply_filters( 'tribe_resource_url', $url, $resource ); @@ -180,11 +184,12 @@ function tribe_resource_url( $resource, $echo = false, $root_dir = null, $origin * helper function to remove empty lines from multi-line strings * * @category Events + * * @link http://stackoverflow.com/questions/709669/how-do-i-remove-blank-lines-from-text-in-php * - * @param string $multi_line_string a multiline string + * @param string $multi_line_string a multiline string. * - * @return string the same string without empty lines + * @return string the same string without empty lines. */ function tribe_multi_line_remove_empty_lines( $multi_line_string ) { return preg_replace( "/^\n+|^[\t\s]*\n+/m", '', $multi_line_string ); @@ -196,7 +201,8 @@ function tribe_multi_line_remove_empty_lines( $multi_line_string ) { * Get the date format specified in the tribe options * * @category Events - * @param bool $with_year + * + * @param bool $with_year. * * @return mixed */ @@ -217,7 +223,7 @@ function tribe_get_date_format( $with_year = false ) { * * @category Events * - * @param bool $with_year + * @param bool $with_year. * * @return mixed|void */ @@ -234,6 +240,7 @@ function tribe_get_datetime_format( $with_year = false ) { * * @param string $fallback The string to use as the fallback. * @param string $raw_separator The raw value of the dateTimeSeparator option. + * * @return string */ $separator[0] = apply_filters( 'tribe_empty_datetime_separator_fallback', ' ', $raw_separator ); @@ -255,7 +262,7 @@ function tribe_get_datetime_format( $with_year = false ) { * * @return mixed|void */ - function tribe_get_time_format( ) { + function tribe_get_time_format() { static $cache_var_name = __FUNCTION__; $format = tribe_get_var( $cache_var_name, null ); @@ -275,9 +282,9 @@ function tribe_get_time_format( ) { * * @category Events * - * @param string $start_date - * @param string $end_date - * @param string|bool $day_cutoff + * @param string $start_date The start date. + * @param string $end_date The end date. + * @param string|bool $day_cutoff The time of day to use as the cutoff for the day. If false, no cutoff is used. If true, the cutoff is the value of the multiDayCutoff option. * * @return int * @see Tribe__Date_Utils::date_diff() @@ -310,7 +317,7 @@ function tribe_get_days_between( $start_date, $end_date, $day_cutoff = '00:00' ) * * @category Events * - * @param $string + * @param string $string The string to be cleaned. * * @return string */ @@ -332,7 +339,7 @@ function tribe_prepare_for_json( $string ) { * * @category Events * - * @param mixed $value The data to be cleaned + * @param mixed $value The data to be cleaned. * * @return mixed The clean data */ @@ -357,7 +364,7 @@ function tribe_prepare_for_json_deep( $value ) { * * @category Events * - * @param bool $echo Whether or not to echo the notices html + * @param bool $echo Whether or not to echo the notices html. * * @return void | string * @see Tribe__Notices::get() @@ -427,8 +434,8 @@ function tribe_is_bot() { /** * Count keys in a hierarchical array * - * @param $value - * @param $key + * @param $value. + * @param $key. * @todo - remove, only used in the meta walker */ function tribe_count_hierarchical_keys( $value, $key ) { @@ -441,7 +448,7 @@ function tribe_count_hierarchical_keys( $value, $key ) { /** * Count items in a hierarchical array * - * @param array $walk + * @param array $walk. * * @return int * @todo - remove, only used in the meta walker @@ -463,7 +470,7 @@ function tribe_count_hierarchical( array $walk ) { * * @category Events * - * @param int $default The default width (in pixels) at which to break into mobile styles + * @param int $default The default width (in pixels) at which to break into mobile styles. * * @return int */ @@ -477,10 +484,10 @@ function tribe_get_mobile_breakpoint( $default = 768 ) { * Receives a float and formats it with a currency symbol * * @category Cost - * @param string $cost pricing to format - * @param null|int $post_id - * @param null|string $currency_symbol - * @param null|bool $reverse_position + * @param string $cost pricing to format. + * @param ?int $post_id post id. + * @param ?string $currency_symbol currency symbol. + * @param ?bool $reverse_position reverse position of symbol. * * @return string */ @@ -498,8 +505,8 @@ function tribe_format_currency( $cost, $post_id = null, $currency_symbol = null, * * @since 4.7.7 * - * @param string $currency_symbol - * @param int $post_id + * @param string $currency_symbol. + * @param int $post_id. */ $currency_symbol = apply_filters( 'tribe_currency_symbol', $currency_symbol, $post_id ); } @@ -513,8 +520,8 @@ function tribe_format_currency( $cost, $post_id = null, $currency_symbol = null, * * @since 4.7.7 * - * @param bool $reverse_position - * @param int $post_id + * @param bool $reverse_position. + * @param int $post_id. */ $reverse_position = apply_filters( 'tribe_reverse_currency_position', (bool) $reverse_position, $post_id ); } @@ -530,8 +537,8 @@ function tribe_format_currency( $cost, $post_id = null, $currency_symbol = null, * * @since 4.7.10 * - * @param string $cost - * @param int $post_id + * @param string $cost The cost value. + * @param int $post_id The post ID. */ $cost = apply_filters( 'tribe_currency_cost', $cost, $post_id ); @@ -544,8 +551,8 @@ function tribe_format_currency( $cost, $post_id = null, $currency_symbol = null, * * @since 4.14.9 * - * @param string $cost - * @param int $post_id + * @param string $cost The cost value. + * @param int $post_id The post ID. */ return apply_filters( 'tribe_currency_formatted', $cost, $post_id ); } @@ -558,7 +565,7 @@ function tribe_format_currency( $cost, $post_id = null, $currency_symbol = null, * Retrieve an option value taking care to escape it to preserve date format slashes. * * @category Events - * @param string $optionName Name of the option to retrieve. + * @param string $optionName Name of the option to retrieve. * @param string $default Value to return if no such option is found. * * @return mixed Value of the option if found @@ -573,10 +580,10 @@ function tribe_get_date_option( $optionName, $default = '' ) { /** * Shortcut for Tribe__Admin__Notices::register(), create a Admin Notice easily * - * @param string $slug Slug to save the notice - * @param callable|string $callback A callable Method/Function to actually display the notice - * @param array $arguments Arguments to Setup a notice - * @param callable|null $active_callback An optional callback that should return bool values + * @param string $slug Slug to save the notice. + * @param callable|string $callback A callable Method/Function to actually display the notice. + * @param array $arguments Arguments to Setup a notice. + * @param ?callable $active_callback An optional callback that should return bool values. * to indicate whether the notice should display or not. * * @return stdClass Which notice was registered @@ -591,10 +598,10 @@ function tribe_notice( $slug, $callback, $arguments = [], $active_callback = nul * A transient admin notice is a "fire-and-forget" admin notice that will display once registered and * until dismissed (if dismissible) without need, on the side of the source code, to register it on each request. * - * @param string $slug Slug to save the notice - * @param string $html The notice output HTML code - * @param array $arguments Arguments to Setup a notice - * @param int $expire After how much time (in seconds) the notice will stop showing. + * @param string $slug Slug to save the notice. + * @param string $html The notice output HTML code. + * @param array $arguments Arguments to Setup a notice. + * @param int $expire After how much time (in seconds) the notice will stop showing. * * @return stdClass Which notice was registered */ @@ -609,7 +616,7 @@ function tribe_transient_notice( $slug, $html, $arguments = [], $expire = null ) * * @since 4.7.7 * - * @param string $slug + * @param string $slug The slug of the transient notice to remove. */ function tribe_transient_notice_remove( $slug ) { Tribe__Admin__Notices::instance()->remove_transient( $slug ); @@ -618,9 +625,9 @@ function tribe_transient_notice_remove( $slug ) { /** * A quick internal way of sending errors using WP_Error * - * @param string|array $indexes Which Error we are looking for - * @param array $context Gives the Error context - * @param array $sprintf Allows variables on the message + * @param string|array $indexes Which Error we are looking for. + * @param array $context Gives the Error context. + * @param array $sprintf Allows variables on the message. * * @return WP_Error */ @@ -631,8 +638,8 @@ function tribe_error( $indexes, $context = [], $sprintf = [] ) { /** * Register a new error based on a Namespace * - * @param string|array $indexes A list of the namespaces and last item should be the error name - * @param string $message What is going to be the message associate with this indexes + * @param string|array $indexes A list of the namespaces and last item should be the error name. + * @param string $message What is going to be the message associate with this indexes. * * @return boolean */ @@ -649,7 +656,7 @@ function tribe_register_error( $indexes, $message ) { * @param string $slug Slug to save the asset - passes through `sanitize_title_with_dashes()`. * @param string $file The asset file to load (CSS or JS), including non-minified file extension. * @param array $deps The list of dependencies or callable function that will return a list of dependencies. - * @param string|array|null $action The WordPress action(s) to enqueue on, such as `wp_enqueue_scripts`, + * @param string|array|null $action The WordPress action(s) to enqueue on, such as `wp_enqueue_scripts`,. * `admin_enqueue_scripts`, or `login_enqueue_scripts`. * @param array $arguments See `Tribe__Assets::register()` for more info. * @@ -667,7 +674,7 @@ function tribe_asset( $origin, $slug, $file, $deps = [], $action = null, $argume * * @since 4.7 * - * @param string|array $slug Slug to enqueue + * @param string|array $slug Slug to enqueue. */ function tribe_asset_enqueue( $slug ) { /** @var Tribe__Assets $assets */ @@ -681,7 +688,7 @@ function tribe_asset_enqueue( $slug ) { * * @since 4.7 * - * @param string|array $group Which group(s) should be enqueued. + * @param string|array $group Which group(s) should be enqueued. */ function tribe_asset_enqueue_group( $group ) { /** @var Tribe__Assets $assets */ @@ -696,8 +703,8 @@ function tribe_asset_enqueue_group( $group ) { * @since 4.3 * @since 4.12.10 Added support for overriding arguments for individual assets. * - * @param object $origin The main Object for the plugin you are enqueueing the script/style for - * @param array $assets { + * @param object $origin The main Object for the plugin you are enqueueing the script/style for. + * @param array $assets {. * Indexed array, don't use any associative key. * E.g.: [ 'slug-my-script', 'my/own/path.js', [ 'jquery' ] ] * @@ -705,10 +712,10 @@ function tribe_asset_enqueue_group( $group ) { * @type string $file Which file will be loaded, either CSS or JS * @type array $deps (optional) Dependencies * } - * @param string $action A WordPress hook that will automatically enqueue this asset once fired - * @param array $arguments Look at `Tribe__Assets::register()` for more info + * @param string $action A WordPress hook that will automatically enqueue this asset once fired. + * @param array $arguments Look at `Tribe__Assets::register()` for more info. * - * @return array Which Assets were registered + * @return array Which Assets were registered */ function tribe_assets( $origin, $assets, $action = null, $arguments = [] ) { $registered = []; @@ -746,7 +753,7 @@ function tribe_assets( $origin, $assets, $action = null, $arguments = [] ) { * * @since 4.7.4 * - * @param bool $doing_frontend Whether what is being done happens in the + * @param bool $doing_frontend Whether what is being done happens in the. * context of the frontend or not. */ function tribe_doing_frontend( $doing_frontend ) { @@ -770,7 +777,7 @@ function tribe_is_frontend() { * * @since 4.6.2 * - * @param bool $is_frontend + * @param bool $is_frontend. */ return (bool) apply_filters( 'tribe_doing_frontend', false ); } @@ -844,14 +851,14 @@ function tribe_cache() { * @since 4.12.6 * * @param string|array $group Which group(s) should be enqueued. - * @param bool $echo Whether to print the group(s) tag(s) to the page or not; default to `true` to + * @param bool $echo Whether to print the group(s) tag(s) to the page or not; default to `true` to. * print the HTML `script` (JS) and `link` (CSS) tags to the page. * * @return string The `script` and `link` HTML tags produced for the group(s). */ function tribe_asset_print_group( $group, $echo = true ) { /** @var \Tribe__Assets $assets */ - $assets = tribe( 'assets' ); + $assets = tribe( 'assets' ); return $assets->print_group($group, $echo); } @@ -865,7 +872,7 @@ function tribe_asset_print_group( $group, $echo = true ) { * * @since 4.12.10 * - * @param null|string $tag The shortcode tag name, or null to check if doing any shortcode. + * @param ?string $tag The shortcode tag name, or null to check if doing any shortcode. * * @return bool Whether the shortcode is currently being run. */ diff --git a/src/functions/utils.php b/src/functions/utils.php index c01cd540b9..9943c88d30 100644 --- a/src/functions/utils.php +++ b/src/functions/utils.php @@ -76,7 +76,7 @@ function tribe_register_plugin( $file_path, $main_class, $version, $classes_req */ function tribe_check_plugin( $main_class ) { - $tribe_dependency = Tribe__Dependency::instance(); + $tribe_dependency = tribe( Tribe__Dependency::class ); return $tribe_dependency->check_plugin( $main_class ); @@ -131,8 +131,8 @@ function tribe_exit( $status = '' ) { /** * Filters the callback to call in place of `die()`. * - * @param callable $handler The `die` replacement callback. - * @param string $status The exit/die status. + * @param callable|string $handler The `die` replacement callback. + * @param string $status The exit/die status. */ $handler = apply_filters( 'tribe_exit', $handler, $status ); @@ -743,30 +743,40 @@ function tribe_register_rest_route( $namespace, $route, $args = [], $override = * * @since 4.9.12 * + * @param array $args Either an array of options for the endpoint, or an array of arrays for + * multiple methods. Default empty array. * @param string $namespace The first URL segment after core prefix. Should be unique to your package/plugin. * @param string $route The base URL for route you are adding. * @param bool $override Optional. If the route already exists, should we override it? True overrides, * false merges (with newer overriding if duplicate keys exist). Default false. - * - * @param array $args Either an array of options for the endpoint, or an array of arrays for - * multiple methods. Default empty array. */ - $args = apply_filters( 'tribe_register_rest_route_args_' . $namespace . $route, $args, $namespace, $route, $override ); + $args = apply_filters( + 'tribe_register_rest_route_args_' . $namespace . $route, + $args, + $namespace, + $route, + $override + ); /** * Allow plugins to customize REST API arguments and callbacks. * * @since 4.9.12 * + * @param array $args Either an array of options for the endpoint, or an array of arrays for + * multiple methods. Default empty array. * @param string $namespace The first URL segment after core prefix. Should be unique to your package/plugin. * @param string $route The base URL for route you are adding. * @param bool $override Optional. If the route already exists, should we override it? True overrides, * false merges (with newer overriding if duplicate keys exist). Default false. - * - * @param array $args Either an array of options for the endpoint, or an array of arrays for - * multiple methods. Default empty array. */ - $args = apply_filters( 'tribe_register_rest_route_args', $args, $namespace, $route, $override ); + $args = apply_filters( + 'tribe_register_rest_route_args', + $args, + $namespace, + $route, + $override + ); // Compatibility with version 5.5 of WordPress to avoid notices. if ( diff --git a/src/views/dialog/button.php b/src/views/dialog/button.php index d872ffcda7..29190799de 100644 --- a/src/views/dialog/button.php +++ b/src/views/dialog/button.php @@ -41,6 +41,6 @@ class="" value="" - + disabled aria-disabled="true" > From 9d0bb7bf4d45203de10aacc38273a820d172d6ca Mon Sep 17 00:00:00 2001 From: Stephen Page Date: Fri, 12 Jan 2024 10:50:34 -0500 Subject: [PATCH 6/6] Fixing failures --- src/Tribe/Admin/Activation_Page.php | 4 +- .../Datetime_Conditional_Abstract.php | 37 +++- src/Tribe/Admin/Help_Page.php | 6 +- src/Tribe/Admin/Helpers.php | 52 +++-- src/Tribe/Admin/Notice/Date_Based.php | 61 ++++-- src/Tribe/Admin/Notice/Marketing.php | 207 ------------------ src/Tribe/Admin/Notice/Php_Version.php | 20 +- .../Admin/Notice/Plugin_Upgrade_Notice.php | 44 ++-- src/Tribe/App_Shop.php | 2 +- src/Tribe/Credits.php | 2 +- src/Tribe/Main.php | 2 +- 11 files changed, 143 insertions(+), 294 deletions(-) delete mode 100644 src/Tribe/Admin/Notice/Marketing.php diff --git a/src/Tribe/Admin/Activation_Page.php b/src/Tribe/Admin/Activation_Page.php index 8782dc82bb..d7fdff3a1a 100644 --- a/src/Tribe/Admin/Activation_Page.php +++ b/src/Tribe/Admin/Activation_Page.php @@ -337,12 +337,10 @@ protected function disable_default_settings_page() { * Prints the splash screen. * * @param string $context - * - * @return string|null */ public function display_page() { if ( empty( $this->args[ $this->current_context . '_page_title' ] ) || empty( $this->args[ $this->current_context . '_page_template'] ) ) { - return null; + return; } do_action( 'tribe_settings_top' ); diff --git a/src/Tribe/Admin/Conditional_Content/Datetime_Conditional_Abstract.php b/src/Tribe/Admin/Conditional_Content/Datetime_Conditional_Abstract.php index 47c93351c3..a0da0fa377 100644 --- a/src/Tribe/Admin/Conditional_Content/Datetime_Conditional_Abstract.php +++ b/src/Tribe/Admin/Conditional_Content/Datetime_Conditional_Abstract.php @@ -1,4 +1,8 @@ slug}_start_date", $date, $this ); @@ -92,6 +107,7 @@ protected function get_start_time() { * Unix datetime for content end. * * @since 4.14.7 + * * @return \Tribe\Utils\Date_I18n - Date Object */ protected function get_end_time() { @@ -107,8 +123,8 @@ protected function get_end_time() { * Allow filtering of the end date for testing. * * @since 4.14.7 - * @param \DateTime $date - Unix timestamp for end date - * @param object $this + * @param \DateTime $date Unix timestamp for end date. + * @param object $instance the conditional content object. */ $date = apply_filters( "tec_admin_conditional_content_{$this->slug}_end_date", $date, $this ); @@ -119,7 +135,8 @@ protected function get_end_time() { * Whether the content should display. * * @since 4.14.7 - * @return boolean - Whether the content should display + * + * @return boolean Whether the content should display. */ protected function should_display() { $now = Dates::build_date_object( 'now', 'UTC' ); @@ -131,12 +148,10 @@ protected function should_display() { * Allow filtering whether the content should display. * * @since 4.14.7 - * @param bool $should_display - whether the content should display - * @param object $this - the conditional content object + * @param bool $should_display whether the content should display. + * @param object $instance the conditional content object. */ - $should_display = apply_filters( "tec_admin_conditional_content_{$this->slug}_should_display", $display, $this ); - - return $should_display; + return apply_filters( "tec_admin_conditional_content_{$this->slug}_should_display", $display, $this ); } /** diff --git a/src/Tribe/Admin/Help_Page.php b/src/Tribe/Admin/Help_Page.php index 6a13ac4c34..88779d70c7 100644 --- a/src/Tribe/Admin/Help_Page.php +++ b/src/Tribe/Admin/Help_Page.php @@ -57,7 +57,7 @@ public function admin_body_class( $classes ) { * @return bool */ public function is_current_page() { - $is_screen = Tribe__Admin__Helpers::instance()->is_screen(); + $is_screen = tribe( 'admin.helpers' )->is_screen(); if ( ! $is_screen ) { return false; @@ -81,7 +81,7 @@ public function is_current_page() { * @return bool */ public function is_tec_events_help_page() { - $is_screen = Tribe__Admin__Helpers::instance()->is_screen(); + $is_screen = tribe( 'admin.helpers' )->is_screen(); if ( ! $is_screen ) { return false; @@ -100,7 +100,7 @@ public function is_tec_events_help_page() { * @return bool */ public function is_tec_tickets_help_page() { - $is_screen = Tribe__Admin__Helpers::instance()->is_screen(); + $is_screen = tribe( 'admin.helpers' )->is_screen(); if ( ! $is_screen ) { return false; diff --git a/src/Tribe/Admin/Helpers.php b/src/Tribe/Admin/Helpers.php index 7f1d832b29..fa43477265 100644 --- a/src/Tribe/Admin/Helpers.php +++ b/src/Tribe/Admin/Helpers.php @@ -1,31 +1,34 @@ is_wp_screen() ) { return false; } $defaults = apply_filters( 'tribe_is_post_type_screen_post_types', Tribe__Main::get_post_types() ); - // Match any Post Type from Tribe + // Match any Post Type from TEC. if ( is_null( $post_type ) && in_array( $current_screen->post_type, $defaults ) ) { return true; } - // Match any of the post_types set + // Match any of the post_types set. if ( ! is_scalar( $post_type ) && in_array( $current_screen->post_type, (array) $post_type ) ) { return true; } - // Match a specific Post Type + // Match a specific Post Type. if ( $current_screen->post_type === $post_type ) { return true; } @@ -102,14 +106,14 @@ public function is_post_type_screen( $post_type = null ) { /** * Matcher for administration pages that are from Tribe the easier way * - * @param string|array|null $id What will be checked to see if we return true or false + * @param string|array|null $id What will be checked to see if we return true or false. * * @return boolean */ public function is_screen( $id = null ) { global $current_screen; - // Not in the admin we don't even care + // Not in the admin we don't even care. if ( ! is_admin() ) { return false; } @@ -134,7 +138,7 @@ public function is_screen( $id = null ) { return true; } - // Match any of the pages set + // Match any of the pages set. if ( ! is_scalar( $id ) && in_array( $current_screen->id, (array) $id ) ) { return true; } @@ -149,21 +153,21 @@ public function is_screen( $id = null ) { if ( in_array( $current_screen->post_type, $defaults ) ) { return true; } - return false; + return false; } /** * Matcher for administration pages action * - * @param string|array|null $action What will be checked to see if we return true or false + * @param mixed $action What will be checked to see if we return true or false. * * @return boolean */ public function is_action( $action = null ) { global $current_screen; - // Not in the admin we don't even care + // Not in the admin we don't even care. if ( ! is_admin() ) { return false; } @@ -173,17 +177,17 @@ public function is_action( $action = null ) { return false; } - // Avoid Notices by checking the object type of WP_Screen + // Avoid Notices by checking the object type of WP_Screen. if ( ! $this->is_wp_screen() ) { return false; } - // Match any of the pages set + // Match any of the pages set. if ( ! is_scalar( $action ) && in_array( $current_screen->action, (array) $action ) ) { return true; } - // Match a specific page + // Match a specific page. if ( $current_screen->action === $action ) { return true; } diff --git a/src/Tribe/Admin/Notice/Date_Based.php b/src/Tribe/Admin/Notice/Date_Based.php index d3ae9ac9e1..fca8367ef0 100644 --- a/src/Tribe/Admin/Notice/Date_Based.php +++ b/src/Tribe/Admin/Notice/Date_Based.php @@ -9,6 +9,9 @@ use Tribe__Date_Utils as Dates; +/** + * Class Date_Based + */ abstract class Date_Based { /** * The slug used to make filters specific to an individual notice. @@ -121,10 +124,13 @@ abstract class Date_Based { 'tribe_events_page_tribe-common', // Old Settings & Welcome. 'events_page_tribe-common', // Settings & Welcome. 'toplevel_page_tribe-common', // Settings & Welcome. - 'tribe_events_page_aggregator', // Import page - 'edit-tribe_events', // Events admin list + 'tribe_events_page_aggregator', // Import page. + 'edit-tribe_events', // Events admin list. ]; + /** + * Constructor. + */ public function __construct() { $tribe_dependency = tribe( \Tribe__Dependency::class ); $this->tec_is_active = $tribe_dependency->is_plugin_active( 'Tribe__Events__Main' ); @@ -137,15 +143,18 @@ public function __construct() { // If we have an extension date defined. if ( ! empty( $this->get_extension_time() ) ) { - // If the sale has started and + // If the sale has started. if ( $notice_start <= $now && $notice_end < $now && $now < $extension_date ) { - add_filter( "tribe_{$this->slug}_notice_end_date", function() { - return $this->get_extension_time(); - }); + add_filter( + "tribe_{$this->slug}_notice_end_date", + function () { + return $this->get_extension_time(); + } + ); } } @@ -169,14 +178,14 @@ public function hook() { public function hook_notice() { tribe_notice( $this->slug, - [ $this, "display_notice" ], + [ $this, 'display_notice' ], [ 'type' => 'tribe-banner', 'dismiss' => 1, 'priority' => -1, 'wrap' => false, ], - [ $this, "should_display" ] + [ $this, 'should_display' ] ); } @@ -187,7 +196,7 @@ public function hook_notice() { * * @return string The HTML string to be displayed. */ - abstract function display_notice(); + abstract public function display_notice(); /** * Function to get and filter the screens the notice is displayed on. @@ -257,7 +266,6 @@ public function should_display() { $now = Dates::build_date_object( 'now', 'UTC' ); $notice_start = $this->get_start_time(); $notice_end = $this->get_end_time(); - $should_display = $notice_start <= $now && $now < $notice_end; @@ -266,10 +274,14 @@ public function should_display() { * * @since 4.14.2 * - * @param boolean $should_display Whether the notice should display. - * @param Tribe__Admin__Notice_Date_Based $notice The notice object. + * @param boolean $should_display Whether the notice should display. + * @param Date_Based $notice The notice object. */ - return apply_filters( "tribe_{$this->slug}_notice_should_display", $should_display, $this ); + return apply_filters( + "tribe_{$this->slug}_notice_should_display", + $should_display, + $this + ); } /** @@ -291,7 +303,8 @@ public function get_start_time() { * * @since 4.14.2 * - * @param \DateTime $date Date object for the notice start. + * @param \DateTime $date Date object for the notice start. + * @param Date_Based $notice The notice object. */ $date = apply_filters( "tribe_{$this->slug}_notice_start_date", $date, $this ); @@ -312,13 +325,14 @@ public function get_end_time() { } /** - * Allow filtering of the end date DateTime object, - * to allow for things like "the day after" ( $date->modify( '+1 day' ) ) and such. - * - * @since 4.14.2 - * - * @param \DateTime $date Date object for the notice end. - */ + * Allow filtering of the end date DateTime object, + * to allow for things like "the day after" ( $date->modify( '+1 day' ) ) and such. + * + * @since 4.14.2 + * + * @param \DateTime $date Date object for the notice end. + * @param Date_Based $notice The notice object. + */ $date = apply_filters( "tribe_{$this->slug}_notice_end_date", $date, $this ); return $date; @@ -348,7 +362,8 @@ public function get_extension_time() { * * @since 4.14.2 * - * @param \DateTime $date Date object for the notice end. + * @param \DateTime $date Date object for the notice end. + * @param Date_Based $notice The notice object. */ $date = apply_filters( "tribe_{$this->slug}_notice_extension_date", $date, $this ); @@ -373,4 +388,4 @@ public function get_template() { return $this->template; } -} \ No newline at end of file +} diff --git a/src/Tribe/Admin/Notice/Marketing.php b/src/Tribe/Admin/Notice/Marketing.php deleted file mode 100644 index ecb017af2e..0000000000 --- a/src/Tribe/Admin/Notice/Marketing.php +++ /dev/null @@ -1,207 +0,0 @@ -tec_is_active = $tribe_dependency->is_plugin_active( 'Tribe__Events__Main' ); - $this->et_is_active = $tribe_dependency->is_plugin_active( 'Tribe__Tickets__Main' ); - } - - /** - * Register the various Marketing notices. - * - * @since 4.7.23 - * @deprecated 5.1.10 - */ - public function hook() { - _deprecated_function( __METHOD__, '5.1.10', 'See Tribe\Admin\Notice\Date_Based.' ); - $this->black_friday_hook_notice(); - } - - /** - * Register the Black Friday notice. - * - * @since 4.12.14 - * @deprecated 5.1.10 - */ - public function black_friday_hook_notice() { - _deprecated_function( __METHOD__, '5.1.10', 'See Tribe\Admin\Notice\Marketing\Black_Friday.' ); - - tribe_notice( - 'black-friday', - [ $this, 'black_friday_display_notice' ], - [ - 'type' => 'tribe-banner', - 'dismiss' => 1, - 'priority' => -1, - 'wrap' => false, - ], - [ $this, 'black_friday_should_display' ] - ); - } - - /** - * Unix time for Monday of Thanksgiving week @ 11am UTC. (11am UTC is 6am EST). - * - * @since 4.12.14 - * @deprecated 5.1.10 - * - * @return int - */ - public function get_black_friday_start_time() { - _deprecated_function( __METHOD__, '5.1.10', 'See Tribe\Admin\Notice\Marketing\Black_Friday.' ); - - $date = Dates::build_date_object( 'fourth Thursday of November ' . date( 'Y' ), 'UTC' ); - $date = $date->modify( '-3 days' ); - $date = $date->setTime( 11, 0 ); - - $start_time = $date->format( 'U' ); - - /** - * Allow filtering of the Black Friday sale start date, mainly for testing purposes. - * - * @since 4.12.14 - * - * @param int $bf_start_date Unix time for the Monday of Thanksgiving week @ 6am UTC. - */ - return apply_filters( 'tribe_black_friday_start_time', $start_time ); - } - - /** - * Unix time for Dec 1 @ 5am UTC. (5am UTC is 12am EST). - * - * @since 4.12.14 - * @deprecated 5.1.10 - * - * @return int - */ - public function get_black_friday_end_time() { - _deprecated_function( __METHOD__, '5.1.10', 'See Tribe\Admin\Notice\Marketing\Black_Friday.' ); - - $date = Dates::build_date_object( 'December 1st', 'UTC' ); - $date = $date->setTime( 5, 0 ); - - $end_time = $date->format( 'U' ); - - /** - * Allow filtering of the Black Friday sale end date, mainly for testing purposes. - * - * @since 4.12.14 - * - * @param int $bf_end_date Unix time for Dec 1 @ 6am UTC. - */ - return apply_filters( 'tribe_black_friday_end_time', $end_time ); - } - - /** - * Whether the Black Friday notice should display. - * - * Unix times for Monday of Thanksgiving week @ 6am UTC and Dec 1 2020 @ 6am UTC. - * 6am UTC is midnight for TheEventsCalendar.com, which uses the America/Los_Angeles time zone. - * - * @since 4.12.14 - * @deprecated 5.1.10 - * - * @return boolean - */ - public function black_friday_should_display() { - _deprecated_function( __METHOD__, '5.1.10', 'See Tribe\Admin\Notice\Marketing\Black_Friday.' ); - - // If upsells have been manually hidden, respect that. - if ( tec_should_hide_upsell() ) { - return false; - } - - $now = Dates::build_date_object( 'now', 'UTC' )->format( 'U' ); - $bf_sale_start = $this->get_black_friday_start_time(); - $bf_sale_end = $this->get_black_friday_end_time(); - - $current_screen = get_current_screen(); - - $screens = [ - 'tribe_events_page_tribe-app-shop', // App shop. - 'events_page_tribe-app-shop', // App shop. - 'tribe_events_page_tribe-common', // Settings & Welcome. - 'tribe_events_page_tec-events-settings', // New Settings & Welcome. - 'events_page_tribe-common', // Settings & Welcome. - 'toplevel_page_tribe-common', // Settings & Welcome. - ]; - - // If not a valid screen, don't display. - if ( empty( $current_screen->id ) || ! in_array( $current_screen->id, $screens, true ) ) { - return false; - } - - return $bf_sale_start <= $now && $now < $bf_sale_end; - } - - /** - * HTML for the Black Friday notice. - * - * @since 4.12.14 - * @deprecated 5.1.10 - * - * @return string - */ - public function black_friday_display_notice() { - _deprecated_function( __METHOD__, '5.1.10', 'See Tribe\Admin\Notice\Marketing\Black_Friday.' ); - - Tribe__Assets::instance()->enqueue( [ 'tribe-common-admin' ] ); - - $current_screen = get_current_screen(); - - $icon_url = Tribe__Main::instance()->plugin_url . 'src/resources/images/icons/sale-burst.svg'; - $cta_url = 'https://evnt.is/bf' . date( 'Y' ); - $screens = [ - 'tribe_events_page_tribe-common', - 'tribe_events_page_tec-events-settings', - 'events_page_tribe-common', - 'toplevel_page_tribe-common', - ]; - - // If we are on the settings page or a welcome page, change the Black Friday URL. - if ( - ! empty( $current_screen->id ) - && in_array( $current_screen->id, $screens ) - ) { - if ( isset( $_GET['welcome-message-the-events-calendar'] ) || isset( $_GET['welcome-message-event-tickets' ] ) ) { - $cta_url .= 'welcome'; - } else { - $cta_url .= 'settings'; - } - } - - ob_start(); - - include Tribe__Main::instance()->plugin_path . 'src/admin-views/notices/tribe-bf-general.php'; - - return ob_get_clean(); - } -} diff --git a/src/Tribe/Admin/Notice/Php_Version.php b/src/Tribe/Admin/Notice/Php_Version.php index cfb18e4eeb..a1ae1fac31 100644 --- a/src/Tribe/Admin/Notice/Php_Version.php +++ b/src/Tribe/Admin/Notice/Php_Version.php @@ -1,12 +1,26 @@ get_active_plugins(); + $active_plugins = tribe( Tribe__Dependency::class )->get_active_plugins(); foreach ( $active_plugins as $active_plugin ) { diff --git a/src/Tribe/Admin/Notice/Plugin_Upgrade_Notice.php b/src/Tribe/Admin/Notice/Plugin_Upgrade_Notice.php index 819d85ba54..10ee3d388f 100644 --- a/src/Tribe/Admin/Notice/Plugin_Upgrade_Notice.php +++ b/src/Tribe/Admin/Notice/Plugin_Upgrade_Notice.php @@ -7,6 +7,13 @@ * the one belonging to the current stable accessible via WP SVN - at least by * default). */ + +// phpcs:disable TEC.Classes.ValidClassName.NotSnakeCase +// phpcs:disable PEAR.NamingConventions.ValidClassName.Invalid + +/** + * Class Tribe__Admin__Notice__Plugin_Upgrade_Notice + */ class Tribe__Admin__Notice__Plugin_Upgrade_Notice { /** * Currently installed version of the plugin @@ -39,8 +46,8 @@ class Tribe__Admin__Notice__Plugin_Upgrade_Notice { * are any upgrade notices worth displaying. If not provided, an object of the * default type will be created (which connects to WP SVN). * - * @param string $current_version - * @param string $plugin_path (ie "plugin-dir/main-file.php") + * @param string $current_version The current version (ie "4.0.1"). + * @param string $plugin_path The plugin path (ie "plugin-dir/main-file.php"). */ public function __construct( $current_version, $plugin_path ) { $this->current_version = $current_version; @@ -119,7 +126,8 @@ protected function discover_upgrade_notice() { * @var string $url * @var string $plugin_path */ - $readme_url = apply_filters( 'tribe_plugin_upgrade_readme_url', + $readme_url = apply_filters( + 'tribe_plugin_upgrade_readme_url', $this->form_wp_svn_readme_url(), $this->plugin_path ); @@ -143,7 +151,8 @@ protected function discover_upgrade_notice() { * @var string $upgrade_notice * @var string $plugin_path */ - return apply_filters( 'tribe_plugin_upgrade_notice', + return apply_filters( + 'tribe_plugin_upgrade_notice', $this->upgrade_notice, $this->plugin_path ); @@ -157,7 +166,7 @@ protected function discover_upgrade_notice() { */ protected function form_wp_svn_readme_url() { $parts = explode( '/', $this->plugin_path ); - $slug = empty( $parts[0] ) ? '' : $parts[0]; + $slug = empty( $parts[0] ) ? '' : $parts[0]; return esc_url( "https://plugins.svn.wordpress.org/$slug/trunk/readme.txt" ); } @@ -165,31 +174,30 @@ protected function form_wp_svn_readme_url() { * Given a standard Markdown-format WP readme.txt file, finds the first upgrade * notice (if any) for a version higher than $this->current_version. * - * @param string $readme - * @return string + * @param string $readme The contents of the readme.txt file. */ - protected function parse_for_upgrade_notice( $readme ) { + protected function parse_for_upgrade_notice( $readme ): void { $in_upgrade_notice = false; $in_version_notice = false; $readme_lines = explode( "\n", $readme ); foreach ( $readme_lines as $line ) { - // Once we leave the Upgrade Notice section (ie, we encounter a new section header), bail + // Once we leave the Upgrade Notice section (ie, we encounter a new section header), bail. if ( $in_upgrade_notice && 0 === strpos( $line, '==' ) ) { break; } - // Look out for the start of the Upgrade Notice section + // Look out for the start of the Upgrade Notice section. if ( ! $in_upgrade_notice && preg_match( '/^==\s*Upgrade\s+Notice\s*==/i', $line ) ) { $in_upgrade_notice = true; } - // Also test to see if we have left the version specific note (ie, we encounter a new sub heading or header) + // Also test to see if we have left the version specific note (ie, we encounter a new sub heading or header). if ( $in_upgrade_notice && $in_version_notice && 0 === strpos( $line, '=' ) ) { break; } - // Look out for the first applicable version-specific note within the Upgrade Notice section + // Look out for the first applicable version-specific note within the Upgrade Notice section. if ( $in_upgrade_notice && ! $in_version_notice && preg_match( '/^=\s*\[?([0-9\.]{3,})\]?\s*=/', $line, $matches ) ) { // Is this a higher version than currently installed? if ( version_compare( $matches[1], $this->current_version, '>' ) ) { @@ -197,7 +205,7 @@ protected function parse_for_upgrade_notice( $readme ) { } } - // Copy the details of the upgrade notice for the first higher version we find + // Copy the details of the upgrade notice for the first higher version we find. if ( $in_upgrade_notice && $in_version_notice ) { $this->upgrade_notice .= $line . "\n"; } @@ -208,14 +216,14 @@ protected function parse_for_upgrade_notice( $readme ) { * Convert the plugin version header and any links from Markdown to HTML. */ protected function format_upgrade_notice() { - // Convert [links](http://...) to tags + // Convert [links](http://...) to tags. $this->upgrade_notice = preg_replace( '/\[([^\]]*)\]\(([^\)]*)\)/', '${1}', $this->upgrade_notice ); - // Convert =4.0= headings to

4.0

tags + // Convert =4.0= headings to

4.0

tags. $this->upgrade_notice = preg_replace( '/=\s*([a-zA-Z0-9\.]{3,})\s*=/', '

${1}

', @@ -233,7 +241,9 @@ protected function format_upgrade_notice() { * #the-events-calendar-update .tribe-plugin-update-message { ... } */ public function display_message() { - $notice = wp_kses_post( $this->upgrade_notice ); - echo "
$notice
"; + printf( + '
%1$s
', + wp_kses_post( $this->upgrade_notice ) + ); } } diff --git a/src/Tribe/App_Shop.php b/src/Tribe/App_Shop.php index 850a954f9b..bd10528382 100755 --- a/src/Tribe/App_Shop.php +++ b/src/Tribe/App_Shop.php @@ -124,7 +124,7 @@ public function is_current_page() { return false; } - return Tribe__Admin__Helpers::instance()->is_screen( $this->admin_page ); + return tribe( 'admin.helpers' )->is_screen( $this->admin_page ); } /** diff --git a/src/Tribe/Credits.php b/src/Tribe/Credits.php index c87bc1f518..72996c9cb7 100755 --- a/src/Tribe/Credits.php +++ b/src/Tribe/Credits.php @@ -41,7 +41,7 @@ public function html_comment_credit( $after_html ) { * @return string */ public function rating_nudge( $footer_text ) { - $admin_helpers = Tribe__Admin__Helpers::instance(); + $admin_helpers = tribe( 'admin.helpers' ); add_filter( 'tribe_tickets_post_types', [ $this, 'tmp_return_tribe_events' ], 99 ); diff --git a/src/Tribe/Main.php b/src/Tribe/Main.php index 2c761728cf..2f47653422 100644 --- a/src/Tribe/Main.php +++ b/src/Tribe/Main.php @@ -503,7 +503,7 @@ public function toggle_js_class() { * @return bool Whether we should load Common Admin CSS or not. */ public function should_load_common_admin_css() { - $helper = Tribe__Admin__Helpers::instance(); + $helper = tribe( 'admin.helpers' ); // Are we on a post type screen? $is_post_type = $helper->is_post_type_screen();