@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | $query = false; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - if (is_object($query) && !is_a($query, 'WP_Query') ){ |
|
| 40 | + if (is_object($query) && !is_a($query, 'WP_Query') ) { |
|
| 41 | 41 | // The only object other than a query is a type of post object |
| 42 | 42 | $query = array( $query ); |
| 43 | 43 | } |
@@ -52,11 +52,11 @@ discard block |
||
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - static function get_pids($query){ |
|
| 55 | + static function get_pids($query) { |
|
| 56 | 56 | $posts = self::get_posts($query); |
| 57 | 57 | $pids = array(); |
| 58 | - foreach($posts as $post){ |
|
| 59 | - if (isset($post->ID)){ |
|
| 58 | + foreach($posts as $post) { |
|
| 59 | + if (isset($post->ID)) { |
|
| 60 | 60 | $pids[] = $post->ID; |
| 61 | 61 | } |
| 62 | 62 | } |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | * @param string|array $arg |
| 90 | 90 | * @return bool |
| 91 | 91 | */ |
| 92 | - static function is_post_class_or_class_map($arg){ |
|
| 92 | + static function is_post_class_or_class_map($arg) { |
|
| 93 | 93 | if (is_string($arg) && class_exists($arg)) { |
| 94 | 94 | return true; |
| 95 | 95 | } |
@@ -606,7 +606,7 @@ |
||
| 606 | 606 | * Is post class or class map. |
| 607 | 607 | * |
| 608 | 608 | * @param string|array $args |
| 609 | - * @return bool |
|
| 609 | + * @return boolean|null |
|
| 610 | 610 | * @deprecated since 0.20.0 |
| 611 | 611 | */ |
| 612 | 612 | public static function is_post_class_or_class_map( $args ) { |
@@ -8,19 +8,19 @@ discard block |
||
| 8 | 8 | * @return array|bool|null |
| 9 | 9 | */ |
| 10 | 10 | static function get_post($query = false, $PostClass = 'TimberPost') { |
| 11 | - $posts = self::get_posts( $query, $PostClass ); |
|
| 12 | - if ( $post = reset($posts ) ) { |
|
| 11 | + $posts = self::get_posts($query, $PostClass); |
|
| 12 | + if ( $post = reset($posts) ) { |
|
| 13 | 13 | return $post; |
| 14 | 14 | } |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | - static function get_posts( $query = false, $PostClass = 'TimberPost', $return_collection = false ) { |
|
| 18 | - $posts = self::query_posts( $query, $PostClass ); |
|
| 19 | - return apply_filters('timber_post_getter_get_posts', $posts->get_posts( $return_collection )); |
|
| 17 | + static function get_posts($query = false, $PostClass = 'TimberPost', $return_collection = false) { |
|
| 18 | + $posts = self::query_posts($query, $PostClass); |
|
| 19 | + return apply_filters('timber_post_getter_get_posts', $posts->get_posts($return_collection)); |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | - static function query_post( $query = false, $PostClass = 'TimberPost' ) { |
|
| 23 | - $posts = self::query_posts( $query, $PostClass ); |
|
| 22 | + static function query_post($query = false, $PostClass = 'TimberPost') { |
|
| 23 | + $posts = self::query_posts($query, $PostClass); |
|
| 24 | 24 | if ( method_exists($posts, 'current') && $post = $posts->current() ) { |
| 25 | 25 | return $post; |
| 26 | 26 | } |
@@ -31,32 +31,32 @@ discard block |
||
| 31 | 31 | * @param string $PostClass |
| 32 | 32 | * @return array|bool|null |
| 33 | 33 | */ |
| 34 | - static function query_posts($query = false, $PostClass = 'TimberPost' ) { |
|
| 35 | - if (self::is_post_class_or_class_map($query)) { |
|
| 34 | + static function query_posts($query = false, $PostClass = 'TimberPost') { |
|
| 35 | + if ( self::is_post_class_or_class_map($query) ) { |
|
| 36 | 36 | $PostClass = $query; |
| 37 | 37 | $query = false; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - if (is_object($query) && !is_a($query, 'WP_Query') ){ |
|
| 40 | + if ( is_object($query) && !is_a($query, 'WP_Query') ) { |
|
| 41 | 41 | // The only object other than a query is a type of post object |
| 42 | - $query = array( $query ); |
|
| 42 | + $query = array($query); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - if ( is_array( $query ) && count( $query ) && isset( $query[0] ) && is_object( $query[0] ) ) { |
|
| 45 | + if ( is_array($query) && count($query) && isset($query[0]) && is_object($query[0]) ) { |
|
| 46 | 46 | // We have an array of post objects that already have data |
| 47 | - return new TimberPostsCollection( $query, $PostClass ); |
|
| 47 | + return new TimberPostsCollection($query, $PostClass); |
|
| 48 | 48 | } else { |
| 49 | 49 | // We have a query (of sorts) to work with |
| 50 | - $tqi = new TimberQueryIterator( $query, $PostClass ); |
|
| 50 | + $tqi = new TimberQueryIterator($query, $PostClass); |
|
| 51 | 51 | return $tqi; |
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - static function get_pids($query){ |
|
| 55 | + static function get_pids($query) { |
|
| 56 | 56 | $posts = self::get_posts($query); |
| 57 | 57 | $pids = array(); |
| 58 | - foreach($posts as $post){ |
|
| 59 | - if (isset($post->ID)){ |
|
| 58 | + foreach ($posts as $post) { |
|
| 59 | + if ( isset($post->ID) ) { |
|
| 60 | 60 | $pids[] = $post->ID; |
| 61 | 61 | } |
| 62 | 62 | } |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | static function loop_to_id() { |
| 67 | - if (!self::wp_query_has_posts()) { return false; } |
|
| 67 | + if ( !self::wp_query_has_posts() ) { return false; } |
|
| 68 | 68 | |
| 69 | 69 | global $wp_query; |
| 70 | 70 | $post_num = property_exists($wp_query, 'current_post') |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | : 0 |
| 73 | 73 | ; |
| 74 | 74 | |
| 75 | - if (!isset($wp_query->posts[$post_num])) { return false; } |
|
| 75 | + if ( !isset($wp_query->posts[$post_num]) ) { return false; } |
|
| 76 | 76 | |
| 77 | 77 | return $wp_query->posts[$post_num]->ID; |
| 78 | 78 | } |
@@ -89,13 +89,13 @@ discard block |
||
| 89 | 89 | * @param string|array $arg |
| 90 | 90 | * @return bool |
| 91 | 91 | */ |
| 92 | - static function is_post_class_or_class_map($arg){ |
|
| 93 | - if (is_string($arg) && class_exists($arg)) { |
|
| 92 | + static function is_post_class_or_class_map($arg) { |
|
| 93 | + if ( is_string($arg) && class_exists($arg) ) { |
|
| 94 | 94 | return true; |
| 95 | 95 | } |
| 96 | - if (is_array($arg)) { |
|
| 96 | + if ( is_array($arg) ) { |
|
| 97 | 97 | foreach ($arg as $item) { |
| 98 | - if (is_string($item) && (class_exists($item) && is_subclass_of($item, 'TimberPost'))) { |
|
| 98 | + if ( is_string($item) && (class_exists($item) && is_subclass_of($item, 'TimberPost')) ) { |
|
| 99 | 99 | return true; |
| 100 | 100 | } |
| 101 | 101 | } |
@@ -2,96 +2,96 @@ |
||
| 2 | 2 | |
| 3 | 3 | // Exit if accessed directly |
| 4 | 4 | if ( !defined( 'ABSPATH' ) ) |
| 5 | - exit; |
|
| 5 | + exit; |
|
| 6 | 6 | |
| 7 | 7 | class TimberPostsCollection extends ArrayObject { |
| 8 | 8 | |
| 9 | - public function __construct( $posts = array(), $post_class = 'TimberPost' ) { |
|
| 10 | - $returned_posts = array(); |
|
| 11 | - if ( is_null( $posts ) ){ |
|
| 12 | - $posts = array(); |
|
| 13 | - } |
|
| 14 | - foreach ( $posts as $post_object ) { |
|
| 15 | - $post_class_use = $post_class; |
|
| 16 | - |
|
| 17 | - if ( is_array( $post_class ) ) { |
|
| 18 | - $post_type = get_post_type( $post_object ); |
|
| 19 | - $post_class_use = 'TimberPost'; |
|
| 20 | - |
|
| 21 | - if ( isset( $post_class[$post_type] ) ) { |
|
| 22 | - $post_class_use = $post_class[$post_type]; |
|
| 23 | - |
|
| 24 | - } else { |
|
| 25 | - if ( is_array( $post_class ) ) { |
|
| 26 | - TimberHelper::error_log( $post_type . ' of ' . $post_object->ID . ' not found in ' . print_r( $post_class, true ) ); |
|
| 27 | - } else { |
|
| 28 | - TimberHelper::error_log( $post_type . ' not found in ' . $post_class ); |
|
| 29 | - } |
|
| 30 | - } |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - // Don't create yet another object if $post_object is already of the right type |
|
| 34 | - if ( is_a( $post_object, $post_class_use ) ) { |
|
| 35 | - $post = $post_object; |
|
| 36 | - } else { |
|
| 37 | - $post = new $post_class_use( $post_object ); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - if ( isset( $post->ID ) ) { |
|
| 41 | - $returned_posts[] = $post; |
|
| 42 | - } |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - $returned_posts = self::maybe_set_preview($returned_posts); |
|
| 46 | - |
|
| 47 | - parent::__construct( $returned_posts, $flags = 0, 'TimberPostsIterator' ); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - public function get_posts() { |
|
| 51 | - return $this->getArrayCopy(); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @param array $posts |
|
| 56 | - * @return array |
|
| 57 | - */ |
|
| 58 | - static function maybe_set_preview( $posts ) { |
|
| 59 | - if ( is_array( $posts ) && isset( $_GET['preview'] ) && $_GET['preview'] |
|
| 60 | - && isset( $_GET['preview_id'] ) && $_GET['preview_id'] |
|
| 61 | - && current_user_can( 'edit_post', $_GET['preview_id'] ) ) { |
|
| 62 | - // No need to check the nonce, that already happened in _show_post_preview on init |
|
| 63 | - |
|
| 64 | - $preview_id = $_GET['preview_id']; |
|
| 65 | - foreach( $posts as &$post ) { |
|
| 66 | - if ( is_object( $post ) && $post->ID == $preview_id ) { |
|
| 67 | - // Based on _set_preview( $post ), but adds import_custom |
|
| 68 | - $preview = wp_get_post_autosave( $preview_id ); |
|
| 69 | - if ( is_object($preview) ) { |
|
| 70 | - |
|
| 71 | - $preview = sanitize_post($preview); |
|
| 72 | - |
|
| 73 | - $post->post_content = $preview->post_content; |
|
| 74 | - $post->post_title = $preview->post_title; |
|
| 75 | - $post->post_excerpt = $preview->post_excerpt; |
|
| 76 | - $post->import_custom( $preview_id ); |
|
| 77 | - |
|
| 78 | - add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 ); |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - return $posts; |
|
| 86 | - } |
|
| 9 | + public function __construct( $posts = array(), $post_class = 'TimberPost' ) { |
|
| 10 | + $returned_posts = array(); |
|
| 11 | + if ( is_null( $posts ) ){ |
|
| 12 | + $posts = array(); |
|
| 13 | + } |
|
| 14 | + foreach ( $posts as $post_object ) { |
|
| 15 | + $post_class_use = $post_class; |
|
| 16 | + |
|
| 17 | + if ( is_array( $post_class ) ) { |
|
| 18 | + $post_type = get_post_type( $post_object ); |
|
| 19 | + $post_class_use = 'TimberPost'; |
|
| 20 | + |
|
| 21 | + if ( isset( $post_class[$post_type] ) ) { |
|
| 22 | + $post_class_use = $post_class[$post_type]; |
|
| 23 | + |
|
| 24 | + } else { |
|
| 25 | + if ( is_array( $post_class ) ) { |
|
| 26 | + TimberHelper::error_log( $post_type . ' of ' . $post_object->ID . ' not found in ' . print_r( $post_class, true ) ); |
|
| 27 | + } else { |
|
| 28 | + TimberHelper::error_log( $post_type . ' not found in ' . $post_class ); |
|
| 29 | + } |
|
| 30 | + } |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + // Don't create yet another object if $post_object is already of the right type |
|
| 34 | + if ( is_a( $post_object, $post_class_use ) ) { |
|
| 35 | + $post = $post_object; |
|
| 36 | + } else { |
|
| 37 | + $post = new $post_class_use( $post_object ); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + if ( isset( $post->ID ) ) { |
|
| 41 | + $returned_posts[] = $post; |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + $returned_posts = self::maybe_set_preview($returned_posts); |
|
| 46 | + |
|
| 47 | + parent::__construct( $returned_posts, $flags = 0, 'TimberPostsIterator' ); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + public function get_posts() { |
|
| 51 | + return $this->getArrayCopy(); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @param array $posts |
|
| 56 | + * @return array |
|
| 57 | + */ |
|
| 58 | + static function maybe_set_preview( $posts ) { |
|
| 59 | + if ( is_array( $posts ) && isset( $_GET['preview'] ) && $_GET['preview'] |
|
| 60 | + && isset( $_GET['preview_id'] ) && $_GET['preview_id'] |
|
| 61 | + && current_user_can( 'edit_post', $_GET['preview_id'] ) ) { |
|
| 62 | + // No need to check the nonce, that already happened in _show_post_preview on init |
|
| 63 | + |
|
| 64 | + $preview_id = $_GET['preview_id']; |
|
| 65 | + foreach( $posts as &$post ) { |
|
| 66 | + if ( is_object( $post ) && $post->ID == $preview_id ) { |
|
| 67 | + // Based on _set_preview( $post ), but adds import_custom |
|
| 68 | + $preview = wp_get_post_autosave( $preview_id ); |
|
| 69 | + if ( is_object($preview) ) { |
|
| 70 | + |
|
| 71 | + $preview = sanitize_post($preview); |
|
| 72 | + |
|
| 73 | + $post->post_content = $preview->post_content; |
|
| 74 | + $post->post_title = $preview->post_title; |
|
| 75 | + $post->post_excerpt = $preview->post_excerpt; |
|
| 76 | + $post->import_custom( $preview_id ); |
|
| 77 | + |
|
| 78 | + add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 ); |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + return $posts; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | class TimberPostsIterator extends ArrayIterator { |
| 91 | 91 | |
| 92 | - public function current() { |
|
| 93 | - global $post; |
|
| 94 | - $post = parent::current(); |
|
| 95 | - return $post; |
|
| 96 | - } |
|
| 92 | + public function current() { |
|
| 93 | + global $post; |
|
| 94 | + $post = parent::current(); |
|
| 95 | + return $post; |
|
| 96 | + } |
|
| 97 | 97 | } |
@@ -1,50 +1,50 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | // Exit if accessed directly |
| 4 | -if ( !defined( 'ABSPATH' ) ) |
|
| 4 | +if ( !defined('ABSPATH') ) |
|
| 5 | 5 | exit; |
| 6 | 6 | |
| 7 | 7 | class TimberPostsCollection extends ArrayObject { |
| 8 | 8 | |
| 9 | - public function __construct( $posts = array(), $post_class = 'TimberPost' ) { |
|
| 9 | + public function __construct($posts = array(), $post_class = 'TimberPost') { |
|
| 10 | 10 | $returned_posts = array(); |
| 11 | - if ( is_null( $posts ) ){ |
|
| 11 | + if ( is_null($posts) ) { |
|
| 12 | 12 | $posts = array(); |
| 13 | 13 | } |
| 14 | - foreach ( $posts as $post_object ) { |
|
| 14 | + foreach ($posts as $post_object) { |
|
| 15 | 15 | $post_class_use = $post_class; |
| 16 | 16 | |
| 17 | - if ( is_array( $post_class ) ) { |
|
| 18 | - $post_type = get_post_type( $post_object ); |
|
| 17 | + if ( is_array($post_class) ) { |
|
| 18 | + $post_type = get_post_type($post_object); |
|
| 19 | 19 | $post_class_use = 'TimberPost'; |
| 20 | 20 | |
| 21 | - if ( isset( $post_class[$post_type] ) ) { |
|
| 21 | + if ( isset($post_class[$post_type]) ) { |
|
| 22 | 22 | $post_class_use = $post_class[$post_type]; |
| 23 | 23 | |
| 24 | 24 | } else { |
| 25 | - if ( is_array( $post_class ) ) { |
|
| 26 | - TimberHelper::error_log( $post_type . ' of ' . $post_object->ID . ' not found in ' . print_r( $post_class, true ) ); |
|
| 25 | + if ( is_array($post_class) ) { |
|
| 26 | + TimberHelper::error_log($post_type . ' of ' . $post_object->ID . ' not found in ' . print_r($post_class, true)); |
|
| 27 | 27 | } else { |
| 28 | - TimberHelper::error_log( $post_type . ' not found in ' . $post_class ); |
|
| 28 | + TimberHelper::error_log($post_type . ' not found in ' . $post_class); |
|
| 29 | 29 | } |
| 30 | 30 | } |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | // Don't create yet another object if $post_object is already of the right type |
| 34 | - if ( is_a( $post_object, $post_class_use ) ) { |
|
| 34 | + if ( is_a($post_object, $post_class_use) ) { |
|
| 35 | 35 | $post = $post_object; |
| 36 | 36 | } else { |
| 37 | - $post = new $post_class_use( $post_object ); |
|
| 37 | + $post = new $post_class_use($post_object); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - if ( isset( $post->ID ) ) { |
|
| 40 | + if ( isset($post->ID) ) { |
|
| 41 | 41 | $returned_posts[] = $post; |
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | $returned_posts = self::maybe_set_preview($returned_posts); |
| 46 | 46 | |
| 47 | - parent::__construct( $returned_posts, $flags = 0, 'TimberPostsIterator' ); |
|
| 47 | + parent::__construct($returned_posts, $flags = 0, 'TimberPostsIterator'); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | public function get_posts() { |
@@ -55,17 +55,17 @@ discard block |
||
| 55 | 55 | * @param array $posts |
| 56 | 56 | * @return array |
| 57 | 57 | */ |
| 58 | - static function maybe_set_preview( $posts ) { |
|
| 59 | - if ( is_array( $posts ) && isset( $_GET['preview'] ) && $_GET['preview'] |
|
| 60 | - && isset( $_GET['preview_id'] ) && $_GET['preview_id'] |
|
| 61 | - && current_user_can( 'edit_post', $_GET['preview_id'] ) ) { |
|
| 58 | + static function maybe_set_preview($posts) { |
|
| 59 | + if ( is_array($posts) && isset($_GET['preview']) && $_GET['preview'] |
|
| 60 | + && isset($_GET['preview_id']) && $_GET['preview_id'] |
|
| 61 | + && current_user_can('edit_post', $_GET['preview_id']) ) { |
|
| 62 | 62 | // No need to check the nonce, that already happened in _show_post_preview on init |
| 63 | 63 | |
| 64 | 64 | $preview_id = $_GET['preview_id']; |
| 65 | - foreach( $posts as &$post ) { |
|
| 66 | - if ( is_object( $post ) && $post->ID == $preview_id ) { |
|
| 65 | + foreach ($posts as &$post) { |
|
| 66 | + if ( is_object($post) && $post->ID == $preview_id ) { |
|
| 67 | 67 | // Based on _set_preview( $post ), but adds import_custom |
| 68 | - $preview = wp_get_post_autosave( $preview_id ); |
|
| 68 | + $preview = wp_get_post_autosave($preview_id); |
|
| 69 | 69 | if ( is_object($preview) ) { |
| 70 | 70 | |
| 71 | 71 | $preview = sanitize_post($preview); |
@@ -73,9 +73,9 @@ discard block |
||
| 73 | 73 | $post->post_content = $preview->post_content; |
| 74 | 74 | $post->post_title = $preview->post_title; |
| 75 | 75 | $post->post_excerpt = $preview->post_excerpt; |
| 76 | - $post->import_custom( $preview_id ); |
|
| 76 | + $post->import_custom($preview_id); |
|
| 77 | 77 | |
| 78 | - add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 ); |
|
| 78 | + add_filter('get_the_terms', '_wp_preview_terms_filter', 10, 3); |
|
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | } |
@@ -1,14 +1,15 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | // Exit if accessed directly |
| 4 | -if ( !defined( 'ABSPATH' ) ) |
|
| 4 | +if ( !defined( 'ABSPATH' ) ) { |
|
| 5 | 5 | exit; |
| 6 | +} |
|
| 6 | 7 | |
| 7 | 8 | class TimberPostsCollection extends ArrayObject { |
| 8 | 9 | |
| 9 | 10 | public function __construct( $posts = array(), $post_class = 'TimberPost' ) { |
| 10 | 11 | $returned_posts = array(); |
| 11 | - if ( is_null( $posts ) ){ |
|
| 12 | + if ( is_null( $posts ) ) { |
|
| 12 | 13 | $posts = array(); |
| 13 | 14 | } |
| 14 | 15 | foreach ( $posts as $post_object ) { |
@@ -1,156 +1,156 @@ |
||
| 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 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly |
| 3 | -if ( !defined( 'ABSPATH' ) ) |
|
| 3 | +if ( !defined('ABSPATH') ) |
|
| 4 | 4 | exit; |
| 5 | 5 | |
| 6 | 6 | class TimberQueryIterator implements Iterator { |
@@ -13,38 +13,38 @@ discard block |
||
| 13 | 13 | private $_query = null; |
| 14 | 14 | private $_posts_class = 'TimberPost'; |
| 15 | 15 | |
| 16 | - public function __construct( $query = false, $posts_class = 'TimberPost' ) { |
|
| 17 | - add_action( 'pre_get_posts', array($this, 'fix_number_posts_wp_quirk' )); |
|
| 16 | + public function __construct($query = false, $posts_class = 'TimberPost') { |
|
| 17 | + add_action('pre_get_posts', array($this, 'fix_number_posts_wp_quirk')); |
|
| 18 | 18 | if ( $posts_class ) |
| 19 | 19 | $this->_posts_class = $posts_class; |
| 20 | 20 | |
| 21 | - if ( is_a( $query, 'WP_Query' ) ) { |
|
| 21 | + if ( is_a($query, 'WP_Query') ) { |
|
| 22 | 22 | // We got a full-fledged WP Query, look no further! |
| 23 | 23 | $the_query = $query; |
| 24 | 24 | |
| 25 | 25 | } elseif ( false === $query ) { |
| 26 | 26 | // If query is explicitly set to false, use the main loop |
| 27 | 27 | global $wp_query; |
| 28 | - $the_query =& $wp_query; |
|
| 28 | + $the_query = & $wp_query; |
|
| 29 | 29 | //if we're on a custom posts page? |
| 30 | 30 | $the_query = self::handle_maybe_custom_posts_page($the_query); |
| 31 | - } elseif ( TimberHelper::is_array_assoc( $query ) || ( is_string( $query ) && strstr( $query, '=' ) ) ) { |
|
| 31 | + } elseif ( TimberHelper::is_array_assoc($query) || (is_string($query) && strstr($query, '=')) ) { |
|
| 32 | 32 | // We have a regularly formed WP query string or array to use |
| 33 | - $the_query = new WP_Query( $query ); |
|
| 33 | + $the_query = new WP_Query($query); |
|
| 34 | 34 | |
| 35 | - } elseif ( is_numeric( $query ) || is_string( $query ) ) { |
|
| 35 | + } elseif ( is_numeric($query) || is_string($query) ) { |
|
| 36 | 36 | // We have what could be a post name or post ID to pull out |
| 37 | - $the_query = self::get_query_from_string( $query ); |
|
| 37 | + $the_query = self::get_query_from_string($query); |
|
| 38 | 38 | |
| 39 | - } elseif ( is_array( $query ) && count( $query ) && ( is_integer( $query[0] ) || is_string( $query[0] ) ) ) { |
|
| 39 | + } elseif ( is_array($query) && count($query) && (is_integer($query[0]) || is_string($query[0])) ) { |
|
| 40 | 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)) { |
|
| 41 | + $the_query = self::get_query_from_array_of_ids($query); |
|
| 42 | + } elseif ( is_array($query) && empty($query) ) { |
|
| 43 | 43 | // it's an empty array |
| 44 | 44 | $the_query = array(); |
| 45 | 45 | } else { |
| 46 | - TimberHelper::error_log( 'I have failed you! in ' . basename( __FILE__ ) . '::' . __LINE__ ); |
|
| 47 | - TimberHelper::error_log( $query ); |
|
| 46 | + TimberHelper::error_log('I have failed you! in ' . basename(__FILE__) . '::' . __LINE__); |
|
| 47 | + TimberHelper::error_log($query); |
|
| 48 | 48 | |
| 49 | 49 | // We have failed hard, at least let get something. |
| 50 | 50 | $the_query = new WP_Query(); |
@@ -54,49 +54,49 @@ discard block |
||
| 54 | 54 | |
| 55 | 55 | } |
| 56 | 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(); |
|
| 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 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | // |
| 65 | 65 | // GET POSTS |
| 66 | 66 | // |
| 67 | - public static function get_query_from_array_of_ids( $query = array() ) { |
|
| 68 | - if ( !is_array( $query ) || !count( $query ) ) |
|
| 67 | + public static function get_query_from_array_of_ids($query = array()) { |
|
| 68 | + if ( !is_array($query) || !count($query) ) |
|
| 69 | 69 | return null; |
| 70 | 70 | |
| 71 | - return new WP_Query( array( |
|
| 71 | + return new WP_Query(array( |
|
| 72 | 72 | 'post_type'=> 'any', |
| 73 | 73 | 'ignore_sticky_posts' => true, |
| 74 | 74 | 'post__in' => $query, |
| 75 | 75 | 'orderby' => 'post__in', |
| 76 | 76 | 'nopaging' => true |
| 77 | - ) ); |
|
| 77 | + )); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - public static function get_query_from_string( $string = '' ) { |
|
| 80 | + public static function get_query_from_string($string = '') { |
|
| 81 | 81 | $post_type = false; |
| 82 | 82 | |
| 83 | - if ( is_string( $string ) && strstr( $string, '#' ) ) { |
|
| 83 | + if ( is_string($string) && strstr($string, '#') ) { |
|
| 84 | 84 | //we have a post_type directive here |
| 85 | - list( $post_type, $string ) = explode( '#', $string ); |
|
| 85 | + list($post_type, $string) = explode('#', $string); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | $query = array( |
| 89 | - 'post_type' => ( $post_type ) ? $post_type : 'any' |
|
| 89 | + 'post_type' => ($post_type) ? $post_type : 'any' |
|
| 90 | 90 | ); |
| 91 | 91 | |
| 92 | - if ( is_numeric( $string ) ) { |
|
| 92 | + if ( is_numeric($string) ) { |
|
| 93 | 93 | $query['p'] = $string; |
| 94 | 94 | |
| 95 | 95 | } else { |
| 96 | 96 | $query['name'] = $string; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - return new WP_Query( $query ); |
|
| 99 | + return new WP_Query($query); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | // |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | |
| 115 | 115 | // Sets up the global post, but also return the post, for use in Twig template |
| 116 | 116 | $posts_class = $this->_posts_class; |
| 117 | - return new $posts_class( $post ); |
|
| 117 | + return new $posts_class($post); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -131,10 +131,10 @@ discard block |
||
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 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'] ); |
|
| 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 | 138 | } |
| 139 | 139 | return $query; |
| 140 | 140 | } |
@@ -144,8 +144,8 @@ discard block |
||
| 144 | 144 | * @param WP_Query $query the original query recived from WordPress |
| 145 | 145 | * @return WP_Query |
| 146 | 146 | */ |
| 147 | - static function handle_maybe_custom_posts_page( $query ) { |
|
| 148 | - if ($custom_posts_page = get_option('page_for_posts')) { |
|
| 147 | + static function handle_maybe_custom_posts_page($query) { |
|
| 148 | + if ( $custom_posts_page = get_option('page_for_posts') ) { |
|
| 149 | 149 | if ( isset($query->query['p']) && $query->query['p'] == $custom_posts_page ) { |
| 150 | 150 | return new WP_Query(array('post_type' => 'post')); |
| 151 | 151 | } |
@@ -1,7 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly |
| 3 | -if ( !defined( 'ABSPATH' ) ) |
|
| 3 | +if ( !defined( 'ABSPATH' ) ) { |
|
| 4 | 4 | exit; |
| 5 | +} |
|
| 5 | 6 | |
| 6 | 7 | class TimberQueryIterator implements Iterator { |
| 7 | 8 | |
@@ -15,8 +16,9 @@ discard block |
||
| 15 | 16 | |
| 16 | 17 | public function __construct( $query = false, $posts_class = 'TimberPost' ) { |
| 17 | 18 | add_action( 'pre_get_posts', array($this, 'fix_number_posts_wp_quirk' )); |
| 18 | - if ( $posts_class ) |
|
| 19 | - $this->_posts_class = $posts_class; |
|
| 19 | + if ( $posts_class ) { |
|
| 20 | + $this->_posts_class = $posts_class; |
|
| 21 | + } |
|
| 20 | 22 | |
| 21 | 23 | if ( is_a( $query, 'WP_Query' ) ) { |
| 22 | 24 | // We got a full-fledged WP Query, look no further! |
@@ -55,7 +57,7 @@ discard block |
||
| 55 | 57 | } |
| 56 | 58 | |
| 57 | 59 | public function get_posts( $return_collection = false ) { |
| 58 | - if (isset($this->_query->posts)){ |
|
| 60 | + if (isset($this->_query->posts)) { |
|
| 59 | 61 | $posts = new TimberPostsCollection( $this->_query->posts, $this->_posts_class ); |
| 60 | 62 | return ( $return_collection ) ? $posts : $posts->get_posts(); |
| 61 | 63 | } |
@@ -65,8 +67,9 @@ discard block |
||
| 65 | 67 | // GET POSTS |
| 66 | 68 | // |
| 67 | 69 | public static function get_query_from_array_of_ids( $query = array() ) { |
| 68 | - if ( !is_array( $query ) || !count( $query ) ) |
|
| 69 | - return null; |
|
| 70 | + if ( !is_array( $query ) || !count( $query ) ) { |
|
| 71 | + return null; |
|
| 72 | + } |
|
| 70 | 73 | |
| 71 | 74 | return new WP_Query( array( |
| 72 | 75 | 'post_type'=> 'any', |
@@ -64,7 +64,7 @@ |
||
| 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 | /** |
@@ -101,10 +101,10 @@ discard block |
||
| 101 | 101 | * ``` |
| 102 | 102 | * @param string|int $site_name_or_id |
| 103 | 103 | */ |
| 104 | - function __construct( $site_name_or_id = null ) { |
|
| 104 | + function __construct($site_name_or_id = null) { |
|
| 105 | 105 | $this->init(); |
| 106 | 106 | if ( is_multisite() ) { |
| 107 | - $this->init_as_multisite( $site_name_or_id ); |
|
| 107 | + $this->init_as_multisite($site_name_or_id); |
|
| 108 | 108 | } else { |
| 109 | 109 | $this->init_as_singlesite(); |
| 110 | 110 | } |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | * @internal |
| 115 | 115 | * @param string|int $site_name_or_id |
| 116 | 116 | */ |
| 117 | - protected function init_as_multisite( $site_name_or_id ) { |
|
| 117 | + protected function init_as_multisite($site_name_or_id) { |
|
| 118 | 118 | if ( $site_name_or_id === null ) { |
| 119 | 119 | //this is necessary for some reason, otherwise returns 1 all the time |
| 120 | 120 | if ( is_multisite() ) { |
@@ -122,17 +122,17 @@ discard block |
||
| 122 | 122 | $site_name_or_id = get_current_blog_id(); |
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | - $info = get_blog_details( $site_name_or_id ); |
|
| 126 | - $this->import( $info ); |
|
| 125 | + $info = get_blog_details($site_name_or_id); |
|
| 126 | + $this->import($info); |
|
| 127 | 127 | $this->ID = $info->blog_id; |
| 128 | 128 | $this->id = $this->ID; |
| 129 | 129 | $this->name = $this->blogname; |
| 130 | 130 | $this->title = $this->blogname; |
| 131 | 131 | $this->url = $this->siteurl; |
| 132 | - $theme_slug = get_blog_option( $info->blog_id, 'stylesheet' ); |
|
| 133 | - $this->theme = new TimberTheme( $theme_slug ); |
|
| 134 | - $this->description = get_blog_option( $info->blog_id, 'blogdescription' ); |
|
| 135 | - $this->admin_email = get_blog_option( $info->blog_id, 'admin_email' ); |
|
| 132 | + $theme_slug = get_blog_option($info->blog_id, 'stylesheet'); |
|
| 133 | + $this->theme = new TimberTheme($theme_slug); |
|
| 134 | + $this->description = get_blog_option($info->blog_id, 'blogdescription'); |
|
| 135 | + $this->admin_email = get_blog_option($info->blog_id, 'admin_email'); |
|
| 136 | 136 | $this->multisite = true; |
| 137 | 137 | } |
| 138 | 138 | |
@@ -141,13 +141,13 @@ discard block |
||
| 141 | 141 | * @internal |
| 142 | 142 | */ |
| 143 | 143 | protected function init_as_singlesite() { |
| 144 | - $this->admin_email = get_bloginfo( 'admin_email' ); |
|
| 145 | - $this->name = get_bloginfo( 'name' ); |
|
| 144 | + $this->admin_email = get_bloginfo('admin_email'); |
|
| 145 | + $this->name = get_bloginfo('name'); |
|
| 146 | 146 | $this->title = $this->name; |
| 147 | - $this->description = get_bloginfo( 'description' ); |
|
| 148 | - $this->url = get_bloginfo( 'url' ); |
|
| 147 | + $this->description = get_bloginfo('description'); |
|
| 148 | + $this->url = get_bloginfo('url'); |
|
| 149 | 149 | $this->theme = new TimberTheme(); |
| 150 | - $this->language_attributes = TimberHelper::function_wrapper( 'language_attributes' ); |
|
| 150 | + $this->language_attributes = TimberHelper::function_wrapper('language_attributes'); |
|
| 151 | 151 | $this->multisite = false; |
| 152 | 152 | } |
| 153 | 153 | |
@@ -156,16 +156,16 @@ discard block |
||
| 156 | 156 | * @internal |
| 157 | 157 | */ |
| 158 | 158 | protected function init() { |
| 159 | - $this->rdf = get_bloginfo( 'rdf_url' ); |
|
| 160 | - $this->rss = get_bloginfo( 'rss_url' ); |
|
| 161 | - $this->rss2 = get_bloginfo( 'rss2_url' ); |
|
| 162 | - $this->atom = get_bloginfo( 'atom_url' ); |
|
| 163 | - $this->language = get_bloginfo( 'language' ); |
|
| 164 | - $this->charset = get_bloginfo( 'charset' ); |
|
| 165 | - $this->pingback = get_bloginfo( 'pingback_url' ); |
|
| 166 | - $this->language_attributes = TimberHelper::function_wrapper( 'language_attributes' ); |
|
| 159 | + $this->rdf = get_bloginfo('rdf_url'); |
|
| 160 | + $this->rss = get_bloginfo('rss_url'); |
|
| 161 | + $this->rss2 = get_bloginfo('rss2_url'); |
|
| 162 | + $this->atom = get_bloginfo('atom_url'); |
|
| 163 | + $this->language = get_bloginfo('language'); |
|
| 164 | + $this->charset = get_bloginfo('charset'); |
|
| 165 | + $this->pingback = get_bloginfo('pingback_url'); |
|
| 166 | + $this->language_attributes = TimberHelper::function_wrapper('language_attributes'); |
|
| 167 | 167 | /* deprecated benath this comment */ |
| 168 | - $this->pingback_url = get_bloginfo( 'pingback_url' ); |
|
| 168 | + $this->pingback_url = get_bloginfo('pingback_url'); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | /** |
@@ -174,12 +174,12 @@ discard block |
||
| 174 | 174 | * @param string $field |
| 175 | 175 | * @return mixed |
| 176 | 176 | */ |
| 177 | - function __get( $field ) { |
|
| 178 | - if ( !isset( $this->$field ) ) { |
|
| 177 | + function __get($field) { |
|
| 178 | + if ( !isset($this->$field) ) { |
|
| 179 | 179 | if ( is_multisite() ) { |
| 180 | - $this->$field = get_blog_option( $this->ID, $field ); |
|
| 180 | + $this->$field = get_blog_option($this->ID, $field); |
|
| 181 | 181 | } else { |
| 182 | - $this->$field = get_option( $field ); |
|
| 182 | + $this->$field = get_option($field); |
|
| 183 | 183 | } |
| 184 | 184 | } |
| 185 | 185 | return $this->$field; |
@@ -226,8 +226,8 @@ discard block |
||
| 226 | 226 | /** |
| 227 | 227 | * @ignore |
| 228 | 228 | */ |
| 229 | - public function meta( $field ) { |
|
| 230 | - return $this->__get( $field ); |
|
| 229 | + public function meta($field) { |
|
| 230 | + return $this->__get($field); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -236,12 +236,12 @@ discard block |
||
| 236 | 236 | * @param string $key |
| 237 | 237 | * @param mixed $value |
| 238 | 238 | */ |
| 239 | - public function update( $key, $value ) { |
|
| 240 | - $value = apply_filters( 'timber_site_set_meta', $value, $key, $this->ID, $this ); |
|
| 239 | + public function update($key, $value) { |
|
| 240 | + $value = apply_filters('timber_site_set_meta', $value, $key, $this->ID, $this); |
|
| 241 | 241 | if ( is_multisite() ) { |
| 242 | - update_blog_option( $this->ID, $key, $value ); |
|
| 242 | + update_blog_option($this->ID, $key, $value); |
|
| 243 | 243 | } else { |
| 244 | - update_option( $key, $value ); |
|
| 244 | + update_option($key, $value); |
|
| 245 | 245 | } |
| 246 | 246 | $this->$key = $value; |
| 247 | 247 | } |
@@ -54,11 +54,11 @@ discard block |
||
| 54 | 54 | * @param int $tid |
| 55 | 55 | * @param string $tax |
| 56 | 56 | */ |
| 57 | - public function __construct( $tid = null, $tax = '' ) { |
|
| 58 | - if ($tid === null) { |
|
| 57 | + public function __construct($tid = null, $tax = '') { |
|
| 58 | + if ( $tid === null ) { |
|
| 59 | 59 | $tid = $this->get_term_from_query(); |
| 60 | 60 | } |
| 61 | - if (strlen($tax)) { |
|
| 61 | + if ( strlen($tax) ) { |
|
| 62 | 62 | $this->taxonomy = $tax; |
| 63 | 63 | } |
| 64 | 64 | $this->init($tid); |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | * |
| 78 | 78 | * @return static |
| 79 | 79 | */ |
| 80 | - public static function from( $tid, $taxonomy ) { |
|
| 80 | + public static function from($tid, $taxonomy) { |
|
| 81 | 81 | return new static($tid, $taxonomy); |
| 82 | 82 | } |
| 83 | 83 | |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | global $wp_query; |
| 94 | 94 | if ( isset($wp_query->queried_object) ) { |
| 95 | 95 | $qo = $wp_query->queried_object; |
| 96 | - if (isset($qo->term_id)) { |
|
| 96 | + if ( isset($qo->term_id) ) { |
|
| 97 | 97 | return $qo->term_id; |
| 98 | 98 | } |
| 99 | 99 | } |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | * @internal |
| 107 | 107 | * @param int $tid |
| 108 | 108 | */ |
| 109 | - protected function init( $tid ) { |
|
| 109 | + protected function init($tid) { |
|
| 110 | 110 | $term = $this->get_term($tid); |
| 111 | 111 | if ( isset($term->id) ) { |
| 112 | 112 | $term->ID = $term->id; |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | //echo 'bad call using '.$tid; |
| 117 | 117 | //TimberHelper::error_log(debug_backtrace()); |
| 118 | 118 | } |
| 119 | - if ( isset($term->ID) ){ |
|
| 119 | + if ( isset($term->ID) ) { |
|
| 120 | 120 | $term->id = $term->ID; |
| 121 | 121 | $this->import($term); |
| 122 | 122 | if ( isset($term->term_id) ) { |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | * @param int $tid |
| 143 | 143 | * @return mixed |
| 144 | 144 | */ |
| 145 | - protected function get_term( $tid ) { |
|
| 145 | + protected function get_term($tid) { |
|
| 146 | 146 | if ( is_object($tid) || is_array($tid) ) { |
| 147 | 147 | return $tid; |
| 148 | 148 | } |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | global $wpdb; |
| 155 | 155 | $query = $wpdb->prepare("SELECT taxonomy FROM $wpdb->term_taxonomy WHERE term_id = %d LIMIT 1", $tid); |
| 156 | 156 | $tax = $wpdb->get_var($query); |
| 157 | - if (isset($tax) && strlen($tax)) { |
|
| 157 | + if ( isset($tax) && strlen($tax) ) { |
|
| 158 | 158 | $this->taxonomy = $tax; |
| 159 | 159 | return get_term($tid, $tax); |
| 160 | 160 | } |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | * @param int $tid |
| 168 | 168 | * @return int |
| 169 | 169 | */ |
| 170 | - protected function get_tid( $tid ) { |
|
| 170 | + protected function get_tid($tid) { |
|
| 171 | 171 | global $wpdb; |
| 172 | 172 | if ( is_numeric($tid) ) { |
| 173 | 173 | return $tid; |
@@ -205,8 +205,8 @@ discard block |
||
| 205 | 205 | * @param string $field_name |
| 206 | 206 | * @return string |
| 207 | 207 | */ |
| 208 | - public function get_meta_field( $field_name ) { |
|
| 209 | - if (!isset($this->$field_name)) { |
|
| 208 | + public function get_meta_field($field_name) { |
|
| 209 | + if ( !isset($this->$field_name) ) { |
|
| 210 | 210 | $field_value = ''; |
| 211 | 211 | $field_value = apply_filters('timber_term_get_meta_field', $field_value, $this->ID, $field_name, $this); |
| 212 | 212 | $field_value = apply_filters('timber/term/meta/field', $field_value, $this->ID, $field_name, $this); |
@@ -244,8 +244,8 @@ discard block |
||
| 244 | 244 | * @param string $PostClass |
| 245 | 245 | * @return array|bool|null |
| 246 | 246 | */ |
| 247 | - public function get_posts( $numberposts = 10, $post_type = 'any', $PostClass = '' ) { |
|
| 248 | - if (!strlen($PostClass)) { |
|
| 247 | + public function get_posts($numberposts = 10, $post_type = 'any', $PostClass = '') { |
|
| 248 | + if ( !strlen($PostClass) ) { |
|
| 249 | 249 | $PostClass = $this->PostClass; |
| 250 | 250 | } |
| 251 | 251 | $default_tax_query = array(array( |
@@ -259,10 +259,10 @@ discard block |
||
| 259 | 259 | parse_str($args, $new_args); |
| 260 | 260 | $args = $new_args; |
| 261 | 261 | $args['tax_query'] = $default_tax_query; |
| 262 | - if (!isset($args['post_type'])) { |
|
| 262 | + if ( !isset($args['post_type']) ) { |
|
| 263 | 263 | $args['post_type'] = 'any'; |
| 264 | 264 | } |
| 265 | - if (class_exists($post_type)) { |
|
| 265 | + if ( class_exists($post_type) ) { |
|
| 266 | 266 | $PostClass = $post_type; |
| 267 | 267 | } |
| 268 | 268 | } else if ( is_array($numberposts) ) { |
@@ -308,8 +308,8 @@ discard block |
||
| 308 | 308 | * @param string $key |
| 309 | 309 | * @param mixed $value |
| 310 | 310 | */ |
| 311 | - function update( $key, $value ) { |
|
| 312 | - $value = apply_filters( 'timber_term_set_meta', $value, $key, $this->ID, $this ); |
|
| 311 | + function update($key, $value) { |
|
| 312 | + $value = apply_filters('timber_term_set_meta', $value, $key, $this->ID, $this); |
|
| 313 | 313 | $this->$key = $value; |
| 314 | 314 | } |
| 315 | 315 | |
@@ -331,11 +331,11 @@ discard block |
||
| 331 | 331 | public function description() { |
| 332 | 332 | $prefix = '<p>'; |
| 333 | 333 | $suffix = '</p>'; |
| 334 | - $desc = term_description( $this->ID, $this->taxonomy ); |
|
| 335 | - if (substr($desc, 0, strlen($prefix)) == $prefix) { |
|
| 334 | + $desc = term_description($this->ID, $this->taxonomy); |
|
| 335 | + if ( substr($desc, 0, strlen($prefix)) == $prefix ) { |
|
| 336 | 336 | $desc = substr($desc, strlen($prefix)); |
| 337 | 337 | } |
| 338 | - $desc = preg_replace('/'. preg_quote('</p>', '/') . '$/', '', $desc); |
|
| 338 | + $desc = preg_replace('/' . preg_quote('</p>', '/') . '$/', '', $desc); |
|
| 339 | 339 | return trim($desc); |
| 340 | 340 | } |
| 341 | 341 | |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | * @param string $field_name |
| 370 | 370 | * @return string |
| 371 | 371 | */ |
| 372 | - public function meta( $field_name ) { |
|
| 372 | + public function meta($field_name) { |
|
| 373 | 373 | return $this->get_meta_field($field_name); |
| 374 | 374 | } |
| 375 | 375 | |
@@ -397,7 +397,7 @@ discard block |
||
| 397 | 397 | * ``` |
| 398 | 398 | * @return array|bool|null |
| 399 | 399 | */ |
| 400 | - public function posts( $numberposts_or_args = 10, $post_type_or_class = 'any', $post_class = '' ) { |
|
| 400 | + public function posts($numberposts_or_args = 10, $post_type_or_class = 'any', $post_class = '') { |
|
| 401 | 401 | return $this->get_posts($numberposts_or_args, $post_type_or_class, $post_class); |
| 402 | 402 | } |
| 403 | 403 | |
@@ -422,7 +422,7 @@ discard block |
||
| 422 | 422 | * @param int $i |
| 423 | 423 | * @return string |
| 424 | 424 | */ |
| 425 | - function get_page( $i ) { |
|
| 425 | + function get_page($i) { |
|
| 426 | 426 | return $this->get_path() . '/page/' . $i; |
| 427 | 427 | } |
| 428 | 428 | |
@@ -116,7 +116,7 @@ |
||
| 116 | 116 | //echo 'bad call using '.$tid; |
| 117 | 117 | //TimberHelper::error_log(debug_backtrace()); |
| 118 | 118 | } |
| 119 | - if ( isset($term->ID) ){ |
|
| 119 | + if ( isset($term->ID) ) { |
|
| 120 | 120 | $term->id = $term->ID; |
| 121 | 121 | $this->import($term); |
| 122 | 122 | if ( isset($term->term_id) ) { |
@@ -1,35 +1,35 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Terms: WordPress has got 'em, you want 'em. Categories. Tags. Custom Taxonomies. You don't care, you're a fiend. Well let's get this under control |
|
| 4 | - * @example |
|
| 5 | - * ```php |
|
| 6 | - * //Get a term by its ID |
|
| 7 | - * $context['term'] = new TimberTerm(6); |
|
| 8 | - * //Get a term when on a term archive page |
|
| 9 | - * $context['term_page'] = new TimberTerm(); |
|
| 10 | - * //Get a term with a slug |
|
| 11 | - * $context['team'] = new TimberTerm('patriots'); |
|
| 12 | - * //Get a team with a slug from a specific taxonomy |
|
| 13 | - * $context['st_louis'] = new TimberTerm('cardinals', 'baseball'); |
|
| 14 | - * Timber::render('index.twig', $context); |
|
| 15 | - * ``` |
|
| 16 | - * ```twig |
|
| 17 | - * <h2>{{term_page.name}} Archives</h2> |
|
| 18 | - * <h3>Teams</h3> |
|
| 19 | - * <ul> |
|
| 20 | - * <li>{{st_louis.name}} - {{st_louis.description}}</li> |
|
| 21 | - * <li>{{team.name}} - {{team.description}}</li> |
|
| 22 | - * </ul> |
|
| 23 | - * ``` |
|
| 24 | - * ```html |
|
| 25 | - * <h2>Team Archives</h2> |
|
| 26 | - * <h3>Teams</h3> |
|
| 27 | - * <ul> |
|
| 28 | - * <li>St. Louis Cardinals - Winner of 11 World Series</li> |
|
| 29 | - * <li>New England Patriots - Winner of 4 Super Bowls</li> |
|
| 30 | - * </ul> |
|
| 31 | - * ``` |
|
| 32 | - */ |
|
| 3 | + * Terms: WordPress has got 'em, you want 'em. Categories. Tags. Custom Taxonomies. You don't care, you're a fiend. Well let's get this under control |
|
| 4 | + * @example |
|
| 5 | + * ```php |
|
| 6 | + * //Get a term by its ID |
|
| 7 | + * $context['term'] = new TimberTerm(6); |
|
| 8 | + * //Get a term when on a term archive page |
|
| 9 | + * $context['term_page'] = new TimberTerm(); |
|
| 10 | + * //Get a term with a slug |
|
| 11 | + * $context['team'] = new TimberTerm('patriots'); |
|
| 12 | + * //Get a team with a slug from a specific taxonomy |
|
| 13 | + * $context['st_louis'] = new TimberTerm('cardinals', 'baseball'); |
|
| 14 | + * Timber::render('index.twig', $context); |
|
| 15 | + * ``` |
|
| 16 | + * ```twig |
|
| 17 | + * <h2>{{term_page.name}} Archives</h2> |
|
| 18 | + * <h3>Teams</h3> |
|
| 19 | + * <ul> |
|
| 20 | + * <li>{{st_louis.name}} - {{st_louis.description}}</li> |
|
| 21 | + * <li>{{team.name}} - {{team.description}}</li> |
|
| 22 | + * </ul> |
|
| 23 | + * ``` |
|
| 24 | + * ```html |
|
| 25 | + * <h2>Team Archives</h2> |
|
| 26 | + * <h3>Teams</h3> |
|
| 27 | + * <ul> |
|
| 28 | + * <li>St. Louis Cardinals - Winner of 11 World Series</li> |
|
| 29 | + * <li>New England Patriots - Winner of 4 Super Bowls</li> |
|
| 30 | + * </ul> |
|
| 31 | + * ``` |
|
| 32 | + */ |
|
| 33 | 33 | class TimberTerm extends TimberCore implements TimberCoreInterface { |
| 34 | 34 | |
| 35 | 35 | public $PostClass = 'TimberPost'; |
@@ -333,7 +333,7 @@ discard block |
||
| 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); |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | $ss = $data->get_stylesheet(); |
| 77 | 77 | $this->slug = $ss; |
| 78 | 78 | |
| 79 | - if ( ! function_exists( 'get_home_path' ) ) { |
|
| 79 | + if ( !function_exists('get_home_path') ) { |
|
| 80 | 80 | require_once(ABSPATH . 'wp-admin/includes/file.php'); |
| 81 | 81 | } |
| 82 | 82 | |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | * @return string the relative path to the theme (ex: `/wp-content/themes/my-timber-theme`) |
| 104 | 104 | */ |
| 105 | 105 | public function path() { |
| 106 | - return TimberURLHelper::get_rel_url( $this->link() ); |
|
| 106 | + return TimberURLHelper::get_rel_url($this->link()); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -12,8 +12,8 @@ discard block |
||
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | function __construct() { |
| 15 | - add_action( 'timber/twig/filters', array( $this, 'add_timber_filters_deprecated' ) ); |
|
| 16 | - add_action( 'timber/twig/filters', array( $this, 'add_timber_filters' ) ); |
|
| 15 | + add_action('timber/twig/filters', array($this, 'add_timber_filters_deprecated')); |
|
| 16 | + add_action('timber/twig/filters', array($this, 'add_timber_filters')); |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | /** |
@@ -23,14 +23,14 @@ discard block |
||
| 23 | 23 | * @deprecated since 0.20.7 |
| 24 | 24 | * @return Twig_Environment |
| 25 | 25 | */ |
| 26 | - function add_timber_filters_deprecated( $twig ) { |
|
| 27 | - $twig->addFilter( new Twig_SimpleFilter( 'get_src_from_attachment_id', 'twig_get_src_from_attachment_id' ) ); |
|
| 28 | - $twig->addFilter( new Twig_SimpleFilter( 'wp_body_class', array( $this, 'body_class' ) ) ); |
|
| 29 | - $twig->addFilter( new Twig_SimpleFilter( 'twitterify', array( 'TimberHelper', 'twitterify' ) ) ); |
|
| 30 | - $twig->addFilter( new Twig_SimpleFilter( 'twitterfy', array( 'TimberHelper', 'twitterify' ) ) ); |
|
| 31 | - $twig->addFilter( new Twig_SimpleFilter( 'string', function($arr, $glue = ' '){ |
|
| 26 | + function add_timber_filters_deprecated($twig) { |
|
| 27 | + $twig->addFilter(new Twig_SimpleFilter('get_src_from_attachment_id', 'twig_get_src_from_attachment_id')); |
|
| 28 | + $twig->addFilter(new Twig_SimpleFilter('wp_body_class', array($this, 'body_class'))); |
|
| 29 | + $twig->addFilter(new Twig_SimpleFilter('twitterify', array('TimberHelper', 'twitterify'))); |
|
| 30 | + $twig->addFilter(new Twig_SimpleFilter('twitterfy', array('TimberHelper', 'twitterify'))); |
|
| 31 | + $twig->addFilter(new Twig_SimpleFilter('string', function($arr, $glue = ' ') { |
|
| 32 | 32 | return twig_join_filter($arr, $glue); |
| 33 | - } ) ); |
|
| 33 | + } )); |
|
| 34 | 34 | return $twig; |
| 35 | 35 | } |
| 36 | 36 | |
@@ -40,151 +40,151 @@ discard block |
||
| 40 | 40 | * @param Twig_Environment $twig |
| 41 | 41 | * @return Twig_Environment |
| 42 | 42 | */ |
| 43 | - function add_timber_filters( $twig ) { |
|
| 43 | + function add_timber_filters($twig) { |
|
| 44 | 44 | /* image filters */ |
| 45 | - $twig->addFilter( new Twig_SimpleFilter( 'resize', array( 'TimberImageHelper', 'resize' ) ) ); |
|
| 46 | - $twig->addFilter( new Twig_SimpleFilter( 'retina', array( 'TimberImageHelper', 'retina_resize' ) ) ); |
|
| 47 | - $twig->addFilter( new Twig_SimpleFilter( 'letterbox', array( 'TimberImageHelper', 'letterbox' ) ) ); |
|
| 48 | - $twig->addFilter( new Twig_SimpleFilter( 'tojpg', array( 'TimberImageHelper', 'img_to_jpg' ) ) ); |
|
| 45 | + $twig->addFilter(new Twig_SimpleFilter('resize', array('TimberImageHelper', 'resize'))); |
|
| 46 | + $twig->addFilter(new Twig_SimpleFilter('retina', array('TimberImageHelper', 'retina_resize'))); |
|
| 47 | + $twig->addFilter(new Twig_SimpleFilter('letterbox', array('TimberImageHelper', 'letterbox'))); |
|
| 48 | + $twig->addFilter(new Twig_SimpleFilter('tojpg', array('TimberImageHelper', 'img_to_jpg'))); |
|
| 49 | 49 | |
| 50 | 50 | /* debugging filters */ |
| 51 | - $twig->addFilter( new Twig_SimpleFilter( 'docs', 'twig_object_docs' ) ); |
|
| 52 | - $twig->addFilter( new Twig_SimpleFilter( 'get_class', 'get_class' ) ); |
|
| 53 | - $twig->addFilter( new Twig_SimpleFilter( 'get_type', 'get_type' ) ); |
|
| 54 | - $twig->addFilter( new Twig_SimpleFilter( 'print_r', function( $arr ) { |
|
| 55 | - return print_r( $arr, true ); |
|
| 56 | - } ) ); |
|
| 57 | - $twig->addFilter( new Twig_SimpleFilter( 'print_a', function( $arr ) { |
|
| 58 | - return '<pre>' . self::object_docs( $arr, true ) . '</pre>'; |
|
| 59 | - } ) ); |
|
| 51 | + $twig->addFilter(new Twig_SimpleFilter('docs', 'twig_object_docs')); |
|
| 52 | + $twig->addFilter(new Twig_SimpleFilter('get_class', 'get_class')); |
|
| 53 | + $twig->addFilter(new Twig_SimpleFilter('get_type', 'get_type')); |
|
| 54 | + $twig->addFilter(new Twig_SimpleFilter('print_r', function($arr) { |
|
| 55 | + return print_r($arr, true); |
|
| 56 | + } )); |
|
| 57 | + $twig->addFilter(new Twig_SimpleFilter('print_a', function($arr) { |
|
| 58 | + return '<pre>' . self::object_docs($arr, true) . '</pre>'; |
|
| 59 | + } )); |
|
| 60 | 60 | |
| 61 | 61 | /* other filters */ |
| 62 | - $twig->addFilter( new Twig_SimpleFilter( 'stripshortcodes', 'strip_shortcodes' ) ); |
|
| 63 | - $twig->addFilter( new Twig_SimpleFilter( 'array', array( $this, 'to_array' ) ) ); |
|
| 64 | - $twig->addFilter( new Twig_SimpleFilter( 'excerpt', 'wp_trim_words' ) ); |
|
| 65 | - $twig->addFilter( new Twig_SimpleFilter( 'function', array( $this, 'exec_function' ) ) ); |
|
| 66 | - $twig->addFilter( new Twig_SimpleFilter( 'pretags', array( $this, 'twig_pretags' ) ) ); |
|
| 67 | - $twig->addFilter( new Twig_SimpleFilter( 'sanitize', 'sanitize_title' ) ); |
|
| 68 | - $twig->addFilter( new Twig_SimpleFilter( 'shortcodes', 'do_shortcode' ) ); |
|
| 69 | - $twig->addFilter( new Twig_SimpleFilter( 'time_ago', array( $this, 'time_ago' ) ) ); |
|
| 70 | - $twig->addFilter( new Twig_SimpleFilter( 'wpautop', 'wpautop' ) ); |
|
| 71 | - $twig->addFilter( new Twig_SimpleFilter( 'list', array( $this, 'add_list_separators' ) ) ); |
|
| 72 | - |
|
| 73 | - $twig->addFilter( new Twig_SimpleFilter( 'relative', function ( $link ) { |
|
| 74 | - return TimberURLHelper::get_rel_url( $link, true ); |
|
| 75 | - } ) ); |
|
| 76 | - |
|
| 77 | - $twig->addFilter( new Twig_SimpleFilter( 'date', array( $this, 'intl_date' ) ) ); |
|
| 78 | - |
|
| 79 | - $twig->addFilter( new Twig_SimpleFilter( 'truncate', function ( $text, $len ) { |
|
| 80 | - return TimberHelper::trim_words( $text, $len ); |
|
| 81 | - } ) ); |
|
| 62 | + $twig->addFilter(new Twig_SimpleFilter('stripshortcodes', 'strip_shortcodes')); |
|
| 63 | + $twig->addFilter(new Twig_SimpleFilter('array', array($this, 'to_array'))); |
|
| 64 | + $twig->addFilter(new Twig_SimpleFilter('excerpt', 'wp_trim_words')); |
|
| 65 | + $twig->addFilter(new Twig_SimpleFilter('function', array($this, 'exec_function'))); |
|
| 66 | + $twig->addFilter(new Twig_SimpleFilter('pretags', array($this, 'twig_pretags'))); |
|
| 67 | + $twig->addFilter(new Twig_SimpleFilter('sanitize', 'sanitize_title')); |
|
| 68 | + $twig->addFilter(new Twig_SimpleFilter('shortcodes', 'do_shortcode')); |
|
| 69 | + $twig->addFilter(new Twig_SimpleFilter('time_ago', array($this, 'time_ago'))); |
|
| 70 | + $twig->addFilter(new Twig_SimpleFilter('wpautop', 'wpautop')); |
|
| 71 | + $twig->addFilter(new Twig_SimpleFilter('list', array($this, 'add_list_separators'))); |
|
| 72 | + |
|
| 73 | + $twig->addFilter(new Twig_SimpleFilter('relative', function($link) { |
|
| 74 | + return TimberURLHelper::get_rel_url($link, true); |
|
| 75 | + } )); |
|
| 76 | + |
|
| 77 | + $twig->addFilter(new Twig_SimpleFilter('date', array($this, 'intl_date'))); |
|
| 78 | + |
|
| 79 | + $twig->addFilter(new Twig_SimpleFilter('truncate', function($text, $len) { |
|
| 80 | + return TimberHelper::trim_words($text, $len); |
|
| 81 | + } )); |
|
| 82 | 82 | |
| 83 | 83 | /* actions and filters */ |
| 84 | - $twig->addFunction( new Twig_SimpleFunction( 'action', function ( $context ) { |
|
| 84 | + $twig->addFunction(new Twig_SimpleFunction('action', function($context) { |
|
| 85 | 85 | $args = func_get_args(); |
| 86 | - array_shift( $args ); |
|
| 86 | + array_shift($args); |
|
| 87 | 87 | $args[] = $context; |
| 88 | - call_user_func_array( 'do_action', $args ); |
|
| 89 | - }, array( 'needs_context' => true ) ) ); |
|
| 88 | + call_user_func_array('do_action', $args); |
|
| 89 | + }, array('needs_context' => true))); |
|
| 90 | 90 | |
| 91 | - $twig->addFilter( new Twig_SimpleFilter( 'apply_filters', function () { |
|
| 91 | + $twig->addFilter(new Twig_SimpleFilter('apply_filters', function() { |
|
| 92 | 92 | $args = func_get_args(); |
| 93 | - $tag = current( array_splice( $args, 1, 1 ) ); |
|
| 93 | + $tag = current(array_splice($args, 1, 1)); |
|
| 94 | 94 | |
| 95 | - return apply_filters_ref_array( $tag, $args ); |
|
| 96 | - } ) ); |
|
| 97 | - $twig->addFunction( new Twig_SimpleFunction( 'function', array( &$this, 'exec_function' ) ) ); |
|
| 98 | - $twig->addFunction( new Twig_SimpleFunction( 'fn', array( &$this, 'exec_function' ) ) ); |
|
| 95 | + return apply_filters_ref_array($tag, $args); |
|
| 96 | + } )); |
|
| 97 | + $twig->addFunction(new Twig_SimpleFunction('function', array(&$this, 'exec_function'))); |
|
| 98 | + $twig->addFunction(new Twig_SimpleFunction('fn', array(&$this, 'exec_function'))); |
|
| 99 | 99 | |
| 100 | - $twig->addFunction( new Twig_SimpleFunction( 'shortcode', 'do_shortcode' ) ); |
|
| 100 | + $twig->addFunction(new Twig_SimpleFunction('shortcode', 'do_shortcode')); |
|
| 101 | 101 | |
| 102 | 102 | /* TimberObjects */ |
| 103 | - $twig->addFunction( new Twig_SimpleFunction( 'TimberPost', function ( $pid, $PostClass = 'TimberPost' ) { |
|
| 104 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
| 105 | - foreach ( $pid as &$p ) { |
|
| 106 | - $p = new $PostClass( $p ); |
|
| 103 | + $twig->addFunction(new Twig_SimpleFunction('TimberPost', function($pid, $PostClass = 'TimberPost') { |
|
| 104 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
| 105 | + foreach ($pid as &$p) { |
|
| 106 | + $p = new $PostClass($p); |
|
| 107 | 107 | } |
| 108 | 108 | return $pid; |
| 109 | 109 | } |
| 110 | - return new $PostClass( $pid ); |
|
| 111 | - } ) ); |
|
| 112 | - $twig->addFunction( new Twig_SimpleFunction( 'TimberImage', function ( $pid, $ImageClass = 'TimberImage' ) { |
|
| 113 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
| 114 | - foreach ( $pid as &$p ) { |
|
| 115 | - $p = new $ImageClass( $p ); |
|
| 110 | + return new $PostClass($pid); |
|
| 111 | + } )); |
|
| 112 | + $twig->addFunction(new Twig_SimpleFunction('TimberImage', function($pid, $ImageClass = 'TimberImage') { |
|
| 113 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
| 114 | + foreach ($pid as &$p) { |
|
| 115 | + $p = new $ImageClass($p); |
|
| 116 | 116 | } |
| 117 | 117 | return $pid; |
| 118 | 118 | } |
| 119 | - return new $ImageClass( $pid ); |
|
| 120 | - } ) ); |
|
| 121 | - $twig->addFunction( new Twig_SimpleFunction( 'TimberTerm', function ( $pid, $TermClass = 'TimberTerm' ) { |
|
| 122 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
| 123 | - foreach ( $pid as &$p ) { |
|
| 124 | - $p = new $TermClass( $p ); |
|
| 119 | + return new $ImageClass($pid); |
|
| 120 | + } )); |
|
| 121 | + $twig->addFunction(new Twig_SimpleFunction('TimberTerm', function($pid, $TermClass = 'TimberTerm') { |
|
| 122 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
| 123 | + foreach ($pid as &$p) { |
|
| 124 | + $p = new $TermClass($p); |
|
| 125 | 125 | } |
| 126 | 126 | return $pid; |
| 127 | 127 | } |
| 128 | - return new $TermClass( $pid ); |
|
| 129 | - } ) ); |
|
| 130 | - $twig->addFunction( new Twig_SimpleFunction( 'TimberUser', function ( $pid, $UserClass = 'TimberUser' ) { |
|
| 131 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
| 132 | - foreach ( $pid as &$p ) { |
|
| 133 | - $p = new $UserClass( $p ); |
|
| 128 | + return new $TermClass($pid); |
|
| 129 | + } )); |
|
| 130 | + $twig->addFunction(new Twig_SimpleFunction('TimberUser', function($pid, $UserClass = 'TimberUser') { |
|
| 131 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
| 132 | + foreach ($pid as &$p) { |
|
| 133 | + $p = new $UserClass($p); |
|
| 134 | 134 | } |
| 135 | 135 | return $pid; |
| 136 | 136 | } |
| 137 | - return new $UserClass( $pid ); |
|
| 138 | - } ) ); |
|
| 137 | + return new $UserClass($pid); |
|
| 138 | + } )); |
|
| 139 | 139 | |
| 140 | 140 | /* TimberObjects Alias */ |
| 141 | - $twig->addFunction( new Twig_SimpleFunction( 'Post', function ( $pid, $PostClass = 'TimberPost' ) { |
|
| 142 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
| 143 | - foreach ( $pid as &$p ) { |
|
| 144 | - $p = new $PostClass( $p ); |
|
| 141 | + $twig->addFunction(new Twig_SimpleFunction('Post', function($pid, $PostClass = 'TimberPost') { |
|
| 142 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
| 143 | + foreach ($pid as &$p) { |
|
| 144 | + $p = new $PostClass($p); |
|
| 145 | 145 | } |
| 146 | 146 | return $pid; |
| 147 | 147 | } |
| 148 | - return new $PostClass( $pid ); |
|
| 149 | - } ) ); |
|
| 150 | - $twig->addFunction( new Twig_SimpleFunction( 'Image', function ( $pid, $ImageClass = 'TimberImage' ) { |
|
| 151 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
| 152 | - foreach ( $pid as &$p ) { |
|
| 153 | - $p = new $ImageClass( $p ); |
|
| 148 | + return new $PostClass($pid); |
|
| 149 | + } )); |
|
| 150 | + $twig->addFunction(new Twig_SimpleFunction('Image', function($pid, $ImageClass = 'TimberImage') { |
|
| 151 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
| 152 | + foreach ($pid as &$p) { |
|
| 153 | + $p = new $ImageClass($p); |
|
| 154 | 154 | } |
| 155 | 155 | return $pid; |
| 156 | 156 | } |
| 157 | - return new $ImageClass( $pid ); |
|
| 158 | - } ) ); |
|
| 159 | - $twig->addFunction( new Twig_SimpleFunction( 'Term', function ( $pid, $TermClass = 'TimberTerm' ) { |
|
| 160 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
| 161 | - foreach ( $pid as &$p ) { |
|
| 162 | - $p = new $TermClass( $p ); |
|
| 157 | + return new $ImageClass($pid); |
|
| 158 | + } )); |
|
| 159 | + $twig->addFunction(new Twig_SimpleFunction('Term', function($pid, $TermClass = 'TimberTerm') { |
|
| 160 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
| 161 | + foreach ($pid as &$p) { |
|
| 162 | + $p = new $TermClass($p); |
|
| 163 | 163 | } |
| 164 | 164 | return $pid; |
| 165 | 165 | } |
| 166 | - return new $TermClass( $pid ); |
|
| 167 | - } ) ); |
|
| 168 | - $twig->addFunction( new Twig_SimpleFunction( 'User', function ( $pid, $UserClass = 'TimberUser' ) { |
|
| 169 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
| 170 | - foreach ( $pid as &$p ) { |
|
| 171 | - $p = new $UserClass( $p ); |
|
| 166 | + return new $TermClass($pid); |
|
| 167 | + } )); |
|
| 168 | + $twig->addFunction(new Twig_SimpleFunction('User', function($pid, $UserClass = 'TimberUser') { |
|
| 169 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
| 170 | + foreach ($pid as &$p) { |
|
| 171 | + $p = new $UserClass($p); |
|
| 172 | 172 | } |
| 173 | 173 | return $pid; |
| 174 | 174 | } |
| 175 | - return new $UserClass( $pid ); |
|
| 176 | - } ) ); |
|
| 175 | + return new $UserClass($pid); |
|
| 176 | + } )); |
|
| 177 | 177 | |
| 178 | 178 | /* bloginfo and translate */ |
| 179 | - $twig->addFunction( 'bloginfo', new Twig_SimpleFunction( 'bloginfo', function ( $show = '', $filter = 'raw' ) { |
|
| 180 | - return get_bloginfo( $show, $filter ); |
|
| 181 | - } ) ); |
|
| 182 | - $twig->addFunction( '__', new Twig_SimpleFunction( '__', function ( $text, $domain = 'default' ) { |
|
| 183 | - return __( $text, $domain ); |
|
| 184 | - } ) ); |
|
| 179 | + $twig->addFunction('bloginfo', new Twig_SimpleFunction('bloginfo', function($show = '', $filter = 'raw') { |
|
| 180 | + return get_bloginfo($show, $filter); |
|
| 181 | + } )); |
|
| 182 | + $twig->addFunction('__', new Twig_SimpleFunction('__', function($text, $domain = 'default') { |
|
| 183 | + return __($text, $domain); |
|
| 184 | + } )); |
|
| 185 | 185 | /* get_twig is deprecated, use timber/twig */ |
| 186 | - $twig = apply_filters( 'get_twig', $twig ); |
|
| 187 | - $twig = apply_filters( 'timber/twig', $twig ); |
|
| 186 | + $twig = apply_filters('get_twig', $twig); |
|
| 187 | + $twig = apply_filters('timber/twig', $twig); |
|
| 188 | 188 | return $twig; |
| 189 | 189 | } |
| 190 | 190 | |
@@ -194,11 +194,11 @@ discard block |
||
| 194 | 194 | * @param mixed $arr |
| 195 | 195 | * @return array |
| 196 | 196 | */ |
| 197 | - function to_array( $arr ) { |
|
| 198 | - if ( is_array( $arr ) ) { |
|
| 197 | + function to_array($arr) { |
|
| 198 | + if ( is_array($arr) ) { |
|
| 199 | 199 | return $arr; |
| 200 | 200 | } |
| 201 | - $arr = array( $arr ); |
|
| 201 | + $arr = array($arr); |
|
| 202 | 202 | return $arr; |
| 203 | 203 | } |
| 204 | 204 | |
@@ -208,13 +208,13 @@ discard block |
||
| 208 | 208 | * @param string $function_name |
| 209 | 209 | * @return mixed |
| 210 | 210 | */ |
| 211 | - function exec_function( $function_name ) { |
|
| 211 | + function exec_function($function_name) { |
|
| 212 | 212 | $args = func_get_args(); |
| 213 | - array_shift( $args ); |
|
| 213 | + array_shift($args); |
|
| 214 | 214 | if ( is_string($function_name) ) { |
| 215 | - $function_name = trim( $function_name ); |
|
| 215 | + $function_name = trim($function_name); |
|
| 216 | 216 | } |
| 217 | - return call_user_func_array( $function_name, ( $args ) ); |
|
| 217 | + return call_user_func_array($function_name, ($args)); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | /** |
@@ -223,8 +223,8 @@ discard block |
||
| 223 | 223 | * @param string $content |
| 224 | 224 | * @return string |
| 225 | 225 | */ |
| 226 | - function twig_pretags( $content ) { |
|
| 227 | - return preg_replace_callback( '|<pre.*>(.*)</pre|isU', array( &$this, 'convert_pre_entities' ), $content ); |
|
| 226 | + function twig_pretags($content) { |
|
| 227 | + return preg_replace_callback('|<pre.*>(.*)</pre|isU', array(&$this, 'convert_pre_entities'), $content); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -233,8 +233,8 @@ discard block |
||
| 233 | 233 | * @param array $matches |
| 234 | 234 | * @return string |
| 235 | 235 | */ |
| 236 | - function convert_pre_entities( $matches ) { |
|
| 237 | - return str_replace( $matches[1], htmlentities( $matches[1] ), $matches[0] ); |
|
| 236 | + function convert_pre_entities($matches) { |
|
| 237 | + return str_replace($matches[1], htmlentities($matches[1]), $matches[0]); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -242,12 +242,12 @@ discard block |
||
| 242 | 242 | * @deprecated 0.20.7 |
| 243 | 243 | * @return string |
| 244 | 244 | */ |
| 245 | - function body_class( $body_classes ) { |
|
| 245 | + function body_class($body_classes) { |
|
| 246 | 246 | ob_start(); |
| 247 | - if ( is_array( $body_classes ) ) { |
|
| 248 | - $body_classes = explode( ' ', $body_classes ); |
|
| 247 | + if ( is_array($body_classes) ) { |
|
| 248 | + $body_classes = explode(' ', $body_classes); |
|
| 249 | 249 | } |
| 250 | - body_class( $body_classes ); |
|
| 250 | + body_class($body_classes); |
|
| 251 | 251 | $return = ob_get_contents(); |
| 252 | 252 | ob_end_clean(); |
| 253 | 253 | return $return; |
@@ -260,20 +260,20 @@ discard block |
||
| 260 | 260 | * @param string $format (optional) |
| 261 | 261 | * @return string |
| 262 | 262 | */ |
| 263 | - function intl_date( $date, $format = null ) { |
|
| 263 | + function intl_date($date, $format = null) { |
|
| 264 | 264 | if ( $format === null ) { |
| 265 | - $format = get_option( 'date_format' ); |
|
| 265 | + $format = get_option('date_format'); |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | if ( $date instanceof DateTime ) { |
| 269 | 269 | $timestamp = $date->getTimestamp(); |
| 270 | - } else if (is_numeric( $date ) && strtotime( $date ) === false ) { |
|
| 271 | - $timestamp = intval( $date ); |
|
| 270 | + } else if ( is_numeric($date) && strtotime($date) === false ) { |
|
| 271 | + $timestamp = intval($date); |
|
| 272 | 272 | } else { |
| 273 | - $timestamp = strtotime( $date ); |
|
| 273 | + $timestamp = strtotime($date); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | - return date_i18n( $format, $timestamp ); |
|
| 276 | + return date_i18n($format, $timestamp); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | //debug |
@@ -285,17 +285,17 @@ discard block |
||
| 285 | 285 | * @param bool $methods |
| 286 | 286 | * @return string |
| 287 | 287 | */ |
| 288 | - function object_docs( $obj, $methods = true ) { |
|
| 289 | - $class = get_class( $obj ); |
|
| 290 | - $properties = (array)$obj; |
|
| 288 | + function object_docs($obj, $methods = true) { |
|
| 289 | + $class = get_class($obj); |
|
| 290 | + $properties = (array) $obj; |
|
| 291 | 291 | if ( $methods ) { |
| 292 | 292 | /** @var array $methods */ |
| 293 | 293 | $methods = $obj->get_method_values(); |
| 294 | 294 | } |
| 295 | - $rets = array_merge( $properties, $methods ); |
|
| 296 | - ksort( $rets ); |
|
| 297 | - $str = print_r( $rets, true ); |
|
| 298 | - $str = str_replace( 'Array', $class . ' Object', $str ); |
|
| 295 | + $rets = array_merge($properties, $methods); |
|
| 296 | + ksort($rets); |
|
| 297 | + $str = print_r($rets, true); |
|
| 298 | + $str = str_replace('Array', $class . ' Object', $str); |
|
| 299 | 299 | return $str; |
| 300 | 300 | } |
| 301 | 301 | |
@@ -306,15 +306,15 @@ discard block |
||
| 306 | 306 | * @param string $format_future |
| 307 | 307 | * @return string |
| 308 | 308 | */ |
| 309 | - function time_ago( $from, $to = null, $format_past = '%s ago', $format_future = '%s from now' ) { |
|
| 309 | + function time_ago($from, $to = null, $format_past = '%s ago', $format_future = '%s from now') { |
|
| 310 | 310 | $to = $to === null ? time() : $to; |
| 311 | - $to = is_int( $to ) ? $to : strtotime( $to ); |
|
| 312 | - $from = is_int( $from ) ? $from : strtotime( $from ); |
|
| 311 | + $to = is_int($to) ? $to : strtotime($to); |
|
| 312 | + $from = is_int($from) ? $from : strtotime($from); |
|
| 313 | 313 | |
| 314 | 314 | if ( $from < $to ) { |
| 315 | - return sprintf( $format_past, human_time_diff( $from, $to ) ); |
|
| 315 | + return sprintf($format_past, human_time_diff($from, $to)); |
|
| 316 | 316 | } else { |
| 317 | - return sprintf( $format_future, human_time_diff( $to, $from ) ); |
|
| 317 | + return sprintf($format_future, human_time_diff($to, $from)); |
|
| 318 | 318 | } |
| 319 | 319 | } |
| 320 | 320 | |
@@ -324,18 +324,18 @@ discard block |
||
| 324 | 324 | * @param string $second_delimiter |
| 325 | 325 | * @return string |
| 326 | 326 | */ |
| 327 | - function add_list_separators( $arr, $first_delimiter = ',', $second_delimiter = 'and' ) { |
|
| 328 | - $length = count( $arr ); |
|
| 327 | + function add_list_separators($arr, $first_delimiter = ',', $second_delimiter = 'and') { |
|
| 328 | + $length = count($arr); |
|
| 329 | 329 | $list = ''; |
| 330 | - foreach( $arr as $index => $item ) { |
|
| 330 | + foreach ($arr as $index => $item) { |
|
| 331 | 331 | if ( $index < $length - 2 ) { |
| 332 | - $delimiter = $first_delimiter.' '; |
|
| 332 | + $delimiter = $first_delimiter . ' '; |
|
| 333 | 333 | } elseif ( $index == $length - 2 ) { |
| 334 | - $delimiter = ' '.$second_delimiter.' '; |
|
| 334 | + $delimiter = ' ' . $second_delimiter . ' '; |
|
| 335 | 335 | } else { |
| 336 | 336 | $delimiter = ''; |
| 337 | 337 | } |
| 338 | - $list = $list.$item.$delimiter; |
|
| 338 | + $list = $list . $item . $delimiter; |
|
| 339 | 339 | } |
| 340 | 340 | return $list; |
| 341 | 341 | } |
@@ -75,6 +75,9 @@ discard block |
||
| 75 | 75 | return $image->writeImages($save_filename, true); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | + /** |
|
| 79 | + * @param string $load_filename |
|
| 80 | + */ |
|
| 78 | 81 | protected function get_target_sizes( $load_filename ) { |
| 79 | 82 | $image = wp_get_image_editor( $load_filename ); |
| 80 | 83 | $w = $this->w; |
@@ -142,7 +145,7 @@ discard block |
||
| 142 | 145 | * (ex: /src/var/www/wp-content/uploads/my-pic.jpg) |
| 143 | 146 | * @param string $save_filename filepath (not URL) where result file should be saved |
| 144 | 147 | * (ex: /src/var/www/wp-content/uploads/my-pic-300x200-c-default.jpg) |
| 145 | - * @return bool true if everything went fine, false otherwise |
|
| 148 | + * @return boolean|null true if everything went fine, false otherwise |
|
| 146 | 149 | */ |
| 147 | 150 | public function run($load_filename, $save_filename) { |
| 148 | 151 | //should be resized by gif resizer |
@@ -21,8 +21,8 @@ discard block |
||
| 21 | 21 | $this->w = $w; |
| 22 | 22 | $this->h = $h; |
| 23 | 23 | // Sanitize crop position |
| 24 | - $allowed_crop_positions = array( 'default', 'center', 'top', 'bottom', 'left', 'right', 'top-center', 'bottom-center' ); |
|
| 25 | - if ( $crop !== false && !in_array( $crop, $allowed_crop_positions ) ) { |
|
| 24 | + $allowed_crop_positions = array('default', 'center', 'top', 'bottom', 'left', 'right', 'top-center', 'bottom-center'); |
|
| 25 | + if ( $crop !== false && !in_array($crop, $allowed_crop_positions) ) { |
|
| 26 | 26 | $crop = $allowed_crop_positions[0]; |
| 27 | 27 | } |
| 28 | 28 | $this->crop = $crop; |
@@ -42,9 +42,9 @@ discard block |
||
| 42 | 42 | if ( $this->h ) { |
| 43 | 43 | $h = $this->h; |
| 44 | 44 | } |
| 45 | - $result = $src_filename . '-' . $w . 'x' . $h . '-c-' . ( $this->crop ? $this->crop : 'f' ); // Crop will be either user named or f (false) |
|
| 46 | - if($src_extension) { |
|
| 47 | - $result .= '.'.$src_extension; |
|
| 45 | + $result = $src_filename . '-' . $w . 'x' . $h . '-c-' . ($this->crop ? $this->crop : 'f'); // Crop will be either user named or f (false) |
|
| 46 | + if ( $src_extension ) { |
|
| 47 | + $result .= '.' . $src_extension; |
|
| 48 | 48 | } |
| 49 | 49 | return $result; |
| 50 | 50 | } |
@@ -53,8 +53,8 @@ discard block |
||
| 53 | 53 | * @param string $load_filename |
| 54 | 54 | * @param string $save_filename |
| 55 | 55 | */ |
| 56 | - protected function run_animated_gif( $load_filename, $save_filename ) { |
|
| 57 | - $image = wp_get_image_editor( $load_filename ); |
|
| 56 | + protected function run_animated_gif($load_filename, $save_filename) { |
|
| 57 | + $image = wp_get_image_editor($load_filename); |
|
| 58 | 58 | $current_size = $image->get_size(); |
| 59 | 59 | $src_w = $current_size['width']; |
| 60 | 60 | $src_h = $current_size['height']; |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | } |
| 66 | 66 | $image = new Imagick($load_filename); |
| 67 | 67 | $image = $image->coalesceImages(); |
| 68 | - $crop = self::get_target_sizes( $load_filename ); |
|
| 68 | + $crop = self::get_target_sizes($load_filename); |
|
| 69 | 69 | foreach ($image as $frame) { |
| 70 | 70 | $frame->cropImage($crop['src_w'], $crop['src_h'], $crop['x'], $crop['y']); |
| 71 | 71 | $frame->thumbnailImage($w, $h); |
@@ -75,8 +75,8 @@ discard block |
||
| 75 | 75 | return $image->writeImages($save_filename, true); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - protected function get_target_sizes( $load_filename ) { |
|
| 79 | - $image = wp_get_image_editor( $load_filename ); |
|
| 78 | + protected function get_target_sizes($load_filename) { |
|
| 79 | + $image = wp_get_image_editor($load_filename); |
|
| 80 | 80 | $w = $this->w; |
| 81 | 81 | $h = $this->h; |
| 82 | 82 | $crop = $this->crop; |
@@ -86,11 +86,11 @@ discard block |
||
| 86 | 86 | $src_h = $current_size['height']; |
| 87 | 87 | $src_ratio = $src_w / $src_h; |
| 88 | 88 | if ( !$h ) { |
| 89 | - $h = round( $w / $src_ratio ); |
|
| 89 | + $h = round($w / $src_ratio); |
|
| 90 | 90 | } |
| 91 | 91 | if ( !$w ) { |
| 92 | 92 | //the user wants to resize based on constant height |
| 93 | - $w = round( $h * $src_ratio ); |
|
| 93 | + $w = round($h * $src_ratio); |
|
| 94 | 94 | } |
| 95 | 95 | if ( !$crop ) { |
| 96 | 96 | return array( |
@@ -104,13 +104,13 @@ discard block |
||
| 104 | 104 | $src_wt = $src_h * $dest_ratio; |
| 105 | 105 | $src_ht = $src_w / $dest_ratio; |
| 106 | 106 | $src_x = $src_w / 2 - $src_wt / 2; |
| 107 | - $src_y = ( $src_h - $src_ht ) / 6; |
|
| 107 | + $src_y = ($src_h - $src_ht) / 6; |
|
| 108 | 108 | //now specific overrides based on options: |
| 109 | - switch ( $crop ) { |
|
| 109 | + switch ($crop) { |
|
| 110 | 110 | case 'center': |
| 111 | 111 | // Get source x and y |
| 112 | - $src_x = round( ( $src_w - $src_wt ) / 2 ); |
|
| 113 | - $src_y = round( ( $src_h - $src_ht ) / 2 ); |
|
| 112 | + $src_x = round(($src_w - $src_wt) / 2); |
|
| 113 | + $src_y = round(($src_h - $src_ht) / 2); |
|
| 114 | 114 | break; |
| 115 | 115 | |
| 116 | 116 | case 'top': |
@@ -122,11 +122,11 @@ discard block |
||
| 122 | 122 | break; |
| 123 | 123 | |
| 124 | 124 | case 'top-center': |
| 125 | - $src_y = round( ( $src_h - $src_ht ) / 4 ); |
|
| 125 | + $src_y = round(($src_h - $src_ht) / 4); |
|
| 126 | 126 | break; |
| 127 | 127 | |
| 128 | 128 | case 'bottom-center': |
| 129 | - $src_y = $src_h - $src_ht - round( ( $src_h - $src_ht ) / 4 ); |
|
| 129 | + $src_y = $src_h - $src_ht - round(($src_h - $src_ht) / 4); |
|
| 130 | 130 | break; |
| 131 | 131 | |
| 132 | 132 | case 'left': |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | break; |
| 139 | 139 | } |
| 140 | 140 | // Crop the image |
| 141 | - return ( $dest_ratio > $src_ratio ) |
|
| 141 | + return ($dest_ratio > $src_ratio) |
|
| 142 | 142 | ? array( |
| 143 | 143 | 'x' => 0, 'y' => $src_y, |
| 144 | 144 | 'src_w' => $src_w, 'src_h' => $src_ht, |
@@ -168,35 +168,35 @@ discard block |
||
| 168 | 168 | //return if successful |
| 169 | 169 | //proceed if not |
| 170 | 170 | $gif = self::run_animated_gif($load_filename, $save_filename); |
| 171 | - if ($gif) { |
|
| 171 | + if ( $gif ) { |
|
| 172 | 172 | return true; |
| 173 | 173 | } |
| 174 | 174 | } |
| 175 | - $image = wp_get_image_editor( $load_filename ); |
|
| 176 | - if ( !is_wp_error( $image ) ) { |
|
| 177 | - $crop = self::get_target_sizes( $load_filename ); |
|
| 178 | - $image->crop( $crop['x'], |
|
| 175 | + $image = wp_get_image_editor($load_filename); |
|
| 176 | + if ( !is_wp_error($image) ) { |
|
| 177 | + $crop = self::get_target_sizes($load_filename); |
|
| 178 | + $image->crop($crop['x'], |
|
| 179 | 179 | $crop['y'], |
| 180 | 180 | $crop['src_w'], |
| 181 | 181 | $crop['src_h'], |
| 182 | 182 | $crop['target_w'], |
| 183 | 183 | $crop['target_h'] |
| 184 | 184 | ); |
| 185 | - $result = $image->save( $save_filename ); |
|
| 186 | - if ( is_wp_error( $result ) ) { |
|
| 185 | + $result = $image->save($save_filename); |
|
| 186 | + if ( is_wp_error($result) ) { |
|
| 187 | 187 | // @codeCoverageIgnoreStart |
| 188 | - TimberHelper::error_log( 'Error resizing image' ); |
|
| 189 | - TimberHelper::error_log( $result ); |
|
| 188 | + TimberHelper::error_log('Error resizing image'); |
|
| 189 | + TimberHelper::error_log($result); |
|
| 190 | 190 | return false; |
| 191 | 191 | // @codeCoverageIgnoreEnd |
| 192 | 192 | } else { |
| 193 | 193 | return true; |
| 194 | 194 | } |
| 195 | - } else if ( isset( $image->error_data['error_loading_image'] ) ) { |
|
| 195 | + } else if ( isset($image->error_data['error_loading_image']) ) { |
|
| 196 | 196 | // @codeCoverageIgnoreStart |
| 197 | - TimberHelper::error_log( 'Error loading ' . $image->error_data['error_loading_image'] ); |
|
| 197 | + TimberHelper::error_log('Error loading ' . $image->error_data['error_loading_image']); |
|
| 198 | 198 | } else { |
| 199 | - TimberHelper::error_log( $image ); |
|
| 199 | + TimberHelper::error_log($image); |
|
| 200 | 200 | // @codeCoverageIgnoreEnd |
| 201 | 201 | } |
| 202 | 202 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | function init($cid) { |
| 56 | 56 | $comment_data = $cid; |
| 57 | - if (is_integer($cid)) { |
|
| 57 | + if ( is_integer($cid) ) { |
|
| 58 | 58 | $comment_data = get_comment($cid); |
| 59 | 59 | } |
| 60 | 60 | $this->import($comment_data); |
@@ -86,11 +86,11 @@ discard block |
||
| 86 | 86 | * @return TimberUser |
| 87 | 87 | */ |
| 88 | 88 | public function author() { |
| 89 | - if ($this->user_id) { |
|
| 89 | + if ( $this->user_id ) { |
|
| 90 | 90 | return new TimberUser($this->user_id); |
| 91 | 91 | } else { |
| 92 | 92 | $author = new TimberUser(0); |
| 93 | - if (isset($this->comment_author) && $this->comment_author) { |
|
| 93 | + if ( isset($this->comment_author) && $this->comment_author ) { |
|
| 94 | 94 | $author->name = $this->comment_author; |
| 95 | 95 | } else { |
| 96 | 96 | $author->name = 'Anonymous'; |
@@ -114,21 +114,21 @@ discard block |
||
| 114 | 114 | * @return bool|mixed|string |
| 115 | 115 | */ |
| 116 | 116 | public function avatar($size = 92, $default = '') { |
| 117 | - if (!get_option('show_avatars')) { |
|
| 117 | + if ( !get_option('show_avatars') ) { |
|
| 118 | 118 | return false; |
| 119 | 119 | } |
| 120 | - if (!is_numeric($size)) { |
|
| 120 | + if ( !is_numeric($size) ) { |
|
| 121 | 121 | $size = '92'; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | $email = $this->avatar_email(); |
| 125 | 125 | $email_hash = ''; |
| 126 | - if (!empty($email)) { |
|
| 126 | + if ( !empty($email) ) { |
|
| 127 | 127 | $email_hash = md5(strtolower(trim($email))); |
| 128 | 128 | } |
| 129 | 129 | $host = $this->avatar_host($email_hash); |
| 130 | 130 | $default = $this->avatar_default($default, $email, $size, $host); |
| 131 | - if (!empty($email)) { |
|
| 131 | + if ( !empty($email) ) { |
|
| 132 | 132 | $avatar = $this->avatar_out($default, $host, $email_hash, $size); |
| 133 | 133 | } else { |
| 134 | 134 | $avatar = $default; |
@@ -179,9 +179,9 @@ discard block |
||
| 179 | 179 | * ``` |
| 180 | 180 | * @return string |
| 181 | 181 | */ |
| 182 | - public function date( $date_format = '' ) { |
|
| 182 | + public function date($date_format = '') { |
|
| 183 | 183 | $df = $date_format ? $date_format : get_option('date_format'); |
| 184 | - $the_date = (string)mysql2date($df, $this->comment_date); |
|
| 184 | + $the_date = (string) mysql2date($df, $this->comment_date); |
|
| 185 | 185 | return apply_filters('get_comment_date ', $the_date, $df); |
| 186 | 186 | } |
| 187 | 187 | |
@@ -204,9 +204,9 @@ discard block |
||
| 204 | 204 | * ``` |
| 205 | 205 | * @return string |
| 206 | 206 | */ |
| 207 | - public function time( $time_format = '' ) { |
|
| 207 | + public function time($time_format = '') { |
|
| 208 | 208 | $tf = $time_format ? $time_format : get_option('time_format'); |
| 209 | - $the_time = (string)mysql2date($tf, $this->comment_date); |
|
| 209 | + $the_time = (string) mysql2date($tf, $this->comment_date); |
|
| 210 | 210 | return apply_filters('get_comment_time', $the_time, $tf); |
| 211 | 211 | } |
| 212 | 212 | |
@@ -232,14 +232,14 @@ discard block |
||
| 232 | 232 | * @return mixed |
| 233 | 233 | */ |
| 234 | 234 | protected function get_meta_fields($comment_id = null) { |
| 235 | - if ($comment_id === null) { |
|
| 235 | + if ( $comment_id === null ) { |
|
| 236 | 236 | $comment_id = $this->ID; |
| 237 | 237 | } |
| 238 | 238 | //Could not find a WP function to fetch all comment meta data, so I made one. |
| 239 | 239 | apply_filters('timber_comment_get_meta_pre', array(), $comment_id); |
| 240 | 240 | $comment_metas = get_comment_meta($comment_id); |
| 241 | 241 | foreach ($comment_metas as &$cm) { |
| 242 | - if (is_array($cm) && count($cm) == 1) { |
|
| 242 | + if ( is_array($cm) && count($cm) == 1 ) { |
|
| 243 | 243 | $cm = $cm[0]; |
| 244 | 244 | } |
| 245 | 245 | } |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | */ |
| 255 | 255 | protected function get_meta_field($field_name) { |
| 256 | 256 | $value = apply_filters('timber_comment_get_meta_field_pre', null, $this->ID, $field_name, $this); |
| 257 | - if ($value === null) { |
|
| 257 | + if ( $value === null ) { |
|
| 258 | 258 | $value = get_comment_meta($this->ID, $field_name, true); |
| 259 | 259 | } |
| 260 | 260 | $value = apply_filters('timber_comment_get_meta_field', $value, $this->ID, $field_name, $this); |
@@ -267,9 +267,9 @@ discard block |
||
| 267 | 267 | * @api |
| 268 | 268 | * @return string |
| 269 | 269 | */ |
| 270 | - public function reply_link( $reply_text = 'Reply' ) { |
|
| 270 | + public function reply_link($reply_text = 'Reply') { |
|
| 271 | 271 | if ( is_singular() && comments_open() && get_option('thread_comments') ) { |
| 272 | - wp_enqueue_script( 'comment-reply' ); |
|
| 272 | + wp_enqueue_script('comment-reply'); |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | // Get the comments depth option from the admin panel |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | 'max_depth' => $max_depth, |
| 285 | 285 | ); |
| 286 | 286 | |
| 287 | - return get_comment_reply_link( $args, $this->ID, $this->post_id ); |
|
| 287 | + return get_comment_reply_link($args, $this->ID, $this->post_id); |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /* AVATAR Stuff |
@@ -295,9 +295,9 @@ discard block |
||
| 295 | 295 | * @return string |
| 296 | 296 | */ |
| 297 | 297 | protected function avatar_email() { |
| 298 | - $id = (int)$this->user_id; |
|
| 298 | + $id = (int) $this->user_id; |
|
| 299 | 299 | $user = get_userdata($id); |
| 300 | - if ($user) { |
|
| 300 | + if ( $user ) { |
|
| 301 | 301 | $email = $user->user_email; |
| 302 | 302 | } else { |
| 303 | 303 | $email = $this->comment_author_email; |
@@ -311,10 +311,10 @@ discard block |
||
| 311 | 311 | * @return string |
| 312 | 312 | */ |
| 313 | 313 | protected function avatar_host($email_hash) { |
| 314 | - if (is_ssl()) { |
|
| 314 | + if ( is_ssl() ) { |
|
| 315 | 315 | $host = 'https://secure.gravatar.com'; |
| 316 | 316 | } else { |
| 317 | - if (!empty($email_hash)) { |
|
| 317 | + if ( !empty($email_hash) ) { |
|
| 318 | 318 | $host = sprintf("http://%d.gravatar.com", (hexdec($email_hash[0]) % 2)); |
| 319 | 319 | } else { |
| 320 | 320 | $host = 'http://0.gravatar.com'; |
@@ -333,28 +333,28 @@ discard block |
||
| 333 | 333 | * @return string |
| 334 | 334 | */ |
| 335 | 335 | protected function avatar_default($default, $email, $size, $host) { |
| 336 | - if (substr($default, 0, 1) == '/') { |
|
| 336 | + if ( substr($default, 0, 1) == '/' ) { |
|
| 337 | 337 | $default = home_url() . $default; |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | - if (empty($default)) { |
|
| 340 | + if ( empty($default) ) { |
|
| 341 | 341 | $avatar_default = get_option('avatar_default'); |
| 342 | - if (empty($avatar_default)) { |
|
| 342 | + if ( empty($avatar_default) ) { |
|
| 343 | 343 | $default = 'mystery'; |
| 344 | 344 | } else { |
| 345 | 345 | $default = $avatar_default; |
| 346 | 346 | } |
| 347 | 347 | } |
| 348 | - if ('mystery' == $default) { |
|
| 348 | + if ( 'mystery' == $default ) { |
|
| 349 | 349 | $default = $host . '/avatar/ad516503a11cd5ca435acc9bb6523536?s=' . $size; |
| 350 | 350 | // ad516503a11cd5ca435acc9bb6523536 == md5('[email protected]') |
| 351 | - } else if ('blank' == $default) { |
|
| 351 | + } else if ( 'blank' == $default ) { |
|
| 352 | 352 | $default = $email ? 'blank' : includes_url('images/blank.gif'); |
| 353 | - } else if (!empty($email) && 'gravatar_default' == $default) { |
|
| 353 | + } else if ( !empty($email) && 'gravatar_default' == $default ) { |
|
| 354 | 354 | $default = ''; |
| 355 | - } else if ('gravatar_default' == $default) { |
|
| 355 | + } else if ( 'gravatar_default' == $default ) { |
|
| 356 | 356 | $default = $host . '/avatar/?s=' . $size; |
| 357 | - } else if (empty($email) && !strstr($default, 'http://')) { |
|
| 357 | + } else if ( empty($email) && !strstr($default, 'http://') ) { |
|
| 358 | 358 | $default = $host . '/avatar/?d=' . $default . '&s=' . $size; |
| 359 | 359 | } |
| 360 | 360 | return $default; |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | protected function avatar_out($default, $host, $email_hash, $size) { |
| 372 | 372 | $out = $host . '/avatar/' . $email_hash . '?s=' . $size . '&d=' . urlencode($default); |
| 373 | 373 | $rating = get_option('avatar_rating'); |
| 374 | - if (!empty($rating)) { |
|
| 374 | + if ( !empty($rating) ) { |
|
| 375 | 375 | $out .= '&r=' . $rating; |
| 376 | 376 | } |
| 377 | 377 | return str_replace('&', '&', esc_url($out)); |