From 151026ef878ace0e5fd8dad0b2dbd7b2c8896afb Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 28 May 2021 21:06:37 +0900 Subject: [PATCH 1/3] =?UTF-8?q?WP=20PLUGIN=20MTEE(Meta=20Tag=20etc=20Exten?= =?UTF-8?q?d)=20OGP=E3=82=BF=E3=82=B0=E8=A8=AD=E5=AE=9A=E3=81=AE=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ・language_attributesフックでhtmlタグにprefixを追加 --- class/mtee-ogp-setting.php | 52 ++++++++++++++++++++++++++++++++++++++ class/mtee-output-ogp.php | 30 ++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 class/mtee-ogp-setting.php create mode 100644 class/mtee-output-ogp.php diff --git a/class/mtee-ogp-setting.php b/class/mtee-ogp-setting.php new file mode 100644 index 0000000..bcd5c3f --- /dev/null +++ b/class/mtee-ogp-setting.php @@ -0,0 +1,52 @@ + array('page', 'post',), + ); + + foreach ($default_built_ins['posts'] as $built_in) { + add_meta_box( + 'canonical_setting', + 'Canonical設定', + array($this, 'insert_meta_fields'), + $built_in, + 'normal' + ); + } + + if (isset($this->options['custom_posts'])) { + foreach ($this->options['custom_posts'] as $custom_post => $post_chk) { + if ($post_chk == 1) { + add_meta_box( + 'canonical_setting', + 'Canonical設定', + array($this, 'insert_meta_fields'), + $custom_post, 'normal' + ); + } + } + } + } + + } + +} \ No newline at end of file diff --git a/class/mtee-output-ogp.php b/class/mtee-output-ogp.php new file mode 100644 index 0000000..cff6e84 --- /dev/null +++ b/class/mtee-output-ogp.php @@ -0,0 +1,30 @@ +create_ogp_prefix(); + return $output; + } + + private function create_ogp_prefix(): string { + return ' prefix="og: https://ogp.me/ns#"'; + } + } +} \ No newline at end of file From c7f4e41e1c8123cd34308bf0440b1be91cfe6431 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 30 May 2021 12:46:26 +0900 Subject: [PATCH 2/3] =?UTF-8?q?WP=20PLUGIN=20MTEE(Meta=20Tag=20etc=20Exten?= =?UTF-8?q?d)=20=E3=82=AB=E3=82=B9=E3=82=BF=E3=83=A0=E6=8A=95=E7=A8=BF?= =?UTF-8?q?=E3=80=81=E3=82=AB=E3=82=B9=E3=82=BF=E3=83=A0=E5=88=86=E9=A1=9E?= =?UTF-8?q?=E3=81=AE=E3=82=AD=E3=83=BC=E3=83=AF=E3=83=BC=E3=83=89=E3=80=81?= =?UTF-8?q?=E3=83=87=E3=82=A3=E3=82=B9=E3=82=AF=E3=83=AA=E3=83=97=E3=82=B7?= =?UTF-8?q?=E3=83=A7=E3=83=B3=E3=81=AE=E9=81=A9=E7=94=A8=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ・カスタム投稿、カスタム分類のキーワード、ディスクリプションの適用チェックボックスを廃止し、全カスタム投稿、全カスタム分類に適用するよう修正 --- class/mtee-tax-setting.php | 92 ------------------- ...setting.php => mtee_canonical_setting.php} | 30 ++---- ...cal.php => mtee_meta_output_canonical.php} | 0 ...p => mtee_meta_output_noindexnofollow.php} | 0 ...utput-ogp.php => mtee_meta_output_ogp.php} | 0 ...ng.php => mtee_noindexnofolow_setting.php} | 0 ...post-setting.php => mtee_post_setting.php} | 38 ++++---- class/mtee_tax_setting.php | 90 ++++++++++++++++++ ...n-setting.php => mtee_version_setting.php} | 0 config.php | 4 +- meta-tag-etc-extend.php | 20 ++-- template/index.php | 51 ---------- 12 files changed, 128 insertions(+), 197 deletions(-) delete mode 100644 class/mtee-tax-setting.php rename class/{mtee-canonical-setting.php => mtee_canonical_setting.php} (84%) rename class/{mtee-output-canonical.php => mtee_meta_output_canonical.php} (100%) rename class/{mtee-output-noindexnofollow.php => mtee_meta_output_noindexnofollow.php} (100%) rename class/{mtee-output-ogp.php => mtee_meta_output_ogp.php} (100%) rename class/{mtee-noindexnofollow-setting.php => mtee_noindexnofolow_setting.php} (100%) rename class/{mtee-post-setting.php => mtee_post_setting.php} (73%) create mode 100644 class/mtee_tax_setting.php rename class/{mtee-version-setting.php => mtee_version_setting.php} (100%) diff --git a/class/mtee-tax-setting.php b/class/mtee-tax-setting.php deleted file mode 100644 index 6b04a18..0000000 --- a/class/mtee-tax-setting.php +++ /dev/null @@ -1,92 +0,0 @@ -options = $options; - $this->set_fields(); - add_action( 'create_term', array( $this, 'save_terms' ) ); //新規追加用フック - add_action( 'edit_terms', array( $this, 'save_terms' ) ); //編集ページ用フック - } - - public function set_fields() { - $built_ins = array( - 'term' => array( 'category', 'post_tag' ), - ); - - foreach ( $built_ins['term'] as $built_in ) { - add_action( $built_in . '_add_form_fields', array( $this, 'insert_term_meta_add_fields' ) ); - add_action( $built_in . '_edit_form_fields', array( $this, 'insert_term_meta_edit_fields' ) ); - } - - if ( isset( $this->options['taxonomies'] ) ) { - foreach ( $this->options['taxonomies'] as $tax_key => $tax_chk ) { - if ( $tax_chk == 1 ) { - add_action( $tax_key . '_add_form_fields', array( $this, 'insert_term_meta_add_fields' ) ); - add_action( $tax_key . '_edit_form_fields', array( $this, 'insert_term_meta_edit_fields' ) ); - } - } - } - } - - function insert_term_meta_add_fields( $tag ) { - $key_value = ''; - $desc_value = ''; - if ( isset( $tag->term_id ) ) { - $key_value = get_term_meta( $tag->term_id, MTEE_NAME_KEYWORDS, true ); - $desc_value = get_term_meta( $tag->term_id, MTEE_MTEE_NAME_DESCRIPTION, true ); - } - echo ' -
-meta keywords
- -
-
-meta description
- -
-'; - } - - function insert_term_meta_edit_fields( $tag ) { - $key_value = ''; - $desc_value = ''; - if ( isset( $tag->term_id ) ) { - $key_value = get_term_meta( $tag->term_id, MTEE_NAME_KEYWORDS, true ); - $desc_value = get_term_meta( $tag->term_id, MTEE_NAME_DESCRIPTION, true ); - } - echo ' - -meta keywords - - - -meta description - - -'; - } - - - function save_terms( $term_id ) { - if ( array_key_exists( MTEE_NAME_KEYWORDS, $_POST ) ) { - update_term_meta( $term_id, MTEE_NAME_KEYWORDS, $_POST[ MTEE_NAME_KEYWORDS ] ); - } - if ( array_key_exists( MTEE_NAME_DESCRIPTION, $_POST ) ) { - update_term_meta( $term_id, MTEE_NAME_DESCRIPTION, $_POST[ MTEE_NAME_DESCRIPTION ] ); - } - } - } - -} \ No newline at end of file diff --git a/class/mtee-canonical-setting.php b/class/mtee_canonical_setting.php similarity index 84% rename from class/mtee-canonical-setting.php rename to class/mtee_canonical_setting.php index 6341906..6730c28 100644 --- a/class/mtee-canonical-setting.php +++ b/class/mtee_canonical_setting.php @@ -33,31 +33,19 @@ if (!class_exists('mtee_canonical_setting')) { //------------------------------------------------------------------------------------------- public function add_meta_fields() { //add_meta_box(表示される入力ボックスのHTMLのID, ラベル, 表示する内容を作成する関数名, 投稿タイプ, 表示方法) - $default_built_ins = array( - 'posts' => array('page', 'post',), - ); + $custom_posts = array_values(get_post_types(array('public' => true, '_builtin' => false))); + $target_posts = array_merge(array('page', 'post',), $custom_posts); - foreach ($default_built_ins['posts'] as $built_in) { + foreach ($target_posts as $target_post) { add_meta_box( 'canonical_setting', 'Canonical設定', - array($this, 'insert_meta_fields'), - $built_in, - 'normal' - ); - } - - if (isset($this->options['custom_posts'])) { - foreach ($this->options['custom_posts'] as $custom_post => $post_chk) { - if ($post_chk == 1) { - add_meta_box( - 'canonical_setting', - 'Canonical設定', - array($this, 'insert_meta_fields'), - $custom_post, 'normal' - ); - } - } + array( + $this, + 'insert_meta_fields' + ), + $target_post, + 'normal'); } } diff --git a/class/mtee-output-canonical.php b/class/mtee_meta_output_canonical.php similarity index 100% rename from class/mtee-output-canonical.php rename to class/mtee_meta_output_canonical.php diff --git a/class/mtee-output-noindexnofollow.php b/class/mtee_meta_output_noindexnofollow.php similarity index 100% rename from class/mtee-output-noindexnofollow.php rename to class/mtee_meta_output_noindexnofollow.php diff --git a/class/mtee-output-ogp.php b/class/mtee_meta_output_ogp.php similarity index 100% rename from class/mtee-output-ogp.php rename to class/mtee_meta_output_ogp.php diff --git a/class/mtee-noindexnofollow-setting.php b/class/mtee_noindexnofolow_setting.php similarity index 100% rename from class/mtee-noindexnofollow-setting.php rename to class/mtee_noindexnofolow_setting.php diff --git a/class/mtee-post-setting.php b/class/mtee_post_setting.php similarity index 73% rename from class/mtee-post-setting.php rename to class/mtee_post_setting.php index d450ea0..89e26ca 100644 --- a/class/mtee-post-setting.php +++ b/class/mtee_post_setting.php @@ -5,10 +5,9 @@ if ( ! defined( 'ABSPATH' ) ) { if ( ! class_exists( 'mtee_post_setting' ) ) { - /** - * ページ、投稿、カスタム投稿の設定フォーム - * Class amd_post_setting - */ + /** + * Class mtee_post_setting + */ class mtee_post_setting { private $options; @@ -23,24 +22,19 @@ if ( ! class_exists( 'mtee_post_setting' ) ) { public function add_meta_fields() { //add_meta_box(表示される入力ボックスのHTMLのID, ラベル, 表示する内容を作成する関数名, 投稿タイプ, 表示方法) - $default_built_ins = array( - 'posts' => array( 'page', 'post', ), - ); - - foreach ( $default_built_ins['posts'] as $built_in ) { - add_meta_box( 'meta_setting', 'meta設定', array( $this, 'insert_meta_fields' ), $built_in, 'normal' ); - } - - if ( isset( $this->options['custom_posts'] ) ) { - foreach ( $this->options['custom_posts'] as $custom_post => $post_chk ) { - if ( $post_chk == 1 ) { - add_meta_box( 'meta_setting', 'meta設定', array( - $this, - 'insert_meta_fields' - ), $custom_post, 'normal' ); - } - } - } + $custom_posts = array_values(get_post_types(array('public' => true, '_builtin' => false))); + $target_posts = array_merge(array('page', 'post',), $custom_posts); + foreach ($target_posts as $target_post) { + add_meta_box( + 'meta_setting', + 'meta設定', + array( + $this, + 'insert_meta_fields'), + $target_post, + 'normal' + ); + } } // カスタムフィールドの入力エリア diff --git a/class/mtee_tax_setting.php b/class/mtee_tax_setting.php new file mode 100644 index 0000000..0aeecbd --- /dev/null +++ b/class/mtee_tax_setting.php @@ -0,0 +1,90 @@ +options = $options; + $this->set_fields(); + add_action('create_term', array($this, 'save_terms')); //新規追加用フック + add_action('edit_terms', array($this, 'save_terms')); //編集ページ用フック + } + + public function set_fields() { + $taxs = $this->set_tax_types(); + foreach ($taxs as $tax) { + add_action($tax . '_add_form_fields', array($this, 'insert_term_meta_add_fields')); + add_action($tax . '_edit_form_fields', array($this, 'insert_term_meta_edit_fields')); + } + } + + public function set_tax_types(): array { + $custom_tax = get_taxonomies(array('public' => true, '_builtin' => false)); + $tax_array = array_merge(array('category', 'post_tag'), $custom_tax); + $add_tax = filter_input(INPUT_GET, 'taxonomy'); + + if (!empty($add_tax)) { + return array_merge($tax_array, array($add_tax)); + } + return $tax_array; + } + + function insert_term_meta_add_fields($tag) { + $key_value = ''; + $desc_value = ''; + if (isset($tag->term_id)) { + $key_value = get_term_meta($tag->term_id, MTEE_NAME_KEYWORDS, true); + $desc_value = get_term_meta($tag->term_id, MTEE_MTEE_NAME_DESCRIPTION, true); + } + echo ' +
+meta keywords
+ +
+
+meta description
+ +
+'; + } + + function insert_term_meta_edit_fields($tag) { + $key_value = ''; + $desc_value = ''; + if (isset($tag->term_id)) { + $key_value = get_term_meta($tag->term_id, MTEE_NAME_KEYWORDS, true); + $desc_value = get_term_meta($tag->term_id, MTEE_NAME_DESCRIPTION, true); + } + echo ' + +meta keywords + + + +meta description + + +'; + } + + + function save_terms($term_id) { + if (array_key_exists(MTEE_NAME_KEYWORDS, $_POST)) { + update_term_meta($term_id, MTEE_NAME_KEYWORDS, $_POST[MTEE_NAME_KEYWORDS]); + } + if (array_key_exists(MTEE_NAME_DESCRIPTION, $_POST)) { + update_term_meta($term_id, MTEE_NAME_DESCRIPTION, $_POST[MTEE_NAME_DESCRIPTION]); + } + } + } + +} \ No newline at end of file diff --git a/class/mtee-version-setting.php b/class/mtee_version_setting.php similarity index 100% rename from class/mtee-version-setting.php rename to class/mtee_version_setting.php diff --git a/config.php b/config.php index 481ad2a..2cc6bbc 100644 --- a/config.php +++ b/config.php @@ -1,13 +1,15 @@ get_options(); // enabled my meta keywords, description if ($mtee->is_enable('enabled')) { - require_once MTEE_CLASS_DIR . 'mtee-tax-setting.php'; - require_once MTEE_CLASS_DIR . 'mtee-post-setting.php'; + require_once MTEE_CLASS_DIR . 'mtee_tax_setting.php'; + require_once MTEE_CLASS_DIR . 'mtee_post_setting.php'; require_once MTEE_CLASS_DIR . 'mtee_meta_output_keydesc.php'; new mtee_tax_setting($options); new mtee_post_setting($options); @@ -41,31 +41,31 @@ if ($mtee->is_enable('enabled')) { // enabled my canonical. caution : default canonical delete if ($mtee->is_enable('canonical_setting')) { remove_action('wp_head', 'rel_canonical'); - require_once MTEE_CLASS_DIR . 'mtee-canonical-setting.php'; - require_once MTEE_CLASS_DIR . 'mtee-output-canonical.php'; + require_once MTEE_CLASS_DIR . 'mtee_canonical_setting.php'; + require_once MTEE_CLASS_DIR . 'mtee_meta_output_canonical.php'; new mtee_canonical_setting($options); new mtee_meta_output_canonical(); } // enabled my OGP tag if ($mtee->is_enable('ogp_setting')) { - require_once MTEE_CLASS_DIR . 'mtee-ogp-setting.php'; - require_once MTEE_CLASS_DIR . 'mtee-output-ogp.php'; - new mtee_ogp_setting(); + require_once MTEE_CLASS_DIR . 'mtee_ogp_post_setting.php'; + require_once MTEE_CLASS_DIR . 'mtee_meta_output_ogp.php'; + new mtee_ogp_post_setting($options); new mtee_meta_output_ogp(); } //enabled my noindex, nofollow if ($mtee->is_enable('noindex_nofollow')) { - require_once MTEE_CLASS_DIR . 'mtee-noindexnofollow-setting.php'; - require_once MTEE_CLASS_DIR . 'mtee-output-noindexnofollow.php'; + require_once MTEE_CLASS_DIR . 'mtee_noindexnofolow_setting.php'; + require_once MTEE_CLASS_DIR . 'mtee_meta_output_noindexnofollow.php'; new mtee_noindexnofolow_setting($options); new mtee_meta_output_noindexnofollow(); } //disabled WP version, WP JS/CSS version if ($mtee->is_disable('asset_ver_disabled') || $mtee->is_disable('asset_ver_disabled')) { - require_once MTEE_CLASS_DIR . 'mtee-version-setting.php'; + require_once MTEE_CLASS_DIR . 'mtee_version_setting.php'; new mtee_version_setting($options); } diff --git a/template/index.php b/template/index.php index 2cde990..ae60a71 100644 --- a/template/index.php +++ b/template/index.php @@ -27,57 +27,6 @@ $asset_ver_disabled = $this->get_key_setting('asset_ver_disabled'); value="1">有効 - 0 || count($register_targets['taxonomies']) > 0): ?> - - 0): ?> - - - - - - 0): ?> - - - - - -
カスタム投稿 -
    - - -
  • - -
  • - -
-
カスタム分類 -
    - -
  • - - -
  • - -
-
-

meta keywords テンプレート設定 is_enable('enabled')): ?> From 0bc4ee1d2352e85e451f1b04ad97bf1d2259444c Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 30 May 2021 14:25:57 +0900 Subject: [PATCH 3/3] =?UTF-8?q?WP=20PLUGIN=20MTEE(Meta=20Tag=20etc=20Exten?= =?UTF-8?q?d)=20OGP=E8=A8=AD=E5=AE=9A=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ・OGP設定追加 --- class/mtee-ogp-setting.php | 52 --------------------- class/mtee_ogp_post_setting.php | 82 +++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 52 deletions(-) delete mode 100644 class/mtee-ogp-setting.php create mode 100644 class/mtee_ogp_post_setting.php diff --git a/class/mtee-ogp-setting.php b/class/mtee-ogp-setting.php deleted file mode 100644 index bcd5c3f..0000000 --- a/class/mtee-ogp-setting.php +++ /dev/null @@ -1,52 +0,0 @@ - array('page', 'post',), - ); - - foreach ($default_built_ins['posts'] as $built_in) { - add_meta_box( - 'canonical_setting', - 'Canonical設定', - array($this, 'insert_meta_fields'), - $built_in, - 'normal' - ); - } - - if (isset($this->options['custom_posts'])) { - foreach ($this->options['custom_posts'] as $custom_post => $post_chk) { - if ($post_chk == 1) { - add_meta_box( - 'canonical_setting', - 'Canonical設定', - array($this, 'insert_meta_fields'), - $custom_post, 'normal' - ); - } - } - } - } - - } - -} \ No newline at end of file diff --git a/class/mtee_ogp_post_setting.php b/class/mtee_ogp_post_setting.php new file mode 100644 index 0000000..5e3b8d4 --- /dev/null +++ b/class/mtee_ogp_post_setting.php @@ -0,0 +1,82 @@ +options = $options; + add_action('admin_menu', array($this, 'add_meta_fields')); + //画像をアップする場合は、multipart/form-dataの設定が必要なので、post_edit_form_tagをフックしてformタグに追加 + add_action('post_edit_form_tag', array($this, 'custom_meta_box_edit_form_tag')); + add_action('save_post', array($this, 'save_meta_fields')); + } + + public function custom_meta_box_edit_form_tag() { + echo ' enctype="multipart/form-data"'; + } + + //add_meta_box(表示される入力ボックスのHTMLのID, ラベル, 表示する内容を作成する関数名, 投稿タイプ, 表示方法) + public function add_meta_fields() { + $custom_posts = array_values(get_post_types(array('public' => true, '_builtin' => false))); + $target_posts = array_merge(array('page', 'post',), $custom_posts); + foreach ($target_posts as $target_post) { + add_meta_box( + 'ogp_setting', + 'OGP設定', + array( + $this, + 'insert_meta_fields'), + $target_post, + 'normal' + ); + } + } + + // カスタムフィールドの入力エリア + public function insert_meta_fields() { + global $post; + echo '
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
'; + } + + // カスタムフィールドの値を保存 + public function save_meta_fields($post_id) { + if (!empty($_POST[MTEE_OGP_TITLE])) { //meta_keywordsが入力されている場合 + update_post_meta($post_id, MTEE_OGP_TITLE, $_POST[MTEE_OGP_TITLE]); //値を保存 + } else { //未入力の場合は値を削除 + delete_post_meta($post_id, MTEE_OGP_TITLE); + } + if (!empty($_POST[MTEE_OGP_DESC])) { + update_post_meta($post_id, MTEE_OGP_DESC, $_POST[MTEE_OGP_DESC]); + } else { + delete_post_meta($post_id, MTEE_OGP_DESC); + } + } + } + +} \ No newline at end of file