WP PLUGIN
・選択カスタムフィールドをオートコンプリートに変更
This commit is contained in:
@@ -5,7 +5,7 @@ Plugin URI: https://develop.n-k-y.net/wordpress/wp_plugin/apop/
|
||||
Author: NBK45
|
||||
Author URI: https://develop.n-k-y.net
|
||||
Description: 通常表示、検索表示、タクソノミー毎に投稿の表示順を設定するプラグイン
|
||||
Version: 1.1.2
|
||||
Version: 1.1.3
|
||||
License: GPLv2
|
||||
*/
|
||||
|
||||
@@ -37,6 +37,7 @@ new APOP_POST;
|
||||
//CSS, JSの読み込み
|
||||
add_action( 'admin_enqueue_scripts', 'apop_register_my_styles' );
|
||||
function apop_register_my_styles() {
|
||||
wp_enqueue_style( 'jq_ui_css', APOP_PLUGIN_URL . 'css/jquery-ui.css' );
|
||||
wp_enqueue_style( 'hrc_post_style', APOP_PLUGIN_URL . 'css/apop-style.css' );
|
||||
wp_enqueue_script( 'jquery-ui-sortable' );
|
||||
wp_enqueue_script( 'post-sort-cat-order_js', APOP_PLUGIN_URL . 'js/apop-style.js' );
|
||||
|
||||
@@ -346,8 +346,11 @@ value="' . esc_html( $sort_num ) . '">
|
||||
$name_meta_key = '_' . $name_key . '[' . $target_key . '][field][meta_key]';
|
||||
$name_value_type = '_' . $name_key . '[' . $target_key . '][field][value_type]';
|
||||
$name_custom_field_type = '_' . $name_key . '[' . $target_key . '][field][custom_field_type]';
|
||||
$custom_field_val_1 = $custom_field_type == '1' ? $meta_key : '';
|
||||
$custom_field_val_2 = $custom_field_type == '2' ? $meta_key : '';;
|
||||
echo '<div class="sort-custom-field">
|
||||
<div class="sort-custom-field-types"><div class="sort-custom-field-inner-label">
|
||||
<div class="sort-custom-field-types">
|
||||
<div class="sort-custom-field-inner-label">
|
||||
<label>
|
||||
<input type="radio"
|
||||
class="custom-field-type"
|
||||
@@ -359,8 +362,8 @@ value="' . esc_html( $sort_num ) . '">
|
||||
name="' . esc_attr( $name_custom_field_type ) . '"
|
||||
value="2"' . esc_attr( self::set_search_normal_checked( $custom_field_type, '2' ) ) . '>追加</label>
|
||||
</div>';
|
||||
self::set_all_customfield_select( $name_meta_key, $meta_key );
|
||||
echo '<input type="text" class="custom_field_key" name="' . esc_attr( $name_meta_key ) . '" value="' . esc_attr( $meta_key ) . '" required>
|
||||
echo '<input type="text" id="select-custom-field-input" class="custom_field_key_select" name="' . esc_attr( $name_meta_key ) . '" . value="' . esc_attr( $custom_field_val_1 ) . '" required>
|
||||
<input type="text" class="custom_field_key" name="' . esc_attr( $name_meta_key ) . '" value="' . esc_attr( $custom_field_val_2 ) . '" required>
|
||||
</div>
|
||||
<div class="sort-custom-field-inner">
|
||||
<div class="sort-custom-field-inner-label">値タイプ:</div>
|
||||
|
||||
@@ -6,15 +6,18 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
if ( ! class_exists( 'APOP' ) ) {
|
||||
|
||||
require_once __DIR__ . '/../util/apop-order-setting.php';
|
||||
require_once __DIR__ . '/../util/apop-customfield-select.php';
|
||||
|
||||
class APOP {
|
||||
|
||||
use APOP_ORDER_SETTING;
|
||||
use APOP_ORDER_SETTING, CUSTOMFIELD_SELECT;
|
||||
|
||||
const TEMPLATE_DIR = __DIR__ . '/../template/';
|
||||
|
||||
public function __construct() {
|
||||
add_action( 'admin_menu', array( $this, 'add_pages' ) );
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'set_custom_field_ajax' ) );
|
||||
add_action( 'wp_ajax_set_custom_field', array( $this, 'set_custom_field' ) );
|
||||
}
|
||||
|
||||
public function add_pages() {
|
||||
|
||||
Vendored
+1312
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,21 @@
|
||||
jQuery(function ($) {
|
||||
$('#select-custom-field-input').autocomplete({
|
||||
source: function (req, resp) {
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: localize.ajax_url,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: localize.action,
|
||||
param: req.term
|
||||
}
|
||||
}).done(function (o) {
|
||||
resp(o);
|
||||
}).fail(function () {
|
||||
resp(['']);
|
||||
});
|
||||
},
|
||||
autoFocus: true,
|
||||
minLength: 2
|
||||
});
|
||||
});
|
||||
+10
-3
@@ -4,7 +4,7 @@ Tags: 投稿,表示順,投稿表示順,カテゴリー,タグ,カスタム分類
|
||||
Requires at least: 4.9
|
||||
Tested up to: 5.7.2
|
||||
Requires PHP: 7.0
|
||||
Stable tag: 1.1.2
|
||||
Stable tag: 1.1.3
|
||||
License: GPLv2 or later
|
||||
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
||||
|
||||
@@ -45,8 +45,12 @@ License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
||||
|
||||
|
||||
== Screenshots ==
|
||||
|
||||
|
||||
screenshot-1.png
|
||||
screenshot-2.png
|
||||
screenshot-3.png
|
||||
screenshot-4.png
|
||||
screenshot-5.png
|
||||
screenshot-6.png
|
||||
|
||||
== Changelog ==
|
||||
|
||||
@@ -69,5 +73,8 @@ License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
||||
= 1.1.2 =
|
||||
選択カスタムフィールドを読み取り専用表示するよう修正
|
||||
|
||||
= 1.1.3 =
|
||||
選択カスタムフィールドをオートコンプリートに変更
|
||||
|
||||
== Upgrade Notice ==
|
||||
No information
|
||||
@@ -7,25 +7,29 @@ if ( ! trait_exists( 'CUSTOMFIELD_SELECT' ) ) {
|
||||
|
||||
trait CUSTOMFIELD_SELECT {
|
||||
|
||||
public static function set_all_customfield_select( $name_meta_key, $meta_key ) {
|
||||
$selects = self::get_all_custom_fields();
|
||||
echo '<select class="custom_field_key_select" name="' . esc_attr( $name_meta_key ) . '" required>';
|
||||
foreach ( $selects as $select ) {
|
||||
if ( $select->meta_key == $meta_key ) {
|
||||
$selected = ' selected';
|
||||
} else {
|
||||
$selected = '';
|
||||
}
|
||||
echo '<option value="' . esc_attr( $select->meta_key ) . '"' . esc_attr( $selected ) . '>' . esc_html( $select->meta_key ) . '</option>';
|
||||
}
|
||||
echo '</select>';
|
||||
public function set_custom_field_ajax() {
|
||||
$handle = 'custom_field_ajax';
|
||||
wp_register_script( $handle, APOP_PLUGIN_URL . 'js/custom_field.js', [ 'jquery' ], '', true );
|
||||
$localize = [
|
||||
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
||||
'action' => 'set_custom_field',
|
||||
];
|
||||
wp_localize_script( $handle, 'localize', $localize );
|
||||
wp_enqueue_script( $handle );
|
||||
}
|
||||
|
||||
private static function get_all_custom_fields() {
|
||||
public function set_custom_field() {
|
||||
$param = filter_input( INPUT_GET, 'param', FILTER_SANITIZE_STRING );
|
||||
echo json_encode( $this->get_custom_fields_by_param( $param ) );
|
||||
die();
|
||||
}
|
||||
|
||||
private function get_custom_fields_by_param( $param ) {
|
||||
global $wpdb;
|
||||
$stmnt = "SELECT DISTINCT meta_key AS value, meta_key as label FROM $wpdb->postmeta WHERE meta_key LIKE %s AND meta_key NOT LIKE %s";
|
||||
|
||||
return $wpdb->get_results( $wpdb->prepare( $stmnt, $wpdb->esc_like( $param ) . '%', $wpdb->esc_like( '_%' ) ) );
|
||||
}
|
||||
|
||||
//アンダーバーで始まるシステム系のパラメータは除外する
|
||||
return $wpdb->get_results( 'SELECT DISTINCT meta_key FROM ' . $wpdb->prefix . 'postmeta WHERE meta_key NOT LIKE ' . "'\_%' ORDER BY meta_key ASC" );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user