From 6cf3ba80c57440a1713061bd57baca7b51480b42 Mon Sep 17 00:00:00 2001 From: jeremyfelt Date: Mon, 18 Nov 2024 12:29:35 -0800 Subject: [PATCH 1/5] Abstract the HTML output of a content type field a bit --- src/Admin.php | 133 ++++++++++++++++---------------------------------- 1 file changed, 41 insertions(+), 92 deletions(-) diff --git a/src/Admin.php b/src/Admin.php index b00c058..e41bb76 100644 --- a/src/Admin.php +++ b/src/Admin.php @@ -108,6 +108,29 @@ public static function get_id( $post_type, $name ): string { return 'organizational_names_' . $post_type . '_' . $name; } + /** + * Render a settings field for a content type's singular and plural names. + * + * @param string $post_type Post type. + * @param string $label Label. + * @param string $value Value. + * @param string $type Type. + */ + public static function render_content_type_field( string $post_type, string $label, string $value, string $type ): void { + ?> +
+ + +
+

Changing the settings here will override the default labels for the content types provided by the Organizational plugin. The default labels are listed to the left of each field. The singular label will also be used as a slug in URLs.

- projects ) ) : ?> -
- - -
- -
- - -
- - - people ) ) : ?> -
- - -
- -
- - -
- - - entities ) ) : ?> -
- - -
+ projects ) ) { + self::render_content_type_field( $organizational->projects->post_type, 'Project (Singular)', $display_names[ $organizational->projects->post_type ]['singular'], 'singular' ); + self::render_content_type_field( $organizational->projects->post_type, 'Projects (Plural)', $display_names[ $organizational->projects->post_type ]['plural'], 'plural' ); + } -
- - -
- + if ( isset( $organizational->people ) ) { + self::render_content_type_field( $organizational->people->post_type, 'Person (Singular)', $display_names[ $organizational->people->post_type ]['singular'], 'singular' ); + self::render_content_type_field( $organizational->people->post_type, 'People (Plural)', $display_names[ $organizational->people->post_type ]['plural'], 'plural' ); + } - publications ) ) : ?> -
- - -
+ if ( isset( $organizational->entities ) ) { + self::render_content_type_field( $organizational->entities->post_type, 'Entity (Singular)', $display_names[ $organizational->entities->post_type ]['singular'], 'singular' ); + self::render_content_type_field( $organizational->entities->post_type, 'Entities (Plural)', $display_names[ $organizational->entities->post_type ]['plural'], 'plural' ); + } -
- - -
- + if ( isset( $organizational->publications ) ) { + self::render_content_type_field( $organizational->publications->post_type, 'Publication (Singular)', $display_names[ $organizational->publications->post_type ]['singular'], 'singular' ); + self::render_content_type_field( $organizational->publications->post_type, 'Publications (Plural)', $display_names[ $organizational->publications->post_type ]['plural'], 'plural' ); + } + ?> Date: Tue, 19 Nov 2024 14:00:27 -0800 Subject: [PATCH 2/5] Add optional taxonomies to each content type This changeset does way too many things at once, but here we are. * Move the settings screen for Organizational out of General and into its own view under Settings -> Organizational. * Add a toggle to enable a taxonomy for each supported content type that can be used to group content of that type. * Abstract a few more things to improve how the admin screen and other bits are managed. --- src/Admin.php | 303 +++++++++++++++++++++++++---------------- src/ContentType.php | 97 ++++++++++++- src/Entities.php | 31 +++++ src/Init.php | 16 +-- src/Organizational.php | 14 ++ src/People.php | 31 +++++ src/Projects.php | 31 +++++ src/Publications.php | 31 +++++ 8 files changed, 423 insertions(+), 131 deletions(-) diff --git a/src/Admin.php b/src/Admin.php index e41bb76..111b9cb 100644 --- a/src/Admin.php +++ b/src/Admin.php @@ -16,29 +16,112 @@ class Admin { * Initialize customizations in the WordPress admin. */ public static function init(): void { + add_action( 'admin_menu', array( __CLASS__, 'add_settings_page' ) ); add_action( 'admin_init', array( __CLASS__, 'register_settings' ) ); } + /** + * Add the settings page to the WordPress admin menu. + */ + public static function add_settings_page(): void { + add_options_page( + 'Organizational Settings', + 'Organizational', + 'manage_options', + 'organizational-settings', + array( __CLASS__, 'render_settings_page' ) + ); + } + /** * Register plugin settings fields. */ public static function register_settings(): void { + global $organizational; + register_setting( - 'general', + 'organizational_settings', 'organizational_names', array( __CLASS__, 'sanitize_names' ) ); - add_settings_field( - 'organizational-names', - 'Organizational Names', - array( __CLASS__, 'general_settings_names' ), - 'general', - 'default', - array( - 'label_for' => 'organizational_names', - ) + add_settings_section( + 'organizational_names_section', + 'Content Type Names', + array( __CLASS__, 'render_names_section' ), + 'organizational-settings' ); + + $content_types = $organizational->get_content_types(); + + foreach ( $content_types as $content_type ) { + add_settings_field( + 'organizational-names-' . $content_type->post_type, + $content_type->default_name, + array( __CLASS__, 'general_settings_names' ), + 'organizational-settings', + 'organizational_names_section', + array( + 'content_type' => $content_type, + ) + ); + } + } + + /** + * Render the settings page. + */ + public static function render_settings_page(): void { + ?> +
+

Organizational Settings

+
+ +
+
+ +

Changing the settings here will override the default labels for the content types + provided by the Organizational plugin. The default labels are listed to the left + of each field. The singular label will also be used as a slug + in URLs.

+ + get_content_types(); $supported_post_types = array(); - if ( isset( $organizational->projects ) ) { - $supported_post_types[] = $organizational->projects->post_type; - } - - if ( isset( $organizational->people ) ) { - $supported_post_types[] = $organizational->people->post_type; - } - - if ( isset( $organizational->entities ) ) { - $supported_post_types[] = $organizational->entities->post_type; - } - - if ( isset( $organizational->publications ) ) { - $supported_post_types[] = $organizational->publications->post_type; + foreach ( $content_types as $content_type ) { + $supported_post_types[] = $content_type->post_type; } $clean_names = array(); @@ -75,8 +147,14 @@ public static function sanitize_names( $names ): array { continue; } - $clean_names[ $name ]['singular'] = sanitize_text_field( $data['singular'] ); - $clean_names[ $name ]['plural'] = sanitize_text_field( $data['plural'] ); + $clean_names[ $name ]['singular'] = sanitize_text_field( $data['singular'] ); + $clean_names[ $name ]['plural'] = sanitize_text_field( $data['plural'] ); + $clean_names[ $name ]['taxonomy_singular'] = sanitize_text_field( $data['taxonomy_singular'] ); + $clean_names[ $name ]['taxonomy_plural'] = sanitize_text_field( $data['taxonomy_plural'] ); + + if ( isset( $data['taxonomy-toggle'] ) ) { + $clean_names[ $name ]['taxonomy_toggle'] = 1; + } } wp_schedule_single_event( time() + 1, 'organizational_flush_rewrite_rules' ); @@ -87,8 +165,8 @@ public static function sanitize_names( $names ): array { /** * Get the name attribute for a settings field. * - * @param string $post_type Post type. - * @param string $name Field name. + * @param string $post_type The content type's post type. + * @param string $name The field's name. * * @return string Name attribute. */ @@ -99,8 +177,8 @@ public static function get_name( $post_type, $name ): string { /** * Get the ID attribute for a settings field. * - * @param string $post_type Post type. - * @param string $name Field name. + * @param string $post_type The content type's post type. + * @param string $name The field's name. * * @return string ID attribute. */ @@ -111,10 +189,10 @@ public static function get_id( $post_type, $name ): string { /** * Render a settings field for a content type's singular and plural names. * - * @param string $post_type Post type. - * @param string $label Label. - * @param string $value Value. - * @param string $type Type. + * @param string $post_type The content type's post type. + * @param string $label The field's label. + * @param string $value The field's current value. + * @param string $type Whether the field is for the content type's singular or plural name. */ public static function render_content_type_field( string $post_type, string $label, string $value, string $type ): void { ?> @@ -132,99 +210,96 @@ class="regular-text" } /** - * Output the settings fields for the Organizational plugin. + * Render a settings field to toggle whether an additional taxonomy is + * registered for a content type. + * + * @param string $post_type The content type's post type. + * @param string $label The label text for the toggle. + * @param int $value Whether the toggle is checked. */ - public static function general_settings_names(): void { - global $organizational; + public static function render_taxonomy_toggle( string $post_type, string $label, int $value ): void { + ?> + + /> + + +
+ + +
+ projects ) && ! isset( $names[ $organizational->projects->post_type ] ) ) { - $names[ $organizational->projects->post_type ] = array(); - } - - if ( isset( $organizational->people ) && ! isset( $names[ $organizational->people->post_type ] ) ) { - $names[ $organizational->people->post_type ] = array(); - } - - if ( isset( $organizational->entities ) && ! isset( $names[ $organizational->entities->post_type ] ) ) { - $names[ $organizational->entities->post_type ] = array(); - } - - if ( isset( $organizational->publications ) && ! isset( $names[ $organizational->publications->post_type ] ) ) { - $names[ $organizational->publications->post_type ] = array(); - } - - if ( isset( $organizational->projects ) ) { - $display_names[ $organizational->projects->post_type ] = wp_parse_args( - $names[ $organizational->projects->post_type ], - array( - 'singular' => $organizational->projects->singular_name, - 'plural' => $organizational->projects->plural_name, - ) - ); + if ( ! isset( $names[ $content_type->post_type ] ) ) { + $names[ $content_type->post_type ] = array(); } - if ( isset( $organizational->people ) ) { - $display_names[ $organizational->people->post_type ] = wp_parse_args( - $names[ $organizational->people->post_type ], - array( - 'singular' => $organizational->people->singular_name, - 'plural' => $organizational->people->plural_name, - ) - ); - } + $display_names[ $content_type->post_type ] = wp_parse_args( + $names[ $content_type->post_type ], + array( + 'singular' => $content_type->singular_name, + 'plural' => $content_type->plural_name, + 'taxonomy_singular' => $content_type->taxonomy_singular_name, + 'taxonomy_plural' => $content_type->taxonomy_plural_name, + ) + ); - if ( isset( $organizational->entities ) ) { - $display_names[ $organizational->entities->post_type ] = wp_parse_args( - $names[ $organizational->entities->post_type ], - array( - 'singular' => $organizational->entities->singular_name, - 'plural' => $organizational->entities->plural_name, - ) - ); - } + $taxonomy_toggle = isset( $display_names[ $content_type->post_type ]['taxonomy_toggle'] ) ? (int) $display_names[ $content_type->post_type ]['taxonomy_toggle'] : 0; - if ( isset( $organizational->publications ) ) { - $display_names[ $organizational->publications->post_type ] = wp_parse_args( - $names[ $organizational->publications->post_type ], - array( - 'singular' => $organizational->publications->singular_name, - 'plural' => $organizational->publications->plural_name, - ) - ); - } ?>
-

Changing the settings here will override the default labels for the content types provided by the Organizational plugin. The default labels are listed to the left of each field. The singular label will also be used as a slug in URLs.

- - projects ) ) { - self::render_content_type_field( $organizational->projects->post_type, 'Project (Singular)', $display_names[ $organizational->projects->post_type ]['singular'], 'singular' ); - self::render_content_type_field( $organizational->projects->post_type, 'Projects (Plural)', $display_names[ $organizational->projects->post_type ]['plural'], 'plural' ); - } - - if ( isset( $organizational->people ) ) { - self::render_content_type_field( $organizational->people->post_type, 'Person (Singular)', $display_names[ $organizational->people->post_type ]['singular'], 'singular' ); - self::render_content_type_field( $organizational->people->post_type, 'People (Plural)', $display_names[ $organizational->people->post_type ]['plural'], 'plural' ); - } - - if ( isset( $organizational->entities ) ) { - self::render_content_type_field( $organizational->entities->post_type, 'Entity (Singular)', $display_names[ $organizational->entities->post_type ]['singular'], 'singular' ); - self::render_content_type_field( $organizational->entities->post_type, 'Entities (Plural)', $display_names[ $organizational->entities->post_type ]['plural'], 'plural' ); - } - - if ( isset( $organizational->publications ) ) { - self::render_content_type_field( $organizational->publications->post_type, 'Publication (Singular)', $display_names[ $organizational->publications->post_type ]['singular'], 'singular' ); - self::render_content_type_field( $organizational->publications->post_type, 'Publications (Plural)', $display_names[ $organizational->publications->post_type ]['plural'], 'plural' ); - } - ?> +
+ post_type, 'Singular', $display_names[ $content_type->post_type ]['singular'], 'singular' ); + self::render_content_type_field( $content_type->post_type, 'Plural', $display_names[ $content_type->post_type ]['plural'], 'plural' ); + self::render_taxonomy_toggle( $content_type->post_type, 'Enable additional taxonomy for ' . $content_type->default_name, $taxonomy_toggle ); + ?> +
+ post_type, 'Singular', $display_names[ $content_type->post_type ]['taxonomy_singular'], 'taxonomy_singular' ); + self::render_taxonomy_field( $content_type->post_type, 'Plural', $display_names[ $content_type->post_type ]['taxonomy_plural'], 'taxonomy_plural' ); + ?> +
+
post_type, $this->get_args() ); $this->register_meta(); + + if ( $this->taxonomy_active ) { + $this->register_taxonomy(); + } } /** @@ -98,6 +130,15 @@ public function register_meta(): void { } } + /** + * Register the additional taxonomy for the content type. + * + * @return void + */ + public function register_taxonomy(): void { + register_taxonomy( $this->taxonomy, $this->post_type, $this->get_taxonomy_args() ); + } + /** * Retrieve the labels for the post type. * @@ -168,6 +209,41 @@ public function get_args(): array { return $args; } + /** + * Retrieve the arguments for taxonomy registration. + * + * @return array + */ + public function get_taxonomy_args(): array { + $args = array( + 'label' => $this->taxonomy_plural_name, + 'labels' => array( + 'name' => $this->taxonomy_plural_name, + 'singular_name' => $this->taxonomy_singular_name, + ), + 'public' => true, + 'publicly_queryable' => true, + 'hierarchical' => true, + 'show_ui' => true, + 'show_in_menu' => true, + 'show_in_nav_menus' => true, + 'query_var' => true, + 'rewrite' => array( + 'slug' => sanitize_title( strtolower( $this->taxonomy_singular_name ) ), + 'with_front' => true, + ), + 'show_admin_column' => true, + 'show_in_rest' => true, + 'rest_base' => sanitize_title( strtolower( $this->taxonomy_plural_name ) ), + 'rest_controller_class' => 'WP_REST_Terms_Controller', + 'show_in_quick_edit' => true, + ); + + $args = apply_filters( "organizational_{$this->post_type}_taxonomy_args", $args ); + + return $args; + } + /** * Retrieve object type names from a previously saved names option. * @@ -184,11 +260,26 @@ private function get_object_type_names(): array { $this->plural_name = $names[ $this->post_type ]['plural'] ? $names[ $this->post_type ]['plural'] : $this->plural_name; } + if ( false !== $names && isset( $names[ $this->post_type ] ) && isset( $names[ $this->post_type ]['taxonomy_singular'] ) ) { + $this->taxonomy_singular_name = $names[ $this->post_type ]['taxonomy_singular'] ? $names[ $this->post_type ]['taxonomy_singular'] : $this->taxonomy_singular_name; + } + + if ( false !== $names && isset( $names[ $this->post_type ] ) && isset( $names[ $this->post_type ]['taxonomy_plural'] ) ) { + $this->taxonomy_plural_name = $names[ $this->post_type ]['taxonomy_plural'] ? $names[ $this->post_type ]['taxonomy_plural'] : $this->taxonomy_plural_name; + } + + if ( false !== $names && isset( $names[ $this->post_type ] ) && isset( $names[ $this->post_type ]['taxonomy_toggle'] ) ) { + $this->taxonomy_active = $names[ $this->post_type ]['taxonomy_toggle'] ? true : false; + } + return apply_filters( "organizational_{$this->post_type}_type_names", array( - 'singular' => $this->singular_name, - 'plural' => $this->plural_name, + 'singular' => $this->singular_name, + 'plural' => $this->plural_name, + 'taxonomy_active' => $this->taxonomy_active, + 'taxonomy_singular' => $this->taxonomy_singular_name, + 'taxonomy_plural' => $this->taxonomy_plural_name, ) ); } diff --git a/src/Entities.php b/src/Entities.php index 893150a..bc8cd7c 100644 --- a/src/Entities.php +++ b/src/Entities.php @@ -18,6 +18,16 @@ class Entities extends ContentType { */ public string $post_type = 'og_entity'; + /** + * The default name. + * + * Used to refer to the content type in the admin settings even after the + * name has been overridden. + * + * @var string + */ + public string $default_name = 'Entities'; + /** * The singular name. * @@ -38,4 +48,25 @@ class Entities extends ContentType { * @var string */ public string $menu_icon = 'dashicons-groups'; + + /** + * The slug for an additional taxonomy associated with the content type. + * + * @var string + */ + public string $taxonomy = 'og_entity_group'; + + /** + * The plural name of an additional taxonomy for the content type. + * + * @var string + */ + public string $taxonomy_plural_name = 'Entity Groups'; + + /** + * The singular name of an additional taxonomy for the content type. + * + * @var string + */ + public string $taxonomy_singular_name = 'Entity Group'; } diff --git a/src/Init.php b/src/Init.php index f35cef3..b626b9a 100644 --- a/src/Init.php +++ b/src/Init.php @@ -117,20 +117,8 @@ public static function enqueue_block_editor_assets(): void { return; } - if ( current_theme_supports( 'organizational_person' ) ) { - $organizational->people->enqueue_block_editor_assets(); - } - - if ( current_theme_supports( 'organizational_project' ) ) { - $organizational->projects->enqueue_block_editor_assets(); - } - - if ( current_theme_supports( 'organizational_entity' ) ) { - $organizational->entities->enqueue_block_editor_assets(); - } - - if ( current_theme_supports( 'organizational_publication' ) ) { - $organizational->publications->enqueue_block_editor_assets(); + foreach ( $organizational->get_content_types() as $content_type ) { + $content_type->enqueue_block_editor_assets(); } } } diff --git a/src/Organizational.php b/src/Organizational.php index 882cdb0..07612e9 100644 --- a/src/Organizational.php +++ b/src/Organizational.php @@ -44,6 +44,20 @@ class Organizational { */ public function __construct() {} + /** + * Retrieve supported content types for the site. + * + * @return ContentType[] + */ + public function get_content_types(): array { + return array_filter( + get_object_vars( $this ), + function ( $property ) { + return $property instanceof ContentType; + } + ); + } + /** * Enable Shadow Terms to supported post types. * diff --git a/src/People.php b/src/People.php index f89bc8e..b5f989c 100644 --- a/src/People.php +++ b/src/People.php @@ -18,6 +18,16 @@ class People extends ContentType { */ public string $post_type = 'og_person'; + /** + * The default name. + * + * Used to refer to the content type in the admin settings even after the + * name has been overridden. + * + * @var string + */ + public string $default_name = 'People'; + /** * The singular name. * @@ -39,6 +49,27 @@ class People extends ContentType { */ public string $menu_icon = 'dashicons-id-alt'; + /** + * The slug for an additional taxonomy associated with the content type. + * + * @var string + */ + public string $taxonomy = 'og_person_group'; + + /** + * The plural name of an additional taxonomy for the content type. + * + * @var string + */ + public string $taxonomy_plural_name = 'People Groups'; + + /** + * The singular name of an additional taxonomy for the content type. + * + * @var string + */ + public string $taxonomy_singular_name = 'People Group'; + /** * Meta keys automatically registered for the post type. * diff --git a/src/Projects.php b/src/Projects.php index 02d9b7c..6573bb6 100644 --- a/src/Projects.php +++ b/src/Projects.php @@ -18,6 +18,16 @@ class Projects extends ContentType { */ public string $post_type = 'og_project'; + /** + * The default name. + * + * Used to refer to the content type in the admin settings even after the + * name has been overridden. + * + * @var string + */ + public string $default_name = 'Projects'; + /** * The singular name. * @@ -38,4 +48,25 @@ class Projects extends ContentType { * @var string */ public string $menu_icon = 'dashicons-analytics'; + + /** + * The slug for an additional taxonomy associated with the content type. + * + * @var string + */ + public string $taxonomy = 'og_project_group'; + + /** + * The plural name of an additional taxonomy for the content type. + * + * @var string + */ + public string $taxonomy_plural_name = 'Project Groups'; + + /** + * The singular name of an additional taxonomy for the content type. + * + * @var string + */ + public string $taxonomy_singular_name = 'Project Group'; } diff --git a/src/Publications.php b/src/Publications.php index 5ee98d9..81abd84 100644 --- a/src/Publications.php +++ b/src/Publications.php @@ -18,6 +18,16 @@ class Publications extends ContentType { */ public string $post_type = 'og_publication'; + /** + * The default name. + * + * Used to refer to the content type in the admin settings even after the + * name has been overridden. + * + * @var string + */ + public string $default_name = 'Publications'; + /** * The singular name. * @@ -39,6 +49,27 @@ class Publications extends ContentType { */ public string $menu_icon = 'dashicons-book'; + /** + * The slug for an additional taxonomy associated with the content type. + * + * @var string + */ + public string $taxonomy = 'og_publication_group'; + + /** + * The plural name of an additional taxonomy for the content type. + * + * @var string + */ + public string $taxonomy_plural_name = 'Publication Groups'; + + /** + * The singular name of an additional taxonomy for the content type. + * + * @var string + */ + public string $taxonomy_singular_name = 'Publication Group'; + /** * Meta keys automatically registered for the post type. * From fe9a06d85a43c55d1f378f4e1887242dbea0486d Mon Sep 17 00:00:00 2001 From: jeremyfelt Date: Tue, 19 Nov 2024 14:08:06 -0800 Subject: [PATCH 3/5] Namespace constants --- plugin.php | 5 ++--- src/Init.php | 2 +- src/People.php | 4 ++-- src/Publications.php | 4 ++-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/plugin.php b/plugin.php index 8d463a9..b76c898 100644 --- a/plugin.php +++ b/plugin.php @@ -19,9 +19,8 @@ die; } -define( 'ORGANIZATIONAL_VERSION', '2.2.0' ); -define( 'ORGANIZATIONAL_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); -define( 'ORGANIZATIONAL_PLUGIN_FILE', __FILE__ ); +const VERSION = '2.2.0'; +const PLUGIN_FILE = __FILE__; require_once __DIR__ . '/vendor/autoload.php'; diff --git a/src/Init.php b/src/Init.php index b626b9a..5503e9b 100644 --- a/src/Init.php +++ b/src/Init.php @@ -55,7 +55,7 @@ public static function process_upgrade_routine(): void { flush_rewrite_rules(); } - update_option( 'organizational_version', ORGANIZATIONAL_VERSION ); + update_option( 'organizational_version', VERSION ); } /** diff --git a/src/People.php b/src/People.php index b5f989c..ac3b76c 100644 --- a/src/People.php +++ b/src/People.php @@ -202,11 +202,11 @@ public function enqueue_block_editor_assets(): void { return; } - $asset_data = require_once ORGANIZATIONAL_PLUGIN_DIR . '/js/build/people-meta/index.asset.php'; + $asset_data = require_once plugin_dir_path( PLUGIN_FILE ) . '/js/build/people-meta/index.asset.php'; wp_enqueue_script( 'organizational-people-meta', - plugins_url( '/js/build/people-meta/index.js', ORGANIZATIONAL_PLUGIN_FILE ), + plugins_url( '/js/build/people-meta/index.js', PLUGIN_FILE ), $asset_data['dependencies'], $asset_data['version'], true diff --git a/src/Publications.php b/src/Publications.php index 81abd84..6724db4 100644 --- a/src/Publications.php +++ b/src/Publications.php @@ -154,11 +154,11 @@ public function enqueue_block_editor_assets(): void { return; } - $asset_data = require_once ORGANIZATIONAL_PLUGIN_DIR . '/js/build/publication-meta/index.asset.php'; + $asset_data = require_once plugin_dir_path( PLUGIN_FILE ) . '/js/build/publication-meta/index.asset.php'; wp_enqueue_script( 'organizational-publication-meta', - plugins_url( '/js/build/publication-meta/index.js', ORGANIZATIONAL_PLUGIN_FILE ), + plugins_url( '/js/build/publication-meta/index.js', PLUGIN_FILE ), $asset_data['dependencies'], $asset_data['version'], true From 1cf8a86817aaab55dcc2cf70b99c1e4cc63a48c7 Mon Sep 17 00:00:00 2001 From: jeremyfelt Date: Tue, 19 Nov 2024 14:11:58 -0800 Subject: [PATCH 4/5] Ensure `get_current_screen()` access, bump phpstan level 8 Chasing waterfalls --- phpstan.neon.dist | 4 +++- src/People.php | 2 +- src/Publications.php | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index ac75668..7c2e4ef 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -2,4 +2,6 @@ includes: - %rootDir%/../../happyprime/coding-standards/phpstan.neon.dist parameters: - level: 5 + level: 8 + ignoreErrors: + - identifier: missingType.iterableValue diff --git a/src/People.php b/src/People.php index ac3b76c..20f77c1 100644 --- a/src/People.php +++ b/src/People.php @@ -198,7 +198,7 @@ public function get_mailto_source( array $source_args, \WP_Block $block_instance * Enqueue block editor assets used by this post type. */ public function enqueue_block_editor_assets(): void { - if ( 'post' !== get_current_screen()->base || get_current_screen()->post_type !== $this->post_type ) { + if ( ! get_current_screen() || 'post' !== get_current_screen()->base || get_current_screen()->post_type !== $this->post_type ) { return; } diff --git a/src/Publications.php b/src/Publications.php index 6724db4..4865f57 100644 --- a/src/Publications.php +++ b/src/Publications.php @@ -150,7 +150,7 @@ public function get_date_source( array $source_args, \WP_Block $block_instance ) * Enqueue block editor assets used by this post type. */ public function enqueue_block_editor_assets(): void { - if ( 'post' !== get_current_screen()->base || get_current_screen()->post_type !== $this->post_type ) { + if ( ! get_current_screen() || 'post' !== get_current_screen()->base || get_current_screen()->post_type !== $this->post_type ) { return; } From 7223319cceb5f680c639ca0eda52d2e2beaf353f Mon Sep 17 00:00:00 2001 From: jeremyfelt Date: Tue, 19 Nov 2024 14:12:44 -0800 Subject: [PATCH 5/5] Fix PHPCS spacing --- plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.php b/plugin.php index b76c898..4af999a 100644 --- a/plugin.php +++ b/plugin.php @@ -19,7 +19,7 @@ die; } -const VERSION = '2.2.0'; +const VERSION = '2.2.0'; const PLUGIN_FILE = __FILE__; require_once __DIR__ . '/vendor/autoload.php';