From 0fbe48a17052802409d4c2caf82375abac686cc9 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 19 Oct 2023 12:31:16 -0600 Subject: [PATCH 01/15] define the wp-cli command varied on pantheon env --- pantheon-sessions.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pantheon-sessions.php b/pantheon-sessions.php index ded3b2f..b8a57bf 100644 --- a/pantheon-sessions.php +++ b/pantheon-sessions.php @@ -268,8 +268,11 @@ public static function force_first_load() { public static function check_native_primary_keys() { global $wpdb; $table_name = $wpdb->prefix . 'pantheon_sessions'; - $old_table = $wpdb->prefix . 'bak_pantheon_sessions'; - $query = "SHOW KEYS FROM {$table_name} WHERE key_name = 'PRIMARY';"; + $old_table = $wpdb->prefix . 'bak_pantheon_sessions'; + $query = "SHOW KEYS FROM {$table_name} WHERE key_name = 'PRIMARY';"; + $is_pantheon = isset( $_ENV['PANTHEON_ENVIRONMENT'] ) ? true : false; + $wp_cli_cmd = $is_pantheon ? 'terminus wp <site>.<env> --' : 'wp'; + $cli_add_index = $wp_cli_cmd . 'pantheon session add-index'; $key_existence = $wpdb->get_results( $query ); From 7d227859f2b618e7e0454106b6565d8afddcc08b Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 19 Oct 2023 12:31:33 -0600 Subject: [PATCH 02/15] update the notice --- pantheon-sessions.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pantheon-sessions.php b/pantheon-sessions.php index b8a57bf..ef2cd15 100644 --- a/pantheon-sessions.php +++ b/pantheon-sessions.php @@ -281,10 +281,16 @@ public static function check_native_primary_keys() { ?>

- wp pantheon session add-index and verify that the process completes successfully and that this message goes away to resolve this issue on your live environment.', 'wp-native-php-sessions' ) ); - ?> -

+ +

+

+ $cli_add_index" ) ); + ?> +

Date: Thu, 19 Oct 2023 12:31:50 -0600 Subject: [PATCH 03/15] vary the finalize/revert commands based on pantheon env --- pantheon-sessions.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/pantheon-sessions.php b/pantheon-sessions.php index ef2cd15..c3d0326 100644 --- a/pantheon-sessions.php +++ b/pantheon-sessions.php @@ -300,14 +300,18 @@ public static function check_native_primary_keys() { // Check for table existence and delete if present. if ( $wpdb->get_var( $query ) == $old_table ) { + $cli_key_finalize = $wp_cli_cmd . 'pantheon session primary-key-finalize'; + $cli_key_revert = $wp_cli_cmd . 'pantheon session primary-key-revert'; + // If an old table exists but has not been removed, suggest doing so. ?>

- wp pantheon session primary-key-finalize to clean up old data, or run wp pantheon session primary-key-revert if there were issues.', 'wp-native-php-sessions' ) ); - ?> -

+ $cli_key_finalize", "$cli_key_revert" ) ); + ?> +

query( $query ); $current_results = $results + ( $batch_size * $i ); From 356fe54ca125784ae940ef2e9269014af7ee5b20 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 19 Oct 2023 13:17:04 -0600 Subject: [PATCH 04/15] add a custom directory installer and use it for wptrt/admin-notices we want this library to be part of the plugin --- composer.json | 16 +- composer.lock | 309 ++++++++++++++++++--------- lib/admin-notices/LICENSE | 339 ++++++++++++++++++++++++++++++ lib/admin-notices/readme.md | 116 ++++++++++ lib/admin-notices/src/Dismiss.php | 166 +++++++++++++++ lib/admin-notices/src/Notice.php | 297 ++++++++++++++++++++++++++ lib/admin-notices/src/Notices.php | 115 ++++++++++ 7 files changed, 1257 insertions(+), 101 deletions(-) create mode 100644 lib/admin-notices/LICENSE create mode 100644 lib/admin-notices/readme.md create mode 100644 lib/admin-notices/src/Dismiss.php create mode 100644 lib/admin-notices/src/Notice.php create mode 100644 lib/admin-notices/src/Notices.php diff --git a/composer.json b/composer.json index 8083ba8..b41436b 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,10 @@ "email": "daniel@handbuilt.co" } ], + "require": { + "mnsami/composer-custom-directory-installer": "^2.0", + "wptrt/admin-notices": "^1.0" + }, "require-dev": { "pantheon-systems/pantheon-wordpress-upstream-tests": "dev-master", "pantheon-systems/pantheon-wp-coding-standards": "^2.0", @@ -34,7 +38,15 @@ }, "config": { "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true - } + "dealerdirect/phpcodesniffer-composer-installer": true, + "composer/installers": true, + "mnsami/composer-custom-directory-installer": true + }, + "sort-packages": true + }, + "extra": { + "installer-paths": { + "lib/{$name}/": ["wptrt/admin-notices"] + } } } diff --git a/composer.lock b/composer.lock index 97b6141..0dcf7a5 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,117 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b40b554af1a7b400e1dd4bff4afb982e", - "packages": [], + "content-hash": "104888d7217d064bbf2a3a1378841c75", + "packages": [ + { + "name": "mnsami/composer-custom-directory-installer", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/mnsami/composer-custom-directory-installer.git", + "reference": "85f66323978d0b1cb0e6acc7f69b3e7b912f82d9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/mnsami/composer-custom-directory-installer/zipball/85f66323978d0b1cb0e6acc7f69b3e7b912f82d9", + "reference": "85f66323978d0b1cb0e6acc7f69b3e7b912f82d9", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0", + "php": ">=5.3" + }, + "type": "composer-plugin", + "extra": { + "class": [ + "Composer\\CustomDirectoryInstaller\\LibraryPlugin", + "Composer\\CustomDirectoryInstaller\\PearPlugin", + "Composer\\CustomDirectoryInstaller\\PluginPlugin" + ], + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "psr-0": { + "Composer\\CustomDirectoryInstaller": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mina Nabil Sami", + "email": "mina.nsami@gmail.com" + } + ], + "description": "A composer plugin, to help install packages of different types in custom paths.", + "keywords": [ + "composer", + "composer-installer", + "composer-plugin" + ], + "support": { + "issues": "https://github.com/mnsami/composer-custom-directory-installer/issues", + "source": "https://github.com/mnsami/composer-custom-directory-installer/tree/2.0.0" + }, + "time": "2020-08-18T11:00:11+00:00" + }, + { + "name": "wptrt/admin-notices", + "version": "v1.0.4", + "source": { + "type": "git", + "url": "https://github.com/WPTT/admin-notices.git", + "reference": "1df860950b4198cc93e867873b1b571b51f908b0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/WPTT/admin-notices/zipball/1df860950b4198cc93e867873b1b571b51f908b0", + "reference": "1df860950b4198cc93e867873b1b571b51f908b0", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2", + "php": "~7.1", + "szepeviktor/phpstan-wordpress": "^0.6.0", + "wp-coding-standards/wpcs": "^2.3" + }, + "type": "library", + "autoload": { + "psr-4": { + "WPTRT\\AdminNotices\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "authors": [ + { + "name": "WordPress.org Theme Review Team", + "email": "themes@wordpress.org", + "homepage": "https://make.wordpress.org/themes", + "role": "Developer" + } + ], + "description": "A class to create admin-notices for the WordPress dashboard.", + "homepage": "https://github.com/WPTRT/admin-notices", + "keywords": [ + "wordpress" + ], + "support": { + "issues": "https://github.com/WPTRT/admin-notices/issues", + "source": "https://github.com/WPTT/admin-notices/tree/v1.0.4" + }, + "time": "2023-10-06T03:42:42+00:00" + } + ], "packages-dev": [ { "name": "automattic/vipwpcs", @@ -589,30 +698,30 @@ }, { "name": "doctrine/instantiator", - "version": "1.5.0", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b" + "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/0a0fa9780f5d4e507415a065172d26a98d02047b", - "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/c6222283fa3f4ac679f8b9ced9a4e23f163e80d0", + "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0", "shasum": "" }, "require": { - "php": "^7.1 || ^8.0" + "php": "^8.1" }, "require-dev": { - "doctrine/coding-standard": "^9 || ^11", + "doctrine/coding-standard": "^11", "ext-pdo": "*", "ext-phar": "*", - "phpbench/phpbench": "^0.16 || ^1", - "phpstan/phpstan": "^1.4", - "phpstan/phpstan-phpunit": "^1", - "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", - "vimeo/psalm": "^4.30 || ^5.4" + "phpbench/phpbench": "^1.2", + "phpstan/phpstan": "^1.9.4", + "phpstan/phpstan-phpunit": "^1.3", + "phpunit/phpunit": "^9.5.27", + "vimeo/psalm": "^5.4" }, "type": "library", "autoload": { @@ -639,7 +748,7 @@ ], "support": { "issues": "https://github.com/doctrine/instantiator/issues", - "source": "https://github.com/doctrine/instantiator/tree/1.5.0" + "source": "https://github.com/doctrine/instantiator/tree/2.0.0" }, "funding": [ { @@ -655,7 +764,7 @@ "type": "tidelift" } ], - "time": "2022-12-30T00:15:36+00:00" + "time": "2022-12-30T00:23:10+00:00" }, { "name": "fabpot/goutte", @@ -719,16 +828,16 @@ }, { "name": "fig-r/psr2r-sniffer", - "version": "1.5.0", + "version": "1.5.1", "source": { "type": "git", "url": "https://github.com/php-fig-rectified/psr2r-sniffer.git", - "reference": "53ca1ecd62b0dc2ab8ea48635f583cb361c5e8f2" + "reference": "c950b88ed7ad8ae115e11896bbe36d5896aa4f36" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig-rectified/psr2r-sniffer/zipball/53ca1ecd62b0dc2ab8ea48635f583cb361c5e8f2", - "reference": "53ca1ecd62b0dc2ab8ea48635f583cb361c5e8f2", + "url": "https://api.github.com/repos/php-fig-rectified/psr2r-sniffer/zipball/c950b88ed7ad8ae115e11896bbe36d5896aa4f36", + "reference": "c950b88ed7ad8ae115e11896bbe36d5896aa4f36", "shasum": "" }, "require": { @@ -769,9 +878,9 @@ ], "support": { "issues": "https://github.com/php-fig-rectified/psr2r-sniffer/issues", - "source": "https://github.com/php-fig-rectified/psr2r-sniffer/tree/1.5.0" + "source": "https://github.com/php-fig-rectified/psr2r-sniffer/tree/1.5.1" }, - "time": "2023-01-01T15:31:05+00:00" + "time": "2023-09-23T19:16:19+00:00" }, { "name": "guzzlehttp/guzzle", @@ -1547,16 +1656,16 @@ }, { "name": "phpcsstandards/phpcsextra", - "version": "1.1.1", + "version": "1.1.2", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/PHPCSExtra.git", - "reference": "98bcdbacbda14b1db85f710b1853125726795bbc" + "reference": "746c3190ba8eb2f212087c947ba75f4f5b9a58d5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHPCSExtra/zipball/98bcdbacbda14b1db85f710b1853125726795bbc", - "reference": "98bcdbacbda14b1db85f710b1853125726795bbc", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSExtra/zipball/746c3190ba8eb2f212087c947ba75f4f5b9a58d5", + "reference": "746c3190ba8eb2f212087c947ba75f4f5b9a58d5", "shasum": "" }, "require": { @@ -1606,7 +1715,7 @@ "issues": "https://github.com/PHPCSStandards/PHPCSExtra/issues", "source": "https://github.com/PHPCSStandards/PHPCSExtra" }, - "time": "2023-08-26T04:46:45+00:00" + "time": "2023-09-20T22:06:18+00:00" }, { "name": "phpcsstandards/phpcsutils", @@ -1683,16 +1792,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.24.0", + "version": "1.24.2", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "3510b0a6274cc42f7219367cb3abfc123ffa09d6" + "reference": "bcad8d995980440892759db0c32acae7c8e79442" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/3510b0a6274cc42f7219367cb3abfc123ffa09d6", - "reference": "3510b0a6274cc42f7219367cb3abfc123ffa09d6", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/bcad8d995980440892759db0c32acae7c8e79442", + "reference": "bcad8d995980440892759db0c32acae7c8e79442", "shasum": "" }, "require": { @@ -1724,22 +1833,22 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.0" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.2" }, - "time": "2023-09-07T20:46:32+00:00" + "time": "2023-09-26T12:28:12+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "9.2.28", + "version": "9.2.29", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "7134a5ccaaf0f1c92a4f5501a6c9f98ac4dcc0ef" + "reference": "6a3a87ac2bbe33b25042753df8195ba4aa534c76" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/7134a5ccaaf0f1c92a4f5501a6c9f98ac4dcc0ef", - "reference": "7134a5ccaaf0f1c92a4f5501a6c9f98ac4dcc0ef", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/6a3a87ac2bbe33b25042753df8195ba4aa534c76", + "reference": "6a3a87ac2bbe33b25042753df8195ba4aa534c76", "shasum": "" }, "require": { @@ -1796,7 +1905,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.28" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.29" }, "funding": [ { @@ -1804,7 +1913,7 @@ "type": "github" } ], - "time": "2023-09-12T14:36:20+00:00" + "time": "2023-09-19T04:57:46+00:00" }, { "name": "phpunit/php-file-iterator", @@ -2049,16 +2158,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.12", + "version": "9.6.13", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "a122c2ebd469b751d774aa0f613dc0d67697653f" + "reference": "f3d767f7f9e191eab4189abe41ab37797e30b1be" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a122c2ebd469b751d774aa0f613dc0d67697653f", - "reference": "a122c2ebd469b751d774aa0f613dc0d67697653f", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/f3d767f7f9e191eab4189abe41ab37797e30b1be", + "reference": "f3d767f7f9e191eab4189abe41ab37797e30b1be", "shasum": "" }, "require": { @@ -2132,7 +2241,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.12" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.13" }, "funding": [ { @@ -2148,7 +2257,7 @@ "type": "tidelift" } ], - "time": "2023-09-12T14:39:31+00:00" + "time": "2023-09-19T05:39:22+00:00" }, { "name": "psr/container", @@ -3369,32 +3478,32 @@ }, { "name": "slevomat/coding-standard", - "version": "8.13.4", + "version": "8.14.1", "source": { "type": "git", "url": "https://github.com/slevomat/coding-standard.git", - "reference": "4b2af2fb17773656d02fbfb5d18024ebd19fe322" + "reference": "fea1fd6f137cc84f9cba0ae30d549615dbc6a926" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/4b2af2fb17773656d02fbfb5d18024ebd19fe322", - "reference": "4b2af2fb17773656d02fbfb5d18024ebd19fe322", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/fea1fd6f137cc84f9cba0ae30d549615dbc6a926", + "reference": "fea1fd6f137cc84f9cba0ae30d549615dbc6a926", "shasum": "" }, "require": { "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7 || ^1.0", "php": "^7.2 || ^8.0", - "phpstan/phpdoc-parser": "^1.23.0", + "phpstan/phpdoc-parser": "^1.23.1", "squizlabs/php_codesniffer": "^3.7.1" }, "require-dev": { "phing/phing": "2.17.4", "php-parallel-lint/php-parallel-lint": "1.3.2", - "phpstan/phpstan": "1.10.26", - "phpstan/phpstan-deprecation-rules": "1.1.3", - "phpstan/phpstan-phpunit": "1.3.13", + "phpstan/phpstan": "1.10.37", + "phpstan/phpstan-deprecation-rules": "1.1.4", + "phpstan/phpstan-phpunit": "1.3.14", "phpstan/phpstan-strict-rules": "1.5.1", - "phpunit/phpunit": "7.5.20|8.5.21|9.6.8|10.2.6" + "phpunit/phpunit": "8.5.21|9.6.8|10.3.5" }, "type": "phpcodesniffer-standard", "extra": { @@ -3418,7 +3527,7 @@ ], "support": { "issues": "https://github.com/slevomat/coding-standard/issues", - "source": "https://github.com/slevomat/coding-standard/tree/8.13.4" + "source": "https://github.com/slevomat/coding-standard/tree/8.14.1" }, "funding": [ { @@ -3430,7 +3539,7 @@ "type": "tidelift" } ], - "time": "2023-07-25T10:28:55+00:00" + "time": "2023-10-08T07:28:08+00:00" }, { "name": "spryker/code-sniffer", @@ -3950,25 +4059,25 @@ }, { "name": "symfony/deprecation-contracts", - "version": "v3.0.2", + "version": "v3.3.0", "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "26954b3d62a6c5fd0ea8a2a00c0353a14978d05c" + "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/26954b3d62a6c5fd0ea8a2a00c0353a14978d05c", - "reference": "26954b3d62a6c5fd0ea8a2a00c0353a14978d05c", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/7c3aff79d10325257a001fcf92d991f24fc967cf", + "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf", "shasum": "" }, "require": { - "php": ">=8.0.2" + "php": ">=8.1" }, "type": "library", "extra": { "branch-alias": { - "dev-main": "3.0-dev" + "dev-main": "3.4-dev" }, "thanks": { "name": "symfony/contracts", @@ -3997,7 +4106,7 @@ "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v3.0.2" + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.3.0" }, "funding": [ { @@ -4013,7 +4122,7 @@ "type": "tidelift" } ], - "time": "2022-01-02T09:55:41+00:00" + "time": "2023-05-23T14:45:45+00:00" }, { "name": "symfony/dom-crawler", @@ -4176,29 +4285,26 @@ }, { "name": "symfony/event-dispatcher-contracts", - "version": "v3.0.2", + "version": "v3.3.0", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher-contracts.git", - "reference": "7bc61cc2db649b4637d331240c5346dcc7708051" + "reference": "a76aed96a42d2b521153fb382d418e30d18b59df" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/7bc61cc2db649b4637d331240c5346dcc7708051", - "reference": "7bc61cc2db649b4637d331240c5346dcc7708051", + "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/a76aed96a42d2b521153fb382d418e30d18b59df", + "reference": "a76aed96a42d2b521153fb382d418e30d18b59df", "shasum": "" }, "require": { - "php": ">=8.0.2", + "php": ">=8.1", "psr/event-dispatcher": "^1" }, - "suggest": { - "symfony/event-dispatcher-implementation": "" - }, "type": "library", "extra": { "branch-alias": { - "dev-main": "3.0-dev" + "dev-main": "3.4-dev" }, "thanks": { "name": "symfony/contracts", @@ -4235,7 +4341,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v3.0.2" + "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v3.3.0" }, "funding": [ { @@ -4251,7 +4357,7 @@ "type": "tidelift" } ], - "time": "2022-01-02T09:55:41+00:00" + "time": "2023-05-23T14:45:45+00:00" }, { "name": "symfony/filesystem", @@ -5136,32 +5242,33 @@ }, { "name": "symfony/string", - "version": "v6.0.19", + "version": "v6.3.5", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "d9e72497367c23e08bf94176d2be45b00a9d232a" + "reference": "13d76d0fb049051ed12a04bef4f9de8715bea339" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/d9e72497367c23e08bf94176d2be45b00a9d232a", - "reference": "d9e72497367c23e08bf94176d2be45b00a9d232a", + "url": "https://api.github.com/repos/symfony/string/zipball/13d76d0fb049051ed12a04bef4f9de8715bea339", + "reference": "13d76d0fb049051ed12a04bef4f9de8715bea339", "shasum": "" }, "require": { - "php": ">=8.0.2", + "php": ">=8.1", "symfony/polyfill-ctype": "~1.8", "symfony/polyfill-intl-grapheme": "~1.0", "symfony/polyfill-intl-normalizer": "~1.0", "symfony/polyfill-mbstring": "~1.0" }, "conflict": { - "symfony/translation-contracts": "<2.0" + "symfony/translation-contracts": "<2.5" }, "require-dev": { "symfony/error-handler": "^5.4|^6.0", "symfony/http-client": "^5.4|^6.0", - "symfony/translation-contracts": "^2.0|^3.0", + "symfony/intl": "^6.2", + "symfony/translation-contracts": "^2.5|^3.0", "symfony/var-exporter": "^5.4|^6.0" }, "type": "library", @@ -5201,7 +5308,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v6.0.19" + "source": "https://github.com/symfony/string/tree/v6.3.5" }, "funding": [ { @@ -5217,7 +5324,7 @@ "type": "tidelift" } ], - "time": "2023-01-01T08:36:10+00:00" + "time": "2023-09-18T10:38:32+00:00" }, { "name": "symfony/translation", @@ -5388,20 +5495,21 @@ }, { "name": "symfony/yaml", - "version": "v6.0.19", + "version": "v6.3.3", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "deec3a812a0305a50db8ae689b183f43d915c884" + "reference": "e23292e8c07c85b971b44c1c4b87af52133e2add" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/deec3a812a0305a50db8ae689b183f43d915c884", - "reference": "deec3a812a0305a50db8ae689b183f43d915c884", + "url": "https://api.github.com/repos/symfony/yaml/zipball/e23292e8c07c85b971b44c1c4b87af52133e2add", + "reference": "e23292e8c07c85b971b44c1c4b87af52133e2add", "shasum": "" }, "require": { - "php": ">=8.0.2", + "php": ">=8.1", + "symfony/deprecation-contracts": "^2.5|^3", "symfony/polyfill-ctype": "^1.8" }, "conflict": { @@ -5410,9 +5518,6 @@ "require-dev": { "symfony/console": "^5.4|^6.0" }, - "suggest": { - "symfony/console": "For validating YAML files using the lint command" - }, "bin": [ "Resources/bin/yaml-lint" ], @@ -5442,7 +5547,7 @@ "description": "Loads and dumps YAML files", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/yaml/tree/v6.0.19" + "source": "https://github.com/symfony/yaml/tree/v6.3.3" }, "funding": [ { @@ -5458,7 +5563,7 @@ "type": "tidelift" } ], - "time": "2023-01-11T11:50:03+00:00" + "time": "2023-07-31T07:08:24+00:00" }, { "name": "theseer/tokenizer", @@ -5512,16 +5617,16 @@ }, { "name": "wp-coding-standards/wpcs", - "version": "3.0.0", + "version": "3.0.1", "source": { "type": "git", "url": "https://github.com/WordPress/WordPress-Coding-Standards.git", - "reference": "bb792cb331472b82c5d7f28fb9b8ec2d20f68826" + "reference": "b4caf9689f1a0e4a4c632679a44e638c1c67aff1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/bb792cb331472b82c5d7f28fb9b8ec2d20f68826", - "reference": "bb792cb331472b82c5d7f28fb9b8ec2d20f68826", + "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/b4caf9689f1a0e4a4c632679a44e638c1c67aff1", + "reference": "b4caf9689f1a0e4a4c632679a44e638c1c67aff1", "shasum": "" }, "require": { @@ -5568,7 +5673,13 @@ "source": "https://github.com/WordPress/WordPress-Coding-Standards", "wiki": "https://github.com/WordPress/WordPress-Coding-Standards/wiki" }, - "time": "2023-08-21T14:28:38+00:00" + "funding": [ + { + "url": "https://opencollective.com/thewpcc/contribute/wp-php-63406", + "type": "custom" + } + ], + "time": "2023-09-14T07:06:09+00:00" }, { "name": "yoast/phpunit-polyfills", @@ -5640,5 +5751,5 @@ "prefer-lowest": false, "platform": [], "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/lib/admin-notices/LICENSE b/lib/admin-notices/LICENSE new file mode 100644 index 0000000..d511905 --- /dev/null +++ b/lib/admin-notices/LICENSE @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/lib/admin-notices/readme.md b/lib/admin-notices/readme.md new file mode 100644 index 0000000..f4da7a5 --- /dev/null +++ b/lib/admin-notices/readme.md @@ -0,0 +1,116 @@ +# WPTRT Admin Notices + +This is a custom class allowing WordPress theme authors to add admin notices to the WordPress dashboard. +Its primary purpose is for providing a standardized method of creating admin notices in a consistent manner using the default WordPress styles. + +Notices created using this method are automatically dismissible. + +## Usage + +```php +$my_theme_notices = new \WPTRT\AdminNotices\Notices(); + +// Add a notice. +$my_theme_notices->add( (string) $id, (string) $title, (string) $content, (array) $options ); + +// Boot things up. +$my_theme_notices->boot(); +``` + +After you instantiate the `Notices` object using `$my_theme_notices = new \WPTRT\AdminNotices\Notices();` you can add new notices using the `add()` method. + +The arguments of this method are: + +| Parameter | Type | | Description +|---|---|---|---| +| `$id`| `string` | Required | A unique ID for this notice. **The ID can contain lowercase latin letters and underscores**. It is used to construct the option (or user-meta) key that will be strored in the database. | +| `$title` | `string` | Required | The title for your notice. If you don't want to use a title you can use set it to `false`. | +| `$message` | `string` | Required | The content for the notice you want to create. Please note that the only acceptable tags here are `

`, ``, ``, ``.| +| `$options` | `array` | Optional | Extra arguments for this notice. Can be used to alter the notice's default behavior. | + +The `$options` argument is an array that can have the following optional items: + +| Key | Type | Value | Default +|---|---|---|---| +| `scope` | `string` | Can be `global` or `user`. Determines if the dismissed status will be saved as an option or user-meta. | `global` | +| `type` | `string` | Can be one of `info`, `success`, `warning`, `error`. | `info` +| `alt_style` | `bool` | Set to true if you want to use alternative styles. These have a background-color depending on the `type` argument - in contrast to the normal styles that use a white background. | `false` | +| `capability` | `string` | The user capability required to see the notice. For a list of all available capabilities please refer to the [Roles and Capabilities](https://wordpress.org/support/article/roles-and-capabilities/) article. | `edit_theme_options` +| `screens` | `array` | An array of screens where the notice will be displayed. For a reference of all available screen-IDs, refer to [this article](https://codex.wordpress.org/Plugin_API/Admin_Screen_Reference). | `[]` | +| `option_prefix` | `string` | The prefix that will be used to build the option (or user-meta) name. Can contain lowercase latin letters and underscores. The actual option is built by combining the `option_prefix` argument with the defined ID from the 1st argument of the `add()` method. | `wptrt_notice_dismissed` | + +## Examples +You can add the following code within your theme's existing code. + +First we need to instantiate the `Notices` object: +```php +use WPTRT\AdminNotices\Notices; + +$my_theme_notices = new Notices(); +``` +To add a simple, default notice: +```php +$my_theme_notices->add( + 'my_theme_notice', // Unique ID. + esc_html__( 'Notice Title', 'textdomain' ), // The title for this notice. + esc_html__( 'Notice content', 'textdomain' ) // The content for this notice. +); +``` +The above example will create a new notice that will only show on all dashboard pages. When the notice gets dismissed, a new option will be saved in the database with the key `wptrt_notice_dismissed_my_theme_notice`. The key gets created by appending the `$id` to the default prefix for the option (`wptrt_notice_dismissed`), separated by an underscore. + +To add a more customized notice: + +```php +$my_theme_notices->add( + 'my_notice', // Unique ID. + esc_html__( 'Notice Title', 'textdomain' ), // The title for this notice. + esc_html__( 'Notice content', 'textdomain' ), // The content for this notice. + [ + 'scope' => 'user', // Dismiss is per-user instead of global. + 'screens' => [ 'themes' ], // Only show notice in the "themes" screen. + 'type' => 'warning', // Make this a warning (orange color). + 'alt_style' => true, // Use alt styles. + 'option_prefix' => 'my_theme', // Change the user-meta prefix. + ] +); +``` + +The above example will create a new notice that will only show in the "Themes" screen in the dashboard. When the notice gets dismissed, a new user-meta will be saved and the key for the stored user-meta will be `my_theme_my_notice`. The key gets created by appending the `$id` to our defined `option_prefix`, separated by an underscore. + +The `Notices` class can be used to add multiple notices. +Once you have finished adding the notices, you will have to run the `boot` method so that the notices can be added to the dashboard: +```php +$my_theme_notices->boot(); +``` + +To sum up all the above, a complete example of how to add an admin notice would look like this: + +```php +$my_theme_notices = new \WPTRT\AdminNotices\Notices(); +$my_theme_notices->add( 'my_theme_notice', __( 'Title', 'textdomain' ), __( 'Content', 'textdomain' ) ); +$my_theme_notices->boot(); +``` + +## Autoloading + +You'll need to use an autoloader with this. Ideally, this would be [Composer](https://getcomposer.org). However, we have a [basic autoloader](https://github.com/WPTRT/autoload) available to include with themes if needed. + +### Composer + +From the command line: + +```sh +composer require wptrt/admin-notices +``` + +### WPTRT Autoloader + +If using the WPTRT autoloader, use the following code: + +```php +include get_theme_file_path( 'path/to/autoload/src/Loader.php' ); + +$loader = new \WPTRT\Autoload\Loader(); +$loader->add( 'WPTRT\\AdminNotices\\Notice', get_theme_file_path( 'path/to/admin-notices/src' ) ); +$loader->register(); +``` diff --git a/lib/admin-notices/src/Dismiss.php b/lib/admin-notices/src/Dismiss.php new file mode 100644 index 0000000..22cfe98 --- /dev/null +++ b/lib/admin-notices/src/Dismiss.php @@ -0,0 +1,166 @@ + + * @copyright 2019 WPTRT + * @license https://www.gnu.org/licenses/gpl-2.0.html GPL-2.0-or-later + * @link https://github.com/WPTRT/admin-notices + */ + +namespace WPTRT\AdminNotices; + +/** + * The Dismiss class, responsible for dismissing and checking the status of admin notices. + * + * @since 1.0.0 + */ +class Dismiss { + + /** + * The notice-ID. + * + * @access private + * @since 1.0 + * @var string + */ + private $id; + + /** + * The prefix we'll be using for the option/user-meta. + * + * @access private + * @since 1.0 + * @var string + */ + private $prefix; + + /** + * The notice's scope. Can be "user" or "global". + * + * @access private + * @since 1.0 + * @var string + */ + private $scope; + + /** + * Constructor. + * + * @access public + * @since 1.0 + * @param string $id A unique ID for this notice. Can contain lowercase characters and underscores. + * @param string $prefix The prefix that will be used for the option/user-meta. + * @param string $scope Controls where the dismissal will be saved: user or global. + */ + public function __construct( $id, $prefix, $scope = 'global' ) { + + // Set the object properties. + $this->id = sanitize_key( $id ); + $this->prefix = sanitize_key( $prefix ); + $this->scope = ( in_array( $scope, [ 'global', 'user' ], true ) ) ? $scope : 'global'; + + // Handle AJAX requests to dismiss the notice. + add_action( 'wp_ajax_wptrt_dismiss_notice', [ $this, 'ajax_maybe_dismiss_notice' ] ); + + // Print the script after common.js. + add_action( 'admin_enqueue_scripts', array( $this, 'add_script' ) ); + } + + /** + * Print the script for dismissing the notice. + * + * @since 1.0 + * @return void + */ + public function add_script() { + + $id = esc_attr( $this->id ); + $nonce = wp_create_nonce( 'wptrt_dismiss_notice_' . $this->id ); + $admin_ajax_url = esc_url( admin_url( 'admin-ajax.php' ) ); + + $script = <<scope ) { + return ( get_user_meta( get_current_user_id(), "{$this->prefix}_{$this->id}", true ) ); + } + + return ( get_option( "{$this->prefix}_{$this->id}" ) ); + } + + /** + * Run check to see if we need to dismiss the notice. + * If all tests are successful then call the dismiss_notice() method. + * + * @access public + * @since 1.0 + * @return void + */ + public function ajax_maybe_dismiss_notice() { + + // Sanity check: Early exit if we're not on a wptrt_dismiss_notice action. + if ( ! isset( $_POST['action'] ) || 'wptrt_dismiss_notice' !== $_POST['action'] ) { + return; + } + + // Sanity check: Early exit if the ID of the notice is not the one from this object. + if ( ! isset( $_POST['id'] ) || $this->id !== $_POST['id'] ) { + return; + } + + // Security check: Make sure nonce is OK. + check_ajax_referer( 'wptrt_dismiss_notice_' . $this->id, 'nonce', true ); + + // If we got this far, we need to dismiss the notice. + $this->dismiss_notice(); + } + + /** + * Actually dismisses the notice. + * + * @access private + * @since 1.0 + * @return void + */ + private function dismiss_notice() { + if ( 'user' === $this->scope ) { + update_user_meta( get_current_user_id(), "{$this->prefix}_{$this->id}", true ); + return; + } + update_option( "{$this->prefix}_{$this->id}", true, false ); + } +} diff --git a/lib/admin-notices/src/Notice.php b/lib/admin-notices/src/Notice.php new file mode 100644 index 0000000..ec35dae --- /dev/null +++ b/lib/admin-notices/src/Notice.php @@ -0,0 +1,297 @@ + + * @copyright 2019 WPTRT + * @license https://www.gnu.org/licenses/gpl-2.0.html GPL-2.0-or-later + * @link https://github.com/WPTRT/admin-notices + */ + +namespace WPTRT\AdminNotices; + +/** + * The Admin_Notice class, responsible for creating admin notices. + * + * Each notice is a new instance of the object. + * + * @since 1.0.0 + */ +class Notice { + + /** + * The notice-ID. + * + * @access private + * @since 1.0 + * @var string + */ + private $id; + + /** + * The notice title. + * + * @access private + * @since 1.0 + * @var string + */ + private $title; + + /** + * The notice message. + * + * @access private + * @since 1.0 + * @var string + */ + private $message; + + /** + * An instance of the \WPTRT\AdminNotices\Dismiss object. + * + * @access public + * @since 1.0 + * @var \WPTRT\AdminNotices\Dismiss + */ + public $dismiss; + + /** + * The notice arguments. + * + * @access private + * @since 1.0 + * @var array + */ + private $options = [ + 'scope' => 'global', + 'type' => 'info', + 'alt_style' => false, + 'capability' => 'edit_theme_options', + 'option_prefix' => 'wptrt_notice_dismissed', + 'screens' => [], + ]; + + /** + * Allowed HTML in the message. + * + * @access private + * @since 1.0 + * @var array + */ + private $allowed_html = [ + 'p' => [], + 'a' => [ + 'href' => [], + 'rel' => [], + ], + 'em' => [], + 'strong' => [], + 'br' => [], + ]; + + /** + * An array of allowed types. + * + * @access private + * @since 1.0 + * @var array + */ + private $allowed_types = [ + 'info', + 'success', + 'error', + 'warning', + ]; + + /** + * Constructor. + * + * @access public + * @since 1.0 + * @param string $id A unique ID for this notice. Can contain lowercase characters and underscores. + * @param string $title The title for our notice. + * @param string $message The message for our notice. + * @param array $options An array of additional options to change the defaults for this notice. + * [ + * 'screens' => (array) An array of screens where the notice will be displayed. + * Leave empty to always show. + * Defaults to an empty array. + * 'scope' => (string) Can be "global" or "user". + * Determines if the dismissed status will be saved as an option or user-meta. + * Defaults to "global". + * 'type' => (string) Can be one of "info", "success", "warning", "error". + * Defaults to "info". + * 'alt_style' => (bool) Whether we want to use alt styles or not. + * Defaults to false. + * 'capability' => (string) The user capability required to see the notice. + * Defaults to "edit_theme_options". + * 'option_prefix' => (string) The prefix that will be used to build the option (or post-meta) name. + * Can contain lowercase latin letters and underscores. + * ]. + */ + public function __construct( $id, $title, $message, $options = [] ) { + + // Set the object properties. + $this->id = $id; + $this->title = $title; + $this->message = $message; + $this->options = wp_parse_args( $options, $this->options ); + + // Sanity check: Early exit if ID or message are empty. + if ( ! $this->id || ! $this->message ) { + return; + } + + /** + * Allow filtering the allowed HTML tags array. + * + * @since 1.0.2 + * @param array $allowed_html The list of allowed HTML tags. + * @return array + */ + $this->allowed_html = apply_filters( 'wptrt_admin_notices_allowed_html', $this->allowed_html ); + + // Instantiate the Dismiss object. + $this->dismiss = new Dismiss( $this->id, $this->options['option_prefix'], $this->options['scope'] ); + } + + /** + * Prints the notice. + * + * @access public + * @since 1.0 + * @return void + */ + public function the_notice() { + + // Early exit if we don't want to show this notice. + if ( ! $this->show() ) { + return; + } + + $html = $this->get_title(); + $html .= $this->get_message(); + + // Print the notice. + printf( + '

', + 'wptrt-notice-' . esc_attr( $this->id ), // The ID. + esc_attr( $this->get_classes() ), // The classes. + $html // The HTML. + ); + } + + /** + * Determine if the notice should be shown or not. + * + * @access public + * @since 1.0 + * @return bool + */ + public function show() { + + // Don't show if the user doesn't have the required capability. + if ( ! current_user_can( $this->options['capability'] ) ) { + return false; + } + + // Don't show if we're not on the right screen. + if ( ! $this->is_screen() ) { + return false; + } + + // Don't show if notice has been dismissed. + if ( $this->dismiss->is_dismissed() ) { + return false; + } + + return true; + } + + /** + * Get the notice classes. + * + * @access public + * @since 1.0 + * @return string + */ + public function get_classes() { + $classes = [ + 'notice', + 'is-dismissible', + ]; + + // Make sure the defined type is allowed. + $this->options['type'] = in_array( $this->options['type'], $this->allowed_types, true ) ? $this->options['type'] : 'info'; + + // Add the class for notice-type. + $classes[] = 'notice-' . $this->options['type']; + + // Do we want alt styles? + if ( $this->options['alt_style'] ) { + $classes[] = 'notice-alt'; + } + + // Combine classes to a string. + return implode( ' ', $classes ); + } + + /** + * Returns the title. + * + * @access public + * @since 1.0 + * @return string + */ + public function get_title() { + + // Sanity check: Early exit if no title is defined. + if ( ! $this->title ) { + return ''; + } + + return sprintf( + '

%s

', + wp_strip_all_tags( $this->title ) + ); + } + + /** + * Returns the message. + * + * @access public + * @since 1.0 + * @return string + */ + public function get_message() { + return wpautop( wp_kses( $this->message, $this->allowed_html ) ); + } + + /** + * Evaluate if we're on the right place depending on the "screens" argument. + * + * @access private + * @since 1.0 + * @return bool + */ + private function is_screen() { + + // If screen is empty we want this shown on all screens. + if ( ! $this->options['screens'] || empty( $this->options['screens'] ) ) { + return true; + } + + // Make sure the get_current_screen function exists. + if ( ! function_exists( 'get_current_screen' ) ) { + require_once ABSPATH . 'wp-admin/includes/screen.php'; + } + + /** @var \WP_Screen $current_screen */ + $current_screen = get_current_screen(); + // Check if we're on one of the defined screens. + return ( in_array( $current_screen->id, $this->options['screens'], true ) ); + } +} diff --git a/lib/admin-notices/src/Notices.php b/lib/admin-notices/src/Notices.php new file mode 100644 index 0000000..8d14367 --- /dev/null +++ b/lib/admin-notices/src/Notices.php @@ -0,0 +1,115 @@ + + * @copyright 2019 WPTRT + * @license https://www.gnu.org/licenses/gpl-2.0.html GPL-2.0-or-later + * @link https://github.com/WPTRT/admin-notices + */ + +namespace WPTRT\AdminNotices; + +/** + * The Admin_Notice class, responsible for creating admin notices. + * + * Each notice is a new instance of the object. + * + * @since 1.0.0 + */ +class Notices { + + /** + * An array of notices. + * + * @access private + * @since 1.0 + * @var array + */ + private $notices = []; + + /** + * Adds actions for the notices. + * + * @access public + * @since 1.0 + * @return void + */ + public function boot() { + + // Add the notice. + add_action( 'admin_notices', [ $this, 'the_notices' ] ); + } + + /** + * Add a notice. + * + * @access public + * @since 1.0 + * @param string $id A unique ID for this notice. Can contain lowercase characters and underscores. + * @param string $title The title for our notice. + * @param string $message The message for our notice. + * @param array $options An array of additional options to change the defaults for this notice. + * See Notice::__constructor() for details. + * @return void + */ + public function add( $id, $title, $message, $options = [] ) { + $this->notices[ $id ] = new Notice( $id, $title, $message, $options ); + } + + /** + * Remove a notice. + * + * @access public + * @since 1.0 + * @param string $id The unique ID of the notice we want to remove. + * @return void + */ + public function remove( $id ) { + unset( $this->notices[ $id ] ); + } + + /** + * Get a single notice. + * + * @access public + * @since 1.0 + * @param string $id The unique ID of the notice we want to retrieve. + * @return Notice|null + */ + public function get( $id ) { + if ( isset( $this->notices[ $id ] ) ) { + return $this->notices[ $id ]; + } + return null; + } + + /** + * Get all notices. + * + * @access public + * @since 1.0 + * @return array + */ + public function get_all() { + return $this->notices; + } + + /** + * Prints the notice. + * + * @access public + * @since 1.0 + * @return void + */ + public function the_notices() { + $notices = $this->get_all(); + + foreach ( $notices as $notice ) { + $notice->the_notice(); + } + } +} From 54dff50e8cf30abbbb198d9043d80ff106391aa9 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 19 Oct 2023 13:32:40 -0600 Subject: [PATCH 05/15] use pantheon-systems/wpunit-helpers --- .gitignore | 4 ++++ composer.json | 11 ++++++++++- composer.lock | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 302abb2..95ce030 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,7 @@ Thumbs.db wp-cli.local.yml node_modules/ vendor/ +# Managed by wpunit-helpers +bin/install-local-tests.sh +bin/install-wp-tests.sh +bin/phpunit-test.sh diff --git a/composer.json b/composer.json index b41436b..dee032b 100644 --- a/composer.json +++ b/composer.json @@ -20,10 +20,18 @@ "require-dev": { "pantheon-systems/pantheon-wordpress-upstream-tests": "dev-master", "pantheon-systems/pantheon-wp-coding-standards": "^2.0", + "pantheon-systems/wpunit-helpers": "^1.0", "phpunit/phpunit": "^9", "yoast/phpunit-polyfills": "^2.0" }, "scripts": { + "post-install-cmd": [ + "@get-wptrt-loader" + ], + "post-update-cmd": [ + "@get-wptrt-loader" + ], + "get-wptrt-loader": "bash bin/get-wptrt-loader.sh", "lint": [ "@phpcs", "@phplint" @@ -40,7 +48,8 @@ "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true, "composer/installers": true, - "mnsami/composer-custom-directory-installer": true + "mnsami/composer-custom-directory-installer": true, + "pantheon-systems/wpunit-helpers": true }, "sort-packages": true }, diff --git a/composer.lock b/composer.lock index 0dcf7a5..ae365f8 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": "104888d7217d064bbf2a3a1378841c75", + "content-hash": "6e8dd6781922c762b41393a0dcae6a6b", "packages": [ { "name": "mnsami/composer-custom-directory-installer", @@ -1369,6 +1369,52 @@ "description": "PHPCS Rulesets for WordPress projects on Pantheon.", "time": "2023-09-12T17:25:08+00:00" }, + { + "name": "pantheon-systems/wpunit-helpers", + "version": "v1.0.1", + "source": { + "type": "git", + "url": "https://github.com/pantheon-systems/wpunit-helpers.git", + "reference": "683c9eb83a76c5229a40eef2ec1b19162f162a50" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/pantheon-systems/wpunit-helpers/zipball/683c9eb83a76c5229a40eef2ec1b19162f162a50", + "reference": "683c9eb83a76c5229a40eef2ec1b19162f162a50", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^2.0" + }, + "require-dev": { + "squizlabs/php_codesniffer": "^3.7" + }, + "type": "composer-plugin", + "extra": { + "class": "Pantheon\\WPUnitHelpers\\Plugin" + }, + "autoload": { + "psr-4": { + "Pantheon\\WPUnitHelpers\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Pantheon", + "email": "noreply@pantheon.io" + } + ], + "description": "Unified scripts for installing and running automated WP Unit Tests.", + "support": { + "issues": "https://github.com/pantheon-systems/wpunit-helpers/issues", + "source": "https://github.com/pantheon-systems/wpunit-helpers/tree/v1.0.1" + }, + "time": "2023-10-12T20:08:14+00:00" + }, { "name": "phar-io/manifest", "version": "2.0.3", From b649c3598199e57320f8c71a89a6ff2753669f16 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 19 Oct 2023 13:33:35 -0600 Subject: [PATCH 06/15] delete the scripts managed by wpunit-helpers --- bin/install-local-tests.sh | 61 --------------- bin/install-wp-tests.sh | 151 ------------------------------------- bin/phpunit-test.sh | 18 ----- 3 files changed, 230 deletions(-) delete mode 100644 bin/install-local-tests.sh delete mode 100755 bin/install-wp-tests.sh delete mode 100644 bin/phpunit-test.sh diff --git a/bin/install-local-tests.sh b/bin/install-local-tests.sh deleted file mode 100644 index c1f8cc5..0000000 --- a/bin/install-local-tests.sh +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/bash -set -e - -# Initialize variables with default values -TMPDIR="/tmp" -DB_NAME="wordpress_test" -DB_USER="root" -DB_PASS="" -DB_HOST="127.0.0.1" -WP_VERSION="latest" -SKIP_DB="" - -# Display usage information -usage() { - echo "Usage:" - echo "./install-local-tests.sh [--dbname=wordpress_test] [--dbuser=root] [--dbpass=''] [--dbhost=127.0.0.1] [--wpversion=latest] [--no-db]" -} - -# Parse command-line arguments -for i in "$@" -do -case $i in - --dbname=*) - DB_NAME="${i#*=}" - shift - ;; - --dbuser=*) - DB_USER="${i#*=}" - shift - ;; - --dbpass=*) - DB_PASS="${i#*=}" - shift - ;; - --dbhost=*) - DB_HOST="${i#*=}" - shift - ;; - --wpversion=*) - WP_VERSION="${i#*=}" - shift - ;; - --no-db) - SKIP_DB="true" - shift - ;; - *) - # unknown option - usage - exit 1 - ;; -esac -done - -# Run install-wp-tests.sh -echo "Installing local tests into ${TMPDIR}" -bash "$(dirname "$0")/install-wp-tests.sh" "$DB_NAME" "$DB_USER" "$DB_PASS" "$DB_HOST" "$WP_VERSION" "$SKIP_DB" - -# Run PHPUnit -echo "Running PHPUnit" -composer phpunit diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh deleted file mode 100755 index 675dd97..0000000 --- a/bin/install-wp-tests.sh +++ /dev/null @@ -1,151 +0,0 @@ -#!/usr/bin/env bash - -if [ $# -lt 3 ]; then - echo "usage: $0 [db-host] [wp-version] [skip-database-creation]" - exit 1 -fi - -DB_NAME=$1 -DB_USER=$2 -DB_PASS=$3 -DB_HOST=${4-localhost} -WP_VERSION=${5-latest} -SKIP_DB_CREATE=${6-false} - -TMPDIR=${TMPDIR-/tmp} -WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib} -WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/} - -download() { - if [ `which curl` ]; then - curl -s "$1" > "$2"; - elif [ `which wget` ]; then - wget -nv -O "$2" "$1" - fi -} - -if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+$ ]]; then - WP_TESTS_TAG="branches/$WP_VERSION" -elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then - if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then - # version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x - WP_TESTS_TAG="tags/${WP_VERSION%??}" - else - WP_TESTS_TAG="tags/$WP_VERSION" - fi -elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then - WP_TESTS_TAG="trunk" -else - # http serves a single offer, whereas https serves multiple. we only want one - download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json - grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json - LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//') - if [[ -z "$LATEST_VERSION" ]]; then - echo "Latest WordPress version could not be found" - exit 1 - fi - WP_TESTS_TAG="tags/$LATEST_VERSION" -fi - -set -e - -install_wp() { - - if [ -d $WP_CORE_DIR ]; then - return; - fi - - mkdir -p $WP_CORE_DIR - - if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then - mkdir -p $TMPDIR/wordpress-nightly - download https://wordpress.org/nightly-builds/wordpress-latest.zip $TMPDIR/wordpress-nightly/wordpress-nightly.zip - unzip -q $TMPDIR/wordpress-nightly/wordpress-nightly.zip -d $TMPDIR/wordpress-nightly/ - mv $TMPDIR/wordpress-nightly/wordpress/* $WP_CORE_DIR - else - if [ $WP_VERSION == 'latest' ]; then - local ARCHIVE_NAME='latest' - elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+ ]]; then - # https serves multiple offers, whereas http serves single. - download https://api.wordpress.org/core/version-check/1.7/ $TMPDIR/wp-latest.json - if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then - # version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x - LATEST_VERSION=${WP_VERSION%??} - else - # otherwise, scan the releases and get the most up to date minor version of the major release - local VERSION_ESCAPED=`echo $WP_VERSION | sed 's/\./\\\\./g'` - LATEST_VERSION=$(grep -o '"version":"'$VERSION_ESCAPED'[^"]*' $TMPDIR/wp-latest.json | sed 's/"version":"//' | head -1) - fi - if [[ -z "$LATEST_VERSION" ]]; then - local ARCHIVE_NAME="wordpress-$WP_VERSION" - else - local ARCHIVE_NAME="wordpress-$LATEST_VERSION" - fi - else - local ARCHIVE_NAME="wordpress-$WP_VERSION" - fi - download https://wordpress.org/${ARCHIVE_NAME}.tar.gz $TMPDIR/wordpress.tar.gz - tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR - fi - - download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php -} - -install_test_suite() { - # portable in-place argument for both GNU sed and Mac OSX sed - if [[ $(uname -s) == 'Darwin' ]]; then - local ioption='-i .bak' - else - local ioption='-i' - fi - - # set up testing suite if it doesn't yet exist - if [ ! -d $WP_TESTS_DIR ]; then - # set up testing suite - mkdir -p $WP_TESTS_DIR - svn co --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes - svn co --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data - fi - - if [ ! -f wp-tests-config.php ]; then - download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php - # remove all forward slashes in the end - WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::") - sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php - sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php - sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php - sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php - sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php - fi - -} - -install_db() { - - if [ ${SKIP_DB_CREATE} = "true" ]; then - return 0 - fi - - # parse DB_HOST for port or socket references - local PARTS=(${DB_HOST//\:/ }) - local DB_HOSTNAME=${PARTS[0]}; - local DB_SOCK_OR_PORT=${PARTS[1]}; - local EXTRA="" - - if ! [ -z $DB_HOSTNAME ] ; then - if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then - EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp" - elif ! [ -z $DB_SOCK_OR_PORT ] ; then - EXTRA=" --socket=$DB_SOCK_OR_PORT" - elif ! [ -z $DB_HOSTNAME ] ; then - EXTRA=" --host=$DB_HOSTNAME --protocol=tcp" - fi - fi - - # create database - mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA -} - -install_wp -install_test_suite -install_db diff --git a/bin/phpunit-test.sh b/bin/phpunit-test.sh deleted file mode 100644 index 450c3a8..0000000 --- a/bin/phpunit-test.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -set -e - -DIRNAME=$(dirname "$0") - -bash "${DIRNAME}/install-wp-tests.sh" wordpress_test root root 127.0.0.1 latest -echo "Running PHPUnit on Single Site" -composer phpunit -rm -rf "$WP_TESTS_DIR" "$WP_CORE_DIR" - -bash "${DIRNAME}/install-wp-tests.sh" wordpress_test root root 127.0.0.1 nightly true -echo "Running PHPUnit on Single Site (Nightly WordPress)" -composer phpunit - -bash "${DIRNAME}/install-wp-tests.sh" wordpress_test root root 127.0.0.1 latest true -echo "Running PHPUnit on Multisite" -WP_MULTISITE=1 composer phpunit From f2f9ef118f32795fc6fba5236cc603949e56d0e4 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 19 Oct 2023 13:34:34 -0600 Subject: [PATCH 07/15] add a script to get the wptrt loader file from github & add it --- bin/get-wptrt-loader.sh | 27 ++++++++ lib/Loader.php | 136 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 163 insertions(+) create mode 100755 bin/get-wptrt-loader.sh create mode 100644 lib/Loader.php diff --git a/bin/get-wptrt-loader.sh b/bin/get-wptrt-loader.sh new file mode 100755 index 0000000..a62bcd6 --- /dev/null +++ b/bin/get-wptrt-loader.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# URL of the remote file +remote_url="https://raw.githubusercontent.com/WPTT/autoload/master/src/Loader.php" + +# Path to the local file +local_file="lib/Loader.php" + +# Get the last modification time of the remote file in seconds since epoch +remote_epoch=$(curl -sI $remote_url | grep -i last-modified | awk -F': ' '{print $2}' | awk -F' ' '{print mktime($5" "$4" "$3" "$2" "$1" 00 00 00")}') + +if [[ -e $local_file ]]; then + echo "Found local WPTRT Loader..." + # Get the modification time of the local file in seconds since epoch + local_epoch=$(stat -c %Y $local_file 2>/dev/null || stat -f %m $local_file) + + # Compare modification times + if (( remote_epoch > local_epoch )); then + echo "Remote WPTRT Loader is newer, downloading..." + # Remote file is newer, download it + wget -O $local_file $remote_url + fi +else + echo "No local WPTRT Loader found, downloading..." + # Local file doesn't exist, download the remote file + wget -O $local_file $remote_url +fi diff --git a/lib/Loader.php b/lib/Loader.php new file mode 100644 index 0000000..15fed5c --- /dev/null +++ b/lib/Loader.php @@ -0,0 +1,136 @@ + + * @copyright 2019 WPTRT + * @license https://www.gnu.org/licenses/gpl-2.0.html GPL-2.0-or-later + * @link https://github.com/WPTRT/autoload + */ + +namespace WPTRT\Autoload; + +class Loader { + + /** + * Array of loaders. + * + * @since 1.0.0 + * @access protected + * @var array + */ + protected $loaders = []; + + /** + * Adds a new prefix and path to load. + * + * @since 1.0.0 + * @access public + * @param string $prefix Namespace prefix. + * @param array|string $paths Absolute path(s) where to look for classes. + * @return void + */ + public function add( $prefix, $paths ) { + + foreach ( (array) $paths as $path ) { + $this->loaders[ $prefix ][] = $path; + } + } + + /** + * Removes a loader by prefix or prefix + path. + * + * @since 1.0.0 + * @access public + * @param string $prefix Namespace prefix. + * @param string $path Absolute path. + * @return void + */ + public function remove( $prefix, $path = '' ) { + + // Remove specific loader if both the prefix and path are provided. + if ( $path ) { + if ( $this->has( $prefix, $path ) ) { + $key = array_search( $path, $this->loaders[ $prefix ], true ); + unset( $this->loaders[ $prefix ][ $key ] ); + } + + return; + } + + // Remove all loaders for a prefix if no path is provided. + if ( $this->has( $prefix ) ) { + unset( $this->loaders[ $prefix ] ); + } + } + + /** + * Checks if a loader is already added. + * + * @since 1.0.0 + * @access public + * @param string $prefix Namespace prefix. + * @param string $path Absolute path. + * @return bool + */ + public function has( $prefix, $path = '' ) { + + if ( $path ) { + return isset( $this->loaders[ $prefix ] ) && in_array( $path, $this->loaders[ $prefix ], true ); + } + + return isset( $this->loaders[ $prefix ] ); + } + + /** + * Registers all loaders. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function register() { + + if ( $this->loaders ) { + spl_autoload_register( function( $class ) { + $this->load( $class ); + }, true, true ); + } + } + + /** + * Loads a class if it's within the given namespace. + * + * @since 1.0.0 + * @access protected + * @param string $class Fully-qualified class name. + * @return void + */ + protected function load( $class ) { + + foreach ( $this->loaders as $prefix => $paths ) { + + // Continue if the class is not in our namespace. + if ( 0 !== strpos( $class, $prefix ) ) { + continue; + } + + // Build a class filename to append to the path. + $suffix = ltrim( str_replace( $prefix, '', $class ), '\\' ); + $suffix = DIRECTORY_SEPARATOR . str_replace( '\\', DIRECTORY_SEPARATOR, $suffix ) . '.php'; + + // Loop through the paths to see if we can find the file + // for the class. + foreach ( $paths as $path ) { + + // Load the class file if it exists and return. + if ( file_exists( $file = realpath( $path ) . $suffix ) ) { + include $file; + return; + } + } + } + } +} From 4a5561e71407cdd73b7f9b724fc55a2d3ada4c17 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 19 Oct 2023 14:58:09 -0600 Subject: [PATCH 08/15] get rid of the trt notices stuff couldn't get it working, was able to use an admin ajax way of doing it --- bin/get-wptrt-loader.sh | 27 --- composer.json | 17 -- lib/Loader.php | 136 ------------ lib/admin-notices/LICENSE | 339 ------------------------------ lib/admin-notices/readme.md | 116 ---------- lib/admin-notices/src/Dismiss.php | 166 --------------- lib/admin-notices/src/Notice.php | 297 -------------------------- lib/admin-notices/src/Notices.php | 115 ---------- 8 files changed, 1213 deletions(-) delete mode 100755 bin/get-wptrt-loader.sh delete mode 100644 lib/Loader.php delete mode 100644 lib/admin-notices/LICENSE delete mode 100644 lib/admin-notices/readme.md delete mode 100644 lib/admin-notices/src/Dismiss.php delete mode 100644 lib/admin-notices/src/Notice.php delete mode 100644 lib/admin-notices/src/Notices.php diff --git a/bin/get-wptrt-loader.sh b/bin/get-wptrt-loader.sh deleted file mode 100755 index a62bcd6..0000000 --- a/bin/get-wptrt-loader.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -# URL of the remote file -remote_url="https://raw.githubusercontent.com/WPTT/autoload/master/src/Loader.php" - -# Path to the local file -local_file="lib/Loader.php" - -# Get the last modification time of the remote file in seconds since epoch -remote_epoch=$(curl -sI $remote_url | grep -i last-modified | awk -F': ' '{print $2}' | awk -F' ' '{print mktime($5" "$4" "$3" "$2" "$1" 00 00 00")}') - -if [[ -e $local_file ]]; then - echo "Found local WPTRT Loader..." - # Get the modification time of the local file in seconds since epoch - local_epoch=$(stat -c %Y $local_file 2>/dev/null || stat -f %m $local_file) - - # Compare modification times - if (( remote_epoch > local_epoch )); then - echo "Remote WPTRT Loader is newer, downloading..." - # Remote file is newer, download it - wget -O $local_file $remote_url - fi -else - echo "No local WPTRT Loader found, downloading..." - # Local file doesn't exist, download the remote file - wget -O $local_file $remote_url -fi diff --git a/composer.json b/composer.json index dee032b..8d80d9e 100644 --- a/composer.json +++ b/composer.json @@ -13,10 +13,6 @@ "email": "daniel@handbuilt.co" } ], - "require": { - "mnsami/composer-custom-directory-installer": "^2.0", - "wptrt/admin-notices": "^1.0" - }, "require-dev": { "pantheon-systems/pantheon-wordpress-upstream-tests": "dev-master", "pantheon-systems/pantheon-wp-coding-standards": "^2.0", @@ -25,13 +21,6 @@ "yoast/phpunit-polyfills": "^2.0" }, "scripts": { - "post-install-cmd": [ - "@get-wptrt-loader" - ], - "post-update-cmd": [ - "@get-wptrt-loader" - ], - "get-wptrt-loader": "bash bin/get-wptrt-loader.sh", "lint": [ "@phpcs", "@phplint" @@ -48,14 +37,8 @@ "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true, "composer/installers": true, - "mnsami/composer-custom-directory-installer": true, "pantheon-systems/wpunit-helpers": true }, "sort-packages": true - }, - "extra": { - "installer-paths": { - "lib/{$name}/": ["wptrt/admin-notices"] - } } } diff --git a/lib/Loader.php b/lib/Loader.php deleted file mode 100644 index 15fed5c..0000000 --- a/lib/Loader.php +++ /dev/null @@ -1,136 +0,0 @@ - - * @copyright 2019 WPTRT - * @license https://www.gnu.org/licenses/gpl-2.0.html GPL-2.0-or-later - * @link https://github.com/WPTRT/autoload - */ - -namespace WPTRT\Autoload; - -class Loader { - - /** - * Array of loaders. - * - * @since 1.0.0 - * @access protected - * @var array - */ - protected $loaders = []; - - /** - * Adds a new prefix and path to load. - * - * @since 1.0.0 - * @access public - * @param string $prefix Namespace prefix. - * @param array|string $paths Absolute path(s) where to look for classes. - * @return void - */ - public function add( $prefix, $paths ) { - - foreach ( (array) $paths as $path ) { - $this->loaders[ $prefix ][] = $path; - } - } - - /** - * Removes a loader by prefix or prefix + path. - * - * @since 1.0.0 - * @access public - * @param string $prefix Namespace prefix. - * @param string $path Absolute path. - * @return void - */ - public function remove( $prefix, $path = '' ) { - - // Remove specific loader if both the prefix and path are provided. - if ( $path ) { - if ( $this->has( $prefix, $path ) ) { - $key = array_search( $path, $this->loaders[ $prefix ], true ); - unset( $this->loaders[ $prefix ][ $key ] ); - } - - return; - } - - // Remove all loaders for a prefix if no path is provided. - if ( $this->has( $prefix ) ) { - unset( $this->loaders[ $prefix ] ); - } - } - - /** - * Checks if a loader is already added. - * - * @since 1.0.0 - * @access public - * @param string $prefix Namespace prefix. - * @param string $path Absolute path. - * @return bool - */ - public function has( $prefix, $path = '' ) { - - if ( $path ) { - return isset( $this->loaders[ $prefix ] ) && in_array( $path, $this->loaders[ $prefix ], true ); - } - - return isset( $this->loaders[ $prefix ] ); - } - - /** - * Registers all loaders. - * - * @since 1.0.0 - * @access public - * @return void - */ - public function register() { - - if ( $this->loaders ) { - spl_autoload_register( function( $class ) { - $this->load( $class ); - }, true, true ); - } - } - - /** - * Loads a class if it's within the given namespace. - * - * @since 1.0.0 - * @access protected - * @param string $class Fully-qualified class name. - * @return void - */ - protected function load( $class ) { - - foreach ( $this->loaders as $prefix => $paths ) { - - // Continue if the class is not in our namespace. - if ( 0 !== strpos( $class, $prefix ) ) { - continue; - } - - // Build a class filename to append to the path. - $suffix = ltrim( str_replace( $prefix, '', $class ), '\\' ); - $suffix = DIRECTORY_SEPARATOR . str_replace( '\\', DIRECTORY_SEPARATOR, $suffix ) . '.php'; - - // Loop through the paths to see if we can find the file - // for the class. - foreach ( $paths as $path ) { - - // Load the class file if it exists and return. - if ( file_exists( $file = realpath( $path ) . $suffix ) ) { - include $file; - return; - } - } - } - } -} diff --git a/lib/admin-notices/LICENSE b/lib/admin-notices/LICENSE deleted file mode 100644 index d511905..0000000 --- a/lib/admin-notices/LICENSE +++ /dev/null @@ -1,339 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. diff --git a/lib/admin-notices/readme.md b/lib/admin-notices/readme.md deleted file mode 100644 index f4da7a5..0000000 --- a/lib/admin-notices/readme.md +++ /dev/null @@ -1,116 +0,0 @@ -# WPTRT Admin Notices - -This is a custom class allowing WordPress theme authors to add admin notices to the WordPress dashboard. -Its primary purpose is for providing a standardized method of creating admin notices in a consistent manner using the default WordPress styles. - -Notices created using this method are automatically dismissible. - -## Usage - -```php -$my_theme_notices = new \WPTRT\AdminNotices\Notices(); - -// Add a notice. -$my_theme_notices->add( (string) $id, (string) $title, (string) $content, (array) $options ); - -// Boot things up. -$my_theme_notices->boot(); -``` - -After you instantiate the `Notices` object using `$my_theme_notices = new \WPTRT\AdminNotices\Notices();` you can add new notices using the `add()` method. - -The arguments of this method are: - -| Parameter | Type | | Description -|---|---|---|---| -| `$id`| `string` | Required | A unique ID for this notice. **The ID can contain lowercase latin letters and underscores**. It is used to construct the option (or user-meta) key that will be strored in the database. | -| `$title` | `string` | Required | The title for your notice. If you don't want to use a title you can use set it to `false`. | -| `$message` | `string` | Required | The content for the notice you want to create. Please note that the only acceptable tags here are `', - 'wptrt-notice-' . esc_attr( $this->id ), // The ID. - esc_attr( $this->get_classes() ), // The classes. - $html // The HTML. - ); - } - - /** - * Determine if the notice should be shown or not. - * - * @access public - * @since 1.0 - * @return bool - */ - public function show() { - - // Don't show if the user doesn't have the required capability. - if ( ! current_user_can( $this->options['capability'] ) ) { - return false; - } - - // Don't show if we're not on the right screen. - if ( ! $this->is_screen() ) { - return false; - } - - // Don't show if notice has been dismissed. - if ( $this->dismiss->is_dismissed() ) { - return false; - } - - return true; - } - - /** - * Get the notice classes. - * - * @access public - * @since 1.0 - * @return string - */ - public function get_classes() { - $classes = [ - 'notice', - 'is-dismissible', - ]; - - // Make sure the defined type is allowed. - $this->options['type'] = in_array( $this->options['type'], $this->allowed_types, true ) ? $this->options['type'] : 'info'; - - // Add the class for notice-type. - $classes[] = 'notice-' . $this->options['type']; - - // Do we want alt styles? - if ( $this->options['alt_style'] ) { - $classes[] = 'notice-alt'; - } - - // Combine classes to a string. - return implode( ' ', $classes ); - } - - /** - * Returns the title. - * - * @access public - * @since 1.0 - * @return string - */ - public function get_title() { - - // Sanity check: Early exit if no title is defined. - if ( ! $this->title ) { - return ''; - } - - return sprintf( - '

%s

', - wp_strip_all_tags( $this->title ) - ); - } - - /** - * Returns the message. - * - * @access public - * @since 1.0 - * @return string - */ - public function get_message() { - return wpautop( wp_kses( $this->message, $this->allowed_html ) ); - } - - /** - * Evaluate if we're on the right place depending on the "screens" argument. - * - * @access private - * @since 1.0 - * @return bool - */ - private function is_screen() { - - // If screen is empty we want this shown on all screens. - if ( ! $this->options['screens'] || empty( $this->options['screens'] ) ) { - return true; - } - - // Make sure the get_current_screen function exists. - if ( ! function_exists( 'get_current_screen' ) ) { - require_once ABSPATH . 'wp-admin/includes/screen.php'; - } - - /** @var \WP_Screen $current_screen */ - $current_screen = get_current_screen(); - // Check if we're on one of the defined screens. - return ( in_array( $current_screen->id, $this->options['screens'], true ) ); - } -} diff --git a/lib/admin-notices/src/Notices.php b/lib/admin-notices/src/Notices.php deleted file mode 100644 index 8d14367..0000000 --- a/lib/admin-notices/src/Notices.php +++ /dev/null @@ -1,115 +0,0 @@ - - * @copyright 2019 WPTRT - * @license https://www.gnu.org/licenses/gpl-2.0.html GPL-2.0-or-later - * @link https://github.com/WPTRT/admin-notices - */ - -namespace WPTRT\AdminNotices; - -/** - * The Admin_Notice class, responsible for creating admin notices. - * - * Each notice is a new instance of the object. - * - * @since 1.0.0 - */ -class Notices { - - /** - * An array of notices. - * - * @access private - * @since 1.0 - * @var array - */ - private $notices = []; - - /** - * Adds actions for the notices. - * - * @access public - * @since 1.0 - * @return void - */ - public function boot() { - - // Add the notice. - add_action( 'admin_notices', [ $this, 'the_notices' ] ); - } - - /** - * Add a notice. - * - * @access public - * @since 1.0 - * @param string $id A unique ID for this notice. Can contain lowercase characters and underscores. - * @param string $title The title for our notice. - * @param string $message The message for our notice. - * @param array $options An array of additional options to change the defaults for this notice. - * See Notice::__constructor() for details. - * @return void - */ - public function add( $id, $title, $message, $options = [] ) { - $this->notices[ $id ] = new Notice( $id, $title, $message, $options ); - } - - /** - * Remove a notice. - * - * @access public - * @since 1.0 - * @param string $id The unique ID of the notice we want to remove. - * @return void - */ - public function remove( $id ) { - unset( $this->notices[ $id ] ); - } - - /** - * Get a single notice. - * - * @access public - * @since 1.0 - * @param string $id The unique ID of the notice we want to retrieve. - * @return Notice|null - */ - public function get( $id ) { - if ( isset( $this->notices[ $id ] ) ) { - return $this->notices[ $id ]; - } - return null; - } - - /** - * Get all notices. - * - * @access public - * @since 1.0 - * @return array - */ - public function get_all() { - return $this->notices; - } - - /** - * Prints the notice. - * - * @access public - * @since 1.0 - * @return void - */ - public function the_notices() { - $notices = $this->get_all(); - - foreach ( $notices as $notice ) { - $notice->the_notice(); - } - } -} From f642d049f35027e80690520fe939908284d5b070 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 19 Oct 2023 14:58:54 -0600 Subject: [PATCH 09/15] add a notice dismissal script --- assets/js/notices.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 assets/js/notices.js diff --git a/assets/js/notices.js b/assets/js/notices.js new file mode 100644 index 0000000..f880014 --- /dev/null +++ b/assets/js/notices.js @@ -0,0 +1,11 @@ +jQuery(document).ready(function($) { + $(document).on('click', '.notice-dismiss', function() { + $.ajax({ + url: ajaxurl, + type: 'POST', + data: { + action: 'dismiss_notice' + } + }); + }); +}); From d61e1d8ec5e1d02ff36f479bca5ddd4aed86fcb2 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 19 Oct 2023 14:59:26 -0600 Subject: [PATCH 10/15] hide the notice if dismissed --- pantheon-sessions.php | 55 ++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/pantheon-sessions.php b/pantheon-sessions.php index c3d0326..fef8f65 100644 --- a/pantheon-sessions.php +++ b/pantheon-sessions.php @@ -72,8 +72,26 @@ private function load() { add_action( 'set_logged_in_cookie', [ __CLASS__, 'action_set_logged_in_cookie' ], 10, 4 ); add_action( 'clear_auth_cookie', [ __CLASS__, 'action_clear_auth_cookie' ] ); } + + add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); + add_action( 'wp_ajax_dismiss_notice', [ $this, 'dismiss_notice' ] ); } + /** + * Enqueue scripts + */ + public function enqueue_scripts() { + wp_enqueue_script( 'notices', plugins_url( '/assets/js/notices.js', __FILE__ ), ['jquery'], PANTHEON_SESSIONS_VERSION, true ); + } + + /** + * Dismiss the notice when the button is clicked. + */ + public function dismiss_notice() { + $user_id = get_current_user_id(); + update_user_meta( $user_id, 'notice_dismissed', true ); + } + /** * Define our constants */ @@ -273,26 +291,29 @@ public static function check_native_primary_keys() { $is_pantheon = isset( $_ENV['PANTHEON_ENVIRONMENT'] ) ? true : false; $wp_cli_cmd = $is_pantheon ? 'terminus wp <site>.<env> --' : 'wp'; $cli_add_index = $wp_cli_cmd . 'pantheon session add-index'; - $key_existence = $wpdb->get_results( $query ); + $user_id = get_current_user_id(); + $dismissed = get_user_meta( $user_id, 'notice_dismissed', true ); if ( empty( $key_existence ) ) { - // If the key doesn't exist, recommend remediation. - ?> -
-

- -

-

- $cli_add_index" ) ); - ?> -

-
- +
+

+ +

+

+ $cli_add_index" ) ); + ?> +

+
+ prepare( 'SHOW TABLES LIKE %s', From 405905be0f11cc6039f23767bdc576a61a51d993 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 19 Oct 2023 15:04:09 -0600 Subject: [PATCH 11/15] remove composer/installers, too don't need that either --- composer.json | 1 - composer.lock | 113 +------------------------------------------------- 2 files changed, 2 insertions(+), 112 deletions(-) diff --git a/composer.json b/composer.json index 8d80d9e..4634a7c 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,6 @@ "config": { "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true, - "composer/installers": true, "pantheon-systems/wpunit-helpers": true }, "sort-packages": true diff --git a/composer.lock b/composer.lock index ae365f8..31381ac 100644 --- a/composer.lock +++ b/composer.lock @@ -4,117 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6e8dd6781922c762b41393a0dcae6a6b", - "packages": [ - { - "name": "mnsami/composer-custom-directory-installer", - "version": "2.0.0", - "source": { - "type": "git", - "url": "https://github.com/mnsami/composer-custom-directory-installer.git", - "reference": "85f66323978d0b1cb0e6acc7f69b3e7b912f82d9" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/mnsami/composer-custom-directory-installer/zipball/85f66323978d0b1cb0e6acc7f69b3e7b912f82d9", - "reference": "85f66323978d0b1cb0e6acc7f69b3e7b912f82d9", - "shasum": "" - }, - "require": { - "composer-plugin-api": "^1.0 || ^2.0", - "php": ">=5.3" - }, - "type": "composer-plugin", - "extra": { - "class": [ - "Composer\\CustomDirectoryInstaller\\LibraryPlugin", - "Composer\\CustomDirectoryInstaller\\PearPlugin", - "Composer\\CustomDirectoryInstaller\\PluginPlugin" - ], - "branch-alias": { - "dev-master": "1.1.x-dev" - } - }, - "autoload": { - "psr-0": { - "Composer\\CustomDirectoryInstaller": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Mina Nabil Sami", - "email": "mina.nsami@gmail.com" - } - ], - "description": "A composer plugin, to help install packages of different types in custom paths.", - "keywords": [ - "composer", - "composer-installer", - "composer-plugin" - ], - "support": { - "issues": "https://github.com/mnsami/composer-custom-directory-installer/issues", - "source": "https://github.com/mnsami/composer-custom-directory-installer/tree/2.0.0" - }, - "time": "2020-08-18T11:00:11+00:00" - }, - { - "name": "wptrt/admin-notices", - "version": "v1.0.4", - "source": { - "type": "git", - "url": "https://github.com/WPTT/admin-notices.git", - "reference": "1df860950b4198cc93e867873b1b571b51f908b0" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/WPTT/admin-notices/zipball/1df860950b4198cc93e867873b1b571b51f908b0", - "reference": "1df860950b4198cc93e867873b1b571b51f908b0", - "shasum": "" - }, - "require": { - "php": ">=5.6" - }, - "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2", - "php": "~7.1", - "szepeviktor/phpstan-wordpress": "^0.6.0", - "wp-coding-standards/wpcs": "^2.3" - }, - "type": "library", - "autoload": { - "psr-4": { - "WPTRT\\AdminNotices\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "GPL-2.0-or-later" - ], - "authors": [ - { - "name": "WordPress.org Theme Review Team", - "email": "themes@wordpress.org", - "homepage": "https://make.wordpress.org/themes", - "role": "Developer" - } - ], - "description": "A class to create admin-notices for the WordPress dashboard.", - "homepage": "https://github.com/WPTRT/admin-notices", - "keywords": [ - "wordpress" - ], - "support": { - "issues": "https://github.com/WPTRT/admin-notices/issues", - "source": "https://github.com/WPTT/admin-notices/tree/v1.0.4" - }, - "time": "2023-10-06T03:42:42+00:00" - } - ], + "content-hash": "a92957659a2954cb30276b6a855aad5d", + "packages": [], "packages-dev": [ { "name": "automattic/vipwpcs", From 0ebec88da9f02c7779e02bd56b7862594f284090 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 19 Oct 2023 15:04:19 -0600 Subject: [PATCH 12/15] linting fixes --- pantheon-sessions.php | 94 ++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 46 deletions(-) diff --git a/pantheon-sessions.php b/pantheon-sessions.php index fef8f65..e4552db 100644 --- a/pantheon-sessions.php +++ b/pantheon-sessions.php @@ -73,24 +73,24 @@ private function load() { add_action( 'clear_auth_cookie', [ __CLASS__, 'action_clear_auth_cookie' ] ); } - add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); - add_action( 'wp_ajax_dismiss_notice', [ $this, 'dismiss_notice' ] ); + add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); + add_action( 'wp_ajax_dismiss_notice', [ $this, 'dismiss_notice' ] ); } - /** - * Enqueue scripts - */ - public function enqueue_scripts() { - wp_enqueue_script( 'notices', plugins_url( '/assets/js/notices.js', __FILE__ ), ['jquery'], PANTHEON_SESSIONS_VERSION, true ); - } - - /** - * Dismiss the notice when the button is clicked. - */ - public function dismiss_notice() { - $user_id = get_current_user_id(); - update_user_meta( $user_id, 'notice_dismissed', true ); - } + /** + * Enqueue scripts + */ + public function enqueue_scripts() { + wp_enqueue_script( 'notices', plugins_url( '/assets/js/notices.js', __FILE__ ), [ 'jquery' ], PANTHEON_SESSIONS_VERSION, true ); + } + + /** + * Dismiss the notice when the button is clicked. + */ + public function dismiss_notice() { + $user_id = get_current_user_id(); + update_user_meta( $user_id, 'notice_dismissed', true ); + } /** * Define our constants @@ -288,32 +288,34 @@ public static function check_native_primary_keys() { $table_name = $wpdb->prefix . 'pantheon_sessions'; $old_table = $wpdb->prefix . 'bak_pantheon_sessions'; $query = "SHOW KEYS FROM {$table_name} WHERE key_name = 'PRIMARY';"; - $is_pantheon = isset( $_ENV['PANTHEON_ENVIRONMENT'] ) ? true : false; - $wp_cli_cmd = $is_pantheon ? 'terminus wp <site>.<env> --' : 'wp'; - $cli_add_index = $wp_cli_cmd . 'pantheon session add-index'; + $is_pantheon = isset( $_ENV['PANTHEON_ENVIRONMENT'] ) ? true : false; + $wp_cli_cmd = $is_pantheon ? 'terminus wp <site>.<env> --' : 'wp'; + $cli_add_index = $wp_cli_cmd . 'pantheon session add-index'; $key_existence = $wpdb->get_results( $query ); - $user_id = get_current_user_id(); - $dismissed = get_user_meta( $user_id, 'notice_dismissed', true ); + $user_id = get_current_user_id(); + $dismissed = get_user_meta( $user_id, 'notice_dismissed', true ); if ( empty( $key_existence ) ) { - if ( ! $dismissed ) { - // If the key doesn't exist, recommend remediation. - ?> -
-

- -

-

- $cli_add_index" ) ); - ?> -

-
- +
+

+ +

+

+ $cli_add_index" ) ); + ?> +

+
+ prepare( 'SHOW TABLES LIKE %s', @@ -321,18 +323,18 @@ public static function check_native_primary_keys() { // Check for table existence and delete if present. if ( $wpdb->get_var( $query ) == $old_table ) { - $cli_key_finalize = $wp_cli_cmd . 'pantheon session primary-key-finalize'; - $cli_key_revert = $wp_cli_cmd . 'pantheon session primary-key-revert'; + $cli_key_finalize = $wp_cli_cmd . 'pantheon session primary-key-finalize'; + $cli_key_revert = $wp_cli_cmd . 'pantheon session primary-key-revert'; // If an old table exists but has not been removed, suggest doing so. ?>

- $cli_key_finalize", "$cli_key_revert" ) ); - ?> -

+ $cli_key_finalize", "$cli_key_revert" ) ); + ?> +

Date: Thu, 19 Oct 2023 15:09:40 -0600 Subject: [PATCH 13/15] update changelog --- README.md | 2 ++ pantheon-sessions.php | 4 ++-- readme.txt | 5 ++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b268ee9..8980134 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,8 @@ Adds a WP-CLI command to add an index to the sessions table if one does not exis ## Changelog ## ### 1.4.1-dev ### +* Fixed an issue with the `pantheon session add-index` command not working properly on WP multisite [[#270](https://github.com/pantheon-systems/wp-native-php-sessions/pull/270)] +* Made the notice added in 1.4.0 dismissable (stores in user meta) & hides for multisite (an update is coming to iterate through all sites on a network) [[#271](https://github.com/pantheon-systems/wp-native-php-sessions/pull/271)] ### 1.4.0 (October 17, 2023) ### * Adds new CLI command to add a Primary Column (id) to the `pantheon_sessions` table for users who do not have one. [[#265](https://github.com/pantheon-systems/wp-native-php-sessions/pull/265)] diff --git a/pantheon-sessions.php b/pantheon-sessions.php index e4552db..2889169 100644 --- a/pantheon-sessions.php +++ b/pantheon-sessions.php @@ -1,7 +1,7 @@ Date: Thu, 19 Oct 2023 15:16:45 -0600 Subject: [PATCH 14/15] update readme with notes for running the command on multisite --- README.md | 15 +++++++++++++++ readme.txt | 18 +++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8980134..891ccdb 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,21 @@ Added in 1.4.0. If you have run the `add-index` command and have verified that t Added in 1.4.0. If you have run the `add-index` command and something unexpected has occurred, just run the `primary-key-revert` command and the backup table will immediately be returned to being the active table. +### WordPress Multisite +As of 1.4.1 the `add-index`, `primary-key-add` and `primary-key-revert` commands only apply to a single site. This means that to run on a WordPress multisite, for sites beyond the main site, you would need to pass the `--url=` flag for each subsite. + +However, you can script this process in bash by getting a list of sites and looping over them: + +```bash +for site in $(wp site list --field=url); +then + wp pantheon session add-index +done +``` + +This can be applied to any of the other commands as needed to do them all in one go. We will be updating the command to iterate over all the sites in a multisite in a forthcoming release. + + ## Contributing ## See [CONTRIBUTING.md](https://github.com/pantheon-systems/wp-native-php-sessions/blob/main/CONTRIBUTING.md) for information on contributing. diff --git a/readme.txt b/readme.txt index 7acf585..18bb718 100644 --- a/readme.txt +++ b/readme.txt @@ -43,18 +43,30 @@ To override this use the `pantheon_session_expiration` filter before the WordPre == CLI Commands == -= `wp pantheon session add-index` = +**`wp pantheon session add-index`** Added in 1.4.0. This command should be run if your installation of the plugin occurred before the addition of the primary ID key to the session table in version 1.2.2. You will be automatically notified when you visit any admin page if this is the case. If there's no message, your version is good to go. Note that this command is non-destructive, a new table will be created and the existing one preserved in a backup state until you have verified that the upgrade is functioning as expected. -= `wp pantheon session primary-key-finalize` = +**`wp pantheon session primary-key-finalize`** Added in 1.4.0. If you have run the `add-index` command and have verified that the new table is functioning correctly, running the `primary-key-finalize` command will perform a database cleanup and remove the backup table. -= `wp pantheon session primary-key-revert` = +**`wp pantheon session primary-key-revert`** Added in 1.4.0. If you have run the `add-index` command and something unexpected has occurred, just run the `primary-key-revert` command and the backup table will immediately be returned to being the active table. += WordPress Multisite = +As of 1.4.1 the `add-index`, `primary-key-add` and `primary-key-revert` commands only apply to a single site. This means that to run on a WordPress multisite, for sites beyond the main site, you would need to pass the `--url=` flag for each subsite. + +However, you can script this process in bash by getting a list of sites and looping over them: + + for site in $(wp site list --field=url); + then + wp pantheon session add-index + done + +This can be applied to any of the other commands as needed to do them all in one go. We will be updating the command to iterate over all the sites in a multisite in a forthcoming release. + == Contributing == See [CONTRIBUTING.md](https://github.com/pantheon-systems/wp-native-php-sessions/blob/main/CONTRIBUTING.md) for information on contributing. From 00f0e57e7cd91f27e4a1adf1df3ef86cfc23fec9 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 19 Oct 2023 15:19:10 -0600 Subject: [PATCH 15/15] remove lint.yml that got merged in by accident --- .github/workflows/lint.yml | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 66d11af..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Lint and Test -on: push - -jobs: - lint: - runs-on: ubuntu-latest - name: Lint - steps: - - name: Checkout code - uses: actions/checkout@v3 - - name: Cache dependencies - uses: actions/cache@v3 - with: - path: ~/vendor - key: test-lint-dependencies-{{ checksum "composer.json" }} - restore-keys: test-lint-dependencies-{{ checksum "composer.json" }} - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: '8.0' - - name: Install dependencies - run: composer install -n --prefer-dist - - name: Run PHP Lint - run: composer phpcs

`, ``, ``, ``.| -| `$options` | `array` | Optional | Extra arguments for this notice. Can be used to alter the notice's default behavior. | - -The `$options` argument is an array that can have the following optional items: - -| Key | Type | Value | Default -|---|---|---|---| -| `scope` | `string` | Can be `global` or `user`. Determines if the dismissed status will be saved as an option or user-meta. | `global` | -| `type` | `string` | Can be one of `info`, `success`, `warning`, `error`. | `info` -| `alt_style` | `bool` | Set to true if you want to use alternative styles. These have a background-color depending on the `type` argument - in contrast to the normal styles that use a white background. | `false` | -| `capability` | `string` | The user capability required to see the notice. For a list of all available capabilities please refer to the [Roles and Capabilities](https://wordpress.org/support/article/roles-and-capabilities/) article. | `edit_theme_options` -| `screens` | `array` | An array of screens where the notice will be displayed. For a reference of all available screen-IDs, refer to [this article](https://codex.wordpress.org/Plugin_API/Admin_Screen_Reference). | `[]` | -| `option_prefix` | `string` | The prefix that will be used to build the option (or user-meta) name. Can contain lowercase latin letters and underscores. The actual option is built by combining the `option_prefix` argument with the defined ID from the 1st argument of the `add()` method. | `wptrt_notice_dismissed` | - -## Examples -You can add the following code within your theme's existing code. - -First we need to instantiate the `Notices` object: -```php -use WPTRT\AdminNotices\Notices; - -$my_theme_notices = new Notices(); -``` -To add a simple, default notice: -```php -$my_theme_notices->add( - 'my_theme_notice', // Unique ID. - esc_html__( 'Notice Title', 'textdomain' ), // The title for this notice. - esc_html__( 'Notice content', 'textdomain' ) // The content for this notice. -); -``` -The above example will create a new notice that will only show on all dashboard pages. When the notice gets dismissed, a new option will be saved in the database with the key `wptrt_notice_dismissed_my_theme_notice`. The key gets created by appending the `$id` to the default prefix for the option (`wptrt_notice_dismissed`), separated by an underscore. - -To add a more customized notice: - -```php -$my_theme_notices->add( - 'my_notice', // Unique ID. - esc_html__( 'Notice Title', 'textdomain' ), // The title for this notice. - esc_html__( 'Notice content', 'textdomain' ), // The content for this notice. - [ - 'scope' => 'user', // Dismiss is per-user instead of global. - 'screens' => [ 'themes' ], // Only show notice in the "themes" screen. - 'type' => 'warning', // Make this a warning (orange color). - 'alt_style' => true, // Use alt styles. - 'option_prefix' => 'my_theme', // Change the user-meta prefix. - ] -); -``` - -The above example will create a new notice that will only show in the "Themes" screen in the dashboard. When the notice gets dismissed, a new user-meta will be saved and the key for the stored user-meta will be `my_theme_my_notice`. The key gets created by appending the `$id` to our defined `option_prefix`, separated by an underscore. - -The `Notices` class can be used to add multiple notices. -Once you have finished adding the notices, you will have to run the `boot` method so that the notices can be added to the dashboard: -```php -$my_theme_notices->boot(); -``` - -To sum up all the above, a complete example of how to add an admin notice would look like this: - -```php -$my_theme_notices = new \WPTRT\AdminNotices\Notices(); -$my_theme_notices->add( 'my_theme_notice', __( 'Title', 'textdomain' ), __( 'Content', 'textdomain' ) ); -$my_theme_notices->boot(); -``` - -## Autoloading - -You'll need to use an autoloader with this. Ideally, this would be [Composer](https://getcomposer.org). However, we have a [basic autoloader](https://github.com/WPTRT/autoload) available to include with themes if needed. - -### Composer - -From the command line: - -```sh -composer require wptrt/admin-notices -``` - -### WPTRT Autoloader - -If using the WPTRT autoloader, use the following code: - -```php -include get_theme_file_path( 'path/to/autoload/src/Loader.php' ); - -$loader = new \WPTRT\Autoload\Loader(); -$loader->add( 'WPTRT\\AdminNotices\\Notice', get_theme_file_path( 'path/to/admin-notices/src' ) ); -$loader->register(); -``` diff --git a/lib/admin-notices/src/Dismiss.php b/lib/admin-notices/src/Dismiss.php deleted file mode 100644 index 22cfe98..0000000 --- a/lib/admin-notices/src/Dismiss.php +++ /dev/null @@ -1,166 +0,0 @@ - - * @copyright 2019 WPTRT - * @license https://www.gnu.org/licenses/gpl-2.0.html GPL-2.0-or-later - * @link https://github.com/WPTRT/admin-notices - */ - -namespace WPTRT\AdminNotices; - -/** - * The Dismiss class, responsible for dismissing and checking the status of admin notices. - * - * @since 1.0.0 - */ -class Dismiss { - - /** - * The notice-ID. - * - * @access private - * @since 1.0 - * @var string - */ - private $id; - - /** - * The prefix we'll be using for the option/user-meta. - * - * @access private - * @since 1.0 - * @var string - */ - private $prefix; - - /** - * The notice's scope. Can be "user" or "global". - * - * @access private - * @since 1.0 - * @var string - */ - private $scope; - - /** - * Constructor. - * - * @access public - * @since 1.0 - * @param string $id A unique ID for this notice. Can contain lowercase characters and underscores. - * @param string $prefix The prefix that will be used for the option/user-meta. - * @param string $scope Controls where the dismissal will be saved: user or global. - */ - public function __construct( $id, $prefix, $scope = 'global' ) { - - // Set the object properties. - $this->id = sanitize_key( $id ); - $this->prefix = sanitize_key( $prefix ); - $this->scope = ( in_array( $scope, [ 'global', 'user' ], true ) ) ? $scope : 'global'; - - // Handle AJAX requests to dismiss the notice. - add_action( 'wp_ajax_wptrt_dismiss_notice', [ $this, 'ajax_maybe_dismiss_notice' ] ); - - // Print the script after common.js. - add_action( 'admin_enqueue_scripts', array( $this, 'add_script' ) ); - } - - /** - * Print the script for dismissing the notice. - * - * @since 1.0 - * @return void - */ - public function add_script() { - - $id = esc_attr( $this->id ); - $nonce = wp_create_nonce( 'wptrt_dismiss_notice_' . $this->id ); - $admin_ajax_url = esc_url( admin_url( 'admin-ajax.php' ) ); - - $script = <<scope ) { - return ( get_user_meta( get_current_user_id(), "{$this->prefix}_{$this->id}", true ) ); - } - - return ( get_option( "{$this->prefix}_{$this->id}" ) ); - } - - /** - * Run check to see if we need to dismiss the notice. - * If all tests are successful then call the dismiss_notice() method. - * - * @access public - * @since 1.0 - * @return void - */ - public function ajax_maybe_dismiss_notice() { - - // Sanity check: Early exit if we're not on a wptrt_dismiss_notice action. - if ( ! isset( $_POST['action'] ) || 'wptrt_dismiss_notice' !== $_POST['action'] ) { - return; - } - - // Sanity check: Early exit if the ID of the notice is not the one from this object. - if ( ! isset( $_POST['id'] ) || $this->id !== $_POST['id'] ) { - return; - } - - // Security check: Make sure nonce is OK. - check_ajax_referer( 'wptrt_dismiss_notice_' . $this->id, 'nonce', true ); - - // If we got this far, we need to dismiss the notice. - $this->dismiss_notice(); - } - - /** - * Actually dismisses the notice. - * - * @access private - * @since 1.0 - * @return void - */ - private function dismiss_notice() { - if ( 'user' === $this->scope ) { - update_user_meta( get_current_user_id(), "{$this->prefix}_{$this->id}", true ); - return; - } - update_option( "{$this->prefix}_{$this->id}", true, false ); - } -} diff --git a/lib/admin-notices/src/Notice.php b/lib/admin-notices/src/Notice.php deleted file mode 100644 index ec35dae..0000000 --- a/lib/admin-notices/src/Notice.php +++ /dev/null @@ -1,297 +0,0 @@ - - * @copyright 2019 WPTRT - * @license https://www.gnu.org/licenses/gpl-2.0.html GPL-2.0-or-later - * @link https://github.com/WPTRT/admin-notices - */ - -namespace WPTRT\AdminNotices; - -/** - * The Admin_Notice class, responsible for creating admin notices. - * - * Each notice is a new instance of the object. - * - * @since 1.0.0 - */ -class Notice { - - /** - * The notice-ID. - * - * @access private - * @since 1.0 - * @var string - */ - private $id; - - /** - * The notice title. - * - * @access private - * @since 1.0 - * @var string - */ - private $title; - - /** - * The notice message. - * - * @access private - * @since 1.0 - * @var string - */ - private $message; - - /** - * An instance of the \WPTRT\AdminNotices\Dismiss object. - * - * @access public - * @since 1.0 - * @var \WPTRT\AdminNotices\Dismiss - */ - public $dismiss; - - /** - * The notice arguments. - * - * @access private - * @since 1.0 - * @var array - */ - private $options = [ - 'scope' => 'global', - 'type' => 'info', - 'alt_style' => false, - 'capability' => 'edit_theme_options', - 'option_prefix' => 'wptrt_notice_dismissed', - 'screens' => [], - ]; - - /** - * Allowed HTML in the message. - * - * @access private - * @since 1.0 - * @var array - */ - private $allowed_html = [ - 'p' => [], - 'a' => [ - 'href' => [], - 'rel' => [], - ], - 'em' => [], - 'strong' => [], - 'br' => [], - ]; - - /** - * An array of allowed types. - * - * @access private - * @since 1.0 - * @var array - */ - private $allowed_types = [ - 'info', - 'success', - 'error', - 'warning', - ]; - - /** - * Constructor. - * - * @access public - * @since 1.0 - * @param string $id A unique ID for this notice. Can contain lowercase characters and underscores. - * @param string $title The title for our notice. - * @param string $message The message for our notice. - * @param array $options An array of additional options to change the defaults for this notice. - * [ - * 'screens' => (array) An array of screens where the notice will be displayed. - * Leave empty to always show. - * Defaults to an empty array. - * 'scope' => (string) Can be "global" or "user". - * Determines if the dismissed status will be saved as an option or user-meta. - * Defaults to "global". - * 'type' => (string) Can be one of "info", "success", "warning", "error". - * Defaults to "info". - * 'alt_style' => (bool) Whether we want to use alt styles or not. - * Defaults to false. - * 'capability' => (string) The user capability required to see the notice. - * Defaults to "edit_theme_options". - * 'option_prefix' => (string) The prefix that will be used to build the option (or post-meta) name. - * Can contain lowercase latin letters and underscores. - * ]. - */ - public function __construct( $id, $title, $message, $options = [] ) { - - // Set the object properties. - $this->id = $id; - $this->title = $title; - $this->message = $message; - $this->options = wp_parse_args( $options, $this->options ); - - // Sanity check: Early exit if ID or message are empty. - if ( ! $this->id || ! $this->message ) { - return; - } - - /** - * Allow filtering the allowed HTML tags array. - * - * @since 1.0.2 - * @param array $allowed_html The list of allowed HTML tags. - * @return array - */ - $this->allowed_html = apply_filters( 'wptrt_admin_notices_allowed_html', $this->allowed_html ); - - // Instantiate the Dismiss object. - $this->dismiss = new Dismiss( $this->id, $this->options['option_prefix'], $this->options['scope'] ); - } - - /** - * Prints the notice. - * - * @access public - * @since 1.0 - * @return void - */ - public function the_notice() { - - // Early exit if we don't want to show this notice. - if ( ! $this->show() ) { - return; - } - - $html = $this->get_title(); - $html .= $this->get_message(); - - // Print the notice. - printf( - '