/** * */ static function _wp_loaded() { if (!WPLib::cache_get($cache_key = 'roles_initialized')) { self::_initialize_roles(); WPLib::cache_set($cache_key, true); } }
/** * Return number of is use categories on posts. * * @note Ignores 'Uncategorized' * * @param array $args * * @return int|mixed */ function category_count($args = array()) { $category_count = WPLib::cache_get($cache_key = 'category_count'); if (false === $category_count) { $args = wp_parse_args($args, array('fields' => 'ids', 'hide_empty' => 1)); $categories = get_categories($args); WPLib::cache_set($cache_key, $category_count = count($categories), null, 15 * 60); } return intval($category_count) - 1; }
/** * @return array|mixed */ static function role_classes() { if (!($role_classes = WPLib::cache_get($cache_key = 'role_classes'))) { WPLib::autoload_all_classes(); $role_classes = array(); foreach (get_declared_classes() as $user_class) { if (!is_subclass_of($user_class, 'WPLib_User_Base')) { continue; } if ($role_slug = self::get_role_slug_by('class', $user_class)) { $role_classes[$role_slug] = $user_class; } } WPLib::cache_set($cache_key, $role_classes); } return $role_classes; }
/** * @param string $template * @param array $args * @return string */ function get_template_html($template, $args = array()) { $cache_key = "wplib_template[{$template}][" . md5(serialize($args)) . ']'; if (!($output = WPLib::cache_get($cache_key))) { ob_start(); $index = 0; foreach ($this->elements() as $element) { /** * @var WPLib_Item_Base $element * * @todo Create a interface that would indicate a class has a 'the_template' method. * */ $args['index'] = $index++; $element->the_template($template, $args); } WPLib::cache_set($cache_key, $output = ob_get_clean()); } return $output; }
/** * Returns array of class names $base_class children with positive values for $base_class::$contant_name. * * @param $type * @param $constant_name * @param $base_class * * @return string[] */ static function _get_child_classes($type, $constant_name, $base_class) { if (!($child_classes = WPLib::cache_get($cache_key = "{$type}_classes"))) { $child_classes = array(); foreach (self::site_classes() as $class_name) { do { if (!is_subclass_of($class_name, $base_class)) { continue; } if (!is_null($constant_value = WPLib::get_constant($constant_name, $class_name))) { continue; } $child_classes[$constant_value] = $class_name; } while (false); } WPLib::cache_set($cache_key, $child_classes); } return $child_classes; }