From 49532a935b3868bb500f093304eb5ede2a8761e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Sun, 11 Aug 2019 09:48:29 +0000 Subject: [PATCH 001/157] Introduce phpstan --- phpstan.neon.dist | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 phpstan.neon.dist diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..71d7036 --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,25 @@ +#$ composer require --dev phpstan/phpstan-shim szepeviktor/phpstan-wordpress +#$ vendor/bin/phpstan analyze + +includes: + - phar://phpstan.phar/conf/bleedingEdge.neon + - vendor/szepeviktor/phpstan-wordpress/extension.neon +parameters: +# TODO level: max + level: 5 + inferPrivatePropertyTypeFromConstructor: true + paths: + - %currentWorkingDirectory%/functions.php + - %currentWorkingDirectory%/src/ + autoload_files: + - %currentWorkingDirectory%/functions.php + autoload_directories: + - %currentWorkingDirectory%/src/ + ignoreErrors: + # Uses func_get_args() + - '#^Function apply_filters invoked with [34567] parameters, 2 required\.$#' + - '#^Function do_action invoked with [3456] parameters, 1-2 required\.$#' + - '#^Function current_user_can invoked with 2 parameters, 1 required\.$#' + - '#^Function add_query_arg invoked with [123] parameters?, 0 required\.$#' + # p2p plugin + - '#^Function (p2p_type|p2p_connection_exists) not found\.$#' From ba02881b8064307cb0709c25e7b34662449d828a Mon Sep 17 00:00:00 2001 From: Nicolas Lemoine Date: Sat, 4 Apr 2020 15:02:26 +0200 Subject: [PATCH 002/157] Add $post_id parameter to column custom callback --- src/class-extended-cpt-admin.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/class-extended-cpt-admin.php b/src/class-extended-cpt-admin.php index 1de1661..d928789 100644 --- a/src/class-extended-cpt-admin.php +++ b/src/class-extended-cpt-admin.php @@ -59,7 +59,7 @@ public function __construct( Extended_CPT $cpt, array $args = [] ) { add_filter( 'manage_pages_columns', [ $this, '_log_default_cols' ], 0 ); add_filter( "manage_edit-{$this->cpt->post_type}_sortable_columns", [ $this, 'sortables' ] ); add_filter( "manage_{$this->cpt->post_type}_posts_columns", [ $this, 'cols' ] ); - add_action( "manage_{$this->cpt->post_type}_posts_custom_column", [ $this, 'col' ] ); + add_action( "manage_{$this->cpt->post_type}_posts_custom_column", [ $this, 'col' ], 10, 2 ); add_action( 'load-edit.php', [ $this, 'default_sort' ] ); add_filter( 'pre_get_posts', [ $this, 'maybe_sort_by_fields' ] ); add_filter( 'posts_clauses', [ $this, 'maybe_sort_by_taxonomy' ], 10, 2 ); @@ -811,7 +811,7 @@ public function cols( array $cols ) : array { * * @param string $col The column name */ - public function col( string $col ) { + public function col( string $col, int $post_id ) { # Shorthand: $c = $this->args['admin_cols']; @@ -831,7 +831,7 @@ public function col( string $col ) { } if ( isset( $c[ $col ]['function'] ) ) { - call_user_func( $c[ $col ]['function'] ); + call_user_func( $c[ $col ]['function'], $post_id ); } elseif ( isset( $c[ $col ]['meta_key'] ) ) { $this->col_post_meta( $c[ $col ]['meta_key'], $c[ $col ] ); } elseif ( isset( $c[ $col ]['taxonomy'] ) ) { From 79b4ce70b3042d6fcbf1c8deabdd227051cc95fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Wed, 8 Jul 2020 21:29:38 +0000 Subject: [PATCH 003/157] Upgrade static analysis --- composer.json | 7 ++++++- phpstan.neon.dist | 20 +++++++------------- src/class-extended-cpt-admin.php | 2 +- src/class-extended-taxonomy-admin.php | 8 ++++---- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index 7bbdeb0..cff2942 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "wordpress-install-dir": "tests/wordpress" }, "require": { - "php": "^7.0" + "php": "^7.1" }, "require-dev": { "automattic/phpcs-neutron-standard": "^1.5", @@ -27,6 +27,7 @@ "phpcompatibility/phpcompatibility-wp": "^2", "phpunit/phpunit": "^6", "roots/wordpress": "*", + "szepeviktor/phpstan-wordpress": "^0.6.1", "vlucas/phpdotenv": "^3", "wp-cli/wp-cli-bundle": "^2.1", "wp-coding-standards/wpcs": "^2", @@ -39,6 +40,9 @@ "test:cs": [ "vendor/bin/phpcs -nps --colors --report-code --report-summary --report-width=80 --cache=tests/cache/phpcs ." ], + "test:analyze": [ + "vendor/bin/phpstan analyze" + ], "test:ut": [ "vendor/bin/wp db reset --yes --path=tests/wordpress #", "export WP_MULTISITE=0 && vendor/bin/phpunit --verbose --colors=always --exclude-group=ms-required", @@ -46,6 +50,7 @@ ], "test": [ "@test:cs", + "@test:analyze", "@test:ut" ] }, diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 71d7036..ca9acd0 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,25 +1,19 @@ -#$ composer require --dev phpstan/phpstan-shim szepeviktor/phpstan-wordpress -#$ vendor/bin/phpstan analyze - includes: - phar://phpstan.phar/conf/bleedingEdge.neon - vendor/szepeviktor/phpstan-wordpress/extension.neon parameters: -# TODO level: max + # Please raise level. level: 5 inferPrivatePropertyTypeFromConstructor: true paths: - - %currentWorkingDirectory%/functions.php - - %currentWorkingDirectory%/src/ - autoload_files: - - %currentWorkingDirectory%/functions.php - autoload_directories: - - %currentWorkingDirectory%/src/ + - functions.php + - src/ + scanFiles: + - functions.php + scanDirectories: + - src/ ignoreErrors: # Uses func_get_args() - '#^Function apply_filters invoked with [34567] parameters, 2 required\.$#' - - '#^Function do_action invoked with [3456] parameters, 1-2 required\.$#' - - '#^Function current_user_can invoked with 2 parameters, 1 required\.$#' - - '#^Function add_query_arg invoked with [123] parameters?, 0 required\.$#' # p2p plugin - '#^Function (p2p_type|p2p_connection_exists) not found\.$#' diff --git a/src/class-extended-cpt-admin.php b/src/class-extended-cpt-admin.php index 25a83a6..8a96459 100644 --- a/src/class-extended-cpt-admin.php +++ b/src/class-extended-cpt-admin.php @@ -33,7 +33,7 @@ class Extended_CPT_Admin { protected $_cols; /** - * @var array + * @var array|null */ protected $the_cols = null; diff --git a/src/class-extended-taxonomy-admin.php b/src/class-extended-taxonomy-admin.php index 7322b48..96e5ac8 100644 --- a/src/class-extended-taxonomy-admin.php +++ b/src/class-extended-taxonomy-admin.php @@ -32,7 +32,7 @@ class Extended_Taxonomy_Admin { protected $_cols; /** - * @var array + * @var array|null */ protected $the_cols = null; @@ -268,13 +268,13 @@ public function col_term_meta( string $meta_key, array $args, int $term_id ) { * Returns a sensible title for the current item (usually the arguments array for a column) * * @param array $item An array of arguments - * @return string The item title + * @return string|null The item title */ - protected function get_item_title( array $item ) : string { + protected function get_item_title( array $item ) : ?string { if ( isset( $item['meta_key'] ) ) { return ucwords( trim( str_replace( [ '_', '-' ], ' ', $item['meta_key'] ) ) ); } else { - return ''; + return null; } } From 40c5ef5e159c0d195ff0fa5ce086c68671caeb74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Wed, 8 Jul 2020 21:33:35 +0000 Subject: [PATCH 004/157] Raise PHP version for PHPCompatibility --- phpcs.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 9af19c3..8eb6fd8 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -1,7 +1,7 @@ - + */tests/* */vendor/* From 58d4a03704a875ae03548b05885505689f3f88f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Wed, 8 Jul 2020 23:34:59 +0200 Subject: [PATCH 005/157] Raise PHP verion in CI 7.0 -> 7.1 --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 51db2a7..e33652b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,7 @@ jobs: if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository strategy: matrix: - php: ['7.3', '7.0'] + php: ['7.3', '7.1'] wp: ['4.9', '*', 'dev-nightly'] fail-fast: false name: WP ${{ matrix.wp }} / PHP ${{ matrix.php }} From c1159ad5bdd7135cf81063e1a4d1b7097eb0d19d Mon Sep 17 00:00:00 2001 From: Nicolas Lemoine Date: Mon, 15 Mar 2021 12:11:22 +0100 Subject: [PATCH 006/157] Add attachment support (admin) --- src/class-extended-cpt-admin.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/class-extended-cpt-admin.php b/src/class-extended-cpt-admin.php index bdaaec3..41b6763 100644 --- a/src/class-extended-cpt-admin.php +++ b/src/class-extended-cpt-admin.php @@ -58,9 +58,16 @@ public function __construct( Extended_CPT $cpt, array $args = [] ) { if ( $this->args['admin_cols'] ) { add_filter( 'manage_posts_columns', [ $this, '_log_default_cols' ], 0 ); add_filter( 'manage_pages_columns', [ $this, '_log_default_cols' ], 0 ); - add_filter( "manage_edit-{$this->cpt->post_type}_sortable_columns", [ $this, 'sortables' ] ); - add_filter( "manage_{$this->cpt->post_type}_posts_columns", [ $this, 'cols' ] ); - add_action( "manage_{$this->cpt->post_type}_posts_custom_column", [ $this, 'col' ] ); + add_filter( 'manage_media_columns', [ $this, '_log_default_cols' ], 0 ); + if ( 'attachment' === $this->cpt->post_type ) { + add_filter( 'manage_upload_sortable_columns', [ $this, 'sortables' ] ); + add_filter( 'manage_media_columns', [ $this, 'cols' ] ); + add_action( 'manage_media_custom_column', [ $this, 'col' ] ); + } else { + add_filter( "manage_edit-{$this->cpt->post_type}_sortable_columns", [ $this, 'sortables' ] ); + add_filter( "manage_{$this->cpt->post_type}_posts_columns", [ $this, 'cols' ] ); + add_action( "manage_{$this->cpt->post_type}_posts_custom_column", [ $this, 'col' ] ); + } add_action( 'load-edit.php', [ $this, 'default_sort' ] ); add_action( 'pre_get_posts', [ $this, 'maybe_sort_by_fields' ] ); add_filter( 'posts_clauses', [ $this, 'maybe_sort_by_taxonomy' ], 10, 2 ); @@ -206,7 +213,7 @@ public function block_editor( bool $current_status, string $post_type ): bool { * @return string The post type name. */ protected static function get_current_post_type(): string { - if ( function_exists( 'get_current_screen' ) && is_object( get_current_screen() ) && 'edit' === get_current_screen()->base ) { + if ( function_exists( 'get_current_screen' ) && is_object( get_current_screen() ) && in_array( get_current_screen()->base, [ 'edit', 'upload' ], true ) ) { return get_current_screen()->post_type; } else { return ''; @@ -788,7 +795,7 @@ public function cols( array $cols ): array { } $new_cols = []; - $keep = [ + $keep = [ 'cb', 'title', ]; @@ -995,7 +1002,7 @@ public function col_taxonomy( string $taxonomy, array $args ) { break; case 'list': - $link = add_query_arg( [ + $link = add_query_arg( [ 'post_type' => $post->post_type, $taxonomy => $term->slug, ], admin_url( 'edit.php' ) ); @@ -1130,7 +1137,7 @@ public function col_connection( string $connection, array $args ) { $field = 'connected_' . $connection; if ( isset( $args['field'] ) && isset( $args['value'] ) ) { - $meta = [ + $meta = [ 'connected_meta' => [ $args['field'] => $args['value'], ], @@ -1202,7 +1209,7 @@ public function col_connection( string $connection, array $args ) { break; case 'list': - $link = add_query_arg( array_merge( [ + $link = add_query_arg( array_merge( [ 'post_type' => $_post->post_type, 'connected_type' => $connection, 'connected_items' => $post->ID, From 63ceff6c7adf14dd5627da1638b4d90e92adbea9 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sat, 20 Mar 2021 18:27:45 +0100 Subject: [PATCH 007/157] Switch to testing against a fixed WP version for stability. We'll introduce an action later for testing against trunk. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c2d3bc9..130e69c 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "johnbillion/falsey-assertequals-detector": "^2", "phpcompatibility/phpcompatibility-wp": "^2", "phpunit/phpunit": "^6", - "roots/wordpress": "*", + "roots/wordpress": "^5.7.0", "vlucas/phpdotenv": "^3", "wp-cli/db-command": "^2.0", "wp-coding-standards/wpcs": "2.3.0", From b5c45e95a7e909e9970b32da56e2c1c699b5e42a Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sat, 20 Mar 2021 18:28:30 +0100 Subject: [PATCH 008/157] Add support for new labels added in 5.7. Fixes #158. --- src/class-extended-cpt.php | 1 + src/class-extended-taxonomy.php | 1 + tests/phpunit/Setup.php | 3 +++ 3 files changed, 5 insertions(+) diff --git a/src/class-extended-cpt.php b/src/class-extended-cpt.php index 2b0a3de..d5b0f49 100644 --- a/src/class-extended-cpt.php +++ b/src/class-extended-cpt.php @@ -174,6 +174,7 @@ public function __construct( string $post_type, array $args = [], array $names = 'insert_into_item' => sprintf( 'Insert into %s', $this->post_singular_low ), 'uploaded_to_this_item' => sprintf( 'Uploaded to this %s', $this->post_singular_low ), 'filter_items_list' => sprintf( 'Filter %s list', $this->post_plural_low ), + 'filter_by_date' => 'Filter by date', 'items_list_navigation' => sprintf( '%s list navigation', $this->post_plural ), 'items_list' => sprintf( '%s list', $this->post_plural ), 'item_published' => sprintf( '%s published.', $this->post_singular ), diff --git a/src/class-extended-taxonomy.php b/src/class-extended-taxonomy.php index 56b4d91..e26229c 100644 --- a/src/class-extended-taxonomy.php +++ b/src/class-extended-taxonomy.php @@ -167,6 +167,7 @@ public function __construct( string $taxonomy, $object_type, array $args = [], a 'choose_from_most_used' => sprintf( 'Choose from most used %s', $this->tax_plural_low ), 'not_found' => sprintf( 'No %s found', $this->tax_plural_low ), 'no_terms' => sprintf( 'No %s', $this->tax_plural_low ), + 'filter_by_item' => sprintf( 'Filter by %s', $this->tax_singular_low ), 'items_list_navigation' => sprintf( '%s list navigation', $this->tax_plural ), 'items_list' => sprintf( '%s list', $this->tax_plural ), 'most_used' => 'Most Used', diff --git a/tests/phpunit/Setup.php b/tests/phpunit/Setup.php index 80490ec..5de9853 100644 --- a/tests/phpunit/Setup.php +++ b/tests/phpunit/Setup.php @@ -166,6 +166,7 @@ public function testPostTypeLabelsAreCorrect() { 'remove_featured_image' => 'Remove icon', 'use_featured_image' => 'Use as icon', 'filter_items_list' => 'Filter plural list', + 'filter_by_date' => 'Filter by date', 'items_list_navigation' => 'Plural list navigation', 'items_list' => 'Plural list', 'item_published' => 'Singular published.', @@ -202,6 +203,7 @@ public function testPostTypeLabelsAreCorrect() { 'remove_featured_image' => 'Remove featured image', 'use_featured_image' => 'Use as featured image', 'filter_items_list' => 'Filter FAQs list', + 'filter_by_date' => 'Filter by date', 'items_list_navigation' => 'FAQs list navigation', 'items_list' => 'FAQs list', 'item_published' => 'FAQ published.', @@ -240,6 +242,7 @@ public function testTaxonomyLabelsAreCorrect() { 'choose_from_most_used' => 'Choose from most used foo categorys', 'not_found' => 'No foo categorys found', 'no_terms' => 'No foo categorys', + 'filter_by_item' => 'Filter by foo category', 'items_list_navigation' => 'Foo Categorys list navigation', 'items_list' => 'Foo Categorys list', 'most_used' => 'Most Used', From 6e2b763ed7f630e99b36bea6855f3a12dbef7fa3 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sat, 20 Mar 2021 18:30:46 +0100 Subject: [PATCH 009/157] Use the default MySQL installed on Ubuntu. --- .github/workflows/test.yml | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e565a10..26809ed 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,15 +11,6 @@ jobs: fail-fast: false name: WP ${{ matrix.wp }} / PHP ${{ matrix.php }} runs-on: ubuntu-18.04 - services: - mysql: - image: mysql:5.7 - env: - MYSQL_DATABASE: wordpress - MYSQL_ALLOW_EMPTY_PASSWORD: yes - ports: - - 3306 - options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 steps: - name: Checkout repository uses: actions/checkout@v1 @@ -55,13 +46,16 @@ jobs: php --version php -m composer --version + mysql --version - name: Install dependencies run: | + sudo systemctl start mysql.service composer install --prefer-dist --no-suggest composer require --dev --update-with-dependencies --no-suggest --prefer-dist roots/wordpress="${{ matrix.wp }} || *" wp-phpunit/wp-phpunit="${{ matrix.wp }} || *" - name: Run the tests run: composer test env: - WP_TESTS_DB_HOST: 127.0.0.1:${{ job.services.mysql.ports['3306'] }} + MYSQL_DATABASE: wordpress + WP_TESTS_DB_PASS: root From e758d7b180cb999476829200eeb3a149811c17c1 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sat, 20 Mar 2021 18:46:14 +0100 Subject: [PATCH 010/157] More tweaks to dependencies and the actions. --- .github/workflows/test.yml | 5 ++--- composer.json | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 26809ed..e28d6c1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,7 +7,7 @@ jobs: strategy: matrix: php: ['7.4', '7.0'] - wp: ['4.9', '*', 'dev-nightly'] + wp: ['4.9', '5.7', 'dev-nightly'] fail-fast: false name: WP ${{ matrix.wp }} / PHP ${{ matrix.php }} runs-on: ubuntu-18.04 @@ -51,8 +51,7 @@ jobs: - name: Install dependencies run: | sudo systemctl start mysql.service - composer install --prefer-dist --no-suggest - composer require --dev --update-with-dependencies --no-suggest --prefer-dist roots/wordpress="${{ matrix.wp }} || *" wp-phpunit/wp-phpunit="${{ matrix.wp }} || *" + composer require --dev --update-with-dependencies --no-suggest --prefer-dist roots/wordpress="${{ matrix.wp }}" wp-phpunit/wp-phpunit="${{ matrix.wp }} || *" - name: Run the tests run: composer test diff --git a/composer.json b/composer.json index 130e69c..faaadcc 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "vlucas/phpdotenv": "^3", "wp-cli/db-command": "^2.0", "wp-coding-standards/wpcs": "2.3.0", - "wp-phpunit/wp-phpunit": "*" + "wp-phpunit/wp-phpunit": "^5.7.0" }, "scripts": { "post-update-cmd": [ From 21d620995af3dcdd18c3848597b481e3affbb82a Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sat, 20 Mar 2021 18:46:22 +0100 Subject: [PATCH 011/157] Add a weekly cron event. --- .github/workflows/test.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e28d6c1..5dafd92 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,5 +1,10 @@ name: Test -on: [push, pull_request] +on: + push: + pull_request: + # Once weekly On Wednesdays at 02:00 UTC. + schedule: + - cron: '0 2 * * 3' jobs: build: From d1312807df97e04f2d56c94a2a0731a8646b3dad Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sat, 20 Mar 2021 18:48:08 +0100 Subject: [PATCH 012/157] This is needed. --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5dafd92..6ea4d79 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -57,6 +57,7 @@ jobs: run: | sudo systemctl start mysql.service composer require --dev --update-with-dependencies --no-suggest --prefer-dist roots/wordpress="${{ matrix.wp }}" wp-phpunit/wp-phpunit="${{ matrix.wp }} || *" + composer install --prefer-dist --no-suggest - name: Run the tests run: composer test From 8b06ffe11587a0019acd88215dcaa982b293a5e3 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sat, 20 Mar 2021 18:51:23 +0100 Subject: [PATCH 013/157] Boop. --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6ea4d79..1aa83e5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -56,8 +56,8 @@ jobs: - name: Install dependencies run: | sudo systemctl start mysql.service - composer require --dev --update-with-dependencies --no-suggest --prefer-dist roots/wordpress="${{ matrix.wp }}" wp-phpunit/wp-phpunit="${{ matrix.wp }} || *" composer install --prefer-dist --no-suggest + composer require --dev --update-with-dependencies --no-suggest --prefer-dist roots/wordpress="${{ matrix.wp }}" wp-phpunit/wp-phpunit="${{ matrix.wp }} || *" - name: Run the tests run: composer test From fdc326e50b080db968dcda4c4e212ba1c94287c9 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sat, 20 Mar 2021 19:09:53 +0100 Subject: [PATCH 014/157] More version consistency. --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1aa83e5..82659fc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: php: ['7.4', '7.0'] - wp: ['4.9', '5.7', 'dev-nightly'] + wp: ['^4.9.0', '^5.7.0', 'dev-nightly'] fail-fast: false name: WP ${{ matrix.wp }} / PHP ${{ matrix.php }} runs-on: ubuntu-18.04 From d5c16a688fe73e5e0c517e4a80b0c770c876413b Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sat, 20 Mar 2021 19:36:11 +0100 Subject: [PATCH 015/157] More dependency fixing. --- .github/workflows/test.yml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 82659fc..50df2cd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: php: ['7.4', '7.0'] - wp: ['^4.9.0', '^5.7.0', 'dev-nightly'] + wp: ['4.9', '5.7', 'nightly'] fail-fast: false name: WP ${{ matrix.wp }} / PHP ${{ matrix.php }} runs-on: ubuntu-18.04 @@ -56,8 +56,17 @@ jobs: - name: Install dependencies run: | sudo systemctl start mysql.service - composer install --prefer-dist --no-suggest - composer require --dev --update-with-dependencies --no-suggest --prefer-dist roots/wordpress="${{ matrix.wp }}" wp-phpunit/wp-phpunit="${{ matrix.wp }} || *" + composer install --prefer-dist + + - name: Update dependencies for nightly + if: ${{ matrix.wp == 'nightly' }} + run: | + composer require --dev --update-with-dependencies --prefer-dist roots/wordpress="dev-nightly" wp-phpunit/wp-phpunit="dev-master" + + - name: Update dependencies for stable + if: ${{ matrix.wp != 'nightly' }} + run: | + composer require --dev --update-with-dependencies --prefer-dist roots/wordpress="^${{ matrix.wp }}.0" wp-phpunit/wp-phpunit="^${{ matrix.wp }}.0" - name: Run the tests run: composer test From f6ef69b80d41f775824bef38493debac5df466f4 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sat, 20 Mar 2021 19:45:29 +0100 Subject: [PATCH 016/157] Only test WP 4.9 on PHP 7.2 as that's the latest PHP version supported. --- .github/workflows/test.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 50df2cd..0089a03 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,10 @@ jobs: strategy: matrix: php: ['7.4', '7.0'] - wp: ['4.9', '5.7', 'nightly'] + wp: ['5.7', 'nightly'] + include: + - php: '7.2' + wp: '4.9' fail-fast: false name: WP ${{ matrix.wp }} / PHP ${{ matrix.php }} runs-on: ubuntu-18.04 From 3b58e254b708464489ad9d1f36b9f46ec7b93adc Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sat, 20 Mar 2021 19:57:00 +0100 Subject: [PATCH 017/157] Allow the job to run on the cron schedule. --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0089a03..b86cb64 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ on: jobs: build: - if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository + if: github.event_name == 'push' || github.event_name == 'schedule' || github.event.pull_request.head.repo.full_name != github.repository strategy: matrix: php: ['7.4', '7.0'] From 10898487af59de3f0727f8f8af048e5a1b30633f Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sat, 20 Mar 2021 20:07:26 +0100 Subject: [PATCH 018/157] Split the WP nightly test and only run it on a cron schedule. --- .github/workflows/test-nightly.yml | 36 ++++++++++++++++++++++++++++++ .github/workflows/test.yml | 14 +----------- 2 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/test-nightly.yml diff --git a/.github/workflows/test-nightly.yml b/.github/workflows/test-nightly.yml new file mode 100644 index 0000000..b292c76 --- /dev/null +++ b/.github/workflows/test-nightly.yml @@ -0,0 +1,36 @@ +name: Test Nightly +on: + # Once weekly on Wednesdays at 02:00 UTC. + schedule: + - cron: '0 2 * * 3' + +jobs: + build: + strategy: + matrix: + php: ['7.4', '7.0'] + fail-fast: false + name: WP nightly / PHP ${{ matrix.php }} + runs-on: ubuntu-18.04 + steps: + - name: Checkout repository + uses: actions/checkout@v1 + + - name: Install PHP + uses: shivammathur/setup-php@2.7.0 + with: + php-version: ${{ matrix.php }} + extensions: mysqli, xmlwriter + coverage: none + + - name: Install dependencies + run: | + sudo systemctl start mysql.service + composer install --prefer-dist + composer require --dev --update-with-dependencies --prefer-dist roots/wordpress="dev-nightly" wp-phpunit/wp-phpunit="dev-master" + + - name: Run the tests + run: composer test + env: + MYSQL_DATABASE: wordpress + WP_TESTS_DB_PASS: root diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b86cb64..7f17989 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,13 +2,10 @@ name: Test on: push: pull_request: - # Once weekly On Wednesdays at 02:00 UTC. - schedule: - - cron: '0 2 * * 3' jobs: build: - if: github.event_name == 'push' || github.event_name == 'schedule' || github.event.pull_request.head.repo.full_name != github.repository + if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository strategy: matrix: php: ['7.4', '7.0'] @@ -60,15 +57,6 @@ jobs: run: | sudo systemctl start mysql.service composer install --prefer-dist - - - name: Update dependencies for nightly - if: ${{ matrix.wp == 'nightly' }} - run: | - composer require --dev --update-with-dependencies --prefer-dist roots/wordpress="dev-nightly" wp-phpunit/wp-phpunit="dev-master" - - - name: Update dependencies for stable - if: ${{ matrix.wp != 'nightly' }} - run: | composer require --dev --update-with-dependencies --prefer-dist roots/wordpress="^${{ matrix.wp }}.0" wp-phpunit/wp-phpunit="^${{ matrix.wp }}.0" - name: Run the tests From 9883c4e116bb283e738d9e413334a527ec86db76 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sat, 20 Mar 2021 20:09:15 +0100 Subject: [PATCH 019/157] Allow manually running the nightly action. --- .github/workflows/test-nightly.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-nightly.yml b/.github/workflows/test-nightly.yml index b292c76..9441f7d 100644 --- a/.github/workflows/test-nightly.yml +++ b/.github/workflows/test-nightly.yml @@ -3,6 +3,7 @@ on: # Once weekly on Wednesdays at 02:00 UTC. schedule: - cron: '0 2 * * 3' + workflow_dispatch: jobs: build: From fcab93d380a344ef914f0e43fb22d4e3f46f1ee6 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sat, 20 Mar 2021 20:10:07 +0100 Subject: [PATCH 020/157] Switch to actively testing against the two most recent versions of WP. --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7f17989..e18a5a8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: php: ['7.4', '7.0'] - wp: ['5.7', 'nightly'] + wp: ['5.6', '5.7'] include: - php: '7.2' wp: '4.9' From ae0524cbc18d8b4a5b2100519c717c8d66599155 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sat, 20 Mar 2021 20:12:48 +0100 Subject: [PATCH 021/157] Yeah actually let's trim this down some more. --- .github/workflows/test.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e18a5a8..cffd258 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,12 +9,11 @@ jobs: strategy: matrix: php: ['7.4', '7.0'] - wp: ['5.6', '5.7'] include: - php: '7.2' wp: '4.9' fail-fast: false - name: WP ${{ matrix.wp }} / PHP ${{ matrix.php }} + name: PHP ${{ matrix.php }} runs-on: ubuntu-18.04 steps: - name: Checkout repository @@ -57,7 +56,6 @@ jobs: run: | sudo systemctl start mysql.service composer install --prefer-dist - composer require --dev --update-with-dependencies --prefer-dist roots/wordpress="^${{ matrix.wp }}.0" wp-phpunit/wp-phpunit="^${{ matrix.wp }}.0" - name: Run the tests run: composer test From 4813a7a87fe4369ef26dbbc36b2419d57d24809f Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sat, 20 Mar 2021 20:13:57 +0100 Subject: [PATCH 022/157] Improve the test labelling. --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cffd258..cbc9727 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,11 +9,12 @@ jobs: strategy: matrix: php: ['7.4', '7.0'] + wp: ['5.7'] include: - php: '7.2' wp: '4.9' fail-fast: false - name: PHP ${{ matrix.php }} + name: WP ${{ matrix.wp }} / PHP ${{ matrix.php }} runs-on: ubuntu-18.04 steps: - name: Checkout repository From 62ddc190615815dfe03e85256014a230985d31ec Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sun, 21 Mar 2021 01:12:35 +0100 Subject: [PATCH 023/157] New labels for WP 5.8. --- src/class-extended-cpt.php | 2 ++ src/class-extended-taxonomy.php | 2 ++ tests/phpunit/Setup.php | 7 +++++++ 3 files changed, 11 insertions(+) diff --git a/src/class-extended-cpt.php b/src/class-extended-cpt.php index d5b0f49..e7e8f3b 100644 --- a/src/class-extended-cpt.php +++ b/src/class-extended-cpt.php @@ -182,6 +182,8 @@ public function __construct( string $post_type, array $args = [], array $names = 'item_reverted_to_draft' => sprintf( '%s reverted to draft.', $this->post_singular ), 'item_scheduled' => sprintf( '%s scheduled.', $this->post_singular ), 'item_updated' => sprintf( '%s updated.', $this->post_singular ), + 'item_link' => sprintf( '%s Link', $this->post_singular ), + 'item_link_description' => sprintf( 'A link to a %s.', $this->post_singular_low ), ]; # Build the featured image labels: diff --git a/src/class-extended-taxonomy.php b/src/class-extended-taxonomy.php index e26229c..6295908 100644 --- a/src/class-extended-taxonomy.php +++ b/src/class-extended-taxonomy.php @@ -172,6 +172,8 @@ public function __construct( string $taxonomy, $object_type, array $args = [], a 'items_list' => sprintf( '%s list', $this->tax_plural ), 'most_used' => 'Most Used', 'back_to_items' => sprintf( '← Back to %s', $this->tax_plural ), + 'item_link' => sprintf( '%s Link', $this->tax_singular ), + 'item_link_description' => sprintf( 'A link to a %s.', $this->tax_singular_low ), 'no_item' => sprintf( 'No %s', $this->tax_singular_low ), # Custom label 'filter_by' => sprintf( 'Filter by %s', $this->tax_singular_low ), # Custom label ]; diff --git a/tests/phpunit/Setup.php b/tests/phpunit/Setup.php index 5de9853..4261bd1 100644 --- a/tests/phpunit/Setup.php +++ b/tests/phpunit/Setup.php @@ -174,6 +174,8 @@ public function testPostTypeLabelsAreCorrect() { 'item_reverted_to_draft' => 'Singular reverted to draft.', 'item_scheduled' => 'Singular scheduled.', 'item_updated' => 'Singular updated.', + 'item_link' => 'Singular Link', + 'item_link_description' => 'A link to a singular.', ), $bar->labels ); $featured_image = version_compare( $wp_version, '5.4', '>=' ) ? 'Featured image' : 'Featured Image'; @@ -211,6 +213,8 @@ public function testPostTypeLabelsAreCorrect() { 'item_reverted_to_draft' => 'FAQ reverted to draft.', 'item_scheduled' => 'FAQ scheduled.', 'item_updated' => 'FAQ updated.', + 'item_link' => 'FAQ Link', + 'item_link_description' => 'A link to a FAQ.', ), $faq->labels ); $post = get_post_type_object( 'post' ); @@ -251,8 +255,11 @@ public function testTaxonomyLabelsAreCorrect() { 'filter_by' => 'Filter by foo category', 'name_admin_bar' => 'Foo Category', 'archives' => 'Foo Categorys Archives', + 'item_link' => 'Foo Category Link', + 'item_link_description' => 'A link to a foo category.', ), $foo->labels ); } + public function testArchiveLinksAreCorrect() { $link = get_post_type_archive_link( $this->cpts['hello']->post_type ); From e420662e5e5ceb82d3d73680876a3fb24016a171 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sun, 21 Mar 2021 01:26:00 +0100 Subject: [PATCH 024/157] Docs. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f3ead39..4476940 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [![Build Status](https://img.shields.io/github/workflow/status/johnbillion/extended-cpts/Test/develop?style=flat-square)](https://github.com/johnbillion/extended-cpts/actions) [![Stable Release](https://img.shields.io/packagist/v/johnbillion/extended-cpts.svg)](https://packagist.org/packages/johnbillion/extended-cpts) [![License](https://img.shields.io/badge/license-GPL_v2%2B-blue.svg)](https://github.com/johnbillion/extended-cpts/blob/master/LICENSE) -[![PHP 7](https://img.shields.io/badge/php-7%20/%208-blue.svg)](https://wordpress.org/support/update-php/) +[![PHP 7 and 8](https://img.shields.io/badge/php-7%20/%208-blue.svg)](https://wordpress.org/support/update-php/) [![Documentation](https://img.shields.io/badge/documentation-wiki-blue.svg)](https://github.com/johnbillion/extended-cpts/wiki) # Extended CPTs # @@ -63,7 +63,7 @@ Not your first time here? See [Recent Changes for Developers](https://github.com - PHP 7.4+ is recommended - PHP 8 is supported * **WordPress:** 4.8 - - Tested up to WP 5.6 + - Tested up to WP 5.7 ## Installation ## From 59ce9f4e0422512eec6f698ccba4a6a81b018fdb Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sun, 21 Mar 2021 01:26:19 +0100 Subject: [PATCH 025/157] Version 4.5.2. --- extended-cpts.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extended-cpts.php b/extended-cpts.php index 9ccabe2..aa57afa 100755 --- a/extended-cpts.php +++ b/extended-cpts.php @@ -9,7 +9,7 @@ * @link https://github.com/johnbillion/extended-cpts * @copyright 2012-2021 John Blackbourn * @license GPL v2 or later - * @version 4.5.1 + * @version 4.5.2 * * 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 From 6c3bdcd8005d3adc6374acbc0a114962c7e28618 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sun, 21 Mar 2021 15:49:27 +0100 Subject: [PATCH 026/157] Docs. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4476940..196d865 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![Build Status](https://img.shields.io/github/workflow/status/johnbillion/extended-cpts/Test/develop?style=flat-square)](https://github.com/johnbillion/extended-cpts/actions) [![Stable Release](https://img.shields.io/packagist/v/johnbillion/extended-cpts.svg)](https://packagist.org/packages/johnbillion/extended-cpts) -[![License](https://img.shields.io/badge/license-GPL_v2%2B-blue.svg)](https://github.com/johnbillion/extended-cpts/blob/master/LICENSE) +[![License](https://img.shields.io/badge/license-GPL_v2%2B-blue.svg)](https://github.com/johnbillion/extended-cpts/blob/trunk/LICENSE) [![PHP 7 and 8](https://img.shields.io/badge/php-7%20/%208-blue.svg)](https://wordpress.org/support/update-php/) [![Documentation](https://img.shields.io/badge/documentation-wiki-blue.svg)](https://github.com/johnbillion/extended-cpts/wiki) From 000c820d5aaae5d6894385a38b9c8e8aa8938ce2 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sat, 27 Mar 2021 18:19:24 +0100 Subject: [PATCH 027/157] Prevent the tests running when a tag is pushed. --- .github/workflows/test.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cbc9727..c915840 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,11 +1,15 @@ name: Test on: push: + branches: + - 'develop' + - 'trunk' pull_request: + branches: + - '**' jobs: build: - if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository strategy: matrix: php: ['7.4', '7.0'] From a676841ee9543e26bd38adf15d06503a4a363d5e Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sat, 27 Mar 2021 19:03:48 +0100 Subject: [PATCH 028/157] We're going to 7.2. --- .github/workflows/test.yml | 2 +- README.md | 2 +- composer.json | 2 +- phpcs.xml.dist | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 19450b0..562f769 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: build: strategy: matrix: - php: ['7.4', '7.1'] + php: ['7.4', '7.2'] wp: ['5.7'] include: - php: '7.2' diff --git a/README.md b/README.md index 196d865..5d2f5ce 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ Not your first time here? See [Recent Changes for Developers](https://github.com ## Minimum Requirements ## -* **PHP:** 7.0 +* **PHP:** 7.2 - PHP 7.4+ is recommended - PHP 8 is supported * **WordPress:** 4.8 diff --git a/composer.json b/composer.json index faaadcc..a8e744d 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "wordpress-install-dir": "tests/wordpress" }, "require": { - "php": "^7 | ^8" + "php": "^7.2 | ^8" }, "require-dev": { "automattic/phpcs-neutron-standard": "1.6.0", diff --git a/phpcs.xml.dist b/phpcs.xml.dist index af79822..e3276c2 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -1,7 +1,7 @@ - + */tests/* */vendor/* From ae49f76e78c384e42139cf0e82ebd40a328927b8 Mon Sep 17 00:00:00 2001 From: Jordy Crescoli Date: Fri, 16 Apr 2021 17:06:54 +0200 Subject: [PATCH 029/157] Add the "ext-cpts-admin/{$post_type}/instance" action to allow access to the Extended_CPT_Admin instances. --- src/class-extended-cpt-admin.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/class-extended-cpt-admin.php b/src/class-extended-cpt-admin.php index 41b6763..a88c4bc 100644 --- a/src/class-extended-cpt-admin.php +++ b/src/class-extended-cpt-admin.php @@ -116,6 +116,15 @@ public function __construct( Extended_CPT $cpt, array $args = [] ) { # Post updated messages: add_filter( 'post_updated_messages', [ $this, 'post_updated_messages' ], 1 ); add_filter( 'bulk_post_updated_messages', [ $this, 'bulk_post_updated_messages' ], 1, 2 ); + + /** + * Fired when the extended post type admin instance is set up. + * + * @todo Add @since tag when version is bumped. + * + * @param Extended_CPT_Admin $instance The extended post type admin instance. + */ + do_action( "ext-cpts-admin/{$this->cpt->post_type}/instance", $this ); } /** From e03a3593a731b4f58e4eeeb0d9ef52f57b0a4b65 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sun, 6 Jun 2021 16:37:28 +0100 Subject: [PATCH 030/157] Introduce the `ExtCPTs` namespace for all classes. --- functions.php | 23 +++++++++++------- src/class-extended-cpt-admin.php | 24 ++++++++++++------- src/class-extended-cpt-rewrite-testing.php | 8 ++++--- src/class-extended-cpt.php | 16 +++++++++---- src/class-extended-rewrite-testing.php | 2 ++ src/class-extended-taxonomy-admin.php | 13 ++++++---- ...lass-extended-taxonomy-rewrite-testing.php | 8 ++++--- src/class-extended-taxonomy.php | 8 ++++--- ...lass-walker-extendedtaxonomycheckboxes.php | 4 ++++ src/class-walker-extendedtaxonomydropdown.php | 4 ++++ src/class-walker-extendedtaxonomyradios.php | 4 ++++ 11 files changed, 80 insertions(+), 34 deletions(-) diff --git a/functions.php b/functions.php index 32b63eb..ba1491e 100644 --- a/functions.php +++ b/functions.php @@ -1,6 +1,11 @@ args ); + new Post_Type_Admin( $cpt, $cpt->args ); } return $cpt; @@ -83,7 +88,7 @@ function register_extended_post_type( string $post_type, array $args = [], array * @type bool $dashboard_glance Whether to show this taxonomy on the 'At a Glance' section of the admin dashboard. * Default false. * @type array $admin_cols Associative array of admin screen columns to show for this taxonomy. See the - * `Extended_Taxonomy_Admin::cols()` method for more information. + * `Taxonomy_Admin::cols()` method for more information. * @type bool $exclusive This parameter isn't feature complete. All it does currently is set the meta box * to the 'radio' meta box, thus meaning any given post can only have one term * associated with it for that taxonomy. 'exclusive' isn't really the right name for @@ -100,17 +105,17 @@ function register_extended_post_type( string $post_type, array $args = [], array * @type string $singular The singular form of the taxonomy name. * @type string $slug The slug used in the term permalinks for this taxonomy. * } - * @return Extended_Taxonomy + * @return Taxonomy */ -function register_extended_taxonomy( string $taxonomy, $object_type, array $args = [], array $names = [] ): Extended_Taxonomy { +function register_extended_taxonomy( string $taxonomy, $object_type, array $args = [], array $names = [] ): Taxonomy { if ( ! did_action( 'init' ) ) { trigger_error( esc_html__( 'Taxonomies must be registered on the "init" hook.', 'extended-cpts' ), E_USER_WARNING ); } - $taxo = new Extended_Taxonomy( $taxonomy, $object_type, $args, $names ); + $taxo = new Taxonomy( $taxonomy, $object_type, $args, $names ); if ( is_admin() ) { - new Extended_Taxonomy_Admin( $taxo, $taxo->args ); + new Taxonomy_Admin( $taxo, $taxo->args ); } return $taxo; diff --git a/src/class-extended-cpt-admin.php b/src/class-extended-cpt-admin.php index 41b6763..2d298e2 100644 --- a/src/class-extended-cpt-admin.php +++ b/src/class-extended-cpt-admin.php @@ -1,7 +1,15 @@ cpt = $cpt; # Merge our args with the defaults: $this->args = array_merge( $this->defaults, $args ); @@ -249,7 +257,7 @@ public function filters() { * * @since 4.3.0 * - * @param Extended_CPT_Admin $this The post type admin controller instance. + * @param Post_Type_Admin $this The post type admin controller instance. * @param array $filter The filter arguments. * @param string $id The filter's `id` attribute value. */ @@ -499,7 +507,7 @@ public function maybe_filter( WP_Query $wp_query ) { return; } - $vars = Extended_CPT::get_filter_vars( $wp_query->query, $this->cpt->args['admin_filters'], $this->cpt->post_type ); + $vars = Post_Type::get_filter_vars( $wp_query->query, $this->cpt->args['admin_filters'], $this->cpt->post_type ); if ( empty( $vars ) ) { return; @@ -527,7 +535,7 @@ public function maybe_sort_by_fields( WP_Query $wp_query ) { return; } - $sort = Extended_CPT::get_sort_field_vars( $wp_query->query, $this->cpt->args['admin_cols'] ); + $sort = Post_Type::get_sort_field_vars( $wp_query->query, $this->cpt->args['admin_cols'] ); if ( empty( $sort ) ) { return; @@ -550,7 +558,7 @@ public function maybe_sort_by_taxonomy( array $clauses, WP_Query $wp_query ): ar return $clauses; } - $sort = Extended_CPT::get_sort_taxonomy_clauses( $clauses, $wp_query->query, $this->cpt->args['admin_cols'] ); + $sort = Post_Type::get_sort_taxonomy_clauses( $clauses, $wp_query->query, $this->cpt->args['admin_cols'] ); if ( empty( $sort ) ) { return $clauses; diff --git a/src/class-extended-cpt-rewrite-testing.php b/src/class-extended-cpt-rewrite-testing.php index c5445b0..9a1a47b 100644 --- a/src/class-extended-cpt-rewrite-testing.php +++ b/src/class-extended-cpt-rewrite-testing.php @@ -1,17 +1,19 @@ cpt = $cpt; } diff --git a/src/class-extended-cpt.php b/src/class-extended-cpt.php index e7e8f3b..c4dafe9 100644 --- a/src/class-extended-cpt.php +++ b/src/class-extended-cpt.php @@ -1,7 +1,15 @@ get_tests() ); } diff --git a/src/class-extended-rewrite-testing.php b/src/class-extended-rewrite-testing.php index b61851e..6d31a56 100644 --- a/src/class-extended-rewrite-testing.php +++ b/src/class-extended-rewrite-testing.php @@ -1,6 +1,8 @@ taxo = $taxo; # Merge our args with the defaults: diff --git a/src/class-extended-taxonomy-rewrite-testing.php b/src/class-extended-taxonomy-rewrite-testing.php index 95bcd32..cc17dce 100644 --- a/src/class-extended-taxonomy-rewrite-testing.php +++ b/src/class-extended-taxonomy-rewrite-testing.php @@ -1,14 +1,16 @@ taxo = $taxo; } diff --git a/src/class-extended-taxonomy.php b/src/class-extended-taxonomy.php index 6295908..83bb277 100644 --- a/src/class-extended-taxonomy.php +++ b/src/class-extended-taxonomy.php @@ -1,7 +1,9 @@ get_tests() ); } diff --git a/src/class-walker-extendedtaxonomycheckboxes.php b/src/class-walker-extendedtaxonomycheckboxes.php index 9db2bed..7b46a37 100644 --- a/src/class-walker-extendedtaxonomycheckboxes.php +++ b/src/class-walker-extendedtaxonomycheckboxes.php @@ -1,6 +1,10 @@ elements properly. * diff --git a/src/class-walker-extendedtaxonomydropdown.php b/src/class-walker-extendedtaxonomydropdown.php index dc08c57..a1be3ea 100644 --- a/src/class-walker-extendedtaxonomydropdown.php +++ b/src/class-walker-extendedtaxonomydropdown.php @@ -1,6 +1,10 @@ Date: Sun, 6 Jun 2021 16:49:52 +0100 Subject: [PATCH 031/157] Improved naming for the term walkers. --- src/class-extended-cpt-admin.php | 2 +- src/class-extended-taxonomy-admin.php | 13 ++++++------- src/class-walker-extendedtaxonomycheckboxes.php | 8 ++------ src/class-walker-extendedtaxonomydropdown.php | 8 ++------ src/class-walker-extendedtaxonomyradios.php | 8 ++------ 5 files changed, 13 insertions(+), 26 deletions(-) diff --git a/src/class-extended-cpt-admin.php b/src/class-extended-cpt-admin.php index 2d298e2..11cf6a9 100644 --- a/src/class-extended-cpt-admin.php +++ b/src/class-extended-cpt-admin.php @@ -274,7 +274,7 @@ public function filters() { require_once __DIR__ . '/class-walker-extendedtaxonomydropdown.php'; - $walker = new Walker_ExtendedTaxonomyDropdown( [ + $walker = new Walker\Dropdown( [ 'field' => 'slug', ] ); diff --git a/src/class-extended-taxonomy-admin.php b/src/class-extended-taxonomy-admin.php index fe1ee30..6b18080 100644 --- a/src/class-extended-taxonomy-admin.php +++ b/src/class-extended-taxonomy-admin.php @@ -4,7 +4,6 @@ namespace ExtCPTs; use WP_Post; -use Walker; class Taxonomy_Admin { @@ -356,7 +355,7 @@ public function meta_boxes( string $object_type, $object ) { /** * Displays the 'radio' meta box on the post editing screen. * - * Uses the Walker_ExtendedTaxonomyRadios class for the walker. + * Uses the Walker\Radios class for the walker. * * @param WP_Post $post The post object. * @param array $meta_box The meta box arguments. @@ -364,14 +363,14 @@ public function meta_boxes( string $object_type, $object ) { public function meta_box_radio( WP_Post $post, array $meta_box ) { require_once __DIR__ . '/class-walker-extendedtaxonomyradios.php'; - $walker = new Walker_ExtendedTaxonomyRadios(); + $walker = new Walker\Radios(); $this->do_meta_box( $post, $walker, true, 'checklist' ); } /** * Displays the 'dropdown' meta box on the post editing screen. * - * Uses the Walker_ExtendedTaxonomyDropdown class for the walker. + * Uses the Walker\Dropdown class for the walker. * * @param WP_Post $post The post object. * @param array $meta_box The meta box arguments. @@ -379,7 +378,7 @@ public function meta_box_radio( WP_Post $post, array $meta_box ) { public function meta_box_dropdown( WP_Post $post, array $meta_box ) { require_once __DIR__ . '/class-walker-extendedtaxonomydropdown.php'; - $walker = new Walker_ExtendedTaxonomyDropdown(); + $walker = new Walker\Dropdown(); $this->do_meta_box( $post, $walker, true, 'dropdown' ); } @@ -401,7 +400,7 @@ public function meta_box_simple( WP_Post $post, array $meta_box ) { * @param bool $show_none Optional. Whether to include a 'none' item in the term list. Default false. * @param string $type Optional. The taxonomy list type (checklist or dropdown). Default 'checklist'. */ - protected function do_meta_box( WP_Post $post, Walker $walker = null, bool $show_none = false, string $type = 'checklist' ) { + protected function do_meta_box( WP_Post $post, \Walker $walker = null, bool $show_none = false, string $type = 'checklist' ) { $taxonomy = $this->taxo->taxonomy; $tax = get_taxonomy( $taxonomy ); $selected = wp_get_object_terms( $post->ID, $taxonomy, [ @@ -479,7 +478,7 @@ protected function do_meta_box( WP_Post $post, Walker $walker = null, bool $show # Standard WP Walker_Category_Checklist does not cut it if ( ! $walker ) { require_once __DIR__ . '/class-walker-extendedtaxonomycheckboxes.php'; - $walker = new Walker_ExtendedTaxonomyCheckboxes(); + $walker = new Walker\Checkboxes(); } # Output the terms: diff --git a/src/class-walker-extendedtaxonomycheckboxes.php b/src/class-walker-extendedtaxonomycheckboxes.php index 7b46a37..ed70f9c 100644 --- a/src/class-walker-extendedtaxonomycheckboxes.php +++ b/src/class-walker-extendedtaxonomycheckboxes.php @@ -1,16 +1,12 @@ elements properly. - * - * @uses Walker */ -class Walker_ExtendedTaxonomyCheckboxes extends Walker { +class Checkboxes extends \Walker { /** * @var string diff --git a/src/class-walker-extendedtaxonomydropdown.php b/src/class-walker-extendedtaxonomydropdown.php index a1be3ea..2e9f7bb 100644 --- a/src/class-walker-extendedtaxonomydropdown.php +++ b/src/class-walker-extendedtaxonomydropdown.php @@ -1,16 +1,12 @@ Date: Tue, 28 Sep 2021 22:20:45 +0200 Subject: [PATCH 032/157] Reinstate the WordPress version testing during CI. --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c915840..f2f27c7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -61,6 +61,7 @@ jobs: run: | sudo systemctl start mysql.service composer install --prefer-dist + composer require --dev --update-with-dependencies --prefer-dist roots/wordpress="^${{ matrix.wp }}.0" wp-phpunit/wp-phpunit="^${{ matrix.wp }}.0" - name: Run the tests run: composer test From 701f7dccab31061e390b32c125902ccb4667fe52 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Tue, 28 Sep 2021 22:24:38 +0200 Subject: [PATCH 033/157] WordPress 5.8. --- .github/workflows/test.yml | 2 +- README.md | 2 +- composer.json | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f2f27c7..86998d6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: php: ['7.4', '7.0'] - wp: ['5.7'] + wp: ['5.8'] include: - php: '7.2' wp: '4.9' diff --git a/README.md b/README.md index 196d865..6f0bec2 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ Not your first time here? See [Recent Changes for Developers](https://github.com - PHP 7.4+ is recommended - PHP 8 is supported * **WordPress:** 4.8 - - Tested up to WP 5.7 + - Tested up to WP 5.8 ## Installation ## diff --git a/composer.json b/composer.json index faaadcc..dd0000c 100644 --- a/composer.json +++ b/composer.json @@ -25,11 +25,11 @@ "johnbillion/falsey-assertequals-detector": "^2", "phpcompatibility/phpcompatibility-wp": "^2", "phpunit/phpunit": "^6", - "roots/wordpress": "^5.7.0", + "roots/wordpress": "^5.8.0", "vlucas/phpdotenv": "^3", "wp-cli/db-command": "^2.0", "wp-coding-standards/wpcs": "2.3.0", - "wp-phpunit/wp-phpunit": "^5.7.0" + "wp-phpunit/wp-phpunit": "^5.8.0" }, "scripts": { "post-update-cmd": [ From 2768ac03a9ece650c32e36d23cd705aa52348df0 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Tue, 28 Sep 2021 23:17:40 +0200 Subject: [PATCH 034/157] Nope. --- phpcs.xml.dist | 1 + 1 file changed, 1 insertion(+) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index af79822..e175130 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -23,6 +23,7 @@ + From 81484c80394c7a3849967237e7539c1cad8e891e Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Tue, 28 Sep 2021 23:28:10 +0200 Subject: [PATCH 035/157] Ain't nobody got time for this. --- .github/workflows/test.yml | 2 +- README.md | 3 +-- composer.json | 2 +- phpcs.xml.dist | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 562f769..41e5dad 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: build: strategy: matrix: - php: ['7.4', '7.2'] + php: ['7.4'] wp: ['5.7'] include: - php: '7.2' diff --git a/README.md b/README.md index 5d2f5ce..cbd78f0 100644 --- a/README.md +++ b/README.md @@ -59,8 +59,7 @@ Not your first time here? See [Recent Changes for Developers](https://github.com ## Minimum Requirements ## -* **PHP:** 7.2 - - PHP 7.4+ is recommended +* **PHP:** 7.4 - PHP 8 is supported * **WordPress:** 4.8 - Tested up to WP 5.7 diff --git a/composer.json b/composer.json index a8e744d..d4b0c6d 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "wordpress-install-dir": "tests/wordpress" }, "require": { - "php": "^7.2 | ^8" + "php": "^7.4 | ^8" }, "require-dev": { "automattic/phpcs-neutron-standard": "1.6.0", diff --git a/phpcs.xml.dist b/phpcs.xml.dist index e3276c2..33d184f 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -1,7 +1,7 @@ - + */tests/* */vendor/* From e7740c3a337552e1dce84c7699dd099c0b733868 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Tue, 28 Sep 2021 23:41:33 +0200 Subject: [PATCH 036/157] Bump the minimum supported WordPress version. --- .github/workflows/test.yml | 5 +---- README.md | 4 +++- phpcs.xml.dist | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 569099c..c4fac3b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,10 +13,7 @@ jobs: strategy: matrix: php: ['7.4'] - wp: ['5.8'] - include: - - php: '7.2' - wp: '4.9' + wp: ['5.8','5.6'] fail-fast: false name: WP ${{ matrix.wp }} / PHP ${{ matrix.php }} runs-on: ubuntu-18.04 diff --git a/README.md b/README.md index 46b36a4..4a31110 100644 --- a/README.md +++ b/README.md @@ -61,9 +61,11 @@ Not your first time here? See [Recent Changes for Developers](https://github.com * **PHP:** 7.4 - PHP 8 is supported -* **WordPress:** 4.8 +* **WordPress:** 5.6 - Tested up to WP 5.8 +Extended CPTs should work with versions of WordPress back to 4.9 but these versions are not tested and not officially supported. + ## Installation ## Extended CPTs is a developer library, not a plugin, which means you need to include it as a dependency in your project. Install it using Composer: diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 33d184f..6a2b6fe 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -33,7 +33,7 @@ - + From 71dd0e382466070e9e5a378e3b589a8cc2f5d906 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 29 Sep 2021 00:40:13 +0200 Subject: [PATCH 037/157] Don't need this any more. --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 4a31110..d3560e9 100644 --- a/README.md +++ b/README.md @@ -76,8 +76,6 @@ composer require johnbillion/extended-cpts Other means of installation or usage, particularly bundling within a plugin, is not officially supported and done at your own risk. -Note that *Extended Taxonomies* is part of this library since version 4.0, so there's no need to require that too. - ## Usage ## Need a simple post type with no frills? You can register a post type with a single parameter: From 3b413180e02a330cb3396822b64d750ff1dc2317 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 29 Sep 2021 00:58:51 +0200 Subject: [PATCH 038/157] Update Neutron. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index fc64d8b..2f7862b 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "php": "^7.4 | ^8" }, "require-dev": { - "automattic/phpcs-neutron-standard": "1.6.0", + "automattic/phpcs-neutron-standard": "1.7.0", "dealerdirect/phpcodesniffer-composer-installer": "^0.7", "johnbillion/falsey-assertequals-detector": "^2", "phpcompatibility/phpcompatibility-wp": "^2", From 19ae135c075a8a0731219bbe3d7ef9eb00883165 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 29 Sep 2021 01:02:28 +0200 Subject: [PATCH 039/157] Coding standards updates. --- phpcs.xml.dist | 1 - src/class-extended-cpt-admin.php | 249 +++++++++++++++++--------- src/class-extended-cpt.php | 38 ++-- src/class-extended-taxonomy-admin.php | 66 ++++--- src/class-extended-taxonomy.php | 38 ++-- 5 files changed, 250 insertions(+), 142 deletions(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 91a03ec..6a86e4b 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -20,7 +20,6 @@ - diff --git a/src/class-extended-cpt-admin.php b/src/class-extended-cpt-admin.php index 11cf6a9..15bd1a9 100644 --- a/src/class-extended-cpt-admin.php +++ b/src/class-extended-cpt-admin.php @@ -274,9 +274,11 @@ public function filters() { require_once __DIR__ . '/class-walker-extendedtaxonomydropdown.php'; - $walker = new Walker\Dropdown( [ - 'field' => 'slug', - ] ); + $walker = new Walker\Dropdown( + [ + 'field' => 'slug', + ] + ); # If we haven't specified a title, use the all_items label from the taxonomy: if ( ! isset( $filter['title'] ) ) { @@ -290,51 +292,67 @@ public function filters() { ); # Output the dropdown: - wp_dropdown_categories( [ - 'show_option_all' => $filter['title'], - 'hide_empty' => false, - 'hide_if_empty' => true, - 'hierarchical' => true, - 'show_count' => false, - 'orderby' => 'name', - 'selected_cats' => get_query_var( $tax->query_var ), - 'id' => $id, - 'name' => $tax->query_var, - 'taxonomy' => $filter['taxonomy'], - 'walker' => $walker, - ] ); + wp_dropdown_categories( + [ + 'show_option_all' => $filter['title'], + 'hide_empty' => false, + 'hide_if_empty' => true, + 'hierarchical' => true, + 'show_count' => false, + 'orderby' => 'name', + 'selected_cats' => get_query_var( $tax->query_var ), + 'id' => $id, + 'name' => $tax->query_var, + 'taxonomy' => $filter['taxonomy'], + 'walker' => $walker, + ] + ); } elseif ( isset( $filter['meta_key'] ) ) { # If we haven't specified a title, generate one from the meta key: if ( ! isset( $filter['title'] ) ) { - $filter['title'] = str_replace( [ - '-', - '_', - ], ' ', $filter['meta_key'] ); + $filter['title'] = str_replace( + [ + '-', + '_', + ], + ' ', + $filter['meta_key'] + ); $filter['title'] = ucwords( $filter['title'] ) . 's'; $filter['title'] = sprintf( 'All %s', $filter['title'] ); } # If we haven't specified a label, generate one from the meta key: if ( ! isset( $filter['label'] ) ) { - $filter['label'] = str_replace( [ - '-', - '_', - ], ' ', $filter['meta_key'] ); + $filter['label'] = str_replace( + [ + '-', + '_', + ], + ' ', + $filter['meta_key'] + ); $filter['label'] = ucwords( $filter['label'] ); $filter['label'] = sprintf( 'Filter by %s', $filter['label'] ); } if ( ! isset( $filter['options'] ) ) { # Fetch all the values for our meta key: - $filter['options'] = $wpdb->get_col( $wpdb->prepare( " - SELECT DISTINCT meta_value - FROM {$wpdb->postmeta} as m - JOIN {$wpdb->posts} as p ON ( p.ID = m.post_id ) - WHERE m.meta_key = %s - AND m.meta_value != '' - AND p.post_type = %s - ORDER BY m.meta_value ASC - ", $filter['meta_key'], $this->cpt->post_type ) ); + $filter['options'] = $wpdb->get_col( + $wpdb->prepare( + " + SELECT DISTINCT meta_value + FROM {$wpdb->postmeta} as m + JOIN {$wpdb->posts} as p ON ( p.ID = m.post_id ) + WHERE m.meta_key = %s + AND m.meta_value != '' + AND p.post_type = %s + ORDER BY m.meta_value ASC + ", + $filter['meta_key'], + $this->cpt->post_type + ) + ); } elseif ( is_callable( $filter['options'] ) ) { $filter['options'] = call_user_func( $filter['options'] ); } @@ -377,10 +395,14 @@ public function filters() { } elseif ( isset( $filter['meta_search_key'] ) ) { # If we haven't specified a title, generate one from the meta key: if ( ! isset( $filter['title'] ) ) { - $filter['title'] = str_replace( [ - '-', - '_', - ], ' ', $filter['meta_search_key'] ); + $filter['title'] = str_replace( + [ + '-', + '_', + ], + ' ', + $filter['meta_search_key'] + ); $filter['title'] = ucwords( $filter['title'] ); } @@ -459,11 +481,16 @@ public function filters() { if ( ! isset( $filter['options'] ) ) { # Fetch all the values for our field: - $filter['options'] = $wpdb->get_col( $wpdb->prepare( " - SELECT DISTINCT post_author - FROM {$wpdb->posts} - WHERE post_type = %s - ", $this->cpt->post_type ) ); + $filter['options'] = $wpdb->get_col( + $wpdb->prepare( + " + SELECT DISTINCT post_author + FROM {$wpdb->posts} + WHERE post_type = %s + ", + $this->cpt->post_type + ) + ); } elseif ( is_callable( $filter['options'] ) ) { $filter['options'] = call_user_func( $filter['options'] ); } @@ -473,14 +500,16 @@ public function filters() { } # Output a dropdown: - wp_dropdown_users( [ - 'id' => $id, - 'include' => $filter['options'], - 'name' => 'author', - 'option_none_value' => '0', - 'selected' => $value, - 'show_option_none' => $filter['title'], - ] ); + wp_dropdown_users( + [ + 'id' => $id, + 'include' => $filter['options'], + 'name' => 'author', + 'option_none_value' => '0', + 'selected' => $value, + 'show_option_none' => $filter['title'], + ] + ); } } } @@ -589,9 +618,12 @@ public function glance_items( array $items ): array { $num = number_format_i18n( $count->publish ); # This is absolutely not localisable. WordPress 3.8 didn't add a new post type label. - $url = add_query_arg( [ - 'post_type' => $this->cpt->post_type, - ], admin_url( 'edit.php' ) ); + $url = add_query_arg( + [ + 'post_type' => $this->cpt->post_type, + ], + admin_url( 'edit.php' ) + ); $class = 'cpt-' . $this->cpt->post_type . '-count'; $text = '' . esc_html( $num . ' ' . $text ) . ''; $css = <<<'ICONCSS' @@ -1010,10 +1042,13 @@ public function col_taxonomy( string $taxonomy, array $args ) { break; case 'list': - $link = add_query_arg( [ - 'post_type' => $post->post_type, - $taxonomy => $term->slug, - ], admin_url( 'edit.php' ) ); + $link = add_query_arg( + [ + 'post_type' => $post->post_type, + $taxonomy => $term->slug, + ], + admin_url( 'edit.php' ) + ); $out[] = sprintf( '%2$s', esc_url( $link ), @@ -1104,11 +1139,13 @@ public function col_featured_image( string $image_size, array $args ) { } $image_atts = [ - 'style' => esc_attr( sprintf( - 'width:%1$s;height:%2$s', - $width, - $height - ) ), + 'style' => esc_attr( + sprintf( + 'width:%1$s;height:%2$s', + $width, + $height + ) + ), 'title' => '', ]; @@ -1131,11 +1168,13 @@ public function col_connection( string $connection, array $args ) { } if ( ! $this->p2p_connection_exists( $connection ) ) { - echo esc_html( sprintf( - /* translators: %s: The ID of the Posts 2 Posts connection type */ - __( 'Invalid connection type: %s', 'extended-cpts' ), - $connection - ) ); + echo esc_html( + sprintf( + /* translators: %s: The ID of the Posts 2 Posts connection type */ + __( 'Invalid connection type: %s', 'extended-cpts' ), + $connection + ) + ); return; } @@ -1158,11 +1197,13 @@ public function col_connection( string $connection, array $args ) { if ( $type ) { $type->each_connected( [ $_post ], $meta, $field ); } else { - echo esc_html( sprintf( - /* translators: %s: The ID of the Posts 2 Posts connection type */ - __( 'Invalid connection type: %s', 'extended-cpts' ), - $connection - ) ); + echo esc_html( + sprintf( + /* translators: %s: The ID of the Posts 2 Posts connection type */ + __( 'Invalid connection type: %s', 'extended-cpts' ), + $connection + ) + ); return; } } @@ -1217,11 +1258,17 @@ public function col_connection( string $connection, array $args ) { break; case 'list': - $link = add_query_arg( array_merge( [ - 'post_type' => $_post->post_type, - 'connected_type' => $connection, - 'connected_items' => $post->ID, - ], $meta ), admin_url( 'edit.php' ) ); + $link = add_query_arg( + array_merge( + [ + 'post_type' => $_post->post_type, + 'connected_type' => $connection, + 'connected_items' => $post->ID, + ], + $meta + ), + admin_url( 'edit.php' ) + ); $out[] = sprintf( '%2$s', esc_url( $link ), @@ -1314,20 +1361,44 @@ protected function get_item_title( array $item ) { return $item['taxonomy']; } } elseif ( isset( $item['post_field'] ) ) { - return ucwords( trim( str_replace( [ - 'post_', - '_', - ], ' ', $item['post_field'] ) ) ); + return ucwords( + trim( + str_replace( + [ + 'post_', + '_', + ], + ' ', + $item['post_field'] + ) + ) + ); } elseif ( isset( $item['meta_key'] ) ) { - return ucwords( trim( str_replace( [ - '_', - '-', - ], ' ', $item['meta_key'] ) ) ); + return ucwords( + trim( + str_replace( + [ + '_', + '-', + ], + ' ', + $item['meta_key'] + ) + ) + ); } elseif ( isset( $item['connection'] ) && isset( $item['field'] ) && isset( $item['value'] ) ) { - $fallback = ucwords( trim( str_replace( [ - '_', - '-', - ], ' ', $item['value'] ) ) ); + $fallback = ucwords( + trim( + str_replace( + [ + '_', + '-', + ], + ' ', + $item['value'] + ) + ) + ); if ( ! function_exists( 'p2p_type' ) || ! $this->p2p_connection_exists( $item['connection'] ) ) { return $fallback; diff --git a/src/class-extended-cpt.php b/src/class-extended-cpt.php index c4dafe9..b30a89a 100644 --- a/src/class-extended-cpt.php +++ b/src/class-extended-cpt.php @@ -121,10 +121,16 @@ public function __construct( string $post_type, array $args = [], array $names = if ( isset( $names['singular'] ) ) { $this->post_singular = $names['singular']; } else { - $this->post_singular = ucwords( str_replace( [ - '-', - '_', - ], ' ', $post_type ) ); + $this->post_singular = ucwords( + str_replace( + [ + '-', + '_', + ], + ' ', + $post_type + ) + ); } if ( isset( $names['slug'] ) ) { @@ -743,19 +749,27 @@ public function register_post_type() { } $existing = get_post_type_object( $this->post_type ); - $taxonomies = get_taxonomies( [ - 'query_var' => $query_var, - ], 'objects' ); + $taxonomies = get_taxonomies( + [ + 'query_var' => $query_var, + ], + 'objects' + ); if ( $query_var && count( $taxonomies ) ) { // https://core.trac.wordpress.org/ticket/35089 foreach ( $taxonomies as $tax ) { if ( $tax->query_var === $query_var ) { - trigger_error( esc_html( sprintf( - /* translators: %s: Post type query variable name */ - __( 'Post type query var "%s" clashes with a taxonomy query var of the same name', 'extended-cpts' ), - $query_var - ) ), E_USER_ERROR ); + trigger_error( + esc_html( + sprintf( + /* translators: %s: Post type query variable name */ + __( 'Post type query var "%s" clashes with a taxonomy query var of the same name', 'extended-cpts' ), + $query_var + ) + ), + E_USER_ERROR + ); } } } diff --git a/src/class-extended-taxonomy-admin.php b/src/class-extended-taxonomy-admin.php index 6b18080..af13301 100644 --- a/src/class-extended-taxonomy-admin.php +++ b/src/class-extended-taxonomy-admin.php @@ -403,9 +403,13 @@ public function meta_box_simple( WP_Post $post, array $meta_box ) { protected function do_meta_box( WP_Post $post, \Walker $walker = null, bool $show_none = false, string $type = 'checklist' ) { $taxonomy = $this->taxo->taxonomy; $tax = get_taxonomy( $taxonomy ); - $selected = wp_get_object_terms( $post->ID, $taxonomy, [ - 'fields' => 'ids', - ] ); + $selected = wp_get_object_terms( + $post->ID, + $taxonomy, + [ + 'fields' => 'ids', + ] + ); if ( $show_none ) { if ( isset( $tax->labels->no_item ) ) { @@ -441,20 +445,22 @@ protected function do_meta_box( WP_Post $post, \Walker $walker = null, bool $sho esc_attr( "{$taxonomy}dropdown" ), esc_html( $tax->labels->singular_name ) ); - wp_dropdown_categories( [ - 'option_none_value' => ( is_taxonomy_hierarchical( $taxonomy ) ? '-1' : '' ), - 'show_option_none' => $none, - 'hide_empty' => false, - 'hierarchical' => true, - 'show_count' => false, - 'orderby' => 'name', - 'selected' => reset( $selected ), - 'id' => "{$taxonomy}dropdown", - 'name' => is_taxonomy_hierarchical( $taxonomy ) ? "tax_input[{$taxonomy}][]" : "tax_input[{$taxonomy}]", - 'taxonomy' => $taxonomy, - 'walker' => $walker, - 'required' => $this->args['required'], - ] ); + wp_dropdown_categories( + [ + 'option_none_value' => ( is_taxonomy_hierarchical( $taxonomy ) ? '-1' : '' ), + 'show_option_none' => $none, + 'hide_empty' => false, + 'hierarchical' => true, + 'show_count' => false, + 'orderby' => 'name', + 'selected' => reset( $selected ), + 'id' => "{$taxonomy}dropdown", + 'name' => is_taxonomy_hierarchical( $taxonomy ) ? "tax_input[{$taxonomy}][]" : "tax_input[{$taxonomy}]", + 'taxonomy' => $taxonomy, + 'walker' => $walker, + 'required' => $this->args['required'], + ] + ); break; case 'checklist': @@ -482,12 +488,15 @@ protected function do_meta_box( WP_Post $post, \Walker $walker = null, bool $sho } # Output the terms: - wp_terms_checklist( $post->ID, [ - 'taxonomy' => $taxonomy, - 'walker' => $walker, - 'selected_cats' => $selected, - 'checked_ontop' => $this->args['checked_ontop'], - ] ); + wp_terms_checklist( + $post->ID, + [ + 'taxonomy' => $taxonomy, + 'walker' => $walker, + 'selected_cats' => $selected, + 'checked_ontop' => $this->args['checked_ontop'], + ] + ); # Output the 'none' item: if ( $show_none ) { @@ -562,10 +571,13 @@ public function glance_items( array $items ): array { $num = number_format_i18n( $count ); # This is absolutely not localisable. WordPress 3.8 didn't add a new taxonomy label. - $url = add_query_arg( [ - 'taxonomy' => $this->taxo->taxonomy, - 'post_type' => reset( $taxonomy->object_type ), - ], admin_url( 'edit-tags.php' ) ); + $url = add_query_arg( + [ + 'taxonomy' => $this->taxo->taxonomy, + 'post_type' => reset( $taxonomy->object_type ), + ], + admin_url( 'edit-tags.php' ) + ); $text = '' . esc_html( $num . ' ' . $text ) . ''; # Go! diff --git a/src/class-extended-taxonomy.php b/src/class-extended-taxonomy.php index 83bb277..3e91f4b 100644 --- a/src/class-extended-taxonomy.php +++ b/src/class-extended-taxonomy.php @@ -244,22 +244,34 @@ public function register_taxonomy() { $query_var = $this->args['query_var']; } - $post_types = get_post_types( [ - 'query_var' => $query_var, - ] ); + $post_types = get_post_types( + [ + 'query_var' => $query_var, + ] + ); if ( $query_var && count( $post_types ) ) { - trigger_error( esc_html( sprintf( - /* translators: %s: Taxonomy query variable name */ - __( 'Taxonomy query var "%s" clashes with a post type query var of the same name', 'extended-cpts' ), - $query_var - ) ), E_USER_ERROR ); + trigger_error( + esc_html( + sprintf( + /* translators: %s: Taxonomy query variable name */ + __( 'Taxonomy query var "%s" clashes with a post type query var of the same name', 'extended-cpts' ), + $query_var + ) + ), + E_USER_ERROR + ); } elseif ( in_array( $query_var, [ 'type', 'tab' ], true ) ) { - trigger_error( esc_html( sprintf( - /* translators: %s: Taxonomy query variable name */ - __( 'Taxonomy query var "%s" is not allowed', 'extended-cpts' ), - $query_var - ) ), E_USER_ERROR ); + trigger_error( + esc_html( + sprintf( + /* translators: %s: Taxonomy query variable name */ + __( 'Taxonomy query var "%s" is not allowed', 'extended-cpts' ), + $query_var + ) + ), + E_USER_ERROR + ); } else { register_taxonomy( $this->taxonomy, $this->object_type, $this->args ); } From 4b957040f9cbcabf64481a8d57d101f798fa82c9 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 29 Sep 2021 01:05:27 +0200 Subject: [PATCH 040/157] Docs. --- src/class-extended-cpt-admin.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/class-extended-cpt-admin.php b/src/class-extended-cpt-admin.php index 7858a8d..e4e7655 100644 --- a/src/class-extended-cpt-admin.php +++ b/src/class-extended-cpt-admin.php @@ -901,7 +901,8 @@ public function cols( array $cols ): array { /** * Output the column data for our custom columns. * - * @param string $col The column name + * @param string $col The column name + * @param int $post_id The post ID */ public function col( string $col, int $post_id ) { # Shorthand: From 1b3b2d95be3d5ffc14c9d94ecdae1dfd4bb584cf Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 29 Sep 2021 01:06:06 +0200 Subject: [PATCH 041/157] Strictness everywhere. --- tests/phpunit/Admin.php | 1 + tests/phpunit/Admin/Queries.php | 1 + tests/phpunit/Admin/Requests.php | 1 + tests/phpunit/Setup.php | 1 + tests/phpunit/Site.php | 1 + tests/phpunit/Sites/Queries.php | 1 + tests/phpunit/Sites/Requests.php | 1 + tests/phpunit/Test.php | 1 + tests/phpunit/includes/bootstrap.php | 1 + 9 files changed, 9 insertions(+) diff --git a/tests/phpunit/Admin.php b/tests/phpunit/Admin.php index a91018b..c98f341 100644 --- a/tests/phpunit/Admin.php +++ b/tests/phpunit/Admin.php @@ -1,4 +1,5 @@ Date: Wed, 29 Sep 2021 01:21:35 +0200 Subject: [PATCH 042/157] More types. --- src/class-extended-cpt-admin.php | 22 +++++++++++----------- src/class-extended-cpt.php | 10 +++++----- src/class-extended-taxonomy-admin.php | 16 ++++++++-------- src/class-extended-taxonomy.php | 2 +- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/class-extended-cpt-admin.php b/src/class-extended-cpt-admin.php index e4e7655..3d2ae9f 100644 --- a/src/class-extended-cpt-admin.php +++ b/src/class-extended-cpt-admin.php @@ -144,7 +144,7 @@ public function filter_disable_months_dropdown( bool $disable, string $post_type /** * Sets the default sort field and sort order on our post type admin screen. */ - public function default_sort() { + public function default_sort(): void { if ( self::get_current_post_type() !== $this->cpt->post_type ) { return; } @@ -167,7 +167,7 @@ public function default_sort() { /** * Sets the default sort field and sort order on our post type admin screen. */ - public function default_filter() { + public function default_filter(): void { if ( self::get_current_post_type() !== $this->cpt->post_type ) { return; } @@ -531,7 +531,7 @@ public function add_query_vars( array $vars ): array { * * @param WP_Query $wp_query A `WP_Query` object */ - public function maybe_filter( WP_Query $wp_query ) { + public function maybe_filter( WP_Query $wp_query ): void { if ( empty( $wp_query->query['post_type'] ) || ! in_array( $this->cpt->post_type, (array) $wp_query->query['post_type'], true ) ) { return; } @@ -559,7 +559,7 @@ public function maybe_filter( WP_Query $wp_query ) { * * @param WP_Query $wp_query The current `WP_Query` object. */ - public function maybe_sort_by_fields( WP_Query $wp_query ) { + public function maybe_sort_by_fields( WP_Query $wp_query ): void { if ( empty( $wp_query->query['post_type'] ) || ! in_array( $this->cpt->post_type, (array) $wp_query->query['post_type'], true ) ) { return; } @@ -904,7 +904,7 @@ public function cols( array $cols ): array { * @param string $col The column name * @param int $post_id The post ID */ - public function col( string $col, int $post_id ) { + public function col( string $col, int $post_id ): void { # Shorthand: $c = $this->args['admin_cols']; @@ -944,7 +944,7 @@ public function col( string $col, int $post_id ) { * @param string $meta_key The post meta key * @param array $args Array of arguments for this field */ - public function col_post_meta( string $meta_key, array $args ) { + public function col_post_meta( string $meta_key, array $args ): void { $vals = get_post_meta( get_the_ID(), $meta_key, false ); $echo = []; @@ -990,7 +990,7 @@ public function col_post_meta( string $meta_key, array $args ) { * @param string $taxonomy The taxonomy name * @param array $args Array of arguments for this field */ - public function col_taxonomy( string $taxonomy, array $args ) { + public function col_taxonomy( string $taxonomy, array $args ): void { global $post; $terms = get_the_terms( $post, $taxonomy ); @@ -1073,7 +1073,7 @@ public function col_taxonomy( string $taxonomy, array $args ) { * @param string $field The post field * @param array $args Array of arguments for this field */ - public function col_post_field( string $field, array $args ) { + public function col_post_field( string $field, array $args ): void { global $post; switch ( $field ) { @@ -1122,7 +1122,7 @@ public function col_post_field( string $field, array $args ) { * @param string $image_size The image size * @param array $args Array of `width` and `height` attributes for the image */ - public function col_featured_image( string $image_size, array $args ) { + public function col_featured_image( string $image_size, array $args ): void { if ( ! function_exists( 'has_post_thumbnail' ) ) { return; } @@ -1161,7 +1161,7 @@ public function col_featured_image( string $image_size, array $args ) { * @param string $connection The ID of the connection type * @param array $args Array of arguments for a given connection type */ - public function col_connection( string $connection, array $args ) { + public function col_connection( string $connection, array $args ): void { global $post, $wp_query; if ( ! function_exists( 'p2p_type' ) ) { @@ -1349,7 +1349,7 @@ protected static function n( string $single, string $plural, int $number ): stri * @param array $item An array of arguments * @return string|null The item title */ - protected function get_item_title( array $item ) { + protected function get_item_title( array $item ): ?string { if ( isset( $item['taxonomy'] ) ) { $tax = get_taxonomy( $item['taxonomy'] ); if ( $tax ) { diff --git a/src/class-extended-cpt.php b/src/class-extended-cpt.php index b30a89a..977f5bb 100644 --- a/src/class-extended-cpt.php +++ b/src/class-extended-cpt.php @@ -285,7 +285,7 @@ public function __construct( string $post_type, array $args = [], array $names = * * @param WP_Query $wp_query The current WP_Query object. */ - public function maybe_filter( WP_Query $wp_query ) { + public function maybe_filter( WP_Query $wp_query ): void { if ( empty( $wp_query->query['post_type'] ) || ! in_array( $this->post_type, (array) $wp_query->query['post_type'], true ) ) { return; } @@ -313,7 +313,7 @@ public function maybe_filter( WP_Query $wp_query ) { * * @param WP_Query $wp_query The current WP_Query object. */ - public function maybe_sort_by_fields( WP_Query $wp_query ) { + public function maybe_sort_by_fields( WP_Query $wp_query ): void { if ( empty( $wp_query->query['post_type'] ) || ! in_array( $this->post_type, (array) $wp_query->query['post_type'], true ) ) { return; } @@ -628,7 +628,7 @@ public function override_private_query_vars( WP $wp ): WP { * @param string $post_type Post type name. * @param WP_Post_Type $post_type_object Post type object. */ - public function registered_post_type( string $post_type, WP_Post_Type $post_type_object ) { + public function registered_post_type( string $post_type, WP_Post_Type $post_type_object ): void { if ( $post_type !== $this->post_type ) { return; } @@ -741,7 +741,7 @@ public function rewrite_testing_tests( array $tests ): array { * `E_USER_ERROR` level if a `WP_Error` is returned. * */ - public function register_post_type() { + public function register_post_type(): void { if ( ! isset( $this->args['query_var'] ) || ( true === $this->args['query_var'] ) ) { $query_var = $this->post_type; } else { @@ -792,7 +792,7 @@ public function register_post_type() { * * @param WP_Post_Type $pto A post type object. */ - public function extend( WP_Post_Type $pto ) { + public function extend( WP_Post_Type $pto ): void { # Merge core with overridden labels $this->args['labels'] = array_merge( (array) get_post_type_labels( $pto ), $this->args['labels'] ); diff --git a/src/class-extended-taxonomy-admin.php b/src/class-extended-taxonomy-admin.php index af13301..f262fee 100644 --- a/src/class-extended-taxonomy-admin.php +++ b/src/class-extended-taxonomy-admin.php @@ -84,7 +84,7 @@ public function __construct( Taxonomy $taxo, array $args = [] ) { * @param array $cols The default columns for this taxonomy screen * @return array The default columns for this taxonomy screen */ - public function _log_default_cols( array $cols ) { + public function _log_default_cols( array $cols ): array { $this->_cols = $cols; return $this->_cols; } @@ -238,7 +238,7 @@ public function col( string $string, string $col, int $term_id ): string { * @param array $args Array of arguments for this field * @param int $term_id Term ID. */ - public function col_term_meta( string $meta_key, array $args, int $term_id ) { + public function col_term_meta( string $meta_key, array $args, int $term_id ): void { $vals = get_term_meta( $term_id, $meta_key, false ); $echo = []; @@ -291,7 +291,7 @@ protected function get_item_title( array $item ): string { * @param string $object_type The object type (eg. the post type) * @param mixed $object The object (eg. a WP_Post object) */ - public function meta_boxes( string $object_type, $object ) { + public function meta_boxes( string $object_type, $object ): void { if ( ! is_a( $object, 'WP_Post' ) ) { return; } @@ -360,7 +360,7 @@ public function meta_boxes( string $object_type, $object ) { * @param WP_Post $post The post object. * @param array $meta_box The meta box arguments. */ - public function meta_box_radio( WP_Post $post, array $meta_box ) { + public function meta_box_radio( WP_Post $post, array $meta_box ): void { require_once __DIR__ . '/class-walker-extendedtaxonomyradios.php'; $walker = new Walker\Radios(); @@ -375,7 +375,7 @@ public function meta_box_radio( WP_Post $post, array $meta_box ) { * @param WP_Post $post The post object. * @param array $meta_box The meta box arguments. */ - public function meta_box_dropdown( WP_Post $post, array $meta_box ) { + public function meta_box_dropdown( WP_Post $post, array $meta_box ): void { require_once __DIR__ . '/class-walker-extendedtaxonomydropdown.php'; $walker = new Walker\Dropdown(); @@ -388,7 +388,7 @@ public function meta_box_dropdown( WP_Post $post, array $meta_box ) { * @param WP_Post $post The post object. * @param array $meta_box The meta box arguments. */ - public function meta_box_simple( WP_Post $post, array $meta_box ) { + public function meta_box_simple( WP_Post $post, array $meta_box ): void { $this->do_meta_box( $post ); } @@ -400,7 +400,7 @@ public function meta_box_simple( WP_Post $post, array $meta_box ) { * @param bool $show_none Optional. Whether to include a 'none' item in the term list. Default false. * @param string $type Optional. The taxonomy list type (checklist or dropdown). Default 'checklist'. */ - protected function do_meta_box( WP_Post $post, \Walker $walker = null, bool $show_none = false, string $type = 'checklist' ) { + protected function do_meta_box( WP_Post $post, \Walker $walker = null, bool $show_none = false, string $type = 'checklist' ): void { $taxonomy = $this->taxo->taxonomy; $tax = get_taxonomy( $taxonomy ); $selected = wp_get_object_terms( @@ -622,7 +622,7 @@ public function term_updated_messages( array $messages ): array { * @param int $number The number to compare against to use either $single or $plural * @return string Either $single or $plural text */ - public static function n( $single, $plural, $number ) { + public static function n( string $single, string $plural, int $number ): string { return ( 1 === intval( $number ) ) ? $single : $plural; } diff --git a/src/class-extended-taxonomy.php b/src/class-extended-taxonomy.php index 3e91f4b..95a8367 100644 --- a/src/class-extended-taxonomy.php +++ b/src/class-extended-taxonomy.php @@ -237,7 +237,7 @@ public function rewrite_testing_tests( array $tests ): array { /** * Registers our taxonomy. */ - public function register_taxonomy() { + public function register_taxonomy(): void { if ( true === $this->args['query_var'] ) { $query_var = $this->taxonomy; } else { From 91ff9fcfa6856253422ef8579216d7cc28f2e24e Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 29 Sep 2021 01:22:02 +0200 Subject: [PATCH 043/157] Boop. --- functions.php | 2 +- src/class-extended-taxonomy.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/functions.php b/functions.php index ba1491e..b5b9f06 100644 --- a/functions.php +++ b/functions.php @@ -112,7 +112,7 @@ function register_extended_taxonomy( string $taxonomy, $object_type, array $args trigger_error( esc_html__( 'Taxonomies must be registered on the "init" hook.', 'extended-cpts' ), E_USER_WARNING ); } - $taxo = new Taxonomy( $taxonomy, $object_type, $args, $names ); + $taxo = new Taxonomy( $taxonomy, (array) $object_type, $args, $names ); if ( is_admin() ) { new Taxonomy_Admin( $taxo, $taxo->args ); diff --git a/src/class-extended-taxonomy.php b/src/class-extended-taxonomy.php index 95a8367..d6ec303 100644 --- a/src/class-extended-taxonomy.php +++ b/src/class-extended-taxonomy.php @@ -11,7 +11,7 @@ class Taxonomy { * * @var array */ - protected $defaults = [ + protected array $defaults = [ 'public' => true, 'show_ui' => true, 'hierarchical' => true, @@ -66,11 +66,11 @@ class Taxonomy { * @see register_extended_taxonomy() * * @param string $taxonomy The taxonomy name. - * @param array|string $object_type Name(s) of the object type(s) for the taxonomy. + * @param string[] $object_type Names of the object types for the taxonomy. * @param array $args Optional. The taxonomy arguments. * @param string[] $names Optional. An associative array of the plural, singular, and slug names. */ - public function __construct( string $taxonomy, $object_type, array $args = [], array $names = [] ) { + public function __construct( string $taxonomy, array $object_type, array $args = [], array $names = [] ) { /** * Filter the arguments for a taxonomy. * @@ -129,7 +129,7 @@ public function __construct( string $taxonomy, $object_type, array $args = [], a $this->tax_plural = ucwords( str_replace( [ '-', '_' ], ' ', $this->tax_slug ) ); } - $this->object_type = (array) $object_type; + $this->object_type = $object_type; $this->taxonomy = strtolower( $taxonomy ); $this->tax_slug = strtolower( $this->tax_slug ); From 02ca241c3f740e4e66a0b90bf545ff58641106b7 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 29 Sep 2021 01:47:17 +0200 Subject: [PATCH 044/157] Introduce property types. --- src/class-extended-cpt-admin.php | 29 +++---------- src/class-extended-cpt-rewrite-testing.php | 5 +-- src/class-extended-cpt.php | 39 ++++------------- src/class-extended-taxonomy-admin.php | 24 +++-------- ...lass-extended-taxonomy-rewrite-testing.php | 5 +-- src/class-extended-taxonomy.php | 42 ++++--------------- 6 files changed, 29 insertions(+), 115 deletions(-) diff --git a/src/class-extended-cpt-admin.php b/src/class-extended-cpt-admin.php index 3d2ae9f..0fe5627 100644 --- a/src/class-extended-cpt-admin.php +++ b/src/class-extended-cpt-admin.php @@ -13,10 +13,8 @@ class Post_Type_Admin { /** * Default arguments for custom post types. - * - * @var array */ - protected $defaults = [ + protected array $defaults = [ 'quick_edit' => true, # Custom arg 'dashboard_glance' => true, # Custom arg 'dashboard_activity' => false, # Custom arg @@ -26,30 +24,15 @@ class Post_Type_Admin { 'block_editor' => null, # Custom arg ]; - /** - * @var Post_Type - */ - public $cpt; + public Post_Type $cpt; - /** - * @var array - */ - public $args; + public array $args; - /** - * @var array - */ - protected $_cols; + protected array $_cols; - /** - * @var array - */ - protected $the_cols = null; + protected ?array $the_cols = null; - /** - * @var array - */ - protected $connection_exists = []; + protected array $connection_exists = []; /** * Class constructor. diff --git a/src/class-extended-cpt-rewrite-testing.php b/src/class-extended-cpt-rewrite-testing.php index 9a1a47b..89c8ee3 100644 --- a/src/class-extended-cpt-rewrite-testing.php +++ b/src/class-extended-cpt-rewrite-testing.php @@ -8,10 +8,7 @@ */ class Post_Type_Rewrite_Testing extends Extended_Rewrite_Testing { - /** - * @var Post_Type - */ - public $cpt; + public Post_Type $cpt; public function __construct( Post_Type $cpt ) { $this->cpt = $cpt; diff --git a/src/class-extended-cpt.php b/src/class-extended-cpt.php index 977f5bb..b7fe119 100644 --- a/src/class-extended-cpt.php +++ b/src/class-extended-cpt.php @@ -15,10 +15,8 @@ class Post_Type { * Default arguments for custom post types. * * The arguments listed are the ones which differ from the defaults in `register_post_type()`. - * - * @var array */ - protected $defaults = [ + protected array $defaults = [ 'public' => true, 'menu_position' => 6, 'capability_type' => 'page', @@ -35,40 +33,19 @@ class Post_Type { 'featured_image' => null, # Custom arg ]; - /** - * @var string - */ - public $post_type; + public string $post_type; - /** - * @var string - */ - public $post_slug; + public string $post_slug; - /** - * @var string - */ - public $post_singular; + public string $post_singular; - /** - * @var string - */ - public $post_plural; + public string $post_plural; - /** - * @var string - */ - public $post_singular_low; + public string $post_singular_low; - /** - * @var string - */ - public $post_plural_low; + public string $post_plural_low; - /** - * @var array - */ - public $args; + public array $args; /** * Class constructor. diff --git a/src/class-extended-taxonomy-admin.php b/src/class-extended-taxonomy-admin.php index f262fee..60f52e6 100644 --- a/src/class-extended-taxonomy-admin.php +++ b/src/class-extended-taxonomy-admin.php @@ -9,10 +9,8 @@ class Taxonomy_Admin { /** * Default arguments for custom taxonomies. - * - * @var array */ - protected $defaults = [ + protected array $defaults = [ 'meta_box' => null, # Custom arg 'dashboard_glance' => false, # Custom arg 'checked_ontop' => null, # Custom arg @@ -20,25 +18,13 @@ class Taxonomy_Admin { 'required' => false, # Custom arg ]; - /** - * @var Taxonomy - */ - public $taxo; + public Taxonomy $taxo; - /** - * @var array - */ - public $args; + public array $args; - /** - * @var array - */ - protected $_cols; + protected array $_cols; - /** - * @var array - */ - protected $the_cols = null; + protected ?array $the_cols = null; /** * Class constructor. diff --git a/src/class-extended-taxonomy-rewrite-testing.php b/src/class-extended-taxonomy-rewrite-testing.php index cc17dce..9aff260 100644 --- a/src/class-extended-taxonomy-rewrite-testing.php +++ b/src/class-extended-taxonomy-rewrite-testing.php @@ -5,10 +5,7 @@ class Taxonomy_Rewrite_Testing extends Extended_Rewrite_Testing { - /** - * @var Taxonomy - */ - public $taxo; + public Taxonomy $taxo; public function __construct( Taxonomy $taxo ) { $this->taxo = $taxo; diff --git a/src/class-extended-taxonomy.php b/src/class-extended-taxonomy.php index d6ec303..c961fc8 100644 --- a/src/class-extended-taxonomy.php +++ b/src/class-extended-taxonomy.php @@ -8,8 +8,6 @@ class Taxonomy { /** * Default arguments for custom taxonomies. * Several of these differ from the defaults in WordPress' register_taxonomy() function. - * - * @var array */ protected array $defaults = [ 'public' => true, @@ -20,45 +18,21 @@ class Taxonomy { 'allow_hierarchy' => false, # Custom arg ]; - /** - * @var string - */ - public $taxonomy; + public string $taxonomy; - /** - * @var array - */ - public $object_type; + public array $object_type; - /** - * @var string - */ - public $tax_slug; + public string $tax_slug; - /** - * @var string - */ - public $tax_singular; + public string $tax_singular; - /** - * @var string - */ - public $tax_plural; + public string $tax_plural; - /** - * @var string - */ - public $tax_singular_low; + public string $tax_singular_low; - /** - * @var string - */ - public $tax_plural_low; + public string $tax_plural_low; - /** - * @var array - */ - public $args; + public array $args; /** * Class constructor. From e4eb4da80df0cea136e08740c90024a9114cd02b Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 29 Sep 2021 11:39:35 +0200 Subject: [PATCH 045/157] Fix the nightly test. --- .github/workflows/test-nightly.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-nightly.yml b/.github/workflows/test-nightly.yml index 9441f7d..2ee8c73 100644 --- a/.github/workflows/test-nightly.yml +++ b/.github/workflows/test-nightly.yml @@ -9,7 +9,7 @@ jobs: build: strategy: matrix: - php: ['7.4', '7.0'] + php: ['7.4'] fail-fast: false name: WP nightly / PHP ${{ matrix.php }} runs-on: ubuntu-18.04 From 9801031fb7ae7bf892a55e0a4ba670a6055d649a Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 29 Sep 2021 18:05:52 +0200 Subject: [PATCH 046/157] Only need this to scan PHP files. --- phpcs.xml.dist | 1 + 1 file changed, 1 insertion(+) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 6a86e4b..4ba06fb 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -2,6 +2,7 @@ + */tests/* */vendor/* From 20ece49b3cdd9c75ac1496a78fbb8e51f67e561c Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 29 Sep 2021 19:22:28 +0200 Subject: [PATCH 047/157] Update PHPStan dependencies. --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4631b13..009f4d7 100644 --- a/composer.json +++ b/composer.json @@ -24,9 +24,10 @@ "dealerdirect/phpcodesniffer-composer-installer": "^0.7", "johnbillion/falsey-assertequals-detector": "^2", "phpcompatibility/phpcompatibility-wp": "^2", + "phpstan/phpstan": "0.12.99", "phpunit/phpunit": "^6", "roots/wordpress": "^5.8.0", - "szepeviktor/phpstan-wordpress": "^0.6.1", + "szepeviktor/phpstan-wordpress": "^0.7.7", "vlucas/phpdotenv": "^3", "wp-cli/db-command": "^2.0", "wp-coding-standards/wpcs": "2.3.0", From 9dcf7e0e167c7c969301a66e9498cfa2e4d92538 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 29 Sep 2021 19:25:07 +0200 Subject: [PATCH 048/157] Update the PHPStan config. --- phpstan.neon.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index ca9acd0..769d34b 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,5 +1,4 @@ includes: - - phar://phpstan.phar/conf/bleedingEdge.neon - vendor/szepeviktor/phpstan-wordpress/extension.neon parameters: # Please raise level. @@ -16,4 +15,5 @@ parameters: # Uses func_get_args() - '#^Function apply_filters invoked with [34567] parameters, 2 required\.$#' # p2p plugin + - '#^Used function (p2p_type|p2p_connection_exists) not found\.$#' - '#^Function (p2p_type|p2p_connection_exists) not found\.$#' From 342131e699926d2643fb32c8ad19dd6533cdb3a5 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 29 Sep 2021 19:29:07 +0200 Subject: [PATCH 049/157] Some type fixes. --- src/class-extended-taxonomy-admin.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/class-extended-taxonomy-admin.php b/src/class-extended-taxonomy-admin.php index 60f52e6..86fd557 100644 --- a/src/class-extended-taxonomy-admin.php +++ b/src/class-extended-taxonomy-admin.php @@ -382,7 +382,7 @@ public function meta_box_simple( WP_Post $post, array $meta_box ): void { * Displays a meta box on the post editing screen. * * @param WP_Post $post The post object. - * @param Walker $walker Optional. A term walker. + * @param \Walker $walker Optional. A term walker. * @param bool $show_none Optional. Whether to include a 'none' item in the term list. Default false. * @param string $type Optional. The taxonomy list type (checklist or dropdown). Default 'checklist'. */ @@ -553,8 +553,13 @@ public function glance_items( array $items ): array { # Get the labels and format the counts: $count = wp_count_terms( $this->taxo->taxonomy ); - $text = self::n( $taxonomy->labels->singular_name, $taxonomy->labels->name, $count ); - $num = number_format_i18n( $count ); + + if ( is_wp_error( $count ) ) { + return $items; + } + + $text = self::n( $taxonomy->labels->singular_name, $taxonomy->labels->name, (int) $count ); + $num = number_format_i18n( (int) $count ); # This is absolutely not localisable. WordPress 3.8 didn't add a new taxonomy label. $url = add_query_arg( From 43e30e6f241eaf805d15aaaf0f22aecb999cb5f7 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 29 Sep 2021 19:45:20 +0200 Subject: [PATCH 050/157] Next level. --- phpstan.neon.dist | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 769d34b..0677479 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,8 +1,7 @@ includes: - vendor/szepeviktor/phpstan-wordpress/extension.neon parameters: - # Please raise level. - level: 5 + level: 6 inferPrivatePropertyTypeFromConstructor: true paths: - functions.php From b71558f9029ace542d176106ad183aabe25b312f Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 29 Sep 2021 19:46:15 +0200 Subject: [PATCH 051/157] Add a missing return type. --- src/class-extended-cpt-admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/class-extended-cpt-admin.php b/src/class-extended-cpt-admin.php index 0fe5627..5526773 100644 --- a/src/class-extended-cpt-admin.php +++ b/src/class-extended-cpt-admin.php @@ -216,7 +216,7 @@ protected static function get_current_post_type(): string { * * @link https://github.com/johnbillion/extended-cpts/wiki/Admin-filters */ - public function filters() { + public function filters(): void { global $wpdb; if ( self::get_current_post_type() !== $this->cpt->post_type ) { From c48aac1ec06d1a26f6e5f5071bbac673c73aadca Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sat, 2 Oct 2021 22:07:48 +0200 Subject: [PATCH 052/157] Everything is an array. --- functions.php | 4 +- src/class-extended-cpt-admin.php | 58 ++++++++++++------- src/class-extended-cpt-rewrite-testing.php | 3 + src/class-extended-cpt.php | 49 +++++++++------- src/class-extended-rewrite-testing.php | 8 +++ src/class-extended-taxonomy-admin.php | 43 +++++++++----- ...lass-extended-taxonomy-rewrite-testing.php | 3 + src/class-extended-taxonomy.php | 14 ++++- ...lass-walker-extendedtaxonomycheckboxes.php | 16 +++-- src/class-walker-extendedtaxonomydropdown.php | 7 ++- src/class-walker-extendedtaxonomyradios.php | 16 +++-- 11 files changed, 141 insertions(+), 80 deletions(-) diff --git a/functions.php b/functions.php index b5b9f06..ab0b9b3 100644 --- a/functions.php +++ b/functions.php @@ -17,7 +17,7 @@ * @see register_post_type() for default arguments. * * @param string $post_type The post type name. - * @param array $args { + * @param mixed[] $args { * Optional. The post type arguments. * * @type array $admin_cols Associative array of admin screen columns to show for this post type. @@ -73,7 +73,7 @@ function register_extended_post_type( string $post_type, array $args = [], array * * @param string $taxonomy The taxonomy name. * @param string|string[] $object_type Name(s) of the object type(s) for the taxonomy. - * @param array $args { + * @param mixed[] $args { * Optional. The taxonomy arguments. * * @type string $meta_box The name of the custom meta box to use on the post editing screen for this diff --git a/src/class-extended-cpt-admin.php b/src/class-extended-cpt-admin.php index 5526773..8275d61 100644 --- a/src/class-extended-cpt-admin.php +++ b/src/class-extended-cpt-admin.php @@ -13,6 +13,8 @@ class Post_Type_Admin { /** * Default arguments for custom post types. + * + * @var array */ protected array $defaults = [ 'quick_edit' => true, # Custom arg @@ -26,19 +28,31 @@ class Post_Type_Admin { public Post_Type $cpt; + /** + * @var array + */ public array $args; + /** + * @var array + */ protected array $_cols; + /** + * @var array + */ protected ?array $the_cols = null; + /** + * @var array + */ protected array $connection_exists = []; /** * Class constructor. * * @param Post_Type $cpt An extended post type object. - * @param array $args Optional. The post type arguments. + * @param mixed[] $args Optional. The post type arguments. */ public function __construct( Post_Type $cpt, array $args = [] ) { $this->cpt = $cpt; @@ -500,8 +514,8 @@ public function filters(): void { /** * Adds our filter names to the public query vars. * - * @param array $vars Public query variables - * @return array Updated public query variables + * @param array $vars Public query variables + * @return array Updated public query variables */ public function add_query_vars( array $vars ): array { $filters = array_keys( $this->args['admin_filters'] ); @@ -561,9 +575,9 @@ public function maybe_sort_by_fields( WP_Query $wp_query ): void { /** * Filters the query's SQL clauses so we can sort posts by taxonomy terms. * - * @param array $clauses The current query's SQL clauses. + * @param array $clauses The current query's SQL clauses. * @param WP_Query $wp_query The current `WP_Query` object. - * @return array The updated SQL clauses. + * @return array The updated SQL clauses. */ public function maybe_sort_by_taxonomy( array $clauses, WP_Query $wp_query ): array { if ( empty( $wp_query->query['post_type'] ) || ! in_array( $this->cpt->post_type, (array) $wp_query->query['post_type'], true ) ) { @@ -582,8 +596,8 @@ public function maybe_sort_by_taxonomy( array $clauses, WP_Query $wp_query ): ar /** * Adds our post type to the 'At a Glance' widget on the dashboard. * - * @param array $items Array of items to display on the widget. - * @return array Updated array of items. + * @param array $items Array of items to display on the widget. + * @return array Updated array of items. */ public function glance_items( array $items ): array { $pto = get_post_type_object( $this->cpt->post_type ); @@ -642,8 +656,8 @@ public function glance_items( array $items ): array { /** * Adds our post type to the 'Recently Published' section on the dashboard. * - * @param array $query_args Array of query args for the widget. - * @return array Updated array of query args. + * @param array $query_args Array of query args for the widget. + * @return array Updated array of query args. */ public function dashboard_activity( array $query_args ): array { $query_args['post_type'] = (array) $query_args['post_type']; @@ -742,7 +756,7 @@ public function post_updated_messages( array $messages ): array { * * @param array[] $messages An array of bulk post updated message arrays keyed by post type. * @param int[] $counts An array of counts for each key in `$messages`. - * @return array Updated array of bulk post updated messages. + * @return array[] Updated array of bulk post updated messages. */ public function bulk_post_updated_messages( array $messages, array $counts ): array { $messages[ $this->cpt->post_type ] = [ @@ -784,8 +798,8 @@ public function bulk_post_updated_messages( array $messages, array $counts ): ar /** * Adds our custom columns to the list of sortable columns. * - * @param array $cols Array of sortable columns keyed by the column ID. - * @return array Updated array of sortable columns. + * @param array $cols Array of sortable columns keyed by the column ID. + * @return array Updated array of sortable columns. */ public function sortables( array $cols ): array { foreach ( $this->args['admin_cols'] as $id => $col ) { @@ -808,8 +822,8 @@ public function sortables( array $cols ): array { * * @link https://github.com/johnbillion/extended-cpts/wiki/Admin-columns * - * @param array $cols Associative array of columns - * @return array Updated array of columns + * @param array $cols Associative array of columns + * @return array Updated array of columns */ public function cols( array $cols ): array { // This function gets called multiple times, so let's cache it for efficiency: @@ -925,7 +939,7 @@ public function col( string $col, int $post_id ): void { * Outputs column data for a post meta field. * * @param string $meta_key The post meta key - * @param array $args Array of arguments for this field + * @param array $args Array of arguments for this field */ public function col_post_meta( string $meta_key, array $args ): void { $vals = get_post_meta( get_the_ID(), $meta_key, false ); @@ -971,7 +985,7 @@ public function col_post_meta( string $meta_key, array $args ): void { * Outputs column data for a taxonomy's term names. * * @param string $taxonomy The taxonomy name - * @param array $args Array of arguments for this field + * @param array $args Array of arguments for this field */ public function col_taxonomy( string $taxonomy, array $args ): void { global $post; @@ -1054,7 +1068,7 @@ public function col_taxonomy( string $taxonomy, array $args ): void { * Outputs column data for a post field. * * @param string $field The post field - * @param array $args Array of arguments for this field + * @param array $args Array of arguments for this field */ public function col_post_field( string $field, array $args ): void { global $post; @@ -1103,7 +1117,7 @@ public function col_post_field( string $field, array $args ): void { * Outputs column data for a post's featured image. * * @param string $image_size The image size - * @param array $args Array of `width` and `height` attributes for the image + * @param array $args Array of `width` and `height` attributes for the image */ public function col_featured_image( string $image_size, array $args ): void { if ( ! function_exists( 'has_post_thumbnail' ) ) { @@ -1142,7 +1156,7 @@ public function col_featured_image( string $image_size, array $args ): void { * Outputs column data for a Posts 2 Posts connection. * * @param string $connection The ID of the connection type - * @param array $args Array of arguments for a given connection type + * @param array $args Array of arguments for a given connection type */ public function col_connection( string $connection, array $args ): void { global $post, $wp_query; @@ -1305,8 +1319,8 @@ public function remove_quick_edit_menu( array $actions ): array { /** * Logs the default columns so we don't remove any custom columns added by other plugins. * - * @param array $cols The default columns for this post type screen - * @return array The default columns for this post type screen + * @param array $cols The default columns for this post type screen + * @return array The default columns for this post type screen */ public function _log_default_cols( array $cols ): array { $this->_cols = $cols; @@ -1329,7 +1343,7 @@ protected static function n( string $single, string $plural, int $number ): stri /** * Returns a sensible title for the current item (usually the arguments array for a column) * - * @param array $item An array of arguments + * @param array $item An array of arguments * @return string|null The item title */ protected function get_item_title( array $item ): ?string { diff --git a/src/class-extended-cpt-rewrite-testing.php b/src/class-extended-cpt-rewrite-testing.php index 89c8ee3..d890ca8 100644 --- a/src/class-extended-cpt-rewrite-testing.php +++ b/src/class-extended-cpt-rewrite-testing.php @@ -14,6 +14,9 @@ public function __construct( Post_Type $cpt ) { $this->cpt = $cpt; } + /** + * @return array> + */ public function get_tests(): array { global $wp_rewrite; diff --git a/src/class-extended-cpt.php b/src/class-extended-cpt.php index b7fe119..96dd050 100644 --- a/src/class-extended-cpt.php +++ b/src/class-extended-cpt.php @@ -15,6 +15,8 @@ class Post_Type { * Default arguments for custom post types. * * The arguments listed are the ones which differ from the defaults in `register_post_type()`. + * + * @var array */ protected array $defaults = [ 'public' => true, @@ -45,6 +47,9 @@ class Post_Type { public string $post_plural_low; + /** + * @var array + */ public array $args; /** @@ -52,9 +57,9 @@ class Post_Type { * * @see register_extended_post_type() * - * @param string $post_type The post type name. - * @param array $args Optional. The post type arguments. - * @param string[] $names Optional. The plural, singular, and slug names. + * @param string $post_type The post type name. + * @param array $args Optional. The post type arguments. + * @param array $names Optional. The plural, singular, and slug names. */ public function __construct( string $post_type, array $args = [], array $names = [] ) { /** @@ -344,11 +349,11 @@ public function maybe_sort_by_taxonomy( array $clauses, WP_Query $wp_query ): ar * Get the array of private query vars for the given filters, to apply to the current query in order to filter it by the * given public query vars. * - * @param array $query The public query vars, usually from `$wp_query->query`. - * @param array $filters The filters valid for this query (usually the value of the `admin_filters` or - * `site_filters` argument when registering an extended post type). - * @param string $post_type The post type name. - * @return array The list of private query vars to apply to the query. + * @param array $query The public query vars, usually from `$wp_query->query`. + * @param array $filters The filters valid for this query (usually the value of the `admin_filters` or + * `site_filters` argument when registering an extended post type). + * @param string $post_type The post type name. + * @return array The list of private query vars to apply to the query. */ public static function get_filter_vars( array $query, array $filters, string $post_type ): array { $return = []; @@ -436,10 +441,10 @@ public static function get_filter_vars( array $query, array $filters, string $po * Get the array of private and public query vars for the given sortables, to apply to the current query in order to * sort it by the requested orderby field. * - * @param array $vars The public query vars, usually from `$wp_query->query`. - * @param array $sortables The sortables valid for this query (usually the value of the `admin_cols` or - * `site_sortables` argument when registering an extended post type. - * @return array The list of private and public query vars to apply to the query. + * @param array $vars The public query vars, usually from `$wp_query->query`. + * @param array $sortables The sortables valid for this query (usually the value of the `admin_cols` or + * `site_sortables` argument when registering an extended post type. + * @return array The list of private and public query vars to apply to the query. */ public static function get_sort_field_vars( array $vars, array $sortables ): array { if ( ! isset( $vars['orderby'] ) ) { @@ -486,11 +491,11 @@ public static function get_sort_field_vars( array $vars, array $sortables ): arr * Get the array of SQL clauses for the given sortables, to apply to the current query in order to * sort it by the requested orderby field. * - * @param array $clauses The query's SQL clauses. - * @param array $vars The public query vars, usually from `$wp_query->query`. - * @param array $sortables The sortables valid for this query (usually the value of the `admin_cols` or + * @param array $clauses The query's SQL clauses. + * @param array $vars The public query vars, usually from `$wp_query->query`. + * @param array $sortables The sortables valid for this query (usually the value of the `admin_cols` or * `site_sortables` argument when registering an extended post type). - * @return array The list of SQL clauses to apply to the query. + * @return array The list of SQL clauses to apply to the query. */ public static function get_sort_taxonomy_clauses( array $clauses, array $vars, array $sortables ): array { global $wpdb; @@ -553,8 +558,8 @@ public function add_query_vars( array $vars ): array { /** * Add our post type to the feed. * - * @param array $vars Request parameters. - * @return array Updated request parameters. + * @param array $vars Request parameters. + * @return array Updated request parameters. */ public function add_to_feed( array $vars ): array { # If it's not a feed, we're not interested: @@ -699,8 +704,8 @@ public function post_type_link( string $post_link, WP_Post $post, bool $leavenam * * @codeCoverageIgnore * - * @param array $tests The existing rewrite rule tests. - * @return array Updated rewrite rule tests. + * @param array> $tests The existing rewrite rule tests. + * @return array> Updated rewrite rule tests. */ public function rewrite_testing_tests( array $tests ): array { require_once __DIR__ . '/class-extended-rewrite-testing.php'; @@ -787,8 +792,8 @@ public function extend( WP_Post_Type $pto ): void { * $location = $events->add_taxonomy( 'location' ); * * @param string $taxonomy The taxonomy name. - * @param array $args Optional. The taxonomy arguments. - * @param array $names Optional. An associative array of the plural, singular, and slug names. + * @param array $args Optional. The taxonomy arguments. + * @param array $names Optional. An associative array of the plural, singular, and slug names. * @return WP_Taxonomy Taxonomy object. */ public function add_taxonomy( string $taxonomy, array $args = [], array $names = [] ): WP_Taxonomy { diff --git a/src/class-extended-rewrite-testing.php b/src/class-extended-rewrite-testing.php index 6d31a56..4e5b78f 100644 --- a/src/class-extended-rewrite-testing.php +++ b/src/class-extended-rewrite-testing.php @@ -8,8 +8,16 @@ */ abstract class Extended_Rewrite_Testing { + /** + * @return array> + */ abstract public function get_tests(): array; + /** + * @param mixed[] $struct + * @param mixed[] $additional + * @return array + */ public function get_rewrites( array $struct, array $additional ): array { global $wp_rewrite; diff --git a/src/class-extended-taxonomy-admin.php b/src/class-extended-taxonomy-admin.php index 86fd557..516981e 100644 --- a/src/class-extended-taxonomy-admin.php +++ b/src/class-extended-taxonomy-admin.php @@ -9,6 +9,8 @@ class Taxonomy_Admin { /** * Default arguments for custom taxonomies. + * + * @var array */ protected array $defaults = [ 'meta_box' => null, # Custom arg @@ -20,17 +22,26 @@ class Taxonomy_Admin { public Taxonomy $taxo; + /** + * @var array + */ public array $args; + /** + * @var array + */ protected array $_cols; + /** + * @var array + */ protected ?array $the_cols = null; /** * Class constructor. * - * @param Taxonomy $taxo An extended taxonomy object. - * @param array $args Optional. The admin arguments. + * @param Taxonomy $taxo An extended taxonomy object. + * @param array $args Optional. The admin arguments. */ public function __construct( Taxonomy $taxo, array $args = [] ) { $this->taxo = $taxo; @@ -67,8 +78,8 @@ public function __construct( Taxonomy $taxo, array $args = [] ) { /** * Logs the default columns so we don't remove any custom columns added by other plugins. * - * @param array $cols The default columns for this taxonomy screen - * @return array The default columns for this taxonomy screen + * @param array $cols The default columns for this taxonomy screen + * @return array The default columns for this taxonomy screen */ public function _log_default_cols( array $cols ): array { $this->_cols = $cols; @@ -126,8 +137,8 @@ public function _log_default_cols( array $cols ): array { * * Note that sortable admin columns are not yet supported. * - * @param array $cols Associative array of columns - * @return array Updated array of columns + * @param array $cols Associative array of columns + * @return array Updated array of columns */ public function cols( array $cols ): array { // This function gets called multiple times, so let's cache it for efficiency: @@ -220,9 +231,9 @@ public function col( string $string, string $col, int $term_id ): string { /** * Output column data for a term meta field. * - * @param string $meta_key The term meta key - * @param array $args Array of arguments for this field - * @param int $term_id Term ID. + * @param string $meta_key The term meta key + * @param array $args Array of arguments for this field + * @param int $term_id Term ID. */ public function col_term_meta( string $meta_key, array $args, int $term_id ): void { $vals = get_term_meta( $term_id, $meta_key, false ); @@ -260,7 +271,7 @@ public function col_term_meta( string $meta_key, array $args, int $term_id ): vo /** * Returns a sensible title for the current item (usually the arguments array for a column) * - * @param array $item An array of arguments + * @param array $item An array of arguments * @return string The item title */ protected function get_item_title( array $item ): string { @@ -343,8 +354,8 @@ public function meta_boxes( string $object_type, $object ): void { * * Uses the Walker\Radios class for the walker. * - * @param WP_Post $post The post object. - * @param array $meta_box The meta box arguments. + * @param WP_Post $post The post object. + * @param array $meta_box The meta box arguments. */ public function meta_box_radio( WP_Post $post, array $meta_box ): void { require_once __DIR__ . '/class-walker-extendedtaxonomyradios.php'; @@ -358,8 +369,8 @@ public function meta_box_radio( WP_Post $post, array $meta_box ): void { * * Uses the Walker\Dropdown class for the walker. * - * @param WP_Post $post The post object. - * @param array $meta_box The meta box arguments. + * @param WP_Post $post The post object. + * @param array $meta_box The meta box arguments. */ public function meta_box_dropdown( WP_Post $post, array $meta_box ): void { require_once __DIR__ . '/class-walker-extendedtaxonomydropdown.php'; @@ -371,8 +382,8 @@ public function meta_box_dropdown( WP_Post $post, array $meta_box ): void { /** * Displays the 'simple' meta box on the post editing screen. * - * @param WP_Post $post The post object. - * @param array $meta_box The meta box arguments. + * @param WP_Post $post The post object. + * @param array $meta_box The meta box arguments. */ public function meta_box_simple( WP_Post $post, array $meta_box ): void { $this->do_meta_box( $post ); diff --git a/src/class-extended-taxonomy-rewrite-testing.php b/src/class-extended-taxonomy-rewrite-testing.php index 9aff260..e97ec4b 100644 --- a/src/class-extended-taxonomy-rewrite-testing.php +++ b/src/class-extended-taxonomy-rewrite-testing.php @@ -11,6 +11,9 @@ public function __construct( Taxonomy $taxo ) { $this->taxo = $taxo; } + /** + * @return array> + */ public function get_tests(): array { global $wp_rewrite; diff --git a/src/class-extended-taxonomy.php b/src/class-extended-taxonomy.php index c961fc8..14ebc4f 100644 --- a/src/class-extended-taxonomy.php +++ b/src/class-extended-taxonomy.php @@ -8,6 +8,8 @@ class Taxonomy { /** * Default arguments for custom taxonomies. * Several of these differ from the defaults in WordPress' register_taxonomy() function. + * + * @var array */ protected array $defaults = [ 'public' => true, @@ -20,6 +22,9 @@ class Taxonomy { public string $taxonomy; + /** + * @var array + */ public array $object_type; public string $tax_slug; @@ -32,6 +37,9 @@ class Taxonomy { public string $tax_plural_low; + /** + * @var array + */ public array $args; /** @@ -41,7 +49,7 @@ class Taxonomy { * * @param string $taxonomy The taxonomy name. * @param string[] $object_type Names of the object types for the taxonomy. - * @param array $args Optional. The taxonomy arguments. + * @param array $args Optional. The taxonomy arguments. * @param string[] $names Optional. An associative array of the plural, singular, and slug names. */ public function __construct( string $taxonomy, array $object_type, array $args = [], array $names = [] ) { @@ -196,8 +204,8 @@ public function __construct( string $taxonomy, array $object_type, array $args = * * @codeCoverageIgnore * - * @param array $tests The existing rewrite rule tests. - * @return array Updated rewrite rule tests. + * @param array> $tests The existing rewrite rule tests. + * @return array> Updated rewrite rule tests. */ public function rewrite_testing_tests( array $tests ): array { require_once __DIR__ . '/class-extended-rewrite-testing.php'; diff --git a/src/class-walker-extendedtaxonomycheckboxes.php b/src/class-walker-extendedtaxonomycheckboxes.php index ed70f9c..3b4e582 100644 --- a/src/class-walker-extendedtaxonomycheckboxes.php +++ b/src/class-walker-extendedtaxonomycheckboxes.php @@ -14,7 +14,7 @@ class Checkboxes extends \Walker { public $tree_type = 'category'; /** - * @var array + * @var array */ public $db_fields = [ 'parent' => 'parent', @@ -29,7 +29,7 @@ class Checkboxes extends \Walker { /** * Class constructor. * - * @param array $args Optional arguments. + * @param array $args Optional arguments. */ public function __construct( $args = null ) { if ( $args && isset( $args['field'] ) ) { @@ -42,7 +42,8 @@ public function __construct( $args = null ) { * * @param string $output Passed by reference. Used to append additional content. * @param int $depth Depth of term in reference to parents. - * @param array $args Optional arguments. + * @param array $args Optional arguments. + * @return void */ public function start_lvl( &$output, $depth = 0, $args = [] ) { $indent = str_repeat( "\t", $depth ); @@ -54,7 +55,8 @@ public function start_lvl( &$output, $depth = 0, $args = [] ) { * * @param string $output Passed by reference. Used to append additional content. * @param int $depth Depth of term in reference to parents. - * @param array $args Optional arguments. + * @param array $args Optional arguments. + * @return void */ public function end_lvl( &$output, $depth = 0, $args = [] ) { $indent = str_repeat( "\t", $depth ); @@ -67,8 +69,9 @@ public function end_lvl( &$output, $depth = 0, $args = [] ) { * @param string $output Passed by reference. Used to append additional content. * @param object $object Term data object. * @param int $depth Depth of term in reference to parents. - * @param array $args Optional arguments. + * @param array $args Optional arguments. * @param int $current_object_id Current object ID. + * @return void */ public function start_el( &$output, $object, $depth = 0, $args = [], $current_object_id = 0 ) { $tax = get_taxonomy( $args['taxonomy'] ); @@ -100,7 +103,8 @@ public function start_el( &$output, $object, $depth = 0, $args = [], $current_ob * @param string $output Passed by reference. Used to append additional content. * @param object $object Term data object. * @param int $depth Depth of term in reference to parents. - * @param array $args Optional arguments. + * @param array $args Optional arguments. + * @return void */ public function end_el( &$output, $object, $depth = 0, $args = [] ) { $output .= "\n"; diff --git a/src/class-walker-extendedtaxonomydropdown.php b/src/class-walker-extendedtaxonomydropdown.php index 2e9f7bb..c1d6e20 100644 --- a/src/class-walker-extendedtaxonomydropdown.php +++ b/src/class-walker-extendedtaxonomydropdown.php @@ -14,7 +14,7 @@ class Dropdown extends \Walker { public $tree_type = 'category'; /** - * @var array + * @var array */ public $db_fields = [ 'parent' => 'parent', @@ -29,7 +29,7 @@ class Dropdown extends \Walker { /** * Class constructor. * - * @param array $args Optional arguments. + * @param array $args Optional arguments. */ public function __construct( $args = null ) { if ( $args && isset( $args['field'] ) ) { @@ -43,8 +43,9 @@ public function __construct( $args = null ) { * @param string $output Passed by reference. Used to append additional content. * @param object $object Term data object. * @param int $depth Depth of term in reference to parents. - * @param array $args Optional arguments. + * @param array $args Optional arguments. * @param int $current_object_id Current object ID. + * @return void */ public function start_el( &$output, $object, $depth = 0, $args = [], $current_object_id = 0 ) { $pad = str_repeat( ' ', $depth * 3 ); diff --git a/src/class-walker-extendedtaxonomyradios.php b/src/class-walker-extendedtaxonomyradios.php index afcec9c..4e30bd7 100644 --- a/src/class-walker-extendedtaxonomyradios.php +++ b/src/class-walker-extendedtaxonomyradios.php @@ -14,7 +14,7 @@ class Radios extends \Walker { public $tree_type = 'category'; /** - * @var array + * @var array */ public $db_fields = [ 'parent' => 'parent', @@ -29,7 +29,7 @@ class Radios extends \Walker { /** * Class constructor. * - * @param array $args Optional arguments. + * @param array $args Optional arguments. */ public function __construct( $args = null ) { if ( $args && isset( $args['field'] ) ) { @@ -42,7 +42,8 @@ public function __construct( $args = null ) { * * @param string $output Passed by reference. Used to append additional content. * @param int $depth Depth of term in reference to parents. - * @param array $args Optional arguments. + * @param array $args Optional arguments. + * @return void */ public function start_lvl( &$output, $depth = 0, $args = [] ) { $indent = str_repeat( "\t", $depth ); @@ -54,7 +55,8 @@ public function start_lvl( &$output, $depth = 0, $args = [] ) { * * @param string $output Passed by reference. Used to append additional content. * @param int $depth Depth of term in reference to parents. - * @param array $args Optional arguments. + * @param array $args Optional arguments. + * @return void */ public function end_lvl( &$output, $depth = 0, $args = [] ) { $indent = str_repeat( "\t", $depth ); @@ -67,8 +69,9 @@ public function end_lvl( &$output, $depth = 0, $args = [] ) { * @param string $output Passed by reference. Used to append additional content. * @param object $object Term data object. * @param int $depth Depth of term in reference to parents. - * @param array $args Optional arguments. + * @param array $args Optional arguments. * @param int $current_object_id Current object ID. + * @return void */ public function start_el( &$output, $object, $depth = 0, $args = [], $current_object_id = 0 ) { $tax = get_taxonomy( $args['taxonomy'] ); @@ -100,7 +103,8 @@ public function start_el( &$output, $object, $depth = 0, $args = [], $current_ob * @param string $output Passed by reference. Used to append additional content. * @param object $object Term data object. * @param int $depth Depth of term in reference to parents. - * @param array $args Optional arguments. + * @param array $args Optional arguments. + * @return void */ public function end_el( &$output, $object, $depth = 0, $args = [] ) { $output .= "\n"; From 455d74197bcd90fa09be9ebf0eb1a9c91a451f08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Sat, 2 Oct 2021 22:28:49 +0200 Subject: [PATCH 053/157] Remove redundant PHPStan config PHPStan scans all files in `paths:` --- phpstan.neon.dist | 4 ---- 1 file changed, 4 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 0677479..c34817f 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -6,10 +6,6 @@ parameters: paths: - functions.php - src/ - scanFiles: - - functions.php - scanDirectories: - - src/ ignoreErrors: # Uses func_get_args() - '#^Function apply_filters invoked with [34567] parameters, 2 required\.$#' From 0e7fc68b92bd6b74759b89d9cda3bfa0d053dd3a Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sun, 3 Oct 2021 00:04:05 +0200 Subject: [PATCH 054/157] More type fixes. --- phpcs.xml.dist | 1 + src/class-extended-cpt-admin.php | 25 +++++++++++++++---- src/class-extended-cpt.php | 6 ++++- src/class-extended-taxonomy-admin.php | 3 +++ ...lass-extended-taxonomy-rewrite-testing.php | 1 + ...lass-walker-extendedtaxonomycheckboxes.php | 10 ++++++-- src/class-walker-extendedtaxonomydropdown.php | 8 +++++- src/class-walker-extendedtaxonomyradios.php | 10 ++++++-- 8 files changed, 53 insertions(+), 11 deletions(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 4ba06fb..daa53b9 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -24,6 +24,7 @@ + diff --git a/src/class-extended-cpt-admin.php b/src/class-extended-cpt-admin.php index 8275d61..eab0239 100644 --- a/src/class-extended-cpt-admin.php +++ b/src/class-extended-cpt-admin.php @@ -297,7 +297,7 @@ public function filters(): void { 'hierarchical' => true, 'show_count' => false, 'orderby' => 'name', - 'selected_cats' => get_query_var( $tax->query_var ), + 'selected_cats' => $tax->query_var ? get_query_var( $tax->query_var ) : [], 'id' => $id, 'name' => $tax->query_var, 'taxonomy' => $filter['taxonomy'], @@ -514,10 +514,11 @@ public function filters(): void { /** * Adds our filter names to the public query vars. * - * @param array $vars Public query variables - * @return array Updated public query variables + * @param array $vars Public query variables + * @return array Updated public query variables */ public function add_query_vars( array $vars ): array { + /** @var array */ $filters = array_keys( $this->args['admin_filters'] ); return array_merge( $vars, $filters ); @@ -610,6 +611,7 @@ public function glance_items( array $items ): array { } # Get the labels and format the counts: + /** @var \stdClass */ $count = wp_count_posts( $this->cpt->post_type ); $text = self::n( $pto->labels->singular_name, $pto->labels->name, (int) $count->publish ); $num = number_format_i18n( $count->publish ); @@ -635,7 +637,8 @@ public function glance_items( array $items ): array { // https://core.trac.wordpress.org/ticket/33714 // https://github.com/WordPress/dashicons/blob/master/codepoints.json if ( is_string( $pto->menu_icon ) && 0 === strpos( $pto->menu_icon, 'dashicons-' ) ) { - $codepoints = json_decode( file_get_contents( __DIR__ . '/dashicons-codepoints.json' ), true ); + $contents = file_get_contents( __DIR__ . '/dashicons-codepoints.json' ); + $codepoints = json_decode( $contents ?: '', true ); $unprefixed = str_replace( 'dashicons-', '', $pto->menu_icon ); if ( isset( $codepoints[ $unprefixed ] ) ) { @@ -802,7 +805,10 @@ public function bulk_post_updated_messages( array $messages, array $counts ): ar * @return array Updated array of sortable columns. */ public function sortables( array $cols ): array { - foreach ( $this->args['admin_cols'] as $id => $col ) { + $admin_cols = $this->args['admin_cols']; + + /** @var array $admin_cols */ + foreach ( $admin_cols as $id => $col ) { if ( ! is_array( $col ) ) { continue; } @@ -998,6 +1004,10 @@ public function col_taxonomy( string $taxonomy, array $args ): void { return; } + if ( ! $tax ) { + return; + } + if ( empty( $terms ) ) { printf( '%s', @@ -1073,6 +1083,10 @@ public function col_taxonomy( string $taxonomy, array $args ): void { public function col_post_field( string $field, array $args ): void { global $post; + if ( ! $post ) { + return; + } + switch ( $field ) { case 'post_date': @@ -1211,6 +1225,7 @@ public function col_connection( string $connection, array $args ): void { setup_postdata( $post ); $pto = get_post_type_object( $post->post_type ); + /** @var \stdClass */ $pso = get_post_status_object( $post->post_status ); if ( $pso->protected && ! current_user_can( 'edit_post', $post->ID ) ) { diff --git a/src/class-extended-cpt.php b/src/class-extended-cpt.php index 96dd050..04834e6 100644 --- a/src/class-extended-cpt.php +++ b/src/class-extended-cpt.php @@ -651,6 +651,7 @@ public function post_type_link( string $post_link, WP_Post $post, bool $leavenam $replacements['%author%'] = get_userdata( (int) $post->post_author )->user_nicename; } + /** @var string $tax */ foreach ( get_object_taxonomies( $post ) as $tax ) { if ( false === strpos( $post_link, "%{$tax}%" ) ) { continue; @@ -803,7 +804,10 @@ public function add_taxonomy( string $taxonomy, array $args = [], array $names = register_extended_taxonomy( $taxonomy, $this->post_type, $args, $names ); } - return get_taxonomy( $taxonomy ); + /** @var WP_Taxonomy */ + $tax = get_taxonomy( $taxonomy ); + + return $tax; } } diff --git a/src/class-extended-taxonomy-admin.php b/src/class-extended-taxonomy-admin.php index 516981e..e8dcd37 100644 --- a/src/class-extended-taxonomy-admin.php +++ b/src/class-extended-taxonomy-admin.php @@ -298,6 +298,7 @@ public function meta_boxes( string $object_type, $object ): void { $taxos = get_post_taxonomies( $post ); if ( in_array( $this->taxo->taxonomy, $taxos, true ) ) { + /** @var WP_Taxonomy */ $tax = get_taxonomy( $this->taxo->taxonomy ); # Remove default meta box from classic editor: @@ -399,6 +400,7 @@ public function meta_box_simple( WP_Post $post, array $meta_box ): void { */ protected function do_meta_box( WP_Post $post, \Walker $walker = null, bool $show_none = false, string $type = 'checklist' ): void { $taxonomy = $this->taxo->taxonomy; + /** @var WP_Taxonomy */ $tax = get_taxonomy( $taxonomy ); $selected = wp_get_object_terms( $post->ID, @@ -553,6 +555,7 @@ protected function do_meta_box( WP_Post $post, \Walker $walker = null, bool $sho * @return string[] Updated array of items. */ public function glance_items( array $items ): array { + /** @var WP_Taxonomy */ $taxonomy = get_taxonomy( $this->taxo->taxonomy ); if ( ! current_user_can( $taxonomy->cap->manage_terms ) ) { diff --git a/src/class-extended-taxonomy-rewrite-testing.php b/src/class-extended-taxonomy-rewrite-testing.php index e97ec4b..47521e7 100644 --- a/src/class-extended-taxonomy-rewrite-testing.php +++ b/src/class-extended-taxonomy-rewrite-testing.php @@ -26,6 +26,7 @@ public function get_tests(): array { } $struct = $wp_rewrite->extra_permastructs[ $this->taxo->taxonomy ]; + /** @var WP_Taxonomy */ $tax = get_taxonomy( $this->taxo->taxonomy ); $name = sprintf( '%s (%s)', $tax->labels->name, $this->taxo->taxonomy ); diff --git a/src/class-walker-extendedtaxonomycheckboxes.php b/src/class-walker-extendedtaxonomycheckboxes.php index 3b4e582..e1776b9 100644 --- a/src/class-walker-extendedtaxonomycheckboxes.php +++ b/src/class-walker-extendedtaxonomycheckboxes.php @@ -3,6 +3,8 @@ namespace ExtCPTs\Walker; +use WP_Term; + /** * Walker to output an unordered list of category checkbox elements properly. */ @@ -67,7 +69,7 @@ public function end_lvl( &$output, $depth = 0, $args = [] ) { * Start the element output. * * @param string $output Passed by reference. Used to append additional content. - * @param object $object Term data object. + * @param WP_Term $object Term data object. * @param int $depth Depth of term in reference to parents. * @param array $args Optional arguments. * @param int $current_object_id Current object ID. @@ -76,6 +78,10 @@ public function end_lvl( &$output, $depth = 0, $args = [] ) { public function start_el( &$output, $object, $depth = 0, $args = [], $current_object_id = 0 ) { $tax = get_taxonomy( $args['taxonomy'] ); + if ( ! $tax ) { + return; + } + if ( $this->field ) { $value = $object->{$this->field}; } else { @@ -101,7 +107,7 @@ public function start_el( &$output, $object, $depth = 0, $args = [], $current_ob * Ends the element output, if needed. * * @param string $output Passed by reference. Used to append additional content. - * @param object $object Term data object. + * @param WP_Term $object Term data object. * @param int $depth Depth of term in reference to parents. * @param array $args Optional arguments. * @return void diff --git a/src/class-walker-extendedtaxonomydropdown.php b/src/class-walker-extendedtaxonomydropdown.php index c1d6e20..1b0e0fd 100644 --- a/src/class-walker-extendedtaxonomydropdown.php +++ b/src/class-walker-extendedtaxonomydropdown.php @@ -3,6 +3,8 @@ namespace ExtCPTs\Walker; +use WP_Term; + /** * A term walker class for a dropdown menu. */ @@ -41,7 +43,7 @@ public function __construct( $args = null ) { * Start the element output. * * @param string $output Passed by reference. Used to append additional content. - * @param object $object Term data object. + * @param WP_Term $object Term data object. * @param int $depth Depth of term in reference to parents. * @param array $args Optional arguments. * @param int $current_object_id Current object ID. @@ -51,6 +53,10 @@ public function start_el( &$output, $object, $depth = 0, $args = [], $current_ob $pad = str_repeat( ' ', $depth * 3 ); $tax = get_taxonomy( $args['taxonomy'] ); + if ( ! $tax ) { + return; + } + if ( $this->field ) { $value = $object->{$this->field}; } else { diff --git a/src/class-walker-extendedtaxonomyradios.php b/src/class-walker-extendedtaxonomyradios.php index 4e30bd7..25b494d 100644 --- a/src/class-walker-extendedtaxonomyradios.php +++ b/src/class-walker-extendedtaxonomyradios.php @@ -3,6 +3,8 @@ namespace ExtCPTs\Walker; +use WP_Term; + /** * A term walker class for radio buttons. */ @@ -67,7 +69,7 @@ public function end_lvl( &$output, $depth = 0, $args = [] ) { * Start the element output. * * @param string $output Passed by reference. Used to append additional content. - * @param object $object Term data object. + * @param WP_Term $object Term data object. * @param int $depth Depth of term in reference to parents. * @param array $args Optional arguments. * @param int $current_object_id Current object ID. @@ -76,6 +78,10 @@ public function end_lvl( &$output, $depth = 0, $args = [] ) { public function start_el( &$output, $object, $depth = 0, $args = [], $current_object_id = 0 ) { $tax = get_taxonomy( $args['taxonomy'] ); + if ( ! $tax ) { + return; + } + if ( $this->field ) { $value = $object->{$this->field}; } else { @@ -101,7 +107,7 @@ public function start_el( &$output, $object, $depth = 0, $args = [], $current_ob * Ends the element output, if needed. * * @param string $output Passed by reference. Used to append additional content. - * @param object $object Term data object. + * @param WP_Term $object Term data object. * @param int $depth Depth of term in reference to parents. * @param array $args Optional arguments. * @return void From 457597fc7a1f82076f28c2efefb35f67170f7e01 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sun, 3 Oct 2021 00:05:38 +0200 Subject: [PATCH 055/157] Need to use these. --- src/class-extended-taxonomy-admin.php | 1 + src/class-extended-taxonomy-rewrite-testing.php | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/class-extended-taxonomy-admin.php b/src/class-extended-taxonomy-admin.php index e8dcd37..4480895 100644 --- a/src/class-extended-taxonomy-admin.php +++ b/src/class-extended-taxonomy-admin.php @@ -4,6 +4,7 @@ namespace ExtCPTs; use WP_Post; +use WP_Taxonomy; class Taxonomy_Admin { diff --git a/src/class-extended-taxonomy-rewrite-testing.php b/src/class-extended-taxonomy-rewrite-testing.php index 47521e7..2efaa8f 100644 --- a/src/class-extended-taxonomy-rewrite-testing.php +++ b/src/class-extended-taxonomy-rewrite-testing.php @@ -3,6 +3,8 @@ namespace ExtCPTs; +use WP_Taxonomy; + class Taxonomy_Rewrite_Testing extends Extended_Rewrite_Testing { public Taxonomy $taxo; From 5908f874e8c806c940a247df6781f52e32d657a1 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sun, 3 Oct 2021 00:07:35 +0200 Subject: [PATCH 056/157] Cast this to a string to avoid complaints. --- src/class-walker-extendedtaxonomyradios.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/class-walker-extendedtaxonomyradios.php b/src/class-walker-extendedtaxonomyradios.php index 25b494d..3bf940a 100644 --- a/src/class-walker-extendedtaxonomyradios.php +++ b/src/class-walker-extendedtaxonomyradios.php @@ -95,7 +95,7 @@ public function start_el( &$output, $object, $depth = 0, $args = [], $current_ob $output .= "\n
  • term_id}'>" . '