diff --git a/class/mtee-output.php b/class/mtee-output.php index ca9907c..8bfba48 100644 --- a/class/mtee-output.php +++ b/class/mtee-output.php @@ -1,202 +1,214 @@ site_name = get_bloginfo( 'name' ); - $this->description = $this->site_name . MTEE_META_DESC_PARTICLE; - add_action( 'wp_head', array( $this, 'post_output_add_metas' ) ); - add_action( 'wp_head', array( $this, 'set_noindex_nofollow' ) ); - } + public function __construct() { + $this->site_name = get_bloginfo('name'); + $this->description = $this->site_name . MTEE_META_DESC_PARTICLE; + add_action('wp_head', array($this, 'post_output_add_metas')); + add_action('wp_head', array($this, 'set_noindex_nofollow')); + } - //-------------------------------------------------------------------- - // meta keywords & meta description - //-------------------------------------------------------------------- - public function post_output_add_metas() { - $metas = []; - if ( is_tax() ) { - $metas = $this->post_output_view_metas( get_queried_object()->taxonomy ); - } elseif ( is_page() || is_single() ) { - $metas = $this->post_output_view_metas( get_post_type() ); - } elseif ( is_category() ) { - $metas = $this->post_output_view_metas( 'category' ); - } elseif ( is_tag() ) { - $metas = $this->post_output_view_metas( 'post_tag' ); - } - if ( count( $metas ) == 0 ) { - $metas = $this->create_default_keywords_description(); - } - echo implode( PHP_EOL, $metas ) . PHP_EOL; - } + //-------------------------------------------------------------------- + // meta keywords & meta description + //-------------------------------------------------------------------- + public function post_output_add_metas() { + $metas = array(); + if (is_home() || is_front_page()) { + $metas = $this->post_output_view_metas('top_page'); + } elseif (is_tax()) { + $metas = $this->post_output_view_metas(get_queried_object()->taxonomy); + } elseif (is_page() || is_single()) { + $metas = $this->post_output_view_metas(get_post_type()); + } elseif (is_category()) { + $metas = $this->post_output_view_metas('category'); + } elseif (is_tag()) { + $metas = $this->post_output_view_metas('post_tag'); + } + if (count($metas) == 0) { + $metas = $this->create_default_keywords_description(); + } - private function post_output_view_metas( $type ): array { - $targets = get_option( '_mtee' ); - if ( isset( $targets['custom_posts'] ) && array_key_exists( $type, $targets['custom_posts'] ) ) { - $type = 'custom_post'; - } elseif ( isset( $targets['taxonomies'] ) && array_key_exists( $type, $targets['taxonomies'] ) ) { - $type = 'custom_tax'; - } + echo implode(PHP_EOL, $metas) . PHP_EOL; + } - $meta_data = $this->post_output_get_meta_data( $type ); + private function post_output_view_metas($type): array { + $targets = get_option('_mtee'); + if (isset($targets['custom_posts']) && array_key_exists($type, $targets['custom_posts'])) { + $type = 'custom_post'; + } elseif (isset($targets['taxonomies']) && array_key_exists($type, $targets['taxonomies'])) { + $type = 'custom_tax'; + } - return $this->create_meta_tags( $meta_data ); - } + $meta_data = $this->post_output_get_meta_data($type); + return $this->create_meta_tags($meta_data); + } - private function post_output_get_meta_data( $type ): array { - global $post; - if ( $type == 'custom_tax' || $type == 'category' || $type == 'post_tag' ) { - $queried_object = get_queried_object(); - $meta_key_words = get_term_meta( $queried_object->term_id, MTEE_NAME_KEYWORDS, true ); - $meta_description = get_term_meta( $queried_object->term_id, MTEE_NAME_DESCRIPTION, true ); - } else { - $meta_key_words = get_post_meta( $post->ID, MTEE_NAME_KEYWORDS, true ); - $meta_description = get_post_meta( $post->ID, MTEE_NAME_DESCRIPTION, true ); - } + private function post_output_get_meta_data($type): array { + global $post; + if ($type == 'top_page') { + $meta_key_words = get_option('_mtee')['top_page']['keywords']; + $meta_description = get_option('_mtee')['top_page']['description']; + } elseif ($type == 'custom_tax' || $type == 'category' || $type == 'post_tag') { + $queried_object = get_queried_object(); + $meta_key_words = get_term_meta($queried_object->term_id, MTEE_NAME_KEYWORDS, true); + $meta_description = get_term_meta($queried_object->term_id, MTEE_NAME_DESCRIPTION, true); + } else { + $meta_key_words = get_post_meta($post->ID, MTEE_NAME_KEYWORDS, true); + $meta_description = get_post_meta($post->ID, MTEE_NAME_DESCRIPTION, true); + } - return [ - MTEE_NAME_KEYWORDS => $meta_key_words, - MTEE_NAME_DESCRIPTION => $meta_description, - ]; - } + return array( + MTEE_NAME_KEYWORDS => $meta_key_words, + MTEE_NAME_DESCRIPTION => $meta_description, + ); + } - private function create_meta_tags( $meta_data ): array { - $metas = []; - if ( ! empty( $meta_data[ MTEE_NAME_KEYWORDS ] ) ) { - $metas[] = str_replace( '##KEYWORDS##', $meta_data[ MTEE_NAME_KEYWORDS ], '' ); - } - if ( ! empty( $meta_data[ MTEE_NAME_DESCRIPTION ] ) ) { - $metas[] = str_replace( '##DISCRIPTION##', $meta_data[ MTEE_NAME_DESCRIPTION ], '' ); - } + private function create_meta_tags($meta_data): array { + $metas = array(); + if (!empty($meta_data[MTEE_NAME_KEYWORDS])) { + $metas[] = str_replace('##KEYWORDS##', $meta_data[MTEE_NAME_KEYWORDS], ''); + } + if (!empty($meta_data[MTEE_NAME_DESCRIPTION])) { + $metas[] = str_replace('##DISCRIPTION##', $meta_data[MTEE_NAME_DESCRIPTION], ''); + } + return $metas; + } - return $metas; - } + public function create_default_keywords_description(): array { + $keywords[] = $this->site_name; //サイトタイトル + if (!empty(get_bloginfo('description'))) { + $keywords[] = get_bloginfo('description'); //サイトタイトル + } - public function create_default_keywords_description(): array { - $keywords[] = $this->site_name; //サイトタイトル - if ( ! empty( get_bloginfo( 'description' ) ) ) { - $keywords[] = get_bloginfo( 'description' ); //サイトタイトル - } + $this->createKeywords($keywords); + $this->createDescription(); - $this->createKeywords( $keywords ); - $this->createDescription(); + $meta_data = array( + MTEE_NAME_KEYWORDS => implode(',', array_reverse($keywords)), + MTEE_NAME_DESCRIPTION => $this->description, + ); - $meta_data = [ - MTEE_NAME_KEYWORDS => implode( ',', array_reverse( $keywords ) ), - MTEE_NAME_DESCRIPTION => $this->description, - ]; + return $this->create_meta_tags($meta_data); + } - return $this->create_meta_tags( $meta_data ); - } + private function createKeywords(&$keywords) { + if (is_category() || is_tag()) { + $keywords[] = single_cat_title('', false); + } elseif (is_tax()) { + $keywords[] = single_term_title('', false); + } elseif (is_post_type_archive()) { + $keywords[] = post_type_archive_title('', false); + } else { + $keywords[] = get_the_title(); + } + } - private function createKeywords( &$keywords ) { - if ( is_category() || is_tag() ) { - $keywords[] = single_cat_title( '', false ); - } elseif ( is_tax() ) { - $keywords[] = single_term_title( '', false ); - } elseif ( is_post_type_archive() ) { - $keywords[] = post_type_archive_title( '', false ); - } else { - $keywords[] = get_the_title(); - } - } + private function createDescription() { + if (is_home() || is_front_page()) { //ページ + $this->description .= MTEE_META_DESC_TOP_BASE; + } elseif (is_page() || is_single()) { //ページ + $replacement = array(get_the_title(), MTEE_META_DESC_SINGLE_BASE); + } elseif (is_category()) { //カテゴリー + $replacement = array(single_cat_title('', false), MTEE_META_DESC_ARCHIVE_BASE); + } elseif (is_tag()) { //タグ + $replacement = array(single_tag_title('', false), MTEE_META_DESC_ARCHIVE_BASE); + } elseif (is_tax()) { //タクソノミー + $replacement = array(single_term_title('', false), MTEE_META_DESC_ARCHIVE_BASE); + } elseif (is_post_type_archive()) { //カスタム投稿のアーカイブ + $replacement = array(post_type_archive_title('', false), MTEE_META_DESC_ARCHIVE_BASE); + } - private function createDescription() { - if ( is_home() || is_front_page() ) { //ページ - $this->description .= MTEE_META_DESC_TOP_BASE; - } + if (isset($replacement)) { + $search = array('<###>', '<%%%>'); + $description_noun = MTEE_META_DESC_BEFORE_BRACKETS . '<###>' . MTEE_META_DESC_AFTER_BRACKETS . '<%%%>'; + $this->description .= str_replace($search, $replacement, $description_noun); + } + } - if ( is_page() || is_single() ) { //ページ - $replacement = array( get_the_title(), MTEE_META_DESC_SINGLE_BASE ); - } elseif ( is_category() ) { //カテゴリー - $replacement = array( single_cat_title( '', false ), MTEE_META_DESC_ARCHIVE_BASE ); - } elseif ( is_tag() ) { //タグ - $replacement = array( single_tag_title( '', false ), MTEE_META_DESC_ARCHIVE_BASE ); - } elseif ( is_tax() ) { //タクソノミー - $replacement = array( single_term_title( '', false ), MTEE_META_DESC_ARCHIVE_BASE ); - } elseif ( is_post_type_archive() ) { //カスタム投稿のアーカイブ - $replacement = array( post_type_archive_title( '', false ), MTEE_META_DESC_ARCHIVE_BASE ); - } + //-------------------------------------------------------------------- + // noindex, nofollow + //-------------------------------------------------------------------- + public function set_noindex_nofollow() { + global $post; + $type = ''; + if (is_category()) { + $id = get_query_var('cat'); + $type = 'tax'; + } elseif (is_tag()) { + $id = get_query_var('tag_id'); + $type = 'tax'; + } elseif (is_tax()) { + $id = get_queried_object()->term_id; + $type = 'tax'; + } elseif (is_home() || is_front_page()) { + $id = null; + $type = 'top_page'; + } elseif (is_page() || is_single()) { + $id = $post->ID; + $type = 'posts'; + } - if ( isset( $replacement ) ) { - $search = array( '<###>', '<%%%>' ); - $description_noun = MTEE_META_DESC_BEFORE_BRACKETS . '<###>' . MTEE_META_DESC_AFTER_BRACKETS . '<%%%>'; - $this->description .= str_replace( $search, $replacement, $description_noun ); - } - } + echo $this->get_noindex_nofollow_data($id, $type); - //-------------------------------------------------------------------- - // noindex, nofollow - //-------------------------------------------------------------------- - public function set_noindex_nofollow() { - global $post; - $type = ''; - if ( is_category() ) { - $id = get_query_var( 'cat' ); - $type = 'tax'; - } elseif ( is_tag() ) { - $id = get_query_var( 'tag_id' ); - $type = 'tax'; - } elseif ( is_tax() ) { - $id = get_queried_object()->term_id; - $type = 'tax'; - } elseif ( is_home() || is_front_page() || is_page() || is_single() ) { - $id = $post->ID; - $type = 'posts'; - } + } - echo $this->get_noindex_nofollow_data( $id, $type ); + private function get_noindex_nofollow_data($id, $type) { + if (empty($type)) { + return; + } - } + $status = $this->get_noindex_nofollow_stauts($type, $id); - private function get_noindex_nofollow_data( $id, $type ) { - if ( empty( $type ) ) { - return; - } - $status = $this->get_noindex_nofollow_stauts( $type, $id ); - if ( $status['noindex'] == '0' && $status['nofollow'] == '0' ) { - return; - } - if ( $status['noindex'] == '1' && $status['nofollow'] == '1' ) { - return ''; - } - if ( $status['noindex'] == '1' && $status['nofollow'] == '0' ) { - return ''; - } - if ( $status['noindex'] == '0' && $status['nofollow'] == '1' ) { - return ''; - } - } + if ($status['noindex'] == '0' && $status['nofollow'] == '0') { + return; + } + if ($status['noindex'] == '1' && $status['nofollow'] == '1') { + return ''; + } + if ($status['noindex'] == '1' && $status['nofollow'] == '0') { + return ''; + } + if ($status['noindex'] == '0' && $status['nofollow'] == '1') { + return ''; + } + } - private function get_noindex_nofollow_stauts( $type, $id ) { - if ( $type == 'posts' ) { - $noindex = get_post_meta( $id, MTEE_NAME_NOINDEX, true ); - $nofollow = get_post_meta( $id, MTEE_NAME_NOFOLLOW, true ); - } elseif ( $type == 'tax' ) { - $noindex = get_term_meta( $id, MTEE_NAME_NOINDEX, true ); - $nofollow = get_term_meta( $id, MTEE_NAME_NOFOLLOW, true ); - } + private function get_noindex_nofollow_stauts($type, $id): array { + $noindex = 0; + $nofollow = 0; + if ($type == 'top_page') { + $noindex = get_option('_mtee')['top_page']['noindex']; + $nofollow = get_option('_mtee')['top_page']['nofollow']; + } elseif ($type == 'posts') { + $noindex = get_post_meta($id, MTEE_NAME_NOINDEX, true); + $nofollow = get_post_meta($id, MTEE_NAME_NOFOLLOW, true); + } elseif ($type == 'tax') { + $noindex = get_term_meta($id, MTEE_NAME_NOINDEX, true); + $nofollow = get_term_meta($id, MTEE_NAME_NOFOLLOW, true); + } - return array( - 'noindex' => $noindex, - 'nofollow' => $nofollow, - ); - } + return array( + 'noindex' => $noindex, + 'nofollow' => $nofollow, + ); + } - } + } } \ No newline at end of file diff --git a/class/mtee.php b/class/mtee.php index 544ba14..13eb56d 100644 --- a/class/mtee.php +++ b/class/mtee.php @@ -1,121 +1,157 @@ true, '_builtin' => false ) ); - $taxonomies = get_taxonomies( array( 'public' => true, '_builtin' => false ) ); + public function show_option_page() { + //$_POST['_mtee'])があったら保存 + if (isset($_POST['_mtee'])) { + check_admin_referer('check_options'); + $opt = $_POST['_mtee']; + update_option('_mtee', $opt); + require_once MTEE_TEMPLATE_DIR . 'success.php'; + } + require_once MTEE_TEMPLATE_DIR . 'index.php'; + } - return [ - 'custom_posts' => $custom_posts, - 'taxonomies' => $taxonomies, - ]; - } + public function pages_setting() { + //$_POST['_mtee'])があったら保存 + if (isset($_POST['_mtee'])) { + check_admin_referer('check_options'); + $opt = $_POST['_mtee']; + update_option('_mtee', $opt); + require_once MTEE_TEMPLATE_DIR . 'success.php'; + } + require_once MTEE_TEMPLATE_DIR . 'pages.php'; + } - public function get_options() { - return get_option( '_mtee' ); - } + public static function register_target(): array { + $custom_posts = get_post_types(array('public' => true, '_builtin' => false)); + $taxonomies = get_taxonomies(array('public' => true, '_builtin' => false)); - public function is_enable(): bool { - if ( $this->get_options()['enabled'] == 1 ) { - return true; - } + return [ + 'custom_posts' => $custom_posts, + 'taxonomies' => $taxonomies, + ]; + } - return false; - } + public function get_options() { + return get_option('_mtee'); + } - public function is_wp_ver_disable(): bool { - if ( $this->get_options()['wp_ver_disabled'] == 1 ) { - return true; - } + public function is_enable(): bool { + if (isset($this->get_options()['enabled']) + && $this->get_options()['enabled'] == 1) { + return true; + } - return false; - } + return false; + } - public function is_asset_ver_disable(): bool { - if ( $this->get_options()['asset_ver_disabled'] == 1 ) { - return true; - } + public function is_wp_ver_disable(): bool { + if (isset($this->get_options()['wp_ver_disabled']) + && $this->get_options()['wp_ver_disabled'] == 1) { + return true; + } - return false; - } + return false; + } - public function is_noindex_nofollow_disable(): bool { - if ( $this->get_options()['noindex_nofollow'] == '1' ) { - return true; - } + public function is_asset_ver_disable(): bool { + if (isset($this->get_options()['asset_ver_disabled']) + && $this->get_options()['asset_ver_disabled'] == 1) { + return true; + } - return false; - } + return false; + } - public function get_key_desc_status(): int { - if ( isset( $this->get_options()['enabled'] ) && $this->get_options()['enabled'] == '1' ) { - return 1; - } else { - return 0; - } - } + public function is_noindex_nofollow_disable(): bool { + if (isset($this->get_options()['noindex_nofollow']) + && $this->get_options()['noindex_nofollow'] == '1') { + return true; + } - public function get_wp_ver_disabled(): int { - if ( isset( $this->get_options()['wp_ver_disabled'] ) && $this->get_options()['wp_ver_disabled'] == '1' ) { - return 1; - } else { - return 0; - } - } + return false; + } - public function get_asset_ver_disabled(): int { - if ( isset( $this->get_options()['asset_ver_disabled'] ) && $this->get_options()['asset_ver_disabled'] == '1' ) { - return 1; - } else { - return 0; - } - } + public function get_key_desc_status(): int { + if (isset($this->get_options()['enabled']) + && $this->get_options()['enabled'] == '1') { + return 1; + } else { + return 0; + } + } - public function get_noindex_nofollow(): int { - if ( isset( $this->get_options()['noindex_nofollow'] ) && $this->get_options()['noindex_nofollow'] == '1' ) { - return 1; - } else { - return 0; - } - } + public function get_wp_ver_disabled(): int { + if (isset($this->get_options()['wp_ver_disabled']) + && $this->get_options()['wp_ver_disabled'] == '1') { + return 1; + } else { + return 0; + } + } - } + public function get_asset_ver_disabled(): int { + if (isset($this->get_options()['asset_ver_disabled']) + && $this->get_options()['asset_ver_disabled'] == '1') { + return 1; + } else { + return 0; + } + } + + public function get_noindex_nofollow(): int { + if (isset($this->get_options()['noindex_nofollow']) + && $this->get_options()['noindex_nofollow'] == '1') { + return 1; + } else { + return 0; + } + } + + } } diff --git a/css/mtee.css b/css/mtee.css index 81cad78..7a0934d 100644 --- a/css/mtee.css +++ b/css/mtee.css @@ -41,4 +41,9 @@ h2 { .meta_noindex_nofollow_box label { width: 8em; +} + +.top_page_keywords, +.top_page_description { + width: 95%; } \ No newline at end of file diff --git a/meta-tag-etc-extend.php b/meta-tag-etc-extend.php index 143950e..1d082e4 100644 --- a/meta-tag-etc-extend.php +++ b/meta-tag-etc-extend.php @@ -6,6 +6,20 @@ Author: Nob Kim Version: 1.0 */ +/* +Todo:meta keywords & description +・デスクリプションの雛形登録 +・カスタム投稿アーカイブページ追加 + +Todo:OGPタグ +・OGPタグを追加する +<各OGP画像の保存> +・投稿のOGP用画像 => post_meta +・各タクソノミーのOGP画像 => term_meta +・トップ、カスタム投稿アーカイブ => wp_options + +*/ + include_once 'config.php'; include_once MTEE_CLASS_DIR . 'mtee.php'; diff --git a/template/top.php b/template/index.php similarity index 69% rename from template/top.php rename to template/index.php index c48789e..50adc3e 100644 --- a/template/top.php +++ b/template/index.php @@ -1,90 +1,91 @@ get_key_desc_status(); -$wp_ver_disabled = $this->get_wp_ver_disabled(); +$register_targets = MTEE::register_target(); +$opt = get_option('_mtee'); +$enabled = $this->get_key_desc_status(); +$wp_ver_disabled = $this->get_wp_ver_disabled(); $asset_ver_disabled = $this->get_asset_ver_disabled(); $noindex_nofollow = $this->get_noindex_nofollow(); ?>
-

meta keyword, description / バージョン情報 設定

- +

キーワード・ディスクリプション

- 0 || count( $register_targets['taxonomies'] ) > 0 ): ?> + 0 || count($register_targets['taxonomies']) > 0): ?> - 0 ): ?> + 0): ?> - - 0 ): ?> + + 0): ?> - +
カスタム投稿
    - + +
  • - +
カスタム分類
    - +
  • +
  • - +
- + @@ -93,7 +94,7 @@ $noindex_nofollow = $this->get_noindex_nofollow();
@@ -102,7 +103,7 @@ $noindex_nofollow = $this->get_noindex_nofollow(); @@ -111,7 +112,7 @@ $noindex_nofollow = $this->get_noindex_nofollow(); diff --git a/template/pages.php b/template/pages.php new file mode 100644 index 0000000..01fe18c --- /dev/null +++ b/template/pages.php @@ -0,0 +1,61 @@ + +
+

meta keyword, description / ページ設定

+ is_enable()): ?> + + + +
+

トップページ

+ + + + + + + + + + + + + +
meta keywords +
キーワードはカンマ(,)区切りで入力してください +
meta description +
noindex nofollow +
+ + +
+
+
+

+ + + +

全体設定を有効にしてください

+ +
\ No newline at end of file