-
Notifications
You must be signed in to change notification settings - Fork 3
[ カスタム投稿タイプマネージャー ] 設定から解説記事やベクトレへのリンクを追加 #1117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
0e20445
fb90706
d2b308b
07a3c26
518d3c5
8c87a21
36b94d8
dec9aab
2cc0229
eadbb8a
8fdc899
0fe8dfc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,65 @@ public static function add_cap_post_type_manage() { | |
$role->add_cap( 'publish_others_' . $post_type_name . 's' ); | ||
} | ||
|
||
/** | ||
* ヘルプ通知 | ||
* | ||
* @return string | ||
*/ | ||
public static function add_post_type_get_help_notice() { | ||
// サイトの言語が日本語 (ja) であるかどうかを判定 | ||
if ( get_locale() !== 'ja' ) { | ||
return ''; // 日本語以外の場合は何も返さない | ||
} | ||
|
||
// ユーザーが通知を無視したフラグが保存されているかをチェック | ||
if ( get_user_meta( get_current_user_id(), 'vk-all-in-one-expansion-unit_dismissed_notice', true ) ) { | ||
return ''; // 通知を無視している場合は何も返さない | ||
} | ||
kurudrive marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
$dismiss_url = esc_url( | ||
wp_nonce_url( | ||
add_query_arg('vk-all-in-one-expansion-unit-dismiss', 'dismiss_admin_notice'), | ||
'vk-all-in-one-expansion-unit-dismiss-' . get_current_user_id() | ||
) | ||
); | ||
|
||
// ヘルプ通知のHTMLを生成して返す | ||
return wp_kses_post( | ||
'<div class="notice notice-info is-dismissible"> | ||
<p style="margin-top: 10px;"><strong>' . __( 'Help and Documentation', 'vk-all-in-one-expansion-unit' ) . ':</strong> ' . __( 'Learn more about custom post type settings by visiting the following resources:', 'vk-all-in-one-expansion-unit' ) . '</p> | ||
<ul style="list-style-type: disc; margin-top: 0; margin-left: 20px;"> | ||
<li><a href="https://ex-unit.nagoya/ja/about/custom_post_type_manager" target="_blank">' . __( 'ExUnit Site: Custom Post Type Manager', 'vk-all-in-one-expansion-unit' ) . '</a></li> | ||
<li><a href="https://training.vektor-inc.co.jp/courses/x-t9-custom-post-type/" target="_blank">' . __( 'Vektor Training: X-T9 Setup Guide for Custom Post Types', 'vk-all-in-one-expansion-unit' ) . '</a></li> | ||
<li><a href="https://training.vektor-inc.co.jp/courses/lightning-basic-settings/lessons/lightning-custom-post-type-lightning/" target="_blank">' . __( 'Vektor Training: Lightning Basic Settings for Custom Post Types', 'vk-all-in-one-expansion-unit' ) . '</a></li> | ||
</ul> | ||
<p><a href="' . $dismiss_url . '" target="_parent">' . esc_html__( 'Dismiss this notice', 'vk-blocks' ) . '</a></p> | ||
</div>' | ||
); | ||
} | ||
|
||
/** | ||
* Display help notice on specific page | ||
* | ||
* @return void | ||
*/ | ||
public static function display_help_notice() { | ||
// 現在のページを取得 | ||
global $pagenow; | ||
|
||
// 特定のページのみ通知を表示する | ||
if ($pagenow === 'edit.php' && isset($_GET['post_type']) && $_GET['post_type'] === 'post_type_manage') { | ||
// 通知のHTMLを取得して表示 | ||
echo self::add_post_type_get_help_notice(); | ||
} | ||
|
||
// 通知の無視パラメーターをチェック | ||
if ( isset( $_GET['vk-all-in-one-expansion-unit-dismiss'] ) && $_GET['vk-all-in-one-expansion-unit-dismiss'] === 'dismiss_admin_notice' ) { | ||
check_admin_referer( 'vk-all-in-one-expansion-unit-dismiss-' . get_current_user_id() ); | ||
update_user_meta( get_current_user_id(), 'vk-all-in-one-expansion-unit_dismissed_notice', true ); | ||
} | ||
} | ||
|
||
/******************************************* | ||
* カスタムフィールドの meta box を作成. | ||
*/ | ||
|
@@ -70,11 +129,15 @@ public static function add_meta_box() { | |
* @return void | ||
*/ | ||
public static function add_meta_box_action() { | ||
|
||
global $post; | ||
|
||
// CSRF対策の設定(フォームにhiddenフィールドとして追加するためのnonceを「'noncename__post_type_manager」として設定). | ||
wp_nonce_field( wp_create_nonce( __FILE__ ), 'noncename__post_type_manager' ); | ||
|
||
// 通知メッセージを取得して表示 | ||
echo self::add_post_type_get_help_notice(); | ||
|
||
?> | ||
<style type="text/css"> | ||
table.table { border-collapse: collapse; border-spacing: 0;width:100%; } | ||
|
@@ -170,24 +233,25 @@ public static function add_meta_box_action() { | |
echo '<hr>'; | ||
|
||
// JavaScript to update icon selection and validate input | ||
echo '<script> | ||
function updateIconSelection(icon) { | ||
document.getElementById("veu_menu_icon").value = icon; | ||
} | ||
echo ' | ||
<script> | ||
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 = ""; // 不正な入力をクリア | ||
} | ||
}); | ||
}); | ||
</script>'; | ||
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 = ""; // 不正な入力をクリア | ||
} | ||
}); | ||
}); | ||
</script>'; | ||
|
||
/******************************************* | ||
* Export to Rest api | ||
|
@@ -568,4 +632,6 @@ public function __construct() { | |
|
||
$VK_Post_Type_Manager = new VK_Post_Type_Manager(); // phpcs:ignore | ||
|
||
add_action('admin_notices', array('VK_Post_Type_Manager', 'display_help_notice'), 20); | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mtdkei
あー、これは「ExUnit の有効化設定画面で別ウィンドウで開く設定を追加」で趣旨が少し異なるので、微妙なラインですが別のプルリクであげて欲しいですー。で、多分こういう変更は作業中に発生してすぐに承認して欲しい時が多いと思うので、別でプルリクだけ作って、説明とかは適当で良いので、優先ですぐ見て欲しいとか連絡いただけるといいかなとー。
(今回はこのままでいいですー🙂)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
そうですね、おっしゃる通りです。次から別のプルリクで対応します。