diff --git a/class/mtee-canonical-setting.php b/class/mtee-canonical-setting.php
new file mode 100644
index 0000000..dfd9391
--- /dev/null
+++ b/class/mtee-canonical-setting.php
@@ -0,0 +1,139 @@
+options = $options;
+ if ($this->options['canonical_setting'] == 1) {
+ //Posts
+ add_action('admin_menu', array($this, 'add_meta_fields'));
+ add_action('save_post', array($this, 'save_meta_fields'));
+
+ //Taxonomy
+ $this->set_tax_meta_box(); //各投稿画面
+ add_action('create_term', array($this, 'save_terms')); //新規追加用フック
+ add_action('edit_terms', array($this, 'save_terms')); //編集ページ用フック
+
+ }
+ }
+
+ //-------------------------------------------------------------------------------------------
+ // 投稿、ページのカスタムフィールド設定
+ //-------------------------------------------------------------------------------------------
+ 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(
+ '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'
+ );
+ }
+ }
+ }
+ }
+
+ // カスタムフィールドの入力エリア
+ public function insert_meta_fields() {
+ global $post;
+ echo '
@@ -212,25 +230,38 @@ $noindex_nofollow = $this->get_noindex_nofollow();
$description = $opt['top_page']['description'] ?? '';
$noindex = $opt['top_page']['noindex'] ?? '0';
$nofollow = $opt['top_page']['nofollow'] ?? '0';
+ $canonical_url = $opt['top_page']['canonical'] ?? '';
?>
0): ?>
@@ -260,6 +302,7 @@ $noindex_nofollow = $this->get_noindex_nofollow();
$description = $opt['custom_post'][$custom_post]['description'] ?? '';
$noindex = $opt['custom_post'][$custom_post]['noindex'] ?? '0';
$nofollow = $opt['custom_post'][$custom_post]['nofollow'] ?? '0';
+ $canonical_url = $opt['custom_post'][$custom_post]['canonical'] ?? '0';
?>
diff --git a/trait/output_canonical.php b/trait/output_canonical.php
new file mode 100644
index 0000000..8207140
--- /dev/null
+++ b/trait/output_canonical.php
@@ -0,0 +1,87 @@
+set_top_page_canonical();
+ } elseif ($type == 'custom_post_archive') {
+ $canonical = $this->set_custom_post_archive_canonical();
+ } elseif ($type == 'posts') {
+ $canonical = $this->set_post_canonical($id);
+ } elseif ($type == 'cat') {
+ $canonical = $this->set_category_canonical($id);
+ } elseif ($type == 'tag') {
+ $canonical = $this->set_tag_canonical($id);
+ } elseif ($type == 'tax') {
+ $canonical = $this->set_tax_canonical($id);
+ }
+
+ if ($canonical) {
+ return '
' . PHP_EOL;
+ }
+ }
+
+ public function set_top_page_canonical() {
+ $canonical = get_option('_mtee')['top_page']['canonical'];
+ if (empty($canonical)) {
+ $canonical = get_bloginfo('url');
+ }
+ return $canonical;
+ }
+
+ public function set_custom_post_archive_canonical() {
+ $custom_post_name = get_post_type_object(get_post_type())->name;
+ $canonical = get_option('_mtee')['custom_post'][$custom_post_name]['canonical'];
+ if (empty($canonical)) {
+ $canonical = get_post_type_archive_link($custom_post_name);
+ }
+ return $canonical;
+ }
+
+ public function set_post_canonical($id) {
+ $canonical = get_post_meta($id, MTEE_CANONICAL_URL, true);
+ if (empty($canonical)) {
+ $canonical = get_permalink($id);
+ global $page, $paged;
+ if ($paged >= 2 || $page >= 2) {
+ $canonical .= 'page/' . max($paged, $page) . '/';
+ }
+ }
+ return $canonical;
+ }
+
+ public function set_category_canonical($id) {
+ $canonical = get_term_meta($id, MTEE_CANONICAL_URL, true);
+ if (empty($canonical)) {
+ $canonical = get_category_link($id);
+ }
+ return $canonical;
+ }
+
+ public function set_tag_canonical($id) {
+ $canonical = get_term_meta($id, MTEE_CANONICAL_URL, true);
+ if (empty($canonical)) {
+ $canonical = get_tag_link($id);
+ }
+ return $canonical;
+ }
+
+ public function set_tax_canonical($id) {
+ $canonical = get_term_meta($id, MTEE_CANONICAL_URL, true);
+ if (empty($canonical)) {
+ $canonical = get_term_link($id);
+ }
+ return $canonical;
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/trait/output_keyword_trait.php b/trait/output_keyword_trait.php
new file mode 100644
index 0000000..c54d7ba
--- /dev/null
+++ b/trait/output_keyword_trait.php
@@ -0,0 +1,152 @@
+get_keywords_data($type, $title);
+ }
+
+ return $this->get_custom_template_keywords_data($custom_keywords_temp, $type, $title);
+
+ }
+
+ public function get_keywords_data($type, $keyword) {
+ $keywords = array();
+ $keywords[] = $this->site_name; //サイトタイトル
+ if (!empty(get_bloginfo('description'))) {
+ $keywords[] = get_bloginfo('description'); //サイトタイトル
+ }
+ if ($type == 'post') {
+ $this->get_single_keywords_tax($keywords);
+ } else {
+ $keywords[] = $keyword;
+ }
+ return array_reverse($keywords);
+ }
+
+ public function get_custom_template_keywords_data($custom_keywords_temp, $type, $title) {
+ $targets = explode(',', $custom_keywords_temp[$type]);
+ $keywords = array();
+ foreach ($targets as $target) {
+ switch ($target) {
+ case '##title##':
+ $keywords[] = $title;
+ break;
+ case '##site_name##':
+ $keywords[] = $this->site_name;
+ break;
+ case '##site_description##':
+ $keywords[] = get_bloginfo('description');
+ break;
+ case '##category##':
+ $this->get_custom_template_single_keywords($keywords, 'category');
+ break;
+ case '##tag##':
+ $this->get_custom_template_single_keywords($keywords, 'post_tag');
+ break;
+ case '##custom_tax##':
+ $this->get_custom_template_single_keywords($keywords, 'custom_tax');
+ break;
+ }
+ }
+ return $keywords;
+ }
+
+ public function get_custom_template_single_keywords(&$keywords, $type) {
+ global $post;
+ $taxonomies = $this->get_single_keyword_tax_data();
+ if ($type == 'custom_tax') {
+ foreach ($taxonomies as $target) {
+ if ($target != 'post_format' && $target != 'category' && $target != 'post_tag') {
+ $this->get_custom_keywords_terms($keywords, $post->ID, $target);
+ }
+ }
+ } else {
+ foreach ($taxonomies as $target) {
+ if ($target == $type) {
+ $this->get_custom_keywords_terms($keywords, $post->ID, $target);
+ }
+ }
+ }
+ }
+
+ public function get_single_keywords_tax(&$keywords) {
+ global $post;
+ $taxonomies = $this->get_single_keyword_tax_data();
+ foreach ($taxonomies as $target) {
+ if ($target != 'post_format') {
+ $this->get_custom_keywords_terms($keywords, $post->ID, $target);
+ }
+ }
+ }
+
+ public function get_single_keyword_tax_data(): array {
+ global $post;
+ return array_reverse(get_object_taxonomies(get_post_type($post->ID)));
+ }
+
+ public function get_custom_keywords_terms(&$keywords, $id, $target) {
+ $terms = get_the_terms($id, $target);
+ if ($terms) {
+ foreach ($terms as $term) {
+ $keywords[] = $term->name;
+ }
+ }
+ }
+
+ public 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;
+ }
+
+ public function cnv_custom_template($type, $title, $suffix_text) {
+ if ($type == 'custom_post') {
+ return array('org' => array(post_type_archive_title('', false), $suffix_text));
+ }
+
+ $template = get_option('_mtee')['description_tmp'];
+ if (isset($template[$type]) && !empty($template[$type])) {
+ $search = array('##title##', '##site_name##', '##site_description##');
+ $replacement = array($title, get_bloginfo('name'), get_bloginfo('description'));
+ $this->description = str_replace($search, $replacement, $template[$type]);
+ } else {
+ return array('org' => array($title, $suffix_text));
+ }
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/trait/output_noindexnofollow_trait.php b/trait/output_noindexnofollow_trait.php
new file mode 100644
index 0000000..760b750
--- /dev/null
+++ b/trait/output_noindexnofollow_trait.php
@@ -0,0 +1,56 @@
+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 '
';
+ }
+ }
+
+ public 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 == 'custom_post_archive') {
+ $custom_post_name = get_post_type_object(get_post_type())->name;
+ $noindex = get_option('_mtee')['custom_post'][$custom_post_name]['noindex'];
+ $nofollow = get_option('_mtee')['custom_post'][$custom_post_name]['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,
+ );
+ }
+
+ }
+
+}
\ No newline at end of file