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.option.php

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

80 lines 2.0 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_Option class.
10 */
11 class Smart_Custom_Fields_Controller_Option extends Smart_Custom_Fields_Controller_Base {
12
13 /**
14 * __construct
15 */
16 public function __construct() {
17 parent::__construct();
18 add_action( SCF_Config::PREFIX . 'custom-options-page', array( $this, 'save_option' ) );
19 add_action( SCF_Config::PREFIX . 'custom-options-page', array( $this, 'custom_options_page' ) );
20 }
21
22 /**
23 * Loading resources for term edit page.
24 *
25 * @param string $hook The current admin page.
26 */
27 public function admin_enqueue_scripts( $hook ) {
28 parent::admin_enqueue_scripts( $hook );
29 wp_enqueue_style(
30 SCF_Config::PREFIX . 'option',
31 SMART_CUSTOM_FIELDS_URL . '/css/option.css',
32 array(),
33 filemtime( SMART_CUSTOM_FIELDS_PATH . '/css/option.css' )
34 );
35 }
36
37 /**
38 * Displaying custom fields in custom options page.
39 *
40 * @param stdClass $option Option object.
41 */
42 public function custom_options_page( $option ) {
43 $settings = SCF::get_settings( $option );
44 if ( ! $settings ) {
45 return;
46 }
47
48 $callback_args = array();
49 ?>
50 <form method="post" action="">
51 <?php foreach ( $settings as $setting ) : ?>
52 <?php $callback_args['args'] = $setting->get_groups(); ?>
53 <table class="form-table">
54 <tr>
55 <th scope="row"><?php echo esc_html( $setting->get_title() ); ?></th>
56 <td><?php $this->display_meta_box( $option, $callback_args ); ?></td>
57 </tr>
58 </table>
59 <?php endforeach; ?>
60 <p class="submit">
61 <input type="submit" name="submit" id="submit" class="button button-primary" value="<?php esc_attr_e( 'Save settings', 'smart-custom-fields' ); ?>">
62 </p>
63 </form>
64 <?php
65 }
66
67 /**
68 * Saving meta data from custom fields in custom options page.
69 *
70 * @param stdClass $option Option object.
71 */
72 public function save_option( $option ) {
73 if ( ! filter_input( INPUT_POST, SCF_Config::NAME, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ) ) {
74 return;
75 }
76
77 $this->save( filter_input_array( INPUT_POST ), $option );
78 }
79 }
80