callback) && !empty($this->id) && $this->title !== '' ) { if ($this->base->cache->doing_ajax) { add_filter(ACF_Stylizer_Constants::HOOK_VALIDATE_DATA, array($this, 'validate_data')); } else { $this->id = ACF_Stylizer_Constants::TOKEN . '_meta_box_' . $this->id; add_action('add_meta_boxes', array($this, 'add_meta_box')); add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'), 0); } } } /** * Get a default value based on the provided name. * * @since 2.0.0 * * @access protected * @param string $name Name of the value to return. * @return mixed Default value if it exists, otherwise an empty string. */ protected function _default($name) { switch ($name) { /** * Function used to populate the meta box. * * @since 2.0.0 * * @var function */ case 'callback': return array($this, 'callback'); /** * Data that should be set as the $args property of the box array. * * @since 2.0.0 * * @var array */ case 'callback_args': return null; /** * CSS classes added to the meta box. * * @since 2.0.0 * * @var array */ case 'classes': /** * Fields displayed in the meta box. * * @since 2.0.0 * * @var array */ case 'fields': /** * Value collection for the fields displayed in the meta box. * * @since 2.0.0 * * @var mixed */ case 'value_collection': return array(); /** * Context within the screen where the boxes should display. * * @since 2.0.0 * * @var string */ case 'context': return 'advanced'; /** * Base ID for the meta box. * * @since 2.0.0 * * @var string */ case 'id': /** * Title displayed in the meta box. * * @since 2.0.0 * * @var string */ case 'title': return ''; /** * Option name for the fields in the meta box. * * @since 2.0.0 * * @var string */ case 'option_name': return ACF_Stylizer_Constants::TOKEN; /** * Priority within the context where the boxes should show. * * @since 2.0.0 * * @var string */ case 'priority': return 'default'; } return parent::_default($name); } /** * Validate data associated with this meta box. * * @since 2.1.0 * * @access public * @param array $valid_data Existing validated data. * @return array Modified validated data. */ public function validate_data($valid_data) { if ( !empty($this->option_name) && isset($_POST[$this->option_name]) && is_array($_POST[$this->option_name]) ) { foreach ($this->fields as $field) { $valid_data = array_merge_recursive($valid_data, $field->validate_data($_POST[$this->option_name])); } } return $valid_data; } /** * Add the meta box to the page. * * @since 2.0.0 * * @access public * @return void */ public function add_meta_box() { $title = esc_html($this->title); add_meta_box($this->id, $title, $this->callback, $this->base->cache->screen, $this->context, $this->priority, $this->callback_args); add_filter('postbox_classes_' . esc_attr($this->base->cache->screen->id) . '_' . esc_attr($this->id), array($this, 'postbox_classes')); } /** * The default callback that is fired for the meta box when one isn't provided. * * @since 2.0.0 * * @access public * @return void */ public function callback() { echo '
'; foreach ($this->fields as $field) { $field->output(true); } echo '
'; wp_nonce_field($this->id, $this->id . '_nonce', false); } /** * Add additional classes to a meta box. * * @since 2.0.0 * * @access public * @param array $classes Current meta box classes. * @return array Modified meta box classes. */ public function postbox_classes($classes) { $add_classes = ACF_Stylizer_Utilities::check_array($this->classes); array_unshift($add_classes, 'acfs-meta-box'); return array_merge($classes, $add_classes); } /** * Verify and setup the meta box fields. * * @since 2.0.0 * * @access public * @return void */ public function admin_enqueue_scripts() { $fields = (is_array($this->fields)) ? $this->fields : array(); $verified_fields = array(); foreach ($fields as $field) { if (ACF_Stylizer_Utilities::is_field($field)) { $field->option_name = $this->option_name; $field->value_collection = $this->value_collection; $verified_fields[] = $field; } } $this->fields = $verified_fields; } /** * Add one or more fields to the meta box. * * @since 2.0.0 * * @access public * @param mixed $fields Field object or an array of field objects to add to the meta box. * @return void */ public function add_fields($fields) { $fields = ACF_Stylizer_Utilities::check_array($fields); foreach ($fields as $field) { $this->push('fields', $field); } } /** * Generate the side meta boxes. * * @since 2.1.0 Removed 'noreferrer' from links. * @since 2.0.3 Knowldge base and donation changes. * @since 2.0.2 Added knowledge base field. * @since 2.0.0 * * @access public static * @return void */ public static function side_meta_boxes() { $acfs = ACF_Stylizer(); new self(array ( 'classes' => array('acfs-meta-box-locked'), 'context' => 'side', 'id' => 'support', 'title' => __('Support', 'acf-stylizer'), 'fields' => array ( new ACF_Stylizer_Field_HTML(array ( 'content' => '' . __('Plugin developed by', 'acf-stylizer') . '
' . 'Robert Noakes' )), new ACF_Stylizer_Field_HTML(array ( 'content' => '' . __('Knowledge base available on', 'acf-stylizer') . '
' . 'Noakes Plugins' )), new ACF_Stylizer_Field_HTML(array ( 'content' => __('Running into issues with the plugin?', 'acf-stylizer') . '
' . '' . __('Submit a ticket.', 'acf-stylizer') . '' )), new ACF_Stylizer_Field_HTML(array ( 'content' => __('Have some feedback you\'d like to share?', 'acf-stylizer') . '
' . '' . __('Provide a review.', 'acf-stylizer') . '' )), new ACF_Stylizer_Field_HTML(array ( 'content' => __('Want to see the plugin in your language?', 'acf-stylizer') . '
' . '' . __('Assist with translation.', 'acf-stylizer') . '' )), new ACF_Stylizer_Field_HTML(array ( 'content' => __('Would you like to support development?', 'acf-stylizer') . '
' . '' . sprintf ( _x('Sign up for WPEngine using the banner in the \'Better Hosting with WPEngine\' meta box or %1$s.', 'Donate Link', 'acf-stylizer'), '' . __('make a donation', 'acf-stylizer') . '' ) . '' )) ) )); new self(array ( 'classes' => array('acfs-meta-box-locked'), 'context' => 'normal', 'id' => 'advertising', 'title' => __('Better Hosting with WPEngine', 'acf-stylizer'), 'fields' => array ( new ACF_Stylizer_Field_HTML(array ( 'content' => '' . 'WPEngine - Your WordPress Digital Experience Platform. Get 3 months free with annual plan purchases. - LEARN MORE' . 'WPEngine - High performance WordPress hosting that just works. Get 3 months free with annual plan purchases - LEARN MORE' . '' )) ) )); } /** * Finalize the meta boxes. * * @since 2.1.2 Removed PHP_INT_MAX reference. * @since 2.0.0 * * @access public static * @return void */ public static function finalize_meta_boxes() { add_action('add_meta_boxes', array(__CLASS__, 'remove_meta_boxes'), 9999999); do_action('add_meta_boxes', ACF_Stylizer()->cache->screen->id, null); } /** * Remove unnecessary meta boxes. * * @since 2.0.0 * * @access public static * @return void */ public static function remove_meta_boxes() { $acfs = ACF_Stylizer(); remove_meta_box('eg-meta-box', $acfs->cache->screen->id, 'normal'); remove_meta_box('mymetabox_revslider_0', $acfs->cache->screen->id, 'normal'); } }