@@ -44,7 +44,7 @@ |
||
| 44 | 44 | * (ex: /src/var/www/wp-content/uploads/[email protected]) |
| 45 | 45 | * @return bool true if everything went fine, false otherwise |
| 46 | 46 | */ |
| 47 | - function run($load_filename, $save_filename){ |
|
| 47 | + function run($load_filename, $save_filename) { |
|
| 48 | 48 | $image = wp_get_image_editor( $load_filename ); |
| 49 | 49 | if ( !is_wp_error( $image ) ) { |
| 50 | 50 | $current_size = $image->get_size(); |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Contains the class for running image retina-izing operations |
|
| 4 | - */ |
|
| 3 | + * Contains the class for running image retina-izing operations |
|
| 4 | + */ |
|
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | 7 | * Increases image size by a given factor |
@@ -11,64 +11,64 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | class TimberImageOperationRetina extends TimberImageOperation { |
| 13 | 13 | |
| 14 | - private $factor; |
|
| 14 | + private $factor; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Construct our operation |
|
| 18 | - * @param float $factor to multiply original dimensions by |
|
| 19 | - */ |
|
| 20 | - function __construct($factor) { |
|
| 21 | - $this->factor = $factor; |
|
| 22 | - } |
|
| 16 | + /** |
|
| 17 | + * Construct our operation |
|
| 18 | + * @param float $factor to multiply original dimensions by |
|
| 19 | + */ |
|
| 20 | + function __construct($factor) { |
|
| 21 | + $this->factor = $factor; |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Generates the final filename based on the source's name and extension |
|
| 26 | - * |
|
| 27 | - * @param string $src_filename the basename of the file (ex: my-awesome-pic) |
|
| 28 | - * @param string $src_extension the extension (ex: .jpg) |
|
| 29 | - * @return string the final filename to be used (ex: [email protected]) |
|
| 30 | - */ |
|
| 31 | - function filename($src_filename, $src_extension) { |
|
| 32 | - $newbase = $src_filename . '@' . $this->factor . 'x'; // add @2x, @3x, @1.5x, etc. |
|
| 33 | - $new_name = $newbase . '.' . $src_extension; |
|
| 34 | - return $new_name; |
|
| 35 | - } |
|
| 24 | + /** |
|
| 25 | + * Generates the final filename based on the source's name and extension |
|
| 26 | + * |
|
| 27 | + * @param string $src_filename the basename of the file (ex: my-awesome-pic) |
|
| 28 | + * @param string $src_extension the extension (ex: .jpg) |
|
| 29 | + * @return string the final filename to be used (ex: [email protected]) |
|
| 30 | + */ |
|
| 31 | + function filename($src_filename, $src_extension) { |
|
| 32 | + $newbase = $src_filename . '@' . $this->factor . 'x'; // add @2x, @3x, @1.5x, etc. |
|
| 33 | + $new_name = $newbase . '.' . $src_extension; |
|
| 34 | + return $new_name; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Performs the actual image manipulation, |
|
| 39 | - * including saving the target file. |
|
| 40 | - * |
|
| 41 | - * @param string $load_filename filepath (not URL) to source file |
|
| 42 | - * (ex: /src/var/www/wp-content/uploads/my-pic.jpg) |
|
| 43 | - * @param string $save_filename filepath (not URL) where result file should be saved |
|
| 44 | - * (ex: /src/var/www/wp-content/uploads/[email protected]) |
|
| 45 | - * @return bool true if everything went fine, false otherwise |
|
| 46 | - */ |
|
| 47 | - function run($load_filename, $save_filename){ |
|
| 48 | - $image = wp_get_image_editor( $load_filename ); |
|
| 49 | - if ( !is_wp_error( $image ) ) { |
|
| 50 | - $current_size = $image->get_size(); |
|
| 51 | - $src_w = $current_size['width']; |
|
| 52 | - $src_h = $current_size['height']; |
|
| 53 | - // Get ratios |
|
| 54 | - $w = $src_w * $this->factor; |
|
| 55 | - $h = $src_h * $this->factor; |
|
| 56 | - $image->crop( 0, 0, $src_w, $src_h, $w, $h ); |
|
| 57 | - $result = $image->save( $save_filename ); |
|
| 58 | - if ( is_wp_error( $result ) ) { |
|
| 59 | - // @codeCoverageIgnoreStart |
|
| 37 | + /** |
|
| 38 | + * Performs the actual image manipulation, |
|
| 39 | + * including saving the target file. |
|
| 40 | + * |
|
| 41 | + * @param string $load_filename filepath (not URL) to source file |
|
| 42 | + * (ex: /src/var/www/wp-content/uploads/my-pic.jpg) |
|
| 43 | + * @param string $save_filename filepath (not URL) where result file should be saved |
|
| 44 | + * (ex: /src/var/www/wp-content/uploads/[email protected]) |
|
| 45 | + * @return bool true if everything went fine, false otherwise |
|
| 46 | + */ |
|
| 47 | + function run($load_filename, $save_filename){ |
|
| 48 | + $image = wp_get_image_editor( $load_filename ); |
|
| 49 | + if ( !is_wp_error( $image ) ) { |
|
| 50 | + $current_size = $image->get_size(); |
|
| 51 | + $src_w = $current_size['width']; |
|
| 52 | + $src_h = $current_size['height']; |
|
| 53 | + // Get ratios |
|
| 54 | + $w = $src_w * $this->factor; |
|
| 55 | + $h = $src_h * $this->factor; |
|
| 56 | + $image->crop( 0, 0, $src_w, $src_h, $w, $h ); |
|
| 57 | + $result = $image->save( $save_filename ); |
|
| 58 | + if ( is_wp_error( $result ) ) { |
|
| 59 | + // @codeCoverageIgnoreStart |
|
| 60 | 60 | TimberHelper::error_log( 'Error resizing image' ); |
| 61 | 61 | TimberHelper::error_log( $result ); |
| 62 | 62 | return false; |
| 63 | 63 | // @codeCoverageIgnoreEnd |
| 64 | - } else { |
|
| 65 | - return true; |
|
| 66 | - } |
|
| 67 | - } else if ( isset( $image->error_data['error_loading_image'] ) ) { |
|
| 68 | - TimberHelper::error_log( 'Error loading ' . $image->error_data['error_loading_image'] ); |
|
| 69 | - } else { |
|
| 70 | - TimberHelper::error_log( $image ); |
|
| 71 | - } |
|
| 72 | - return false; |
|
| 73 | - } |
|
| 64 | + } else { |
|
| 65 | + return true; |
|
| 66 | + } |
|
| 67 | + } else if ( isset( $image->error_data['error_loading_image'] ) ) { |
|
| 68 | + TimberHelper::error_log( 'Error loading ' . $image->error_data['error_loading_image'] ); |
|
| 69 | + } else { |
|
| 70 | + TimberHelper::error_log( $image ); |
|
| 71 | + } |
|
| 72 | + return false; |
|
| 73 | + } |
|
| 74 | 74 | } |
@@ -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 | } |
@@ -6,14 +6,14 @@ discard block |
||
| 6 | 6 | */ |
| 7 | 7 | class TimberCommand { |
| 8 | 8 | |
| 9 | - public static function clear_cache($mode = 'all'){ |
|
| 10 | - if (is_array($mode)){ |
|
| 9 | + public static function clear_cache($mode = 'all') { |
|
| 10 | + if (is_array($mode)) { |
|
| 11 | 11 | $mode = reset($mode); |
| 12 | 12 | } |
| 13 | 13 | if ($mode == 'all') { |
| 14 | 14 | $twig_cache = self::clear_cache_twig(); |
| 15 | 15 | $timber_cache = self::clear_cache_timber(); |
| 16 | - if ($twig_cache && $timber_cache){ |
|
| 16 | + if ($twig_cache && $timber_cache) { |
|
| 17 | 17 | return true; |
| 18 | 18 | } |
| 19 | 19 | } else if ($mode == 'twig') { |
@@ -23,12 +23,12 @@ discard block |
||
| 23 | 23 | } |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - static function clear_cache_timber(){ |
|
| 26 | + static function clear_cache_timber() { |
|
| 27 | 27 | $loader = new TimberLoader(); |
| 28 | 28 | return $loader->clear_cache_timber(); |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - static function clear_cache_twig(){ |
|
| 31 | + static function clear_cache_twig() { |
|
| 32 | 32 | $loader = new TimberLoader(); |
| 33 | 33 | return $loader->clear_cache_twig(); |
| 34 | 34 | } |
@@ -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 | } |
@@ -25,9 +25,9 @@ discard block |
||
| 25 | 25 | * wp timber clear_cache_twig |
| 26 | 26 | * |
| 27 | 27 | */ |
| 28 | - function clear_cache_twig(){ |
|
| 28 | + function clear_cache_twig() { |
|
| 29 | 29 | $clear = TimberCommand::clear_cache_twig(); |
| 30 | - if ($clear){ |
|
| 30 | + if ($clear) { |
|
| 31 | 31 | WP_CLI::success('Cleared contents of twig cache'); |
| 32 | 32 | } else { |
| 33 | 33 | WP_CLI::warning('Failed to clear twig cache'); |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | function clear_cache_timber() { |
| 46 | 46 | $clear = TimberCommand::clear_cache_timber(); |
| 47 | 47 | $message = 'Failed to clear timber cache'; |
| 48 | - if ($clear){ |
|
| 48 | + if ($clear) { |
|
| 49 | 49 | $message = "Cleared contents of Timber's Cache"; |
| 50 | 50 | WP_CLI::success($message); |
| 51 | 51 | } else { |
@@ -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 | } |
@@ -63,7 +63,7 @@ |
||
| 63 | 63 | foreach ( $info as $key => $value ) { |
| 64 | 64 | if ( !empty( $key ) && $force ) { |
| 65 | 65 | $this->$key = $value; |
| 66 | - } else if ( !empty( $key ) && !method_exists($this, $key) ){ |
|
| 66 | + } else if ( !empty( $key ) && !method_exists($this, $key) ) { |
|
| 67 | 67 | $this->$key = $value; |
| 68 | 68 | } |
| 69 | 69 | } |
@@ -48,8 +48,9 @@ |
||
| 48 | 48 | |
| 49 | 49 | // lock timeout shouldn't be higher than 5 seconds, unless |
| 50 | 50 | // remote calls with high timeouts are made here |
| 51 | - if ( $enable_transients ) |
|
| 52 | - self::_lock_transient( $slug, $lock_timeout ); |
|
| 51 | + if ( $enable_transients ) { |
|
| 52 | + self::_lock_transient( $slug, $lock_timeout ); |
|
| 53 | + } |
|
| 53 | 54 | |
| 54 | 55 | $data = $callback(); |
| 55 | 56 | |
@@ -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 | /** |
@@ -325,7 +325,8 @@ |
||
| 325 | 325 | ); |
| 326 | 326 | $upload_dir = wp_upload_dir(); |
| 327 | 327 | $tmp = $url; |
| 328 | - if ( 0 === strpos($tmp, ABSPATH) ) { // we've been given a dir, not an url |
|
| 328 | + if ( 0 === strpos($tmp, ABSPATH) ) { |
|
| 329 | +// we've been given a dir, not an url |
|
| 329 | 330 | $result['absolute'] = true; |
| 330 | 331 | if ( 0 === strpos($tmp, $upload_dir['basedir']) ) { |
| 331 | 332 | $result['base']= self::BASE_UPLOADS; // upload based |