/** * Save meta box fields. * * @access public * @since 1.0.0 * @param int $post_id * @return void */ public function meta_box_save($post_id) { global $post, $messages; // Verify if (get_post_type() != $this->post_type || !wp_verify_nonce($_POST['pp-customizer-customizer_' . $this->post_type . '_noonce'], plugin_basename(dirname(PP_Customizer_Customizer()->plugin_path)))) { return $post_id; } if (isset($_POST['post_type']) && 'page' == esc_attr($_POST['post_type'])) { if (!current_user_can('edit_page', $post_id)) { return $post_id; } } else { if (!current_user_can('edit_post', $post_id)) { return $post_id; } } $field_data = $this->get_custom_fields_settings(); $fields = array_keys($field_data); foreach ($fields as $f) { ${$f} = strip_tags(trim($_POST[$f])); // Escape the URLs. if ('url' == $field_data[$f]['type']) { ${$f} = esc_url(${$f}); } if (get_post_meta($post_id, '_' . $f) == '') { add_post_meta($post_id, '_' . $f, ${$f}, true); } elseif (${$f} != get_post_meta($post_id, '_' . $f, true)) { update_post_meta($post_id, '_' . $f, ${$f}); } elseif (${$f} == '') { delete_post_meta($post_id, '_' . $f, get_post_meta($post_id, '_' . $f, true)); } } }
if (!defined('ABSPATH')) { exit; } // Exit if accessed directly /** * Returns the main instance of PP_Customizer_Customizer to prevent the need to use globals. * * @since 1.0.0 * @return object PP_Customizer_Customizer */ function PP_Customizer_Customizer() { return PP_Customizer_Customizer::instance(); } // End PP_Customizer_Customizer() PP_Customizer_Customizer(); /** * Main PP_Customizer_Customizer Class * * @class PP_Customizer_Customizer * @version 1.0.0 * @since 1.0.0 * @package PP_Customizer_Customizer * @author Matty */ final class PP_Customizer_Customizer { /** * PP_Customizer_Customizer The single instance of PP_Customizer_Customizer. * @var object * @access private
/** * Render a field of a given type. * @access public * @since 1.0.0 * @param array $args The field parameters. * @return void */ public function render_field($args) { $html = ''; if (!in_array($args['type'], $this->get_supported_fields())) { return ''; } // Supported field type sanity check. // Make sure we have some kind of default, if the key isn't set. if (!isset($args['default'])) { $args['default'] = ''; } $method = 'render_field_' . $args['type']; if (!method_exists($this, $method)) { $method = 'render_field_text'; } // Construct the key. $key = PP_Customizer_Customizer()->token . '-' . $args['section'] . '[' . $args['id'] . ']'; $method_output = $this->{$method}($key, $args); if (is_wp_error($method_output)) { // if ( defined( 'WP_DEBUG' ) || true == constant( 'WP_DEBUG' ) ) print_r( $method_output ); // Add better error display. } else { $html .= $method_output; } // Output the description, if the current field allows it. if (isset($args['type']) && !in_array($args['type'], (array) apply_filters('wf_no_description_fields', array('checkbox')))) { if (isset($args['description'])) { $description = '<p class="description">' . wp_kses_post($args['description']) . '</p>' . "\n"; if (in_array($args['type'], (array) apply_filters('wf_newline_description_fields', array('textarea', 'select')))) { $description = wpautop($description); } $html .= $description; } } echo $html; }
/** * Validate the settings. * @access public * @since 1.0.0 * @param array $input Inputted data. * @return array Validated data. */ public function validate_settings($input) { $sections = PP_Customizer_Customizer()->settings->get_settings_sections(); $tab = $this->_get_current_tab($sections); return PP_Customizer_Customizer()->settings->validate_settings($input, $tab); }