Compare commits

...

23 Commits

Author SHA1 Message Date
nobu da6cc8f734 WP PLUGIN MTEE(Meta Tag etc Extend) タブコンテンツ表示調整など
・更新ボタン押下後、元のタブコンテンツを表示するよう修正
・トップとアーカイブのOGP登録について未定義時の判定を追加
・保存完了ダイアログに閉じるボタンを追加
2021-06-12 16:53:55 +09:00
nobu 60192377db WP PLUGIN MTEE(Meta Tag etc Extend) 表示変更
・設定項目毎のタブを分割
・トップページのmeta keywordsを復活
2021-06-12 12:36:41 +09:00
nobu d7826ef2be WP PLUGIN MTEE(Meta Tag etc Extend) OGP設定
・OGP imageの設定
・トップページとカスタム投稿アーカイブのOGP title、description追加
・タイトルとディスクリプションの出力
2021-06-12 12:34:03 +09:00
nobu 187f1af050 WP PLUGIN MTEE(Meta Tag etc Extend) OGPタグ
・descriptionをTraitへ
・トップとカスタム投稿アーカイブのOGPイメージ登録対応
・OGP_URLのリンク修正(canonicalは不要のため削除)
・site_name、type、title、urlの設定
・デフォルトのdescriptionの設定
・meta keywordds/description 設定の変数、メソッド整理
2021-06-08 21:05:50 +09:00
nobu b4f43215ba WP PLUGIN MTEE(Meta Tag etc Extend) RSSと絵文字タグ設定
・RSSと絵文字タグの無効化設定を追加
2021-06-06 18:24:46 +09:00
nobu 8c39e705e8 WP PLUGIN MTEE(Meta Tag etc Extend) OGPタグ設定
・画像アップロードをメディアアップローダーに変更
2021-06-06 12:31:29 +09:00
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
nobu 59c03d527c Merge pull request '機能追加_カスタム投稿・分類のキーワード、ディスクリプション修正' (#10) from 機能追加_カスタム投稿・分類のキーワード、ディスクリプション修正 into master
Reviewed-on: https://develop.n-k-y.net/repo/WP_PLUGIN/Meta_Tag_etc_Extend/pulls/10
2021-05-30 14:27:13 +09:00
nobu 0bc4ee1d23 WP PLUGIN MTEE(Meta Tag etc Extend) OGP設定追加
・OGP設定追加
2021-05-30 14:25:57 +09:00
nobu c7f4e41e1c WP PLUGIN MTEE(Meta Tag etc Extend) カスタム投稿、カスタム分類のキーワード、ディスクリプションの適用修正
・カスタム投稿、カスタム分類のキーワード、ディスクリプションの適用チェックボックスを廃止し、全カスタム投稿、全カスタム分類に適用するよう修正
2021-05-30 12:46:26 +09:00
nobu e2d31cec85 Merge branch 'master' of ssh://develop.n-k-y.net:10022/WP_PLUGIN/Meta_Tag_etc_Extend into 機能追加_OGPタグ設定 2021-05-28 21:08:33 +09:00
nobu 1925d320ee Merge pull request 'WP PLUGIN MTEE(Meta Tag etc Extend) ファイル整理' (#9) from 新規追加_ファイル整理 into master
Reviewed-on: https://develop.n-k-y.net/repo/WP_PLUGIN/Meta_Tag_etc_Extend/pulls/9
2021-05-28 21:07:36 +09:00
nobu 151026ef87 WP PLUGIN MTEE(Meta Tag etc Extend) OGPタグ設定の追加
・language_attributesフックでhtmlタグにprefixを追加
2021-05-28 21:06:37 +09:00
nobu 21ccef70f1 WP PLUGIN MTEE(Meta Tag etc Extend) ファイル整理
・各項目のOFF/ONに対応して設定/HTML出力するようファイルを整理
2021-05-28 21:02:28 +09:00
nobu 3c381f8295 WP PLUGIN MTEE(Meta Tag etc Extend) プラグイン削除時の投稿、カテゴリ等のmetaデータ削除
・プラグイン削除時に投稿、カテゴリ等のメタデータを削除するようuninstall.phpにSQLを追加
2021-05-28 18:49:09 +09:00
nobu 2721a62410 Merge pull request '機能追加_canonical設定' (#8) from 機能追加_canonical設定 into master
Reviewed-on: https://develop.n-k-y.net/repo/WP_PLUGIN/Meta_Tag_etc_Extend/pulls/8
2021-05-27 16:18:52 +09:00
nobu ee28571645 WP PLUGIN MTEE(Meta Tag etc Extend) カテゴリー、タグ、カスタム分類のcanonical設定追加
・カテゴリー、タグ、カスタム分類にcanonical urlの入力設定メタボックス追加
・デフォルトのcanonical urlを追加
2021-05-27 16:10:58 +09:00
nobu 0870f12825 WP PLUGIN MTEE(Meta Tag etc Extend) カスタム分類noindex、nofollowの修正
・メソッドを整理
・カスタム分類にnoindex、nofollowのメタボックスが表示されていなかったので修正
2021-05-27 15:00:42 +09:00
nobu 8775a619c7 WP PLUGIN MTEE(Meta Tag etc Extend) canonical設定追加
・トップ、カスタム分類アーカイブ、ページ、投稿、カスタム投稿のcanonical設定の追加
・メソッドを整理
2021-05-26 20:20:13 +09:00
nobu 03ddba7a9b Merge pull request 'WP PLUGIN MTEE(Meta Tag etc Extend) キーワードのテンプレート設定追加' (#7) from 機能追加_キーワードの雛形設定 into master
Reviewed-on: https://develop.n-k-y.net/repo/WP_PLUGIN/Meta_Tag_etc_Extend/pulls/7
2021-05-25 15:08:17 +09:00
nobu 1cc61a0c24 WP PLUGIN MTEE(Meta Tag etc Extend) キーワードのテンプレート設定追加
・meta keywords未設定の投稿、カテゴリー、タグ、カスタム分類のデフォルト表示テンプレート設定の追加
2021-05-25 15:07:29 +09:00
29 changed files with 2249 additions and 932 deletions
-152
View File
@@ -1,152 +0,0 @@
<?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 ] );
}
}
}
}
-255
View File
@@ -1,255 +0,0 @@
<?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 = array();
if (is_home() || is_front_page()) {
$type = 'top_page';
} elseif (is_post_type_archive()) {
$type = 'custom_post_archive';
} elseif (is_tax()) {
$type = get_queried_object()->taxonomy;
} elseif (is_page() || is_single()) {
$type = get_post_type();
} elseif (is_category()) {
$type = 'category';
} elseif (is_tag()) {
$type = 'post_tag';
}
if (isset($type)) {
$metas = $this->post_output_view_metas($type);
}
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 == 'top_page') {
$meta_key_words = get_option('_mtee')['top_page']['keywords'];
$meta_description = get_option('_mtee')['top_page']['description'];
} elseif ($type == 'custom_post_archive') {
$custom_post_name = get_post_type_object(get_post_type())->name;
$meta_key_words = get_option('_mtee')['custom_post'][$custom_post_name]['keywords'];
$meta_description = get_option('_mtee')['custom_post'][$custom_post_name]['description'];
} elseif ($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 array(
MTEE_NAME_KEYWORDS => str_replace('、', ',', $meta_key_words),
MTEE_NAME_DESCRIPTION => $meta_description,
);
}
private 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], '<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 = array(
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() {
$type = '';
$title = '';
$suffix_text = MTEE_META_DESC_ARCHIVE_BASE;
if (is_home() || is_front_page()) { //ページ
$this->description .= MTEE_META_DESC_TOP_BASE;
} elseif (is_page() || is_single()) { //ページ
$type = 'page';
$title = get_the_title();
$suffix_text = MTEE_META_DESC_SINGLE_BASE;
} elseif (is_category()) { //カテゴリー
$type = 'category';
$title = single_cat_title('', false);
} elseif (is_tag()) { //タグ
$type = 'tag';
$title = single_tag_title('', false);
} elseif (is_tax()) { //タクソノミー
$type = 'tax';
$title = single_term_title('', false);
} elseif (is_post_type_archive()) { //カスタム投稿のアーカイブ
$type = 'custom_post';
$title = post_type_archive_title('', false);
}
$replacement = $this->cnv_custom_template($type, $title, $suffix_text);
if (isset($replacement['org'])) {
$search = array('<###>', '<%%%>');
$description_noun = MTEE_META_DESC_BEFORE_BRACKETS . '<###>' . MTEE_META_DESC_AFTER_BRACKETS . '<%%%>';
$this->description .= str_replace($search, $replacement, $description_noun);
}
}
private 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##');
$replacement = array($title, get_bloginfo('name'));
$this->description = str_replace($search, $replacement, $template[$type]);
} else {
return array('org' => array($title, $suffix_text));
}
}
//--------------------------------------------------------------------
// noindex, nofollow
//--------------------------------------------------------------------
public function set_noindex_nofollow() {
global $post;
$type = '';
$id = null;
if (is_post_type_archive()) {
$type = 'custom_post_archive';
} elseif (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()) {
$type = 'top_page';
} elseif (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): 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,
);
}
}
}
-74
View File
@@ -1,74 +0,0 @@
<?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 );
}
}
}
}
-113
View File
@@ -1,113 +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 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 ] );
}
}
}
}
-36
View File
@@ -1,36 +0,0 @@
<?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 = '';
}
}
}
+22 -62
View File
@@ -39,21 +39,9 @@ if (!class_exists('MTEE')) {
require_once MTEE_TEMPLATE_DIR . 'index.php';
}
public function pages_setting() {
//$_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 . 'pages.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,
@@ -64,77 +52,49 @@ if (!class_exists('MTEE')) {
return get_option('_mtee');
}
public function is_enable(): bool {
if (isset($this->get_options()['enabled'])
&& $this->get_options()['enabled'] == 1) {
public function is_enable($type): bool {
if (isset($this->get_options()[$type])
&& $this->get_options()[$type] == 1) {
return true;
}
return false;
}
public function is_wp_ver_disable(): bool {
if (isset($this->get_options()['wp_ver_disabled'])
&& $this->get_options()['wp_ver_disabled'] == 1) {
public function is_disable($type): bool {
if (isset($this->get_options()[$type])
&& $this->get_options()[$type] == 1) {
return true;
}
return false;
}
public function is_asset_ver_disable(): bool {
if (isset($this->get_options()['asset_ver_disabled'])
&& $this->get_options()['asset_ver_disabled'] == 1) {
return true;
}
return false;
}
public function is_noindex_nofollow_disable(): bool {
if (isset($this->get_options()['noindex_nofollow'])
&& $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') {
public function get_key_setting($type): int {
if (isset($this->get_options()[$type])
&& $this->get_options()[$type] == '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_ogp_img($type, $subtype = '') {
if (empty($subtype)) {
if (isset(get_option('_mtee')[$type]['ogp_img'])) {
$id = get_option('_mtee')[$type]['ogp_img'];
}
}
if (!empty($subtype)) {
if (isset(get_option('_mtee')[$type][$subtype]['ogp_img'])) {
$id = get_option('_mtee')[$type][$subtype]['ogp_img'];
}
}
if (!empty($id)) {
return '<img src="' . wp_get_attachment_image_src($id, 'thumbnail')[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;
}
}
}
}
+153
View File
@@ -0,0 +1,153 @@
<?php
if (!defined('ABSPATH')) {
exit;
} // Exit if accessed directly
if (!class_exists('mtee_canonical_setting')) {
/**
* ページ、投稿、カスタム投稿の設定フォーム
* Class amd_post_setting
*/
class mtee_canonical_setting {
private $options;
public function __construct($options) {
$this->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, ラベル, 表示する内容を作成する関数名, 投稿タイプ, 表示方法)
$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(
'canonical_setting',
'Canonical設定',
array(
$this,
'insert_meta_fields'
),
$target_post,
'normal');
}
}
// カスタムフィールドの入力エリア
public function insert_meta_fields() {
global $post;
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) . '"
placeholder="' . $this->set_default_post_canonical_url($post->ID) . '" />
</div>
</div>';
}
// カスタムフィールドの値を保存
public function save_meta_fields($post_id) {
if (!empty($_POST[MTEE_CANONICAL_URL])) { //meta_keywordsが入力されている場合
update_post_meta($post_id, MTEE_CANONICAL_URL, $_POST[MTEE_CANONICAL_URL]); //値を保存
} else { //未入力の場合は値を削除
delete_post_meta($post_id, MTEE_CANONICAL_URL);
}
}
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;
}
//-------------------------------------------------------------------------------------------
// タクソノミーのカスタムフィールド設定
//-------------------------------------------------------------------------------------------
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'));
}
}
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;
}
public function add_tax_term_fields($tag) {
$form = '<div class="form-field">Canonical URL<br>##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">Canonical URL</th>
<td>##CONTENTS##</td>
</tr>';
echo $this->insert_term_meta_fields($tag, $form);
}
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);
}
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]);
}
}
}
}
+124
View File
@@ -0,0 +1,124 @@
<?php
if (!defined('ABSPATH')) {
exit;
} // Exit if accessed directly
if (!class_exists('mtee_meta_output_canonical')) {
/**
* Class mtee_meta_output_canonical
*/
class mtee_meta_output_canonical {
public function __construct() {
add_action('wp_head', array($this, 'set_canonical_url'));
}
public function set_canonical_url() {
global $post;
$type = '';
$id = null;
if (is_post_type_archive()) {
$type = 'custom_post_archive';
} elseif (is_category()) {
$id = get_query_var('cat');
$type = 'cat';
} elseif (is_tag()) {
$id = get_query_var('tag_id');
$type = 'tag';
} elseif (is_tax()) {
$id = get_queried_object()->term_id;
$type = 'tax';
} elseif (is_home() || is_front_page()) {
$type = 'top_page';
} elseif (is_page() || is_single()) {
$id = $post->ID;
$type = 'posts';
}
echo $this->get_canonical_data($id, $type);
}
public function get_canonical_data($id, $type) {
if (empty($type)) {
return;
}
$canonical = '';
if ($type == 'top_page') {
$canonical = $this->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 '<link rel="canonical" href="' . $canonical . '">' . 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((int)$id);
}
return $canonical;
}
}
}
+219
View File
@@ -0,0 +1,219 @@
<?php
if (!defined('ABSPATH')) {
exit;
} // Exit if accessed directly
if (!class_exists('mtee_meta_output_keydesc')) {
include MTEE_TRAIT_DIR . 'mtee_meta_desc_trait.php';
class mtee_meta_output_keydesc {
use mtee_meta_desc_trait;
private $site_name;
private $description;
private $metas = array();
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'));
}
public function post_output_add_metas() {
$this->create_post_output_add_metas();
echo implode(PHP_EOL, $this->metas) . PHP_EOL;
}
public function create_post_output_add_metas() {
if (is_home() || is_front_page()) {
$type = 'top_page';
} elseif (is_post_type_archive()) {
$type = 'custom_post_archive';
} elseif (is_tax()) {
$type = get_queried_object()->taxonomy;
} elseif (is_page() || is_single()) {
$type = get_post_type();
} elseif (is_category()) {
$type = 'category';
} elseif (is_tag()) {
$type = 'post_tag';
}
if (isset($type)) {
$this->metas = $this->post_output_view_metas($type);
}
if (count($this->metas) == 0) {
$this->metas = $this->create_default_keywords_description();
}
}
public 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 = array(
MTEE_NAME_KEYWORDS => str_replace('、', ',', $this->post_output_get_meta_keywords($type)),
MTEE_NAME_DESCRIPTION => $this->post_output_get_meta_desc($type),
);
return $this->create_meta_tags($meta_data);
}
public function post_output_get_meta_keywords($type) {
global $post;
if ($type == 'top_page') {
$meta_key_words = get_option('_mtee')['top_page']['keywords'];
} elseif ($type == 'custom_post_archive') {
$custom_post_name = get_post_type_object(get_post_type())->name;
$meta_key_words = get_option('_mtee')['custom_post'][$custom_post_name]['keywords'];
} elseif ($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);
} else {
$meta_key_words = get_post_meta($post->ID, MTEE_NAME_KEYWORDS, true);
}
return $meta_key_words;
}
public function create_default_keywords_description(): array {
$this->description .= $this->create_default_description();
$meta_data = array(
MTEE_NAME_KEYWORDS => implode(',', $this->create_default_keywords()),
MTEE_NAME_DESCRIPTION => $this->description,
);
return $this->create_meta_tags($meta_data);
}
public function create_default_keywords(): array {
$type = '';
$title = '';
if (is_category()) {
$type = 'category';
$title = single_cat_title('', false);
} elseif (is_tag()) {
$type = 'tag';
$title = single_cat_title('', false);
} elseif (is_tax()) {
$type = 'tax';
$title = single_term_title('', false);
} elseif (is_post_type_archive()) {
$type = 'custom_post_archive';
$title = post_type_archive_title('', false);
} elseif (is_single()) {
$type = 'post';
$title = get_the_title();
} elseif (is_page()) {
$type = 'page';
$title = get_the_title();
}
$custom_keywords_temp = get_option('_mtee')['keywords_tmp'];
if (empty($custom_keywords_temp[$type])) {
return $this->get_keywords_data($type, $title);
}
return $this->get_custom_template_keywords_data($custom_keywords_temp, $type, $title);
}
public function get_keywords_data($type, $keyword): array {
$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): array {
$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], '<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;
}
}
}
@@ -0,0 +1,94 @@
<?php
if (!defined('ABSPATH')) {
exit;
} // Exit if accessed directly
if (!class_exists('mtee_meta_output_noindexnofollow')) {
/**
* Class mtee_meta_output_noindexnofollow
*/
class mtee_meta_output_noindexnofollow {
public function __construct() {
add_action('wp_head', array($this, 'set_noindex_nofollow'));
}
public function set_noindex_nofollow() {
global $post;
$type = '';
$id = null;
if (is_post_type_archive()) {
$type = 'custom_post_archive';
} elseif (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()) {
$type = 'top_page';
} elseif (is_page() || is_single()) {
$id = $post->ID;
$type = 'posts';
}
echo $this->get_noindex_nofollow_data($id, $type);
}
public 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" />';
}
}
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,
);
}
}
}
+255
View File
@@ -0,0 +1,255 @@
<?php
if (!defined('ABSPATH')) {
exit;
} // Exit if accessed directly
if (!class_exists('mtee_meta_output_ogp')) {
class mtee_meta_output_ogp {
use mtee_meta_desc_trait;
public $site_name = '';
public $ogp_type = '';
public $ogp_description = '';
public $ogp_title = '';
public $ogp_url = '';
public $ogp_img = '';
public function __construct() {
$this->site_name = get_bloginfo('name');
//GOPのプレフィックスを出力する
add_filter('language_attributes', array($this, 'add_html_ogp_prefix'));
add_action('wp_head', array($this, 'create_ogp_tag'));
}
/**
* GOPのプレフィックスを設定する
* @param $output
* @return string
*/
public function add_html_ogp_prefix($output): string {
$output .= $this->create_ogp_prefix();
return $output;
}
private function create_ogp_prefix(): string {
return ' prefix="og: https://ogp.me/ns#"';
}
public function create_ogp_tag() {
$this->create_ogp_type();
$this->create_ogp_title();
$this->create_ogp_description();
$this->create_ogp_image();
$this->create_ogp_url();
echo $this->set_ogp_tag();
}
public function set_ogp_tag() {
$tags = '<meta property="og:title" content="' . $this->ogp_title . '" />' . PHP_EOL;
$tags .= '<meta property="og:description" content="' . $this->ogp_description . '" />' . PHP_EOL;
$tags .= '<meta property="og:type" content="' . $this->ogp_type . '" />' . PHP_EOL;
$tags .= '<meta property="og:url" content="' . $this->ogp_url . '" />' . PHP_EOL;
if (!empty($this->ogp_img)) {
$tags .= '<meta property="og:image" content="' . $this->ogp_img . '" />' . PHP_EOL;
}
$tags .= '<meta property="og:site_name" content="' . $this->site_name . '" />' . PHP_EOL;
// $tags .= '<meta name="twitter:card" content="summary_large_image" />' . PHP_EOL;
// $tags .= '<meta name="twitter:site" content="ツイッターのアカウント名" />' . PHP_EOL;
$tags .= '<meta property="og:locale" content="' . $this->get_ogp_locale() . '" />' . "\n";
return $tags;
}
public function get_ogp_locale(): string {
$locale = get_locale();
if (strlen($locale) == 2) {
if ($locale === "ja")
return "ja_JP";
else
return strtolower($locale) . '_' . strtoupper($locale);
}
}
public function create_ogp_type() {
if (is_home() || is_front_page()) {
$this->ogp_type = 'website';
} else {
$this->ogp_type = 'article';
}
}
public function create_ogp_title() {
global $post;
if (is_home() || is_front_page()) {
$this->ogp_title = get_option('_mtee')['top_page']['ogp_title'];
} elseif (is_post_type_archive()) {
$custom_post_name = get_post_type_object(get_post_type())->name;
$this->ogp_title = get_option('_mtee')['custom_post'][$custom_post_name]['ogp_title'];
} elseif (is_category() || is_tag() || is_tax()) {
$queried_object = get_queried_object();
$this->ogp_title = get_term_meta($queried_object->term_id, MTEE_OGP_TITLE, true);
} elseif (is_page() || is_single()) {
$this->ogp_title = get_post_meta($post->ID, MTEE_OGP_TITLE, true);
}
if (empty($this->ogp_title)) {
$this->create_default_title();
}
}
public function create_default_title() {
if (is_category()) {
$this->ogp_title = single_cat_title('', false);
} elseif (is_tag()) {
$this->ogp_title = single_cat_title('', false);
} elseif (is_tax()) {
$this->ogp_title = single_term_title('', false);
} elseif (is_post_type_archive()) {
$this->ogp_title = post_type_archive_title('', false);
} elseif (is_single() || is_page()) {
$this->ogp_title = get_the_title();
} elseif (is_home() || is_front_page()) {
$this->ogp_title = $this->site_name;
}
}
public function create_ogp_description() {
$this->create_input_description();
if (empty($this->ogp_description)) {
$this->set_default_description();
}
}
public function create_input_description() {
global $post;
if (is_home() || is_front_page()) {
$this->ogp_description = get_option('_mtee')['top_page']['ogp_description'];
} elseif (is_post_type_archive()) {
$custom_post_name = get_post_type_object(get_post_type())->name;
$this->ogp_description = get_option('_mtee')['custom_post'][$custom_post_name]['ogp_description'];
} elseif (is_category() || is_tag() || is_tax()) {
$queried_object = get_queried_object();
$this->ogp_description = get_term_meta($queried_object->term_id, MTEE_OGP_DESC, true);
} elseif (is_page() || is_single()) {
$this->ogp_description = get_post_meta($post->ID, MTEE_OGP_DESC, true);
}
}
public function set_default_description() {
$this->ogp_description = $this->site_name . MTEE_META_DESC_PARTICLE;
$type = '';
$ogp_desc = '';
if (is_home() || is_front_page()) {
$type = 'top_page';
} elseif (is_post_type_archive()) {
$type = 'custom_post_archive';
} elseif (is_tax()) {
$type = get_queried_object()->taxonomy;
} elseif (is_page() || is_single()) {
$type = get_post_type();
} elseif (is_category()) {
$type = 'category';
} elseif (is_tag()) {
$type = 'post_tag';
}
$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';
}
if (!empty($type)) {
$this->ogp_description .= $this->post_output_get_meta_desc($type);
}
if (empty($ogp_desc)) {
$this->ogp_description .= $this->create_default_description();
}
}
public function create_ogp_url() {
global $post;
if (is_category()) {
$this->ogp_url = get_category_link(get_query_var('cat'));
} elseif (is_tag()) {
$this->ogp_url = get_tag_link(get_query_var('tag_id'));
} elseif (is_tax()) {
$this->ogp_url = get_term_link((int)get_queried_object()->term_id);
} elseif (is_post_type_archive()) {
$custom_post_name = get_post_type_object(get_post_type())->name;
$this->ogp_url = get_post_type_archive_link($custom_post_name);
} elseif (is_single() || is_page()) {
$this->ogp_url = get_permalink($post->ID);
global $page, $paged;
if ($paged >= 2 || $page >= 2) {
$this->ogp_url .= 'page/' . max($paged, $page) . '/';
}
} elseif (is_home() || is_front_page()) {
$this->ogp_url = get_bloginfo('url');
}
}
public function create_ogp_image() {
global $post;
if (is_post_type_archive()) {
$this->set_custom_post_archive_ogp_img();
} elseif (is_category()) {
$this->set_category_ogp_img(get_query_var('cat'));
} elseif (is_tag()) {
$this->set_tag_ogp_img(get_query_var('tag_id'));
} elseif (is_tax()) {
$this->set_tax_ogp_img(get_queried_object()->term_id);
} elseif (is_home() || is_front_page()) {
$this->set_top_page_ogp_img();
} elseif (is_page() || is_single()) {
$this->set_post_ogp_img($post->ID);
}
}
public function set_top_page_ogp_img() {
$id = get_option('_mtee')['top_page']['ogp_img'];
$this->get_thumbnail($id);
}
public function set_custom_post_archive_ogp_img() {
$custom_post_name = get_post_type_object(get_post_type())->name;
$id = get_option('_mtee')['custom_post'][$custom_post_name]['ogp_img'];
$this->get_thumbnail($id);
}
public function set_post_ogp_img($id) {
$id = get_post_meta($id, MTEE_OGP_IMG, true);
$this->get_thumbnail($id);
}
public function set_category_ogp_img($id) {
$id = get_term_meta($id, MTEE_OGP_IMG, true);
$this->get_thumbnail($id);
}
public function set_tag_ogp_img($id) {
$id = get_term_meta($id, MTEE_OGP_IMG, true);
$this->get_thumbnail($id);
}
public function set_tax_ogp_img($id) {
$id = get_term_meta($id, MTEE_OGP_IMG, true);
$this->get_thumbnail($id);
}
public function get_thumbnail($id) {
if (!empty($id)) {
$this->ogp_img = wp_get_attachment_url($id);
} elseif (has_post_thumbnail($id)) {
$this->ogp_img = wp_get_attachment_url(get_post_thumbnail_id($id));
}
}
}
}
+154
View File
@@ -0,0 +1,154 @@
<?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'));
}
}
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;
}
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]);
}
}
}
}
+115
View File
@@ -0,0 +1,115 @@
<?php
if (!defined('ABSPATH')) {
exit;
} // Exit if accessed directly
if (!class_exists('mtee_ogp_post_setting')) {
/**
* Class mtee_ogp_post_setting
*/
class mtee_ogp_post_setting {
private $options;
public function __construct($options) {
$this->options = $options;
add_action('admin_menu', array($this, 'add_meta_fields'));
add_action('save_post', array($this, 'save_meta_fields'));
add_action('wp_enqueue_scripts', array($this, 'my_media_script'));
}
function my_media_script() {
wp_enqueue_media();
}
//add_meta_box(表示される入力ボックスのHTMLのID, ラベル, 表示する内容を作成する関数名, 投稿タイプ, 表示方法)
public function add_meta_fields() {
$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(
'ogp_setting',
'OGP設定',
array(
$this,
'insert_meta_fields'),
$target_post,
'normal'
);
}
}
// カスタムフィールドの入力エリア
public function insert_meta_fields() {
global $post;
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) . '"
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) . '"
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 class="' . MTEE_OGP_IMG . '" name="' . MTEE_OGP_IMG . '" type="hidden" value="' . get_post_meta($post->ID, MTEE_OGP_IMG, true) . '" />
<input type="button" class="select_ogp_img" name="select_ogp_img" value="選択" />
<input type="button" class="clear_ogp_img" name="clear_ogp_img" value="クリア" />
<div class="ogp_media">' . $this->set_ogp_thumb($post->ID) . '</div>
</div>
</div>
<script>
var ogp_img_name = ' . "'" . MTEE_OGP_IMG . "'" . '
</script>';
}
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 src="' . wp_get_attachment_image_src($ogp_thumb, 'thumbnail')[0] . '">';
}
return '';
}
// カスタムフィールドの値を保存
public function save_meta_fields($post_id) {
if (!empty($_POST[MTEE_OGP_TITLE])) { //meta_keywordsが入力されている場合
update_post_meta($post_id, MTEE_OGP_TITLE, $_POST[MTEE_OGP_TITLE]); //値を保存
} else { //未入力の場合は値を削除
delete_post_meta($post_id, MTEE_OGP_TITLE);
}
if (!empty($_POST[MTEE_OGP_DESC])) {
update_post_meta($post_id, MTEE_OGP_DESC, $_POST[MTEE_OGP_DESC]);
} else {
delete_post_meta($post_id, MTEE_OGP_DESC);
}
if (!empty($_POST[MTEE_OGP_IMG])) {
update_post_meta($post_id, MTEE_OGP_IMG, $_POST[MTEE_OGP_IMG]);
} else {
delete_post_meta($post_id, MTEE_OGP_IMG);
}
}
}
}
+158
View File
@@ -0,0 +1,158 @@
<?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')); //編集ページ用フック
add_action('wp_enqueue_scripts', array($this, 'my_media_script'));
}
function my_media_script() {
wp_enqueue_media();
}
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) {
$input_values = $this->set_input_values($tag);
echo '
<div class="form-field">
OGP title<br>
<input type="text" name="' . MTEE_OGP_TITLE . '"
value=""
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=""
placeholder="' . $input_values['desc_pl'] . '"
class="tax-meta-field" />
</div>
<div class="form-field">
image<br>
<input class="' . MTEE_OGP_IMG . '" name="' . MTEE_OGP_IMG . '" type="hidden" value="" />
<input type="button" class="select_ogp_img" name="select_ogp_img" value="選択" />
<input type="button" class="clear_ogp_img" name="clear_ogp_img" value="クリア" />
<div class="ogp_media"></div>
<script>
var ogp_img_name = ' . "'" . MTEE_OGP_IMG . "'" . '
</script>
</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 class="mtee-label">title:</label>
<input type="text" name="' . MTEE_OGP_TITLE . '"
value="' . $input_values['title'] . '"
placeholder="' . $input_values['title_pl'] . '"
class="tax-meta-field" />
<label class="mtee-label">description:</label>
<input type="text" name="' . MTEE_OGP_DESC . '"
value="' . $input_values['desc'] . '"
placeholder="' . $input_values['desc_pl'] . '"
class="tax-meta-field" />
<label class="mtee-label">image:</label>
<input class="' . MTEE_OGP_IMG . '" name="' . MTEE_OGP_IMG . '" type="hidden" value="' . get_post_meta($tag->term_id, MTEE_OGP_IMG, true) . '" />
<input type="button" class="select_ogp_img" name="select_ogp_img" value="選択" />
<input type="button" class="clear_ogp_img" name="clear_ogp_img" value="クリア" />
<div class="ogp_media">' . $this->set_ogp_thumb($tag->term_id) . '</div>
<script>
var ogp_img_name = ' . "'" . MTEE_OGP_IMG . "'" . '
</script>
</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_post_meta($id, MTEE_OGP_IMG, true);
if (!empty($ogp_thumb)) {
return '<img src="' . wp_get_attachment_image_src($ogp_thumb, 'thumbnail')[0] . '">';
}
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 (!empty($_POST[MTEE_OGP_IMG])) {
update_post_meta($term_id, MTEE_OGP_IMG, $_POST[MTEE_OGP_IMG]);
} else {
delete_post_meta($term_id, MTEE_OGP_IMG);
}
}
}
}
+99
View File
@@ -0,0 +1,99 @@
<?php
if (!defined('ABSPATH')) {
exit;
} // Exit if accessed directly
if (!class_exists('mtee_post_setting')) {
/**
* Class mtee_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, ラベル, 表示する内容を作成する関数名, 投稿タイプ, 表示方法)
$target_posts = $this->get_all_post_type();
foreach ($target_posts as $target_post) {
add_meta_box(
'meta_setting',
'meta設定',
array(
$this,
'insert_meta_fields'),
$target_post,
'normal'
);
}
}
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) . '"
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) . '"
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 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;
}
}
}
+139
View File
@@ -0,0 +1,139 @@
<?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) {
$input_values = $this->set_input_values($tag);
echo '
<div class="form-field">
meta keywords<br>
<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="' . $input_values['desc'] . '"
placeholder="' . $input_values['desc_pl'] . '"
class="tax-meta-field" />
</div>
';
}
function insert_term_meta_edit_fields($tag) {
$input_values = $this->set_input_values($tag);
echo '
<tr class="form-field">
<th scope="row">meta keywords<br>meta description</th>
<td>
<label class="mtee-label">meta keywords:</label>
<input type="text" name="' . MTEE_NAME_KEYWORDS . '"
value="' . $input_values['keywords'] . '"
placeholder="' . $input_values['keyword_pl'] . '"
class="tax-meta-field" />
<label class="mtee-label">meta description:</label>
<input type="text" name="' . MTEE_NAME_DESCRIPTION . '"
value="' . $input_values['desc'] . '"
placeholder="' . $input_values['desc_pl'] . '"
class="tax-meta-field" />
</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)) {
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]);
}
}
}
}
+56
View File
@@ -0,0 +1,56 @@
<?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->disabled_wp_version_view();
$this->disabled_asset_version_view();
$this->disabled_emoji();
$this->disabled_rss_feed();
}
public function disabled_wp_version_view() {
if ($this->options['wp_ver_disabled'] == 1) {
remove_action('wp_head', 'wp_generator');
}
}
public function disabled_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'));
}
}
public function remove_src_wp_ver($dep) {
$dep->default_version = '';
}
public function disabled_emoji() {
if ($this->options['emoji_disabled'] == 1) {
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');
}
}
public function disabled_rss_feed() {
if ($this->options['rss_disabled'] == 1) {
//RSS Feedを停止
remove_action('do_feed_rdf', 'do_feed_rdf');
remove_action('do_feed_rss', 'do_feed_rss');
remove_action('do_feed_rss2', 'do_feed_rss2');
remove_action('do_feed_atom', 'do_feed_atom');
//RSSリンクを無効化
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'feed_links_extra', 3);
}
}
}
}
+5
View File
@@ -1,11 +1,16 @@
<?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 = 'ページです。';
+17 -15
View File
@@ -40,7 +40,6 @@ h2 {
display: block;
}
.mtee_box_border {
border-top: 1px solid #ccc;
}
@@ -63,19 +62,6 @@ h2 {
margin: 0
}
.mtee-example {
width: 95%;
margin-bottom: 2em;
padding: 1em;
background: #f9f9f9;
border: 1px solid #666;
border-radius: 6px;
}
.mtee-example h4 {
margin: 0 0 .5em;
}
.meta_noindex_nofollow_box {
display: flex;
margin-bottom: 2em;
@@ -114,7 +100,8 @@ h2 {
margin-left: 0;
}
.mtee_description_tmp {
.mtee_description_tmp,
.mtee_keywords_tmp {
width: 100%;
}
@@ -123,6 +110,21 @@ h2 {
font-style: italic;
}
.disabled_status {
display: block;
font-size: .8em;
color: #f35;
}
label.mtee-label {
display: block;
margin: .5em 0 0;
}
.ogp_media {
margin-top: 1em;
}
@media screen and (max-width: 768px) {
.mtee_description_tmp_list {
display: block;
+92 -9
View File
@@ -1,20 +1,103 @@
jQuery(function ($) {
nab_menu();
media_uploader();
function nab_menu() {
let menu_list = $('.mtee_tab_menu li');
let content_box = $('.mtee_tab_box');
menu_list.on('click', function () {
if (!$(this).hasClass('en')) {
let index = $(this).index();
$('.mtee_tab_menu li').removeClass('en');
$(this).addClass('en');
content_box.hide();
$('.mtee_tab_box:eq(' + index + ')').show();
}
});
init();
click_menu();
function init() {
let current_nav = $('#mtee_set_nav').val();
let current_index = menu_list.index($('#' + current_nav));
$('.mtee_tab_menu li').removeClass('en');
$('#' + current_nav).addClass('en');
content_box.hide();
$('.mtee_tab_box:eq(' + current_index + ')').show();
}
function click_menu() {
menu_list.on('click', function () {
if (!$(this).hasClass('en')) {
let index = $(this).index();
$('.mtee_tab_menu li').removeClass('en');
$(this).addClass('en');
content_box.hide();
$('#mtee_set_nav').val($(this).attr('id'));
$('.mtee_tab_box:eq(' + index + ')').show();
}
});
}
}
function media_uploader() {
// let custom_uploader;
// let thumb = $('.ogp_media');
let select_ogp = $('.select_ogp_img');
let clear_ogp = $('.clear_ogp_img');
let set_media = [];
select_ogp.click(function (e) {
e.preventDefault();
let media_index = $('.select_ogp_img').index(this);
if (set_media[media_index]) {
set_media[media_index].open();
return;
}
set_media[media_index] = build_media();
set_media[media_index].on("select", function () {
let images = set_media[media_index].state().get("selection");
let thumb = $('.ogp_media:eq(' + media_index + ')');
/* file の中に選択された画像の各種情報が入っている */
images.each(function (file) {
/* テキストフォームと表示されたサムネイル画像があればクリア */
$('.' + ogp_img_name + ':eq(' + media_index + ')').val('');
thumb.empty();
/* テキストフォームに画像の ID を表示 */
$('.' + ogp_img_name + ':eq(' + media_index + ')').val(file.id);
/* プレビュー用に選択されたサムネイル画像を表示 */
thumb.append('<img src="' + file.attributes.sizes.thumbnail.url + '" />');
});
});
set_media[media_index].open();
});
/* クリアボタンを押した時の処理 */
clear_ogp.click(function () {
let clear_index = $('.clear_ogp_img').index(this);
let thumb = $('.ogp_media:eq(' + clear_index + ')');
$('.' + ogp_img_name + ':eq(' + clear_index + ')').val('');
thumb.empty();
});
function build_media() {
return wp.media({
title: "画像を選択",
/* ライブラリの一覧は画像のみにする */
library: {
type: "image"
},
button: {
text: "画像選択"
},
/* 選択できる画像は 1 つだけにする */
multiple: false
});
}
}
});
+56 -22
View File
@@ -7,49 +7,83 @@ Version: 1.0
*/
/*
Todo:meta keywords & description
・キーワードの雛形設定
Todo:OGPタグ
・OGPタグを追加する
<各OGP画像の保存>
・投稿のOGP用画像 => post_meta
・各タクソノミーのOGP画像 => term_meta
・トップ、カスタム投稿アーカイブ => wp_options
画像出力
facebook
<meta property="fb:app_id" content="[FacebookアプリのID]" />
Twitter
*/
include_once 'config.php';
include_once MTEE_CLASS_DIR . 'mtee.php';
/**
* CSSを設定
*/
//admin css/js setting
add_action('admin_enqueue_scripts', function () {
$plugin_url = plugin_dir_url(__FILE__);
wp_enqueue_style('mtee_style', $plugin_url . 'css/mtee.css');
wp_enqueue_script('mtee_js', $plugin_url . 'js/mtee.js', 'jquery');
//メディアアップローダー
wp_enqueue_media();
});
$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';
// 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_meta_output_keydesc.php';
new mtee_tax_setting($options);
new mtee_post_setting($options);
new mtee_meta_output;
new mtee_meta_output_keydesc();
}
if ($mtee->is_noindex_nofollow_disable()) {
require_once MTEE_CLASS_DIR . 'mtee-noindexnofollow-setting.php';
// 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_meta_output_canonical.php';
new mtee_canonical_setting($options);
new mtee_meta_output_canonical();
}
// enabled my OGP tag
if ($mtee->is_enable('ogp_setting')) {
include MTEE_TRAIT_DIR . 'mtee_meta_desc_trait.php';
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();
}
//enabled my noindex, nofollow
if ($mtee->is_enable('noindex_nofollow')) {
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();
}
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);
//disabled WP version, WP JS/CSS version, Emoji, RSS Feed
$disabled_checks = array(
'asset_ver_disabled',
'asset_ver_disabled',
'emoji_disabled',
'rss_disabled'
);
foreach ($disabled_checks as $disabled_check) {
if ($mtee->is_disable($disabled_check)) {
require_once MTEE_CLASS_DIR . 'mtee_version_setting.php';
new mtee_version_setting($options);
break;
}
}
+137 -182
View File
@@ -1,93 +1,98 @@
<?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();
$mtee_set_nav = $_POST['mtee_set_nav'] ?? 'nav_metas';
$enabled = $this->get_key_setting('enabled');
$noindex_nofollow = $this->get_key_setting('noindex_nofollow');
$ogp_setting = $this->get_key_setting('ogp_setting');
$canonical_setting = $this->get_key_setting('canonical_setting');
$wp_ver_disabled = $this->get_key_setting('wp_ver_disabled');
$asset_ver_disabled = $this->get_key_setting('asset_ver_disabled');
$emoji_disabled = $this->get_key_setting('emoji_disabled');
$rss_disabled = $this->get_key_setting('rss_disabled');
?>
<div class="wrap">
<h2>meta keyword, description / バージョン情報 設定</h2>
<nav class="mtee_tab_menu">
<ul>
<li class="en">全体設定</li>
<li>ページ設定</li>
<li id="nav_metas" class="en">メタキーワード・ディスクリプション</li>
<li id="nav_ogp">OGP</li>
<li id="nav_noindex">noindexnofollow</li>
<li id="nav_canonical">Canonical</li>
<li id="nav_version">バージョン情報等</li>
</ul>
</nav>
<form action="" method="post">
<?php wp_nonce_field('check_options'); ?>
<input type="hidden" id="mtee_set_nav" name="mtee_set_nav" value="<?php echo $mtee_set_nav; ?>">
<div class="mtee_tab_box">
<div class="mtee-form-box">
<h2>キーワード・ディスクリプション</h2>
<h2>メタキーワード・ディスクリプション</h2>
<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) : ?>
<?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; ?>
<aside class="mtee-example">
<h4>keywordsの初期表示</h4>
<div class="mtee-form-box mtee_box_border">
<h3>meta keywords テンプレート設定</h3>
<p>個別設定していない投稿やカテゴリー等は、このテンプレートを適用します。</p>
<?php
$post_meta_keywords_tmp = get_option('_mtee')['keywords_tmp']['post'] ?? '';
$page_meta_keywords_tmp = get_option('_mtee')['keywords_tmp']['page'] ?? '';
$cat_meta_keywords_tmp = get_option('_mtee')['keywords_tmp']['category'] ?? '';
$tag_meta_keywords_tmp = get_option('_mtee')['keywords_tmp']['tag'] ?? '';
$tax_meta_keywords_tmp = get_option('_mtee')['keywords_tmp']['tax'] ?? '';
?>
<dl class="mtee_description_tmp_list">
<dt>投稿</dt>
<dd>
<input class="mtee_keywords_tmp" type="text" name="_mtee[keywords_tmp][post]"
value="<?php echo $post_meta_keywords_tmp; ?>"
placeholder="##title##,##category##,##tag##,##custom_tax##,##description##,##site_name##"
</dd>
<dt>ページ</dt>
<dd>
<input class="mtee_keywords_tmp" type="text" name="_mtee[keywords_tmp][page]"
value="<?php echo $page_meta_keywords_tmp; ?>"
placeholder="##title##,##description##,##site_name##"
</dd>
<dt>カテゴリー</dt>
<dd>
<input class="mtee_keywords_tmp" type="text" name="_mtee[keywords_tmp][category]"
value="<?php echo $cat_meta_keywords_tmp; ?>"
placeholder="##title##,##description##,##site_name##">
</dd>
<dt>タグ</dt>
<dd>
<input class="mtee_keywords_tmp" type="text" name="_mtee[keywords_tmp][tag]"
value="<?php echo $tag_meta_keywords_tmp; ?>"
placeholder="##title##,##description##,##site_name##">
</dd>
<dt>カスタム分類</dt>
<dd>
<input class="mtee_keywords_tmp" type="text" name="_mtee[keywords_tmp][tax]"
value="<?php echo $tax_meta_keywords_tmp; ?>"
placeholder="##title##,##description##,##site_name##">
</dd>
</dl>
<ul>
<li>[各ページ、カテゴリー、タグ等のタイトル],<?php
if (!empty(get_bloginfo('description'))) {
echo get_bloginfo('description') . ',';
}
echo get_bloginfo('name');
?>
<li><b>共通</b>
<ul>
<li>##title##:投稿、ページ、カテゴリー等のタイトル</li>
<li>##site_name##:サイト名(<?php echo get_bloginfo('name'); ?></li>
<li>##site_description##:サイトの説明(<?php echo get_bloginfo('description'); ?></li>
</ul>
</li>
<li><b>投稿</b>
<ul>
<li>##category##:投稿のカテゴリー</li>
<li>##tag##:投稿のタグ</li>
<li>##custom_tax##:投稿のカスタム分類</li>
</ul>
</li>
</ul>
</aside>
</div>
<div class="mtee-form-box mtee_box_border">
<h3>meta description テンプレート設定</h3>
<p>個別設定していない投稿やカテゴリー等は、このテンプレートを適用します。</p>
@@ -125,15 +130,66 @@ $noindex_nofollow = $this->get_noindex_nofollow();
</dl>
<ul>
<li>##site_name##:サイト名(<?php echo get_bloginfo('name'); ?></li>
<li>##title##:出力対象(投稿、ページ、カテゴリー等)毎のタイトル</li>
<li>##site_description##:サイトの説明(<?php echo get_bloginfo('description'); ?></li>
<li>##title##:投稿、ページ、カテゴリー等のタイトル</li>
</ul>
</div>
<div class="mtee-form-box mtee_box_border">
<h3>個別設定 NOINDEXNOFOLLOW</h3>
<?php include 'pages_meta.php'; ?>
<p class="submit"><input type="submit" name="Submit" class="button-primary" value="変更を保存"/></p>
</div>
<div class="mtee_tab_box">
<div class="mtee-form-box">
<h2>OGP</h2>
<label>
<input type="hidden" name="_mtee[noindex_nofollow]" value="0">
<input type="hidden" name="_mtee[ogp_setting]" value="0">
<input type="checkbox"
name="_mtee[noindex_nofollow]" <?php checked($noindex_nofollow, 1); ?>
name="_mtee[ogp_setting]" <?php checked($ogp_setting, 1); ?>
value="1">有効(デフォルトのog:descriptionはmeta descriptionになります)
</label>
</div>
<?php include 'pages_ogp.php'; ?>
<p class="submit"><input type="submit" name="Submit" class="button-primary" value="変更を保存"/></p>
</div>
<div class="mtee_tab_box">
<h2>noindexnofollow</h2>
<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>
<?php include 'pages_noindexnofollow.php'; ?>
</div>
<div class="mtee_tab_box">
<div class="mtee-form-box mtee_box_border">
<h3>Canonical URL 出力</h3>
<label>
<input type="hidden" name="_mtee[canonical_setting]" value="0">
<input type="checkbox"
name="_mtee[canonical_setting]" <?php checked($canonical_setting, 1); ?>
value="1">有効
</label>
</div>
<?php include 'pages_canonical.php'; ?>
<p class="submit"><input type="submit" name="Submit" class="button-primary" value="変更を保存"/></p>
</div>
<div class="mtee_tab_box">
<h2>バージョン情報等</h2>
<div class="mtee-form-box mtee_box_border">
<h3>RSS</h3>
<label>
<input type="hidden" name="_mtee[rss_disabled]" value="0">
<input type="checkbox"
name="_mtee[rss_disabled]" <?php checked($rss_disabled, 1); ?>
value="1">出力しない
</label>
</div>
<div class="mtee-form-box mtee_box_border">
<h3>Canonical URL 出力</h3>
<label>
<input type="hidden" name="_mtee[canonical_setting]" value="0">
<input type="checkbox"
name="_mtee[canonical_setting]" <?php checked($canonical_setting, 1); ?>
value="1">有効
</label>
</div>
@@ -147,7 +203,7 @@ $noindex_nofollow = $this->get_noindex_nofollow();
</label>
</div>
<div class="mtee-form-box mtee_box_border">
<h3>CSS / JSバージョン情報</h3>
<h3>CSS/JSバージョン情報</h3>
<label>
<input type="hidden" name="_mtee[asset_ver_disabled]" value="0">
<input type="checkbox"
@@ -155,116 +211,15 @@ $noindex_nofollow = $this->get_noindex_nofollow();
value="1">削除
</label>
</div>
<p class="submit"><input type="submit" name="Submit" class="button-primary" value="変更を保存"/></p>
</div>
<div class="mtee_tab_box">
<h2 class="mtee_page_title">トップページ</h2>
<?php
$keywords = $opt['top_page']['keywords'] ?? '';
$description = $opt['top_page']['description'] ?? '';
$noindex = $opt['top_page']['noindex'] ?? '0';
$nofollow = $opt['top_page']['nofollow'] ?? '0';
?>
<div class="mtee-form-box">
<table class="form-table">
<tr valign="top">
<th>meta keywords</th>
<td><input class="top_page_keywords" type="text" name="_mtee[top_page][keywords]"
value="<?php echo $keywords; ?>" placeholder="キーワード1,キーワード2,キーワード3">
<br>キーワードはカンマ(,)区切りで入力してください
</td>
</tr>
<tr valign="top">
<th>meta description</th>
<td><input class="top_page_description" type="text" name="_mtee[top_page][description]"
value="<?php echo $description; ?>"
placeholder="<?php echo get_bloginfo('name'); ?>の<?php echo MTEE_META_DESC_TOP_BASE; ?>">
</td>
</tr>
<tr valign="top">
<th>noindex nofollow</th>
<td>
<div class="meta_noindex_nofollow_box">
<label>
<input type="hidden" name="_mtee[top_page][noindex]" value="0"/>
<input type="checkbox"
name="_mtee[top_page][noindex]" <?php checked($noindex, 1); ?>
value="1"/>
noindex
</label>
<label>
<input type="hidden" name="_mtee[top_page][nofollow]" value="0"/>
<input type="checkbox"
name="_mtee[top_page][nofollow]" <?php checked($nofollow, 1); ?>
value="1"/>
nofollow
</label>
</div>
</td>
</tr>
</table>
<div class="mtee-form-box mtee_box_border">
<h3>絵文字</h3>
<label>
<input type="hidden" name="_mtee[emoji_disabled]" value="0">
<input type="checkbox"
name="_mtee[emoji_disabled]" <?php checked($emoji_disabled, 1); ?>
value="1">表示しない
</label>
</div>
<?php if (count($register_targets['custom_posts']) > 0): ?>
<h2 class="mtee_page_title">カスタム投稿アーカイブ</h2>
<?php foreach ($register_targets['custom_posts'] as $custom_post): ?>
<?php
$keywords = $opt['custom_post'][$custom_post]['keywords'] ?? '';
$description = $opt['custom_post'][$custom_post]['description'] ?? '';
$noindex = $opt['custom_post'][$custom_post]['noindex'] ?? '0';
$nofollow = $opt['custom_post'][$custom_post]['nofollow'] ?? '0';
?>
<?php wp_nonce_field('check_options'); ?>
<div class="mtee-form-box">
<h3 class="mtee_page_archive_title">
<?php echo get_post_type_object($custom_post)->label; ?>
<?php echo $custom_post; ?>
</h3>
<table class="form-table">
<tr valign="top">
<th>meta keywords</th>
<td><input class="top_page_keywords" type="text"
name="_mtee[custom_post][<?php echo $custom_post; ?>][keywords]"
value="<?php echo $keywords; ?>" placeholder="キーワード1,キーワード2,キーワード3">
<br>キーワードはカンマ(,)区切りで入力してください
</td>
</tr>
<tr valign="top">
<th>meta description</th>
<td><input class="top_page_description" type="text"
name="_mtee[custom_post][<?php echo $custom_post; ?>][description]"
value="<?php echo $description; ?>"
placeholder="<?php echo get_bloginfo('name'); ?>の[カスタム投稿ラベル]<?php echo MTEE_META_DESC_ARCHIVE_BASE; ?>">
</td>
</tr>
<tr valign="top">
<th>noindex nofollow</th>
<td>
<div class="meta_noindex_nofollow_box">
<label>
<input type="hidden"
name="_mtee[custom_post][<?php echo $custom_post; ?>][noindex]"
value="0"/>
<input type="checkbox"
name="_mtee[custom_post][<?php echo $custom_post; ?>][noindex]" <?php checked($noindex, 1); ?>
value="1"/>
noindex
</label>
<label>
<input type="hidden"
name="_mtee[custom_post][<?php echo $custom_post; ?>][nofollow]"
value="0"/>
<input type="checkbox"
name="_mtee[custom_post][<?php echo $custom_post; ?>][nofollow]" <?php checked($nofollow, 1); ?>
value="1"/>
nofollow
</label>
</div>
</td>
</tr>
</table>
</div>
<?php endforeach; ?>
<?php endif; ?>
<p class="submit"><input type="submit" name="Submit" class="button-primary" value="変更を保存"/></p>
</div>
</form>
+42
View File
@@ -0,0 +1,42 @@
<h2 class="mtee_page_title mtee_box_border">トップページ</h2>
<?php
$canonical_url = $opt['top_page']['canonical'] ?? '';
?>
<div class="mtee-form-box">
<table class="form-table">
<tr valign="top">
<th>Canonical URL</th>
<td><input class="top_page_description" type="text"
name="_mtee[top_page][canonical]"
value="<?php echo $canonical_url; ?>"
placeholder="<?php echo get_bloginfo('url'); ?>">
</td>
</tr>
</table>
</div>
<?php if (count($register_targets['custom_posts']) > 0): ?>
<h2 class="mtee_page_title">カスタム投稿アーカイブ</h2>
<?php foreach ($register_targets['custom_posts'] as $custom_post): ?>
<?php
$canonical_url = $opt['custom_post'][$custom_post]['canonical'] ?? '';
?>
<?php wp_nonce_field('check_options'); ?>
<div class="mtee-form-box">
<h3 class="mtee_page_archive_title">
<?php echo get_post_type_object($custom_post)->label; ?>
<?php echo $custom_post; ?>
</h3>
<table class="form-table">
<tr valign="top">
<th>Canonical URL</th>
<td><input class="top_page_description" type="text"
name="_mtee[custom_post][<?php echo $custom_post; ?>][canonical]"
value="<?php echo $canonical_url; ?>"
placeholder="<?php echo get_post_type_archive_link($custom_post); ?>">
</td>
</tr>
</table>
</div>
<?php endforeach; ?>
<?php endif; ?>
+58
View File
@@ -0,0 +1,58 @@
<h2 class="mtee_page_title mtee_box_border">トップページ</h2>
<?php
$keywords = $opt['top_page']['keywords'] ?? '';
$description = $opt['top_page']['description'] ?? '';
?>
<div class="mtee-form-box">
<table class="form-table">
<tr valign="top">
<th>meta keywords</th>
<td><input class="top_page_keywords" type="text" name="_mtee[top_page][keywords]"
value="<?php echo $keywords; ?>" placeholder="キーワード1,キーワード2,キーワード3">
<br>キーワードはカンマ(,)区切りで入力してください
</td>
</tr>
<tr valign="top">
<th>meta description</th>
<td><input class="top_page_description" type="text" name="_mtee[top_page][description]"
value="<?php echo $description; ?>"
placeholder="<?php echo get_bloginfo('name'); ?>の<?php echo MTEE_META_DESC_TOP_BASE; ?>">
</td>
</tr>
</table>
</div>
<?php if (count($register_targets['custom_posts']) > 0): ?>
<h2 class="mtee_page_title">カスタム投稿アーカイブ</h2>
<?php foreach ($register_targets['custom_posts'] as $custom_post): ?>
<?php
$keywords = $opt['custom_post'][$custom_post]['keywords'] ?? '';
$description = $opt['custom_post'][$custom_post]['description'] ?? '';
?>
<?php wp_nonce_field('check_options'); ?>
<div class="mtee-form-box">
<h3 class="mtee_page_archive_title">
<?php echo get_post_type_object($custom_post)->label; ?>
<?php echo $custom_post; ?>
</h3>
<table class="form-table">
<tr valign="top">
<th>meta keywords</th>
<td><input class="top_page_keywords" type="text"
name="_mtee[custom_post][<?php echo $custom_post; ?>][keywords]"
value="<?php echo $keywords; ?>" placeholder="キーワード1,キーワード2,キーワード3">
<br>キーワードはカンマ(,)区切りで入力してください
</td>
</tr>
<tr valign="top">
<th>meta description</th>
<td><input class="top_page_description" type="text"
name="_mtee[custom_post][<?php echo $custom_post; ?>][description]"
value="<?php echo $description; ?>"
placeholder="<?php echo get_bloginfo('name'); ?>の[カスタム投稿ラベル]<?php echo MTEE_META_DESC_ARCHIVE_BASE; ?>">
</td>
</tr>
</table>
</div>
<?php endforeach; ?>
<?php endif; ?>
+74
View File
@@ -0,0 +1,74 @@
<h2 class="mtee_page_title mtee_box_border">トップページ</h2>
<?php
$noindex = $opt['top_page']['noindex'] ?? '0';
$nofollow = $opt['top_page']['nofollow'] ?? '0';
?>
<div class="mtee-form-box">
<table class="form-table">
<tr valign="top">
<th>noindex nofollow</th>
<td>
<div class="meta_noindex_nofollow_box">
<label>
<input type="hidden" name="_mtee[top_page][noindex]" value="0"/>
<input type="checkbox"
name="_mtee[top_page][noindex]" <?php checked($noindex, 1); ?>
value="1"/>
noindex
</label>
<label>
<input type="hidden" name="_mtee[top_page][nofollow]" value="0"/>
<input type="checkbox"
name="_mtee[top_page][nofollow]" <?php checked($nofollow, 1); ?>
value="1"/>
nofollow
</label>
</div>
</td>
</tr>
</table>
</div>
<?php if (count($register_targets['custom_posts']) > 0): ?>
<h2 class="mtee_page_title">カスタム投稿アーカイブ</h2>
<?php foreach ($register_targets['custom_posts'] as $custom_post): ?>
<?php
$noindex = $opt['custom_post'][$custom_post]['noindex'] ?? '0';
$nofollow = $opt['custom_post'][$custom_post]['nofollow'] ?? '0';
?>
<?php wp_nonce_field('check_options'); ?>
<div class="mtee-form-box">
<h3 class="mtee_page_archive_title">
<?php echo get_post_type_object($custom_post)->label; ?>
<?php echo $custom_post; ?>
</h3>
<table class="form-table">
<tr valign="top">
<th>noindex nofollow</th>
<td>
<div class="meta_noindex_nofollow_box">
<label>
<input type="hidden"
name="_mtee[custom_post][<?php echo $custom_post; ?>][noindex]"
value="0"/>
<input type="checkbox"
name="_mtee[custom_post][<?php echo $custom_post; ?>][noindex]" <?php checked($noindex, 1); ?>
value="1"/>
noindex
</label>
<label>
<input type="hidden"
name="_mtee[custom_post][<?php echo $custom_post; ?>][nofollow]"
value="0"/>
<input type="checkbox"
name="_mtee[custom_post][<?php echo $custom_post; ?>][nofollow]" <?php checked($nofollow, 1); ?>
value="1"/>
nofollow
</label>
</div>
</td>
</tr>
</table>
</div>
<?php endforeach; ?>
<?php endif; ?>
<p class="submit"><input type="submit" name="Submit" class="button-primary" value="変更を保存"/></p>
+81
View File
@@ -0,0 +1,81 @@
<h2 class="mtee_page_title mtee_box_border">トップページ</h2>
<?php
$ogp_title = $opt['top_page']['ogp_title'] ?? '';
$ogp_description = $opt['top_page']['ogp_description'] ?? '';
$ogp_img = $opt['top_page']['ogp_img'] ?? '';
?>
<div class="mtee-form-box">
<table class="form-table">
<tr valign="top">
<th>OGP title</th>
<td><input class="top_page_keywords" type="text" name="_mtee[top_page][ogp_title]"
value="<?php echo $ogp_title; ?>">
</td>
</tr>
<tr valign="top">
<th>OGP description</th>
<td><input class="top_page_description" type="text" name="_mtee[top_page][ogp_description]"
value="<?php echo $ogp_description; ?>">
</td>
</tr>
<tr valign="top">
<th>OGP Image</th>
<td>
<input class="<?php echo MTEE_OGP_IMG; ?>" name="_mtee[top_page][ogp_img]" type="hidden"
value="<?php echo $ogp_img; ?>"/>
<input type="button" class="select_ogp_img" name="select_ogp_img" value="選択"/>
<input type="button" class="clear_ogp_img" name="clear_ogp_img" value="クリア"/>
<div class="ogp_media"><?php echo $this->get_ogp_img('top_page'); ?></div>
</td>
</tr>
</table>
</div>
<?php if (count($register_targets['custom_posts']) > 0): ?>
<h2 class="mtee_page_title">カスタム投稿アーカイブ</h2>
<?php foreach ($register_targets['custom_posts'] as $custom_post): ?>
<?php
$ogp_title = $opt['custom_post'][$custom_post]['ogp_title'] ?? '';
$ogp_description = $opt['custom_post'][$custom_post]['ogp_description'] ?? '';
$ogp_img = $opt['custom_post'][$custom_post]['ogp_img'] ?? '';
?>
<?php wp_nonce_field('check_options'); ?>
<div class="mtee-form-box">
<h3 class="mtee_page_archive_title">
<?php echo get_post_type_object($custom_post)->label; ?>
<?php echo $custom_post; ?>
</h3>
<table class="form-table">
<tr valign="top">
<th>OGP title</th>
<td><input class="top_page_keywords" type="text"
name="_mtee[custom_post][<?php echo $custom_post; ?>][ogp_title]"
value="<?php echo $ogp_title; ?>">
</td>
</tr>
<tr valign="top">
<th>OGP description</th>
<td><input class="top_page_description" type="text"
name="_mtee[custom_post][<?php echo $custom_post; ?>][ogp_description]"
value="<?php echo $ogp_description; ?>">
</td>
</tr>
<tr valign="top">
<th>OGP Image</th>
<td>
<input class="<?php echo MTEE_OGP_IMG; ?>"
name="_mtee[custom_post][<?php echo $custom_post; ?>][ogp_img]"
type="hidden"
value="<?php echo $ogp_img; ?>"/>
<input type="button" class="select_ogp_img" name="select_ogp_img" value="選択"/>
<input type="button" class="clear_ogp_img" name="clear_ogp_img" value="クリア"/>
<div class="ogp_media"><?php echo $this->get_ogp_img('custom_post', $custom_post); ?></div>
</td>
</tr>
</table>
</div>
<?php endforeach; ?>
<?php endif; ?>
<script>
var ogp_img_name = "<?php echo MTEE_OGP_IMG; ?>"
</script>
+1 -1
View File
@@ -1 +1 @@
<div class="updated fade"><p><strong>設定を保存しました</strong></p></div>
<div id="settings_updated" class="updated notice is-dismissible"><p><strong>設定を保存しました</strong></p></div>
+78
View File
@@ -0,0 +1,78 @@
<?php
if (!defined('ABSPATH')) {
exit;
} // Exit if accessed directly
if (!trait_exists('mtee_meta_desc_trait')) {
trait mtee_meta_desc_trait {
public function post_output_get_meta_desc($type) {
global $post;
if ($type == 'top_page') {
$meta_description = get_option('_mtee')['top_page']['description'];
} elseif ($type == 'custom_post_archive') {
$custom_post_name = get_post_type_object(get_post_type())->name;
$meta_description = get_option('_mtee')['custom_post'][$custom_post_name]['description'];
} elseif ($type == 'custom_tax' || $type == 'category' || $type == 'post_tag') {
$queried_object = get_queried_object();
$meta_description = get_term_meta($queried_object->term_id, MTEE_NAME_DESCRIPTION, true);
} else {
$meta_description = get_post_meta($post->ID, MTEE_NAME_DESCRIPTION, true);
}
return $meta_description;
}
public function create_default_description() {
$type = '';
$title = '';
$suffix_text = MTEE_META_DESC_ARCHIVE_BASE;
if (is_home() || is_front_page()) { //ページ
return MTEE_META_DESC_TOP_BASE;
} elseif (is_page() || is_single()) { //ページ
$type = 'page';
$title = get_the_title();
$suffix_text = MTEE_META_DESC_SINGLE_BASE;
} elseif (is_category()) { //カテゴリー
$type = 'category';
$title = single_cat_title('', false);
} elseif (is_tag()) { //タグ
$type = 'tag';
$title = single_tag_title('', false);
} elseif (is_tax()) { //タクソノミー
$type = 'tax';
$title = single_term_title('', false);
} elseif (is_post_type_archive()) { //カスタム投稿のアーカイブ
$type = 'custom_post';
$title = post_type_archive_title('', false);
}
$replacement = $this->cnv_custom_template($type, $title, $suffix_text);
if (isset($replacement['org'])) {
$search = array('<###>', '<%%%>');
$description_noun = MTEE_META_DESC_BEFORE_BRACKETS . '<###>' . MTEE_META_DESC_AFTER_BRACKETS . '<%%%>';
return str_replace($search, $replacement['org'], $description_noun);
} else {
return $replacement;
}
}
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'));
return str_replace($search, $replacement, $template[$type]);
} else {
return array('org' => array($title, $suffix_text));
}
}
}
}
+20 -11
View File
@@ -1,20 +1,29 @@
<?php
// WP_UNINSTALL_PLUGINが定義されているかチェック
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
die;
if (!defined('WP_UNINSTALL_PLUGIN')) {
die;
}
// オプション設定の削除
delete_option( '_mtee' );
delete_option('_mtee');
//Todo: タームメタの一括削除方法を確認
//post,termの設定削除
global $wpdb;
$tables = array(
'postmeta',
'termmeta'
);
$delete_post_meta_keys = array(
'mtee_meta_keywords',
'mtee_meta_description',
'_mtee_robots_noindex',
'_mtee_robots_nofollow',
"'" . 'mtee_meta_keywords' . "'",
"'" . 'mtee_meta_description' . "'",
"'" . 'mtee_canonical_url' . "'",
"'" . '_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 );
}
$delete_targets = implode(',', $delete_post_meta_keys);
foreach ($tables as $table) {
$stmnt = 'DELETE FROM ' . $wpdb->prefix . $table . ' WHERE meta_key IN(' . $delete_targets . ')';
$wpdb->query($stmnt);
}