From 724bcc1516f02c85595c15e6bd00e996c0acc9da Mon Sep 17 00:00:00 2001 From: mtdkei Date: Thu, 25 Apr 2024 15:20:18 +0900 Subject: [PATCH 1/7] Add post type menu icon --- .../package/class.post-type-manager.php | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/inc/post-type-manager/package/class.post-type-manager.php b/inc/post-type-manager/package/class.post-type-manager.php index c7ad94d6..cb4a67ff 100644 --- a/inc/post-type-manager/package/class.post-type-manager.php +++ b/inc/post-type-manager/package/class.post-type-manager.php @@ -128,6 +128,61 @@ public static function add_meta_box_action() { echo ''; echo '
'; + + /******************************************* + * Menu Icon + */ + echo '

' . esc_html__( 'Menu Icon(Optional)', 'vk-all-in-one-expansion-unit' ) . '

'; + echo '

' . esc_html__( 'Select an icon from the images below, or enter a custom Dashicon class.' ) . '

'; + + echo '
'; + $icons = [ + 'dashicons-admin-post', + 'dashicons-admin-site', + 'dashicons-admin-users', + 'dashicons-admin-media', + 'dashicons-admin-comments', + 'dashicons-admin-appearance', + 'dashicons-welcome-write-blog', + 'dashicons-dashboard', + 'dashicons-admin-plugins', + 'dashicons-admin-settings', + 'dashicons-admin-network', + 'dashicons-admin-home', + 'dashicons-admin-generic', + 'dashicons-admin-collapse', + ]; + + foreach ($icons as $icon) { + echo ''; + } + + echo ''; + echo '' . esc_html__('Dashicons Library', 'vk-all-in-one-expansion-unit') . ''; + + echo '
'; + + echo '
'; + + // JavaScript to update icon selection and validate input + echo ''; /******************************************* * Export to Rest api @@ -270,6 +325,7 @@ public static function save_cf_value( $post_id ) { 'veu_post_type_id', 'veu_post_type_items', 'veu_menu_position', + 'veu_menu_icon', 'veu_post_type_export_to_api', 'veu_post_type_rewrite', 'veu_taxonomy', @@ -329,6 +385,10 @@ public static function add_post_type() { foreach ( $post_type_items as $key => $value ) { $supports[] = $key; } + + // 投稿タイプのアイコンを取得 + $menu_icon = get_post_meta($post->ID, 'veu_menu_icon', true); + $menu_icon = !empty($menu_icon) ? $menu_icon : 'dashicons-admin-generic'; // カスタム投稿タイプのスラッグ. $post_type_id = mb_strimwidth( mb_convert_kana( mb_strtolower( esc_html( get_post_meta( $post->ID, 'veu_post_type_id', true ) ) ), 'a' ), 0, 20, '', 'UTF-8' ); @@ -362,6 +422,7 @@ public static function add_post_type() { 'public' => true, 'has_archive' => true, 'menu_position' => $menu_position, + 'menu_icon' => $menu_icon, 'supports' => $supports, 'rewrite' => $rewrite, ); From 9118a676d21f4338def67dd56d0a1688767eda82 Mon Sep 17 00:00:00 2001 From: mtdkei Date: Thu, 25 Apr 2024 15:21:20 +0900 Subject: [PATCH 2/7] Add a menu icon setting. --- readme.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.txt b/readme.txt index 34dcffb7..b36d0ea2 100644 --- a/readme.txt +++ b/readme.txt @@ -81,6 +81,8 @@ e.g. == Changelog == +[ Add setting ][ Post Type Manager ] Add a menu icon setting. + = 9.97.2 = [ Bug fix ] In WordPress 6.5, a link to the plugin page has been added to the admin bar on the front end by default. Consequently, ExUnit has been modified to no longer add this link on the front end. From cc8f207f798c0081f3d978c5c9a429060600986d Mon Sep 17 00:00:00 2001 From: mtdkei Date: Fri, 26 Apr 2024 08:46:46 +0900 Subject: [PATCH 3/7] Add test-menu-icon-setting.php --- tests/test-menu-icon-setting.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/test-menu-icon-setting.php diff --git a/tests/test-menu-icon-setting.php b/tests/test-menu-icon-setting.php new file mode 100644 index 00000000..d7ca8017 --- /dev/null +++ b/tests/test-menu-icon-setting.php @@ -0,0 +1,32 @@ +postTypeManager = new VK_Post_Type_Manager(); + // Mock any necessary WordPress functions here + } + + public function testMenuIconOutput() { + // Assuming there's a method to get the menu icon form HTML + $output = $this->postTypeManager->get_menu_icon_html(); + $this->assertStringContainsString('dashicons-admin-post', $output, 'The output should contain a default dashicon option.'); + } + + protected function tearDown(): void { + parent::tearDown(); + // Clean up here + } +} From c70002dce0dcc1d5247fb4d1c179a613a6f78ba9 Mon Sep 17 00:00:00 2001 From: mtdkei Date: Fri, 26 Apr 2024 09:07:12 +0900 Subject: [PATCH 4/7] Change test method --- tests/test-menu-icon-setting.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/tests/test-menu-icon-setting.php b/tests/test-menu-icon-setting.php index d7ca8017..7888568f 100644 --- a/tests/test-menu-icon-setting.php +++ b/tests/test-menu-icon-setting.php @@ -10,23 +10,19 @@ */ class MenuIconTest extends WP_UnitTestCase { - private $postTypeManager; - - protected function setUp(): void { - parent::setUp(); - require_once VEU_DIRECTORY_PATH . '/inc/post-type-manager/package/class.post-type-manager.php'; - $this->postTypeManager = new VK_Post_Type_Manager(); - // Mock any necessary WordPress functions here + private function get_menu_icon_html() { + $icon = get_option('veu_menu_icon', 'dashicons-admin-post'); // ここで使用するオプション名を適切なものに変更してください + return ''; } public function testMenuIconOutput() { - // Assuming there's a method to get the menu icon form HTML - $output = $this->postTypeManager->get_menu_icon_html(); - $this->assertStringContainsString('dashicons-admin-post', $output, 'The output should contain a default dashicon option.'); + update_option('veu_menu_icon', 'dashicons-admin-generic'); + $output = $this->get_menu_icon_html(); + $this->assertStringContainsString('dashicons-admin-generic', $output, 'The output should contain the correct dashicon class.'); } protected function tearDown(): void { + delete_option('veu_menu_icon'); parent::tearDown(); - // Clean up here } } From 36f86d5bf586488f5b527b276ebe7870a0c74d72 Mon Sep 17 00:00:00 2001 From: mtdkei Date: Fri, 26 Apr 2024 10:31:58 +0900 Subject: [PATCH 5/7] Add div --- inc/post-type-manager/package/class.post-type-manager.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/inc/post-type-manager/package/class.post-type-manager.php b/inc/post-type-manager/package/class.post-type-manager.php index cb4a67ff..24a799df 100644 --- a/inc/post-type-manager/package/class.post-type-manager.php +++ b/inc/post-type-manager/package/class.post-type-manager.php @@ -159,9 +159,11 @@ public static function add_meta_box_action() { echo ''; } + echo ''; + echo ''; echo '
'; From 372418f8ce40f74cc9cc2fc9664d933422f3dfd6 Mon Sep 17 00:00:00 2001 From: mtdkei Date: Fri, 26 Apr 2024 11:38:04 +0900 Subject: [PATCH 6/7] Add 'none' setting --- .../package/class.post-type-manager.php | 48 ++++++++++++------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/inc/post-type-manager/package/class.post-type-manager.php b/inc/post-type-manager/package/class.post-type-manager.php index 24a799df..172e746c 100644 --- a/inc/post-type-manager/package/class.post-type-manager.php +++ b/inc/post-type-manager/package/class.post-type-manager.php @@ -170,21 +170,24 @@ public static function add_meta_box_action() { // JavaScript to update icon selection and validate input echo ''; +function updateIconSelection(icon) { + document.getElementById("veu_menu_icon").value = icon; +} + +document.addEventListener("DOMContentLoaded", function () { + var inputField = document.getElementById("veu_menu_icon"); + + // `change` イベントを使用して、フォーカスが外れたときにチェックする + inputField.addEventListener("change", function() { + // SVGデータURI、\'none\'、または\'dashicons-\'で始まる値を許可 + if (!this.value.startsWith("dashicons-") && !this.value.startsWith("data:image/svg+xml;base64,") && this.value !== \'none\') { + alert("' . __( 'Please enter a valid input. You can enter a Dashicon class, a base64-encoded SVG, or \'none\' to leave it blank for CSS customization.', 'vk-all-in-one-expansion-unit' ) . '"); + this.value = ""; // 不正な入力をクリア + } + }); +}); +'; + /******************************************* * Export to Rest api @@ -369,8 +372,21 @@ public static function add_post_type() { ); $custom_post_types = get_posts( $args ); if ( $custom_post_types ) { + foreach ( $custom_post_types as $key => $post ) { + /******************************************* + * メニューアイコンを設定するためのコード + */ + $menu_icon = get_post_meta($post->ID, 'veu_menu_icon', true); + if (empty($menu_icon)) { + $menu_icon = 'dashicons-admin-post'; + } elseif ($menu_icon === 'none') { + $menu_icon = ''; // CSSでスタイリング可能に + } elseif (!strpos($menu_icon, 'dashicons-') === 0 && !strpos($menu_icon, 'data:image/svg+xml;base64,') === 0) { + $menu_icon = 'dashicons-admin-post'; + } + /******************************************* * 投稿タイプ追加. */ @@ -390,7 +406,7 @@ public static function add_post_type() { // 投稿タイプのアイコンを取得 $menu_icon = get_post_meta($post->ID, 'veu_menu_icon', true); - $menu_icon = !empty($menu_icon) ? $menu_icon : 'dashicons-admin-generic'; + $menu_icon = !empty($menu_icon) ? $menu_icon : 'dashicons-admin-post'; // カスタム投稿タイプのスラッグ. $post_type_id = mb_strimwidth( mb_convert_kana( mb_strtolower( esc_html( get_post_meta( $post->ID, 'veu_post_type_id', true ) ) ), 'a' ), 0, 20, '', 'UTF-8' ); From 5fd8e190dd6b7f5e68aecb781ded66f79b50a5a1 Mon Sep 17 00:00:00 2001 From: mtdkei Date: Tue, 30 Apr 2024 14:13:48 +0900 Subject: [PATCH 7/7] Remove tests/test-menu-icon-setting.php --- tests/test-menu-icon-setting.php | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 tests/test-menu-icon-setting.php diff --git a/tests/test-menu-icon-setting.php b/tests/test-menu-icon-setting.php deleted file mode 100644 index 7888568f..00000000 --- a/tests/test-menu-icon-setting.php +++ /dev/null @@ -1,28 +0,0 @@ -'; - } - - public function testMenuIconOutput() { - update_option('veu_menu_icon', 'dashicons-admin-generic'); - $output = $this->get_menu_icon_html(); - $this->assertStringContainsString('dashicons-admin-generic', $output, 'The output should contain the correct dashicon class.'); - } - - protected function tearDown(): void { - delete_option('veu_menu_icon'); - parent::tearDown(); - } -}