PluginProbe
Smart Custom Fields / trunk
Smart Custom Fields vtrunk
1.5.1 1.5.2 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.7.0 2.0.0 2.0.1 2.1.0 2.1.1 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 3.0.0 3.0.1 3.1.0 3.1.1 3.1.2 All 68 releases
smart-custom-fields / classes / controller / class.editor.php

class.editor.php in Smart Custom Fields trunk, at classes/controller/class.editor.php

64 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package smart-custom-fields
4 * @author inc2734
5 * @license GPL-2.0+
6 */
7
8 /**
9 * Smart_Custom_Fields_Controller_Editor class.
10 */
11 class Smart_Custom_Fields_Controller_Editor extends Smart_Custom_Fields_Controller_Base {
12
13 /**
14 * __construct
15 */
16 public function __construct() {
17 parent::__construct();
18 add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 10, 2 );
19 add_action( 'save_post', array( $this, 'save_post' ) );
20 }
21
22 /**
23 * Displaying custom fields in post edit page.
24 *
25 * @param string $post_type Post type.
26 * @param WP_Post $post WP_Post object.
27 */
28 public function add_meta_boxes( $post_type, $post ) {
29 $settings = SCF::get_settings( $post );
30 foreach ( $settings as $setting ) {
31 add_meta_box(
32 SCF_Config::PREFIX . 'custom-field-' . $setting->get_id(),
33 $setting->get_title(),
34 array( $this, 'display_meta_box' ),
35 $post_type,
36 'normal',
37 'default',
38 $setting->get_groups()
39 );
40 }
41 }
42
43 /**
44 * Saving meta data from custom fields in post edit page.
45 *
46 * @param int $post_id Post id.
47 */
48 public function save_post( $post_id ) {
49 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
50 return;
51 }
52
53 if ( wp_is_post_autosave( $post_id ) || wp_is_post_revision( $post_id ) ) {
54 return;
55 }
56
57 if ( ! filter_input( INPUT_POST, SCF_Config::NAME, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ) ) {
58 return;
59 }
60
61 $this->save( filter_input_array( INPUT_POST ), get_post( $post_id ) );
62 }
63 }
64