Compare commits

...

3 Commits

Author SHA1 Message Date
nobu 2a28508124 Merge pull request '新規追加_OGP設定' (#11) from 新規追加_OGP設定 into master
Reviewed-on: https://develop.n-k-y.net/repo/WP_PLUGIN/Meta_Tag_etc_Extend/pulls/11
2021-05-30 19:40:07 +09:00
nobu 0a00caef21 WP PLUGIN MTEE(Meta Tag etc Extend) OGPタグ設定
・タクソノミーのOGPタグ設定
・画像アップロード機能の追加
2021-05-30 19:39:00 +09:00
nobu 68b0326e63 WP PLUGIN MTEE(Meta Tag etc Extend) キーワード、カノニカルのplaceholder設定
・各投稿、各タームでキーワード、ディスクリプション、カノニカルのデフォルト設定値をplaceholderに埋め込み
2021-05-30 17:38:42 +09:00
8 changed files with 476 additions and 70 deletions
+29 -2
View File
@@ -55,7 +55,9 @@ if (!class_exists('mtee_canonical_setting')) {
echo '<div class="meta_key_desc_box">
<label style="font-weight: bold; display: block">Canonical URL</label>
<div>
<input style="width:100%" type="text" name="' . MTEE_CANONICAL_URL . '" value="' . get_post_meta($post->ID, MTEE_CANONICAL_URL, true) . '"/>
<input style="width:100%" type="text" name="' . MTEE_CANONICAL_URL . '"
value="' . get_post_meta($post->ID, MTEE_CANONICAL_URL, true) . '"
placeholder="' . $this->set_default_post_canonical_url($post->ID) . '" />
</div>
</div>';
}
@@ -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 = '<input type="text" name="' . MTEE_CANONICAL_URL . '" value="' . $canonical_url . '"/>';
if (isset($tag->term_id) && empty($canonical_url)) {
$placeholder = $this->set_default_tax_canonical_url($tag->term_id, $tag->taxonomy);
}
$add_meta = '<input type="text" name="' . MTEE_CANONICAL_URL . '" value="' . $canonical_url . '"
placeholder="' . $placeholder . '" />';
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]);
+1 -1
View File
@@ -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;
}
+3 -3
View File
@@ -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) {
+85 -4
View File
@@ -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 '<div class="meta_key_desc_box">
<label style="font-weight: bold; display: block">title</label>
<div>
<input style="width:100%" type="text" name="' . MTEE_OGP_TITLE . '" value="' . get_post_meta($post->ID, MTEE_OGP_TITLE, true) . '"/>
<input style="width:100%" type="text"
name="' . MTEE_OGP_TITLE . '"
value="' . get_post_meta($post->ID, MTEE_OGP_TITLE, true) . '"
placeholder="' . $this->set_default_ogp_title() . '"/>
</div>
</div>
<div class="meta_key_desc_box">
<label style="font-weight: bold; display: block">description</label>
<div>
<input style="width:100%" type="text" name="' . MTEE_OGP_DESC . '" value="' . get_post_meta($post->ID, MTEE_OGP_DESC, true) . '"/>
<input style="width:100%" type="text"
name="' . MTEE_OGP_DESC . '"
value="' . get_post_meta($post->ID, MTEE_OGP_DESC, true) . '"
placeholder="' . $this->set_default_ogp_desc() . '"/>
</div>
</div>
<div class="meta_key_desc_box">
<label style="font-weight: bold; display: block">image</label>
<div>
<input style="width:100%" type="file" name="' . MTEE_OGP_IMG . '" value="' . get_post_meta($post->ID, MTEE_OGP_IMG, true) . '" accept="image/*"/>
<input style="width:100%" type="file" name="' . MTEE_OGP_IMG . '" accept="image/*"/>
<p>' . $this->set_ogp_thumb($post->ID) . '</p>
</div>
</div>';
}
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 '<img style="width: 200px;display: block;margin: 1em 0;" src="' . wp_get_attachment_url($ogp_thumb) . '">';
}
return '';
}
// カスタムフィールドの値を保存
public function save_meta_fields($post_id) {
if (!empty($_POST[MTEE_OGP_TITLE])) { //meta_keywordsが入力されている場合
@@ -76,6 +101,62 @@ if (!class_exists('mtee_ogp_post_setting')) {
} else {
delete_post_meta($post_id, MTEE_OGP_DESC);
}
if (isset($_FILES[MTEE_OGP_IMG]) && $_FILES[MTEE_OGP_IMG]['size'] !== 0) {
$this->save_ogp_image('post', $post_id);
}
}
public function save_ogp_image($type, $id) {
$file_name = $this->set_ogp_filename();
$wp_upload_dir = wp_upload_dir(); //現在のuploadディクレトリのパスとURLを入れた配列
$upload_file = $_FILES[MTEE_OGP_IMG]['tmp_name'];
$upload_path = $wp_upload_dir['path'] . '/' . $file_name;
//画像ファイルをuploadディクレトリに移動させる
move_uploaded_file($upload_file, $upload_path);
$this->upload_ogp_file($type, $upload_path, $wp_upload_dir, $file_name, $id);
}
public function set_ogp_filename() {
$file_name = basename($_FILES[MTEE_OGP_IMG]['name']);
$file_name = trim($file_name);
return str_replace(' ', '-', $file_name);
}
public function upload_ogp_file($type, $upload_path, $wp_upload_dir, $file_name, $id) {
if (file_exists($upload_path)) {
//添付ファイルを追加
$attachment = $this->set_upload_file_param($wp_upload_dir, $file_name, $upload_path);
$attach_id = wp_insert_attachment($attachment, $upload_path, $id);
if (!function_exists('wp_generate_attachment_metadata')) {
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
}
//添付ファイルのメタデータを生成し保存
$this->save_ogp_file($type, $attach_id, $upload_path, $id);
} else {
//保存失敗
echo '画像保存に失敗しました';
exit;
}
}
public function set_upload_file_param($wp_upload_dir, $file_name, $upload_path): array {
return array(
'guid' => $wp_upload_dir['url'] . '/' . basename($file_name),
'post_mime_type' => $_FILES[MTEE_OGP_IMG]['type'],
//正規表現で拡張子なしのスラッグ名を生成
'post_title' => preg_replace('/\.[^.]+$/', '', basename($upload_path)),
'post_content' => '',
'post_status' => 'inherit'
);
}
public function save_ogp_file($type, $attach_id, $upload_path, $id) {
$attach_data = wp_generate_attachment_metadata($attach_id, $upload_path);
wp_update_attachment_metadata($attach_id, $attach_data);
if ($type == 'post') {
update_post_meta($id, MTEE_OGP_IMG, $attach_id);
}
}
}
+213
View File
@@ -0,0 +1,213 @@
<?php
if (!defined('ABSPATH')) {
exit;
} // Exit if accessed directly
if (!class_exists('mtee_ogp_tax_setting')) {
/**
* Class mtee_tax_setting
*/
class mtee_ogp_tax_setting {
private $options;
public function __construct($options) {
$this->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'));
//formタグにmultipart/form-data属性を追加
add_action($tax . '_term_edit_form_tag', array($this, 'custom_meta_box_edit_form_tag'));
add_action($tax . '_add_form', array($this, 'create_form_tag'));
}
}
function create_form_tag() {
?>
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery('#addtag').attr("enctype", "multipart/form-data");
});
</script>
<?php
}
public function custom_meta_box_edit_form_tag() {
echo ' enctype="multipart/form-data"';
}
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) {
$input_values = $this->set_input_values($tag);
echo '
<div class="form-field">
OGP title<br>
<input type="text" name="' . MTEE_OGP_TITLE . '"
value="' . $input_values['title'] . '"
placeholder="' . $input_values['title_pl'] . '"
class="tax-meta-field" />
</div>
<div class="form-field">
OGP description<br>
<input type="text" name="' . MTEE_OGP_DESC . '"
value="' . $input_values['desc'] . '"
placeholder="' . $input_values['desc_pl'] . '"
class="tax-meta-field" />
<label>image
<input style="width:100%" type="file" name="' . MTEE_OGP_IMG . '" accept="image/*"/>
</label>
</div>
';
}
function insert_term_meta_edit_fields($tag) {
$input_values = $this->set_input_values($tag);
echo '
<tr class="form-field">
<th scope="row">OGP</th>
<td>
<label>
title:<br><input type="text" name="' . MTEE_OGP_TITLE . '"
value="' . $input_values['title'] . '"
placeholder="' . $input_values['title_pl'] . '"
class="tax-meta-field" />
</label>
<label>
description:<br><input type="text" name="' . MTEE_OGP_DESC . '"
value="' . $input_values['desc'] . '"
placeholder="' . $input_values['desc_pl'] . '"
class="tax-meta-field" />
</label>
<label>image
<input style="width:100%" type="file" name="' . MTEE_OGP_IMG . '" accept="image/*"/>
</label>
<p>' . $this->set_ogp_thumb($tag->term_id) . '</p>
</td>
</tr>
';
}
function set_input_values($tag): array {
$title_value = '';
$desc_value = '';
$title_placeholder = '';
$desc_placeholder = '';
if (isset($tag->term_id)) {
$title_value = get_term_meta($tag->term_id, MTEE_OGP_TITLE, true);
$desc_value = get_term_meta($tag->term_id, MTEE_OGP_DESC, true);
$title_placeholder = $this->set_default_title($tag);
$desc_placeholder = $this->set_default_description($title_placeholder);
}
return array(
'title' => $title_value,
'desc' => $desc_value,
'title_pl' => $title_placeholder,
'desc_pl' => $desc_placeholder,
);
}
public function set_default_title($tag) {
return $tag->name;
}
public function set_default_description($title): string {
return get_bloginfo('name') . 'の' . $title . 'です。';
}
public function set_ogp_thumb($id): string {
$ogp_thumb = get_term_meta($id, MTEE_OGP_IMG, true);
if (!empty($ogp_thumb)) {
return '<img style="width: 200px;display: block;margin: 1em 0;" src="' . wp_get_attachment_url($ogp_thumb) . '">';
}
return '';
}
function save_terms($term_id) {
if (array_key_exists(MTEE_OGP_TITLE, $_POST)) {
update_term_meta($term_id, MTEE_OGP_TITLE, $_POST[MTEE_OGP_TITLE]);
}
if (array_key_exists(MTEE_OGP_DESC, $_POST)) {
update_term_meta($term_id, MTEE_OGP_DESC, $_POST[MTEE_OGP_DESC]);
}
if (isset($_FILES[MTEE_OGP_IMG]) && $_FILES[MTEE_OGP_IMG]['size'] !== 0) {
$this->save_ogp_image('term', $term_id);
}
}
public function save_ogp_image($type, $id) {
$file_name = $this->set_ogp_filename();
$wp_upload_dir = wp_upload_dir(); //現在のuploadディクレトリのパスとURLを入れた配列
$upload_file = $_FILES[MTEE_OGP_IMG]['tmp_name'];
$upload_path = $wp_upload_dir['path'] . '/' . $file_name;
//画像ファイルをuploadディクレトリに移動させる
move_uploaded_file($upload_file, $upload_path);
$this->upload_ogp_file($type, $upload_path, $wp_upload_dir, $file_name, $id);
}
public function set_ogp_filename() {
$file_name = basename($_FILES[MTEE_OGP_IMG]['name']);
$file_name = trim($file_name);
return str_replace(' ', '-', $file_name);
}
public function upload_ogp_file($type, $upload_path, $wp_upload_dir, $file_name, $id) {
if (file_exists($upload_path)) {
//添付ファイルを追加
$attachment = $this->set_upload_file_param($wp_upload_dir, $file_name, $upload_path);
$attach_id = wp_insert_attachment($attachment, $upload_path, $id);
if (!function_exists('wp_generate_attachment_metadata')) {
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
}
//添付ファイルのメタデータを生成し保存
$this->save_ogp_file($type, $attach_id, $upload_path, $id);
} else {
//保存失敗
echo '画像保存に失敗しました';
exit;
}
}
public function set_upload_file_param($wp_upload_dir, $file_name, $upload_path): array {
return array(
'guid' => $wp_upload_dir['url'] . '/' . basename($file_name),
'post_mime_type' => $_FILES[MTEE_OGP_IMG]['type'],
//正規表現で拡張子なしのスラッグ名を生成
'post_title' => preg_replace('/\.[^.]+$/', '', basename($upload_path)),
'post_content' => '',
'post_status' => 'inherit'
);
}
public function save_ogp_file($type, $attach_id, $upload_path, $id) {
$attach_data = wp_generate_attachment_metadata($attach_id, $upload_path);
wp_update_attachment_metadata($attach_id, $attach_data);
if ($type == 'post') {
update_post_meta($id, MTEE_OGP_IMG, $attach_id);
} elseif ($type == 'term') {
update_term_meta($id, MTEE_OGP_IMG, $attach_id);
}
}
}
}
+70 -39
View File
@@ -1,29 +1,28 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
if (!defined('ABSPATH')) {
exit;
} // Exit if accessed directly
if ( ! class_exists( 'mtee_post_setting' ) ) {
if (!class_exists('mtee_post_setting')) {
/**
* Class mtee_post_setting
*/
class mtee_post_setting {
class mtee_post_setting {
private $options;
private $options;
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 __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 '<div class="meta_key_desc_box">
public function get_all_post_type(): array {
$custom_posts = array_values(get_post_types(array('public' => true, '_builtin' => false)));
return array_merge(array('page', 'post',), $custom_posts);
}
// カスタムフィールドの入力エリア
public function insert_meta_fields() {
global $post;
echo '<div class="meta_key_desc_box">
<label style="font-weight: bold; display: block">meta keywords</label>
<div><input style="width:100%" type="text" name="' . MTEE_NAME_KEYWORDS . '" value="' . get_post_meta( $post->ID, MTEE_NAME_KEYWORDS, true ) . '" />
<div><input style="width:100%" type="text" name="' . MTEE_NAME_KEYWORDS . '"
value="' . get_post_meta($post->ID, MTEE_NAME_KEYWORDS, true) . '"
placeholder="' . $this->set_default_keywords() . '"/>
</div>';
echo '<label style="font-weight: bold; display: block">meta description</label>
<div><input style="width:100%" type="text" name="' . MTEE_NAME_DESCRIPTION . '" value="' . get_post_meta( $post->ID, MTEE_NAME_DESCRIPTION, true ) . '" />
echo '<label style="font-weight: bold; display: block">meta description</label>
<div><input style="width:100%" type="text" name="' . MTEE_NAME_DESCRIPTION . '"
value="' . get_post_meta($post->ID, MTEE_NAME_DESCRIPTION, true) . '"
placeholder="' . $this->set_default_description() . '"/>
</div>
</div>';
}
}
// カスタムフィールドの値を保存
public function save_meta_fields( $post_id ) {
if ( ! empty( $_POST[ MTEE_NAME_KEYWORDS ] ) ) { //meta_keywordsが入力されている場合
update_post_meta( $post_id, MTEE_NAME_KEYWORDS, $_POST[ MTEE_NAME_KEYWORDS ] ); //値を保存
} else { //未入力の場合は値を削除
delete_post_meta( $post_id, MTEE_NAME_KEYWORDS );
}
if ( ! empty( $_POST[ MTEE_NAME_DESCRIPTION ] ) ) {
update_post_meta( $post_id, MTEE_NAME_DESCRIPTION, $_POST[ MTEE_NAME_DESCRIPTION ] );
} else {
delete_post_meta( $post_id, MTEE_NAME_DESCRIPTION );
}
}
}
// カスタムフィールドの値を保存
public function save_meta_fields($post_id) {
if (!empty($_POST[MTEE_NAME_KEYWORDS])) { //meta_keywordsが入力されている場合
update_post_meta($post_id, MTEE_NAME_KEYWORDS, $_POST[MTEE_NAME_KEYWORDS]); //値を保存
} else { //未入力の場合は値を削除
delete_post_meta($post_id, MTEE_NAME_KEYWORDS);
}
if (!empty($_POST[MTEE_NAME_DESCRIPTION])) {
update_post_meta($post_id, MTEE_NAME_DESCRIPTION, $_POST[MTEE_NAME_DESCRIPTION]);
} else {
delete_post_meta($post_id, MTEE_NAME_DESCRIPTION);
}
}
public function set_default_keywords() {
global $post_type;
if ($post_type == 'page') {
if (!empty($this->options['keywords_tmp']['page'])) {
return $this->options['keywords_tmp']['page'];
}
return '##title##,##description##,##site_name##';
} else {
if (!empty($this->options['keywords_tmp']['post'])) {
return $this->options['keywords_tmp']['post'];
}
return '##title##,##category##,##tag##,##custom_tax##,##description##,##site_name##';
}
}
public function set_default_description() {
if (!empty($this->options['description_tmp']['page'])) {
return $this->options['description_tmp']['page'];
}
return '##site_name##の' . MTEE_META_DESC_BEFORE_BRACKETS . '##title##' . MTEE_META_DESC_AFTER_BRACKETS . MTEE_META_DESC_SINGLE_BASE;
}
}
}
+72 -20
View File
@@ -39,43 +39,95 @@ if (!class_exists('mtee_tax_setting')) {
}
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);
}
$input_values = $this->set_input_values($tag);
echo '
<div class="form-field">
meta keywords<br>
<input type="text" name="' . MTEE_NAME_KEYWORDS . '" value="' . $key_value . '" class="tax-meta-field" />
<input type="text" name="' . MTEE_NAME_KEYWORDS . '"
value="' . $input_values['keywords'] . '"
placeholder="' . $input_values['keyword_pl'] . '"
class="tax-meta-field" />
</div>
<div class="form-field">
meta description<br>
<input type="text" name="' . MTEE_NAME_DESCRIPTION . '" value="' . $desc_value . '" class="tax-meta-field" />
<input type="text" name="' . MTEE_NAME_DESCRIPTION . '"
value="' . $input_values['desc'] . '"
placeholder="' . $input_values['desc_pl'] . '"
class="tax-meta-field" />
</div>
';
}
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);
}
$input_values = $this->set_input_values($tag);
echo '
<tr class="form-field">
<th scope="row">meta keywords</th>
<td><input type="text" name="' . MTEE_NAME_KEYWORDS . '" value="' . $key_value . '" class="tax-meta-field" /></td>
</tr>
<tr class="form-field">
<th>meta description</th>
<td><input type="text" name="' . MTEE_NAME_DESCRIPTION . '" value="' . $desc_value . '" class="tax-meta-field" /></td>
<th scope="row">meta keywords<br>meta description</th>
<td>
<label>meta keywords:<br>
<input type="text" name="' . MTEE_NAME_KEYWORDS . '"
value="' . $input_values['keywords'] . '"
placeholder="' . $input_values['keyword_pl'] . '"
class="tax-meta-field" />
</label>
<label>
meta description:<br>
<input type="text" name="' . MTEE_NAME_DESCRIPTION . '"
value="' . $input_values['desc'] . '"
placeholder="' . $input_values['desc_pl'] . '"
class="tax-meta-field" />
</label>
</td>
</tr>
';
}
function set_input_values($tag): array {
$key_value = '';
$desc_value = '';
$keyword_placeholder = '';
$desc_placeholder = '';
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);
$keyword_placeholder = $this->set_default_keywords($tag);
$desc_placeholder = $this->set_default_description($tag);
}
return array(
'keywords' => $key_value,
'desc' => $desc_value,
'keyword_pl' => $keyword_placeholder,
'desc_pl' => $desc_placeholder,
);
}
public function set_default_keywords($tag) {
if ($tag->taxonomy == 'category') {
$keywords = $this->options['keywords_tmp']['category'];
} elseif ($tag->taxonomy == 'post_tag') {
$keywords = $this->options['keywords_tmp']['tag'];
} else {
$keywords = $this->options['keywords_tmp']['tax'];
}
if (empty($keywords)) {
$keywords = '##title##,##description##,##site_name##';
}
return $keywords;
}
public function set_default_description($tag) {
if ($tag->taxonomy == 'category') {
$description = $this->options['description_tmp']['category'];
} elseif ($tag->taxonomy == 'post_tag') {
$description = $this->options['description_tmp']['tag'];
} else {
$description = $this->options['description_tmp']['tax'];
}
if (empty($description)) {
$description = '##site_name##の' . MTEE_META_DESC_BEFORE_BRACKETS . '##title##' . MTEE_META_DESC_AFTER_BRACKETS . MTEE_META_DESC_SINGLE_BASE;
}
return $description;
}
function save_terms($term_id) {
if (array_key_exists(MTEE_NAME_KEYWORDS, $_POST)) {
+3 -1
View File
@@ -35,7 +35,7 @@ if ($mtee->is_enable('enabled')) {
require_once MTEE_CLASS_DIR . 'mtee_meta_output_keydesc.php';
new mtee_tax_setting($options);
new mtee_post_setting($options);
new mtee_meta_output_keydesc;
new mtee_meta_output_keydesc();
}
// enabled my canonical. caution : default canonical delete
@@ -49,8 +49,10 @@ if ($mtee->is_enable('canonical_setting')) {
// enabled my OGP tag
if ($mtee->is_enable('ogp_setting')) {
require_once MTEE_CLASS_DIR . 'mtee_ogp_tax_setting.php';
require_once MTEE_CLASS_DIR . 'mtee_ogp_post_setting.php';
require_once MTEE_CLASS_DIR . 'mtee_meta_output_ogp.php';
new mtee_ogp_tax_setting($options);
new mtee_ogp_post_setting($options);
new mtee_meta_output_ogp();
}