/** * @param string $meta_type * @param int $object_id * @param string $multi_key 'abc' or 'ab/c/def' * @param null|mixed $default_value If no option found in the database, this value will be returned * @param bool|null $get_original_value Original value from db, no changes and translations * * @return mixed|null */ public static function get($meta_type, $object_id, $multi_key, $default_value = null, $get_original_value = null) { if ($get_original_value === null) { $get_original_value = is_admin(); } if (empty($multi_key)) { trigger_error('Key not specified', E_USER_WARNING); return null; } $multi_key = explode('/', $multi_key); $key = array_shift($multi_key); $multi_key = implode('/', $multi_key); $cache_key = self::$cache_key . '/' . $meta_type . '/' . $object_id . '/' . $key; try { $values = FW_Cache::get($cache_key); } catch (FW_Cache_Not_Found_Exception $e) { $values = array(); $values['original'] = get_metadata($meta_type, $object_id, $key, true); $values['prepared'] = fw_prepare_option_value($values['original']); FW_Cache::set($cache_key, $values); } if (empty($multi_key)) { return $values[$get_original_value ? 'original' : 'prepared']; } else { return fw_akg($multi_key, $values[$get_original_value ? 'original' : 'prepared'], $default_value); } }
/** * @param int $post_id * @param string $multi_key 'abc' or 'ab/c/def' * @param array|string|int|bool $set_value */ public static function set($post_id, $multi_key, $set_value) { if (empty($multi_key)) { trigger_error('Key not specified', E_USER_WARNING); return; } $multi_key = explode('/', $multi_key); $key = array_shift($multi_key); $multi_key = implode('/', $multi_key); $cache_key = self::$cache_key . '/' . $post_id . '/' . $key; if (empty($multi_key) && $multi_key !== '0') { /** Replace entire meta */ fw_update_post_meta($post_id, $key, $set_value); FW_Cache::del($cache_key); } else { /** Change only specified key */ $values = array(); $values['original'] = self::get($post_id, $key, true); $values['prepared'] = self::get($post_id, $key, false); fw_aks($multi_key, $set_value, $values['original']); fw_aks($multi_key, fw_prepare_option_value($set_value), $values['prepared']); FW_Cache::set($cache_key, $values); fw_update_post_meta($post_id, $key, $values['original']); } }
/** * Returns fonts * @return array */ public function get_fonts() { $cache_key = 'fw_option_type/' . $this->get_type(); try { return FW_Cache::get($cache_key); } catch (FW_Cache_Not_Found_Exception $e) { $fonts = array('standard' => apply_filters('fw_option_type_typography_v2_standard_fonts', array("Arial", "Verdana", "Trebuchet", "Georgia", "Times New Roman", "Tahoma", "Palatino", "Helvetica", "Calibri", "Myriad Pro", "Lucida", "Arial Black", "Gill Sans", "Geneva", "Impact", "Serif")), 'google' => json_decode(fw_get_google_fonts_v2(), true)); FW_Cache::set($cache_key, $fonts); return $fonts; } }
private function get_updates($force_check = false) { $cache_key = 'fw_ext_update/updates'; // use cache because this method may be called multiple times (to prevent useless requests to update servers) try { return FW_Cache::get($cache_key); } catch (FW_Cache_Not_Found_Exception $e) { $updates = array('framework' => $this->get_framework_update($force_check), 'theme' => $this->get_theme_update($force_check), 'extensions' => $this->get_extensions_with_updates($force_check)); FW_Cache::set($cache_key, $updates); return $updates; } }
/** * Get builder item width data * * Default widths are specified in the config, but some builder types can have custom widths * * Usage example: * <div class="<?php echo esc_attr(fw_ext_builder_get_item_width('builder-type', $item['width'] .'/frontend_class')) ?>" > * * @param string $builder_type Builder option type (some builders can have different item widths) * @param null|string $width_id Specify width id (accepts multikey) or leave empty to get all widths * @param null|mixed $default_value Return this value if specified key does not exist * @return array */ function fw_ext_builder_get_item_width($builder_type, $width_id = null, $default_value = null) { try { $cache_key = fw()->extensions->get('builder')->get_cache_key('item_widths/' . $builder_type); $widths = FW_Cache::get($cache_key); } catch (FW_Cache_Not_Found_Exception $e) { $widths = apply_filters('fw_builder_item_widths:' . $builder_type, fw()->extensions->get('builder')->get_config('default_item_widths')); FW_Cache::set($cache_key, $widths); } if (is_null($width_id)) { return $widths; } else { return fw_akg($width_id, $widths, $default_value); } }
/** * @param string $builder_type * @return array|mixed * @since 1.1.14 */ protected function get_predefined_templates($builder_type) { $cache_id = 'fw_ext_builder/predefined_templates/' . $builder_type . '/' . $this->get_type(); try { return FW_Cache::get($cache_id); } catch (FW_Cache_Not_Found_Exception $e) { $templates = array(); foreach (apply_filters('fw_ext_builder:predefined_templates:' . $builder_type . ':' . $this->get_type(), array()) as $id => $template) { if (isset($template['title']) && is_string($template['title']) && isset($template['json']) && is_string($template['json']) && null !== json_decode($template['json'])) { $templates[$id] = array('title' => $template['title'], 'json' => $template['json'], 'type' => 'predefined'); } else { trigger_error('Invalid predefined template: ' . $id, E_USER_WARNING); } } FW_Cache::set($cache_id, $templates); return $templates; } }
/** * Alternative for update_option() * @param string $option_name * @param string|null $specific_multi_key * @param array|string|int|bool $set_value */ public static function set($option_name, $specific_multi_key = null, $set_value) { $cache_key = self::$cache_key . '/' . $option_name; if ($specific_multi_key === null) { /** Replace entire option */ update_option($option_name, $set_value, false); FW_Cache::del($cache_key); } else { /** Change only specified key */ $values = array(); $values['original'] = self::get($option_name, null, true); $values['prepared'] = self::get($option_name, null, false); fw_aks($specific_multi_key, $set_value, $values['original']); fw_aks($specific_multi_key, fw_prepare_option_value($set_value), $values['prepared']); FW_Cache::set($cache_key, $values); update_option($option_name, $values['original'], false); } }
/** * Check if menu item is a MegaMenu item or is inside a MegaMenu item * @param WP_Post $item * @return bool */ function fw_ext_mega_menu_is_mm_item($item) { $cache_key = fw_ext('megamenu')->get_cache_key('/mm_item'); try { $mm_items = FW_Cache::get($cache_key); } catch (FW_Cache_Not_Found_Exception $e) { $mm_items = array(); } if (isset($mm_items[$item->ID])) { return $mm_items[$item->ID]; } $cursor_item = array('id' => $item->ID, 'parent' => $item->menu_item_parent); do { $is_mm_item = fw_ext_mega_menu_get_meta($cursor_item['id'], 'enabled'); } while (!$is_mm_item && intval($cursor_item['parent']) !== 0 && ($cursor_item = get_post($cursor_item['parent'])) && ($cursor_item = array('id' => $cursor_item->ID, 'parent' => get_post_meta($cursor_item->ID, '_menu_item_menu_item_parent', true)))); $mm_items[$item->ID] = (bool) $is_mm_item; FW_Cache::set($cache_key, $mm_items); return $mm_items[$item->ID]; }
/** * @return array {base_dir_real_path => base_dir_wp_filesystem_path} */ public static function get_base_dirs_map() { /** @var WP_Filesystem_Base $wp_filesystem */ global $wp_filesystem; if (!$wp_filesystem) { trigger_error('Filesystem is not available', E_USER_ERROR); } try { $cache_key = 'fw_wp_filesystem/base_dirs_map'; return FW_Cache::get($cache_key); } catch (FW_Cache_Not_Found_Exception $e) { $themes_dir = get_theme_root(); // Account for relative theme roots if ('/themes' == $themes_dir || !is_dir($themes_dir)) { $themes_dir = WP_CONTENT_DIR . $themes_dir; } $dirs = array(fw_fix_path(ABSPATH) => fw_fix_path($wp_filesystem->abspath()), fw_fix_path(WP_CONTENT_DIR) => fw_fix_path($wp_filesystem->wp_content_dir()), fw_fix_path(WP_PLUGIN_DIR) => fw_fix_path($wp_filesystem->wp_plugins_dir()), fw_fix_path($themes_dir) => fw_fix_path($wp_filesystem->wp_themes_dir())); FW_Cache::set($cache_key, $dirs); return $dirs; } }
private function get_post_type($post_id) { $post_id = $this->get_post_id($post_id); try { return FW_Cache::get($cache_key = $this->get_cache_key('type/' . $post_id)); } catch (FW_Cache_Not_Found_Exception $e) { FW_Cache::set($cache_key, $post_type = get_post_type(($post_revision_id = wp_is_post_revision($post_id)) ? $post_revision_id : $post_id)); return $post_type; } }
private function get_sets() { $cache_key = 'fw_option_type_icon/sets'; try { return FW_Cache::get($cache_key); } catch (FW_Cache_Not_Found_Exception $e) { $sets = apply_filters('fw_option_type_icon_sets', $this->get_default_sets()); // do not allow overwrite default sets $sets = array_merge($sets, $this->get_default_sets()); FW_Cache::set($cache_key, $sets); return $sets; } }
/** * @return Array with Google fonts */ function fw_get_google_fonts() { $cache_key = 'fw_google_fonts'; try { return FW_Cache::get($cache_key); } catch (FW_Cache_Not_Found_Exception $e) { $g_fonts = json_decode(fw_get_google_fonts_v2(), true); $old_fonts = (include dirname(__FILE__) . '/fw-google-fonts.json.php'); $fonts = array(); foreach ($g_fonts['items'] as $font) { $fonts[$font['family']] = array('family' => $font['family'], 'variants' => $font['variants'], 'position' => isset($old_fonts[$font['family']]) ? $old_fonts[$font['family']]['position'] : 99999); } $fonts = apply_filters('fw_google_fonts', $fonts); FW_Cache::set($cache_key, $fonts); return $fonts; } }
} switch ($help['icon']) { case 'info': $help['class'] = 'dashicons dashicons-info'; break; case 'video': $help['class'] = 'dashicons dashicons-video-alt3'; break; default: $help['class'] = 'dashicons dashicons-smiley'; } } try { $responsive_classes = FW_Cache::get($cache_key = 'fw:backend-option-view:responsive-classes'); } catch (FW_Cache_Not_Found_Exception $e) { FW_Cache::set($cache_key, $responsive_classes = apply_filters('fw:backend-option-view:design-default:responsive-classes', array('label' => 'fw-col-xs-12 fw-col-sm-3 fw-col-lg-2', 'input' => 'fw-col-xs-12 fw-col-sm-9 fw-col-lg-10'))); } $classes = array('option' => array('fw-backend-option', 'fw-backend-option-design-default', 'fw-backend-option-type-' . $option['type'], 'fw-row'), 'label' => array('fw-backend-option-label', 'responsive' => $responsive_classes['label']), 'input' => array('fw-backend-option-input', 'fw-backend-option-input-type-' . $option['type'], 'responsive' => $responsive_classes['input']), 'desc' => array('fw-backend-option-desc', 'responsive' => 'fw-col-xs-12 fw-col-sm-offset-3 fw-col-sm-9 fw-col-lg-offset-2 fw-col-lg-10')); if ($help) { $classes['option'][] = 'with-help'; } if ($option['label'] === false) { $classes['label']['hidden'] = 'fw-hidden'; unset($classes['label']['responsive']); $classes['input']['responsive'] = 'fw-col-xs-12'; $classes['desc']['responsive'] = 'fw-col-xs-12'; } $width_type = fw()->backend->option_type($option['type'])->_get_backend_width_type(); if (!in_array($width_type, array('auto', 'fixed', 'full'))) { $width_type = 'auto'; }
/** * Get a customizer framework option value from the database * * @param string|null $option_id Specific option id (accepts multikey). null - all options * @param null|mixed $default_value If no option found in the database, this value will be returned * // fixme: Maybe add this parameter? @ param null|bool $get_original_value Original value is that with no translations and other changes * * @return mixed|null */ function fw_get_db_customizer_option($option_id = null, $default_value = null) { // note: this contains only changed controls/options $all_db_values = get_theme_mod(FW_Option_Type::get_default_name_prefix(), array()); $cache_key = 'fw_default_options_values/customizer'; try { $all_default_values = FW_Cache::get($cache_key); } catch (FW_Cache_Not_Found_Exception $e) { // extract the default values from options array $all_default_values = fw_get_options_values_from_input(fw()->theme->get_customizer_options(), array()); FW_Cache::set($cache_key, $all_default_values); } if (is_null($option_id)) { return array_merge($all_default_values, $all_db_values); } else { $base_key = explode('/', $option_id); // note: option_id can be a multi-key 'a/b/c' $base_key = array_shift($base_key); $all_db_values = array_key_exists($base_key, $all_db_values) ? $all_db_values : $all_default_values; return fw_akg($option_id, $all_db_values, $default_value); } }
/** * Return config key value, or entire config array * Config array is merged from child configs * @param string|null $key Multi key format accepted: 'a/b/c' * @param mixed $default_value * @return mixed|null */ public final function get_config($key = null, $default_value = null) { $cache_key = self::$cache_key . '/config'; try { $config = FW_Cache::get($cache_key); } catch (FW_Cache_Not_Found_Exception $e) { $config = array('settings_form_ajax_submit' => true, 'settings_form_side_tabs' => false); if (file_exists(fw_get_template_customizations_directory('/theme/config.php'))) { $variables = fw_get_variables_from_file(fw_get_template_customizations_directory('/theme/config.php'), array('cfg' => null)); if (!empty($variables['cfg'])) { $config = array_merge($config, $variables['cfg']); unset($variables); } } if (is_child_theme() && file_exists(fw_get_stylesheet_customizations_directory('/theme/config.php'))) { $variables = fw_get_variables_from_file(fw_get_stylesheet_customizations_directory('/theme/config.php'), array('cfg' => null)); if (!empty($variables['cfg'])) { $config = array_merge($config, $variables['cfg']); unset($variables); } } unset($path); FW_Cache::set($cache_key, $config); } return $key === null ? $config : fw_akg($key, $config, $default_value); }
/** * @return Array with Google fonts */ function fw_get_google_fonts() { $cache_key = 'fw_google_fonts'; try { return FW_Cache::get($cache_key); } catch (FW_Cache_Not_Found_Exception $e) { $fonts = apply_filters('fw_google_fonts', include dirname(__FILE__) . '/fw-google-fonts.json.php'); FW_Cache::set($cache_key, $fonts); return $fonts; } }
/** * @return Array with Google fonts */ function fw_get_google_fonts() { $cache_key = 'fw_google_fonts'; try { return FW_Cache::get($cache_key); } catch (FW_Cache_Not_Found_Exception $e) { $fonts = apply_filters('fw_google_fonts', json_decode(file_get_contents(dirname(__FILE__) . '/fw-google-fonts.json'), true)); FW_Cache::set($cache_key, $fonts); return $fonts; } }
public function get_locations() { $cache_key = 'fw_extensions_locations'; try { return FW_Cache::get($cache_key); } catch (FW_Cache_Not_Found_Exception $e) { /** * { '/hello/world/extensions' => 'https://hello.com/world/extensions' } */ $custom_locations = apply_filters('fw_extensions_locations', array()); $customizations_locations = array(); if (is_child_theme()) { $customizations_locations[fw_get_stylesheet_customizations_directory('/extensions')] = fw_get_stylesheet_customizations_directory_uri('/extensions'); } $customizations_locations[fw_get_template_customizations_directory('/extensions')] = fw_get_template_customizations_directory_uri('/extensions'); $customizations_locations += $custom_locations; $locations = array(); $locations[fw_get_framework_directory('/extensions')] = array('path' => fw_get_framework_directory('/extensions'), 'uri' => fw_get_framework_directory_uri('/extensions'), 'customizations_locations' => $customizations_locations, 'is' => array('framework' => true, 'custom' => false, 'theme' => false)); foreach ($custom_locations as $path => $uri) { unset($customizations_locations[$path]); $locations[$path] = array('path' => $path, 'uri' => $uri, 'customizations_locations' => $customizations_locations, 'is' => array('framework' => false, 'custom' => true, 'theme' => false)); } array_pop($customizations_locations); $locations[fw_get_template_customizations_directory('/extensions')] = array('path' => fw_get_template_customizations_directory('/extensions'), 'uri' => fw_get_template_customizations_directory_uri('/extensions'), 'customizations_locations' => $customizations_locations, 'is' => array('framework' => false, 'custom' => false, 'theme' => true)); if (is_child_theme()) { array_pop($customizations_locations); $locations[fw_get_stylesheet_customizations_directory('/extensions')] = array('path' => fw_get_stylesheet_customizations_directory('/extensions'), 'uri' => fw_get_stylesheet_customizations_directory_uri('/extensions'), 'customizations_locations' => $customizations_locations, 'is' => array('framework' => false, 'custom' => false, 'theme' => true)); } FW_Cache::set($cache_key, $locations); return $locations; } }
/** * All backups (zip) will go in this directory * @return string */ public function get_backups_dir() { $cache_key = $this->get_cache_key('/dir'); try { return FW_Cache::get($cache_key); } catch (FW_Cache_Not_Found_Exception $e) { $uploads = wp_upload_dir(); $dir = fw_fix_path($uploads['basedir']) . '/fw-backup'; FW_Cache::set($cache_key, $dir); return $dir; } }
public final function set($item_id = null, $option_id = null, $value, array $extra_data = array()) { FW_Cache::del($cache_key_values = $this->get_cache_key('values', $item_id, $extra_data)); FW_Cache::del($cache_key_values_processed = $this->get_cache_key('values:processed', $item_id, $extra_data)); try { $options = FW_Cache::get($cache_key = $this->get_cache_key('options', $item_id, $extra_data)); } catch (FW_Cache_Not_Found_Exception $e) { FW_Cache::set($cache_key, array()); // prevent recursion FW_Cache::set($cache_key, $options = fw_extract_only_options($this->get_options($item_id, $extra_data))); } $sub_keys = null; if ($option_id) { $option_id = explode('/', $option_id); // 'option_id/sub/keys' $_option_id = array_shift($option_id); // 'option_id' $sub_keys = empty($option_id) ? null : implode('/', $option_id); // 'sub/keys' $option_id = $_option_id; unset($_option_id); $old_values = is_array($old_values = $this->get_values($item_id, $extra_data)) ? $old_values : array(); $old_value = isset($old_values[$option_id]) ? $old_values[$option_id] : null; if ($sub_keys) { // update sub_key in old_value and use the entire value $new_value = $old_value; fw_aks($sub_keys, $value, $new_value); $value = $new_value; unset($new_value); $old_value = fw_akg($sub_keys, $old_value); } if (isset($options[$option_id])) { $value = fw()->backend->option_type($options[$option_id]['type'])->storage_save($option_id, $options[$option_id], $value, $this->get_fw_storage_params($item_id, $extra_data)); } $old_values[$option_id] = $value; $this->set_values($item_id, $old_values, $extra_data); unset($old_values); } else { $old_value = is_array($old_values = $this->get_values($item_id, $extra_data)) ? $old_values : array(); if (!is_array($value)) { $value = array(); } foreach ($value as $_option_id => $_option_value) { if (isset($options[$_option_id])) { $value[$_option_id] = fw()->backend->option_type($options[$_option_id]['type'])->storage_save($_option_id, $options[$_option_id], $_option_value, $this->get_fw_storage_params($item_id, $extra_data)); } } $this->set_values($item_id, $value, $extra_data); } FW_Cache::del($cache_key_values); // fixes https://github.com/ThemeFuse/Unyson/issues/1538 FW_Cache::del($cache_key_values_processed); $this->_after_set($item_id, $option_id, $sub_keys, $old_value, $extra_data); }
/** * Scan all directories for extensions * * @param bool $reset_cache * * @return array */ private function get_installed_extensions($reset_cache = false) { $cache_key = $this->get_cache_key('installed_extensions'); if ($reset_cache) { FW_Cache::del($cache_key); } try { return FW_Cache::get($cache_key); } catch (FW_Cache_Not_Found_Exception $e) { $search_paths = array('framework' => fw_get_framework_directory('/extensions'), 'parent' => fw_get_template_customizations_directory('/extensions')); if (is_child_theme()) { $search_paths['child'] = fw_get_stylesheet_customizations_directory('/extensions'); } $extensions = array(); foreach ($search_paths as $source => $path) { $this->read_extensions($source, $path, $extensions); } FW_Cache::set($cache_key, $extensions); return $extensions; } }
public final function get_settings_options() { $cache_key = $this->get_cache_key() . '/settings_options'; try { return FW_Cache::get($cache_key); } catch (FW_Cache_Not_Found_Exception $e) { $path = $this->get_declared_path('/settings-options.php'); if (!file_exists($path)) { FW_Cache::set($cache_key, array()); return array(); } $variables = fw_get_variables_from_file($path, array('options' => array())); FW_Cache::set($cache_key, $variables['options']); return $variables['options']; } }
/** * Return config key value, or entire config array * Config array is merged from child configs * @param string|null $key Multi key format accepted: 'a/b/c' * @return mixed|null */ public final function get_config($key = null) { $cache_key = self::$cache_key . '/config'; try { $config = FW_Cache::get($cache_key); } catch (FW_Cache_Not_Found_Exception $e) { $config = array(); if (file_exists(FW_PT_CUSTOM_DIR . '/theme/config.php')) { $variables = fw_get_variables_from_file(FW_PT_CUSTOM_DIR . '/theme/config.php', array('cfg' => null)); if (!empty($variables['cfg'])) { $config = array_merge($config, $variables['cfg']); unset($variables); } } if (FW_CT && file_exists(FW_CT_CUSTOM_DIR . '/theme/config.php')) { $variables = fw_get_variables_from_file(FW_CT_CUSTOM_DIR . '/theme/config.php', array('cfg' => null)); if (!empty($variables['cfg'])) { $config = array_merge($config, $variables['cfg']); unset($variables); } } unset($path); FW_Cache::set($cache_key, $config); } return $key === null ? $config : fw_akg($key, $config); }
/** * Get extension's settings option value from the database * * @param string $extension_name * @param string|null $option_id * @param null|mixed $default_value If no option found in the database, this value will be returned * @param null|bool $get_original_value Original value is that with no translations and other changes * * @return mixed|null */ function fw_get_db_ext_settings_option($extension_name, $option_id = null, $default_value = null, $get_original_value = null) { if (!($extension = fw()->extensions->get($extension_name))) { trigger_error('Invalid extension: ' . $extension_name, E_USER_WARNING); return null; } $value = FW_WP_Option::get('fw_ext_settings_options:' . $extension_name, $option_id, $default_value, $get_original_value); if (is_null($value)) { /** * Maybe the options was never saved or the given option id does not exists * Extract the default values from the options array and try to find there the option id */ $cache_key = 'fw_default_options_values/ext_settings:' . $extension_name; try { $all_options_values = FW_Cache::get($cache_key); } catch (FW_Cache_Not_Found_Exception $e) { // extract the default values from options array $all_options_values = fw_get_options_values_from_input($extension->get_settings_options(), array()); FW_Cache::set($cache_key, $all_options_values); } if (empty($option_id)) { // option id not specified, return all options values return $all_options_values; } else { return fw_akg($option_id, $all_options_values, $default_value); } } else { return $value; } }
/** * Scan all directories for extensions * * @param bool $reset_cache * @return array */ private function get_installed_extensions($reset_cache = false) { $cache_key = $this->get_cache_key('installed_extensions'); if ($reset_cache) { FW_Cache::del($cache_key); } try { return FW_Cache::get($cache_key); } catch (FW_Cache_Not_Found_Exception $e) { $extensions = array(); foreach (fw()->extensions->get_locations() as $location) { // leave only used keys $location = array('path' => $location['path'], 'is' => $location['is']); $this->read_extensions($location, $extensions); } FW_Cache::set($cache_key, $extensions); return $extensions; } }
/** * Return config key value, or entire config array * Config array is merged from child configs * @param string|null $key Multi key format accepted: 'a/b/c' * @return mixed|null */ public final function get_config($key = null) { $cache_key = $this->get_cache_key() . '/config'; try { $config = FW_Cache::get($cache_key); } catch (FW_Cache_Not_Found_Exception $e) { list($search_in_framework, $search_in_parent_theme, $search_in_child_theme) = $this->correct_search_in_locations(true, true, true); $rel_path = $this->get_rel_path() . '/config.php'; $config = array(); $paths = array(); if ($search_in_framework) { $paths[] = FW_EXTENSIONS_DIR . $rel_path; } if ($search_in_parent_theme) { $paths[] = FW_PT_EXTENSIONS_DIR . $rel_path; } if ($search_in_child_theme) { $paths[] = FW_CT_EXTENSIONS_DIR . $rel_path; } foreach ($paths as $path) { if (file_exists($path)) { $variables = fw_get_variables_from_file($path, array('cfg' => null)); if (!empty($variables['cfg'])) { $config = array_merge($config, $variables['cfg']); unset($variables); } } } unset($path); FW_Cache::set($cache_key, $config); } return $key === null ? $config : fw_akg($key, $config); }
/** * Get a customizer framework option value from the database * * @param string|null $option_id Specific option id (accepts multikey). null - all options * @param null|mixed $default_value If no option found in the database, this value will be returned * // fixme: Maybe add this parameter? @ param null|bool $get_original_value Original value is that with no translations and other changes * * @return mixed|null */ function fw_get_db_customizer_option($option_id = null, $default_value = null) { // note: this contains only changed controls/options $db_values = get_theme_mod(FW_Option_Type::get_default_name_prefix(), null); if (!is_null($default_value) && is_null($option_id ? fw_akg($option_id, $db_values) : $db_values)) { /** * Default value was provided in case db value is empty. * * Do not extract default values from options files (below) * maybe this function was called from options files and it will cause infinite loop, * that's why the developer provided a default value to prevent that. */ return $default_value; } if (is_null($db_values)) { $db_values = array(); } if (is_null($option_id) || ($base_key = explode('/', $option_id)) && ($base_key = array_shift($base_key)) && !array_key_exists($base_key, $db_values)) { $cache_key = 'fw_default_options_values/customizer'; try { $default_values = FW_Cache::get($cache_key); } catch (FW_Cache_Not_Found_Exception $e) { // extract the default values from options array $default_values = fw_get_options_values_from_input(fw()->theme->get_customizer_options(), array()); FW_Cache::set($cache_key, $default_values); } $db_values = array_merge($default_values, $db_values); } return is_null($option_id) ? $db_values : fw_akg($option_id, $db_values, $default_value); }
public final function get_settings_options() { try { return FW_Cache::get($cache_key = $this->get_cache_key('/settings_options')); } catch (FW_Cache_Not_Found_Exception $e) { if (file_exists($path = $this->get_path('/settings-options.php'))) { $variables = fw_get_variables_from_file($path, array('options' => array())); } else { $variables = array('options' => array()); } FW_Cache::set($cache_key, $variables['options']); return $variables['options']; } }
/** * Render a meta box * * @param string $id * @param string $title * @param string $content HTML * @param array $other Optional elements * * @return string Generated meta box html */ public function render_box($id, $title, $content, $other = array()) { if (!function_exists('add_meta_box')) { trigger_error('Try call this method later (\'admin_init\' action), add_meta_box() function does not exists yet.', E_USER_WARNING); return ''; } $other = array_merge(array('html_before_title' => false, 'html_after_title' => false, 'attr' => array()), $other); $placeholders = array('id' => '{{meta_box_id}}', 'title' => '{{meta_box_title}}', 'content' => '{{meta_box_content}}'); $placeholders['html_before_title'] = '{{meta_box_html_before_title}}'; $placeholders['html_after_title'] = '{{meta_box_html_after_title}}'; $placeholders['attr'] = '{{meta_box_attr}}'; $placeholders['attr_class'] = '{{meta_box_attr_class}}'; $cache_key = 'fw_meta_box_template'; try { $meta_box_template = FW_Cache::get($cache_key); } catch (FW_Cache_Not_Found_Exception $e) { $temp_screen_id = 'fw-temp-meta-box-screen-id-' . fw_unique_increment(); $context = 'normal'; add_meta_box($placeholders['id'], $placeholders['title'], $this->print_meta_box_content_callback, $temp_screen_id, $context, 'default', $placeholders['content']); ob_start(); do_meta_boxes($temp_screen_id, $context, null); $meta_box_template = ob_get_clean(); remove_meta_box($id, $temp_screen_id, $context); $meta_box_template = str_replace('<div id="' . $context . '-sortables" class="meta-box-sortables">', '', $meta_box_template); $meta_box_template = explode('</div>', $meta_box_template); array_pop($meta_box_template); $meta_box_template = implode('</div>', $meta_box_template); // add 'fw-postbox' class and some attr related placeholders $meta_box_template = str_replace('class="postbox', $placeholders['attr'] . ' class="postbox fw-postbox' . $placeholders['attr_class'], $meta_box_template); $meta_box_template = str_replace('<span>' . $placeholders['title'] . '</span>', '<small class="fw-html-before-title">' . $placeholders['html_before_title'] . '</small>' . '<span>' . $placeholders['title'] . '</span>' . '<small class="fw-html-after-title">' . $placeholders['html_after_title'] . '</small>', $meta_box_template); FW_Cache::set($cache_key, $meta_box_template); } $attr_class = ''; if (isset($other['attr']['class'])) { $attr_class = ' ' . $other['attr']['class']; unset($other['attr']['class']); } unset($other['attr']['id']); // replace placeholders with data/content return str_replace(array($placeholders['id'], $placeholders['title'], $placeholders['content'], $placeholders['html_before_title'], $placeholders['html_after_title'], $placeholders['attr'], $placeholders['attr_class']), array(esc_attr($id), $title, $content, $other['html_before_title'], $other['html_after_title'], fw_attr_to_html($other['attr']), esc_attr($attr_class)), $meta_box_template); }
/** * URI to the parent-theme/framework directory * @param string $rel_path * @return string */ function fw_get_framework_directory_uri($rel_path = '') { try { $dir = FW_Cache::get($cache_key = 'fw_framework_dir_uri'); } catch (FW_Cache_Not_Found_Exception $e) { FW_Cache::set($cache_key, $dir = apply_filters('fw_framework_directory_uri', get_template_directory_uri() . '/framework')); } return $dir . $rel_path; }