Completed
Pull Request — master (#793)
by Jared
03:28 queued 29s
created
lib/timber-query-iterator.php 1 patch
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -1,156 +1,156 @@
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3 3
 if ( !defined( 'ABSPATH' ) )
4
-    exit;
4
+	exit;
5 5
 
6 6
 class TimberQueryIterator implements Iterator {
7 7
 
8
-    /**
9
-     *
10
-     *
11
-     * @var WP_Query
12
-     */
13
-    private $_query = null;
14
-    private $_posts_class = 'TimberPost';
15
-
16
-    public function __construct( $query = false, $posts_class = 'TimberPost' ) {
17
-        add_action( 'pre_get_posts', array($this, 'fix_number_posts_wp_quirk' ));
18
-        if ( $posts_class )
19
-            $this->_posts_class = $posts_class;
20
-
21
-        if ( is_a( $query, 'WP_Query' ) ) {
22
-            // We got a full-fledged WP Query, look no further!
23
-            $the_query = $query;
24
-
25
-        } elseif ( false === $query ) {
26
-            // If query is explicitly set to false, use the main loop
27
-            global $wp_query;
28
-            $the_query =& $wp_query;
29
-            //if we're on a custom posts page?
30
-            $the_query = self::handle_maybe_custom_posts_page($the_query);
31
-        } elseif ( TimberHelper::is_array_assoc( $query ) || ( is_string( $query ) && strstr( $query, '=' ) ) ) {
32
-            // We have a regularly formed WP query string or array to use
33
-            $the_query = new WP_Query( $query );
34
-
35
-        } elseif ( is_numeric( $query ) || is_string( $query ) ) {
36
-            // We have what could be a post name or post ID to pull out
37
-            $the_query = self::get_query_from_string( $query );
38
-
39
-        } elseif ( is_array( $query ) && count( $query ) && ( is_integer( $query[0] ) || is_string( $query[0] ) ) ) {
40
-            // We have a list of pids (post IDs) to extract from
41
-            $the_query = self::get_query_from_array_of_ids( $query );
42
-        } elseif ( is_array($query) && empty($query)) {
43
-            // it's an empty array
44
-            $the_query = array();
45
-        } else {
46
-            TimberHelper::error_log( 'I have failed you! in ' . basename( __FILE__ ) . '::' . __LINE__ );
47
-            TimberHelper::error_log( $query );
48
-
49
-            // We have failed hard, at least let get something.
50
-            $the_query = new WP_Query();
51
-        }
52
-
53
-        $this->_query = $the_query;
54
-
55
-    }
56
-
57
-    public function get_posts( $return_collection = false ) {
58
-        if (isset($this->_query->posts)){
59
-            $posts = new TimberPostsCollection( $this->_query->posts, $this->_posts_class );
60
-            return ( $return_collection ) ? $posts : $posts->get_posts();
61
-        }
62
-    }
63
-
64
-    //
65
-    // GET POSTS
66
-    //
67
-    public static function get_query_from_array_of_ids( $query = array() ) {
68
-        if ( !is_array( $query ) || !count( $query ) )
69
-            return null;
70
-
71
-        return new WP_Query( array(
72
-                'post_type'=> 'any',
73
-                'ignore_sticky_posts' => true,
74
-                'post__in' => $query,
75
-                'orderby'  => 'post__in',
76
-                'nopaging' => true
77
-            ) );
78
-    }
79
-
80
-    public static function get_query_from_string( $string = '' ) {
81
-        $post_type = false;
82
-
83
-        if ( is_string( $string ) && strstr( $string, '#' ) ) {
84
-            //we have a post_type directive here
85
-            list( $post_type, $string ) = explode( '#', $string );
86
-        }
87
-
88
-        $query = array(
89
-            'post_type' => ( $post_type ) ? $post_type : 'any'
90
-        );
91
-
92
-        if ( is_numeric( $string ) ) {
93
-            $query['p'] = $string;
94
-
95
-        } else {
96
-            $query['name'] = $string;
97
-        }
98
-
99
-        return new WP_Query( $query );
100
-    }
101
-
102
-    //
103
-    // Iterator Interface
104
-    //
105
-
106
-    public function valid() {
107
-        return $this->_query->have_posts();
108
-    }
109
-
110
-    public function current() {
111
-        global $post;
112
-
113
-        $this->_query->the_post();
114
-
115
-        // Sets up the global post, but also return the post, for use in Twig template
116
-        $posts_class = $this->_posts_class;
117
-        return new $posts_class( $post );
118
-    }
119
-
120
-    /**
121
-     * Don't implement next, because current already advances the loop
122
-     */
123
-    final public function next() {}
124
-
125
-    public function rewind() {
126
-        $this->_query->rewind_posts();
127
-    }
128
-
129
-    public function key() {
130
-        $this->_query->current_post;
131
-    }
132
-
133
-    //get_posts users numberposts
134
-    static function fix_number_posts_wp_quirk( $query ) {
135
-        if (isset($query->query) && isset($query->query['numberposts'])
136
-                && !isset($query->query['posts_per_page'])) {
137
-            $query->set( 'posts_per_page', $query->query['numberposts'] );
138
-        }
139
-        return $query;
140
-    }
141
-
142
-    /**
143
-     * this will test for whether a custom page to display posts is active, and if so, set the query to the default
144
-     * @param  WP_Query $query the original query recived from WordPress
145
-     * @return WP_Query
146
-     */
147
-    static function handle_maybe_custom_posts_page( $query ) {
148
-    	if ($custom_posts_page = get_option('page_for_posts')) {
149
-        	if ( isset($query->query['p']) && $query->query['p'] == $custom_posts_page ) {
150
-        		return new WP_Query(array('post_type' => 'post'));
151
-        	}
152
-        }
153
-        return $query;
154
-    }
8
+	/**
9
+	 *
10
+	 *
11
+	 * @var WP_Query
12
+	 */
13
+	private $_query = null;
14
+	private $_posts_class = 'TimberPost';
15
+
16
+	public function __construct( $query = false, $posts_class = 'TimberPost' ) {
17
+		add_action( 'pre_get_posts', array($this, 'fix_number_posts_wp_quirk' ));
18
+		if ( $posts_class )
19
+			$this->_posts_class = $posts_class;
20
+
21
+		if ( is_a( $query, 'WP_Query' ) ) {
22
+			// We got a full-fledged WP Query, look no further!
23
+			$the_query = $query;
24
+
25
+		} elseif ( false === $query ) {
26
+			// If query is explicitly set to false, use the main loop
27
+			global $wp_query;
28
+			$the_query =& $wp_query;
29
+			//if we're on a custom posts page?
30
+			$the_query = self::handle_maybe_custom_posts_page($the_query);
31
+		} elseif ( TimberHelper::is_array_assoc( $query ) || ( is_string( $query ) && strstr( $query, '=' ) ) ) {
32
+			// We have a regularly formed WP query string or array to use
33
+			$the_query = new WP_Query( $query );
34
+
35
+		} elseif ( is_numeric( $query ) || is_string( $query ) ) {
36
+			// We have what could be a post name or post ID to pull out
37
+			$the_query = self::get_query_from_string( $query );
38
+
39
+		} elseif ( is_array( $query ) && count( $query ) && ( is_integer( $query[0] ) || is_string( $query[0] ) ) ) {
40
+			// We have a list of pids (post IDs) to extract from
41
+			$the_query = self::get_query_from_array_of_ids( $query );
42
+		} elseif ( is_array($query) && empty($query)) {
43
+			// it's an empty array
44
+			$the_query = array();
45
+		} else {
46
+			TimberHelper::error_log( 'I have failed you! in ' . basename( __FILE__ ) . '::' . __LINE__ );
47
+			TimberHelper::error_log( $query );
48
+
49
+			// We have failed hard, at least let get something.
50
+			$the_query = new WP_Query();
51
+		}
52
+
53
+		$this->_query = $the_query;
54
+
55
+	}
56
+
57
+	public function get_posts( $return_collection = false ) {
58
+		if (isset($this->_query->posts)){
59
+			$posts = new TimberPostsCollection( $this->_query->posts, $this->_posts_class );
60
+			return ( $return_collection ) ? $posts : $posts->get_posts();
61
+		}
62
+	}
63
+
64
+	//
65
+	// GET POSTS
66
+	//
67
+	public static function get_query_from_array_of_ids( $query = array() ) {
68
+		if ( !is_array( $query ) || !count( $query ) )
69
+			return null;
70
+
71
+		return new WP_Query( array(
72
+				'post_type'=> 'any',
73
+				'ignore_sticky_posts' => true,
74
+				'post__in' => $query,
75
+				'orderby'  => 'post__in',
76
+				'nopaging' => true
77
+			) );
78
+	}
79
+
80
+	public static function get_query_from_string( $string = '' ) {
81
+		$post_type = false;
82
+
83
+		if ( is_string( $string ) && strstr( $string, '#' ) ) {
84
+			//we have a post_type directive here
85
+			list( $post_type, $string ) = explode( '#', $string );
86
+		}
87
+
88
+		$query = array(
89
+			'post_type' => ( $post_type ) ? $post_type : 'any'
90
+		);
91
+
92
+		if ( is_numeric( $string ) ) {
93
+			$query['p'] = $string;
94
+
95
+		} else {
96
+			$query['name'] = $string;
97
+		}
98
+
99
+		return new WP_Query( $query );
100
+	}
101
+
102
+	//
103
+	// Iterator Interface
104
+	//
105
+
106
+	public function valid() {
107
+		return $this->_query->have_posts();
108
+	}
109
+
110
+	public function current() {
111
+		global $post;
112
+
113
+		$this->_query->the_post();
114
+
115
+		// Sets up the global post, but also return the post, for use in Twig template
116
+		$posts_class = $this->_posts_class;
117
+		return new $posts_class( $post );
118
+	}
119
+
120
+	/**
121
+	 * Don't implement next, because current already advances the loop
122
+	 */
123
+	final public function next() {}
124
+
125
+	public function rewind() {
126
+		$this->_query->rewind_posts();
127
+	}
128
+
129
+	public function key() {
130
+		$this->_query->current_post;
131
+	}
132
+
133
+	//get_posts users numberposts
134
+	static function fix_number_posts_wp_quirk( $query ) {
135
+		if (isset($query->query) && isset($query->query['numberposts'])
136
+				&& !isset($query->query['posts_per_page'])) {
137
+			$query->set( 'posts_per_page', $query->query['numberposts'] );
138
+		}
139
+		return $query;
140
+	}
141
+
142
+	/**
143
+	 * this will test for whether a custom page to display posts is active, and if so, set the query to the default
144
+	 * @param  WP_Query $query the original query recived from WordPress
145
+	 * @return WP_Query
146
+	 */
147
+	static function handle_maybe_custom_posts_page( $query ) {
148
+		if ($custom_posts_page = get_option('page_for_posts')) {
149
+			if ( isset($query->query['p']) && $query->query['p'] == $custom_posts_page ) {
150
+				return new WP_Query(array('post_type' => 'post'));
151
+			}
152
+		}
153
+		return $query;
154
+	}
155 155
 
156 156
 }
Please login to merge, or discard this patch.
lib/timber-site.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@
 block discarded – undo
64 64
 
65 65
 	/** @api
66 66
 	 * @var string for people who like trackback spam
67
-	*/
67
+	 */
68 68
 	public $pingback_url;
69 69
 	public $siteurl;
70 70
 	/**
Please login to merge, or discard this patch.
lib/timber-term-getter.php 1 patch
Indentation   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -3,180 +3,180 @@
 block discarded – undo
3 3
 class TimberTermGetter
4 4
 {
5 5
 
6
-    /**
7
-     * @param string|array $args
8
-     * @param array $maybe_args
9
-     * @param string $TermClass
10
-     * @return mixed
11
-     */
12
-    public static function get_terms($args = null, $maybe_args = array(), $TermClass = 'TimberTerm'){
13
-        if (is_string($maybe_args) && !strstr($maybe_args, '=')){
14
-            //the user is sending the $TermClass in the second argument
15
-            $TermClass = $maybe_args;
16
-        }
17
-        if (is_string($maybe_args) && strstr($maybe_args, '=')){
18
-            parse_str($maybe_args, $maybe_args);
19
-        }
20
-        if (is_string($args) && strstr($args, '=')){
21
-            //a string and a query string!
22
-            $parsed = TimberTermGetter::get_term_query_from_query_string($args);
23
-            if (is_array($maybe_args)){
24
-                $parsed->args = array_merge($parsed->args, $maybe_args);
25
-            }
26
-            return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
27
-        } else if (is_string($args)){
28
-            //its just a string with a single taxonomy
29
-            $parsed = TimberTermGetter::get_term_query_from_string($args);
30
-            if (is_array($maybe_args)){
31
-                $parsed->args = array_merge($parsed->args, $maybe_args);
32
-            }
33
-            return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
34
-        } else if (is_array($args) && TimberHelper::is_array_assoc($args)){
35
-            //its an associative array, like a good ole query
36
-            $parsed = TimberTermGetter::get_term_query_from_assoc_array($args);
37
-            return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
38
-        } else if (is_array($args)){
39
-            //its just an array of strings or IDs (hopefully)
40
-            $parsed = TimberTermGetter::get_term_query_from_array($args);
41
-            if (is_array($maybe_args)){
42
-                $parsed->args = array_merge($parsed->args, $maybe_args);
43
-            }
44
-            return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
45
-        } else if (is_null($args)) {
46
-            return self::handle_term_query(get_taxonomies(), array(), $TermClass);
47
-        }
48
-        return null;
49
-    }
6
+	/**
7
+	 * @param string|array $args
8
+	 * @param array $maybe_args
9
+	 * @param string $TermClass
10
+	 * @return mixed
11
+	 */
12
+	public static function get_terms($args = null, $maybe_args = array(), $TermClass = 'TimberTerm'){
13
+		if (is_string($maybe_args) && !strstr($maybe_args, '=')){
14
+			//the user is sending the $TermClass in the second argument
15
+			$TermClass = $maybe_args;
16
+		}
17
+		if (is_string($maybe_args) && strstr($maybe_args, '=')){
18
+			parse_str($maybe_args, $maybe_args);
19
+		}
20
+		if (is_string($args) && strstr($args, '=')){
21
+			//a string and a query string!
22
+			$parsed = TimberTermGetter::get_term_query_from_query_string($args);
23
+			if (is_array($maybe_args)){
24
+				$parsed->args = array_merge($parsed->args, $maybe_args);
25
+			}
26
+			return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
27
+		} else if (is_string($args)){
28
+			//its just a string with a single taxonomy
29
+			$parsed = TimberTermGetter::get_term_query_from_string($args);
30
+			if (is_array($maybe_args)){
31
+				$parsed->args = array_merge($parsed->args, $maybe_args);
32
+			}
33
+			return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
34
+		} else if (is_array($args) && TimberHelper::is_array_assoc($args)){
35
+			//its an associative array, like a good ole query
36
+			$parsed = TimberTermGetter::get_term_query_from_assoc_array($args);
37
+			return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
38
+		} else if (is_array($args)){
39
+			//its just an array of strings or IDs (hopefully)
40
+			$parsed = TimberTermGetter::get_term_query_from_array($args);
41
+			if (is_array($maybe_args)){
42
+				$parsed->args = array_merge($parsed->args, $maybe_args);
43
+			}
44
+			return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
45
+		} else if (is_null($args)) {
46
+			return self::handle_term_query(get_taxonomies(), array(), $TermClass);
47
+		}
48
+		return null;
49
+	}
50 50
 
51
-    /**
52
-     * @param string|array $taxonomies
53
-     * @param string|array $args
54
-     * @param string $TermClass
55
-     * @return mixed
56
-     */
57
-    public static function handle_term_query($taxonomies, $args, $TermClass){
58
-        if (!isset($args['hide_empty'])){
59
-            $args['hide_empty'] = false;
60
-        }
61
-        if (isset($args['term_id']) && is_int($args['term_id'])){
62
-            $args['term_id'] = array($args['term_id']);
63
-        }
64
-        if (isset($args['term_id'])){
65
-            $args['include'] = $args['term_id'];
66
-        }
67
-        $terms = get_terms($taxonomies, $args);
68
-        foreach($terms as &$term){
69
-            $term = new $TermClass($term->term_id, $term->taxonomy);
70
-        }
71
-        return $terms;
72
-    }
51
+	/**
52
+	 * @param string|array $taxonomies
53
+	 * @param string|array $args
54
+	 * @param string $TermClass
55
+	 * @return mixed
56
+	 */
57
+	public static function handle_term_query($taxonomies, $args, $TermClass){
58
+		if (!isset($args['hide_empty'])){
59
+			$args['hide_empty'] = false;
60
+		}
61
+		if (isset($args['term_id']) && is_int($args['term_id'])){
62
+			$args['term_id'] = array($args['term_id']);
63
+		}
64
+		if (isset($args['term_id'])){
65
+			$args['include'] = $args['term_id'];
66
+		}
67
+		$terms = get_terms($taxonomies, $args);
68
+		foreach($terms as &$term){
69
+			$term = new $TermClass($term->term_id, $term->taxonomy);
70
+		}
71
+		return $terms;
72
+	}
73 73
 
74
-    /**
75
-     * @param string $query_string
76
-     * @return stdClass
77
-     */
78
-    public static function get_term_query_from_query_string($query_string) {
79
-        $args = array();
80
-        parse_str($query_string, $args);
81
-        $ret = self::get_term_query_from_assoc_array($args);
82
-        return $ret;
83
-    }
74
+	/**
75
+	 * @param string $query_string
76
+	 * @return stdClass
77
+	 */
78
+	public static function get_term_query_from_query_string($query_string) {
79
+		$args = array();
80
+		parse_str($query_string, $args);
81
+		$ret = self::get_term_query_from_assoc_array($args);
82
+		return $ret;
83
+	}
84 84
 
85
-    /**
86
-     * @param string $taxs
87
-     * @return stdClass
88
-     */
89
-    public static function get_term_query_from_string($taxs) {
90
-        $ret = new stdClass();
91
-        $ret->args = array();
92
-        if (is_string($taxs)) {
93
-            $taxs = array($taxs);
94
-        }
95
-        $ret->taxonomies = self::correct_taxonomy_names($taxs);
96
-        return $ret;
97
-    }
85
+	/**
86
+	 * @param string $taxs
87
+	 * @return stdClass
88
+	 */
89
+	public static function get_term_query_from_string($taxs) {
90
+		$ret = new stdClass();
91
+		$ret->args = array();
92
+		if (is_string($taxs)) {
93
+			$taxs = array($taxs);
94
+		}
95
+		$ret->taxonomies = self::correct_taxonomy_names($taxs);
96
+		return $ret;
97
+	}
98 98
 
99
-    /**
100
-     * @param array $args
101
-     * @return stdClass
102
-     */
103
-    public static function get_term_query_from_assoc_array($args) {
104
-        $ret = new stdClass();
105
-        $ret->args = $args;
106
-        if (isset($ret->args['tax'])) {
107
-            $ret->taxonomies = $ret->args['tax'];
108
-        } else if (isset($ret->args['taxonomies'])) {
109
-            $ret->taxonomies = $ret->args['taxonomies'];
110
-        } else if (isset($ret->args['taxs'])) {
111
-            $ret->taxonomies = $ret->args['taxs'];
112
-        } else if (isset($ret->args['taxonomy'])) {
113
-            $ret->taxonomies = $ret->args['taxonomy'];
114
-        }
115
-        if (isset($ret->taxonomies)) {
116
-            if (is_string($ret->taxonomies)) {
117
-                $ret->taxonomies = array($ret->taxonomies);
118
-            }
119
-            $ret->taxonomies = self::correct_taxonomy_names($ret->taxonomies);
120
-        } else {
121
-            $ret->taxonomies = get_taxonomies();
122
-        }
123
-        return $ret;
124
-    }
99
+	/**
100
+	 * @param array $args
101
+	 * @return stdClass
102
+	 */
103
+	public static function get_term_query_from_assoc_array($args) {
104
+		$ret = new stdClass();
105
+		$ret->args = $args;
106
+		if (isset($ret->args['tax'])) {
107
+			$ret->taxonomies = $ret->args['tax'];
108
+		} else if (isset($ret->args['taxonomies'])) {
109
+			$ret->taxonomies = $ret->args['taxonomies'];
110
+		} else if (isset($ret->args['taxs'])) {
111
+			$ret->taxonomies = $ret->args['taxs'];
112
+		} else if (isset($ret->args['taxonomy'])) {
113
+			$ret->taxonomies = $ret->args['taxonomy'];
114
+		}
115
+		if (isset($ret->taxonomies)) {
116
+			if (is_string($ret->taxonomies)) {
117
+				$ret->taxonomies = array($ret->taxonomies);
118
+			}
119
+			$ret->taxonomies = self::correct_taxonomy_names($ret->taxonomies);
120
+		} else {
121
+			$ret->taxonomies = get_taxonomies();
122
+		}
123
+		return $ret;
124
+	}
125 125
 
126
-    /**
127
-     * @param array $args
128
-     * @return stdClass
129
-     */
130
-    public static function get_term_query_from_array($args) {
131
-        if (is_array($args) && !empty($args)) {
132
-            //okay its an array with content
133
-            if (is_int($args[0])) {
134
-                return self::get_term_query_from_array_of_ids($args);
135
-            } else if (is_string($args[0])) {
136
-                return self::get_term_query_from_array_of_strings($args);
137
-            }
138
-        }
139
-        return null;
140
-    }
126
+	/**
127
+	 * @param array $args
128
+	 * @return stdClass
129
+	 */
130
+	public static function get_term_query_from_array($args) {
131
+		if (is_array($args) && !empty($args)) {
132
+			//okay its an array with content
133
+			if (is_int($args[0])) {
134
+				return self::get_term_query_from_array_of_ids($args);
135
+			} else if (is_string($args[0])) {
136
+				return self::get_term_query_from_array_of_strings($args);
137
+			}
138
+		}
139
+		return null;
140
+	}
141 141
 
142
-    /**
143
-     * @param integer[] $args
144
-     * @return stdClass
145
-     */
146
-    public static function get_term_query_from_array_of_ids($args) {
147
-        $ret = new stdClass();
148
-        $ret->taxonomies = get_taxonomies();
149
-        $ret->args['include'] = $args;
150
-        return $ret;
151
-    }
142
+	/**
143
+	 * @param integer[] $args
144
+	 * @return stdClass
145
+	 */
146
+	public static function get_term_query_from_array_of_ids($args) {
147
+		$ret = new stdClass();
148
+		$ret->taxonomies = get_taxonomies();
149
+		$ret->args['include'] = $args;
150
+		return $ret;
151
+	}
152 152
 
153
-    /**
154
-     * @param string[] $args
155
-     * @return stdClass
156
-     */
157
-    public static function get_term_query_from_array_of_strings($args) {
158
-        $ret = new stdClass();
159
-        $ret->taxonomies = self::correct_taxonomy_names($args);
160
-        $ret->args = array();
161
-        return $ret;
162
-    }
153
+	/**
154
+	 * @param string[] $args
155
+	 * @return stdClass
156
+	 */
157
+	public static function get_term_query_from_array_of_strings($args) {
158
+		$ret = new stdClass();
159
+		$ret->taxonomies = self::correct_taxonomy_names($args);
160
+		$ret->args = array();
161
+		return $ret;
162
+	}
163 163
 
164
-    /**
165
-     * @param string|array $taxs
166
-     * @return array
167
-     */
168
-    private static function correct_taxonomy_names($taxs) {
169
-        if (is_string($taxs)) {
170
-            $taxs = array($taxs);
171
-        }
172
-        foreach ($taxs as &$tax) {
173
-            if ($tax == 'tags' || $tax == 'tag') {
174
-                $tax = 'post_tag';
175
-            } else if ($tax == 'categories') {
176
-                $tax = 'category';
177
-            }
178
-        }
179
-        return $taxs;
180
-    }
164
+	/**
165
+	 * @param string|array $taxs
166
+	 * @return array
167
+	 */
168
+	private static function correct_taxonomy_names($taxs) {
169
+		if (is_string($taxs)) {
170
+			$taxs = array($taxs);
171
+		}
172
+		foreach ($taxs as &$tax) {
173
+			if ($tax == 'tags' || $tax == 'tag') {
174
+				$tax = 'post_tag';
175
+			} else if ($tax == 'categories') {
176
+				$tax = 'category';
177
+			}
178
+		}
179
+		return $taxs;
180
+	}
181 181
 
182 182
 }
Please login to merge, or discard this patch.
lib/timber-term.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -333,7 +333,7 @@
 block discarded – undo
333 333
 		$suffix = '</p>';
334 334
 		$desc = term_description( $this->ID, $this->taxonomy );
335 335
 		if (substr($desc, 0, strlen($prefix)) == $prefix) {
336
-    		$desc = substr($desc, strlen($prefix));
336
+			$desc = substr($desc, strlen($prefix));
337 337
 		}
338 338
 		$desc = preg_replace('/'. preg_quote('</p>', '/') . '$/', '', $desc);
339 339
 		return trim($desc);
Please login to merge, or discard this patch.
lib/image/timber-image-operation-retina.php 1 patch
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Contains the class for running image retina-izing operations
4
- */
3
+	 * Contains the class for running image retina-izing operations
4
+	 */
5 5
 
6 6
 /**
7 7
  * Increases image size by a given factor
@@ -11,64 +11,64 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class TimberImageOperationRetina extends TimberImageOperation {
13 13
 
14
-    private $factor;
14
+	private $factor;
15 15
 
16
-    /**
17
-     * Construct our operation
18
-     * @param float   $factor to multiply original dimensions by
19
-     */
20
-    function __construct($factor) {
21
-        $this->factor = $factor;
22
-    }
16
+	/**
17
+	 * Construct our operation
18
+	 * @param float   $factor to multiply original dimensions by
19
+	 */
20
+	function __construct($factor) {
21
+		$this->factor = $factor;
22
+	}
23 23
 
24
-    /**
25
-     * Generates the final filename based on the source's name and extension
26
-     *
27
-     * @param   string    $src_filename     the basename of the file (ex: my-awesome-pic)
28
-     * @param   string    $src_extension    the extension (ex: .jpg)
29
-     * @return  string    the final filename to be used (ex: [email protected])
30
-     */
31
-    function filename($src_filename, $src_extension) {
32
-        $newbase = $src_filename . '@' . $this->factor . 'x'; // add @2x, @3x, @1.5x, etc.
33
-        $new_name = $newbase . '.' . $src_extension;
34
-        return $new_name;
35
-    }
24
+	/**
25
+	 * Generates the final filename based on the source's name and extension
26
+	 *
27
+	 * @param   string    $src_filename     the basename of the file (ex: my-awesome-pic)
28
+	 * @param   string    $src_extension    the extension (ex: .jpg)
29
+	 * @return  string    the final filename to be used (ex: [email protected])
30
+	 */
31
+	function filename($src_filename, $src_extension) {
32
+		$newbase = $src_filename . '@' . $this->factor . 'x'; // add @2x, @3x, @1.5x, etc.
33
+		$new_name = $newbase . '.' . $src_extension;
34
+		return $new_name;
35
+	}
36 36
 
37
-    /**
38
-     * Performs the actual image manipulation,
39
-     * including saving the target file.
40
-     *
41
-     * @param  string $load_filename filepath (not URL) to source file
42
-     *                               (ex: /src/var/www/wp-content/uploads/my-pic.jpg)
43
-     * @param  string $save_filename filepath (not URL) where result file should be saved
44
-     *                               (ex: /src/var/www/wp-content/uploads/[email protected])
45
-     * @return bool                  true if everything went fine, false otherwise
46
-     */
47
-    function run($load_filename, $save_filename){
48
-        $image = wp_get_image_editor( $load_filename );
49
-        if ( !is_wp_error( $image ) ) {
50
-            $current_size = $image->get_size();
51
-            $src_w = $current_size['width'];
52
-            $src_h = $current_size['height'];
53
-            // Get ratios
54
-            $w = $src_w * $this->factor;
55
-            $h = $src_h * $this->factor;
56
-            $image->crop( 0, 0, $src_w, $src_h, $w, $h );
57
-            $result = $image->save( $save_filename );
58
-            if ( is_wp_error( $result ) ) {
59
-            	// @codeCoverageIgnoreStart
37
+	/**
38
+	 * Performs the actual image manipulation,
39
+	 * including saving the target file.
40
+	 *
41
+	 * @param  string $load_filename filepath (not URL) to source file
42
+	 *                               (ex: /src/var/www/wp-content/uploads/my-pic.jpg)
43
+	 * @param  string $save_filename filepath (not URL) where result file should be saved
44
+	 *                               (ex: /src/var/www/wp-content/uploads/[email protected])
45
+	 * @return bool                  true if everything went fine, false otherwise
46
+	 */
47
+	function run($load_filename, $save_filename){
48
+		$image = wp_get_image_editor( $load_filename );
49
+		if ( !is_wp_error( $image ) ) {
50
+			$current_size = $image->get_size();
51
+			$src_w = $current_size['width'];
52
+			$src_h = $current_size['height'];
53
+			// Get ratios
54
+			$w = $src_w * $this->factor;
55
+			$h = $src_h * $this->factor;
56
+			$image->crop( 0, 0, $src_w, $src_h, $w, $h );
57
+			$result = $image->save( $save_filename );
58
+			if ( is_wp_error( $result ) ) {
59
+				// @codeCoverageIgnoreStart
60 60
 				TimberHelper::error_log( 'Error resizing image' );
61 61
 				TimberHelper::error_log( $result );
62 62
 				return false;
63 63
 				// @codeCoverageIgnoreEnd
64
-            } else {
65
-                return true;
66
-            }
67
-        } else if ( isset( $image->error_data['error_loading_image'] ) ) {
68
-            TimberHelper::error_log( 'Error loading ' . $image->error_data['error_loading_image'] );
69
-        } else {
70
-            TimberHelper::error_log( $image );
71
-        }
72
-        return false;
73
-    }
64
+			} else {
65
+				return true;
66
+			}
67
+		} else if ( isset( $image->error_data['error_loading_image'] ) ) {
68
+			TimberHelper::error_log( 'Error loading ' . $image->error_data['error_loading_image'] );
69
+		} else {
70
+			TimberHelper::error_log( $image );
71
+		}
72
+		return false;
73
+	}
74 74
 }
Please login to merge, or discard this patch.