/** * @inheritdoc * * @param array $arguments */ public function process_call($arguments) { $am = $this->get_am(); $am->ajax_begin(array('nonce' => $am->get_action_js_name(Types_Ajax::CALLBACK_SETTINGS_ACTION))); $setting = sanitize_text_field(wpcf_getpost('setting')); $setting_value = wpcf_getpost('setting_value'); if (!is_array($setting_value)) { parse_str($setting_value, $setting_value); $setting_value = array_pop($setting_value); } $sanitized_value = array(); foreach ($setting_value as $key => $value) { $sanitized_key = sanitize_title($key); $sanitized_value[$sanitized_key] = sanitize_text_field($value); } // use toolset settings if available if (class_exists('Toolset_Settings') && method_exists('Toolset_Settings', 'get_instance')) { $toolset_settings = Toolset_Settings::get_instance(); if (method_exists($toolset_settings, 'save')) { $toolset_settings[$setting] = $sanitized_value; $toolset_settings->save(); $am->ajax_finish('success', true); } } else { update_option($setting, $sanitized_value); $am->ajax_finish('success', true); } // default toolset setting error will be used // todo throw specific error $am->ajax_finish(array('error'), false); }
public function get_stored_value(Types_Setting_Interface $setting) { if ($this->stored_value === null) { if (class_exists('Toolset_Settings') && method_exists('Toolset_Settings', 'get_instance')) { $toolset_settings = Toolset_Settings::get_instance(); $full_setting = $toolset_settings->get($setting->get_id()); } else { $full_setting = get_option($setting->get_id()); } $value = isset($full_setting[$this->get_id()]) ? $full_setting[$this->get_id()] : $this->default; $this->stored_value = $value; } return $this->stored_value; }
public function clear_settings_instance() { Toolset_Settings::clear_instance(); }
/** * Update the stored data once a fields group has been saved. * * @param $group_id string The ID of the group being saved. * * @since 2.2 */ function types_store_fields_on_group_save($group_id) { if (empty($this->pending_to_add) && empty($this->pending_to_remove)) { return; } $relevanssi_fields_to_remove = array(); $relevanssi_fields_changed = false; $toolset_settings = Toolset_Settings::get_instance(); $relevanssi_fields_to_index = isset($toolset_settings['relevanssi_fields_to_index']) ? $toolset_settings['relevanssi_fields_to_index'] : array(); // Note that the 'refresh' argument is temporary and will not me needed much longer $args = array('domain' => 'posts', 'field_type' => array('textfield', 'textarea', 'wysiwyg'), 'group_id' => $group_id, 'refresh' => true); // https://onthegosystems.myjetbrains.com/youtrack/issue/types-742 $group_fields = apply_filters('types_filter_query_field_definitions', array(), $args); foreach ($group_fields as $field) { if (in_array($field['slug'], $this->pending_to_add)) { $real_custom_field_name = wpcf_types_get_meta_prefix($field) . $field['slug']; if (!in_array($real_custom_field_name, $relevanssi_fields_to_index)) { $relevanssi_fields_to_index[] = $real_custom_field_name; $relevanssi_fields_changed = true; } } if (in_array($field['slug'], $this->pending_to_remove)) { $real_custom_field_name = wpcf_types_get_meta_prefix($field) . $field['slug']; if (in_array($real_custom_field_name, $relevanssi_fields_to_index)) { $relevanssi_fields_to_remove[] = $real_custom_field_name; $relevanssi_fields_changed = true; } } } if (count($relevanssi_fields_to_remove) > 0) { $relevanssi_fields_to_index = array_diff($relevanssi_fields_to_index, $relevanssi_fields_to_remove); $relevanssi_fields_to_index = is_array($relevanssi_fields_to_index) ? array_values($relevanssi_fields_to_index) : array(); } if ($relevanssi_fields_changed) { $toolset_settings->relevanssi_fields_to_index = $relevanssi_fields_to_index; $toolset_settings->save(); } }
function toolset_update_toolset_admin_bar_options() { $toolset_options = Toolset_Settings::get_instance(); if (!current_user_can('manage_options')) { $data = array('type' => 'capability', 'message' => __('You do not have permissions for that.', 'wpv-views')); wp_send_json_error($data); } if (!isset($_POST["wpnonce"]) || !wp_verify_nonce($_POST["wpnonce"], 'toolset_admin_bar_settings_nonce')) { $data = array('type' => 'nonce', 'message' => __('Your security credentials have expired. Please reload the page to get new ones.', 'wpv-views')); wp_send_json_error($data); } $frontend = isset($_POST['frontend']) ? sanitize_text_field($_POST['frontend']) : 'true'; $backend = wpv_getpost('backend', null, array('disable', 'editor', 'always')); if (null != $backend) { $toolset_options['shortcodes_generator'] = $backend; } $toolset_options['show_admin_bar_shortcut'] = $frontend == 'true' ? 'on' : 'off'; $toolset_options->save(); wp_send_json_success(); }
public static function clear_instance() { if (Toolset_Settings::$instance) { Toolset_Settings::$instance = null; } }