WP PLUGIN MTEE(Meta Tag etc Extend) カスタム投稿、カスタム分類のキーワード、ディスクリプションの適用修正
・カスタム投稿、カスタム分類のキーワード、ディスクリプションの適用チェックボックスを廃止し、全カスタム投稿、全カスタム分類に適用するよう修正
This commit is contained in:
@@ -1,92 +0,0 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
} // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'mtee_tax_setting' ) ) {
|
||||
|
||||
/**
|
||||
* カテゴリー、タグ、カスタム分類の設定フォーム
|
||||
* Class amd_tax_setting
|
||||
*/
|
||||
class mtee_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() {
|
||||
$built_ins = array(
|
||||
'term' => array( 'category', 'post_tag' ),
|
||||
);
|
||||
|
||||
foreach ( $built_ins['term'] as $built_in ) {
|
||||
add_action( $built_in . '_add_form_fields', array( $this, 'insert_term_meta_add_fields' ) );
|
||||
add_action( $built_in . '_edit_form_fields', array( $this, 'insert_term_meta_edit_fields' ) );
|
||||
}
|
||||
|
||||
if ( isset( $this->options['taxonomies'] ) ) {
|
||||
foreach ( $this->options['taxonomies'] as $tax_key => $tax_chk ) {
|
||||
if ( $tax_chk == 1 ) {
|
||||
add_action( $tax_key . '_add_form_fields', array( $this, 'insert_term_meta_add_fields' ) );
|
||||
add_action( $tax_key . '_edit_form_fields', array( $this, 'insert_term_meta_edit_fields' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
echo '
|
||||
<div class="form-field">
|
||||
meta keywords<br>
|
||||
<input type="text" name="' . MTEE_NAME_KEYWORDS . '" value="' . $key_value . '" 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" />
|
||||
</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 );
|
||||
}
|
||||
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>
|
||||
</tr>
|
||||
';
|
||||
}
|
||||
|
||||
|
||||
function save_terms( $term_id ) {
|
||||
if ( array_key_exists( MTEE_NAME_KEYWORDS, $_POST ) ) {
|
||||
update_term_meta( $term_id, MTEE_NAME_KEYWORDS, $_POST[ MTEE_NAME_KEYWORDS ] );
|
||||
}
|
||||
if ( array_key_exists( MTEE_NAME_DESCRIPTION, $_POST ) ) {
|
||||
update_term_meta( $term_id, MTEE_NAME_DESCRIPTION, $_POST[ MTEE_NAME_DESCRIPTION ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,31 +33,19 @@ if (!class_exists('mtee_canonical_setting')) {
|
||||
//-------------------------------------------------------------------------------------------
|
||||
public function add_meta_fields() {
|
||||
//add_meta_box(表示される入力ボックスのHTMLのID, ラベル, 表示する内容を作成する関数名, 投稿タイプ, 表示方法)
|
||||
$default_built_ins = array(
|
||||
'posts' => array('page', 'post',),
|
||||
);
|
||||
$custom_posts = array_values(get_post_types(array('public' => true, '_builtin' => false)));
|
||||
$target_posts = array_merge(array('page', 'post',), $custom_posts);
|
||||
|
||||
foreach ($default_built_ins['posts'] as $built_in) {
|
||||
foreach ($target_posts as $target_post) {
|
||||
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'
|
||||
);
|
||||
}
|
||||
}
|
||||
array(
|
||||
$this,
|
||||
'insert_meta_fields'
|
||||
),
|
||||
$target_post,
|
||||
'normal');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,9 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
||||
if ( ! class_exists( 'mtee_post_setting' ) ) {
|
||||
|
||||
/**
|
||||
* ページ、投稿、カスタム投稿の設定フォーム
|
||||
* Class amd_post_setting
|
||||
*/
|
||||
/**
|
||||
* Class mtee_post_setting
|
||||
*/
|
||||
class mtee_post_setting {
|
||||
|
||||
private $options;
|
||||
@@ -23,24 +22,19 @@ if ( ! class_exists( 'mtee_post_setting' ) ) {
|
||||
|
||||
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( 'meta_setting', 'meta設定', 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( 'meta_setting', 'meta設定', array(
|
||||
$this,
|
||||
'insert_meta_fields'
|
||||
), $custom_post, 'normal' );
|
||||
}
|
||||
}
|
||||
}
|
||||
$custom_posts = array_values(get_post_types(array('public' => true, '_builtin' => false)));
|
||||
$target_posts = array_merge(array('page', 'post',), $custom_posts);
|
||||
foreach ($target_posts as $target_post) {
|
||||
add_meta_box(
|
||||
'meta_setting',
|
||||
'meta設定',
|
||||
array(
|
||||
$this,
|
||||
'insert_meta_fields'),
|
||||
$target_post,
|
||||
'normal'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// カスタムフィールドの入力エリア
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
} // Exit if accessed directly
|
||||
|
||||
if (!class_exists('mtee_tax_setting')) {
|
||||
|
||||
/**
|
||||
* Class mtee_tax_setting
|
||||
*/
|
||||
class mtee_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'));
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
$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);
|
||||
}
|
||||
echo '
|
||||
<div class="form-field">
|
||||
meta keywords<br>
|
||||
<input type="text" name="' . MTEE_NAME_KEYWORDS . '" value="' . $key_value . '" 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" />
|
||||
</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);
|
||||
}
|
||||
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>
|
||||
</tr>
|
||||
';
|
||||
}
|
||||
|
||||
|
||||
function save_terms($term_id) {
|
||||
if (array_key_exists(MTEE_NAME_KEYWORDS, $_POST)) {
|
||||
update_term_meta($term_id, MTEE_NAME_KEYWORDS, $_POST[MTEE_NAME_KEYWORDS]);
|
||||
}
|
||||
if (array_key_exists(MTEE_NAME_DESCRIPTION, $_POST)) {
|
||||
update_term_meta($term_id, MTEE_NAME_DESCRIPTION, $_POST[MTEE_NAME_DESCRIPTION]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+3
-1
@@ -1,13 +1,15 @@
|
||||
<?php
|
||||
|
||||
const MTEE_CLASS_DIR = __DIR__ . '/class/';
|
||||
const MTEE_TRAIT_DIR = __DIR__ . '/trait/';
|
||||
const MTEE_TEMPLATE_DIR = __DIR__ . '/template/';
|
||||
const MTEE_NAME_KEYWORDS = 'mtee_meta_keywords';
|
||||
const MTEE_NAME_DESCRIPTION = 'mtee_meta_description';
|
||||
const MTEE_NAME_NOINDEX = '_mtee_robots_noindex';
|
||||
const MTEE_NAME_NOFOLLOW = '_mtee_robots_nofollow';
|
||||
const MTEE_CANONICAL_URL = 'mtee_canonical_url';
|
||||
const MTEE_OGP_TITLE = '_mtee_ogp_title';
|
||||
const MTEE_OGP_DESC = '_mtee_ogp_desc';
|
||||
const MTEE_OGP_IMG = '_mtee_ogp_img';
|
||||
|
||||
const MTEE_META_DESC_TOP_BASE = 'トップページです。';
|
||||
const MTEE_META_DESC_SINGLE_BASE = 'ページです。';
|
||||
|
||||
+10
-10
@@ -30,8 +30,8 @@ $options = $mtee->get_options();
|
||||
|
||||
// enabled my meta keywords, description
|
||||
if ($mtee->is_enable('enabled')) {
|
||||
require_once MTEE_CLASS_DIR . 'mtee-tax-setting.php';
|
||||
require_once MTEE_CLASS_DIR . 'mtee-post-setting.php';
|
||||
require_once MTEE_CLASS_DIR . 'mtee_tax_setting.php';
|
||||
require_once MTEE_CLASS_DIR . 'mtee_post_setting.php';
|
||||
require_once MTEE_CLASS_DIR . 'mtee_meta_output_keydesc.php';
|
||||
new mtee_tax_setting($options);
|
||||
new mtee_post_setting($options);
|
||||
@@ -41,31 +41,31 @@ if ($mtee->is_enable('enabled')) {
|
||||
// enabled my canonical. caution : default canonical delete
|
||||
if ($mtee->is_enable('canonical_setting')) {
|
||||
remove_action('wp_head', 'rel_canonical');
|
||||
require_once MTEE_CLASS_DIR . 'mtee-canonical-setting.php';
|
||||
require_once MTEE_CLASS_DIR . 'mtee-output-canonical.php';
|
||||
require_once MTEE_CLASS_DIR . 'mtee_canonical_setting.php';
|
||||
require_once MTEE_CLASS_DIR . 'mtee_meta_output_canonical.php';
|
||||
new mtee_canonical_setting($options);
|
||||
new mtee_meta_output_canonical();
|
||||
}
|
||||
|
||||
// enabled my OGP tag
|
||||
if ($mtee->is_enable('ogp_setting')) {
|
||||
require_once MTEE_CLASS_DIR . 'mtee-ogp-setting.php';
|
||||
require_once MTEE_CLASS_DIR . 'mtee-output-ogp.php';
|
||||
new mtee_ogp_setting();
|
||||
require_once MTEE_CLASS_DIR . 'mtee_ogp_post_setting.php';
|
||||
require_once MTEE_CLASS_DIR . 'mtee_meta_output_ogp.php';
|
||||
new mtee_ogp_post_setting($options);
|
||||
new mtee_meta_output_ogp();
|
||||
}
|
||||
|
||||
//enabled my noindex, nofollow
|
||||
if ($mtee->is_enable('noindex_nofollow')) {
|
||||
require_once MTEE_CLASS_DIR . 'mtee-noindexnofollow-setting.php';
|
||||
require_once MTEE_CLASS_DIR . 'mtee-output-noindexnofollow.php';
|
||||
require_once MTEE_CLASS_DIR . 'mtee_noindexnofolow_setting.php';
|
||||
require_once MTEE_CLASS_DIR . 'mtee_meta_output_noindexnofollow.php';
|
||||
new mtee_noindexnofolow_setting($options);
|
||||
new mtee_meta_output_noindexnofollow();
|
||||
}
|
||||
|
||||
//disabled WP version, WP JS/CSS version
|
||||
if ($mtee->is_disable('asset_ver_disabled') || $mtee->is_disable('asset_ver_disabled')) {
|
||||
require_once MTEE_CLASS_DIR . 'mtee-version-setting.php';
|
||||
require_once MTEE_CLASS_DIR . 'mtee_version_setting.php';
|
||||
new mtee_version_setting($options);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,57 +27,6 @@ $asset_ver_disabled = $this->get_key_setting('asset_ver_disabled');
|
||||
value="1">有効
|
||||
</label>
|
||||
</div>
|
||||
<?php if (count($register_targets['custom_posts']) > 0 || count($register_targets['taxonomies']) > 0): ?>
|
||||
<table class="mtee-setting-tbl">
|
||||
<?php if (count($register_targets['custom_posts']) > 0): ?>
|
||||
<tr>
|
||||
<th>カスタム投稿</th>
|
||||
<td>
|
||||
<ul>
|
||||
<?php foreach ($register_targets['custom_posts'] as $custom_post) : ?>
|
||||
<?php $custom_post_check = $opt['custom_posts'][$custom_post] ?? 0; ?>
|
||||
<li>
|
||||
<label>
|
||||
<input type="hidden"
|
||||
name="_mtee[custom_posts][<?php echo $custom_post; ?>]"
|
||||
value="0">
|
||||
<input type="checkbox"
|
||||
name="_mtee[custom_posts][<?php echo $custom_post; ?>]"
|
||||
<?php checked($custom_post_check, 1); ?>
|
||||
value="1">
|
||||
<?php echo $custom_post . '(' . get_post_type_object($custom_post)->label . ')'; ?>
|
||||
</label>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
<?php if (count($register_targets['taxonomies']) > 0): ?>
|
||||
<tr>
|
||||
<th>カスタム分類</th>
|
||||
<td>
|
||||
<ul>
|
||||
<?php foreach ($register_targets['taxonomies'] as $taxonomy) : ?>
|
||||
<li>
|
||||
<?php $taxonomy_check = $opt['taxonomies'][$taxonomy] ?? 0; ?>
|
||||
<label>
|
||||
<input type="hidden"
|
||||
name="_mtee[taxonomies][<?php echo $taxonomy; ?>]" value="0">
|
||||
<input type="checkbox"
|
||||
name="_mtee[taxonomies][<?php echo $taxonomy; ?>]"
|
||||
<?php checked($taxonomy_check, 1); ?>
|
||||
value="1">
|
||||
<?php echo $taxonomy . '(' . get_taxonomy($taxonomy)->label . ')'; ?>
|
||||
</label>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</table>
|
||||
<?php endif; ?>
|
||||
<div class="mtee-form-box mtee_box_border">
|
||||
<h3>meta keywords テンプレート設定
|
||||
<?php if (!$this->is_enable('enabled')): ?>
|
||||
|
||||
Reference in New Issue
Block a user