WP PLUGIN MTEE(Meta Tag etc Extend)
WordPressに下記を追加する ・meta keywords, description設定 ・noindex, nofollowの表示/非表示設定 ・WPバージョン表示/非表示設定 ・CSS/JSバージョン表示/非表示設定
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
} // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'mtee_noindexnofolow_setting' ) ) {
|
||||
|
||||
/**
|
||||
* noindex,nofollowの設定フォーム
|
||||
* Class mtee_noindexnofolow_setting
|
||||
*/
|
||||
class mtee_noindexnofolow_setting {
|
||||
|
||||
public function __construct( $options ) {
|
||||
//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() {
|
||||
$target_posts = $this->set_post_types();
|
||||
foreach ( $target_posts as $target_post ) {
|
||||
add_meta_box( 'noindex_nofollow_setting', 'noindex nofollow 設定', array(
|
||||
$this,
|
||||
'insert_meta_fields'
|
||||
), $target_post, 'normal' );
|
||||
}
|
||||
}
|
||||
|
||||
private function set_post_types(): 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;
|
||||
$noindex_value = get_post_meta( $post->ID, MTEE_NAME_NOINDEX, true );
|
||||
$nofollow_value = get_post_meta( $post->ID, MTEE_NAME_NOFOLLOW, true );
|
||||
echo '
|
||||
<div class="meta_noindex_nofollow_box">
|
||||
<div>
|
||||
<label style="font-weight: bold;">noindex</label>
|
||||
<input type="hidden" name="' . MTEE_NAME_NOINDEX . '" value="0" />
|
||||
<input type="checkbox" name="' . MTEE_NAME_NOINDEX . '" value="1"';
|
||||
checked( $noindex_value, 1 );
|
||||
echo ' /></div>
|
||||
<div>
|
||||
<label style="font-weight: bold;">nofollow</label>
|
||||
<input type="hidden" name="' . MTEE_NAME_NOFOLLOW . '" value="0" />
|
||||
<input type="checkbox" name="' . MTEE_NAME_NOFOLLOW . '" value="1"';
|
||||
checked( $nofollow_value, 1 );
|
||||
echo '. />
|
||||
</div>
|
||||
</div>';
|
||||
}
|
||||
|
||||
// カスタムフィールドの値を保存
|
||||
public function save_meta_fields( $post_id ) {
|
||||
update_post_meta( $post_id, MTEE_NAME_NOINDEX, $_POST[ MTEE_NAME_NOINDEX ] );
|
||||
update_post_meta( $post_id, MTEE_NAME_NOFOLLOW, $_POST[ MTEE_NAME_NOFOLLOW ] );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------
|
||||
// タクソノミーのカスタムフィールド設定
|
||||
//-------------------------------------------------------------------------------------------
|
||||
public function set_tax_meta_box() {
|
||||
$taxs = $this->set_tax_types();
|
||||
foreach ( $taxs as $tax ) {
|
||||
add_action( $tax . '_add_form_fields', array( $this, 'add_tax_term_fields' ) );
|
||||
add_action( $tax . '_edit_form_fields', array( $this, 'edit_tax_term_fields' ) );
|
||||
}
|
||||
}
|
||||
|
||||
private function set_tax_types() {
|
||||
$custom_tax = get_taxonomies( array( 'public' => true, '_builtin' => false ) );
|
||||
|
||||
return array_merge( array( 'category', 'post_tag' ), $custom_tax );
|
||||
}
|
||||
|
||||
|
||||
public function add_tax_term_fields( $tag ) {
|
||||
$form = '<div class="meta_noindex_nofollow_outer">##CONTENTS##</div>';
|
||||
|
||||
echo $this->insert_term_meta_fields( $tag, $form );
|
||||
}
|
||||
|
||||
public function edit_tax_term_fields( $tag ) {
|
||||
$form = '<tr class="form-field">
|
||||
<th scope="row">noindex / nofollow</th>
|
||||
<td>##CONTENTS##</td>
|
||||
</tr>';
|
||||
|
||||
echo $this->insert_term_meta_fields( $tag, $form );
|
||||
}
|
||||
|
||||
private function insert_term_meta_fields( $tag, $form ) {
|
||||
$noindex_value = '';
|
||||
$nofollow_value = '';
|
||||
if ( isset( $tag->term_id ) ) {
|
||||
$noindex_value = get_term_meta( $tag->term_id, MTEE_NAME_NOINDEX, true );
|
||||
$nofollow_value = get_term_meta( $tag->term_id, MTEE_NAME_NOFOLLOW, true );
|
||||
}
|
||||
$add_meta = '
|
||||
<div class="meta_noindex_nofollow_box">
|
||||
<label>
|
||||
<input type="hidden" name="' . MTEE_NAME_NOINDEX . '" value="0" />
|
||||
<input type="checkbox" name="' . MTEE_NAME_NOINDEX . '" value="1" ' . self::create_checked( 1, $noindex_value ) . ' />
|
||||
noindex
|
||||
</label>
|
||||
<label>
|
||||
<input type="hidden" name="' . MTEE_NAME_NOFOLLOW . '" value="0" />
|
||||
<input type="checkbox" name="' . MTEE_NAME_NOFOLLOW . '" value="1" ' . self::create_checked( 1, $nofollow_value ) . ' />
|
||||
nofollow
|
||||
</label>
|
||||
</div>';
|
||||
|
||||
return str_replace( '##CONTENTS##', $add_meta, $form );
|
||||
|
||||
}
|
||||
|
||||
private static function create_checked( $current, $value ) {
|
||||
if ( $current == $value ) {
|
||||
return ' checked="checked"';
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public function save_terms( $term_id ) {
|
||||
if ( array_key_exists( MTEE_NAME_NOINDEX, $_POST ) ) {
|
||||
update_term_meta( $term_id, MTEE_NAME_NOINDEX, $_POST[ MTEE_NAME_NOINDEX ] );
|
||||
}
|
||||
if ( array_key_exists( MTEE_NAME_NOFOLLOW, $_POST ) ) {
|
||||
update_term_meta( $term_id, MTEE_NAME_NOFOLLOW, $_POST[ MTEE_NAME_NOFOLLOW ] );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
} // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'mtee_meta_output' ) ) {
|
||||
|
||||
/**
|
||||
* HTML出力
|
||||
* 設定が有効でキーワード・ディスクリプションのカスタムフィールドに登録があればそれを出力する。
|
||||
* 登録が無い場合は、デフォルトのキーワード・ディスクリプションを出力する。
|
||||
* Class mtee_meta_output
|
||||
*
|
||||
*/
|
||||
class mtee_meta_output {
|
||||
|
||||
private $site_name;
|
||||
private $description;
|
||||
|
||||
public function __construct() {
|
||||
$this->site_name = get_bloginfo( 'name' );
|
||||
$this->description = $this->site_name . MTEE_META_DESC_PARTICLE;
|
||||
add_action( 'wp_head', array( $this, 'post_output_add_metas' ) );
|
||||
add_action( 'wp_head', array( $this, 'set_noindex_nofollow' ) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// meta keywords & meta description
|
||||
//--------------------------------------------------------------------
|
||||
public function post_output_add_metas() {
|
||||
$metas = [];
|
||||
if ( is_tax() ) {
|
||||
$metas = $this->post_output_view_metas( get_queried_object()->taxonomy );
|
||||
} elseif ( is_page() || is_single() ) {
|
||||
$metas = $this->post_output_view_metas( get_post_type() );
|
||||
} elseif ( is_category() ) {
|
||||
$metas = $this->post_output_view_metas( 'category' );
|
||||
} elseif ( is_tag() ) {
|
||||
$metas = $this->post_output_view_metas( 'post_tag' );
|
||||
}
|
||||
if ( count( $metas ) == 0 ) {
|
||||
$metas = $this->create_default_keywords_description();
|
||||
}
|
||||
echo implode( PHP_EOL, $metas ) . PHP_EOL;
|
||||
}
|
||||
|
||||
private function post_output_view_metas( $type ): array {
|
||||
$targets = get_option( '_mtee' );
|
||||
if ( isset( $targets['custom_posts'] ) && array_key_exists( $type, $targets['custom_posts'] ) ) {
|
||||
$type = 'custom_post';
|
||||
} elseif ( isset( $targets['taxonomies'] ) && array_key_exists( $type, $targets['taxonomies'] ) ) {
|
||||
$type = 'custom_tax';
|
||||
}
|
||||
|
||||
$meta_data = $this->post_output_get_meta_data( $type );
|
||||
|
||||
return $this->create_meta_tags( $meta_data );
|
||||
}
|
||||
|
||||
private function post_output_get_meta_data( $type ): array {
|
||||
global $post;
|
||||
if ( $type == 'custom_tax' || $type == 'category' || $type == 'post_tag' ) {
|
||||
$queried_object = get_queried_object();
|
||||
$meta_key_words = get_term_meta( $queried_object->term_id, MTEE_NAME_KEYWORDS, true );
|
||||
$meta_description = get_term_meta( $queried_object->term_id, MTEE_NAME_DESCRIPTION, true );
|
||||
} else {
|
||||
$meta_key_words = get_post_meta( $post->ID, MTEE_NAME_KEYWORDS, true );
|
||||
$meta_description = get_post_meta( $post->ID, MTEE_NAME_DESCRIPTION, true );
|
||||
}
|
||||
|
||||
return [
|
||||
MTEE_NAME_KEYWORDS => $meta_key_words,
|
||||
MTEE_NAME_DESCRIPTION => $meta_description,
|
||||
];
|
||||
}
|
||||
|
||||
private function create_meta_tags( $meta_data ): array {
|
||||
$metas = [];
|
||||
if ( ! empty( $meta_data[ MTEE_NAME_KEYWORDS ] ) ) {
|
||||
$metas[] = str_replace( '##KEYWORDS##', $meta_data[ MTEE_NAME_KEYWORDS ], '<meta name="keywords" content="##KEYWORDS##" />' );
|
||||
}
|
||||
if ( ! empty( $meta_data[ MTEE_NAME_DESCRIPTION ] ) ) {
|
||||
$metas[] = str_replace( '##DISCRIPTION##', $meta_data[ MTEE_NAME_DESCRIPTION ], '<meta name="description" content="##DISCRIPTION##" />' );
|
||||
}
|
||||
|
||||
return $metas;
|
||||
}
|
||||
|
||||
public function create_default_keywords_description(): array {
|
||||
$keywords[] = $this->site_name; //サイトタイトル
|
||||
if ( ! empty( get_bloginfo( 'description' ) ) ) {
|
||||
$keywords[] = get_bloginfo( 'description' ); //サイトタイトル
|
||||
}
|
||||
|
||||
$this->createKeywords( $keywords );
|
||||
$this->createDescription();
|
||||
|
||||
$meta_data = [
|
||||
MTEE_NAME_KEYWORDS => implode( ',', array_reverse( $keywords ) ),
|
||||
MTEE_NAME_DESCRIPTION => $this->description,
|
||||
];
|
||||
|
||||
return $this->create_meta_tags( $meta_data );
|
||||
}
|
||||
|
||||
private function createKeywords( &$keywords ) {
|
||||
if ( is_category() || is_tag() ) {
|
||||
$keywords[] = single_cat_title( '', false );
|
||||
} elseif ( is_tax() ) {
|
||||
$keywords[] = single_term_title( '', false );
|
||||
} elseif ( is_post_type_archive() ) {
|
||||
$keywords[] = post_type_archive_title( '', false );
|
||||
} else {
|
||||
$keywords[] = get_the_title();
|
||||
}
|
||||
}
|
||||
|
||||
private function createDescription() {
|
||||
if ( is_home() || is_front_page() ) { //ページ
|
||||
$this->description .= MTEE_META_DESC_TOP_BASE;
|
||||
}
|
||||
|
||||
if ( is_page() || is_single() ) { //ページ
|
||||
$replacement = array( get_the_title(), MTEE_META_DESC_SINGLE_BASE );
|
||||
} elseif ( is_category() ) { //カテゴリー
|
||||
$replacement = array( single_cat_title( '', false ), MTEE_META_DESC_ARCHIVE_BASE );
|
||||
} elseif ( is_tag() ) { //タグ
|
||||
$replacement = array( single_tag_title( '', false ), MTEE_META_DESC_ARCHIVE_BASE );
|
||||
} elseif ( is_tax() ) { //タクソノミー
|
||||
$replacement = array( single_term_title( '', false ), MTEE_META_DESC_ARCHIVE_BASE );
|
||||
} elseif ( is_post_type_archive() ) { //カスタム投稿のアーカイブ
|
||||
$replacement = array( post_type_archive_title( '', false ), MTEE_META_DESC_ARCHIVE_BASE );
|
||||
}
|
||||
|
||||
if ( isset( $replacement ) ) {
|
||||
$search = array( '<###>', '<%%%>' );
|
||||
$description_noun = MTEE_META_DESC_BEFORE_BRACKETS . '<###>' . MTEE_META_DESC_AFTER_BRACKETS . '<%%%>';
|
||||
$this->description .= str_replace( $search, $replacement, $description_noun );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// noindex, nofollow
|
||||
//--------------------------------------------------------------------
|
||||
public function set_noindex_nofollow() {
|
||||
global $post;
|
||||
$type = '';
|
||||
if ( is_category() ) {
|
||||
$id = get_query_var( 'cat' );
|
||||
$type = 'tax';
|
||||
} elseif ( is_tag() ) {
|
||||
$id = get_query_var( 'tag_id' );
|
||||
$type = 'tax';
|
||||
} elseif ( is_tax() ) {
|
||||
$id = get_queried_object()->term_id;
|
||||
$type = 'tax';
|
||||
} elseif ( is_home() || is_front_page() || is_page() || is_single() ) {
|
||||
$id = $post->ID;
|
||||
$type = 'posts';
|
||||
}
|
||||
|
||||
echo $this->get_noindex_nofollow_data( $id, $type );
|
||||
|
||||
}
|
||||
|
||||
private function get_noindex_nofollow_data( $id, $type ) {
|
||||
if ( empty( $type ) ) {
|
||||
return;
|
||||
}
|
||||
$status = $this->get_noindex_nofollow_stauts( $type, $id );
|
||||
if ( $status['noindex'] == '0' && $status['nofollow'] == '0' ) {
|
||||
return;
|
||||
}
|
||||
if ( $status['noindex'] == '1' && $status['nofollow'] == '1' ) {
|
||||
return '<meta name="robots" content="noindex,nofollow" />';
|
||||
}
|
||||
if ( $status['noindex'] == '1' && $status['nofollow'] == '0' ) {
|
||||
return '<meta name="robots" content="noindex,follow" />';
|
||||
}
|
||||
if ( $status['noindex'] == '0' && $status['nofollow'] == '1' ) {
|
||||
return '<meta name="robots" content="index,nofollow" />';
|
||||
}
|
||||
}
|
||||
|
||||
private function get_noindex_nofollow_stauts( $type, $id ) {
|
||||
if ( $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,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
} // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'mtee_post_setting' ) ) {
|
||||
|
||||
/**
|
||||
* ページ、投稿、カスタム投稿の設定フォーム
|
||||
* Class amd_post_setting
|
||||
*/
|
||||
class mtee_post_setting {
|
||||
|
||||
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 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' );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// カスタムフィールドの入力エリア
|
||||
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>';
|
||||
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 ) . '" />
|
||||
</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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<?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 term_meta_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_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 ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
} // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'mtee_version_setting' ) ) {
|
||||
|
||||
class mtee_version_setting {
|
||||
private $options;
|
||||
|
||||
public function __construct( $options ) {
|
||||
$this->options = $options;
|
||||
$this->change_wp_version_view();
|
||||
$this->change_asset_version_view();
|
||||
}
|
||||
|
||||
public function change_wp_version_view() {
|
||||
if ( $this->options['wp_ver_disabled'] == 1 ) {
|
||||
remove_action( 'wp_head', 'wp_generator' );
|
||||
}
|
||||
}
|
||||
|
||||
public function change_asset_version_view() {
|
||||
if ( $this->options['asset_ver_disabled'] == 1 ) {
|
||||
add_action( 'wp_default_scripts', array( $this, 'remove_src_wp_ver' ) );
|
||||
add_action( 'wp_default_styles', array( $this, 'remove_src_wp_ver' ) );
|
||||
}
|
||||
}
|
||||
|
||||
function remove_src_wp_ver( $dep ) {
|
||||
$dep->default_version = '';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
} // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'MTEE' ) ) {
|
||||
|
||||
/**
|
||||
* 基本設定
|
||||
* キーワード、ディスクリプションのメタボックス有効・無効の設定
|
||||
* Class MTEE
|
||||
*/
|
||||
class MTEE {
|
||||
|
||||
public function __construct() {
|
||||
add_action( 'admin_menu', array( $this, 'add_pages' ) );
|
||||
}
|
||||
|
||||
public function add_pages() {
|
||||
add_menu_page(
|
||||
'Meta Tag etc Extend',
|
||||
'MTEE',
|
||||
'manage_options',
|
||||
'mtee',
|
||||
array( $this, 'show_option_page' ),
|
||||
''
|
||||
);
|
||||
}
|
||||
|
||||
public function show_option_page() {
|
||||
//$_POST['_mtee'])があったら保存
|
||||
if ( isset( $_POST['_mtee'] ) ) {
|
||||
check_admin_referer( 'check_options' );
|
||||
$opt = $_POST['_mtee'];
|
||||
update_option( '_mtee', $opt );
|
||||
require_once MTEE_TEMPLATE_DIR . 'success.php';
|
||||
}
|
||||
require_once MTEE_TEMPLATE_DIR . 'top.php';
|
||||
}
|
||||
|
||||
public static function register_target(): array {
|
||||
$custom_posts = get_post_types( array( 'public' => true, '_builtin' => false ) );
|
||||
$taxonomies = get_taxonomies( array( 'public' => true, '_builtin' => false ) );
|
||||
|
||||
return [
|
||||
'custom_posts' => $custom_posts,
|
||||
'taxonomies' => $taxonomies,
|
||||
];
|
||||
}
|
||||
|
||||
public function get_options() {
|
||||
return get_option( '_mtee' );
|
||||
}
|
||||
|
||||
public function is_enable(): bool {
|
||||
if ( $this->get_options()['enabled'] == 1 ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function is_wp_ver_disable(): bool {
|
||||
if ( $this->get_options()['wp_ver_disabled'] == 1 ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function is_asset_ver_disable(): bool {
|
||||
if ( $this->get_options()['asset_ver_disabled'] == 1 ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function is_noindex_nofollow_disable(): bool {
|
||||
if ( $this->get_options()['noindex_nofollow'] == '1' ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function get_key_desc_status(): int {
|
||||
if ( isset( $this->get_options()['enabled'] ) && $this->get_options()['enabled'] == '1' ) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_wp_ver_disabled(): int {
|
||||
if ( isset( $this->get_options()['wp_ver_disabled'] ) && $this->get_options()['wp_ver_disabled'] == '1' ) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_asset_ver_disabled(): int {
|
||||
if ( isset( $this->get_options()['asset_ver_disabled'] ) && $this->get_options()['asset_ver_disabled'] == '1' ) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_noindex_nofollow(): int {
|
||||
if ( isset( $this->get_options()['noindex_nofollow'] ) && $this->get_options()['noindex_nofollow'] == '1' ) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
const MTEE_CLASS_DIR = __DIR__ . '/class/';
|
||||
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_META_DESC_TOP_BASE = 'トップページです';
|
||||
const MTEE_META_DESC_SINGLE_BASE = 'ページです。';
|
||||
const MTEE_META_DESC_ARCHIVE_BASE = '一覧ページです。';
|
||||
const MTEE_META_DESC_PARTICLE = 'の';
|
||||
const MTEE_META_DESC_BEFORE_BRACKETS = '「';
|
||||
const MTEE_META_DESC_AFTER_BRACKETS = '」';
|
||||
@@ -0,0 +1,44 @@
|
||||
@charset "UTF-8";
|
||||
|
||||
h2 {
|
||||
margin-bottom: 1em
|
||||
}
|
||||
|
||||
.mtee-form-box {
|
||||
margin-bottom: 2em;
|
||||
}
|
||||
|
||||
.mtee-setting-tbl th {
|
||||
width: 100px;
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.mtee-setting-tbl td {
|
||||
padding: 0 0 1em;
|
||||
}
|
||||
|
||||
.mtee-setting-tbl ul {
|
||||
margin: 0
|
||||
}
|
||||
|
||||
.mtee-example {
|
||||
width: 95%;
|
||||
padding: 1em;
|
||||
background: #fff;
|
||||
border: 1px solid #666;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.mtee-example h4 {
|
||||
margin: 0 0 .5em;
|
||||
}
|
||||
|
||||
.meta_noindex_nofollow_box {
|
||||
display: flex;
|
||||
margin-bottom: 2em;
|
||||
}
|
||||
|
||||
.meta_noindex_nofollow_box label {
|
||||
width: 8em;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/*
|
||||
Plugin Name: Meta Tag etc Extend
|
||||
Description: ページ、投稿、ターム等のmeta keywords, meta description設定とWordPress、CSS,JSのバージョン削除
|
||||
Author: Nob Kim
|
||||
Version: 1.0
|
||||
*/
|
||||
|
||||
include_once 'config.php';
|
||||
include_once MTEE_CLASS_DIR . 'mtee.php';
|
||||
|
||||
/**
|
||||
* CSSを設定
|
||||
*/
|
||||
add_action( 'admin_enqueue_scripts', function () {
|
||||
$plugin_url = plugin_dir_url( __FILE__ );
|
||||
wp_enqueue_style( 'mtee_style', $plugin_url . 'css/mtee.css' );
|
||||
} );
|
||||
|
||||
$mtee = new MTEE;
|
||||
$options = $mtee->get_options();
|
||||
|
||||
// 設定が有効の場合は、各フォームや出力用のクラスを有効にする
|
||||
if ( $mtee->is_enable() ) {
|
||||
require_once MTEE_CLASS_DIR . 'mtee-tax-setting.php';
|
||||
require_once MTEE_CLASS_DIR . 'mtee-post-setting.php';
|
||||
require_once MTEE_CLASS_DIR . 'mtee-output.php';
|
||||
new mtee_tax_setting( $options );
|
||||
new mtee_post_setting( $options );
|
||||
new mtee_meta_output;
|
||||
}
|
||||
|
||||
if ( $mtee->is_noindex_nofollow_disable() ) {
|
||||
require_once MTEE_CLASS_DIR . 'mtee-noindexnofollow-setting.php';
|
||||
new mtee_noindexnofolow_setting( $options );
|
||||
}
|
||||
|
||||
if ( $mtee->is_wp_ver_disable() || $mtee->is_asset_ver_disable() ) {
|
||||
require_once MTEE_CLASS_DIR . 'mtee-version-setting.php';
|
||||
new mtee_version_setting( $options );
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<div class="updated fade"><p><strong>設定を保存しました</strong></p></div>
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
$register_targets = MTEE::register_target();
|
||||
$opt = get_option( '_mtee' );
|
||||
$enabled = $this->get_key_desc_status();
|
||||
$wp_ver_disabled = $this->get_wp_ver_disabled();
|
||||
$asset_ver_disabled = $this->get_asset_ver_disabled();
|
||||
$noindex_nofollow = $this->get_noindex_nofollow();
|
||||
?>
|
||||
<div class="wrap">
|
||||
<div id="icon-options-general" class="icon32"><br/></div>
|
||||
<h2>meta keyword, description / バージョン情報 設定</h2>
|
||||
<form action="" method="post">
|
||||
<?php wp_nonce_field( 'check_options' ); ?>
|
||||
<div class="mtee-form-box">
|
||||
<h3>キーワード・ディスクリプション</h3>
|
||||
<label>
|
||||
<input type="hidden" name="_mtee[enabled]" value="0">
|
||||
<input type="checkbox" name="_mtee[enabled]" <?php checked( $enabled, 1 ); ?>
|
||||
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 ) : ?>
|
||||
<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( $opt['custom_posts'][ $custom_post ], 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>
|
||||
<label>
|
||||
<input type="hidden"
|
||||
name="_mtee[taxonomies][<?php echo $taxonomy; ?>]" value="0">
|
||||
<input type="checkbox"
|
||||
name="_mtee[taxonomies][<?php echo $taxonomy; ?>]"
|
||||
<?php checked( $opt['taxonomies'][ $taxonomy ], 1 ); ?>
|
||||
value="1">
|
||||
<?php echo $taxonomy . '(' . get_taxonomy( $taxonomy )->label . ')'; ?>
|
||||
</label>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</table>
|
||||
<?php endif; ?>
|
||||
<aside class="mtee-example">
|
||||
<h4>keywordsの初期表示</h4>
|
||||
<ul>
|
||||
<li>[各ページ、カテゴリー、タグ等のタイトル],<?php
|
||||
if ( ! empty( get_bloginfo( 'description' ) ) ) {
|
||||
echo get_bloginfo( 'description' ) . ',';
|
||||
}
|
||||
echo get_bloginfo( 'name' );
|
||||
?>
|
||||
</li>
|
||||
</ul>
|
||||
<h4>descriptionの初期表示</h4>
|
||||
<ul>
|
||||
<li>トップページ:<?php echo get_bloginfo( 'name' ); ?>
|
||||
の<?php echo MTEE_META_DESC_TOP_BASE; ?></li>
|
||||
<li>ページ/投稿:<?php echo get_bloginfo( 'name' ); ?>
|
||||
の[ページタイトル]<?php echo MTEE_META_DESC_SINGLE_BASE; ?></li>
|
||||
<li>カテゴリー/タグ等アーカイブ:<?php echo get_bloginfo( 'name' ); ?>
|
||||
の[カテゴリー/タグ等タイトル]<?php echo MTEE_META_DESC_SINGLE_BASE; ?></li>
|
||||
</ul>
|
||||
</aside>
|
||||
<div class="mtee-form-box">
|
||||
<h3>個別設定 NOINDEX/NOFOLLOW</h3>
|
||||
<label>
|
||||
<input type="hidden" name="_mtee[noindex_nofollow]" value="0">
|
||||
<input type="checkbox"
|
||||
name="_mtee[noindex_nofollow]" <?php checked( $noindex_nofollow, 1 ); ?>
|
||||
value="1">有効
|
||||
</label>
|
||||
</div>
|
||||
<div class="mtee-form-box">
|
||||
<h3>WordPressバージョン情報</h3>
|
||||
<label>
|
||||
<input type="hidden" name="_mtee[wp_ver_disabled]" value="0">
|
||||
<input type="checkbox"
|
||||
name="_mtee[wp_ver_disabled]" <?php checked( $wp_ver_disabled, 1 ); ?>
|
||||
value="1">削除
|
||||
</label>
|
||||
</div>
|
||||
<div class="mtee-form-box">
|
||||
<h3>CSS / JSバージョン情報</h3>
|
||||
<label>
|
||||
<input type="hidden" name="_mtee[asset_ver_disabled]" value="0">
|
||||
<input type="checkbox"
|
||||
name="_mtee[asset_ver_disabled]" <?php checked( $asset_ver_disabled, 1 ); ?>
|
||||
value="1">削除
|
||||
</label>
|
||||
</div>
|
||||
<p class="submit"><input type="submit" name="Submit" class="button-primary" value="変更を保存"/></p>
|
||||
</form>
|
||||
<!-- /.wrap -->
|
||||
</div>
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
// WP_UNINSTALL_PLUGINが定義されているかチェック
|
||||
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
||||
die;
|
||||
}
|
||||
|
||||
// オプション設定の削除
|
||||
delete_option( '_mtee' );
|
||||
|
||||
//Todo: タームメタの一括削除方法を確認
|
||||
|
||||
$delete_post_meta_keys = array(
|
||||
'mtee_meta_keywords',
|
||||
'mtee_meta_description',
|
||||
'mtee_robots_noindex',
|
||||
'mtee_robots_nofollow',
|
||||
);
|
||||
foreach ( $delete_post_meta_keys as $delete_post_meta_key ) {
|
||||
delete_post_meta_by_key( $delete_post_meta_key );
|
||||
}
|
||||
Reference in New Issue
Block a user