/**
  * @internal
  */
 public function _form_render($data)
 {
     $this->add_admin_static();
     $options = array(array('custom_css' => array('title' => false, 'type' => 'box', 'options' => self::$user_options)));
     $values = FW_Request::POST(FW_Option_Type::get_default_name_prefix(), fw_get_db_extension_data($this->get_name(), 'options'));
     echo fw()->backend->render_options($options, $values);
     $data['submit']['html'] = '<button class="button-primary button-large">' . __('Save', 'fw') . '</button>';
     unset($options);
     return $data;
 }
 public function setting_sanitize_callback($input)
 {
     $input = json_decode($input, true);
     if (is_null($input)) {
         return null;
     }
     $POST = array();
     foreach ($input as $var) {
         fw_aks(fw_html_attr_name_to_array_multi_key($var['name']), $var['value'], $POST);
     }
     $value = fw_get_options_values_from_input(array($this->id => $this->fw_option), fw_akg(FW_Option_Type::get_default_name_prefix(), $POST));
     $value = array_pop($value);
     return $value;
 }
Example #3
0
 /**
  * @param WP_Customize_Manager $wp_customize
  * @param array $options
  * @param array $parent_data {'type':'...','id':'...'}
  */
 private function customizer_register_options($wp_customize, $options, $parent_data = array())
 {
     $collected = array();
     fw_collect_options($collected, $options, array('limit_option_types' => false, 'limit_container_types' => false, 'limit_level' => 1, 'info_wrapper' => true));
     if (empty($collected)) {
         return;
     }
     foreach ($collected as &$opt) {
         switch ($opt['group']) {
             case 'container':
                 $_collected = array();
                 fw_collect_options($_collected, $opt['option']['options'], array('limit_option_types' => array(), 'limit_container_types' => false, 'limit_level' => 1, 'limit' => 1, 'info_wrapper' => false));
                 $has_containers = !empty($_collected);
                 unset($_collected);
                 $children_data = array('group' => 'container', 'id' => $opt['id']);
                 $args = array('title' => empty($opt['option']['title']) ? fw_id_to_title($opt['id']) : $opt['option']['title'], 'description' => empty($opt['option']['desc']) ? '' : $opt['option']['desc']);
                 if (isset($opt['option']['wp-customizer-args']) && is_array($opt['option']['wp-customizer-args'])) {
                     $args = array_merge($opt['option']['wp-customizer-args'], $args);
                 }
                 if ($has_containers) {
                     if ($parent_data) {
                         trigger_error($opt['id'] . ' panel can\'t have a parent (' . $parent_data['id'] . ')', E_USER_WARNING);
                         break;
                     }
                     $wp_customize->add_panel($opt['id'], $args);
                     $children_data['customizer_type'] = 'panel';
                 } else {
                     if ($parent_data) {
                         if ($parent_data['customizer_type'] === 'panel') {
                             $args['panel'] = $parent_data['id'];
                         } else {
                             trigger_error($opt['id'] . ' section can have only panel parent (' . $parent_data['id'] . ')', E_USER_WARNING);
                             break;
                         }
                     }
                     $wp_customize->add_section($opt['id'], $args);
                     $children_data['customizer_type'] = 'section';
                 }
                 $this->customizer_register_options($wp_customize, $opt['option']['options'], $children_data);
                 unset($children_data);
                 break;
             case 'option':
                 $setting_id = FW_Option_Type::get_default_name_prefix() . '[' . $opt['id'] . ']';
                 $args = array('label' => empty($opt['option']['label']) ? fw_id_to_title($opt['id']) : $opt['option']['label'], 'description' => empty($opt['option']['desc']) ? '' : $opt['option']['desc'], 'settings' => $setting_id);
                 if (isset($opt['option']['wp-customizer-args']) && is_array($opt['option']['wp-customizer-args'])) {
                     $args = array_merge($opt['option']['wp-customizer-args'], $args);
                 }
                 if ($parent_data) {
                     if ($parent_data['customizer_type'] === 'section') {
                         $args['section'] = $parent_data['id'];
                     } else {
                         trigger_error('Invalid control parent: ' . $parent_data['customizer_type'], E_USER_WARNING);
                         break;
                     }
                 } else {
                     // the option is not placed in a section, create a section automatically
                     $args['section'] = 'fw_option_auto_section_' . $opt['id'];
                     $wp_customize->add_section($args['section'], array('title' => empty($opt['option']['label']) ? fw_id_to_title($opt['id']) : $opt['option']['label']));
                 }
                 if (!class_exists('_FW_Customizer_Setting_Option')) {
                     require_once fw_get_framework_directory('/includes/customizer/class--fw-customizer-setting-option.php');
                 }
                 if (!class_exists('_FW_Customizer_Control_Option_Wrapper')) {
                     require_once fw_get_framework_directory('/includes/customizer/class--fw-customizer-control-option-wrapper.php');
                 }
                 $wp_customize->add_setting(new _FW_Customizer_Setting_Option($wp_customize, $setting_id, array('default' => fw()->backend->option_type($opt['option']['type'])->get_value_from_input($opt['option'], null), 'fw_option' => $opt['option'])));
                 $wp_customize->add_control(new _FW_Customizer_Control_Option_Wrapper($wp_customize, $opt['id'], $args));
                 break;
             default:
                 trigger_error('Unknown group: ' . $opt['group'], E_USER_WARNING);
         }
     }
 }
Example #4
0
/**
 * Get correct values from input (POST) for given options
 * This values can be saved in db then replaced with $option['value'] for each option
 * @param array $options
 * @param array $input_array
 * @return array Values
 */
function fw_get_options_values_from_input(array $options, $input_array = null)
{
    if (!is_array($input_array)) {
        $input_array = FW_Request::POST(FW_Option_Type::get_default_name_prefix());
    }
    $values = array();
    foreach (fw_extract_only_options($options) as $id => $option) {
        $values[$id] = fw()->backend->option_type($option['type'])->get_value_from_input($option, isset($input_array[$id]) ? $input_array[$id] : null);
        if (is_null($values[$id])) {
            // do not save null values
            unset($values[$id]);
        }
    }
    return $values;
}
Example #5
0
/**
 * Set a theme customizer option value in database
 *
 * @param null $option_id Specific option id (accepts multikey). null - all options
 * @param mixed $value
 */
function fw_set_db_customizer_option($option_id = null, $value)
{
    $db_value = get_theme_mod(FW_Option_Type::get_default_name_prefix(), array());
    if (is_null($option_id)) {
        $db_value = $value;
    } else {
        fw_aks($option_id, $value, $db_value);
    }
    set_theme_mod(FW_Option_Type::get_default_name_prefix(), $db_value);
}
Example #6
0
 public function _settings_form_render($data)
 {
     /**
      * wp moves flash message error with js after first h2
      * if there are any h2 on the page it shows it wrong
      */
     echo '<h2 class="fw-hidden"></h2>';
     $options = fw()->theme->get_settings_options();
     if (empty($options)) {
         return $data;
     }
     $values = FW_Request::POST(FW_Option_Type::get_default_name_prefix(), fw_get_db_settings_option());
     echo fw()->backend->render_options($options, $values);
     $data['submit']['html'] = '<button class="button-primary button-large">' . __('Save', 'fw') . '</button>';
     return $data;
 }
 /**
  * @param WP_Customize_Manager $wp_customize
  * @param array $options
  * @param array $parent_data {'type':'...','id':'...'}
  */
 private function customizer_register_options($wp_customize, $options, $parent_data = array())
 {
     $collected = array();
     fw_collect_first_level_options($collected, $options);
     if (empty($collected['all'])) {
         return;
     }
     foreach ($collected['all'] as &$opt) {
         switch ($opt['type']) {
             case 'tab':
                 $args = array('title' => $opt['option']['title'], 'description' => empty($opt['option']['desc']) ? '' : $opt['option']['desc']);
                 if ($parent_data) {
                     trigger_error('Not supported panel parent, type: ' . $parent_data['type'], E_USER_WARNING);
                     break;
                 }
                 $wp_customize->add_panel($opt['id'], $args);
                 $this->customizer_register_options($wp_customize, $opt['option']['options'], array('type' => 'panel', 'id' => $opt['id']));
                 break;
             case 'box':
                 $args = array('title' => $opt['option']['title']);
                 if ($parent_data) {
                     if ($parent_data['type'] === 'panel') {
                         $args['panel'] = $parent_data['id'];
                     } else {
                         trigger_error('Not supported section parent, type: ' . $parent_data['type'], E_USER_WARNING);
                         break;
                     }
                 }
                 $wp_customize->add_section($opt['id'], $args);
                 $this->customizer_register_options($wp_customize, $opt['option']['options'], array('type' => 'section', 'id' => $opt['id']));
                 break;
             case 'option':
                 $setting_id = FW_Option_Type::get_default_name_prefix() . '[' . $opt['id'] . ']';
                 $args = array('label' => empty($opt['option']['label']) ? '' : $opt['option']['label'], 'description' => empty($opt['option']['desc']) ? '' : $opt['option']['desc'], 'settings' => $setting_id, 'type' => 'radio', 'choices' => array('a' => 'Demo A', 'b' => 'Demo B'));
                 if ($parent_data) {
                     if ($parent_data['type'] === 'section') {
                         $args['section'] = $parent_data['id'];
                     } else {
                         trigger_error('Not supported control parent, type: ' . $parent_data['type'], E_USER_WARNING);
                         break;
                     }
                 } else {
                     // the option is not placed in a section, create a section automatically
                     $args['section'] = 'fw_option_auto_section_' . $opt['id'];
                     $wp_customize->add_section($args['section'], array('title' => empty($opt['option']['label']) ? fw_id_to_title($opt['id']) : $opt['option']['label']));
                 }
                 if (!class_exists('_FW_Customizer_Control_Option_Wrapper')) {
                     require_once fw_get_framework_directory('/includes/customizer/class--fw-customizer-control-option-wrapper.php');
                 }
                 $wp_customize->add_setting($setting_id, array('default' => fw()->backend->option_type($opt['option']['type'])->get_value_from_input($opt['option'], null)));
                 $control = new _FW_Customizer_Control_Option_Wrapper($wp_customize, $opt['id'], $args, array('fw_option' => $opt['option']));
                 add_filter("customize_sanitize_{$setting_id}", array($control, 'setting_sanitize_callback'), 10, 2);
                 $wp_customize->add_control($control);
                 break;
             default:
                 trigger_error('Not supported option in customizer, type: ' . $opt['type'], E_USER_WARNING);
                 // todo: uncomment
         }
     }
 }
 /**
  * @internal
  *
  * @param $data
  *
  * @return mixed
  */
 public function _form_render($data)
 {
     $options = $this->get_seo_options();
     if (empty($options)) {
         return $data;
     }
     $values = FW_Request::POST(FW_Option_Type::get_default_name_prefix(), fw_get_db_extension_data($this->get_name(), 'options'));
     echo fw()->backend->render_options($options, $values);
     $data['submit']['html'] = '<button class="button-primary button-large">' . __('Save', 'fw') . '</button>';
     unset($options);
     return $data;
 }
 /**
  * Solve the problem with striped backslashes by wordpress when doing add_post_meta
  *
  * @internal
  *
  * @param int $post_id
  * @param string $key
  * @param mixed $value
  **/
 public function _action_import_post_meta($post_id, $key, $value)
 {
     if ($key != FW_Option_Type::get_default_name_prefix() || !isset($value[$this->builder_option_key])) {
         return;
     }
     fw_set_db_post_option($post_id, $this->builder_option_key, $value[$this->builder_option_key]);
 }
 /**
  * Fixes and prepare defaults
  *
  * @param string $id
  * @param array  $option
  * @param array  $data
  * @return array
  */
 private function prepare($id, &$option, &$data)
 {
     $data = array_merge(array('id_prefix' => FW_Option_Type::get_default_id_prefix(), 'name_prefix' => FW_Option_Type::get_default_name_prefix()), $data);
     $option = array_merge($this->get_defaults(), $option, array('type' => $this->get_type()));
     if (!isset($option['attr'])) {
         $option['attr'] = array();
     }
     if (!isset($option['title'])) {
         $option['title'] = fw_id_to_title($id);
     }
     $option['attr']['class'] = 'fw-container fw-container-type-' . $option['type'] . (isset($option['attr']['class']) ? ' ' . $option['attr']['class'] : '');
 }
Example #11
0
 public function _settings_form_render($data)
 {
     $options = fw()->theme->get_settings_options();
     if (empty($options)) {
         return $data;
     }
     if ($values = FW_Request::POST(FW_Option_Type::get_default_name_prefix())) {
         // This is form submit, extract correct values from $_POST values
         $values = fw_get_options_values_from_input($options, $values);
     } else {
         // Extract previously saved correct values
         $values = fw_get_db_settings_option();
     }
     wp_enqueue_script('fw-form-helpers');
     fw_render_view(fw_get_framework_directory('/views/backend-settings-form.php'), array('options' => $options, 'values' => $values, 'focus_tab_input_name' => '_focus_tab', 'reset_input_name' => '_fw_reset_options'), false);
     $data['submit']['html'] = fw_html_tag('input', array('type' => 'submit', 'name' => '_fw_save_options', 'value' => __('Save', 'fw'), 'class' => 'button-primary button-large')) . ' &nbsp;&nbsp; ' . fw_html_tag('input', array('type' => 'submit', 'name' => '_fw_reset_options', 'value' => __('Reset', 'fw'), 'class' => 'button-secondary button-large'));
     return $data;
 }
Example #12
0
 public function _settings_form_render($data)
 {
     $this->enqueue_options_static(array());
     wp_enqueue_script('fw-form-helpers');
     $options = fw()->theme->get_settings_options();
     if (empty($options)) {
         return $data;
     }
     if ($values = FW_Request::POST(FW_Option_Type::get_default_name_prefix())) {
         // This is form submit, extract correct values from $_POST values
         $values = fw_get_options_values_from_input($options, $values);
     } else {
         // Extract previously saved correct values
         $values = fw_get_db_settings_option();
     }
     $ajax_submit = fw()->theme->get_config('settings_form_ajax_submit');
     $side_tabs = fw()->theme->get_config('settings_form_side_tabs');
     $data['attr']['class'] = 'fw-settings-form';
     if ($side_tabs) {
         $data['attr']['class'] .= ' fw-backend-side-tabs';
     }
     $data['submit']['html'] = '<!-- -->';
     // is generated in view
     do_action('fw_settings_form_render', array('ajax_submit' => $ajax_submit, 'side_tabs' => $side_tabs));
     fw_render_view(fw_get_framework_directory('/views/backend-settings-form.php'), array('options' => $options, 'values' => $values, 'focus_tab_input_name' => '_focus_tab', 'reset_input_name' => '_fw_reset_options', 'ajax_submit' => $ajax_submit, 'side_tabs' => $side_tabs), false);
     return $data;
 }