PHP Class WPLib, wplib

Plugin Name: WPLib Plugin URI: http://wordpress.org/plugins/wplib/ Description: A WordPress Website Foundation Library Agency and Internal Corporate Developers Version: 0.13.2 Author: The WPLib Team Author URI: http://wplib.org Text Domain: wplib License: GPLv2 or later Copyright 2015 NewClarity Consulting LLC This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
See also: https://github.com/wplib/wplib/commit/8dc27c368e84f7ba6e1448753e1b1f082a60ac6d#commitcomment-11027141
Afficher le fichier Open project: wplib/wplib Class Usage Examples

Méthodes publiques

Méthode Description
__callStatic ( string $method, array $args ) : mixed
_after_setup_theme ( ) Now load the theme's modules.
_after_setup_theme_11 ( ) Determine and then load the "mustload" classes They are the classes with an on_load() method.
_autoloader ( string $class_name )
_call_helper ( string $helped_class, string $helper_method, array $args, object $container = null ) : mixed | null Delegate calls to other classes.
_ensure_only_one_class ( $class_container ) Scans to ensure that only one PHP class is declared.
_find_files_autoloader ( $class_name ) Special autoloader to run only for conflicts.
_get_raw_meta_fieldname ( string $meta_name ) : string Returns the raw meta fieldname given a non-prefixed field name.
_init_9 ( ) : array Autoload all WPLib module classes to ensure they are available for 'init' hook.
_plugins_loaded_11 ( ) Load all necessary files. This finds autoloading files and loads modules.
_register_templates ( ) : array Register all templates for WPLib, an App or a module.
_set_mustload_classes ( array $autoload_files ) This will get called 4 times.
_shutdown ( ) Throw error if site failed to load because of a module failing to load.
_xmlrpc_call ( ) Capture status of DOING_XMLRPC
add_class_action ( string $action, integer $priority = 10 )
add_class_filter ( string $filter, integer $priority = 10 )
app_class ( ) : string | null Returns the one app class defined.
app_classes ( ) : array | null
assets_url ( ) : string Return the simple asset path
autoload_all_classes ( ) Force loading of all classes if needed to find all classes with a specific constant.
cache_delete ( string $key, string $group = '' )
cache_exists ( string $key, string $group = '' ) : boolean
cache_get ( string $key, string $group = '' ) : mixed
cache_set ( string $key, mixed $value, string $group = '', integer $expire )
can_call ( string $method_name, string | boolean $class_name = false ) : boolean Determines if a named method exists and is_callable a given class.
class_declares_method ( string $class_name, string $method_name ) : boolean Determines is a class actually declares a method instead of just inheriting it.
component_classes ( string $scope = 'all' ) : array Returns the list of "Component" classes. A Component is one of Lib, Site, App, Theme, Module.
current_helped_class ( ) : array Returns the class that is currently being "helped."
dashify ( string $string, boolean | true $lowercase = true ) : string
do_log_errors ( ) : boolean
do_the_methods ( string | object $view, string | object $model, string $method_name, array $args ) : mixed Do "the_" Methods - Allow classes to delegate the "the_" logic processing here.
doing_ajax ( ) : boolean
doing_autosave ( ) : boolean
doing_cron ( ) : boolean
doing_xmlrpc ( ) : boolean
emit_headers ( string | array $headers ) Emits one or more HTTP headers to the output stream
file_hash ( string $filepath ) : string Returns a file hash, but caches it in persistent cache
get_asset_url ( string $asset_path, boolean | string $class_name = false ) : string Return the asset path
get_callable ( string | object $object, string $method_name ) : callable | null Given an object/class name and method name return a callable or null if can't be called.
get_child_classes ( $base_class, $constant_name ) : string[] Returns array of class names $base_class children with positive values for $base_class::$contant_name.
get_constant ( string $constant_name, string | boolean | object $class_name = false, boolean $try_parent = true ) : mixed | null Return a class constant for the called class.
get_contents ( string $filepath ) : boolean
get_module_class ( string $module_name, string | boolean $app_class = false ) : string
get_module_classes ( string $app_class ) : string[]
get_module_dir ( WPLib_Item_Base | string | boolean $item_class = false ) : string | null
get_module_name ( string $class_name ) : mixed | null
get_real_url ( string $url ) : string Like realpath() but for URLs
get_root_dir ( string $filepath, boolean | string $class_name = false ) : string Return the root directory of the Lib/App/Site/Module/Theme class for a given class name.
get_root_url ( string $filepath, boolean | string $class_name = false ) : string Get the root URL for a given Lib/Site/App/Module/Theme.
get_template ( string $template_slug, array | string $_template_vars = [], WPLib_Item_Base | object $item = null ) : string
get_template_dir ( string $template ) : string Return the template filepath for the passed $template for the called class.
get_theme_file ( string $local_file ) : string Returns the filepath for a theme template file given its "local filename."
has_html_suffix ( string | false $suffix ) : boolean
initialize ( ) If used in a theme you have to first initialize it before WPLib_Theme_Base classes will be available to extend.
invoke_with_args ( callable $invokable, array $args ) : mixed
is_development ( ) : boolean
is_found ( string $filepath ) : boolean
is_production ( ) : boolean
is_script_debug ( ) : string If runmode is development or SCRIPT_DEBUG
is_staging ( ) : boolean
is_testing ( ) : boolean
is_wp_debug ( ) : boolean
make_new_item ( WPLib_Item_Base | WP_Post | WP_Term $item, array $args = [] ) : WPLib_Term_Base | WPLib_Post_Base
maybe_make_absolute_path ( string $filepath, boolean | string $dir = false ) : string Convert relative file paths to absolute file paths.
maybe_make_abspath_relative ( string $filepath ) : string Takes a filepath and potentially returns a relative path (prefixed with '~/'), if $filepath begins with ABSPATH.
module_classes ( ) : string[]
new_post_url ( ) : string
on_load ( )
put_contents ( string $filepath, string $contents ) : boolean Runs file_put_contents()
register_helper ( string $helper_class, string | boolean $helped_class = false ) Register a helper class to the specified class.
register_module ( string $module, integer $priority = 10 )
register_template ( string $template, string | boolean $called_class = false ) Register a template
remove_class_action ( string $action, integer $priority = 10 )
remove_class_filter ( string $filter, integer $priority = 10 )
root_dir ( ) : string Return the root directory of the Lib/App/Site/Module/Theme class.
root_url ( ) : string Return the root URL of the Lib/App/Site/Module/Theme class.
runmode ( ) : WPLib_Runmode
set_runmode ( integer | WPLib_Runmode $runmode )
set_stability ( integer | WPLib_Stability $stability )
set_theme ( WPLib_Theme_Base $theme )
short_prefix ( ) : boolean | string
site_classes ( ) : array Return the list of classes declared after WPLib first loads.
stability ( ) : WPLib_Stability
template_dir ( ) : string Return the templates directory path for the called class.
templates_subdir ( ) : string Return the subdir name for templates.
the_asset_url ( string $asset_path, boolean | string $class_name = false ) : string Echo the asset path
the_template ( string $template_slug, array | string $_template_vars = [], WPLib_Item_Base | object $item = null )
theme ( ) : WPLib_Theme_Base
trigger_error ( string $error_msg, integer $error_type = E_USER_NOTICE, boolean $echo = false ) Triggers error message unless doing AJAX, XMLRPC or Cron; then it logs the error but only if Development mode.
use_template_global_vars ( ) : boolean Return if WPLIB_TEMPLATE_GLOBAL_VARS was set to true

Private Methods

Méthode Description
_current_helped_classes ( ) : array
_filter_group ( $group ) : string
_find_autoload_files ( ) Scan registered autoload files, by priority
_flatten_array_dependency_order ( string $parent_class, string $child_class, array &$mustload_classes, string[] &$ordered_classes ) : array Flatten an array containing parent class names with array.
_load_modules ( ) Load all registered modules, by priority
_load_mustload_classes ( string[] $mustload_classes ) Loads the "mustload" classes on every page load.
_load_necessary_files ( ) Load all necessary files, i.e. modules and finds all autoloading files.
_ordered_mustload_classes ( ) : array Orders the Mustload classes in order of least dependency.

Method Details

__callStatic() static public méthode

static public __callStatic ( string $method, array $args ) : mixed
$method string
$args array
Résultat mixed

_after_setup_theme() static public méthode

Now load the theme's modules.
static public _after_setup_theme ( )

_after_setup_theme_11() static public méthode

Determine and then load the "mustload" classes They are the classes with an on_load() method.
static public _after_setup_theme_11 ( )

_autoloader() static public méthode

static public _autoloader ( string $class_name )
$class_name string

_call_helper() static public méthode

This allows us to document a single "API" for WPLib yet structure the code more conveniently in multiple class files.
static public _call_helper ( string $helped_class, string $helper_method, array $args, object $container = null ) : mixed | null
$helped_class string Name of class that is calling the helper
$helper_method string Name of the helper method
$args array Arguments to pass to the helper method
$container object An object containing a 'callable' property.
Résultat mixed | null

_ensure_only_one_class() static public méthode

This is important because we assume only one class for the autoloader.
static public _ensure_only_one_class ( $class_container )
$class_container

_find_files_autoloader() static public méthode

Special autoloader to run only for conflicts.
static public _find_files_autoloader ( $class_name )
$class_name

_get_raw_meta_fieldname() static public méthode

Adds both a leading underscore and a short prefix to the meta name.
static public _get_raw_meta_fieldname ( string $meta_name ) : string
$meta_name string
Résultat string

_init_9() static public méthode

Autoload all WPLib module classes to ensure they are available for 'init' hook.
static public _init_9 ( ) : array
Résultat array

_plugins_loaded_11() static public méthode

Load all necessary files. This finds autoloading files and loads modules.
static public _plugins_loaded_11 ( )

_register_templates() static public méthode

Register all templates for WPLib, an App or a module.
static public _register_templates ( ) : array
Résultat array

_set_mustload_classes() static public méthode

1 & 2: Finding all autoloading files from components that have been loaded by (1) plugins or (2) the theme. 3 & 4: Finding all autoloading files defined by modules specified by (1) plugins or (2) the theme. Each time it is called it will have values added to self::$_mustload_classes.
static public _set_mustload_classes ( array $autoload_files )
$autoload_files array

_shutdown() static public méthode

Throw error if site failed to load because of a module failing to load.
static public _shutdown ( )

_xmlrpc_call() static public méthode

Capture status of DOING_XMLRPC
static public _xmlrpc_call ( )

add_class_action() static public méthode

static public add_class_action ( string $action, integer $priority = 10 )
$action string
$priority integer

add_class_filter() static public méthode

static public add_class_filter ( string $filter, integer $priority = 10 )
$filter string
$priority integer

app_class() static public méthode

Returns the one app class defined.
static public app_class ( ) : string | null
Résultat string | null

app_classes() static public méthode

static public app_classes ( ) : array | null
Résultat array | null

assets_url() static public méthode

Return the simple asset path
static public assets_url ( ) : string
Résultat string

autoload_all_classes() static public méthode

Force loading of all classes if needed to find all classes with a specific constant.
static public autoload_all_classes ( )

cache_delete() static public méthode

static public cache_delete ( string $key, string $group = '' )
$key string
$group string

cache_exists() static public méthode

static public cache_exists ( string $key, string $group = '' ) : boolean
$key string
$group string
Résultat boolean

cache_get() static public méthode

static public cache_get ( string $key, string $group = '' ) : mixed
$key string
$group string
Résultat mixed

cache_set() static public méthode

static public cache_set ( string $key, mixed $value, string $group = '', integer $expire )
$key string
$value mixed
$group string
$expire integer

can_call() static public méthode

Determines if a named method exists and is_callable a given class.
static public can_call ( string $method_name, string | boolean $class_name = false ) : boolean
$method_name string
$class_name string | boolean
Résultat boolean

class_declares_method() static public méthode

Determines is a class actually declares a method instead of just inheriting it.
static public class_declares_method ( string $class_name, string $method_name ) : boolean
$class_name string
$method_name string
Résultat boolean

component_classes() static public méthode

Returns the 'latest' or 'all' (default). This follows 'principle of least surprise'
static public component_classes ( string $scope = 'all' ) : array
$scope string 'all' or 'latest'
Résultat array

current_helped_class() static public méthode

The Helped class is the one to the left of '::' when the method is actually in a "helper" class: {$current_helped_class}::register_helper( $helper_class ); Which is equivalent to: WPLib::register_helper( $helper_class, $current_helped_class );
static public current_helped_class ( ) : array
Résultat array

dashify() static public méthode

static public dashify ( string $string, boolean | true $lowercase = true ) : string
$string string
$lowercase boolean | true
Résultat string

do_log_errors() static public méthode

static public do_log_errors ( ) : boolean
Résultat boolean

do_the_methods() static public méthode

The "the_" method can call virtual methods and/or delegate to a view or a model. The view and model can both be the same object if needed.
static public do_the_methods ( string | object $view, string | object $model, string $method_name, array $args ) : mixed
$view string | object
$model string | object
$method_name string
$args array
Résultat mixed

doing_ajax() static public méthode

static public doing_ajax ( ) : boolean
Résultat boolean

doing_autosave() static public méthode

static public doing_autosave ( ) : boolean
Résultat boolean

doing_cron() static public méthode

static public doing_cron ( ) : boolean
Résultat boolean

doing_xmlrpc() static public méthode

static public doing_xmlrpc ( ) : boolean
Résultat boolean

emit_headers() static public méthode

Emits one or more HTTP headers to the output stream
static public emit_headers ( string | array $headers )
$headers string | array

file_hash() static public méthode

Returns a file hash, but caches it in persistent cache
static public file_hash ( string $filepath ) : string
$filepath string
Résultat string

get_asset_url() static public méthode

Return the asset path
static public get_asset_url ( string $asset_path, boolean | string $class_name = false ) : string
$asset_path string
$class_name boolean | string Name of class to return the root dir.
Résultat string

get_callable() static public méthode

Given an object/class name and method name return a callable or null if can't be called.
static public get_callable ( string | object $object, string $method_name ) : callable | null
$object string | object
$method_name string
Résultat callable | null

get_child_classes() static public méthode

Returns array of class names $base_class children with positive values for $base_class::$contant_name.
static public get_child_classes ( $base_class, $constant_name ) : string[]
$base_class
$constant_name
Résultat string[]

get_constant() static public méthode

Return a class constant for the called class.
static public get_constant ( string $constant_name, string | boolean | object $class_name = false, boolean $try_parent = true ) : mixed | null
$constant_name string
$class_name string | boolean | object
$try_parent boolean
Résultat mixed | null

get_contents() static public méthode

static public get_contents ( string $filepath ) : boolean
$filepath string
Résultat boolean

get_module_class() static public méthode

static public get_module_class ( string $module_name, string | boolean $app_class = false ) : string
$module_name string
$app_class string | boolean
Résultat string

get_module_classes() static public méthode

static public get_module_classes ( string $app_class ) : string[]
$app_class string
Résultat string[]

get_module_dir() static public méthode

static public get_module_dir ( WPLib_Item_Base | string | boolean $item_class = false ) : string | null
$item_class WPLib_Item_Base | string | boolean
Résultat string | null

get_module_name() static public méthode

static public get_module_name ( string $class_name ) : mixed | null
$class_name string
Résultat mixed | null

get_real_url() static public méthode

Like realpath() but for URLs
static public get_real_url ( string $url ) : string
$url string
Résultat string

get_root_dir() static public méthode

Return the root directory of the Lib/App/Site/Module/Theme class for a given class name.
static public get_root_dir ( string $filepath, boolean | string $class_name = false ) : string
$filepath string Name of path to append to root dir.
$class_name boolean | string Name of class to return the source dir.
Résultat string

get_root_url() static public méthode

Get the root URL for a given Lib/Site/App/Module/Theme.
static public get_root_url ( string $filepath, boolean | string $class_name = false ) : string
$filepath string Name of path to append to root URL.
$class_name boolean | string Name of class to return the root dir.
Résultat string

get_template() static public méthode

See also: self::the_template()
static public get_template ( string $template_slug, array | string $_template_vars = [], WPLib_Item_Base | object $item = null ) : string
$template_slug string
$_template_vars array | string
$item WPLib_Item_Base | object
Résultat string

get_template_dir() static public méthode

Return the template filepath for the passed $template for the called class.
static public get_template_dir ( string $template ) : string
$template string
Résultat string

get_theme_file() static public méthode

Local filename means based at the root of the theme w/o leading slash.
static public get_theme_file ( string $local_file ) : string
$local_file string
Résultat string

has_html_suffix() static public méthode

static public has_html_suffix ( string | false $suffix ) : boolean
$suffix string | false
Résultat boolean

initialize() static public méthode

If used in a theme you have to first initialize it before WPLib_Theme_Base classes will be available to extend.
static public initialize ( )

invoke_with_args() static public méthode

static public invoke_with_args ( callable $invokable, array $args ) : mixed
$invokable callable
$args array
Résultat mixed

is_development() static public méthode

static public is_development ( ) : boolean
Résultat boolean

is_found() static public méthode

static public is_found ( string $filepath ) : boolean
$filepath string
Résultat boolean

is_production() static public méthode

static public is_production ( ) : boolean
Résultat boolean

is_script_debug() static public méthode

If runmode is development or SCRIPT_DEBUG
See also: https://github.com/wplib/wplib/commit/8dc27c368e84f7ba6e1448753e1b1f082a60ac6d#commitcomment-11026829
static public is_script_debug ( ) : string
Résultat string

is_staging() static public méthode

static public is_staging ( ) : boolean
Résultat boolean

is_testing() static public méthode

static public is_testing ( ) : boolean
Résultat boolean

is_wp_debug() static public méthode

static public is_wp_debug ( ) : boolean
Résultat boolean

make_new_item() static public méthode

static public make_new_item ( WPLib_Item_Base | WP_Post | WP_Term $item, array $args = [] ) : WPLib_Term_Base | WPLib_Post_Base
$item WPLib_Item_Base | WP_Post | WP_Term
$args array
Résultat WPLib_Term_Base | WPLib_Post_Base

maybe_make_absolute_path() static public méthode

Recognize a path with a leading slash as an absolute, a no leading slash or starting with '~/' as relative.
static public maybe_make_absolute_path ( string $filepath, boolean | string $dir = false ) : string
$filepath string
$dir boolean | string
Résultat string

maybe_make_abspath_relative() static public méthode

Takes a filepath and potentially returns a relative path (prefixed with '~/'), if $filepath begins with ABSPATH.
static public maybe_make_abspath_relative ( string $filepath ) : string
$filepath string
Résultat string

module_classes() static public méthode

static public module_classes ( ) : string[]
Résultat string[]

new_post_url() static public méthode

static public new_post_url ( ) : string
Résultat string

on_load() static public méthode

static public on_load ( )

put_contents() static public méthode

Runs file_put_contents()
static public put_contents ( string $filepath, string $contents ) : boolean
$filepath string
$contents string
Résultat boolean

register_helper() static public méthode

Register a helper class to the specified class.
static public register_helper ( string $helper_class, string | boolean $helped_class = false )
$helper_class string The name of the helper class.
$helped_class string | boolean Name of the class adding the helper. Defaults to called class.

register_module() static public méthode

static public register_module ( string $module, integer $priority = 10 )
$module string
$priority integer

register_template() static public méthode

Register a template
static public register_template ( string $template, string | boolean $called_class = false )
$template string
$called_class string | boolean

remove_class_action() static public méthode

static public remove_class_action ( string $action, integer $priority = 10 )
$action string
$priority integer

remove_class_filter() static public méthode

static public remove_class_filter ( string $filter, integer $priority = 10 )
$filter string
$priority integer

root_dir() static public méthode

Return the root directory of the Lib/App/Site/Module/Theme class.
static public root_dir ( ) : string
Résultat string

root_url() static public méthode

Return the root URL of the Lib/App/Site/Module/Theme class.
static public root_url ( ) : string
Résultat string

runmode() static public méthode

static public runmode ( ) : WPLib_Runmode
Résultat WPLib_Runmode

set_runmode() static public méthode

static public set_runmode ( integer | WPLib_Runmode $runmode )
$runmode integer | WPLib_Runmode

set_stability() static public méthode

static public set_stability ( integer | WPLib_Stability $stability )
$stability integer | WPLib_Stability

set_theme() static public méthode

static public set_theme ( WPLib_Theme_Base $theme )
$theme WPLib_Theme_Base

short_prefix() static public méthode

static public short_prefix ( ) : boolean | string
Résultat boolean | string

site_classes() static public méthode

Return the list of classes declared after WPLib first loads.
static public site_classes ( ) : array
Résultat array

stability() static public méthode

static public stability ( ) : WPLib_Stability
Résultat WPLib_Stability

template_dir() static public méthode

Return the templates directory path for the called class.
static public template_dir ( ) : string
Résultat string

templates_subdir() static public méthode

Return the subdir name for templates.
static public templates_subdir ( ) : string
Résultat string

the_asset_url() static public méthode

Echo the asset path
static public the_asset_url ( string $asset_path, boolean | string $class_name = false ) : string
$asset_path string
$class_name boolean | string Name of class to return the root dir.
Résultat string

the_template() static public méthode

See also: http://stackoverflow.com/a/7983863/102699
static public the_template ( string $template_slug, array | string $_template_vars = [], WPLib_Item_Base | object $item = null )
$template_slug string
$_template_vars array | string
$item WPLib_Item_Base | object

theme() static public méthode

static public theme ( ) : WPLib_Theme_Base
Résultat WPLib_Theme_Base

trigger_error() static public méthode

Triggers error message unless doing AJAX, XMLRPC or Cron; then it logs the error but only if Development mode.
static public trigger_error ( string $error_msg, integer $error_type = E_USER_NOTICE, boolean $echo = false )
$error_msg string
$error_type integer
$echo boolean If true use 'echo', if false use trigger_error().

use_template_global_vars() static public méthode

Setting WPLIB_TEMPLATE_GLOBAL_VARS to false will cause WPLib to extract $GLOBALS before loading the WP template which normally happens in wp-include/template-loader.php but WPLib hijacks that.
static public use_template_global_vars ( ) : boolean
Résultat boolean