@@ -1,13 +1,13 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Each image filter is represented by a subclass of this class,m |
|
4 | - * and each filter call is a new instance, with call arguments as properties. |
|
5 | - * |
|
6 | - * Only 3 methods need to be implemented: |
|
7 | - * - constructor, storing all filter arguments |
|
8 | - * - filename |
|
9 | - * - run |
|
10 | - */ |
|
3 | + * Each image filter is represented by a subclass of this class,m |
|
4 | + * and each filter call is a new instance, with call arguments as properties. |
|
5 | + * |
|
6 | + * Only 3 methods need to be implemented: |
|
7 | + * - constructor, storing all filter arguments |
|
8 | + * - filename |
|
9 | + * - run |
|
10 | + */ |
|
11 | 11 | abstract class TimberImageOperation { |
12 | 12 | /** |
13 | 13 | * Builds the result filename, based on source filename and extension |
@@ -2,57 +2,57 @@ |
||
2 | 2 | |
3 | 3 | class ACFTimber { |
4 | 4 | |
5 | - function __construct() { |
|
6 | - add_filter( 'timber_post_get_meta', array( $this, 'post_get_meta' ), 10, 2 ); |
|
7 | - add_filter( 'timber_post_get_meta_field', array( $this, 'post_get_meta_field' ), 10, 3 ); |
|
8 | - add_filter( 'timber_term_get_meta', array( $this, 'term_get_meta' ), 10, 3 ); |
|
9 | - add_filter( 'timber_term_get_meta_field', array( $this, 'term_get_meta_field' ), 10, 4 ); |
|
10 | - add_filter( 'timber_user_get_meta_field_pre', array( $this, 'user_get_meta_field' ), 10, 3 ); |
|
11 | - add_filter( 'timber_term_set_meta', array( $this, 'term_set_meta'), 10, 4 ); |
|
12 | - } |
|
13 | - |
|
14 | - function post_get_meta( $customs, $post_id ) { |
|
15 | - return $customs; |
|
16 | - } |
|
17 | - |
|
18 | - function post_get_meta_field( $value, $post_id, $field_name ) { |
|
19 | - return get_field( $field_name, $post_id ); |
|
20 | - } |
|
21 | - |
|
22 | - function term_get_meta_field( $value, $term_id, $field_name, $term ) { |
|
23 | - $searcher = $term->taxonomy . "_" . $term->ID; |
|
24 | - return get_field( $field_name, $searcher ); |
|
25 | - } |
|
26 | - |
|
27 | - function term_set_meta( $value, $field, $term_id, $term ) { |
|
28 | - $searcher = $term->taxonomy . "_" . $term->ID; |
|
29 | - update_field( $field, $value, $searcher ); |
|
30 | - return $value; |
|
31 | - } |
|
32 | - |
|
33 | - function term_get_meta( $fields, $term_id, $term ) { |
|
34 | - $searcher = $term->taxonomy . "_" . $term->ID; // save to a specific category |
|
35 | - $fds = get_fields( $searcher ); |
|
36 | - if ( is_array( $fds ) ) { |
|
37 | - foreach ( $fds as $key => $value ) { |
|
38 | - $key = preg_replace( '/_/', '', $key, 1 ); |
|
39 | - $key = str_replace( $searcher, '', $key ); |
|
40 | - $key = preg_replace( '/_/', '', $key, 1 ); |
|
41 | - $field = get_field( $key, $searcher ); |
|
42 | - $fields[$key] = $field; |
|
43 | - } |
|
44 | - $fields = array_merge( $fields, $fds ); |
|
45 | - } |
|
46 | - return $fields; |
|
47 | - } |
|
48 | - |
|
49 | - function user_get_meta( $fields, $user_id ) { |
|
50 | - return $fields; |
|
51 | - } |
|
52 | - |
|
53 | - function user_get_meta_field( $value, $uid, $field ) { |
|
54 | - return get_field( $field, 'user_' . $uid ); |
|
55 | - } |
|
5 | + function __construct() { |
|
6 | + add_filter( 'timber_post_get_meta', array( $this, 'post_get_meta' ), 10, 2 ); |
|
7 | + add_filter( 'timber_post_get_meta_field', array( $this, 'post_get_meta_field' ), 10, 3 ); |
|
8 | + add_filter( 'timber_term_get_meta', array( $this, 'term_get_meta' ), 10, 3 ); |
|
9 | + add_filter( 'timber_term_get_meta_field', array( $this, 'term_get_meta_field' ), 10, 4 ); |
|
10 | + add_filter( 'timber_user_get_meta_field_pre', array( $this, 'user_get_meta_field' ), 10, 3 ); |
|
11 | + add_filter( 'timber_term_set_meta', array( $this, 'term_set_meta'), 10, 4 ); |
|
12 | + } |
|
13 | + |
|
14 | + function post_get_meta( $customs, $post_id ) { |
|
15 | + return $customs; |
|
16 | + } |
|
17 | + |
|
18 | + function post_get_meta_field( $value, $post_id, $field_name ) { |
|
19 | + return get_field( $field_name, $post_id ); |
|
20 | + } |
|
21 | + |
|
22 | + function term_get_meta_field( $value, $term_id, $field_name, $term ) { |
|
23 | + $searcher = $term->taxonomy . "_" . $term->ID; |
|
24 | + return get_field( $field_name, $searcher ); |
|
25 | + } |
|
26 | + |
|
27 | + function term_set_meta( $value, $field, $term_id, $term ) { |
|
28 | + $searcher = $term->taxonomy . "_" . $term->ID; |
|
29 | + update_field( $field, $value, $searcher ); |
|
30 | + return $value; |
|
31 | + } |
|
32 | + |
|
33 | + function term_get_meta( $fields, $term_id, $term ) { |
|
34 | + $searcher = $term->taxonomy . "_" . $term->ID; // save to a specific category |
|
35 | + $fds = get_fields( $searcher ); |
|
36 | + if ( is_array( $fds ) ) { |
|
37 | + foreach ( $fds as $key => $value ) { |
|
38 | + $key = preg_replace( '/_/', '', $key, 1 ); |
|
39 | + $key = str_replace( $searcher, '', $key ); |
|
40 | + $key = preg_replace( '/_/', '', $key, 1 ); |
|
41 | + $field = get_field( $key, $searcher ); |
|
42 | + $fields[$key] = $field; |
|
43 | + } |
|
44 | + $fields = array_merge( $fields, $fds ); |
|
45 | + } |
|
46 | + return $fields; |
|
47 | + } |
|
48 | + |
|
49 | + function user_get_meta( $fields, $user_id ) { |
|
50 | + return $fields; |
|
51 | + } |
|
52 | + |
|
53 | + function user_get_meta_field( $value, $uid, $field ) { |
|
54 | + return get_field( $field, 'user_' . $uid ); |
|
55 | + } |
|
56 | 56 | } |
57 | 57 | |
58 | 58 |
@@ -6,31 +6,31 @@ |
||
6 | 6 | */ |
7 | 7 | class TimberCommand { |
8 | 8 | |
9 | - public static function clear_cache($mode = 'all'){ |
|
10 | - if (is_array($mode)){ |
|
11 | - $mode = reset($mode); |
|
12 | - } |
|
13 | - if ($mode == 'all') { |
|
14 | - $twig_cache = self::clear_cache_twig(); |
|
15 | - $timber_cache = self::clear_cache_timber(); |
|
16 | - if ($twig_cache && $timber_cache){ |
|
17 | - return true; |
|
18 | - } |
|
19 | - } else if ($mode == 'twig') { |
|
20 | - return self::clear_cache_twig(); |
|
21 | - } else if ($mode == 'timber') { |
|
22 | - return self::clear_cache_timber(); |
|
23 | - } |
|
24 | - } |
|
9 | + public static function clear_cache($mode = 'all'){ |
|
10 | + if (is_array($mode)){ |
|
11 | + $mode = reset($mode); |
|
12 | + } |
|
13 | + if ($mode == 'all') { |
|
14 | + $twig_cache = self::clear_cache_twig(); |
|
15 | + $timber_cache = self::clear_cache_timber(); |
|
16 | + if ($twig_cache && $timber_cache){ |
|
17 | + return true; |
|
18 | + } |
|
19 | + } else if ($mode == 'twig') { |
|
20 | + return self::clear_cache_twig(); |
|
21 | + } else if ($mode == 'timber') { |
|
22 | + return self::clear_cache_timber(); |
|
23 | + } |
|
24 | + } |
|
25 | 25 | |
26 | - static function clear_cache_timber(){ |
|
27 | - $loader = new TimberLoader(); |
|
28 | - return $loader->clear_cache_timber(); |
|
29 | - } |
|
26 | + static function clear_cache_timber(){ |
|
27 | + $loader = new TimberLoader(); |
|
28 | + return $loader->clear_cache_timber(); |
|
29 | + } |
|
30 | 30 | |
31 | - static function clear_cache_twig(){ |
|
32 | - $loader = new TimberLoader(); |
|
33 | - return $loader->clear_cache_twig(); |
|
34 | - } |
|
31 | + static function clear_cache_twig(){ |
|
32 | + $loader = new TimberLoader(); |
|
33 | + return $loader->clear_cache_twig(); |
|
34 | + } |
|
35 | 35 | |
36 | 36 | } |
@@ -5,53 +5,53 @@ |
||
5 | 5 | |
6 | 6 | class Timber_WP_CLI_Command extends WP_CLI_Command { |
7 | 7 | |
8 | - /** |
|
9 | - * Clears Timber and Twig's Cache |
|
10 | - * |
|
11 | - * ## EXAMPLES |
|
12 | - * |
|
13 | - * wp timber clear_cache |
|
14 | - * |
|
15 | - */ |
|
16 | - public function clear_cache($mode = 'all') { |
|
17 | - TimberCommand::clear_cache($mode); |
|
18 | - } |
|
8 | + /** |
|
9 | + * Clears Timber and Twig's Cache |
|
10 | + * |
|
11 | + * ## EXAMPLES |
|
12 | + * |
|
13 | + * wp timber clear_cache |
|
14 | + * |
|
15 | + */ |
|
16 | + public function clear_cache($mode = 'all') { |
|
17 | + TimberCommand::clear_cache($mode); |
|
18 | + } |
|
19 | 19 | |
20 | - /** |
|
21 | - * Clears Twig's Cache |
|
22 | - * |
|
23 | - * ## EXAMPLES |
|
24 | - * |
|
25 | - * wp timber clear_cache_twig |
|
26 | - * |
|
27 | - */ |
|
28 | - function clear_cache_twig(){ |
|
29 | - $clear = TimberCommand::clear_cache_twig(); |
|
30 | - if ($clear){ |
|
31 | - WP_CLI::success('Cleared contents of twig cache'); |
|
32 | - } else { |
|
33 | - WP_CLI::warning('Failed to clear twig cache'); |
|
34 | - } |
|
35 | - } |
|
20 | + /** |
|
21 | + * Clears Twig's Cache |
|
22 | + * |
|
23 | + * ## EXAMPLES |
|
24 | + * |
|
25 | + * wp timber clear_cache_twig |
|
26 | + * |
|
27 | + */ |
|
28 | + function clear_cache_twig(){ |
|
29 | + $clear = TimberCommand::clear_cache_twig(); |
|
30 | + if ($clear){ |
|
31 | + WP_CLI::success('Cleared contents of twig cache'); |
|
32 | + } else { |
|
33 | + WP_CLI::warning('Failed to clear twig cache'); |
|
34 | + } |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Clears Timber's Cache |
|
39 | - * |
|
40 | - * ## EXAMPLES |
|
41 | - * |
|
42 | - * wp timber clear_cache_timber |
|
43 | - * |
|
44 | - */ |
|
45 | - function clear_cache_timber() { |
|
46 | - $clear = TimberCommand::clear_cache_timber(); |
|
47 | - $message = 'Failed to clear timber cache'; |
|
48 | - if ($clear){ |
|
49 | - $message = "Cleared contents of Timber's Cache"; |
|
50 | - WP_CLI::success($message); |
|
51 | - } else { |
|
52 | - WP_CLI::warning($message); |
|
53 | - } |
|
54 | - return $message; |
|
55 | - } |
|
37 | + /** |
|
38 | + * Clears Timber's Cache |
|
39 | + * |
|
40 | + * ## EXAMPLES |
|
41 | + * |
|
42 | + * wp timber clear_cache_timber |
|
43 | + * |
|
44 | + */ |
|
45 | + function clear_cache_timber() { |
|
46 | + $clear = TimberCommand::clear_cache_timber(); |
|
47 | + $message = 'Failed to clear timber cache'; |
|
48 | + if ($clear){ |
|
49 | + $message = "Cleared contents of Timber's Cache"; |
|
50 | + WP_CLI::success($message); |
|
51 | + } else { |
|
52 | + WP_CLI::warning($message); |
|
53 | + } |
|
54 | + return $message; |
|
55 | + } |
|
56 | 56 | |
57 | 57 | } |
@@ -2,9 +2,9 @@ |
||
2 | 2 | |
3 | 3 | class TimberAdmin { |
4 | 4 | |
5 | - public static function init() { |
|
6 | - return add_filter( 'plugin_row_meta', array( __CLASS__, 'meta_links' ), 10, 2 ); |
|
7 | - } |
|
5 | + public static function init() { |
|
6 | + return add_filter( 'plugin_row_meta', array( __CLASS__, 'meta_links' ), 10, 2 ); |
|
7 | + } |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * @param array $links |
@@ -2,116 +2,116 @@ |
||
2 | 2 | |
3 | 3 | abstract class TimberCore { |
4 | 4 | |
5 | - public $id; |
|
6 | - public $ID; |
|
7 | - public $object_type; |
|
5 | + public $id; |
|
6 | + public $ID; |
|
7 | + public $object_type; |
|
8 | 8 | |
9 | - /** |
|
10 | - * |
|
11 | - * |
|
12 | - * @return boolean |
|
13 | - */ |
|
14 | - function __isset( $field ) { |
|
15 | - if ( isset( $this->$field ) ) { |
|
16 | - return $this->$field; |
|
17 | - } |
|
18 | - return false; |
|
19 | - } |
|
9 | + /** |
|
10 | + * |
|
11 | + * |
|
12 | + * @return boolean |
|
13 | + */ |
|
14 | + function __isset( $field ) { |
|
15 | + if ( isset( $this->$field ) ) { |
|
16 | + return $this->$field; |
|
17 | + } |
|
18 | + return false; |
|
19 | + } |
|
20 | 20 | |
21 | - /** |
|
22 | - * This is helpful for twig to return properties and methods see: https://github.com/fabpot/Twig/issues/2 |
|
23 | - * @return mixed |
|
24 | - */ |
|
25 | - function __call( $field, $args ) { |
|
26 | - return $this->__get( $field ); |
|
27 | - } |
|
21 | + /** |
|
22 | + * This is helpful for twig to return properties and methods see: https://github.com/fabpot/Twig/issues/2 |
|
23 | + * @return mixed |
|
24 | + */ |
|
25 | + function __call( $field, $args ) { |
|
26 | + return $this->__get( $field ); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * This is helpful for twig to return properties and methods see: https://github.com/fabpot/Twig/issues/2 |
|
31 | - * |
|
32 | - * @return mixed |
|
33 | - */ |
|
34 | - function __get( $field ) { |
|
35 | - if ( property_exists($this, $field) ) { |
|
36 | - return $this->$field; |
|
37 | - } |
|
38 | - if ( method_exists($this, 'meta') && $meta_value = $this->meta( $field ) ) { |
|
39 | - return $this->$field = $meta_value; |
|
40 | - } |
|
41 | - if ( method_exists($this, $field) ) { |
|
42 | - return $this->$field = $this->$field(); |
|
43 | - } |
|
44 | - return $this->$field = false; |
|
45 | - } |
|
29 | + /** |
|
30 | + * This is helpful for twig to return properties and methods see: https://github.com/fabpot/Twig/issues/2 |
|
31 | + * |
|
32 | + * @return mixed |
|
33 | + */ |
|
34 | + function __get( $field ) { |
|
35 | + if ( property_exists($this, $field) ) { |
|
36 | + return $this->$field; |
|
37 | + } |
|
38 | + if ( method_exists($this, 'meta') && $meta_value = $this->meta( $field ) ) { |
|
39 | + return $this->$field = $meta_value; |
|
40 | + } |
|
41 | + if ( method_exists($this, $field) ) { |
|
42 | + return $this->$field = $this->$field(); |
|
43 | + } |
|
44 | + return $this->$field = false; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Takes an array or object and adds the properties to the parent object |
|
49 | - * @example |
|
50 | - * ```php |
|
51 | - * $data = array('airplane' => '757-200', 'flight' => '5316'); |
|
52 | - * $post = new TimberPost() |
|
53 | - * $post->import(data); |
|
54 | - * echo $post->airplane; //757-200 |
|
55 | - * ``` |
|
56 | - * @param array|object $info an object or array you want to grab data from to attach to the Timber object |
|
57 | - */ |
|
58 | - function import( $info, $force = false ) { |
|
59 | - if ( is_object( $info ) ) { |
|
60 | - $info = get_object_vars( $info ); |
|
61 | - } |
|
62 | - if ( is_array( $info ) ) { |
|
63 | - foreach ( $info as $key => $value ) { |
|
64 | - if ( !empty( $key ) && $force ) { |
|
65 | - $this->$key = $value; |
|
66 | - } else if ( !empty( $key ) && !method_exists($this, $key) ){ |
|
67 | - $this->$key = $value; |
|
68 | - } |
|
69 | - } |
|
70 | - } |
|
71 | - } |
|
47 | + /** |
|
48 | + * Takes an array or object and adds the properties to the parent object |
|
49 | + * @example |
|
50 | + * ```php |
|
51 | + * $data = array('airplane' => '757-200', 'flight' => '5316'); |
|
52 | + * $post = new TimberPost() |
|
53 | + * $post->import(data); |
|
54 | + * echo $post->airplane; //757-200 |
|
55 | + * ``` |
|
56 | + * @param array|object $info an object or array you want to grab data from to attach to the Timber object |
|
57 | + */ |
|
58 | + function import( $info, $force = false ) { |
|
59 | + if ( is_object( $info ) ) { |
|
60 | + $info = get_object_vars( $info ); |
|
61 | + } |
|
62 | + if ( is_array( $info ) ) { |
|
63 | + foreach ( $info as $key => $value ) { |
|
64 | + if ( !empty( $key ) && $force ) { |
|
65 | + $this->$key = $value; |
|
66 | + } else if ( !empty( $key ) && !method_exists($this, $key) ){ |
|
67 | + $this->$key = $value; |
|
68 | + } |
|
69 | + } |
|
70 | + } |
|
71 | + } |
|
72 | 72 | |
73 | 73 | |
74 | - /** |
|
75 | - * @ignore |
|
76 | - * @param string $key |
|
77 | - * @param mixed $value |
|
78 | - */ |
|
79 | - function update( $key, $value ) { |
|
80 | - update_metadata( $this->object_type, $this->ID, $key, $value ); |
|
81 | - } |
|
74 | + /** |
|
75 | + * @ignore |
|
76 | + * @param string $key |
|
77 | + * @param mixed $value |
|
78 | + */ |
|
79 | + function update( $key, $value ) { |
|
80 | + update_metadata( $this->object_type, $this->ID, $key, $value ); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Can you edit this post/term/user? Well good for you. You're no better than me. |
|
85 | - * @example |
|
86 | - * ```twig |
|
87 | - * {% if post.can_edit %} |
|
88 | - * <a href="{{ post.edit_link }}">Edit</a> |
|
89 | - * {% endif %} |
|
90 | - * ``` |
|
91 | - * ```html |
|
92 | - * <a href="http://example.org/wp-admin/edit.php?p=242">Edit</a> |
|
93 | - * ``` |
|
94 | - * @return bool |
|
95 | - */ |
|
96 | - function can_edit() { |
|
97 | - if ( !function_exists( 'current_user_can' ) ) { |
|
98 | - return false; |
|
99 | - } |
|
100 | - if ( current_user_can( 'edit_post', $this->ID ) ) { |
|
101 | - return true; |
|
102 | - } |
|
103 | - return false; |
|
104 | - } |
|
83 | + /** |
|
84 | + * Can you edit this post/term/user? Well good for you. You're no better than me. |
|
85 | + * @example |
|
86 | + * ```twig |
|
87 | + * {% if post.can_edit %} |
|
88 | + * <a href="{{ post.edit_link }}">Edit</a> |
|
89 | + * {% endif %} |
|
90 | + * ``` |
|
91 | + * ```html |
|
92 | + * <a href="http://example.org/wp-admin/edit.php?p=242">Edit</a> |
|
93 | + * ``` |
|
94 | + * @return bool |
|
95 | + */ |
|
96 | + function can_edit() { |
|
97 | + if ( !function_exists( 'current_user_can' ) ) { |
|
98 | + return false; |
|
99 | + } |
|
100 | + if ( current_user_can( 'edit_post', $this->ID ) ) { |
|
101 | + return true; |
|
102 | + } |
|
103 | + return false; |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * |
|
108 | - * |
|
109 | - * @return array |
|
110 | - */ |
|
111 | - function get_method_values() { |
|
112 | - $ret = array(); |
|
113 | - $ret['can_edit'] = $this->can_edit(); |
|
114 | - return $ret; |
|
115 | - } |
|
106 | + /** |
|
107 | + * |
|
108 | + * |
|
109 | + * @return array |
|
110 | + */ |
|
111 | + function get_method_values() { |
|
112 | + $ret = array(); |
|
113 | + $ret['can_edit'] = $this->can_edit(); |
|
114 | + return $ret; |
|
115 | + } |
|
116 | 116 | |
117 | 117 | } |
@@ -108,23 +108,23 @@ |
||
108 | 108 | //its a gif so test |
109 | 109 | if(!($fh = @fopen($file, 'rb'))) { |
110 | 110 | return false; |
111 | - } |
|
112 | - $count = 0; |
|
113 | - //an animated gif contains multiple "frames", with each frame having a |
|
114 | - //header made up of: |
|
115 | - // * a static 4-byte sequence (\x00\x21\xF9\x04) |
|
116 | - // * 4 variable bytes |
|
117 | - // * a static 2-byte sequence (\x00\x2C) |
|
111 | + } |
|
112 | + $count = 0; |
|
113 | + //an animated gif contains multiple "frames", with each frame having a |
|
114 | + //header made up of: |
|
115 | + // * a static 4-byte sequence (\x00\x21\xF9\x04) |
|
116 | + // * 4 variable bytes |
|
117 | + // * a static 2-byte sequence (\x00\x2C) |
|
118 | 118 | |
119 | - // We read through the file til we reach the end of the file, or we've found |
|
120 | - // at least 2 frame headers |
|
121 | - while(!feof($fh) && $count < 2) { |
|
122 | - $chunk = fread($fh, 1024 * 100); //read 100kb at a time |
|
123 | - $count += preg_match_all('#\x00\x21\xF9\x04.{4}\x00[\x2C\x21]#s', $chunk, $matches); |
|
124 | - } |
|
119 | + // We read through the file til we reach the end of the file, or we've found |
|
120 | + // at least 2 frame headers |
|
121 | + while(!feof($fh) && $count < 2) { |
|
122 | + $chunk = fread($fh, 1024 * 100); //read 100kb at a time |
|
123 | + $count += preg_match_all('#\x00\x21\xF9\x04.{4}\x00[\x2C\x21]#s', $chunk, $matches); |
|
124 | + } |
|
125 | 125 | |
126 | - fclose($fh); |
|
127 | - return $count > 1; |
|
126 | + fclose($fh); |
|
127 | + return $count > 1; |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
@@ -5,20 +5,20 @@ |
||
5 | 5 | * @package timber |
6 | 6 | */ |
7 | 7 | class TimberIntegrations { |
8 | - public static function init() { |
|
8 | + public static function init() { |
|
9 | 9 | |
10 | - add_action( 'init', array( __CLASS__, 'maybe_init_acftimber' ) ); |
|
10 | + add_action( 'init', array( __CLASS__, 'maybe_init_acftimber' ) ); |
|
11 | 11 | |
12 | - if ( class_exists( 'WP_CLI_Command' ) ) { |
|
13 | - WP_CLI::add_command( 'timber', 'Timber_WP_CLI_Command' ); |
|
14 | - } |
|
15 | - } |
|
12 | + if ( class_exists( 'WP_CLI_Command' ) ) { |
|
13 | + WP_CLI::add_command( 'timber', 'Timber_WP_CLI_Command' ); |
|
14 | + } |
|
15 | + } |
|
16 | 16 | |
17 | - public static function maybe_init_acftimber() { |
|
17 | + public static function maybe_init_acftimber() { |
|
18 | 18 | |
19 | - if ( class_exists( 'ACF' ) ) { |
|
20 | - new ACFTimber(); |
|
21 | - } |
|
19 | + if ( class_exists( 'ACF' ) ) { |
|
20 | + new ACFTimber(); |
|
21 | + } |
|
22 | 22 | |
23 | - } |
|
23 | + } |
|
24 | 24 | } |
@@ -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 | } |