Managing themes andserver environmentswith extensibleconfiguration arraysChris Olbekson@chris_olbekson @X_Team
Managing EnvironmentsMaking your code aware
wp-config.php
The Environment Config Classclass WPized_Env_Config {1. Get defined environment from active-env and assign to $active_env2...
The Environment Config Classclass WPized_Env_Config {1. Get defined environment from active-env and assign to $active_env2...
The Environment Config Classclass WPized_Env_Config {1. Get defined environment from active-env and assign to $active_env2...
The Environment Config Classstatic function merge_arrays( array $array ) {return call_user_func_array(array( WPized_Theme_...
Component LibrariesKeeping a common codebase
Components generic enough to be used in any WordPressproject.● Redirection● oEmbeds● Post/Taxonomy OrderingComponents used...
ComponentsLets make em configurable!
1. Default configs can be defined in the components setup() method.2. Since theme configs can override these defaults we c...
Load a component in functions.phpPath shortcut to the library well be using for this example.define( WPIZED_BASE_LIB, WP_C...
Load a component in functions.phpThe component will load when the theme is initialized.define( WPIZED_BASE_LIB, WP_CONTENT...
Load a component in functions.phpAllows us to use some methods for fetching and merging configs.define( WPIZED_BASE_LIB, W...
Load a component in functions.phpIf theres no config key provided for the component, it never runs.define( WPIZED_BASE_LIB...
Themes config.phpWe have a key! So this component will be loaded.return array(brightcove_oembed => array(players => array(...
The simple conceptWe can setup the component differently on a site-by-site basis!Theme Configssetup( )in componentsclassPa...
Load a component in functions.phpThe config gets passed to components setup() method.define( WPIZED_BASE_LIB, WP_CONTENT_D...
class WPized_Custom_Logo {public static $options = array();public static function setup( $overrides = array() ) {self::$op...
class WPized_Custom_Logo {public static $options = array();public static function setup( $really_default_defaults = array(...
class WPized_Custom_Logo {public static $options = array();public static function setup( $really_default_defaults = array(...
class WPized_Custom_Logo {public static $options = array();public static function setup( $really_default_defaults = array(...
class WPized_Custom_Logo {public static $options = array();public static function setup( $really_default_defaults = array(...
class WPized_Custom_Logo {public static $options = array();public static function setup( $really_default_defaults = array(...
Thank you!
Upcoming SlideShare
Loading in …5
×

Managing themes and server environments with extensible configuration arrays

506 views
431 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
506
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Managing themes and server environments with extensible configuration arrays

  1. 1. Managing themes andserver environmentswith extensibleconfiguration arraysChris Olbekson@chris_olbekson @X_Team
  2. 2. Managing EnvironmentsMaking your code aware
  3. 3. wp-config.php
  4. 4. The Environment Config Classclass WPized_Env_Config {1. Get defined environment from active-env and assign to $active_env2. Load default.env
  5. 5. The Environment Config Classclass WPized_Env_Config {1. Get defined environment from active-env and assign to $active_env2. Load default.env3. Load defined environment (each environment checks for an override)a. local.env.phpb. vagrant.env.phpc. staging.env.phpd. production.env.php
  6. 6. The Environment Config Classclass WPized_Env_Config {1. Get defined environment from active-env and assign to $active_env2. Load default.env3. Load defined environment (each environment checks for an override)a. local.env.phpb. vagrant.env.phpc. staging.env.phpd. production.env.php4. Recursively merge the loaded environment configuration array with thedefault
  7. 7. The Environment Config Classstatic function merge_arrays( array $array ) {return call_user_func_array(array( WPized_Theme_Config,recursive_array_merge_assoc),func_get_args());}continue loading WordPress./** Sets up WordPress vars and included files */require_once(ABSPATH, wp-settings.php);
  8. 8. Component LibrariesKeeping a common codebase
  9. 9. Components generic enough to be used in any WordPressproject.● Redirection● oEmbeds● Post/Taxonomy OrderingComponents used specifically in WordPress projects forspecific client.● Ad Utility● Event Post Type● Social Panel WidgetComponents are housed in multiplelibrariesWPizedBaseClientNameCommon
  10. 10. ComponentsLets make em configurable!
  11. 11. 1. Default configs can be defined in the components setup() method.2. Since theme configs can override these defaults we can use the samecomponent code for any project!3. "Mixin" themes are now possible (like child theme groups) which can bevery useful on large multisite installs.4. Child themes are the final authority.The merge order of configs#4Child Themeconfig.php#3Mixin Themeconfig.php#2Parent Themeconfig.php#1Component(defaults)foo.php
  12. 12. Load a component in functions.phpPath shortcut to the library well be using for this example.define( WPIZED_BASE_LIB, WP_CONTENT_DIR . /includes/wpized_base );function foo_load_config {require_once( WPIZED_BASE_LIB . /theme_config.php );// Custom logoif ( WPized_Theme_Config::defined( custom_logo ) ) {require_once( WPIZED_BASE_LIB . /custom-logo.php );WPized_Custom_Logo::setup( WPized_Theme_Config::get( custom_logo ) );}}add_action( after_setup_theme, foo_load_config );
  13. 13. Load a component in functions.phpThe component will load when the theme is initialized.define( WPIZED_BASE_LIB, WP_CONTENT_DIR . /includes/wpized_base );function foo_load_config {require_once( WPIZED_BASE_LIB . /theme_config.php );// Custom logoif ( WPized_Theme_Config::defined( custom_logo ) ) {require_once( WPIZED_BASE_LIB . /custom-logo.php );WPized_Custom_Logo::setup( WPized_Theme_Config::get( custom_logo ) );}}add_action( after_setup_theme, foo_load_config );
  14. 14. Load a component in functions.phpAllows us to use some methods for fetching and merging configs.define( WPIZED_BASE_LIB, WP_CONTENT_DIR . /includes/wpized_base );function foo_load_config {require_once( WPIZED_BASE_LIB . /theme_config.php );// Custom logoif ( WPized_Theme_Config::defined( custom_logo ) ) {require_once( WPIZED_BASE_LIB . /custom-logo.php );WPized_Custom_Logo::setup( WPized_Theme_Config::get( custom_logo ) );}}add_action( after_setup_theme, foo_load_config );
  15. 15. Load a component in functions.phpIf theres no config key provided for the component, it never runs.define( WPIZED_BASE_LIB, WP_CONTENT_DIR . /includes/wpized_base );function foo_load_config {require_once( WPIZED_BASE_LIB . /theme_config.php );// Custom logoif ( WPized_Theme_Config::defined( custom_logo ) ) {require_once( WPIZED_BASE_LIB . /custom-logo.php );WPized_Custom_Logo::setup( WPized_Theme_Config::get( custom_logo ) );}}add_action( after_setup_theme, foo_load_config );
  16. 16. Themes config.phpWe have a key! So this component will be loaded.return array(brightcove_oembed => array(players => array( ... ),),custom_logo => array(default => get_stylesheet_directory_uri() . /images/common/logo.png,width => 300,height => 100,),ads => array(site => example.com/foo,),);
  17. 17. The simple conceptWe can setup the component differently on a site-by-site basis!Theme Configssetup( )in componentsclassParent > Mixin > ChildDefault config values
  18. 18. Load a component in functions.phpThe config gets passed to components setup() method.define( WPIZED_BASE_LIB, WP_CONTENT_DIR . /includes/wpized_base );function foo_load_config {require_once( WPIZED_BASE_LIB . /theme_config.php );// Custom logoif ( WPized_Theme_Config::defined( custom_logo ) ) {require_once( WPIZED_BASE_LIB . /custom-logo.php );WPized_Custom_Logo::setup( WPized_Theme_Config::get( custom_logo ) );}}add_action( after_setup_theme, foo_load_config );
  19. 19. class WPized_Custom_Logo {public static $options = array();public static function setup( $overrides = array() ) {self::$options = WPized_Theme_Config::recursive_array_merge_assoc(array(default => null,width => 250,height => 100,),$overrides);}}echo esc_html( WPized_Custom_Logo::$options[width] ); // 300Custom logo component
  20. 20. class WPized_Custom_Logo {public static $options = array();public static function setup( $really_default_defaults = array()) {self::$options = WPized_Theme_Config::recursive_array_merge_assoc(array(default => null,width => 250,height => 100,),$really_default_defaults);}}echo esc_html( WPized_Custom_Logo::$options[width] ); // 300Custom logo component
  21. 21. class WPized_Custom_Logo {public static $options = array();public static function setup( $really_default_defaults = array() ) {self::$options = WPized_Theme_Config::recursive_array_merge_assoc(array(default => null,width => 250,height => 100,),$really_default_defaults);}}echo esc_html( WPized_Custom_Logo::$options[width] ); // 300Custom logo component
  22. 22. class WPized_Custom_Logo {public static $options = array();public static function setup( $really_default_defaults = array() ) {self::$options = WPized_Theme_Config::recursive_array_merge_assoc(array(default => null,width => 250,height => 100,),$really_default_defaults);}}echo esc_html( WPized_Custom_Logo::$options[width] ); // 300Custom logo component
  23. 23. class WPized_Custom_Logo {public static $options = array();public static function setup( $really_default_defaults = array() ) {self::$options = WPized_Theme_Config::recursive_array_merge_assoc(array(default => null,width => 250,height => 100,),$really_default_defaults);}}echo esc_html( WPized_Custom_Logo::$options[width] ); // 300Custom logo component
  24. 24. class WPized_Custom_Logo {public static $options = array();public static function setup( $really_default_defaults = array() ) {self::$options = WPized_Theme_Config::recursive_array_merge_assoc(array(default => null,width => 250,height => 100,),$really_default_defaults);}}echo esc_html( WPized_Custom_Logo::$options[width] ); // 300Custom logo component
  25. 25. Thank you!

×