WordPress.org

Forums

Great work (5 posts)

  1. Covi
    Member
    Posted 5 years ago #

    First of all, your code rocks; nice work ;)
    I found this theme while developing a standard interface for themes. I started with something like this:

    <?php
    /**
     * Interface WP_Theme.
     *
     * We can be add two extras methods: get and set generic for class, or for each groups of methods:
     * getStyles(), setStyles(), getFilters(), addFilters() etc.
     */
    interface WP_Theme
    {
    	# Attrs:
    	private $_themeData;
    	private $_styles;
    	private $_scripts;
    	private $_actions;
    	private $_filters;
    	private $_sidebars;
    	private $_widgets;
    	// ¿? private $_plugins;
    	private $_registry; // (Optional). Example: Zend Registry instead CONSTANTS.
    
    	// Global
    	public function getThemeData();
    	public function setThemeData($file);
    
    	// Registry, note this: custom Zend_Registry
    	public function getRegistry();
    	public function setRegistry(Zend_Registry $registry);	// Force type
    
    	// Styles
    	public function addThemeStyle(); 		// Force WP_Styles?
    	public function removeThemeStyle();
    
    	// Scripts
    	public function addThemeScript();		// Force WP_Scripts?
    	public function removeThemeScript();
    
    	// Actions
    	public function addThemeAction();
    	public function removeThemeAction();
    
    	// Filters
    	public function addThemeFilter();
    	public function removeThemeFilter();
    
    	// Sidebars
    	public function addThemeSidebars(array $sidebars);
    	public function removeThemeSidebars(array $sidebars);
    
    	// Widgets
    	public function addThemeWidget(WP_Widget $widgets);
    	public function removeThemeWidget(WP_Widget $widgets);
    
    	// Prepare: Setup or init methods.
    	public function prepareTheme();
    
    	// Runs...
    	public function runBackend();
    	public function runFrontend();
    }

    Time for proposals -ideas- for WordPress standar WP_Theme interface?

  2. Covi
    Member
    Posted 5 years ago #

    Extended with namespaces:

    <?php
    class WP_Theme_MyTheme implements WP_Theme
    {
    }

    Structure:
    WP/
    -- Theme.php (class WP_Theme)
    -- Theme/
    --- MyTheme.php (class WP_Theme_MyTheme)
    --- optional subdirs for theme: WP_Theme_MyTheme_Filter /Filter/
    --- Filter/
    ---- Filter.php (interface WP_Theme_Filter)
    ...

    ^^!

  3. Ptah Dunbar
    Member
    Posted 5 years ago #

    Wow, that looks pretty cool. Have you built a theme based on this?

  4. Covi
    Member
    Posted 4 years ago #

    Oops... sorry for... about 1 year delay :(

    ...and the reply is "yes", I'm using this system on all of my themes. For example at: http://laguardiadejaen.com.

    But, ATM, is not a public work. I'm working on it to publish at Google Code, Gitub... ;)

    ---
    This example implements the new theme with NameSpaces and Controllers instead files (home.php, archive.php...):

    -- MyTheme/
    ------ Controller/
    -------- Front.php -- FronController: methods for all controllers
    You can add hooks from extensions to all controllers, example:
    public static function getPostImage($postID = null) {
    	if ( method_exists('WP_Theme_MyTheme_Extension_Images', 'getPostImage') )
    		return WP_Theme_MyTheme_Extension_Images::getPostImage($postID);
    	else return '';
    }
    Controllers extends Front controller:
    -------- Index.php -- your index.php file
    Example methods from FrontController:
    self::getPostImage();
    -------- Home.php  -- ...
    -------- Archive.php
    ------ Extension/
    -------- Images.php -- Example to call a method from controller:
    WP_Theme_MyTheme_Extension_Images::getPostImage();
    ------ Widget/
    ------ Helper/
    ------ MyTheme.php

    ---
    functions.php load and init the theme class, example using Zend_Autoloader:

    [...]
    $configFile 	= APPLICATION_PATH . DS . 'app.xml';
    $Theme 		= new WP_Theme_MyTheme($configFile, $autoloader);

    The class is your functions.php POO, this init your supports, extensiones, widgets...
    ---

    Now, you only need a simple index file to call the Controller of your app, its a bridge between WP and your app system:

    // AutoControllers:
    if ( is_home() )
    	$ControllerName = 'Home';
    elseif ( is_archive() || is_search() )
    	$ControllerName = 'Archive';
    elseif ( is_attachment() )
    	$ControllerName = 'Attachment';
    else
    	$ControllerName = 'Index';
    
    // ### Run...
    $ClassName = "WP_Theme_MyTheme_Controller_{$ControllerName}";
    call_user_func_array(array($ClassName, 'renderView'), array($wp_query));
  5. Covi
    Member
    Posted 4 years ago #

    [...]
    Simple way index.php:
    call_user_func_array(array(WP_Theme_MyTheme_Controller_Index, 'renderView'), array($wp_query));

    *wp_query is optional.

Topic Closed

This topic has been closed to new replies.

About this Topic