Compare commits

...

5 Commits

Author SHA1 Message Date
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 151026ef87 WP PLUGIN MTEE(Meta Tag etc Extend) OGPタグ設定の追加
・language_attributesフックでhtmlタグにprefixを追加
2021-05-28 21:06:37 +09:00
13 changed files with 240 additions and 197 deletions
-92
View File
@@ -1,92 +0,0 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
} // Exit if accessed directly
if ( ! class_exists( 'mtee_tax_setting' ) ) {
/**
* カテゴリー、タグ、カスタム分類の設定フォーム
* Class amd_tax_setting
*/
class mtee_tax_setting {
private $options;
public function __construct( $options ) {
$this->options = $options;
$this->set_fields();
add_action( 'create_term', array( $this, 'save_terms' ) ); //新規追加用フック
add_action( 'edit_terms', array( $this, 'save_terms' ) ); //編集ページ用フック
}
public function set_fields() {
$built_ins = array(
'term' => array( 'category', 'post_tag' ),
);
foreach ( $built_ins['term'] as $built_in ) {
add_action( $built_in . '_add_form_fields', array( $this, 'insert_term_meta_add_fields' ) );
add_action( $built_in . '_edit_form_fields', array( $this, 'insert_term_meta_edit_fields' ) );
}
if ( isset( $this->options['taxonomies'] ) ) {
foreach ( $this->options['taxonomies'] as $tax_key => $tax_chk ) {
if ( $tax_chk == 1 ) {
add_action( $tax_key . '_add_form_fields', array( $this, 'insert_term_meta_add_fields' ) );
add_action( $tax_key . '_edit_form_fields', array( $this, 'insert_term_meta_edit_fields' ) );
}
}
}
}
function insert_term_meta_add_fields( $tag ) {
$key_value = '';
$desc_value = '';
if ( isset( $tag->term_id ) ) {
$key_value = get_term_meta( $tag->term_id, MTEE_NAME_KEYWORDS, true );
$desc_value = get_term_meta( $tag->term_id, MTEE_MTEE_NAME_DESCRIPTION, true );
}
echo '
<div class="form-field">
meta keywords<br>
<input type="text" name="' . MTEE_NAME_KEYWORDS . '" value="' . $key_value . '" class="tax-meta-field" />
</div>
<div class="form-field">
meta description<br>
<input type="text" name="' . MTEE_NAME_DESCRIPTION . '" value="' . $desc_value . '" class="tax-meta-field" />
</div>
';
}
function insert_term_meta_edit_fields( $tag ) {
$key_value = '';
$desc_value = '';
if ( isset( $tag->term_id ) ) {
$key_value = get_term_meta( $tag->term_id, MTEE_NAME_KEYWORDS, true );
$desc_value = get_term_meta( $tag->term_id, MTEE_NAME_DESCRIPTION, true );
}
echo '
<tr class="form-field">
<th scope="row">meta keywords</th>
<td><input type="text" name="' . MTEE_NAME_KEYWORDS . '" value="' . $key_value . '" class="tax-meta-field" /></td>
</tr>
<tr class="form-field">
<th>meta description</th>
<td><input type="text" name="' . MTEE_NAME_DESCRIPTION . '" value="' . $desc_value . '" class="tax-meta-field" /></td>
</tr>
';
}
function save_terms( $term_id ) {
if ( array_key_exists( MTEE_NAME_KEYWORDS, $_POST ) ) {
update_term_meta( $term_id, MTEE_NAME_KEYWORDS, $_POST[ MTEE_NAME_KEYWORDS ] );
}
if ( array_key_exists( MTEE_NAME_DESCRIPTION, $_POST ) ) {
update_term_meta( $term_id, MTEE_NAME_DESCRIPTION, $_POST[ MTEE_NAME_DESCRIPTION ] );
}
}
}
}
@@ -33,31 +33,19 @@ if (!class_exists('mtee_canonical_setting')) {
//-------------------------------------------------------------------------------------------
public function add_meta_fields() {
//add_meta_box(表示される入力ボックスのHTMLのID, ラベル, 表示する内容を作成する関数名, 投稿タイプ, 表示方法)
$default_built_ins = array(
'posts' => array('page', 'post',),
);
$custom_posts = array_values(get_post_types(array('public' => true, '_builtin' => false)));
$target_posts = array_merge(array('page', 'post',), $custom_posts);
foreach ($default_built_ins['posts'] as $built_in) {
foreach ($target_posts as $target_post) {
add_meta_box(
'canonical_setting',
'Canonical設定',
array($this, 'insert_meta_fields'),
$built_in,
'normal'
);
}
if (isset($this->options['custom_posts'])) {
foreach ($this->options['custom_posts'] as $custom_post => $post_chk) {
if ($post_chk == 1) {
add_meta_box(
'canonical_setting',
'Canonical設定',
array($this, 'insert_meta_fields'),
$custom_post, 'normal'
);
}
}
array(
$this,
'insert_meta_fields'
),
$target_post,
'normal');
}
}
+30
View File
@@ -0,0 +1,30 @@
<?php
if (!defined('ABSPATH')) {
exit;
} // Exit if accessed directly
if (!class_exists('mtee_meta_output_ogp')) {
class mtee_meta_output_ogp {
public function __construct() {
//GOPのプレフィックスを出力する
add_filter('language_attributes', array($this, 'add_html_ogp_prefix'));
}
/**
* 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#"';
}
}
}
+82
View File
@@ -0,0 +1,82 @@
<?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'));
//画像をアップする場合は、multipart/form-dataの設定が必要なので、post_edit_form_tagをフックしてformタグに追加
add_action('post_edit_form_tag', array($this, 'custom_meta_box_edit_form_tag'));
add_action('save_post', array($this, 'save_meta_fields'));
}
public function custom_meta_box_edit_form_tag() {
echo ' enctype="multipart/form-data"';
}
//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) . '"/>
</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) . '"/>
</div>
</div>
<div class="meta_key_desc_box">
<label style="font-weight: bold; display: block">image</label>
<div>
<input style="width:100%" type="file" name="' . MTEE_OGP_IMG . '" value="' . get_post_meta($post->ID, MTEE_OGP_IMG, true) . '" accept="image/*"/>
</div>
</div>';
}
// カスタムフィールドの値を保存
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);
}
}
}
}
@@ -5,10 +5,9 @@ if ( ! defined( 'ABSPATH' ) ) {
if ( ! class_exists( 'mtee_post_setting' ) ) {
/**
* ページ、投稿、カスタム投稿の設定フォーム
* Class amd_post_setting
*/
/**
* Class mtee_post_setting
*/
class mtee_post_setting {
private $options;
@@ -23,24 +22,19 @@ if ( ! class_exists( 'mtee_post_setting' ) ) {
public function add_meta_fields() {
//add_meta_box(表示される入力ボックスのHTMLのID, ラベル, 表示する内容を作成する関数名, 投稿タイプ, 表示方法)
$default_built_ins = array(
'posts' => array( 'page', 'post', ),
);
foreach ( $default_built_ins['posts'] as $built_in ) {
add_meta_box( 'meta_setting', 'meta設定', array( $this, 'insert_meta_fields' ), $built_in, 'normal' );
}
if ( isset( $this->options['custom_posts'] ) ) {
foreach ( $this->options['custom_posts'] as $custom_post => $post_chk ) {
if ( $post_chk == 1 ) {
add_meta_box( 'meta_setting', 'meta設定', array(
$this,
'insert_meta_fields'
), $custom_post, 'normal' );
}
}
}
$custom_posts = array_values(get_post_types(array('public' => true, '_builtin' => false)));
$target_posts = array_merge(array('page', 'post',), $custom_posts);
foreach ($target_posts as $target_post) {
add_meta_box(
'meta_setting',
'meta設定',
array(
$this,
'insert_meta_fields'),
$target_post,
'normal'
);
}
}
// カスタムフィールドの入力エリア
+90
View File
@@ -0,0 +1,90 @@
<?php
if (!defined('ABSPATH')) {
exit;
} // Exit if accessed directly
if (!class_exists('mtee_tax_setting')) {
/**
* Class mtee_tax_setting
*/
class mtee_tax_setting {
private $options;
public function __construct($options) {
$this->options = $options;
$this->set_fields();
add_action('create_term', array($this, 'save_terms')); //新規追加用フック
add_action('edit_terms', array($this, 'save_terms')); //編集ページ用フック
}
public function set_fields() {
$taxs = $this->set_tax_types();
foreach ($taxs as $tax) {
add_action($tax . '_add_form_fields', array($this, 'insert_term_meta_add_fields'));
add_action($tax . '_edit_form_fields', array($this, 'insert_term_meta_edit_fields'));
}
}
public function set_tax_types(): array {
$custom_tax = get_taxonomies(array('public' => true, '_builtin' => false));
$tax_array = array_merge(array('category', 'post_tag'), $custom_tax);
$add_tax = filter_input(INPUT_GET, 'taxonomy');
if (!empty($add_tax)) {
return array_merge($tax_array, array($add_tax));
}
return $tax_array;
}
function insert_term_meta_add_fields($tag) {
$key_value = '';
$desc_value = '';
if (isset($tag->term_id)) {
$key_value = get_term_meta($tag->term_id, MTEE_NAME_KEYWORDS, true);
$desc_value = get_term_meta($tag->term_id, MTEE_MTEE_NAME_DESCRIPTION, true);
}
echo '
<div class="form-field">
meta keywords<br>
<input type="text" name="' . MTEE_NAME_KEYWORDS . '" value="' . $key_value . '" class="tax-meta-field" />
</div>
<div class="form-field">
meta description<br>
<input type="text" name="' . MTEE_NAME_DESCRIPTION . '" value="' . $desc_value . '" class="tax-meta-field" />
</div>
';
}
function insert_term_meta_edit_fields($tag) {
$key_value = '';
$desc_value = '';
if (isset($tag->term_id)) {
$key_value = get_term_meta($tag->term_id, MTEE_NAME_KEYWORDS, true);
$desc_value = get_term_meta($tag->term_id, MTEE_NAME_DESCRIPTION, true);
}
echo '
<tr class="form-field">
<th scope="row">meta keywords</th>
<td><input type="text" name="' . MTEE_NAME_KEYWORDS . '" value="' . $key_value . '" class="tax-meta-field" /></td>
</tr>
<tr class="form-field">
<th>meta description</th>
<td><input type="text" name="' . MTEE_NAME_DESCRIPTION . '" value="' . $desc_value . '" class="tax-meta-field" /></td>
</tr>
';
}
function save_terms($term_id) {
if (array_key_exists(MTEE_NAME_KEYWORDS, $_POST)) {
update_term_meta($term_id, MTEE_NAME_KEYWORDS, $_POST[MTEE_NAME_KEYWORDS]);
}
if (array_key_exists(MTEE_NAME_DESCRIPTION, $_POST)) {
update_term_meta($term_id, MTEE_NAME_DESCRIPTION, $_POST[MTEE_NAME_DESCRIPTION]);
}
}
}
}
+3 -1
View File
@@ -1,13 +1,15 @@
<?php
const MTEE_CLASS_DIR = __DIR__ . '/class/';
const MTEE_TRAIT_DIR = __DIR__ . '/trait/';
const MTEE_TEMPLATE_DIR = __DIR__ . '/template/';
const MTEE_NAME_KEYWORDS = 'mtee_meta_keywords';
const MTEE_NAME_DESCRIPTION = 'mtee_meta_description';
const MTEE_NAME_NOINDEX = '_mtee_robots_noindex';
const MTEE_NAME_NOFOLLOW = '_mtee_robots_nofollow';
const MTEE_CANONICAL_URL = 'mtee_canonical_url';
const MTEE_OGP_TITLE = '_mtee_ogp_title';
const MTEE_OGP_DESC = '_mtee_ogp_desc';
const MTEE_OGP_IMG = '_mtee_ogp_img';
const MTEE_META_DESC_TOP_BASE = 'トップページです。';
const MTEE_META_DESC_SINGLE_BASE = 'ページです。';
+10 -10
View File
@@ -30,8 +30,8 @@ $options = $mtee->get_options();
// enabled my meta keywords, description
if ($mtee->is_enable('enabled')) {
require_once MTEE_CLASS_DIR . 'mtee-tax-setting.php';
require_once MTEE_CLASS_DIR . 'mtee-post-setting.php';
require_once MTEE_CLASS_DIR . 'mtee_tax_setting.php';
require_once MTEE_CLASS_DIR . 'mtee_post_setting.php';
require_once MTEE_CLASS_DIR . 'mtee_meta_output_keydesc.php';
new mtee_tax_setting($options);
new mtee_post_setting($options);
@@ -41,31 +41,31 @@ if ($mtee->is_enable('enabled')) {
// enabled my canonical. caution : default canonical delete
if ($mtee->is_enable('canonical_setting')) {
remove_action('wp_head', 'rel_canonical');
require_once MTEE_CLASS_DIR . 'mtee-canonical-setting.php';
require_once MTEE_CLASS_DIR . 'mtee-output-canonical.php';
require_once MTEE_CLASS_DIR . 'mtee_canonical_setting.php';
require_once MTEE_CLASS_DIR . 'mtee_meta_output_canonical.php';
new mtee_canonical_setting($options);
new mtee_meta_output_canonical();
}
// enabled my OGP tag
if ($mtee->is_enable('ogp_setting')) {
require_once MTEE_CLASS_DIR . 'mtee-ogp-setting.php';
require_once MTEE_CLASS_DIR . 'mtee-output-ogp.php';
new mtee_ogp_setting();
require_once MTEE_CLASS_DIR . 'mtee_ogp_post_setting.php';
require_once MTEE_CLASS_DIR . 'mtee_meta_output_ogp.php';
new mtee_ogp_post_setting($options);
new mtee_meta_output_ogp();
}
//enabled my noindex, nofollow
if ($mtee->is_enable('noindex_nofollow')) {
require_once MTEE_CLASS_DIR . 'mtee-noindexnofollow-setting.php';
require_once MTEE_CLASS_DIR . 'mtee-output-noindexnofollow.php';
require_once MTEE_CLASS_DIR . 'mtee_noindexnofolow_setting.php';
require_once MTEE_CLASS_DIR . 'mtee_meta_output_noindexnofollow.php';
new mtee_noindexnofolow_setting($options);
new mtee_meta_output_noindexnofollow();
}
//disabled WP version, WP JS/CSS version
if ($mtee->is_disable('asset_ver_disabled') || $mtee->is_disable('asset_ver_disabled')) {
require_once MTEE_CLASS_DIR . 'mtee-version-setting.php';
require_once MTEE_CLASS_DIR . 'mtee_version_setting.php';
new mtee_version_setting($options);
}
-51
View File
@@ -27,57 +27,6 @@ $asset_ver_disabled = $this->get_key_setting('asset_ver_disabled');
value="1">有効
</label>
</div>
<?php if (count($register_targets['custom_posts']) > 0 || count($register_targets['taxonomies']) > 0): ?>
<table class="mtee-setting-tbl">
<?php if (count($register_targets['custom_posts']) > 0): ?>
<tr>
<th>カスタム投稿</th>
<td>
<ul>
<?php foreach ($register_targets['custom_posts'] as $custom_post) : ?>
<?php $custom_post_check = $opt['custom_posts'][$custom_post] ?? 0; ?>
<li>
<label>
<input type="hidden"
name="_mtee[custom_posts][<?php echo $custom_post; ?>]"
value="0">
<input type="checkbox"
name="_mtee[custom_posts][<?php echo $custom_post; ?>]"
<?php checked($custom_post_check, 1); ?>
value="1">
<?php echo $custom_post . '' . get_post_type_object($custom_post)->label . ''; ?>
</label>
</li>
<?php endforeach; ?>
</ul>
</td>
</tr>
<?php endif; ?>
<?php if (count($register_targets['taxonomies']) > 0): ?>
<tr>
<th>カスタム分類</th>
<td>
<ul>
<?php foreach ($register_targets['taxonomies'] as $taxonomy) : ?>
<li>
<?php $taxonomy_check = $opt['taxonomies'][$taxonomy] ?? 0; ?>
<label>
<input type="hidden"
name="_mtee[taxonomies][<?php echo $taxonomy; ?>]" value="0">
<input type="checkbox"
name="_mtee[taxonomies][<?php echo $taxonomy; ?>]"
<?php checked($taxonomy_check, 1); ?>
value="1">
<?php echo $taxonomy . '' . get_taxonomy($taxonomy)->label . ''; ?>
</label>
</li>
<?php endforeach; ?>
</ul>
</td>
</tr>
<?php endif; ?>
</table>
<?php endif; ?>
<div class="mtee-form-box mtee_box_border">
<h3>meta keywords テンプレート設定
<?php if (!$this->is_enable('enabled')): ?>