Source for file elastic.php
Documentation is available at elastic.php
* Elastic API: Access to atomic hook functions, context, paths, and Elastic data (prefixes, theme data).
* @author Daryl Koopersmith
* Handles internal framework operation. Do not access directly. Instead, use {@link elastic_get()} and {@link elastic_set()}.
* @author Daryl Koopersmith
* An array containing the context of a page.
* Contains the prefix used for most Elastic hooks and ids. Default 'elastic_'.
* Can be overridden through filter 'elastic_prefix'.
* Warning: Override with care! The names other filters will change when Elastic::$prefix is overridden.
* Contains the prefix used for all Modules. Default 'module_'.
* Can be overridden through filter 'elastic_module_prefix'.
* An array of theme data obtained through {@link get_theme_data()}.
* Filtered hook: 'elastic_theme_data'.
* An array of child theme data obtained through {@link get_theme_data()}.
* Filtered hook: 'elastic_child_data'.
* Are we running a child theme?
* An array of module names.
* @todo Double check if Elastic::module_types is used anywhere.
* Contains an array of relative paths. Access paths through {@link elastic_get_path()}.
* Initializes and sets hooks for the Elastic framework
* @author Daryl Koopersmith
$this->has_child = ( STYLESHEETPATH !== TEMPLATEPATH );
$this->path['root'] = '';
$this->path['library'] = 'library';
$this->path['classes'] = trailingslashit( $this->path['library'] ) . 'classes';
$this->path['lib-css'] = trailingslashit( $this->path['library'] ) . 'css';
$this->path['fallback-views'] = trailingslashit( $this->path['library'] ) . 'fallback-views';
$this->path['custom'] = 'custom';
// Load user's functions.php
$functions = TEMPLATEPATH . '/custom/functions.php';
// Load child's functions.php
$functions = STYLESHEETPATH . '/custom/functions.php';
// Set prefix for all hooks and ids.
$this->prefix = apply_filters('elastic_prefix','elastic_');
// Get theme and child theme data
$this->theme_data = apply_filters($this->prefix . 'theme_data', get_theme_data(TEMPLATEPATH . '/style.css') );
$this->child_data = apply_filters($this->prefix . 'child_data', get_theme_data(STYLESHEETPATH . '/style.css') );
add_action('template_redirect', array(&$this, 'load_styles') );
// Get context (once it's set)
add_action('template_redirect', array(&$this, 'get_context') );
// Get context now, for admin pages
$this->context = $this->get_context();
if( is_admin() ) // Sidebars must be registered during admin_init, which is before template_redirect
add_action('init', array(&$this, 'register_sidebars') );
else // Sidebars are registered on template_redirect to ensure context has loaded
add_action('template_redirect', array(&$this, 'register_sidebars') );
* Loads user stylesheets (both parent and child theme) and base CSS reset.
* CSS reset is a customized version of Tripoli.
* @author Daryl Koopersmith
wp_enqueue_style( $this->prefix . 'tripoli', elastic_get_path('lib-css', 'uri') . '/tripoli.css', false, '0.0.2.7');
wp_enqueue_style( $this->prefix . 'tripoli-ie', elastic_get_path('lib-css', 'uri') . '/tripoli.ie.css', false, '0.0.2.7');
$wp_styles->add_data( $this->prefix . 'tripoli-ie', 'conditional', 'gte IE 5');
wp_enqueue_style( $this->prefix . 'style', elastic_get_path('custom', 'uri') . '/style.css', false, '0.0.2.7');
wp_enqueue_style( $this->prefix . 'style', elastic_get_path('custom', 'child', 'uri') . '/style.css', false, '0.0.2.7');
* Registers all sidebar modules.
* @author Daryl Koopersmith
function register_sidebars() {
$sidebars = $sidebars->get_modules_by_type('sidebar');
foreach( $sidebars as $sidebar ) {
$settings = $sidebar->apply_atomic( '_register_sidebars', array(
'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
'after_widget' => "</li>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
register_sidebar( $settings );
* Retrieve the context of the current page.
* @todo Potentially make this function public, and take in an optional $wp_query variable?
* @author Chris Jean, Ptah Dunbar, Daryl Koopersmith
$context = array( 'global' => '', 'abstract' => null, 'general' => null, 'specific' => null );
$context['global'] = 'admin';
$id = $wp_query->get_queried_object_id();
$context['general'] = 'home';
else if ( is_singular() ) {
$context['abstract'] = 'singular';
$context['general'] = 'attachment';
$context['specific'] = 'attachment-'. $id;
else if ( is_single() ) {
$context['general'] = 'single';
$context['specific'] = 'single-'. $id;
$context['general'] = 'page';
$context['specific'] = 'page-'. $id;
else if ( is_archive() ) {
$context['abstract'] = 'archive';
$context['general'] = 'category';
$context['specific'] = 'category-'. $id;
$context['general'] = 'tag';
$context['specific'] = 'tag-'. $id;
$context['general'] = 'date';
$context['specific'] = 'month-'. $id;
$context['specific'] = 'year-'. $id;
$context['specific'] = 'day-'. $id;
$context['specific'] = 'time-' . $id;
else if ( is_author() ) {
$context['general'] = 'author';
$context['specific'] = 'author-'. $id;
$context['general'] = 'tax';
$context['specific'] = 'tax-'. $id;
$context['general'] = 'search';
$context['general'] = 'error404';
* Gets data within the global {@link Elastic} instance ($elastic).
* @global Elastic $elastic
* @return mixed Requested variable ($elastic->var), or false.
* @author Daryl Koopersmith
if( isset ($elastic->$var) ) {
* Sets data within the global {@link Elastic} instance ($elastic).
* @param string $var Variable name to set.
* @param string $value Value to be set.
* @global Elastic $elastic
* @author Daryl Koopersmith
* Returns a path within the Elastic framework.
* Arguments specify absolute or URI, and theme or child theme.
* Takes a path $name, then up to two optional arguments: ['abs' or 'uri'] and ['theme' or 'child'].
* Defaults to 'abs' and 'theme'.
* @param string $name The name of the path requested. A common value is 'custom'.
* @param string $arg1 Optional. Takes ['abs' or 'uri'] or ['theme' or 'child']
* @param string $arg2 Optional. Takes ['abs' or 'uri'] or ['theme' or 'child']
* @return string Requested path, or false.
* @author Daryl Koopersmith
if( ! isset ($path[ $name ]) )
$uri = ( 'uri' === $arg1 || 'uri' === $arg2 );
$child = ( 'child' === $arg1 || 'child' === $arg2 );
return trailingslashit( ($child) ? get_stylesheet_directory_uri() : get_template_directory_uri() ) . $path[ $name ];
return trailingslashit( ($child) ? STYLESHEETPATH : TEMPLATEPATH ) . $path[ $name ];
* Calls {@link do_action()} at all context levels.
* Actions are run in the order: global, abstract, general, specific.
* Actions are not run for null contexts.
* @param string $id The id of the hook.
* @todo Document how the hooks API can handle any number of variables.
* @author Daryl Koopersmith
* Calls {@link do_action()} at the most specific atomic level with a registered action.
* For example, if actions were registered at the 'global' and 'general' levels,
* only the 'general' action would be called.
* @param string $id The id of the hook.
* @param string $prefix Optional. Defaults to {@link Elastic::$prefix}.
* @author Daryl Koopersmith
if( has_action($hook) ) {
do_action_ref_array( $hook, $args );
* Calls {@link apply_filters()} at all context levels.
* Filters are applied in the order: global, abstract, general, specific.
* Filters are not applied to null contexts.
* $value is updated every time {@link apply_filters()} is run.
* (i.e. {@link apply_filters()} at the 'specific' level receives any changes made at the 'global' level).
* @param string $id The id of the hook.
* @param mixed $value The value to be filtered.
* @param string $prefix Optional. Defaults to {@link Elastic::$prefix}.
* @author Daryl Koopersmith
$value = apply_filters( $output_args[0], $output_args[1] );
* Calls {@link apply_filters()} at the most specific atomic level with a registered action.
* For example, if filters were registered at the 'global' and 'general' levels,
* only the 'general' filter would be called.
* @param string $id The id of the hook.
* @param mixed $value The value to be filtered.
* @param string $prefix Optional. Defaults to {@link Elastic::$prefix}.
* @author Daryl Koopersmith
if( has_filter($hook) ) {
$output_args = array( $hook, $value );
return apply_filters( $output_args[0], $output_args[1] );
* Returns a formatted hook title.
* @param string $prefix Optional. Defaults to {@link Elastic::$prefix}.
* @return string Formatted hook title
* @author Daryl Koopersmith
// If $view is empty (i.e. context['global']), don't add an extra underscore
return $prefix . (( ! empty($view) ) ? $view . "_" : '' ) . $id;
* Returns a formatted hook title with the module prefix.
* @return string Formatted hook title
* @author Daryl Koopersmith
|