Version Description
- Add color picker field.
- Add smart-cf-before-save-post action hook.
- Add smart-cf-after-save-post action hook.
- Add smart-cf-validate-save-post filter hook.
Download this release
Release Info
Developer | inc2734 |
Plugin | Smart Custom Fields |
Version | 1.0.2 |
Comparing to | |
See all releases |
Code changes from version 1.0.1 to 1.0.2
- classes/class.field-base.php +2 -3
- classes/fields/class.field-colorpicker.php +89 -0
- classes/fields/class.field-relation.php +48 -2
- classes/fields/class.field-wysiwyg.php +18 -0
- js/editor-colorpicker.js +27 -0
- js/editor.js +10 -7
- readme.txt +8 -1
- smart-custom-fields.php +19 -47
classes/class.field-base.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Field_Base
|
4 |
-
* Version : 1.0.
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : October 7, 2014
|
7 |
-
* Modified : October
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
@@ -32,7 +32,6 @@ abstract class Smart_Custom_Fields_Field_Base {
|
|
32 |
|
33 |
/**
|
34 |
* __construct
|
35 |
-
* @param array $options
|
36 |
*/
|
37 |
public function __construct() {
|
38 |
$settings = $this->init();
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Field_Base
|
4 |
+
* Version : 1.0.2
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : October 7, 2014
|
7 |
+
* Modified : October 21, 2014
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
32 |
|
33 |
/**
|
34 |
* __construct
|
|
|
35 |
*/
|
36 |
public function __construct() {
|
37 |
$settings = $this->init();
|
classes/fields/class.field-colorpicker.php
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Smart_Custom_Fields_Field_Colorpicker
|
4 |
+
* Version : 1.0.0
|
5 |
+
* Author : Takashi Kitajima
|
6 |
+
* Created : October 21, 2014
|
7 |
+
* Modified :
|
8 |
+
* License : GPLv2
|
9 |
+
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
+
*/
|
11 |
+
class Smart_Custom_Fields_Field_Colorpicker extends Smart_Custom_Fields_Field_Base {
|
12 |
+
|
13 |
+
/**
|
14 |
+
* init
|
15 |
+
* @return array ( name, label, optgroup )
|
16 |
+
*/
|
17 |
+
protected function init() {
|
18 |
+
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
|
19 |
+
return array(
|
20 |
+
'name' => 'colorpicker',
|
21 |
+
'label' => __( 'Color picker', 'smart-custom-fields' ),
|
22 |
+
'optgroup' => 'other-fields',
|
23 |
+
);
|
24 |
+
}
|
25 |
+
|
26 |
+
/**
|
27 |
+
* admin_enqueue_scripts
|
28 |
+
* @param string $hook
|
29 |
+
*/
|
30 |
+
public function admin_enqueue_scripts( $hook ) {
|
31 |
+
if ( in_array( $hook, array( 'post-new.php', 'post.php' ) ) ) {
|
32 |
+
wp_enqueue_style( 'wp-color-picker' );
|
33 |
+
wp_enqueue_script(
|
34 |
+
SCF_Config::PREFIX . 'colorpicker',
|
35 |
+
plugins_url( '../../js/editor-colorpicker.js', __FILE__ ),
|
36 |
+
array( 'jquery', 'wp-color-picker' ),
|
37 |
+
false,
|
38 |
+
true
|
39 |
+
);
|
40 |
+
}
|
41 |
+
}
|
42 |
+
|
43 |
+
/**
|
44 |
+
* get_field
|
45 |
+
* @param array $field フィールドの情報
|
46 |
+
* @param int $index インデックス番号
|
47 |
+
* @param mixed $value 保存されている値(check のときだけ配列)
|
48 |
+
*/
|
49 |
+
public function get_field( $field, $index, $value ) {
|
50 |
+
$name = $this->get_name_attribute( $field['name'], $index );
|
51 |
+
$disabled = $this->get_disable_attribute( $index );
|
52 |
+
return sprintf(
|
53 |
+
'<input type="text" name="%s" value="%s" class="%s" %s />',
|
54 |
+
esc_attr( $name ),
|
55 |
+
esc_attr( $value ),
|
56 |
+
esc_attr( SCF_Config::PREFIX . 'colorpicker' ),
|
57 |
+
disabled( true, $disabled, false )
|
58 |
+
);
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* display_field_options
|
63 |
+
* @param int $group_key
|
64 |
+
* @param int $field_key
|
65 |
+
*/
|
66 |
+
public function display_field_options( $group_key, $field_key ) {
|
67 |
+
?>
|
68 |
+
<tr>
|
69 |
+
<th><?php esc_html_e( 'Default', 'smart-custom-fields' ); ?></th>
|
70 |
+
<td>
|
71 |
+
<input type="text"
|
72 |
+
name="<?php echo esc_attr( $this->get_field_name( $group_key, $field_key, 'default' ) ); ?>"
|
73 |
+
class="widefat"
|
74 |
+
value="<?php echo esc_attr( $this->get_field_value( 'default' ) ); ?>" />
|
75 |
+
</td>
|
76 |
+
</tr>
|
77 |
+
<tr>
|
78 |
+
<th><?php esc_html_e( 'Notes', 'smart-custom-fields' ); ?></th>
|
79 |
+
<td>
|
80 |
+
<input type="text"
|
81 |
+
name="<?php echo esc_attr( $this->get_field_name( $group_key, $field_key, 'notes' ) ); ?>"
|
82 |
+
class="widefat"
|
83 |
+
value="<?php echo esc_attr( $this->get_field_value( 'notes' ) ); ?>"
|
84 |
+
/>
|
85 |
+
</td>
|
86 |
+
</tr>
|
87 |
+
<?php
|
88 |
+
}
|
89 |
+
}
|
classes/fields/class.field-relation.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Field_Relation
|
4 |
-
* Version : 1.0.
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : October 7, 2014
|
7 |
-
* Modified : October
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
@@ -15,6 +15,8 @@ class Smart_Custom_Fields_Field_Relation extends Smart_Custom_Fields_Field_Base
|
|
15 |
* @return array ( name, label, optgroup, allow-multiple-data )
|
16 |
*/
|
17 |
protected function init() {
|
|
|
|
|
18 |
return array(
|
19 |
'name' => 'relation',
|
20 |
'label' => __( 'Relation', 'smart-custom-fields' ),
|
@@ -23,6 +25,50 @@ class Smart_Custom_Fields_Field_Relation extends Smart_Custom_Fields_Field_Base
|
|
23 |
);
|
24 |
}
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
/**
|
27 |
* get_field
|
28 |
* @param array $field フィールドの情報
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Field_Relation
|
4 |
+
* Version : 1.0.2
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : October 7, 2014
|
7 |
+
* Modified : October 21, 2014
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
15 |
* @return array ( name, label, optgroup, allow-multiple-data )
|
16 |
*/
|
17 |
protected function init() {
|
18 |
+
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
|
19 |
+
add_action( 'wp_ajax_smart-cf-relational-posts-search', array( $this, 'relational_posts_search' ) );
|
20 |
return array(
|
21 |
'name' => 'relation',
|
22 |
'label' => __( 'Relation', 'smart-custom-fields' ),
|
25 |
);
|
26 |
}
|
27 |
|
28 |
+
/**
|
29 |
+
* admin_enqueue_scripts
|
30 |
+
* @param string $hook
|
31 |
+
*/
|
32 |
+
public function admin_enqueue_scripts( $hook ) {
|
33 |
+
if ( in_array( $hook, array( 'post-new.php', 'post.php' ) ) ) {
|
34 |
+
wp_enqueue_script(
|
35 |
+
SCF_Config::PREFIX . 'editor-relation',
|
36 |
+
plugin_dir_url( __FILE__ ) . '../../js/editor-relation.js',
|
37 |
+
array( 'jquery' ),
|
38 |
+
null,
|
39 |
+
true
|
40 |
+
);
|
41 |
+
wp_localize_script( SCF_Config::PREFIX . 'editor-relation', 'smart_cf_relation', array(
|
42 |
+
'endpoint' => admin_url( 'admin-ajax.php' ),
|
43 |
+
'action' => SCF_Config::PREFIX . 'relational-posts-search',
|
44 |
+
'nonce' => wp_create_nonce( SCF_Config::NAME . '-relation' )
|
45 |
+
) );
|
46 |
+
}
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
* relational_posts_search
|
51 |
+
*/
|
52 |
+
public function relational_posts_search() {
|
53 |
+
check_ajax_referer( SCF_Config::NAME . '-relation', 'nonce' );
|
54 |
+
$_posts = array();
|
55 |
+
if ( isset( $_POST['post_types'], $_POST['click_count' ] ) ) {
|
56 |
+
$post_type = explode( ',', $_POST['post_types'] );
|
57 |
+
$posts_per_page = get_option( 'posts_per_page' );
|
58 |
+
$offset = $_POST['click_count'] * $posts_per_page;
|
59 |
+
$_posts = get_posts( array(
|
60 |
+
'post_type' => $post_type,
|
61 |
+
'offset' => $offset,
|
62 |
+
'order' => 'ASC',
|
63 |
+
'orderby' => 'ID',
|
64 |
+
'posts_per_page' => $posts_per_page,
|
65 |
+
) );
|
66 |
+
}
|
67 |
+
header( 'Content-Type: application/json; charset=utf-8' );
|
68 |
+
echo json_encode( $_posts );
|
69 |
+
die();
|
70 |
+
}
|
71 |
+
|
72 |
/**
|
73 |
* get_field
|
74 |
* @param array $field フィールドの情報
|
classes/fields/class.field-wysiwyg.php
CHANGED
@@ -15,6 +15,7 @@ class Smart_Custom_Fields_Field_Wysiwyg extends Smart_Custom_Fields_Field_Base {
|
|
15 |
* @return array ( name, label, optgroup )
|
16 |
*/
|
17 |
protected function init() {
|
|
|
18 |
return array(
|
19 |
'name' => 'wysiwyg',
|
20 |
'label' => __( 'Wysiwyg', 'smart-custom-fields' ),
|
@@ -22,6 +23,23 @@ class Smart_Custom_Fields_Field_Wysiwyg extends Smart_Custom_Fields_Field_Base {
|
|
22 |
);
|
23 |
}
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
/**
|
26 |
* after_loaded
|
27 |
*/
|
15 |
* @return array ( name, label, optgroup )
|
16 |
*/
|
17 |
protected function init() {
|
18 |
+
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
|
19 |
return array(
|
20 |
'name' => 'wysiwyg',
|
21 |
'label' => __( 'Wysiwyg', 'smart-custom-fields' ),
|
23 |
);
|
24 |
}
|
25 |
|
26 |
+
/**
|
27 |
+
* admin_enqueue_scripts
|
28 |
+
* @param string $hook
|
29 |
+
*/
|
30 |
+
public function admin_enqueue_scripts( $hook ) {
|
31 |
+
if ( in_array( $hook, array( 'post-new.php', 'post.php' ) ) ) {
|
32 |
+
add_action( 'after_wp_tiny_mce', array( $this, 'after_wp_tiny_mce' ) );
|
33 |
+
}
|
34 |
+
}
|
35 |
+
|
36 |
+
public function after_wp_tiny_mce() {
|
37 |
+
printf(
|
38 |
+
'<script type="text/javascript" src="%s"></script>',
|
39 |
+
plugin_dir_url( __FILE__ ) . '../../js/editor-wysiwyg.js'
|
40 |
+
);
|
41 |
+
}
|
42 |
+
|
43 |
/**
|
44 |
* after_loaded
|
45 |
*/
|
js/editor-colorpicker.js
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* colorpicker.js
|
3 |
+
* Version : 1.0.0
|
4 |
+
* Author : Takashi Kitajima
|
5 |
+
* Created : October 21, 2014
|
6 |
+
* Modified :
|
7 |
+
* License : GPLv2
|
8 |
+
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
+
*/
|
10 |
+
jQuery( function( $ ) {
|
11 |
+
$( '.smart-cf-meta-box-table' ).each( function( i, e ) {
|
12 |
+
$( e ).find( '.smart-cf-colorpicker' ).each( function( i, e ) {
|
13 |
+
if ( $( e ).attr( 'disabled' ) !== 'disabled' ) {
|
14 |
+
$( e ).wpColorPicker();
|
15 |
+
}
|
16 |
+
} );
|
17 |
+
} );
|
18 |
+
|
19 |
+
$( document ).on( 'smart-cf-after-add-group', function( e, button ) {
|
20 |
+
var parent = $( button ).parents( '.smart-cf-meta-box-repeat-tables' );
|
21 |
+
parent.find( '.smart-cf-colorpicker' ).each( function( i, e ) {
|
22 |
+
if ( $( e ).attr( 'disabled' ) !== 'disabled' ) {
|
23 |
+
$( e ).wpColorPicker();
|
24 |
+
}
|
25 |
+
} );
|
26 |
+
} );
|
27 |
+
} );
|
js/editor.js
CHANGED
@@ -58,13 +58,16 @@ jQuery( function( $ ) {
|
|
58 |
var clone = table.clone( true, true ).hide();
|
59 |
|
60 |
clone.find( 'input, select, textarea' ).each( function( i, e ) {
|
61 |
-
$( this ).attr( 'name'
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
68 |
} );
|
69 |
|
70 |
clone.find( '.smart-cf-wp-editor' ).each( function( i, e ) {
|
58 |
var clone = table.clone( true, true ).hide();
|
59 |
|
60 |
clone.find( 'input, select, textarea' ).each( function( i, e ) {
|
61 |
+
var name = $( this ).attr( 'name' );
|
62 |
+
if ( name ) {
|
63 |
+
$( this ).attr( 'name',
|
64 |
+
name.replace(
|
65 |
+
/^(smart-custom-fields\[.+\])\[_\]/,
|
66 |
+
'$1[_' + cnt + ']'
|
67 |
+
)
|
68 |
+
);
|
69 |
+
$( this ).removeAttr( 'disabled' );
|
70 |
+
}
|
71 |
} );
|
72 |
|
73 |
clone.find( '.smart-cf-wp-editor' ).each( function( i, e ) {
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.amazon.co.jp/registry/wishlist/39ANKRNSTNW40
|
|
4 |
Tags: plugin, custom field, custom, field, meta, meta field, repeat, repeatable
|
5 |
Requires at least: 3.9
|
6 |
Tested up to: 4.0
|
7 |
-
Stable tag: 1.0.
|
8 |
License: GPLv2
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -31,6 +31,7 @@ https://www.youtube.com/watch?v=WxPZurn0yvI
|
|
31 |
* Image
|
32 |
* File
|
33 |
* Relation
|
|
|
34 |
|
35 |
= How to get meta data ? =
|
36 |
|
@@ -60,6 +61,12 @@ https://github.com/inc2734/smart-custom-fields/
|
|
60 |
|
61 |
== Changelog ==
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
= 1.0.1 =
|
64 |
* Add display condition by post id.
|
65 |
* Fix bug that is not displayed wysiwyg editor when there are not content editor.
|
4 |
Tags: plugin, custom field, custom, field, meta, meta field, repeat, repeatable
|
5 |
Requires at least: 3.9
|
6 |
Tested up to: 4.0
|
7 |
+
Stable tag: 1.0.2
|
8 |
License: GPLv2
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
31 |
* Image
|
32 |
* File
|
33 |
* Relation
|
34 |
+
* Color picker
|
35 |
|
36 |
= How to get meta data ? =
|
37 |
|
61 |
|
62 |
== Changelog ==
|
63 |
|
64 |
+
= 1.0.2 =
|
65 |
+
* Add color picker field.
|
66 |
+
* Add smart-cf-before-save-post action hook.
|
67 |
+
* Add smart-cf-after-save-post action hook.
|
68 |
+
* Add smart-cf-validate-save-post filter hook.
|
69 |
+
|
70 |
= 1.0.1 =
|
71 |
* Add display condition by post id.
|
72 |
* Fix bug that is not displayed wysiwyg editor when there are not content editor.
|
smart-custom-fields.php
CHANGED
@@ -3,11 +3,11 @@
|
|
3 |
* Plugin name: Smart Custom Fields
|
4 |
* Plugin URI: https://github.com/inc2734/smart-custom-fields/
|
5 |
* Description: Smart Custom Fields is a simple plugin that management custom fields.
|
6 |
-
* Version: 1.0.
|
7 |
* Author: Takashi Kitajima
|
8 |
* Author URI: http://2inc.org
|
9 |
* Created: October 9, 2014
|
10 |
-
* Modified: October
|
11 |
* Text Domain: smart-custom-fields
|
12 |
* Domain Path: /languages/
|
13 |
* License: GPLv2
|
@@ -67,7 +67,6 @@ class Smart_Custom_Fields {
|
|
67 |
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
|
68 |
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 10, 2 );
|
69 |
add_action( 'save_post', array( $this, 'save_post' ) );
|
70 |
-
add_action( 'wp_ajax_smart-cf-relational-posts-search', array( $this, 'relational_posts_search' ) );
|
71 |
}
|
72 |
|
73 |
/**
|
@@ -113,28 +112,9 @@ class Smart_Custom_Fields {
|
|
113 |
'image_uploader_title' => esc_html__( 'Image setting', 'smart-custom-fields' ),
|
114 |
'file_uploader_title' => esc_html__( 'File setting', 'smart-custom-fields' ),
|
115 |
) );
|
116 |
-
add_action( 'after_wp_tiny_mce', array( $this, 'after_wp_tiny_mce' ) );
|
117 |
-
|
118 |
-
// relation field
|
119 |
-
wp_enqueue_script(
|
120 |
-
SCF_Config::PREFIX . 'editor-relation',
|
121 |
-
plugin_dir_url( __FILE__ ) . 'js/editor-relation.js',
|
122 |
-
array( 'jquery' ),
|
123 |
-
null,
|
124 |
-
true
|
125 |
-
);
|
126 |
-
wp_localize_script( SCF_Config::PREFIX . 'editor-relation', 'smart_cf_relation', array(
|
127 |
-
'endpoint' => admin_url( 'admin-ajax.php' ),
|
128 |
-
'action' => SCF_Config::PREFIX . 'relational-posts-search',
|
129 |
-
'nonce' => wp_create_nonce( SCF_Config::NAME . '-relation' )
|
130 |
-
) );
|
131 |
}
|
132 |
}
|
133 |
|
134 |
-
public function after_wp_tiny_mce() {
|
135 |
-
printf( '<script type="text/javascript" src="%s"></script>', plugin_dir_url( __FILE__ ) . 'js/editor-wysiwyg.js' );
|
136 |
-
}
|
137 |
-
|
138 |
/**
|
139 |
* add_meta_boxes
|
140 |
* 投稿画面にカスタムフィールドを表示
|
@@ -268,16 +248,31 @@ class Smart_Custom_Fields {
|
|
268 |
if ( in_array( $name, $multiple_data_fields ) && $value === '' )
|
269 |
continue;
|
270 |
if ( !is_array( $value ) ) {
|
271 |
-
add_post_meta( $post_id, $name, $value );
|
272 |
} else {
|
273 |
foreach ( $value as $val ) {
|
274 |
-
add_post_meta( $post_id, $name, $val );
|
275 |
}
|
276 |
}
|
277 |
}
|
278 |
}
|
279 |
}
|
280 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
281 |
/**
|
282 |
* get_post_custom
|
283 |
* @param int $post_id
|
@@ -486,28 +481,5 @@ class Smart_Custom_Fields {
|
|
486 |
}
|
487 |
echo '</table></div>';
|
488 |
}
|
489 |
-
|
490 |
-
/**
|
491 |
-
* relational_posts_search
|
492 |
-
*/
|
493 |
-
public function relational_posts_search() {
|
494 |
-
check_ajax_referer( SCF_Config::NAME . '-relation', 'nonce' );
|
495 |
-
$_posts = array();
|
496 |
-
if ( isset( $_POST['post_types'], $_POST['click_count' ] ) ) {
|
497 |
-
$post_type = explode( ',', $_POST['post_types'] );
|
498 |
-
$posts_per_page = get_option( 'posts_per_page' );
|
499 |
-
$offset = $_POST['click_count'] * $posts_per_page;
|
500 |
-
$_posts = get_posts( array(
|
501 |
-
'post_type' => $post_type,
|
502 |
-
'offset' => $offset,
|
503 |
-
'order' => 'ASC',
|
504 |
-
'orderby' => 'ID',
|
505 |
-
'posts_per_page' => $posts_per_page,
|
506 |
-
) );
|
507 |
-
}
|
508 |
-
header( 'Content-Type: application/json; charset=utf-8' );
|
509 |
-
echo json_encode( $_posts );
|
510 |
-
die();
|
511 |
-
}
|
512 |
}
|
513 |
new Smart_Custom_Fields();
|
3 |
* Plugin name: Smart Custom Fields
|
4 |
* Plugin URI: https://github.com/inc2734/smart-custom-fields/
|
5 |
* Description: Smart Custom Fields is a simple plugin that management custom fields.
|
6 |
+
* Version: 1.0.2
|
7 |
* Author: Takashi Kitajima
|
8 |
* Author URI: http://2inc.org
|
9 |
* Created: October 9, 2014
|
10 |
+
* Modified: October 21, 2014
|
11 |
* Text Domain: smart-custom-fields
|
12 |
* Domain Path: /languages/
|
13 |
* License: GPLv2
|
67 |
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
|
68 |
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 10, 2 );
|
69 |
add_action( 'save_post', array( $this, 'save_post' ) );
|
|
|
70 |
}
|
71 |
|
72 |
/**
|
112 |
'image_uploader_title' => esc_html__( 'Image setting', 'smart-custom-fields' ),
|
113 |
'file_uploader_title' => esc_html__( 'File setting', 'smart-custom-fields' ),
|
114 |
) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
}
|
116 |
}
|
117 |
|
|
|
|
|
|
|
|
|
118 |
/**
|
119 |
* add_meta_boxes
|
120 |
* 投稿画面にカスタムフィールドを表示
|
248 |
if ( in_array( $name, $multiple_data_fields ) && $value === '' )
|
249 |
continue;
|
250 |
if ( !is_array( $value ) ) {
|
251 |
+
$this->add_post_meta( $post_id, $name, $value );
|
252 |
} else {
|
253 |
foreach ( $value as $val ) {
|
254 |
+
$this->add_post_meta( $post_id, $name, $val );
|
255 |
}
|
256 |
}
|
257 |
}
|
258 |
}
|
259 |
}
|
260 |
|
261 |
+
/**
|
262 |
+
* add_post_meta
|
263 |
+
* @param int $post_id
|
264 |
+
* @param string $name
|
265 |
+
* @param mixed $value
|
266 |
+
*/
|
267 |
+
protected function add_post_meta( $post_id, $name, $value ) {
|
268 |
+
do_action( SCF_Config::PREFIX . '-before-save-post', $post_id, $name, $value );
|
269 |
+
$is_valid = apply_filters( SCF_Config::PREFIX . '-validate-save-post', true, $post_id, $name, $value );
|
270 |
+
if ( $is_valid ) {
|
271 |
+
add_post_meta( $post_id, $name, $value );
|
272 |
+
}
|
273 |
+
do_action( SCF_Config::PREFIX . '-after-save-post', $post_id, $name, $value );
|
274 |
+
}
|
275 |
+
|
276 |
/**
|
277 |
* get_post_custom
|
278 |
* @param int $post_id
|
481 |
}
|
482 |
echo '</table></div>';
|
483 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
484 |
}
|
485 |
new Smart_Custom_Fields();
|