diff --git a/class/mtee_canonical_setting.php b/class/mtee_canonical_setting.php index 6730c28..09f0efe 100644 --- a/class/mtee_canonical_setting.php +++ b/class/mtee_canonical_setting.php @@ -55,7 +55,9 @@ if (!class_exists('mtee_canonical_setting')) { echo '
'; } @@ -69,6 +71,15 @@ if (!class_exists('mtee_canonical_setting')) { } } + public function set_default_post_canonical_url($id) { + $canonical = get_permalink($id); + global $page, $paged; + if ($paged >= 2 || $page >= 2) { + $canonical .= 'page/' . max($paged, $page) . '/'; + } + return $canonical; + } + //------------------------------------------------------------------------------------------- // タクソノミーのカスタムフィールド設定 //------------------------------------------------------------------------------------------- @@ -108,13 +119,29 @@ if (!class_exists('mtee_canonical_setting')) { public function insert_term_meta_fields($tag, $form) { $canonical_url = ''; + $placeholder = ''; if (isset($tag->term_id)) { $canonical_url = get_term_meta($tag->term_id, MTEE_CANONICAL_URL, true); } - $add_meta = ''; + if (isset($tag->term_id) && empty($canonical_url)) { + $placeholder = $this->set_default_tax_canonical_url($tag->term_id, $tag->taxonomy); + } + $add_meta = ''; return str_replace('##CONTENTS##', $add_meta, $form); } + public function set_default_tax_canonical_url($id, $taxonomy) { + if ($taxonomy == 'category') { + $placeholder = get_category_link($id); + } elseif ($taxonomy == 'post_tag') { + $placeholder = get_tag_link($id); + } else { + $placeholder = get_term_link((int)$id); + } + return $placeholder; + } + public function save_terms($term_id) { if (array_key_exists(MTEE_CANONICAL_URL, $_POST)) { update_term_meta($term_id, MTEE_CANONICAL_URL, $_POST[MTEE_CANONICAL_URL]); diff --git a/class/mtee_meta_output_canonical.php b/class/mtee_meta_output_canonical.php index 34d104a..e5c7116 100644 --- a/class/mtee_meta_output_canonical.php +++ b/class/mtee_meta_output_canonical.php @@ -115,7 +115,7 @@ if (!class_exists('mtee_meta_output_canonical')) { public function set_tax_canonical($id) { $canonical = get_term_meta($id, MTEE_CANONICAL_URL, true); if (empty($canonical)) { - $canonical = get_term_link($id); + $canonical = get_term_link((int)$id); } return $canonical; } diff --git a/class/mtee_meta_output_keydesc.php b/class/mtee_meta_output_keydesc.php index 1a7bbd8..e775ba4 100644 --- a/class/mtee_meta_output_keydesc.php +++ b/class/mtee_meta_output_keydesc.php @@ -126,7 +126,7 @@ if (!class_exists('mtee_meta_output_keydesc')) { } } - public function create_default_keywords() { + public function create_default_keywords(): array { $type = ''; $title = ''; if (is_category()) { @@ -158,7 +158,7 @@ if (!class_exists('mtee_meta_output_keydesc')) { } - public function get_keywords_data($type, $keyword) { + public function get_keywords_data($type, $keyword): array { $keywords = array(); $keywords[] = $this->site_name; //サイトタイトル if (!empty(get_bloginfo('description'))) { @@ -172,7 +172,7 @@ if (!class_exists('mtee_meta_output_keydesc')) { return array_reverse($keywords); } - public function get_custom_template_keywords_data($custom_keywords_temp, $type, $title) { + public function get_custom_template_keywords_data($custom_keywords_temp, $type, $title): array { $targets = explode(',', $custom_keywords_temp[$type]); $keywords = array(); foreach ($targets as $target) { diff --git a/class/mtee_post_setting.php b/class/mtee_post_setting.php index 89e26ca..ca30761 100644 --- a/class/mtee_post_setting.php +++ b/class/mtee_post_setting.php @@ -1,29 +1,28 @@ options = $options; - if ( $this->options['enabled'] == 1 ) { - add_action( 'admin_menu', array( $this, 'add_meta_fields' ) ); - add_action( 'save_post', array( $this, 'save_meta_fields' ) ); - } - } + public function __construct($options) { + $this->options = $options; + if ($this->options['enabled'] == 1) { + add_action('admin_menu', array($this, 'add_meta_fields')); + add_action('save_post', array($this, 'save_meta_fields')); + } + } - public function add_meta_fields() { - //add_meta_box(表示される入力ボックスのHTMLのID, ラベル, 表示する内容を作成する関数名, 投稿タイプ, 表示方法) - $custom_posts = array_values(get_post_types(array('public' => true, '_builtin' => false))); - $target_posts = array_merge(array('page', 'post',), $custom_posts); + public function add_meta_fields() { + //add_meta_box(表示される入力ボックスのHTMLのID, ラベル, 表示する内容を作成する関数名, 投稿タイプ, 表示方法) + $target_posts = $this->get_all_post_type(); foreach ($target_posts as $target_post) { add_meta_box( 'meta_setting', @@ -35,34 +34,66 @@ if ( ! class_exists( 'mtee_post_setting' ) ) { 'normal' ); } - } + } - // カスタムフィールドの入力エリア - public function insert_meta_fields() { - global $post; - echo '