Skip to content

Commit

Permalink
Merge pull request #729 from ahmadawais/patch-1
Browse files Browse the repository at this point in the history
Better Documentation
  • Loading branch information
jarednova committed Oct 29, 2015
2 parents eaa7aef + bcda4ec commit 4e5701b
Showing 1 changed file with 75 additions and 12 deletions.
87 changes: 75 additions & 12 deletions timber.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
/*
Plugin Name: Timber
Description: The WordPress Timber Library allows you to write themes using the power Twig templates.
Plugin URI: http://timber.upstatement.com
Description: The WordPress Timber Library allows you to write themes using the power Twig templates
Author: Jared Novack + Upstatement
Version: 0.22.0
Author URI: http://upstatement.com/
Expand All @@ -11,9 +11,9 @@
global $wp_version;
global $timber;

// we look for Composer files first in the plugins dir
// then in the wp-content dir (site install)
// and finally in the current themes directories
// we look for Composer files first in the plugins dir.
// then in the wp-content dir (site install).
// and finally in the current themes directories.
if ( file_exists( $composer_autoload = __DIR__ . '/vendor/autoload.php' ) /* check in self */
|| file_exists( $composer_autoload = WP_CONTENT_DIR.'/vendor/autoload.php') /* check in wp-content */
|| file_exists( $composer_autoload = plugin_dir_path( __FILE__ ).'vendor/autoload.php') /* check in plugin directory */
Expand All @@ -26,18 +26,21 @@
$timber = new Timber();
Timber::$dirname = 'views';

/** Usage:
/**
* Timber Class.
*
* Main class called Timber for this plugin.
*
* Usage:
* $posts = Timber::get_posts();
* $posts = Timber::get_posts('post_type = article')
* $posts = Timber::get_posts(array('post_type' => 'article', 'category_name' => 'sports')); // uses wp_query format
* $posts = Timber::get_posts(array('post_type' => 'article', 'category_name' => 'sports')); // uses wp_query format.
* $posts = Timber::get_posts(array(23,24,35,67), 'InkwellArticle');
*
* $context = Timber::get_context(); // returns wp favorites!
* $context['posts'] = $posts;
* Timber::render('index.twig', $context);
*/

class Timber {

public static $locations;
Expand Down Expand Up @@ -80,10 +83,12 @@ protected function init() {
TimberIntegrations::init();
}

/* Post Retrieval
/* Post Retrieval Routine
================================ */

/**
* Get post.
*
* @param mixed $query
* @param string $PostClass
* @return array|bool|null
Expand All @@ -93,6 +98,8 @@ public static function get_post( $query = false, $PostClass = 'TimberPost' ) {
}

/**
* Get posts.
*
* @param mixed $query
* @param string $PostClass
* @return array|bool|null
Expand All @@ -102,6 +109,8 @@ public static function get_posts( $query = false, $PostClass = 'TimberPost', $re
}

/**
* Query post.
*
* @param mixed $query
* @param string $PostClass
* @return array|bool|null
Expand All @@ -111,6 +120,8 @@ public static function query_post( $query = false, $PostClass = 'TimberPost' ) {
}

/**
* Query posts.
*
* @param mixed $query
* @param string $PostClass
* @return array|bool|null
Expand All @@ -120,6 +131,8 @@ public static function query_posts( $query = false, $PostClass = 'TimberPost' )
}

/**
* Get pids.
*
* @param array|string $query
* @return array
* @deprecated since 0.20.0
Expand All @@ -129,6 +142,8 @@ static function get_pids( $query = null ) {
}

/**
* Get posts from loop.
*
* @param string $PostClass
* @return array
* @deprecated since 0.20.0
Expand All @@ -138,6 +153,8 @@ static function get_posts_from_loop( $PostClass ) {
}

/**
* Get posts from slug.
*
* @param string $slug
* @param string $PostClass
* @return array
Expand All @@ -148,6 +165,8 @@ static function get_posts_from_slug( $slug, $PostClass = 'TimberPost' ) {
}

/**
* Get posts from WP_Query.
*
* @param array $query
* @param string $PostClass
* @return array
Expand All @@ -158,6 +177,8 @@ static function get_posts_from_wp_query( $query = array(), $PostClass = 'TimberP
}

/**
* Get posts from array of ids.
*
* @param array $query
* @param string $PostClass
* @return array|null
Expand All @@ -168,6 +189,8 @@ static function get_posts_from_array_of_ids( $query = array(), $PostClass = 'Tim
}

/**
* Get pid.
*
* @param unknown $query
* @return int
* @deprecated since 0.20.0
Expand All @@ -180,6 +203,8 @@ static function get_pid( $query ) {
}

/**
* WP_Query has posts.
*
* @return bool
* @deprecated since 0.20.0
*/
Expand All @@ -191,6 +216,8 @@ static function wp_query_has_posts() {
================================ */

/**
* Get terms.
*
* @param string|array $args
* @param array $maybe_args
* @param string $TermClass
Expand All @@ -204,6 +231,8 @@ public static function get_terms( $args = null, $maybe_args = array(), $TermClas
================================ */

/**
* Get sites.
*
* @param array|bool $blog_ids
* @return array
*/
Expand All @@ -224,6 +253,8 @@ public static function get_sites( $blog_ids = false ) {
================================ */

/**
* Get context.
*
* @return array
*/
public static function get_context() {
Expand Down Expand Up @@ -257,6 +288,8 @@ public static function get_context() {
}

/**
* Compile function.
*
* @param array $filenames
* @param array $data
* @param bool $expires
Expand Down Expand Up @@ -289,8 +322,10 @@ public static function compile( $filenames, $data = array(), $expires = false, $
}

/**
* @param string $string a string with twig variables
* @param array $data an array with data in it
* Compile string.
*
* @param string $string a string with twig variables.
* @param array $data an array with data in it.
* @return bool|string
*/
public static function compile_string( $string, $data = array() ) {
Expand All @@ -304,6 +339,8 @@ public static function compile_string( $string, $data = array() ) {
}

/**
* Fetch function.
*
* @param array $filenames
* @param array $data
* @param bool $expires
Expand All @@ -323,6 +360,8 @@ public static function fetch( $filenames, $data = array(), $expires = false, $ca
}

/**
* Render function.
*
* @param array $filenames
* @param array $data
* @param bool $expires
Expand All @@ -336,8 +375,10 @@ public static function render( $filenames, $data = array(), $expires = false, $c
}

/**
* @param string $string a string with twig variables
* @param array $data an array with data in it
* Render string.
*
* @param string $string a string with twig variables.
* @param array $data an array with data in it.
* @return bool|string
*/
public static function render_string( $string, $data = array() ) {
Expand All @@ -351,6 +392,8 @@ public static function render_string( $string, $data = array() ) {
================================ */

/**
* Get sidebar.
*
* @param string $sidebar
* @param array $data
* @return bool|string
Expand All @@ -366,6 +409,8 @@ public static function get_sidebar( $sidebar = '', $data = array() ) {
}

/**
* Get sidebar from PHP
*
* @param string $sidebar
* @param array $data
* @return string
Expand Down Expand Up @@ -395,6 +440,8 @@ public static function get_sidebar_from_php( $sidebar = '', $data ) {
================================ */

/**
* Get widgets.
*
* @param int $widget_id
* @return TimberFunctionWrapper
*/
Expand All @@ -407,6 +454,8 @@ public static function get_widgets( $widget_id ) {
================================ */

/**
* Add route.
*
* @param string $route
* @param callable $callback
* @param array $args
Expand All @@ -427,13 +476,17 @@ function cancel_query_posts_request() {
}

/**
* Load template.
*
* @deprecated since 0.20.0
*/
public static function load_template( $template, $query = false, $status_code = 200, $tparams = false ) {
return Routes::load( $template, $tparams, $query, $status_code );
}

/**
* Load view.
*
* @deprecated since 0.20.2
*/
public static function load_view( $template, $query = false, $status_code = 200, $tparams = false ) {
Expand All @@ -445,6 +498,8 @@ public static function load_view( $template, $query = false, $status_code = 200,
================================ */

/**
* Get pagination.
*
* @param array $prefs
* @return array mixed
*/
Expand Down Expand Up @@ -497,6 +552,8 @@ public static function get_pagination( $prefs = array() ) {
================================ */

/**
* Get calling script path.
*
* @param int $offset
* @return string
* @deprecated since 0.20.0
Expand All @@ -507,6 +564,8 @@ public static function get_calling_script_path( $offset = 0 ) {
}

/**
* Get calling script dir.
*
* @return boolean|string
*/
public static function get_calling_script_dir( $offset = 0 ) {
Expand All @@ -520,6 +579,8 @@ public static function get_calling_script_dir( $offset = 0 ) {
}

/**
* Get calling script file.
*
* @param int $offset
* @return string|null
* @deprecated since 0.20.0
Expand All @@ -542,6 +603,8 @@ public static function get_calling_script_file( $offset = 0 ) {
}

/**
* Is post class or class map.
*
* @param string|array $args
* @return bool
* @deprecated since 0.20.0
Expand Down

0 comments on commit 4e5701b

Please sign in to comment.