Hooks::get_option ( $meta_key, $default = false )
Read an option from options_meta.
Return value or $default if not found
Source file: app/src/Hooks.php
Used by
- app/src/Hooks.php: Hooks::update_option()
- app/src/Hooks.php: Hooks::add_option()
Uses
- app/src/Hooks.php: Hooks::maybe_unserialize()
- app/src/Hooks.php: Hooks::apply_filter()
- app/functions/global-function.php: _etsis_flash()
- app/functions/cache-function.php: etsis_cache_get()
- app/functions/cache-function.php: etsis_cache_add()
Source
public function get_option($meta_key, $default = false) { $meta_key = trim($meta_key); if (empty($meta_key)) { return false; } /** * Filter the value of an existing option before it is retrieved. * * The dynamic portion of the hook name, `$meta_key`, refers to the meta_key name. * * Passing a truthy value to the filter will short-circuit retrieving * the option value, returning the passed value instead. * * @since 1.0.0 * * @param bool|mixed $pre_option * Value to return instead of the option value. * Default false to skip it. * @param string $meta_key * Meta key name. */ $pre = $this->apply_filter('pre_option_' . $meta_key, false); if (false !== $pre) { return $pre; } if (!isset($this->app->db->option[$meta_key])) { try { $meta = $this->app->db->options_meta(); $q = $meta->select('meta_value')->where('meta_key = ?', $meta_key); $results = etsis_cache_get($meta_key, 'option'); if (empty($results)) { $results = $q->find(function ($data) { foreach ($data as $d) { return $d['meta_value']; } }); etsis_cache_add($meta_key, $results, 'option'); } if (is_object($q)) { $value = $results; return $value; } else { // option does not exist, so we must cache its non-existence $value = $default; return $value; } $this->app->db->option[$meta_key] = $this->maybe_unserialize($value); } catch (NotFoundException $e) { Cascade::getLogger('error')->error(sprintf('SQLSTATE[%s]: Error: %s', $e->getCode(), $e->getMessage())); _etsis_flash()->error(_etsis_flash()->notice(409)); } catch (Exception $e) { Cascade::getLogger('error')->error(sprintf('SQLSTATE[%s]: Error: %s', $e->getCode(), $e->getMessage())); _etsis_flash()->error(_etsis_flash()->notice(409)); } catch (ORMException $e) { Cascade::getLogger('error')->error(sprintf('SQLSTATE[%s]: Error: %s', $e->getCode(), $e->getMessage())); _etsis_flash()->error(_etsis_flash()->notice(409)); } } /** * Filter the value of an existing option. * * The dynamic portion of the hook name, `$meta_key`, refers to the option name. * * @since 1.0.0 As 'get_option_' . $setting * * @param mixed $value * Value of the option. If stored serialized, it will be * unserialized prior to being returned. * @param string $this->app->db->option[$meta_key] * Option name. */ return $this->apply_filter('get_option_' . $meta_key, $this->app->db->option[$meta_key]); }
Expand full source code Collapse full source code View on Github