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_ogp_post_setting.php b/class/mtee_ogp_post_setting.php index 5e3b8d4..7179419 100644 --- a/class/mtee_ogp_post_setting.php +++ b/class/mtee_ogp_post_setting.php @@ -15,7 +15,7 @@ if (!class_exists('mtee_ogp_post_setting')) { public function __construct($options) { $this->options = $options; add_action('admin_menu', array($this, 'add_meta_fields')); - //画像をアップする場合は、multipart/form-dataの設定が必要なので、post_edit_form_tagをフックしてformタグに追加 + //post_edit_form_tagをフックしてformタグにmultipart/form-data属性を追加 add_action('post_edit_form_tag', array($this, 'custom_meta_box_edit_form_tag')); add_action('save_post', array($this, 'save_meta_fields')); } @@ -47,23 +47,48 @@ if (!class_exists('mtee_ogp_post_setting')) { echo ' '; } + + public function set_default_ogp_title() { + return get_the_title(); + } + + public function set_default_ogp_desc(): string { + return get_bloginfo('name') . 'の' . $this->set_default_ogp_title() . 'です。'; + } + + + public function set_ogp_thumb($id): string { + $ogp_thumb = get_post_meta($id, MTEE_OGP_IMG, true); + if (!empty($ogp_thumb)) { + return '' . $this->set_ogp_thumb($tag->term_id) . '
+