diff --git a/admin/class-admin.php b/admin/class-admin.php index d391c12..bc444b2 100644 --- a/admin/class-admin.php +++ b/admin/class-admin.php @@ -27,12 +27,19 @@ class Admin { * * @var string[] */ - private $settings_page = [ + private array $settings_page = [ 'slug' => 'nlds-community-blocks-settings', 'page_title' => 'NLDS Community Blocks Settings', 'menu_title' => 'NLDS Community Blocks', ]; + /** + * Return strring array of selected blocks. + * + * @var string[] $selected_blocks string[] of selected blocks. + */ + private array $selected_blocks = []; + /** * Enqueue assets for dynamic blocks for the block editor. */ @@ -85,10 +92,37 @@ public function enqueue_block_editor_assets() { } } + /** + * Enqueue settings page assets. + * + * @return void + */ + public function enqueue_settings_page_assets(): void { + global $pagenow; + + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Just checking on which admin page we are. + if ( 'options-general.php' !== $pagenow || ! isset( $_GET['page'] ) || $_GET['page'] !== $this->settings_page['slug'] ) { + return; + } + + if ( ! Plugin::has_resource( NCB_ABSPATH . NCB_ASSETS_DIR . 'admin/settings-page.css' ) ) { + return; + } + + wp_enqueue_style( + $this->settings_page['slug'], + esc_url( NCB_ASSETS_URL ) . 'admin/settings-page.css', + [], + filemtime( NCB_ABSPATH . NCB_ASSETS_DIR . 'admin/settings-page.css' ) ?? NCB_VERSION + ); + } + /** * Load all blocks. + * + * @return void */ - public function load_blocks() { + public function load_blocks(): void { foreach ( glob( NCB_ABSPATH . NCB_BLOCKS_DIR . '*/*/class-*.php' ) as $file ) { include_once $file; } @@ -102,15 +136,16 @@ public function load_blocks() { * Register all blocks from this plugin as allowed block types. * * @param bool|array $allowed_block_types A list of allowed block types, true if all blocks are allowed. + * @source https://developer.wordpress.org/reference/hooks/allowed_block_types_all/ * - * @return array $allowed_block_types A list of all blocks registered by this plugin. + * @return bool|array $allowed_block_types A list of all blocks registered by this plugin. */ - public function allowed_block_types( $allowed_block_types ) { - $ncb_block_list = include_once NCB_ABSPATH . NCB_BLOCKS_DIR . 'block-list.php'; - + public function allowed_block_types( mixed $allowed_block_types ): mixed { + $ncb_block_list = get_option( 'ncb_allowed_blocks', [] ); if ( is_array( $allowed_block_types ) && is_array( $ncb_block_list ) ) { + // Not sure to override or merge, since the person who implements it, may have different blocks. $allowed_block_types = array_merge( $allowed_block_types, $ncb_block_list ); - } else if( ! is_array( $allowed_block_types ) && is_array( $ncb_block_list ) ) { + } elseif ( ! is_array( $allowed_block_types ) && is_array( $ncb_block_list ) ) { $allowed_block_types = $ncb_block_list; } @@ -122,7 +157,7 @@ public function allowed_block_types( $allowed_block_types ) { * * @return void */ - public function nlds_community_blocks_add_settings_page() { + public function nlds_community_blocks_add_settings_page(): void { add_options_page( $this->settings_page['page_title'], $this->settings_page['menu_title'], @@ -137,9 +172,9 @@ public function nlds_community_blocks_add_settings_page() { * * @return void */ - public function nlds_community_blocks_render_settings_page() { + public function nlds_community_blocks_render_settings_page(): void { // Generate a nonce field. - wp_nonce_field( $this->settings_page['slug'], 'nlds-community-blocks-settings-nonce' ); + wp_nonce_field( $this->settings_page['slug'], $this->settings_page['slug'] . '-nonce' ); ?>
%s
', esc_attr_x( 'Select the municipality whose tokens you want to load.', 'Settings page description', 'nlds-community-blocks' ) ); + printf( '%s
', esc_attr_x( 'Select the organisation whose tokens you want to load.', 'Settings page description', 'nlds-community-blocks' ) ); } /** @@ -246,7 +289,7 @@ public function nlds_community_blocks_render_token_select() { * * @return void */ - public function nlds_community_blocks_render_disable_default_blocks() { + public function nlds_community_blocks_render_disable_default_blocks(): void { $ncb_default_block_styles = [ 'wp-block-post-content', 'wp-block-comments', @@ -262,29 +305,242 @@ public function nlds_community_blocks_render_disable_default_blocks() { foreach ( $ncb_default_block_styles as $ncb_default_block_style ) { if ( ! empty( $ncb_selected_default_block_styles ) && in_array( $ncb_default_block_style, $ncb_selected_default_block_styles, true ) ) { - printf( '%s
', esc_attr_x( 'Some default WordPress Block styles can overwrite the NLDS block styles.', 'Settings page description', 'nlds-community-blocks' ) ); } + /** + * Render the checkbox groups for the allowed blocks. + * + * @return void + */ + public function nlds_community_blocks_render_allowed_blocks(): void { + static $registered_blocks = null; + if ( empty( $registered_blocks ) ) { + $registered_blocks = \WP_Block_Type_Registry::get_instance()->get_all_registered(); + } + + // Map core blocks in a more readable format which is far more lightweight. + $ncb_core_blocks = array_reduce( + $registered_blocks, + function ( $carry, $block ) { + if ( ! empty( $block->title ) && str_contains( $block->name, 'core/' ) ) { + $carry[ $block->category ][ $block->name ] = [ + 'title' => $block->title ?? '', + 'description' => $block->description ?? '', + ]; + } + + return $carry; + }, + [] + ); + + $this->selected_blocks = (array) get_option( 'ncb_allowed_blocks', [] ); + + // Sort the outer array by keys. + ksort( $ncb_core_blocks ); + + foreach ( $ncb_core_blocks as &$core_block_groups ) { + uasort( + $core_block_groups, + function ( $a, $b ) { + return strcmp( $a['title'], $b['title'] ); + } + ); + } + + // Render the fieldsets. + self::fieldsets_render( $ncb_core_blocks ); + self::fieldsets_render( self::get_custom_blocks_meta() ); + } + + /** + * Returns multiple fieldsets for the allowed blocks. + * + * @param array $block_groups Array of grouped blocks by category, mapped to a specific format. + * + * @return void + */ + private function fieldsets_render( array $block_groups ): void { + foreach ( $block_groups as $ncb_category => $ncb_blocks ) { + if ( empty( $ncb_blocks ) ) { + continue; + } + + /* translators: %1$s: The slug for the className, %2$s the category title. */ + printf( + ''; + } + } + + /** + * Get the custom blocks meta from the blocks that are compiled. + * + * @return array + */ + private static function get_custom_blocks_meta(): array { + $ncb_blocks_to_return = []; + foreach ( glob( NCB_ABSPATH . NCB_ASSETS_DIR . 'blocks/*/*/block.json' ) as $ncb_block_meta_file ) { + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- We need to read the file, which is from this plugin. + $block = json_decode( file_get_contents( $ncb_block_meta_file ), false ); + $ncb_blocks_to_return[ $block->category ][ $block->name ] = [ + 'title' => $block->title ?? '', + 'description' => $block->description ?? '', + ]; + } + + return $ncb_blocks_to_return; + } + + /** + * Returns the label of the custom or core category. + * + * @param string $slug The category slug. + * + * @return string + */ + private static function get_block_category_label( string $slug ): string { + return implode( + ', ', + array_filter( + [ + self::get_core_block_category_label( $slug ), + self::get_custom_block_category_labels( $slug ), + ] + ) + ); + } + + /** + * Return the title of the block category. + * + * @param string $slug The slug of the category. + * + * @source https://developer.wordpress.org/reference/functions/get_default_block_categories/ + * + * @return string + */ + private static function get_core_block_category_label( string $slug ): string { + static $default_categories = null; + if ( empty( $default_categories ) ) { + $default_categories = get_default_block_categories(); + } + + $index = array_search( $slug, array_column( $default_categories, 'slug' ), true ); + + if ( is_bool( $index ) ) { + return ''; + } + + return $default_categories[ $index ]['title']; + } + + /** + * Return the title of the block category of the custom blocks. + * + * @param string $slug The slug of the category. + * + * @source https://developer.wordpress.org/reference/functions/get_default_block_categories/ + * + * @return string + */ + private static function get_custom_block_category_labels( string $slug ): string { + // Start duplicate code from class-frontend.php, need to refactor this. + + // phpcs:ignore Generic.Commenting.Todo.TaskFound -- Before production this has to be done. + // @todo: Check how to re-use `register_custom_block_category` from class-frontend.php . + $ncb_categories = [ + [ + 'slug' => 'nlds-community-blocks', + 'title' => __( 'NLDS Community Blocks', 'nlds-community-blocks' ), + 'icon' => null, + ], + [ + 'slug' => 'nlds-community-blocks-layout', + 'title' => __( 'NLDS Community Layout Blocks', 'nlds-community-blocks' ), + 'icon' => null, + ], + ]; + + foreach ( glob( NCB_ABSPATH . NCB_ASSETS_DIR . 'blocks/*', GLOB_ONLYDIR ) as $ncb_community_path ) { + if ( empty( $ncb_community_path ) ) { + continue; + } + + $ncb_exploded_community_path = explode( '/', $ncb_community_path ); + $ncb_community = end( $ncb_exploded_community_path ); + + if ( 'nlds' === $ncb_community ) { + continue; + } + + $ncb_categories[] = [ + /* translators: %s Community slug. */ + 'slug' => sprintf( 'nlds-community-%s-blocks', esc_attr( $ncb_community ) ), + /* translators: %s Community slug. */ + 'title' => sprintf( _x( 'NLDS %s Community Blocks', 'Register custom block category', 'nlds-community-blocks' ), esc_attr( ucfirst( $ncb_community ) ) ), + 'icon' => null, + ]; + $ncb_categories[] = [ + /* translators: %s Community slug. */ + 'slug' => sprintf( 'nlds-community-%s-blocks-layout', esc_attr( $ncb_community ) ), + /* translators: %s Community slug. */ + 'title' => sprintf( _x( 'NLDS %s Community Layout Blocks', 'Register custom block category', 'nlds-community-blocks' ), esc_attr( ucfirst( $ncb_community ) ) ), + 'icon' => null, + ]; + } + // End of duplicated code. + + $index = array_search( $slug, array_column( $ncb_categories, 'slug' ), true ); + + if ( is_bool( $index ) ) { + return ''; + } + + return $ncb_categories[ $index ]['title']; + } + /** * Extend body classes of the editor. * - * @param {string} $classes String of classes. + * @param string $classes String of classes. * - * @return mixed|string + * @return string */ - public function ncb_editor_body_class_by_community_theme( $classes ) { + public function ncb_editor_body_class_by_community_theme( string $classes ): string { if ( ! get_current_screen()->is_block_editor ) { return $classes; } $ncb_exploded_classes = explode( ' ', $classes ); - $ncb_theme = esc_attr( get_option( 'ncb_municipality', 'denhaag' ) ); + $ncb_theme = esc_attr( get_option( 'ncb_organisation', '' ) ); if ( ! empty( $ncb_theme ) ) { $ncb_exploded_classes[] = "$ncb_theme-theme"; } diff --git a/filters/ncb-denhaag-meta-accordion-allowed-blocks.php b/filters/ncb-denhaag-meta-accordion-allowed-blocks.php index 5665865..879e97e 100644 --- a/filters/ncb-denhaag-meta-accordion-allowed-blocks.php +++ b/filters/ncb-denhaag-meta-accordion-allowed-blocks.php @@ -10,13 +10,11 @@ /** * Return boolean based on post types we want to allow to show the Share buttons. * - * @param array $blocks The allowed innerBlocks. - * @param string $post_type Post types we want to allow. - * @param int $post_id The post ID. + * @param array $blocks The allowed innerBlocks. * - * @return bool + * @return array */ -function ncb_filter_denhaag_meta_accordion_allowed_blocks( array $blocks = [], string $post_type = 'post', int $post_id = 0 ) { +function ncb_filter_denhaag_meta_accordion_allowed_blocks( array $blocks = [] ):array { $ncb_blocks = [ 'ncb-denhaag/authentication', 'ncb-denhaag/button-group', @@ -33,10 +31,10 @@ function ncb_filter_denhaag_meta_accordion_allowed_blocks( array $blocks = [], s 'ncb-denhaag/table', // Core components we allow. - 'core/list' + 'core/list', ]; return array_unique( array_merge( $blocks, $ncb_blocks ) ); } -add_filter( 'ncb_denhaag_meta_accordion_allowed_blocks', 'ncb_filter_denhaag_meta_accordion_allowed_blocks', 10, 3 ); +add_filter( 'ncb_denhaag_meta_accordion_allowed_blocks', 'ncb_filter_denhaag_meta_accordion_allowed_blocks', 10, 1 ); diff --git a/filters/ncb-denhaag-meta-buttons.php b/filters/ncb-denhaag-meta-buttons.php index 451892d..b602684 100644 --- a/filters/ncb-denhaag-meta-buttons.php +++ b/filters/ncb-denhaag-meta-buttons.php @@ -23,11 +23,3 @@ function ncb_filter_denhaag_meta_buttons( string $post_type = 'post', int $post_ } add_filter( 'ncb_denhaag_meta_buttons', 'ncb_filter_denhaag_meta_buttons', 10, 2 ); - - - - - - - - diff --git a/filters/ncb-filter-denhaag-meta-show-share.php b/filters/ncb-filter-denhaag-meta-show-share.php index e0238f9..590f20e 100644 --- a/filters/ncb-filter-denhaag-meta-show-share.php +++ b/filters/ncb-filter-denhaag-meta-show-share.php @@ -12,12 +12,11 @@ * * @param bool $state The default state. * @param string $post_type Post types we want to allow. - * @param int $post_id The post ID. * * @return bool */ -function ncb_filter_denhaag_meta_show_share( bool $state, string $post_type = 'post', int $post_id = 0 ) { +function ncb_filter_denhaag_meta_show_share( bool $state, string $post_type = 'post' ): bool { return in_array( esc_attr( $post_type ), [ 'post' ], true ); } -add_filter( 'ncb_denhaag_meta_show_share', 'ncb_filter_denhaag_meta_show_share', 10, 3 ); +add_filter( 'ncb_denhaag_meta_show_share', 'ncb_filter_denhaag_meta_show_share', 10, 2 ); diff --git a/filters/ncb-filter-denhaag-meta.php b/filters/ncb-filter-denhaag-meta.php index 31cf7ba..531ffa4 100644 --- a/filters/ncb-filter-denhaag-meta.php +++ b/filters/ncb-filter-denhaag-meta.php @@ -10,31 +10,23 @@ /** * Returns array of metadata we want to show in the denhaag/meta block. * - * @param array $array Array of meta data. + * @param array $args Array of meta data. * @param string $post_type The post type. * @param int $post_id The post ID. * * @return array */ -function ncb_filter_denhaag_meta( array $array = [], string $post_type = 'post', int $post_id = 0 ) { +function ncb_filter_denhaag_meta( array $args = [], string $post_type = 'post', int $post_id = 0 ): array { if ( in_array( $post_type, apply_filters( 'ncb_denhaag_meta_allow_post_types_post_type', [ 'post' ] ), true ) ) { - $array['post_type'] = apply_filters( 'ncb_denhaag_meta_post_type_label', $post_type, 'singular_name' ); + $args['post_type'] = apply_filters( 'ncb_denhaag_meta_post_type_label', $post_type, 'singular_name' ); } if ( in_array( $post_type, apply_filters( 'ncb_denhaag_meta_allow_post_types_date', [ 'post' ] ), true ) ) { - $array['date'] = apply_filters( 'ncb_denhaag_meta_date', get_the_date( 'U', $post_id ) ); + $args['date'] = apply_filters( 'ncb_denhaag_meta_date', get_the_date( 'U', $post_id ) ); } - return ! empty( $array ) ? array_filter( $array ) : []; + return ! empty( $args ) ? array_filter( $args ) : []; } add_filter( 'ncb_denhaag_meta', 'ncb_filter_denhaag_meta', 10, 3 ); - - - - - - - - diff --git a/frontend/class-frontend.php b/frontend/class-frontend.php index 55aa8eb..ebcee09 100644 --- a/frontend/class-frontend.php +++ b/frontend/class-frontend.php @@ -38,7 +38,6 @@ class Frontend { * @return array Array of block categories. */ public function register_custom_block_category( $categories ) { - $ncb_categories = [ [ 'slug' => 'nlds-community-blocks', @@ -52,7 +51,6 @@ public function register_custom_block_category( $categories ) { ], ]; - foreach ( glob( NCB_ABSPATH . NCB_ASSETS_DIR . 'blocks/*', GLOB_ONLYDIR ) as $ncb_community_path ) { if ( empty( $ncb_community_path ) ) { continue; @@ -98,7 +96,7 @@ public function enqueue_block_assets() { return false; } - $ncb_theme = esc_attr( get_option( 'ncb_municipality', 'denhaag' ) ); + $ncb_theme = esc_attr( get_option( 'ncb_organisation', '' ) ); if ( ! empty( $ncb_theme ) && Plugin::has_resource( NCB_ABSPATH . NCB_ASSETS_DIR . "client/tokens/ncb-$ncb_theme-tokens.css" ) ) { wp_enqueue_style( "ncb-$ncb_theme-tokens", @@ -125,9 +123,9 @@ public function enqueue_block_assets() { // Get block version, priority to package-lock.json version. $ncb_package_version = self::get_package_version( self::get_package_name_from_block_name( $ncb_block_meta['name'] ) ); - if( empty( $ncb_package_version ) && ! empty( $ncb_block_meta['version'] ) ) { + if ( empty( $ncb_package_version ) && ! empty( $ncb_block_meta['version'] ) ) { $ncb_package_version = esc_attr( $ncb_block_meta['version'] ); - } else if ( empty( $ncb_package_version ) ) { + } elseif ( empty( $ncb_package_version ) ) { $ncb_package_version = filemtime( $ncb_community . '/style.css' ); } @@ -318,12 +316,19 @@ public function ncb_denhaag_extend_wp_kses_posts( $allowed_tags ) { /** * Set class based on the selected theme. * - * @param {array} $classes An array of classes. + * @param string|string[] $classes An array of classes. * - * @return mixed + * @source https://developer.wordpress.org/reference/functions/body_class/ + * + * @return array */ - public function ncb_body_class_by_community_theme( $classes ) { - $ncb_theme = esc_attr( get_option( 'ncb_municipality', 'denhaag' ) ); + public function ncb_body_class_by_community_theme( mixed $classes ): array { + + if ( is_string( $classes ) ) { + $classes = explode( ' ', $classes ); + } + + $ncb_theme = esc_attr( get_option( 'ncb_organisation', '' ) ); if ( ! empty( $ncb_theme ) ) { $classes[] = "$ncb_theme-theme"; } @@ -435,10 +440,12 @@ public function ncb_action_community_icons_based_on_block() { /* * Each block that has an icon. */ - if ( self::has_block_in_editor_or_widgets( [ - 'ncb-denhaag/accordion', - 'ncb-denhaag/accordion-item', - ] ) ) { + if ( self::has_block_in_editor_or_widgets( + [ + 'ncb-denhaag/accordion', + 'ncb-denhaag/accordion-item', + ] + ) ) { $icons['denhaag'][] = [ '@type' => 'path', 'id' => 'ncb-denhaag-chevron-down-icon', @@ -459,12 +466,14 @@ public function ncb_action_community_icons_based_on_block() { ]; } - if ( self::has_block_in_editor_or_widgets( [ - 'ncb-denhaag/button', - 'ncb-denhaag/description-list', - 'ncb-denhaag/paragraph', - 'ncb-denhaag/link-item', - ] ) ) { + if ( self::has_block_in_editor_or_widgets( + [ + 'ncb-denhaag/button', + 'ncb-denhaag/description-list', + 'ncb-denhaag/paragraph', + 'ncb-denhaag/link-item', + ] + ) ) { $icons['denhaag'][] = [ '@type' => 'path', 'id' => 'ncb-denhaag-external-icon', @@ -473,7 +482,7 @@ public function ncb_action_community_icons_based_on_block() { ]; } - if ( self::has_block_in_editor_or_widgets( ['ncb-denhaag/button'] ) ) { + if ( self::has_block_in_editor_or_widgets( [ 'ncb-denhaag/button' ] ) ) { $icons['denhaag'][] = [ '@type' => 'path', 'id' => 'ncb-denhaag-arrow-right-icon', @@ -489,11 +498,13 @@ public function ncb_action_community_icons_based_on_block() { ]; } - if ( self::has_block_in_editor_or_widgets( [ - 'ncb-denhaag/highlighted-links', - 'ncb-denhaag/link-group', - 'ncb-denhaag/link-item', - ] ) ) { + if ( self::has_block_in_editor_or_widgets( + [ + 'ncb-denhaag/highlighted-links', + 'ncb-denhaag/link-group', + 'ncb-denhaag/link-item', + ] + ) ) { $icons['denhaag'][] = [ '@type' => 'path', 'id' => 'ncb-denhaag-arrow-right-icon', @@ -550,11 +561,13 @@ public function ncb_action_community_icons_based_on_block() { ]; } - if ( self::has_block_in_editor_or_widgets( [ - 'ncb-denhaag/social-links', - 'ncb-denhaag/social-link', - 'ncb-denhaag/meta', - ] ) ) { + if ( self::has_block_in_editor_or_widgets( + [ + 'ncb-denhaag/social-links', + 'ncb-denhaag/social-link', + 'ncb-denhaag/meta', + ] + ) ) { $icons['denhaag'][] = [ '@type' => 'path', 'id' => 'ncb-denhaag-whatsapp-icon', @@ -742,10 +755,12 @@ private static function get_package_version( $handle ): string { return ''; } - $lock = get_object_vars( json_decode( + $lock = get_object_vars( + json_decode( // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents - file_get_contents( $lock ) - ) ); + file_get_contents( $lock ) + ) + ); } if ( ! empty( $lock['dependencies']->{$handle} ) ) { @@ -758,22 +773,22 @@ private static function get_package_version( $handle ): string { /** * Ge the package name from the block name. * - * @param string $string The name of the block. + * @param string $block_name The name of the block. * * @return string|null */ - private static function get_package_name_from_block_name( $string ) { + private static function get_package_name_from_block_name( string $block_name ): ?string { - if( empty( $string )) { + if ( empty( $block_name ) ) { return null; } - if ( str_starts_with( $string, '@gemeente-' ) ) { + if ( str_starts_with( $block_name, '@gemeente-' ) ) { // Probably already formatted to the correct format. - return $string; + return $block_name; } - preg_match( '/ncb-([a-zA-Z]+)[\/-]([a-zA-Z-]+)/i', $string, $matches ); + preg_match( '/ncb-([a-zA-Z]+)[\/-]([a-zA-Z-]+)/i', $block_name, $matches ); if ( empty( $matches ) || empty( $matches[1] ) || empty( $matches[2] ) ) { return null; @@ -785,12 +800,13 @@ private static function get_package_name_from_block_name( $string ) { /** * Returns boolean if one of the blocks is on the page. + * * @param string[] $block_names Array of blocknames. * * @return bool */ private static function has_blocks( $block_names ) { - if( empty( $block_names ) ) { + if ( empty( $block_names ) ) { return false; } @@ -798,10 +814,10 @@ private static function has_blocks( $block_names ) { return has_block( $block_names ); } - foreach( $block_names as $block_name) { + foreach ( $block_names as $block_name ) { $ncb_has_block = has_block( $block_name ); - if( $ncb_has_block ) { + if ( $ncb_has_block ) { return true; } } diff --git a/functions/helpers.php b/functions/helpers.php index 9b0e2bb..9809516 100644 --- a/functions/helpers.php +++ b/functions/helpers.php @@ -181,4 +181,3 @@ function ncb_file_get_contents( $path_or_url ) { return false; } } - diff --git a/functions/ncb-mix.php b/functions/ncb-mix.php index 11df734..b4885ae 100644 --- a/functions/ncb-mix.php +++ b/functions/ncb-mix.php @@ -26,10 +26,12 @@ function ncb_mix( $path ): string { return NCB_ASSETS_URL . $path; } - $manifest = get_object_vars( json_decode( + $manifest = get_object_vars( + json_decode( // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents - file_get_contents( $manifest ), - ) ); + file_get_contents( $manifest ), + ) + ); } if ( ! str_starts_with( $path, '/' ) ) { diff --git a/includes/class-plugin.php b/includes/class-plugin.php index 95e2bed..8934ce2 100644 --- a/includes/class-plugin.php +++ b/includes/class-plugin.php @@ -75,7 +75,7 @@ private function define_constants() { private function set_locale() { $plugin_i18n = new I18n(); - add_action( 'plugins_loaded', array( $plugin_i18n, 'load_plugin_textdomain' ) ); + add_action( 'plugins_loaded', [ $plugin_i18n, 'load_plugin_textdomain' ] ); } /** @@ -100,6 +100,7 @@ private function define_admin_hooks() { $frontend = new Frontend(); add_action( 'admin_head', [ $frontend, 'ncb_action_community_icons_based_on_block' ] ); + add_action( 'admin_enqueue_scripts', [ $admin, 'enqueue_settings_page_assets' ] ); } /** @@ -120,7 +121,7 @@ private function define_frontend_hooks() { add_filter( 'body_class', [ $frontend, 'ncb_body_class_by_community_theme' ] ); add_action( 'wp_head', [ $frontend, 'ncb_action_community_icons_based_on_block' ] ); - $ncb_theme = esc_attr( get_option( 'ncb_municipality', 'denhaag' ) ); + $ncb_theme = esc_attr( get_option( 'ncb_organisation', '' ) ); switch ( $ncb_theme ) { case 'denhaag': add_filter( 'wp_kses_allowed_html', [ $frontend, 'ncb_denhaag_extend_wp_kses_posts' ] ); diff --git a/nlds-community-blocks.php b/nlds-community-blocks.php index 3e90c22..522c36e 100644 --- a/nlds-community-blocks.php +++ b/nlds-community-blocks.php @@ -25,7 +25,7 @@ } require_once plugin_dir_path( __FILE__ ) . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'class-autoloader.php'; -spl_autoload_register( array( '\Nlds_Community_Blocks\Includes\Autoloader', 'autoload' ) ); +spl_autoload_register( [ '\Nlds_Community_Blocks\Includes\Autoloader', 'autoload' ] ); // Make sure global functions are loaded. foreach ( glob( plugin_dir_path( __FILE__ ) . DIRECTORY_SEPARATOR . 'functions' . DIRECTORY_SEPARATOR . '*.php' ) as $ncb_plugin_functions ) { diff --git a/phpcs.xml.dist b/phpcs.xml.dist index f21e929..fa880b2 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -24,6 +24,25 @@