@@ -21,18 +21,18 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class Wordlift_Deactivator { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Short Description. (use period) |
|
| 26 | - * |
|
| 27 | - * Long Description. |
|
| 28 | - * |
|
| 29 | - * @since 1.0.0 |
|
| 30 | - */ |
|
| 31 | - public static function deactivate() { |
|
| 24 | + /** |
|
| 25 | + * Short Description. (use period) |
|
| 26 | + * |
|
| 27 | + * Long Description. |
|
| 28 | + * |
|
| 29 | + * @since 1.0.0 |
|
| 30 | + */ |
|
| 31 | + public static function deactivate() { |
|
| 32 | 32 | |
| 33 | - // Clear caches. |
|
| 34 | - Wordlift_File_Cache_Service::flush_all(); |
|
| 33 | + // Clear caches. |
|
| 34 | + Wordlift_File_Cache_Service::flush_all(); |
|
| 35 | 35 | |
| 36 | - } |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | 38 | } |
@@ -8,7 +8,7 @@ |
||
| 8 | 8 | * @package Wordlift |
| 9 | 9 | * @subpackage Wordlift/includes/cache |
| 10 | 10 | */ |
| 11 | -require_once plugin_dir_path( dirname( dirname( __FILE__ ) ) ) . 'includes/cache/intf-wordlift-cache-service.php'; |
|
| 12 | -require_once plugin_dir_path( dirname( dirname( __FILE__ ) ) ) . 'includes/cache/class-wordlift-file-cache-service.php'; |
|
| 13 | -require_once plugin_dir_path( dirname( dirname( __FILE__ ) ) ) . 'includes/cache/class-wordlift-cached-post-converter.php'; |
|
| 14 | -require_once plugin_dir_path( dirname( dirname( __FILE__ ) ) ) . 'includes/cache/class-wordlift-cached-entity-uri-service.php'; |
|
| 11 | +require_once plugin_dir_path(dirname(dirname(__FILE__))).'includes/cache/intf-wordlift-cache-service.php'; |
|
| 12 | +require_once plugin_dir_path(dirname(dirname(__FILE__))).'includes/cache/class-wordlift-file-cache-service.php'; |
|
| 13 | +require_once plugin_dir_path(dirname(dirname(__FILE__))).'includes/cache/class-wordlift-cached-post-converter.php'; |
|
| 14 | +require_once plugin_dir_path(dirname(dirname(__FILE__))).'includes/cache/class-wordlift-cached-entity-uri-service.php'; |
|
@@ -17,53 +17,53 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | interface Wordlift_Cache_Service { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Get the cached response for the specified `id`. |
|
| 22 | - * |
|
| 23 | - * @since 3.16.0 |
|
| 24 | - * |
|
| 25 | - * @param string $id The cache `id`. |
|
| 26 | - * |
|
| 27 | - * @return mixed|false The cached contents or false if the cache isn't found. |
|
| 28 | - */ |
|
| 29 | - function get_cache( $id ); |
|
| 20 | + /** |
|
| 21 | + * Get the cached response for the specified `id`. |
|
| 22 | + * |
|
| 23 | + * @since 3.16.0 |
|
| 24 | + * |
|
| 25 | + * @param string $id The cache `id`. |
|
| 26 | + * |
|
| 27 | + * @return mixed|false The cached contents or false if the cache isn't found. |
|
| 28 | + */ |
|
| 29 | + function get_cache( $id ); |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Check whether we have cached results for the provided id. |
|
| 33 | - * |
|
| 34 | - * @since 3.16.3 |
|
| 35 | - * |
|
| 36 | - * @param string $id The cache `id`. |
|
| 37 | - * |
|
| 38 | - * @return bool True if we have cached results otherwise false. |
|
| 39 | - */ |
|
| 40 | - function has_cache( $id ); |
|
| 31 | + /** |
|
| 32 | + * Check whether we have cached results for the provided id. |
|
| 33 | + * |
|
| 34 | + * @since 3.16.3 |
|
| 35 | + * |
|
| 36 | + * @param string $id The cache `id`. |
|
| 37 | + * |
|
| 38 | + * @return bool True if we have cached results otherwise false. |
|
| 39 | + */ |
|
| 40 | + function has_cache( $id ); |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Set the cache contents for the specified `id`. |
|
| 44 | - * |
|
| 45 | - * @since 3.16.0 |
|
| 46 | - * |
|
| 47 | - * @param string $id The cache id. |
|
| 48 | - * @param mixed $contents The cache contents. |
|
| 49 | - */ |
|
| 50 | - function set_cache( $id, $contents ); |
|
| 42 | + /** |
|
| 43 | + * Set the cache contents for the specified `id`. |
|
| 44 | + * |
|
| 45 | + * @since 3.16.0 |
|
| 46 | + * |
|
| 47 | + * @param string $id The cache id. |
|
| 48 | + * @param mixed $contents The cache contents. |
|
| 49 | + */ |
|
| 50 | + function set_cache( $id, $contents ); |
|
| 51 | 51 | |
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Delete the cache for the specified `id`. |
|
| 55 | - * |
|
| 56 | - * @since 3.16.0 |
|
| 57 | - * |
|
| 58 | - * @param string $id The cache `id`. |
|
| 59 | - */ |
|
| 60 | - function delete_cache( $id ); |
|
| 53 | + /** |
|
| 54 | + * Delete the cache for the specified `id`. |
|
| 55 | + * |
|
| 56 | + * @since 3.16.0 |
|
| 57 | + * |
|
| 58 | + * @param string $id The cache `id`. |
|
| 59 | + */ |
|
| 60 | + function delete_cache( $id ); |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Flush the whole cache. |
|
| 64 | - * |
|
| 65 | - * @since 3.16.0 |
|
| 66 | - */ |
|
| 67 | - function flush(); |
|
| 62 | + /** |
|
| 63 | + * Flush the whole cache. |
|
| 64 | + * |
|
| 65 | + * @since 3.16.0 |
|
| 66 | + */ |
|
| 67 | + function flush(); |
|
| 68 | 68 | |
| 69 | 69 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | * |
| 27 | 27 | * @return mixed|false The cached contents or false if the cache isn't found. |
| 28 | 28 | */ |
| 29 | - function get_cache( $id ); |
|
| 29 | + function get_cache($id); |
|
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * Check whether we have cached results for the provided id. |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * |
| 38 | 38 | * @return bool True if we have cached results otherwise false. |
| 39 | 39 | */ |
| 40 | - function has_cache( $id ); |
|
| 40 | + function has_cache($id); |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * Set the cache contents for the specified `id`. |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @param string $id The cache id. |
| 48 | 48 | * @param mixed $contents The cache contents. |
| 49 | 49 | */ |
| 50 | - function set_cache( $id, $contents ); |
|
| 50 | + function set_cache($id, $contents); |
|
| 51 | 51 | |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * |
| 58 | 58 | * @param string $id The cache `id`. |
| 59 | 59 | */ |
| 60 | - function delete_cache( $id ); |
|
| 60 | + function delete_cache($id); |
|
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | 63 | * Flush the whole cache. |
@@ -14,200 +14,200 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class Wordlift_Cached_Entity_Uri_Service extends Wordlift_Entity_Uri_Service { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * The {@link Wordlift_Cache_Service} instance. |
|
| 19 | - * |
|
| 20 | - * @since 3.16.3 |
|
| 21 | - * @access private |
|
| 22 | - * @var \Wordlift_Cache_Service $cache_service The {@link Wordlift_Cache_Service} instance. |
|
| 23 | - */ |
|
| 24 | - private $cache_service; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * A {@link Wordlift_Log_Service} instance. |
|
| 28 | - * |
|
| 29 | - * @since 3.16.3 |
|
| 30 | - * @access private |
|
| 31 | - * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 32 | - */ |
|
| 33 | - private $log; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Create a {@link Wordlift_Cached_Entity_Uri_Service} instance. |
|
| 37 | - * |
|
| 38 | - * @since 3.16.3 |
|
| 39 | - * |
|
| 40 | - * @param \Wordlift_Configuration_Service $configuration_service |
|
| 41 | - * @param \Wordlift_Cache_Service $cache_service |
|
| 42 | - */ |
|
| 43 | - public function __construct( $configuration_service, $cache_service ) { |
|
| 44 | - parent::__construct( $configuration_service ); |
|
| 45 | - |
|
| 46 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 47 | - |
|
| 48 | - // Add hooks for meta being added/modified/deleted. |
|
| 49 | - $this->cache_service = $cache_service; |
|
| 50 | - |
|
| 51 | - add_action( 'add_post_meta', array( |
|
| 52 | - $this, |
|
| 53 | - 'on_before_post_meta_add', |
|
| 54 | - ), 10, 3 ); |
|
| 55 | - add_action( 'update_post_meta', array( |
|
| 56 | - $this, |
|
| 57 | - 'on_before_post_meta_change', |
|
| 58 | - ), 10, 4 ); |
|
| 59 | - add_action( 'delete_post_meta', array( |
|
| 60 | - $this, |
|
| 61 | - 'on_before_post_meta_change', |
|
| 62 | - ), 10, 4 ); |
|
| 63 | - |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Preload the URIs. |
|
| 68 | - * |
|
| 69 | - * @since 3.16.3 |
|
| 70 | - * |
|
| 71 | - * @param array $uris Preload an array of URIs. |
|
| 72 | - */ |
|
| 73 | - public function preload_uris( $uris ) { |
|
| 74 | - |
|
| 75 | - // Filter the URIs which aren't yet cached. |
|
| 76 | - $cache_service = $this->cache_service; |
|
| 77 | - $uris_to_cache = array_filter( (array) $uris, function ( $item ) use ( $cache_service ) { |
|
| 78 | - return ! $cache_service->has_cache( $item ); |
|
| 79 | - } ); |
|
| 80 | - |
|
| 81 | - // Preload the URIs. |
|
| 82 | - parent::preload_uris( $uris_to_cache ); |
|
| 83 | - |
|
| 84 | - // Store them in cache. |
|
| 85 | - if ( is_array( $this->uri_to_post ) && ! empty( $this->uri_to_post ) ) { |
|
| 86 | - foreach ( $this->uri_to_post as $uri => $post ) { |
|
| 87 | - $this->set_cache( $uri, $post ); |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Get the entity post for the specified URI. |
|
| 95 | - * |
|
| 96 | - * @since 3.16.3 |
|
| 97 | - * |
|
| 98 | - * @param string $uri The URI. |
|
| 99 | - * |
|
| 100 | - * @return null|WP_Post The {@link WP_Post} or null if not found. |
|
| 101 | - */ |
|
| 102 | - public function get_entity( $uri ) { |
|
| 103 | - |
|
| 104 | - $this->log->trace( "Getting entity for uri $uri..." ); |
|
| 105 | - |
|
| 106 | - // Get the cached post for the specified URI. |
|
| 107 | - $cache = $this->cache_service->get_cache( $uri ); |
|
| 108 | - |
|
| 109 | - // Return the cached data if valid. |
|
| 110 | - if ( false !== $cache && is_numeric( $cache ) ) { |
|
| 111 | - $this->log->debug( "Cached entity $cache for uri $uri found." ); |
|
| 112 | - |
|
| 113 | - return get_post( $cache ); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - // Get the actual result. |
|
| 117 | - $post = parent::get_entity( $uri ); |
|
| 118 | - |
|
| 119 | - // Cache the result, if a post is not found we cache -1. |
|
| 120 | - $this->set_cache( $uri, $post ); |
|
| 121 | - |
|
| 122 | - // Return the result. |
|
| 123 | - return $post; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Set the cached URI for the specified {@link WP_Post}. |
|
| 128 | - * |
|
| 129 | - * @since 3.16.3 |
|
| 130 | - * |
|
| 131 | - * @param string $uri The URI. |
|
| 132 | - * @param WP_Post $post The post. |
|
| 133 | - */ |
|
| 134 | - private function set_cache( $uri, $post ) { |
|
| 135 | - |
|
| 136 | - // Cache the result, if a post is not found we cache -1. |
|
| 137 | - $this->cache_service->set_cache( $uri, ( null === $post ? - 1 : $post->ID ) ); |
|
| 138 | - |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Delete the cache for the specified URIs. |
|
| 143 | - * |
|
| 144 | - * @since 3.16.3 |
|
| 145 | - * |
|
| 146 | - * @param array $uris An array of URIs. |
|
| 147 | - */ |
|
| 148 | - private function delete_cache( $uris ) { |
|
| 149 | - |
|
| 150 | - // Delete the cache for each URI. |
|
| 151 | - foreach ( $uris as $uri ) { |
|
| 152 | - // Delete the single cache file. |
|
| 153 | - $this->cache_service->delete_cache( $uri ); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Before post meta change. |
|
| 160 | - * |
|
| 161 | - * When a post meta is going to be changed, we check if the `meta_key` is |
|
| 162 | - * either the `entity_url` or the `same_as` in which case we delete the cache |
|
| 163 | - * for all the associated URIs. |
|
| 164 | - * |
|
| 165 | - * @since 3.16.3 |
|
| 166 | - * |
|
| 167 | - * @param int|array $meta_ids The {@link WP_Post} meta id(s). |
|
| 168 | - * @param int $post_id The {@link WP_Post} id. |
|
| 169 | - * @param string $meta_key The meta key. |
|
| 170 | - * @param mixed $meta_value The meta value(s). |
|
| 171 | - */ |
|
| 172 | - public function on_before_post_meta_change( $meta_ids, $post_id, $meta_key, $meta_value ) { |
|
| 173 | - |
|
| 174 | - // Bail out if we're not interested in the meta key. |
|
| 175 | - if ( WL_ENTITY_URL_META_NAME !== $meta_key && Wordlift_Schema_Service::FIELD_SAME_AS !== $meta_key ) { |
|
| 176 | - return; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - $this->log->trace( "Updating/deleting $meta_key for post $post_id ($meta_key), invalidating cache..." ); |
|
| 180 | - |
|
| 181 | - // The list of existing URIs, plus the list of URIs being deleted/updated. |
|
| 182 | - $uris = get_post_meta( $post_id, $meta_key ) + (array) $meta_value; |
|
| 183 | - |
|
| 184 | - // Delete the cache for those URIs. |
|
| 185 | - $this->delete_cache( $uris ); |
|
| 186 | - |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Hook to meta add for a {@link WP_Post}, will cause the cache to |
|
| 191 | - * invalidate. |
|
| 192 | - * |
|
| 193 | - * @since 3.16.3 |
|
| 194 | - * |
|
| 195 | - * @param int $post_id The {@link WP_Post} id. |
|
| 196 | - * @param string $meta_key The meta key. |
|
| 197 | - * @param mixed $meta_value The meta value(s). |
|
| 198 | - */ |
|
| 199 | - public function on_before_post_meta_add( $post_id, $meta_key, $meta_value ) { |
|
| 200 | - |
|
| 201 | - // Bail out if we're not interested in the meta key. |
|
| 202 | - if ( WL_ENTITY_URL_META_NAME !== $meta_key && Wordlift_Schema_Service::FIELD_SAME_AS !== $meta_key ) { |
|
| 203 | - return; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - $this->log->trace( "Adding $meta_key for post $post_id ($meta_key), invalidating cache..." ); |
|
| 207 | - |
|
| 208 | - // Delete the cache for the URIs being added. |
|
| 209 | - $this->delete_cache( (array) $meta_value ); |
|
| 210 | - |
|
| 211 | - } |
|
| 17 | + /** |
|
| 18 | + * The {@link Wordlift_Cache_Service} instance. |
|
| 19 | + * |
|
| 20 | + * @since 3.16.3 |
|
| 21 | + * @access private |
|
| 22 | + * @var \Wordlift_Cache_Service $cache_service The {@link Wordlift_Cache_Service} instance. |
|
| 23 | + */ |
|
| 24 | + private $cache_service; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * A {@link Wordlift_Log_Service} instance. |
|
| 28 | + * |
|
| 29 | + * @since 3.16.3 |
|
| 30 | + * @access private |
|
| 31 | + * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 32 | + */ |
|
| 33 | + private $log; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Create a {@link Wordlift_Cached_Entity_Uri_Service} instance. |
|
| 37 | + * |
|
| 38 | + * @since 3.16.3 |
|
| 39 | + * |
|
| 40 | + * @param \Wordlift_Configuration_Service $configuration_service |
|
| 41 | + * @param \Wordlift_Cache_Service $cache_service |
|
| 42 | + */ |
|
| 43 | + public function __construct( $configuration_service, $cache_service ) { |
|
| 44 | + parent::__construct( $configuration_service ); |
|
| 45 | + |
|
| 46 | + $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 47 | + |
|
| 48 | + // Add hooks for meta being added/modified/deleted. |
|
| 49 | + $this->cache_service = $cache_service; |
|
| 50 | + |
|
| 51 | + add_action( 'add_post_meta', array( |
|
| 52 | + $this, |
|
| 53 | + 'on_before_post_meta_add', |
|
| 54 | + ), 10, 3 ); |
|
| 55 | + add_action( 'update_post_meta', array( |
|
| 56 | + $this, |
|
| 57 | + 'on_before_post_meta_change', |
|
| 58 | + ), 10, 4 ); |
|
| 59 | + add_action( 'delete_post_meta', array( |
|
| 60 | + $this, |
|
| 61 | + 'on_before_post_meta_change', |
|
| 62 | + ), 10, 4 ); |
|
| 63 | + |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Preload the URIs. |
|
| 68 | + * |
|
| 69 | + * @since 3.16.3 |
|
| 70 | + * |
|
| 71 | + * @param array $uris Preload an array of URIs. |
|
| 72 | + */ |
|
| 73 | + public function preload_uris( $uris ) { |
|
| 74 | + |
|
| 75 | + // Filter the URIs which aren't yet cached. |
|
| 76 | + $cache_service = $this->cache_service; |
|
| 77 | + $uris_to_cache = array_filter( (array) $uris, function ( $item ) use ( $cache_service ) { |
|
| 78 | + return ! $cache_service->has_cache( $item ); |
|
| 79 | + } ); |
|
| 80 | + |
|
| 81 | + // Preload the URIs. |
|
| 82 | + parent::preload_uris( $uris_to_cache ); |
|
| 83 | + |
|
| 84 | + // Store them in cache. |
|
| 85 | + if ( is_array( $this->uri_to_post ) && ! empty( $this->uri_to_post ) ) { |
|
| 86 | + foreach ( $this->uri_to_post as $uri => $post ) { |
|
| 87 | + $this->set_cache( $uri, $post ); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Get the entity post for the specified URI. |
|
| 95 | + * |
|
| 96 | + * @since 3.16.3 |
|
| 97 | + * |
|
| 98 | + * @param string $uri The URI. |
|
| 99 | + * |
|
| 100 | + * @return null|WP_Post The {@link WP_Post} or null if not found. |
|
| 101 | + */ |
|
| 102 | + public function get_entity( $uri ) { |
|
| 103 | + |
|
| 104 | + $this->log->trace( "Getting entity for uri $uri..." ); |
|
| 105 | + |
|
| 106 | + // Get the cached post for the specified URI. |
|
| 107 | + $cache = $this->cache_service->get_cache( $uri ); |
|
| 108 | + |
|
| 109 | + // Return the cached data if valid. |
|
| 110 | + if ( false !== $cache && is_numeric( $cache ) ) { |
|
| 111 | + $this->log->debug( "Cached entity $cache for uri $uri found." ); |
|
| 112 | + |
|
| 113 | + return get_post( $cache ); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + // Get the actual result. |
|
| 117 | + $post = parent::get_entity( $uri ); |
|
| 118 | + |
|
| 119 | + // Cache the result, if a post is not found we cache -1. |
|
| 120 | + $this->set_cache( $uri, $post ); |
|
| 121 | + |
|
| 122 | + // Return the result. |
|
| 123 | + return $post; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Set the cached URI for the specified {@link WP_Post}. |
|
| 128 | + * |
|
| 129 | + * @since 3.16.3 |
|
| 130 | + * |
|
| 131 | + * @param string $uri The URI. |
|
| 132 | + * @param WP_Post $post The post. |
|
| 133 | + */ |
|
| 134 | + private function set_cache( $uri, $post ) { |
|
| 135 | + |
|
| 136 | + // Cache the result, if a post is not found we cache -1. |
|
| 137 | + $this->cache_service->set_cache( $uri, ( null === $post ? - 1 : $post->ID ) ); |
|
| 138 | + |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Delete the cache for the specified URIs. |
|
| 143 | + * |
|
| 144 | + * @since 3.16.3 |
|
| 145 | + * |
|
| 146 | + * @param array $uris An array of URIs. |
|
| 147 | + */ |
|
| 148 | + private function delete_cache( $uris ) { |
|
| 149 | + |
|
| 150 | + // Delete the cache for each URI. |
|
| 151 | + foreach ( $uris as $uri ) { |
|
| 152 | + // Delete the single cache file. |
|
| 153 | + $this->cache_service->delete_cache( $uri ); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Before post meta change. |
|
| 160 | + * |
|
| 161 | + * When a post meta is going to be changed, we check if the `meta_key` is |
|
| 162 | + * either the `entity_url` or the `same_as` in which case we delete the cache |
|
| 163 | + * for all the associated URIs. |
|
| 164 | + * |
|
| 165 | + * @since 3.16.3 |
|
| 166 | + * |
|
| 167 | + * @param int|array $meta_ids The {@link WP_Post} meta id(s). |
|
| 168 | + * @param int $post_id The {@link WP_Post} id. |
|
| 169 | + * @param string $meta_key The meta key. |
|
| 170 | + * @param mixed $meta_value The meta value(s). |
|
| 171 | + */ |
|
| 172 | + public function on_before_post_meta_change( $meta_ids, $post_id, $meta_key, $meta_value ) { |
|
| 173 | + |
|
| 174 | + // Bail out if we're not interested in the meta key. |
|
| 175 | + if ( WL_ENTITY_URL_META_NAME !== $meta_key && Wordlift_Schema_Service::FIELD_SAME_AS !== $meta_key ) { |
|
| 176 | + return; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + $this->log->trace( "Updating/deleting $meta_key for post $post_id ($meta_key), invalidating cache..." ); |
|
| 180 | + |
|
| 181 | + // The list of existing URIs, plus the list of URIs being deleted/updated. |
|
| 182 | + $uris = get_post_meta( $post_id, $meta_key ) + (array) $meta_value; |
|
| 183 | + |
|
| 184 | + // Delete the cache for those URIs. |
|
| 185 | + $this->delete_cache( $uris ); |
|
| 186 | + |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Hook to meta add for a {@link WP_Post}, will cause the cache to |
|
| 191 | + * invalidate. |
|
| 192 | + * |
|
| 193 | + * @since 3.16.3 |
|
| 194 | + * |
|
| 195 | + * @param int $post_id The {@link WP_Post} id. |
|
| 196 | + * @param string $meta_key The meta key. |
|
| 197 | + * @param mixed $meta_value The meta value(s). |
|
| 198 | + */ |
|
| 199 | + public function on_before_post_meta_add( $post_id, $meta_key, $meta_value ) { |
|
| 200 | + |
|
| 201 | + // Bail out if we're not interested in the meta key. |
|
| 202 | + if ( WL_ENTITY_URL_META_NAME !== $meta_key && Wordlift_Schema_Service::FIELD_SAME_AS !== $meta_key ) { |
|
| 203 | + return; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + $this->log->trace( "Adding $meta_key for post $post_id ($meta_key), invalidating cache..." ); |
|
| 207 | + |
|
| 208 | + // Delete the cache for the URIs being added. |
|
| 209 | + $this->delete_cache( (array) $meta_value ); |
|
| 210 | + |
|
| 211 | + } |
|
| 212 | 212 | |
| 213 | 213 | } |
| 214 | 214 | \ No newline at end of file |
@@ -40,26 +40,26 @@ discard block |
||
| 40 | 40 | * @param \Wordlift_Configuration_Service $configuration_service |
| 41 | 41 | * @param \Wordlift_Cache_Service $cache_service |
| 42 | 42 | */ |
| 43 | - public function __construct( $configuration_service, $cache_service ) { |
|
| 44 | - parent::__construct( $configuration_service ); |
|
| 43 | + public function __construct($configuration_service, $cache_service) { |
|
| 44 | + parent::__construct($configuration_service); |
|
| 45 | 45 | |
| 46 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 46 | + $this->log = Wordlift_Log_Service::get_logger(get_class()); |
|
| 47 | 47 | |
| 48 | 48 | // Add hooks for meta being added/modified/deleted. |
| 49 | 49 | $this->cache_service = $cache_service; |
| 50 | 50 | |
| 51 | - add_action( 'add_post_meta', array( |
|
| 51 | + add_action('add_post_meta', array( |
|
| 52 | 52 | $this, |
| 53 | 53 | 'on_before_post_meta_add', |
| 54 | - ), 10, 3 ); |
|
| 55 | - add_action( 'update_post_meta', array( |
|
| 54 | + ), 10, 3); |
|
| 55 | + add_action('update_post_meta', array( |
|
| 56 | 56 | $this, |
| 57 | 57 | 'on_before_post_meta_change', |
| 58 | - ), 10, 4 ); |
|
| 59 | - add_action( 'delete_post_meta', array( |
|
| 58 | + ), 10, 4); |
|
| 59 | + add_action('delete_post_meta', array( |
|
| 60 | 60 | $this, |
| 61 | 61 | 'on_before_post_meta_change', |
| 62 | - ), 10, 4 ); |
|
| 62 | + ), 10, 4); |
|
| 63 | 63 | |
| 64 | 64 | } |
| 65 | 65 | |
@@ -70,21 +70,21 @@ discard block |
||
| 70 | 70 | * |
| 71 | 71 | * @param array $uris Preload an array of URIs. |
| 72 | 72 | */ |
| 73 | - public function preload_uris( $uris ) { |
|
| 73 | + public function preload_uris($uris) { |
|
| 74 | 74 | |
| 75 | 75 | // Filter the URIs which aren't yet cached. |
| 76 | 76 | $cache_service = $this->cache_service; |
| 77 | - $uris_to_cache = array_filter( (array) $uris, function ( $item ) use ( $cache_service ) { |
|
| 78 | - return ! $cache_service->has_cache( $item ); |
|
| 77 | + $uris_to_cache = array_filter((array) $uris, function($item) use ($cache_service) { |
|
| 78 | + return ! $cache_service->has_cache($item); |
|
| 79 | 79 | } ); |
| 80 | 80 | |
| 81 | 81 | // Preload the URIs. |
| 82 | - parent::preload_uris( $uris_to_cache ); |
|
| 82 | + parent::preload_uris($uris_to_cache); |
|
| 83 | 83 | |
| 84 | 84 | // Store them in cache. |
| 85 | - if ( is_array( $this->uri_to_post ) && ! empty( $this->uri_to_post ) ) { |
|
| 86 | - foreach ( $this->uri_to_post as $uri => $post ) { |
|
| 87 | - $this->set_cache( $uri, $post ); |
|
| 85 | + if (is_array($this->uri_to_post) && ! empty($this->uri_to_post)) { |
|
| 86 | + foreach ($this->uri_to_post as $uri => $post) { |
|
| 87 | + $this->set_cache($uri, $post); |
|
| 88 | 88 | } |
| 89 | 89 | } |
| 90 | 90 | |
@@ -99,25 +99,25 @@ discard block |
||
| 99 | 99 | * |
| 100 | 100 | * @return null|WP_Post The {@link WP_Post} or null if not found. |
| 101 | 101 | */ |
| 102 | - public function get_entity( $uri ) { |
|
| 102 | + public function get_entity($uri) { |
|
| 103 | 103 | |
| 104 | - $this->log->trace( "Getting entity for uri $uri..." ); |
|
| 104 | + $this->log->trace("Getting entity for uri $uri..."); |
|
| 105 | 105 | |
| 106 | 106 | // Get the cached post for the specified URI. |
| 107 | - $cache = $this->cache_service->get_cache( $uri ); |
|
| 107 | + $cache = $this->cache_service->get_cache($uri); |
|
| 108 | 108 | |
| 109 | 109 | // Return the cached data if valid. |
| 110 | - if ( false !== $cache && is_numeric( $cache ) ) { |
|
| 111 | - $this->log->debug( "Cached entity $cache for uri $uri found." ); |
|
| 110 | + if (false !== $cache && is_numeric($cache)) { |
|
| 111 | + $this->log->debug("Cached entity $cache for uri $uri found."); |
|
| 112 | 112 | |
| 113 | - return get_post( $cache ); |
|
| 113 | + return get_post($cache); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | // Get the actual result. |
| 117 | - $post = parent::get_entity( $uri ); |
|
| 117 | + $post = parent::get_entity($uri); |
|
| 118 | 118 | |
| 119 | 119 | // Cache the result, if a post is not found we cache -1. |
| 120 | - $this->set_cache( $uri, $post ); |
|
| 120 | + $this->set_cache($uri, $post); |
|
| 121 | 121 | |
| 122 | 122 | // Return the result. |
| 123 | 123 | return $post; |
@@ -131,10 +131,10 @@ discard block |
||
| 131 | 131 | * @param string $uri The URI. |
| 132 | 132 | * @param WP_Post $post The post. |
| 133 | 133 | */ |
| 134 | - private function set_cache( $uri, $post ) { |
|
| 134 | + private function set_cache($uri, $post) { |
|
| 135 | 135 | |
| 136 | 136 | // Cache the result, if a post is not found we cache -1. |
| 137 | - $this->cache_service->set_cache( $uri, ( null === $post ? - 1 : $post->ID ) ); |
|
| 137 | + $this->cache_service->set_cache($uri, (null === $post ? -1 : $post->ID)); |
|
| 138 | 138 | |
| 139 | 139 | } |
| 140 | 140 | |
@@ -145,12 +145,12 @@ discard block |
||
| 145 | 145 | * |
| 146 | 146 | * @param array $uris An array of URIs. |
| 147 | 147 | */ |
| 148 | - private function delete_cache( $uris ) { |
|
| 148 | + private function delete_cache($uris) { |
|
| 149 | 149 | |
| 150 | 150 | // Delete the cache for each URI. |
| 151 | - foreach ( $uris as $uri ) { |
|
| 151 | + foreach ($uris as $uri) { |
|
| 152 | 152 | // Delete the single cache file. |
| 153 | - $this->cache_service->delete_cache( $uri ); |
|
| 153 | + $this->cache_service->delete_cache($uri); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | } |
@@ -169,20 +169,20 @@ discard block |
||
| 169 | 169 | * @param string $meta_key The meta key. |
| 170 | 170 | * @param mixed $meta_value The meta value(s). |
| 171 | 171 | */ |
| 172 | - public function on_before_post_meta_change( $meta_ids, $post_id, $meta_key, $meta_value ) { |
|
| 172 | + public function on_before_post_meta_change($meta_ids, $post_id, $meta_key, $meta_value) { |
|
| 173 | 173 | |
| 174 | 174 | // Bail out if we're not interested in the meta key. |
| 175 | - if ( WL_ENTITY_URL_META_NAME !== $meta_key && Wordlift_Schema_Service::FIELD_SAME_AS !== $meta_key ) { |
|
| 175 | + if (WL_ENTITY_URL_META_NAME !== $meta_key && Wordlift_Schema_Service::FIELD_SAME_AS !== $meta_key) { |
|
| 176 | 176 | return; |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - $this->log->trace( "Updating/deleting $meta_key for post $post_id ($meta_key), invalidating cache..." ); |
|
| 179 | + $this->log->trace("Updating/deleting $meta_key for post $post_id ($meta_key), invalidating cache..."); |
|
| 180 | 180 | |
| 181 | 181 | // The list of existing URIs, plus the list of URIs being deleted/updated. |
| 182 | - $uris = get_post_meta( $post_id, $meta_key ) + (array) $meta_value; |
|
| 182 | + $uris = get_post_meta($post_id, $meta_key) + (array) $meta_value; |
|
| 183 | 183 | |
| 184 | 184 | // Delete the cache for those URIs. |
| 185 | - $this->delete_cache( $uris ); |
|
| 185 | + $this->delete_cache($uris); |
|
| 186 | 186 | |
| 187 | 187 | } |
| 188 | 188 | |
@@ -196,17 +196,17 @@ discard block |
||
| 196 | 196 | * @param string $meta_key The meta key. |
| 197 | 197 | * @param mixed $meta_value The meta value(s). |
| 198 | 198 | */ |
| 199 | - public function on_before_post_meta_add( $post_id, $meta_key, $meta_value ) { |
|
| 199 | + public function on_before_post_meta_add($post_id, $meta_key, $meta_value) { |
|
| 200 | 200 | |
| 201 | 201 | // Bail out if we're not interested in the meta key. |
| 202 | - if ( WL_ENTITY_URL_META_NAME !== $meta_key && Wordlift_Schema_Service::FIELD_SAME_AS !== $meta_key ) { |
|
| 202 | + if (WL_ENTITY_URL_META_NAME !== $meta_key && Wordlift_Schema_Service::FIELD_SAME_AS !== $meta_key) { |
|
| 203 | 203 | return; |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - $this->log->trace( "Adding $meta_key for post $post_id ($meta_key), invalidating cache..." ); |
|
| 206 | + $this->log->trace("Adding $meta_key for post $post_id ($meta_key), invalidating cache..."); |
|
| 207 | 207 | |
| 208 | 208 | // Delete the cache for the URIs being added. |
| 209 | - $this->delete_cache( (array) $meta_value ); |
|
| 209 | + $this->delete_cache((array) $meta_value); |
|
| 210 | 210 | |
| 211 | 211 | } |
| 212 | 212 | |
@@ -18,15 +18,15 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | interface Wordlift_Admin_Element { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Render the element. |
|
| 23 | - * |
|
| 24 | - * @since 3.11.0 |
|
| 25 | - * |
|
| 26 | - * @param array $args An array of parameters. |
|
| 27 | - * |
|
| 28 | - * @return \Wordlift_Admin_Element The element instance. |
|
| 29 | - */ |
|
| 30 | - public function render( $args ); |
|
| 21 | + /** |
|
| 22 | + * Render the element. |
|
| 23 | + * |
|
| 24 | + * @since 3.11.0 |
|
| 25 | + * |
|
| 26 | + * @param array $args An array of parameters. |
|
| 27 | + * |
|
| 28 | + * @return \Wordlift_Admin_Element The element instance. |
|
| 29 | + */ |
|
| 30 | + public function render( $args ); |
|
| 31 | 31 | |
| 32 | 32 | } |
@@ -27,6 +27,6 @@ |
||
| 27 | 27 | * |
| 28 | 28 | * @return \Wordlift_Admin_Element The element instance. |
| 29 | 29 | */ |
| 30 | - public function render( $args ); |
|
| 30 | + public function render($args); |
|
| 31 | 31 | |
| 32 | 32 | } |
@@ -16,178 +16,178 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class Wordlift_Batch_Analysis_Adapter { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * A {@link Wordlift_Log_Service} instance. |
|
| 21 | - * |
|
| 22 | - * @since 3.17.0 |
|
| 23 | - * @access private |
|
| 24 | - * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 25 | - */ |
|
| 26 | - private $log; |
|
| 19 | + /** |
|
| 20 | + * A {@link Wordlift_Log_Service} instance. |
|
| 21 | + * |
|
| 22 | + * @since 3.17.0 |
|
| 23 | + * @access private |
|
| 24 | + * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 25 | + */ |
|
| 26 | + private $log; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * The {@link Wordlift_Batch_Analysis_Service} instance. |
|
| 30 | - * |
|
| 31 | - * @since 3.17.0 |
|
| 32 | - * @access private |
|
| 33 | - * @var \Wordlift_Batch_Analysis_Service $batch_analysis_service The {@link Wordlift_Batch_Analysis_Service} instance. |
|
| 34 | - */ |
|
| 35 | - private $batch_analysis_service; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Wordlift_Batch_Analysis_Adapter constructor. |
|
| 39 | - * |
|
| 40 | - * @since 3.14.2 |
|
| 41 | - * |
|
| 42 | - * @param \Wordlift_Batch_Analysis_Service $batch_analysis_service |
|
| 43 | - */ |
|
| 44 | - public function __construct( $batch_analysis_service ) { |
|
| 45 | - |
|
| 46 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 47 | - |
|
| 48 | - $this->batch_analysis_service = $batch_analysis_service; |
|
| 49 | - |
|
| 50 | - add_action( 'wp_ajax_wl_batch_analysis_complete', array( |
|
| 51 | - $this, |
|
| 52 | - 'complete', |
|
| 53 | - ) ); |
|
| 54 | - |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Submit the posts for batch analysis. |
|
| 59 | - * |
|
| 60 | - * @since 3.14.2 |
|
| 61 | - */ |
|
| 62 | - public function submit() { |
|
| 63 | - |
|
| 64 | - // Get the parameters from the $_REQUEST. |
|
| 65 | - $params = self::create_params_from_request(); |
|
| 66 | - |
|
| 67 | - // Submit the request. |
|
| 68 | - $count = $this->batch_analysis_service->submit( $params ); |
|
| 69 | - |
|
| 70 | - // Clear any buffer. |
|
| 71 | - ob_clean(); |
|
| 72 | - |
|
| 73 | - // Send the response. |
|
| 74 | - wp_send_json_success( array( 'count' => $count ) ); |
|
| 75 | - |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Submit the posts for batch analysis. |
|
| 80 | - * |
|
| 81 | - * @since 3.14.2 |
|
| 82 | - */ |
|
| 83 | - public function submit_posts() { |
|
| 84 | - |
|
| 85 | - $this->log->trace( 'Received Batch Analysis request for posts...' ); |
|
| 86 | - |
|
| 87 | - if ( empty( $_REQUEST['post'] ) ) { |
|
| 88 | - $this->log->error( 'Batch Analysis request for posts missing the post(s) id.' ); |
|
| 89 | - |
|
| 90 | - wp_send_json_error( 'The `post` parameter is required.' ); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - // Get the parameters from the $_REQUEST. |
|
| 94 | - $params = self::create_params_from_request(); |
|
| 95 | - |
|
| 96 | - // Submit the request. |
|
| 97 | - $count = $this->batch_analysis_service->submit_posts( $params ); |
|
| 98 | - |
|
| 99 | - // Clear any buffer. |
|
| 100 | - ob_clean(); |
|
| 101 | - |
|
| 102 | - // Send the response. |
|
| 103 | - wp_send_json_success( array( 'count' => $count ) ); |
|
| 104 | - |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - public function complete() { |
|
| 108 | - |
|
| 109 | - $this->batch_analysis_service->complete(); |
|
| 110 | - |
|
| 111 | - wp_send_json_success(); |
|
| 112 | - |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * A helper function to create the parameters from the $_REQUEST. |
|
| 118 | - * |
|
| 119 | - * @since 3.17.0 |
|
| 120 | - * |
|
| 121 | - * @return array An array or parameters. |
|
| 122 | - */ |
|
| 123 | - private static function create_params_from_request() { |
|
| 28 | + /** |
|
| 29 | + * The {@link Wordlift_Batch_Analysis_Service} instance. |
|
| 30 | + * |
|
| 31 | + * @since 3.17.0 |
|
| 32 | + * @access private |
|
| 33 | + * @var \Wordlift_Batch_Analysis_Service $batch_analysis_service The {@link Wordlift_Batch_Analysis_Service} instance. |
|
| 34 | + */ |
|
| 35 | + private $batch_analysis_service; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Wordlift_Batch_Analysis_Adapter constructor. |
|
| 39 | + * |
|
| 40 | + * @since 3.14.2 |
|
| 41 | + * |
|
| 42 | + * @param \Wordlift_Batch_Analysis_Service $batch_analysis_service |
|
| 43 | + */ |
|
| 44 | + public function __construct( $batch_analysis_service ) { |
|
| 45 | + |
|
| 46 | + $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 47 | + |
|
| 48 | + $this->batch_analysis_service = $batch_analysis_service; |
|
| 49 | + |
|
| 50 | + add_action( 'wp_ajax_wl_batch_analysis_complete', array( |
|
| 51 | + $this, |
|
| 52 | + 'complete', |
|
| 53 | + ) ); |
|
| 54 | + |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Submit the posts for batch analysis. |
|
| 59 | + * |
|
| 60 | + * @since 3.14.2 |
|
| 61 | + */ |
|
| 62 | + public function submit() { |
|
| 63 | + |
|
| 64 | + // Get the parameters from the $_REQUEST. |
|
| 65 | + $params = self::create_params_from_request(); |
|
| 66 | + |
|
| 67 | + // Submit the request. |
|
| 68 | + $count = $this->batch_analysis_service->submit( $params ); |
|
| 69 | + |
|
| 70 | + // Clear any buffer. |
|
| 71 | + ob_clean(); |
|
| 72 | + |
|
| 73 | + // Send the response. |
|
| 74 | + wp_send_json_success( array( 'count' => $count ) ); |
|
| 75 | + |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Submit the posts for batch analysis. |
|
| 80 | + * |
|
| 81 | + * @since 3.14.2 |
|
| 82 | + */ |
|
| 83 | + public function submit_posts() { |
|
| 84 | + |
|
| 85 | + $this->log->trace( 'Received Batch Analysis request for posts...' ); |
|
| 86 | + |
|
| 87 | + if ( empty( $_REQUEST['post'] ) ) { |
|
| 88 | + $this->log->error( 'Batch Analysis request for posts missing the post(s) id.' ); |
|
| 89 | + |
|
| 90 | + wp_send_json_error( 'The `post` parameter is required.' ); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + // Get the parameters from the $_REQUEST. |
|
| 94 | + $params = self::create_params_from_request(); |
|
| 95 | + |
|
| 96 | + // Submit the request. |
|
| 97 | + $count = $this->batch_analysis_service->submit_posts( $params ); |
|
| 98 | + |
|
| 99 | + // Clear any buffer. |
|
| 100 | + ob_clean(); |
|
| 101 | + |
|
| 102 | + // Send the response. |
|
| 103 | + wp_send_json_success( array( 'count' => $count ) ); |
|
| 104 | + |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + public function complete() { |
|
| 108 | + |
|
| 109 | + $this->batch_analysis_service->complete(); |
|
| 110 | + |
|
| 111 | + wp_send_json_success(); |
|
| 112 | + |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * A helper function to create the parameters from the $_REQUEST. |
|
| 118 | + * |
|
| 119 | + * @since 3.17.0 |
|
| 120 | + * |
|
| 121 | + * @return array An array or parameters. |
|
| 122 | + */ |
|
| 123 | + private static function create_params_from_request() { |
|
| 124 | 124 | |
| 125 | - // Build params array and check if param exists. |
|
| 126 | - // @codingStandardsIgnoreStart, Ignore phpcs indentation errors. |
|
| 127 | - $params = array( |
|
| 128 | - // Get the `links` parameter, or use `default` if not provided. |
|
| 129 | - 'links' => isset( $_REQUEST['links'] ) ? $_REQUEST['links'] : 'default', |
|
| 130 | - // If `include_annotated` is set to `yes`, the set the parameter to true. |
|
| 131 | - 'include_annotated' => isset( $_REQUEST['include_annotated'] ) && 'yes' === $_REQUEST['include_annotated'], |
|
| 132 | - // Set the minimum amount of occurrences, use `1` by default. |
|
| 133 | - 'min_occurrences' => isset( $_REQUEST['min_occurrences'] ) && is_numeric( $_REQUEST['min_occurrences'] ) ? intval( $_REQUEST['min_occurrences'] ) : 1, |
|
| 134 | - // Set the `post_type` to `post` if none provided. |
|
| 135 | - 'post_type' => isset( $_REQUEST['post_type'] ) ? (array) $_REQUEST['post_type'] : 'post', |
|
| 136 | - // Set the exclude array. |
|
| 137 | - 'exclude' => isset( $_REQUEST['exclude'] ) ? (array) $_REQUEST['exclude'] : array(), |
|
| 138 | - // Set the `from` date, or null if not provided. |
|
| 139 | - 'from' => isset( $_REQUEST['from'] ) ? $_REQUEST['from'] : null, |
|
| 140 | - // Set the `to` date, or null if not provided. |
|
| 141 | - 'to' => isset( $_REQUEST['to'] ) ? $_REQUEST['to'] : null, |
|
| 142 | - // |
|
| 143 | - 'ids' => isset( $_REQUEST['post'] ) ? wp_parse_id_list( (array) $_REQUEST['post'] ) : array(), |
|
| 144 | - ); |
|
| 125 | + // Build params array and check if param exists. |
|
| 126 | + // @codingStandardsIgnoreStart, Ignore phpcs indentation errors. |
|
| 127 | + $params = array( |
|
| 128 | + // Get the `links` parameter, or use `default` if not provided. |
|
| 129 | + 'links' => isset( $_REQUEST['links'] ) ? $_REQUEST['links'] : 'default', |
|
| 130 | + // If `include_annotated` is set to `yes`, the set the parameter to true. |
|
| 131 | + 'include_annotated' => isset( $_REQUEST['include_annotated'] ) && 'yes' === $_REQUEST['include_annotated'], |
|
| 132 | + // Set the minimum amount of occurrences, use `1` by default. |
|
| 133 | + 'min_occurrences' => isset( $_REQUEST['min_occurrences'] ) && is_numeric( $_REQUEST['min_occurrences'] ) ? intval( $_REQUEST['min_occurrences'] ) : 1, |
|
| 134 | + // Set the `post_type` to `post` if none provided. |
|
| 135 | + 'post_type' => isset( $_REQUEST['post_type'] ) ? (array) $_REQUEST['post_type'] : 'post', |
|
| 136 | + // Set the exclude array. |
|
| 137 | + 'exclude' => isset( $_REQUEST['exclude'] ) ? (array) $_REQUEST['exclude'] : array(), |
|
| 138 | + // Set the `from` date, or null if not provided. |
|
| 139 | + 'from' => isset( $_REQUEST['from'] ) ? $_REQUEST['from'] : null, |
|
| 140 | + // Set the `to` date, or null if not provided. |
|
| 141 | + 'to' => isset( $_REQUEST['to'] ) ? $_REQUEST['to'] : null, |
|
| 142 | + // |
|
| 143 | + 'ids' => isset( $_REQUEST['post'] ) ? wp_parse_id_list( (array) $_REQUEST['post'] ) : array(), |
|
| 144 | + ); |
|
| 145 | 145 | |
| 146 | - // @codingStandardsIgnoreEnd |
|
| 146 | + // @codingStandardsIgnoreEnd |
|
| 147 | 147 | |
| 148 | - return $params; |
|
| 149 | - } |
|
| 148 | + return $params; |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * Cancel the batch analysis for the specified post. |
|
| 153 | - * |
|
| 154 | - * @since 3.14.0 |
|
| 155 | - */ |
|
| 156 | - public function cancel() { |
|
| 151 | + /** |
|
| 152 | + * Cancel the batch analysis for the specified post. |
|
| 153 | + * |
|
| 154 | + * @since 3.14.0 |
|
| 155 | + */ |
|
| 156 | + public function cancel() { |
|
| 157 | 157 | |
| 158 | - if ( ! isset( $_REQUEST['post'] ) ) { |
|
| 159 | - wp_die( 'The `post` parameter is required.' ); |
|
| 160 | - } |
|
| 158 | + if ( ! isset( $_REQUEST['post'] ) ) { |
|
| 159 | + wp_die( 'The `post` parameter is required.' ); |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - $count = $this->batch_analysis_service->cancel( (array) $_REQUEST['post'] ); |
|
| 162 | + $count = $this->batch_analysis_service->cancel( (array) $_REQUEST['post'] ); |
|
| 163 | 163 | |
| 164 | - // Clear any buffer. |
|
| 165 | - ob_clean(); |
|
| 164 | + // Clear any buffer. |
|
| 165 | + ob_clean(); |
|
| 166 | 166 | |
| 167 | - // Send the response. |
|
| 168 | - wp_send_json_success( array( 'count' => $count ) ); |
|
| 167 | + // Send the response. |
|
| 168 | + wp_send_json_success( array( 'count' => $count ) ); |
|
| 169 | 169 | |
| 170 | - } |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | - /** |
|
| 173 | - * Clear warnings for the specified post. |
|
| 174 | - * |
|
| 175 | - * @since 3.14.0 |
|
| 176 | - */ |
|
| 177 | - public function clear_warning() { |
|
| 172 | + /** |
|
| 173 | + * Clear warnings for the specified post. |
|
| 174 | + * |
|
| 175 | + * @since 3.14.0 |
|
| 176 | + */ |
|
| 177 | + public function clear_warning() { |
|
| 178 | 178 | |
| 179 | - if ( ! isset( $_REQUEST['post'] ) ) { |
|
| 180 | - wp_die( 'The `post` parameter is required.' ); |
|
| 181 | - } |
|
| 179 | + if ( ! isset( $_REQUEST['post'] ) ) { |
|
| 180 | + wp_die( 'The `post` parameter is required.' ); |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - $this->batch_analysis_service->clear_warning( (array) $_REQUEST['post'] ); |
|
| 183 | + $this->batch_analysis_service->clear_warning( (array) $_REQUEST['post'] ); |
|
| 184 | 184 | |
| 185 | - // Clear any buffer. |
|
| 186 | - ob_clean(); |
|
| 185 | + // Clear any buffer. |
|
| 186 | + ob_clean(); |
|
| 187 | 187 | |
| 188 | - // Send the response. |
|
| 189 | - wp_send_json_success(); |
|
| 188 | + // Send the response. |
|
| 189 | + wp_send_json_success(); |
|
| 190 | 190 | |
| 191 | - } |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | 193 | } |
@@ -41,16 +41,16 @@ discard block |
||
| 41 | 41 | * |
| 42 | 42 | * @param \Wordlift_Batch_Analysis_Service $batch_analysis_service |
| 43 | 43 | */ |
| 44 | - public function __construct( $batch_analysis_service ) { |
|
| 44 | + public function __construct($batch_analysis_service) { |
|
| 45 | 45 | |
| 46 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 46 | + $this->log = Wordlift_Log_Service::get_logger(get_class()); |
|
| 47 | 47 | |
| 48 | 48 | $this->batch_analysis_service = $batch_analysis_service; |
| 49 | 49 | |
| 50 | - add_action( 'wp_ajax_wl_batch_analysis_complete', array( |
|
| 50 | + add_action('wp_ajax_wl_batch_analysis_complete', array( |
|
| 51 | 51 | $this, |
| 52 | 52 | 'complete', |
| 53 | - ) ); |
|
| 53 | + )); |
|
| 54 | 54 | |
| 55 | 55 | } |
| 56 | 56 | |
@@ -65,13 +65,13 @@ discard block |
||
| 65 | 65 | $params = self::create_params_from_request(); |
| 66 | 66 | |
| 67 | 67 | // Submit the request. |
| 68 | - $count = $this->batch_analysis_service->submit( $params ); |
|
| 68 | + $count = $this->batch_analysis_service->submit($params); |
|
| 69 | 69 | |
| 70 | 70 | // Clear any buffer. |
| 71 | 71 | ob_clean(); |
| 72 | 72 | |
| 73 | 73 | // Send the response. |
| 74 | - wp_send_json_success( array( 'count' => $count ) ); |
|
| 74 | + wp_send_json_success(array('count' => $count)); |
|
| 75 | 75 | |
| 76 | 76 | } |
| 77 | 77 | |
@@ -82,25 +82,25 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | public function submit_posts() { |
| 84 | 84 | |
| 85 | - $this->log->trace( 'Received Batch Analysis request for posts...' ); |
|
| 85 | + $this->log->trace('Received Batch Analysis request for posts...'); |
|
| 86 | 86 | |
| 87 | - if ( empty( $_REQUEST['post'] ) ) { |
|
| 88 | - $this->log->error( 'Batch Analysis request for posts missing the post(s) id.' ); |
|
| 87 | + if (empty($_REQUEST['post'])) { |
|
| 88 | + $this->log->error('Batch Analysis request for posts missing the post(s) id.'); |
|
| 89 | 89 | |
| 90 | - wp_send_json_error( 'The `post` parameter is required.' ); |
|
| 90 | + wp_send_json_error('The `post` parameter is required.'); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | // Get the parameters from the $_REQUEST. |
| 94 | 94 | $params = self::create_params_from_request(); |
| 95 | 95 | |
| 96 | 96 | // Submit the request. |
| 97 | - $count = $this->batch_analysis_service->submit_posts( $params ); |
|
| 97 | + $count = $this->batch_analysis_service->submit_posts($params); |
|
| 98 | 98 | |
| 99 | 99 | // Clear any buffer. |
| 100 | 100 | ob_clean(); |
| 101 | 101 | |
| 102 | 102 | // Send the response. |
| 103 | - wp_send_json_success( array( 'count' => $count ) ); |
|
| 103 | + wp_send_json_success(array('count' => $count)); |
|
| 104 | 104 | |
| 105 | 105 | } |
| 106 | 106 | |
@@ -126,21 +126,21 @@ discard block |
||
| 126 | 126 | // @codingStandardsIgnoreStart, Ignore phpcs indentation errors. |
| 127 | 127 | $params = array( |
| 128 | 128 | // Get the `links` parameter, or use `default` if not provided. |
| 129 | - 'links' => isset( $_REQUEST['links'] ) ? $_REQUEST['links'] : 'default', |
|
| 129 | + 'links' => isset($_REQUEST['links']) ? $_REQUEST['links'] : 'default', |
|
| 130 | 130 | // If `include_annotated` is set to `yes`, the set the parameter to true. |
| 131 | - 'include_annotated' => isset( $_REQUEST['include_annotated'] ) && 'yes' === $_REQUEST['include_annotated'], |
|
| 131 | + 'include_annotated' => isset($_REQUEST['include_annotated']) && 'yes' === $_REQUEST['include_annotated'], |
|
| 132 | 132 | // Set the minimum amount of occurrences, use `1` by default. |
| 133 | - 'min_occurrences' => isset( $_REQUEST['min_occurrences'] ) && is_numeric( $_REQUEST['min_occurrences'] ) ? intval( $_REQUEST['min_occurrences'] ) : 1, |
|
| 133 | + 'min_occurrences' => isset($_REQUEST['min_occurrences']) && is_numeric($_REQUEST['min_occurrences']) ? intval($_REQUEST['min_occurrences']) : 1, |
|
| 134 | 134 | // Set the `post_type` to `post` if none provided. |
| 135 | - 'post_type' => isset( $_REQUEST['post_type'] ) ? (array) $_REQUEST['post_type'] : 'post', |
|
| 135 | + 'post_type' => isset($_REQUEST['post_type']) ? (array) $_REQUEST['post_type'] : 'post', |
|
| 136 | 136 | // Set the exclude array. |
| 137 | - 'exclude' => isset( $_REQUEST['exclude'] ) ? (array) $_REQUEST['exclude'] : array(), |
|
| 137 | + 'exclude' => isset($_REQUEST['exclude']) ? (array) $_REQUEST['exclude'] : array(), |
|
| 138 | 138 | // Set the `from` date, or null if not provided. |
| 139 | - 'from' => isset( $_REQUEST['from'] ) ? $_REQUEST['from'] : null, |
|
| 139 | + 'from' => isset($_REQUEST['from']) ? $_REQUEST['from'] : null, |
|
| 140 | 140 | // Set the `to` date, or null if not provided. |
| 141 | - 'to' => isset( $_REQUEST['to'] ) ? $_REQUEST['to'] : null, |
|
| 141 | + 'to' => isset($_REQUEST['to']) ? $_REQUEST['to'] : null, |
|
| 142 | 142 | // |
| 143 | - 'ids' => isset( $_REQUEST['post'] ) ? wp_parse_id_list( (array) $_REQUEST['post'] ) : array(), |
|
| 143 | + 'ids' => isset($_REQUEST['post']) ? wp_parse_id_list((array) $_REQUEST['post']) : array(), |
|
| 144 | 144 | ); |
| 145 | 145 | |
| 146 | 146 | // @codingStandardsIgnoreEnd |
@@ -155,17 +155,17 @@ discard block |
||
| 155 | 155 | */ |
| 156 | 156 | public function cancel() { |
| 157 | 157 | |
| 158 | - if ( ! isset( $_REQUEST['post'] ) ) { |
|
| 159 | - wp_die( 'The `post` parameter is required.' ); |
|
| 158 | + if ( ! isset($_REQUEST['post'])) { |
|
| 159 | + wp_die('The `post` parameter is required.'); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - $count = $this->batch_analysis_service->cancel( (array) $_REQUEST['post'] ); |
|
| 162 | + $count = $this->batch_analysis_service->cancel((array) $_REQUEST['post']); |
|
| 163 | 163 | |
| 164 | 164 | // Clear any buffer. |
| 165 | 165 | ob_clean(); |
| 166 | 166 | |
| 167 | 167 | // Send the response. |
| 168 | - wp_send_json_success( array( 'count' => $count ) ); |
|
| 168 | + wp_send_json_success(array('count' => $count)); |
|
| 169 | 169 | |
| 170 | 170 | } |
| 171 | 171 | |
@@ -176,11 +176,11 @@ discard block |
||
| 176 | 176 | */ |
| 177 | 177 | public function clear_warning() { |
| 178 | 178 | |
| 179 | - if ( ! isset( $_REQUEST['post'] ) ) { |
|
| 180 | - wp_die( 'The `post` parameter is required.' ); |
|
| 179 | + if ( ! isset($_REQUEST['post'])) { |
|
| 180 | + wp_die('The `post` parameter is required.'); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | - $this->batch_analysis_service->clear_warning( (array) $_REQUEST['post'] ); |
|
| 183 | + $this->batch_analysis_service->clear_warning((array) $_REQUEST['post']); |
|
| 184 | 184 | |
| 185 | 185 | // Clear any buffer. |
| 186 | 186 | ob_clean(); |
@@ -90,7 +90,7 @@ |
||
| 90 | 90 | * |
| 91 | 91 | * @since 3.18.0 |
| 92 | 92 | * |
| 93 | - * @return string|bool The file extension on success and |
|
| 93 | + * @return string|false The file extension on success and |
|
| 94 | 94 | * false on fail or if the content type is not supported. |
| 95 | 95 | */ |
| 96 | 96 | private static function get_extension_from_content_type( $content_type ) { |
@@ -8,138 +8,138 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class Wordlift_Remote_Image_Service { |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * Save the image with the specified URL locally. |
|
| 13 | - * |
|
| 14 | - * @param string $url The image remote URL. |
|
| 15 | - * |
|
| 16 | - * @since 3.18.0 |
|
| 17 | - * |
|
| 18 | - * @return array|false An array with information about the saved image (*path*: the local path to the image, *url*: the local |
|
| 19 | - * url, *content_type*: the image content type) or false on error. |
|
| 20 | - */ |
|
| 21 | - public static function save_from_url( $url ) { |
|
| 22 | - |
|
| 23 | - // Required for REST API calls |
|
| 24 | - if ( ! function_exists( 'WP_Filesystem' ) ) { |
|
| 25 | - require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
| 26 | - } |
|
| 27 | - // Load `WP_Filesystem`. |
|
| 28 | - WP_Filesystem(); |
|
| 29 | - global $wp_filesystem; |
|
| 30 | - |
|
| 31 | - // Parse the url. |
|
| 32 | - $parts = wp_parse_url( $url ); |
|
| 33 | - |
|
| 34 | - // Get the bare filename (filename w/o the extension). |
|
| 35 | - $basename = pathinfo( $parts['path'], PATHINFO_FILENAME ); |
|
| 36 | - |
|
| 37 | - // Get the base dir. |
|
| 38 | - $wp_upload_dir = wp_upload_dir(); |
|
| 39 | - |
|
| 40 | - // Set the upload directory and URL. |
|
| 41 | - $upload_dir = $wp_upload_dir['basedir'] . '/wl' . $wp_upload_dir['subdir']; |
|
| 42 | - $upload_url = $wp_upload_dir['baseurl'] . '/wl' . $wp_upload_dir['subdir']; |
|
| 43 | - |
|
| 44 | - // Get the full path to the local filename. |
|
| 45 | - $image_full_path = $upload_dir . '/' . $basename; |
|
| 46 | - $image_full_url = $upload_url . '/' . $basename; |
|
| 47 | - |
|
| 48 | - // Create custom directory and bail on failure. |
|
| 49 | - if ( ! wp_mkdir_p( $upload_dir ) ) { |
|
| 50 | - wl_write_log( "save_image_from_url : failed creating upload dir $upload_dir \n" ); |
|
| 51 | - |
|
| 52 | - return false; |
|
| 53 | - }; |
|
| 54 | - |
|
| 55 | - $response = self::get_response( $url ); |
|
| 56 | - |
|
| 57 | - // Bail if the response is not set. |
|
| 58 | - if ( false === $response ) { |
|
| 59 | - wl_write_log( "save_image_from_url : failed to fetch the response from: $url \n" ); |
|
| 60 | - |
|
| 61 | - return false; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - // Get the content type of response. |
|
| 65 | - $content_type = wp_remote_retrieve_header( $response, 'content-type' ); |
|
| 66 | - |
|
| 67 | - // Get the file extension. |
|
| 68 | - $extension = self::get_extension_from_content_type( $content_type ); |
|
| 69 | - |
|
| 70 | - // Bail if the content type is not supported. |
|
| 71 | - if ( empty( $extension ) ) { |
|
| 72 | - return false; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - // Complete the local filename. |
|
| 76 | - $image_full_path .= $extension; |
|
| 77 | - $image_full_url .= $extension; |
|
| 78 | - |
|
| 79 | - // Store the data locally. |
|
| 80 | - $wp_filesystem->put_contents( $image_full_path, wp_remote_retrieve_body( $response ) ); |
|
| 81 | - |
|
| 82 | - // Return the path. |
|
| 83 | - return array( |
|
| 84 | - 'path' => $image_full_path, |
|
| 85 | - 'url' => $image_full_url, |
|
| 86 | - 'content_type' => $content_type, |
|
| 87 | - ); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Returns the file extension using the content type. |
|
| 92 | - * |
|
| 93 | - * @param string $content_type File content type. |
|
| 94 | - * |
|
| 95 | - * @since 3.18.0 |
|
| 96 | - * |
|
| 97 | - * @return string|bool The file extension on success and |
|
| 98 | - * false on fail or if the content type is not supported. |
|
| 99 | - */ |
|
| 100 | - private static function get_extension_from_content_type( $content_type ) { |
|
| 101 | - |
|
| 102 | - // Return the extension if match. |
|
| 103 | - switch ( $content_type ) { |
|
| 104 | - case 'image/jpeg': |
|
| 105 | - case 'image/jpg': |
|
| 106 | - return '.jpg'; |
|
| 107 | - case 'image/gif': |
|
| 108 | - return '.gif'; |
|
| 109 | - case 'image/png': |
|
| 110 | - return '.png'; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - // Otherwise return false. |
|
| 114 | - return false; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Retrieve the response from url and sets the response. |
|
| 119 | - * |
|
| 120 | - * @param string $url The url to retrieve. |
|
| 121 | - * |
|
| 122 | - * @since 3.18.0 |
|
| 123 | - * |
|
| 124 | - * @return false|array True on success and false on failure. |
|
| 125 | - */ |
|
| 126 | - private static function get_response( $url ) { |
|
| 127 | - // Request the remote file. |
|
| 128 | - $response = wp_remote_get( $url ); |
|
| 129 | - |
|
| 130 | - // Bail out if the response is not ok. |
|
| 131 | - if ( |
|
| 132 | - is_wp_error( $response ) |
|
| 133 | - || 200 !== (int) $response['response']['code'] |
|
| 134 | - || ! isset( $response['body'] ) |
|
| 135 | - ) { |
|
| 136 | - wl_write_log( "save_image_from_url : error fetching image $url \n" ); |
|
| 137 | - |
|
| 138 | - return false; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - // Set the response. |
|
| 142 | - return $response; |
|
| 143 | - } |
|
| 11 | + /** |
|
| 12 | + * Save the image with the specified URL locally. |
|
| 13 | + * |
|
| 14 | + * @param string $url The image remote URL. |
|
| 15 | + * |
|
| 16 | + * @since 3.18.0 |
|
| 17 | + * |
|
| 18 | + * @return array|false An array with information about the saved image (*path*: the local path to the image, *url*: the local |
|
| 19 | + * url, *content_type*: the image content type) or false on error. |
|
| 20 | + */ |
|
| 21 | + public static function save_from_url( $url ) { |
|
| 22 | + |
|
| 23 | + // Required for REST API calls |
|
| 24 | + if ( ! function_exists( 'WP_Filesystem' ) ) { |
|
| 25 | + require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
| 26 | + } |
|
| 27 | + // Load `WP_Filesystem`. |
|
| 28 | + WP_Filesystem(); |
|
| 29 | + global $wp_filesystem; |
|
| 30 | + |
|
| 31 | + // Parse the url. |
|
| 32 | + $parts = wp_parse_url( $url ); |
|
| 33 | + |
|
| 34 | + // Get the bare filename (filename w/o the extension). |
|
| 35 | + $basename = pathinfo( $parts['path'], PATHINFO_FILENAME ); |
|
| 36 | + |
|
| 37 | + // Get the base dir. |
|
| 38 | + $wp_upload_dir = wp_upload_dir(); |
|
| 39 | + |
|
| 40 | + // Set the upload directory and URL. |
|
| 41 | + $upload_dir = $wp_upload_dir['basedir'] . '/wl' . $wp_upload_dir['subdir']; |
|
| 42 | + $upload_url = $wp_upload_dir['baseurl'] . '/wl' . $wp_upload_dir['subdir']; |
|
| 43 | + |
|
| 44 | + // Get the full path to the local filename. |
|
| 45 | + $image_full_path = $upload_dir . '/' . $basename; |
|
| 46 | + $image_full_url = $upload_url . '/' . $basename; |
|
| 47 | + |
|
| 48 | + // Create custom directory and bail on failure. |
|
| 49 | + if ( ! wp_mkdir_p( $upload_dir ) ) { |
|
| 50 | + wl_write_log( "save_image_from_url : failed creating upload dir $upload_dir \n" ); |
|
| 51 | + |
|
| 52 | + return false; |
|
| 53 | + }; |
|
| 54 | + |
|
| 55 | + $response = self::get_response( $url ); |
|
| 56 | + |
|
| 57 | + // Bail if the response is not set. |
|
| 58 | + if ( false === $response ) { |
|
| 59 | + wl_write_log( "save_image_from_url : failed to fetch the response from: $url \n" ); |
|
| 60 | + |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + // Get the content type of response. |
|
| 65 | + $content_type = wp_remote_retrieve_header( $response, 'content-type' ); |
|
| 66 | + |
|
| 67 | + // Get the file extension. |
|
| 68 | + $extension = self::get_extension_from_content_type( $content_type ); |
|
| 69 | + |
|
| 70 | + // Bail if the content type is not supported. |
|
| 71 | + if ( empty( $extension ) ) { |
|
| 72 | + return false; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + // Complete the local filename. |
|
| 76 | + $image_full_path .= $extension; |
|
| 77 | + $image_full_url .= $extension; |
|
| 78 | + |
|
| 79 | + // Store the data locally. |
|
| 80 | + $wp_filesystem->put_contents( $image_full_path, wp_remote_retrieve_body( $response ) ); |
|
| 81 | + |
|
| 82 | + // Return the path. |
|
| 83 | + return array( |
|
| 84 | + 'path' => $image_full_path, |
|
| 85 | + 'url' => $image_full_url, |
|
| 86 | + 'content_type' => $content_type, |
|
| 87 | + ); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Returns the file extension using the content type. |
|
| 92 | + * |
|
| 93 | + * @param string $content_type File content type. |
|
| 94 | + * |
|
| 95 | + * @since 3.18.0 |
|
| 96 | + * |
|
| 97 | + * @return string|bool The file extension on success and |
|
| 98 | + * false on fail or if the content type is not supported. |
|
| 99 | + */ |
|
| 100 | + private static function get_extension_from_content_type( $content_type ) { |
|
| 101 | + |
|
| 102 | + // Return the extension if match. |
|
| 103 | + switch ( $content_type ) { |
|
| 104 | + case 'image/jpeg': |
|
| 105 | + case 'image/jpg': |
|
| 106 | + return '.jpg'; |
|
| 107 | + case 'image/gif': |
|
| 108 | + return '.gif'; |
|
| 109 | + case 'image/png': |
|
| 110 | + return '.png'; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + // Otherwise return false. |
|
| 114 | + return false; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Retrieve the response from url and sets the response. |
|
| 119 | + * |
|
| 120 | + * @param string $url The url to retrieve. |
|
| 121 | + * |
|
| 122 | + * @since 3.18.0 |
|
| 123 | + * |
|
| 124 | + * @return false|array True on success and false on failure. |
|
| 125 | + */ |
|
| 126 | + private static function get_response( $url ) { |
|
| 127 | + // Request the remote file. |
|
| 128 | + $response = wp_remote_get( $url ); |
|
| 129 | + |
|
| 130 | + // Bail out if the response is not ok. |
|
| 131 | + if ( |
|
| 132 | + is_wp_error( $response ) |
|
| 133 | + || 200 !== (int) $response['response']['code'] |
|
| 134 | + || ! isset( $response['body'] ) |
|
| 135 | + ) { |
|
| 136 | + wl_write_log( "save_image_from_url : error fetching image $url \n" ); |
|
| 137 | + |
|
| 138 | + return false; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + // Set the response. |
|
| 142 | + return $response; |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | 145 | } |
@@ -18,57 +18,57 @@ discard block |
||
| 18 | 18 | * @return array|false An array with information about the saved image (*path*: the local path to the image, *url*: the local |
| 19 | 19 | * url, *content_type*: the image content type) or false on error. |
| 20 | 20 | */ |
| 21 | - public static function save_from_url( $url ) { |
|
| 21 | + public static function save_from_url($url) { |
|
| 22 | 22 | |
| 23 | 23 | // Required for REST API calls |
| 24 | - if ( ! function_exists( 'WP_Filesystem' ) ) { |
|
| 25 | - require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
| 24 | + if ( ! function_exists('WP_Filesystem')) { |
|
| 25 | + require_once(ABSPATH.'wp-admin/includes/file.php'); |
|
| 26 | 26 | } |
| 27 | 27 | // Load `WP_Filesystem`. |
| 28 | 28 | WP_Filesystem(); |
| 29 | 29 | global $wp_filesystem; |
| 30 | 30 | |
| 31 | 31 | // Parse the url. |
| 32 | - $parts = wp_parse_url( $url ); |
|
| 32 | + $parts = wp_parse_url($url); |
|
| 33 | 33 | |
| 34 | 34 | // Get the bare filename (filename w/o the extension). |
| 35 | - $basename = pathinfo( $parts['path'], PATHINFO_FILENAME ); |
|
| 35 | + $basename = pathinfo($parts['path'], PATHINFO_FILENAME); |
|
| 36 | 36 | |
| 37 | 37 | // Get the base dir. |
| 38 | 38 | $wp_upload_dir = wp_upload_dir(); |
| 39 | 39 | |
| 40 | 40 | // Set the upload directory and URL. |
| 41 | - $upload_dir = $wp_upload_dir['basedir'] . '/wl' . $wp_upload_dir['subdir']; |
|
| 42 | - $upload_url = $wp_upload_dir['baseurl'] . '/wl' . $wp_upload_dir['subdir']; |
|
| 41 | + $upload_dir = $wp_upload_dir['basedir'].'/wl'.$wp_upload_dir['subdir']; |
|
| 42 | + $upload_url = $wp_upload_dir['baseurl'].'/wl'.$wp_upload_dir['subdir']; |
|
| 43 | 43 | |
| 44 | 44 | // Get the full path to the local filename. |
| 45 | - $image_full_path = $upload_dir . '/' . $basename; |
|
| 46 | - $image_full_url = $upload_url . '/' . $basename; |
|
| 45 | + $image_full_path = $upload_dir.'/'.$basename; |
|
| 46 | + $image_full_url = $upload_url.'/'.$basename; |
|
| 47 | 47 | |
| 48 | 48 | // Create custom directory and bail on failure. |
| 49 | - if ( ! wp_mkdir_p( $upload_dir ) ) { |
|
| 50 | - wl_write_log( "save_image_from_url : failed creating upload dir $upload_dir \n" ); |
|
| 49 | + if ( ! wp_mkdir_p($upload_dir)) { |
|
| 50 | + wl_write_log("save_image_from_url : failed creating upload dir $upload_dir \n"); |
|
| 51 | 51 | |
| 52 | 52 | return false; |
| 53 | 53 | }; |
| 54 | 54 | |
| 55 | - $response = self::get_response( $url ); |
|
| 55 | + $response = self::get_response($url); |
|
| 56 | 56 | |
| 57 | 57 | // Bail if the response is not set. |
| 58 | - if ( false === $response ) { |
|
| 59 | - wl_write_log( "save_image_from_url : failed to fetch the response from: $url \n" ); |
|
| 58 | + if (false === $response) { |
|
| 59 | + wl_write_log("save_image_from_url : failed to fetch the response from: $url \n"); |
|
| 60 | 60 | |
| 61 | 61 | return false; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | // Get the content type of response. |
| 65 | - $content_type = wp_remote_retrieve_header( $response, 'content-type' ); |
|
| 65 | + $content_type = wp_remote_retrieve_header($response, 'content-type'); |
|
| 66 | 66 | |
| 67 | 67 | // Get the file extension. |
| 68 | - $extension = self::get_extension_from_content_type( $content_type ); |
|
| 68 | + $extension = self::get_extension_from_content_type($content_type); |
|
| 69 | 69 | |
| 70 | 70 | // Bail if the content type is not supported. |
| 71 | - if ( empty( $extension ) ) { |
|
| 71 | + if (empty($extension)) { |
|
| 72 | 72 | return false; |
| 73 | 73 | } |
| 74 | 74 | |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | $image_full_url .= $extension; |
| 78 | 78 | |
| 79 | 79 | // Store the data locally. |
| 80 | - $wp_filesystem->put_contents( $image_full_path, wp_remote_retrieve_body( $response ) ); |
|
| 80 | + $wp_filesystem->put_contents($image_full_path, wp_remote_retrieve_body($response)); |
|
| 81 | 81 | |
| 82 | 82 | // Return the path. |
| 83 | 83 | return array( |
@@ -97,10 +97,10 @@ discard block |
||
| 97 | 97 | * @return string|bool The file extension on success and |
| 98 | 98 | * false on fail or if the content type is not supported. |
| 99 | 99 | */ |
| 100 | - private static function get_extension_from_content_type( $content_type ) { |
|
| 100 | + private static function get_extension_from_content_type($content_type) { |
|
| 101 | 101 | |
| 102 | 102 | // Return the extension if match. |
| 103 | - switch ( $content_type ) { |
|
| 103 | + switch ($content_type) { |
|
| 104 | 104 | case 'image/jpeg': |
| 105 | 105 | case 'image/jpg': |
| 106 | 106 | return '.jpg'; |
@@ -123,17 +123,17 @@ discard block |
||
| 123 | 123 | * |
| 124 | 124 | * @return false|array True on success and false on failure. |
| 125 | 125 | */ |
| 126 | - private static function get_response( $url ) { |
|
| 126 | + private static function get_response($url) { |
|
| 127 | 127 | // Request the remote file. |
| 128 | - $response = wp_remote_get( $url ); |
|
| 128 | + $response = wp_remote_get($url); |
|
| 129 | 129 | |
| 130 | 130 | // Bail out if the response is not ok. |
| 131 | 131 | if ( |
| 132 | - is_wp_error( $response ) |
|
| 132 | + is_wp_error($response) |
|
| 133 | 133 | || 200 !== (int) $response['response']['code'] |
| 134 | - || ! isset( $response['body'] ) |
|
| 134 | + || ! isset($response['body']) |
|
| 135 | 135 | ) { |
| 136 | - wl_write_log( "save_image_from_url : error fetching image $url \n" ); |
|
| 136 | + wl_write_log("save_image_from_url : error fetching image $url \n"); |
|
| 137 | 137 | |
| 138 | 138 | return false; |
| 139 | 139 | } |
@@ -85,7 +85,7 @@ |
||
| 85 | 85 | /** |
| 86 | 86 | * Retrieve the current db version. |
| 87 | 87 | * |
| 88 | - * @return type |
|
| 88 | + * @return string |
|
| 89 | 89 | */ |
| 90 | 90 | private function get_current_version() { |
| 91 | 91 | return get_option( 'wl_db_version', '0.0.0' ); |
@@ -44,23 +44,23 @@ discard block |
||
| 44 | 44 | public function __construct() { |
| 45 | 45 | |
| 46 | 46 | /** Installs. */ |
| 47 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install.php'; |
|
| 48 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-1-0-0.php'; |
|
| 49 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-10-0.php'; |
|
| 50 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-12-0.php'; |
|
| 51 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-14-0.php'; |
|
| 52 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-15-0.php'; |
|
| 53 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-18-0.php'; |
|
| 54 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-18-3.php'; |
|
| 55 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-19-5.php'; |
|
| 56 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-20-0.php'; |
|
| 57 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-all-entity-types.php'; |
|
| 58 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-package-type.php'; |
|
| 47 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install.php'; |
|
| 48 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-1-0-0.php'; |
|
| 49 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-10-0.php'; |
|
| 50 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-12-0.php'; |
|
| 51 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-14-0.php'; |
|
| 52 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-15-0.php'; |
|
| 53 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-18-0.php'; |
|
| 54 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-18-3.php'; |
|
| 55 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-19-5.php'; |
|
| 56 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-20-0.php'; |
|
| 57 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-all-entity-types.php'; |
|
| 58 | + require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-package-type.php'; |
|
| 59 | 59 | |
| 60 | 60 | |
| 61 | 61 | self::$instance = $this; |
| 62 | 62 | |
| 63 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 63 | + $this->log = Wordlift_Log_Service::get_logger(get_class()); |
|
| 64 | 64 | |
| 65 | 65 | } |
| 66 | 66 | |
@@ -84,12 +84,12 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | public function install() { |
| 86 | 86 | |
| 87 | - if ( false === get_transient( '_wl_installing' ) ) { |
|
| 88 | - set_transient( '_wl_installing', true, 5 * MINUTE_IN_SECONDS ); |
|
| 87 | + if (false === get_transient('_wl_installing')) { |
|
| 88 | + set_transient('_wl_installing', true, 5 * MINUTE_IN_SECONDS); |
|
| 89 | 89 | |
| 90 | 90 | $this->do_install(); |
| 91 | 91 | |
| 92 | - delete_transient( '_wl_installing' ); |
|
| 92 | + delete_transient('_wl_installing'); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | } |
@@ -122,24 +122,24 @@ discard block |
||
| 122 | 122 | $version = null; |
| 123 | 123 | |
| 124 | 124 | /** @var Wordlift_Install $install */ |
| 125 | - foreach ( $installs as $install ) { |
|
| 125 | + foreach ($installs as $install) { |
|
| 126 | 126 | // Get the install version. |
| 127 | 127 | $version = $install->get_version(); |
| 128 | 128 | |
| 129 | - if ( version_compare( $version, $this->get_current_version(), '>' ) |
|
| 130 | - || $install->must_install() ) { |
|
| 129 | + if (version_compare($version, $this->get_current_version(), '>') |
|
| 130 | + || $install->must_install()) { |
|
| 131 | 131 | |
| 132 | - $class_name = get_class( $install ); |
|
| 132 | + $class_name = get_class($install); |
|
| 133 | 133 | |
| 134 | - $this->log->info( "Current version is {$this->get_current_version()}, installing $class_name..." ); |
|
| 134 | + $this->log->info("Current version is {$this->get_current_version()}, installing $class_name..."); |
|
| 135 | 135 | |
| 136 | 136 | // Install version. |
| 137 | 137 | $install->install(); |
| 138 | 138 | |
| 139 | - $this->log->info( "$class_name installed." ); |
|
| 139 | + $this->log->info("$class_name installed."); |
|
| 140 | 140 | |
| 141 | 141 | // Bump the version. |
| 142 | - update_option( 'wl_db_version', $version ); |
|
| 142 | + update_option('wl_db_version', $version); |
|
| 143 | 143 | |
| 144 | 144 | } |
| 145 | 145 | |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * @return type |
| 154 | 154 | */ |
| 155 | 155 | private function get_current_version() { |
| 156 | - return get_option( 'wl_db_version', '0.0.0' ); |
|
| 156 | + return get_option('wl_db_version', '0.0.0'); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | } |
@@ -18,141 +18,141 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Wordlift_Install_Service { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * A {@link Wordlift_Log_Service} instance. |
|
| 23 | - * |
|
| 24 | - * @since 3.18.0 |
|
| 25 | - * @access private |
|
| 26 | - * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 27 | - */ |
|
| 28 | - private $log; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * The singleton instance. |
|
| 32 | - * |
|
| 33 | - * @since 3.18.0 |
|
| 34 | - * @access private |
|
| 35 | - * @var \Wordlift_Install_Service $instance A {@link Wordlift_Install_Service} instance. |
|
| 36 | - */ |
|
| 37 | - private static $instance; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Wordlift_Install_Service constructor. |
|
| 41 | - * |
|
| 42 | - * @since 3.18.0 |
|
| 43 | - */ |
|
| 44 | - public function __construct() { |
|
| 45 | - |
|
| 46 | - /** Installs. */ |
|
| 47 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install.php'; |
|
| 48 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-1-0-0.php'; |
|
| 49 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-10-0.php'; |
|
| 50 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-12-0.php'; |
|
| 51 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-14-0.php'; |
|
| 52 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-15-0.php'; |
|
| 53 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-18-0.php'; |
|
| 54 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-18-3.php'; |
|
| 55 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-19-5.php'; |
|
| 56 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-20-0.php'; |
|
| 57 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-all-entity-types.php'; |
|
| 58 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-package-type.php'; |
|
| 59 | - |
|
| 60 | - self::$instance = $this; |
|
| 61 | - |
|
| 62 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 63 | - |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Get the singleton instance. |
|
| 68 | - * |
|
| 69 | - * @since 3.18.0 |
|
| 70 | - */ |
|
| 71 | - public static function get_instance() { |
|
| 72 | - |
|
| 73 | - return self::$instance; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Loop thought all versions and install the updates. |
|
| 78 | - * |
|
| 79 | - * @since 3.20.0 use a transient to avoid concurrent installation calls. |
|
| 80 | - * @since 3.18.0 |
|
| 81 | - * |
|
| 82 | - * @return void |
|
| 83 | - */ |
|
| 84 | - public function install() { |
|
| 85 | - |
|
| 86 | - if ( false === get_transient( '_wl_installing' ) ) { |
|
| 87 | - set_transient( '_wl_installing', true, 5 * MINUTE_IN_SECONDS ); |
|
| 88 | - |
|
| 89 | - $this->do_install(); |
|
| 90 | - |
|
| 91 | - delete_transient( '_wl_installing' ); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Perform the actual installation. |
|
| 98 | - * |
|
| 99 | - * @since 3.20.0 |
|
| 100 | - */ |
|
| 101 | - private function do_install() { |
|
| 102 | - |
|
| 103 | - // Get the install services. |
|
| 104 | - $installs = array( |
|
| 105 | - new Wordlift_Install_1_0_0(), |
|
| 106 | - new Wordlift_Install_3_10_0(), |
|
| 107 | - new Wordlift_Install_3_12_0(), |
|
| 108 | - new Wordlift_Install_3_14_0(), |
|
| 109 | - new Wordlift_Install_3_15_0(), |
|
| 110 | - new Wordlift_Install_3_18_0(), |
|
| 111 | - new Wordlift_Install_3_18_3(), |
|
| 112 | - new Wordlift_Install_3_19_5(), |
|
| 113 | - new Wordlift_Install_3_20_0(), |
|
| 114 | - /* |
|
| 21 | + /** |
|
| 22 | + * A {@link Wordlift_Log_Service} instance. |
|
| 23 | + * |
|
| 24 | + * @since 3.18.0 |
|
| 25 | + * @access private |
|
| 26 | + * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 27 | + */ |
|
| 28 | + private $log; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * The singleton instance. |
|
| 32 | + * |
|
| 33 | + * @since 3.18.0 |
|
| 34 | + * @access private |
|
| 35 | + * @var \Wordlift_Install_Service $instance A {@link Wordlift_Install_Service} instance. |
|
| 36 | + */ |
|
| 37 | + private static $instance; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Wordlift_Install_Service constructor. |
|
| 41 | + * |
|
| 42 | + * @since 3.18.0 |
|
| 43 | + */ |
|
| 44 | + public function __construct() { |
|
| 45 | + |
|
| 46 | + /** Installs. */ |
|
| 47 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install.php'; |
|
| 48 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-1-0-0.php'; |
|
| 49 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-10-0.php'; |
|
| 50 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-12-0.php'; |
|
| 51 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-14-0.php'; |
|
| 52 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-15-0.php'; |
|
| 53 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-18-0.php'; |
|
| 54 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-18-3.php'; |
|
| 55 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-19-5.php'; |
|
| 56 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-20-0.php'; |
|
| 57 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-all-entity-types.php'; |
|
| 58 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-package-type.php'; |
|
| 59 | + |
|
| 60 | + self::$instance = $this; |
|
| 61 | + |
|
| 62 | + $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 63 | + |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Get the singleton instance. |
|
| 68 | + * |
|
| 69 | + * @since 3.18.0 |
|
| 70 | + */ |
|
| 71 | + public static function get_instance() { |
|
| 72 | + |
|
| 73 | + return self::$instance; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Loop thought all versions and install the updates. |
|
| 78 | + * |
|
| 79 | + * @since 3.20.0 use a transient to avoid concurrent installation calls. |
|
| 80 | + * @since 3.18.0 |
|
| 81 | + * |
|
| 82 | + * @return void |
|
| 83 | + */ |
|
| 84 | + public function install() { |
|
| 85 | + |
|
| 86 | + if ( false === get_transient( '_wl_installing' ) ) { |
|
| 87 | + set_transient( '_wl_installing', true, 5 * MINUTE_IN_SECONDS ); |
|
| 88 | + |
|
| 89 | + $this->do_install(); |
|
| 90 | + |
|
| 91 | + delete_transient( '_wl_installing' ); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Perform the actual installation. |
|
| 98 | + * |
|
| 99 | + * @since 3.20.0 |
|
| 100 | + */ |
|
| 101 | + private function do_install() { |
|
| 102 | + |
|
| 103 | + // Get the install services. |
|
| 104 | + $installs = array( |
|
| 105 | + new Wordlift_Install_1_0_0(), |
|
| 106 | + new Wordlift_Install_3_10_0(), |
|
| 107 | + new Wordlift_Install_3_12_0(), |
|
| 108 | + new Wordlift_Install_3_14_0(), |
|
| 109 | + new Wordlift_Install_3_15_0(), |
|
| 110 | + new Wordlift_Install_3_18_0(), |
|
| 111 | + new Wordlift_Install_3_18_3(), |
|
| 112 | + new Wordlift_Install_3_19_5(), |
|
| 113 | + new Wordlift_Install_3_20_0(), |
|
| 114 | + /* |
|
| 115 | 115 | * This should be enabled with #852. |
| 116 | 116 | */ |
| 117 | - // new Wordlift_Install_All_Entity_Types(), |
|
| 118 | - new Wordlift_Install_Package_Type(), |
|
| 119 | - ); |
|
| 117 | + // new Wordlift_Install_All_Entity_Types(), |
|
| 118 | + new Wordlift_Install_Package_Type(), |
|
| 119 | + ); |
|
| 120 | 120 | |
| 121 | - $version = null; |
|
| 121 | + $version = null; |
|
| 122 | 122 | |
| 123 | - /** @var Wordlift_Install $install */ |
|
| 124 | - foreach ( $installs as $install ) { |
|
| 125 | - // Get the install version. |
|
| 126 | - $version = $install->get_version(); |
|
| 123 | + /** @var Wordlift_Install $install */ |
|
| 124 | + foreach ( $installs as $install ) { |
|
| 125 | + // Get the install version. |
|
| 126 | + $version = $install->get_version(); |
|
| 127 | 127 | |
| 128 | - if ( version_compare( $version, $this->get_current_version(), '>' ) |
|
| 129 | - || $install->must_install() ) { |
|
| 128 | + if ( version_compare( $version, $this->get_current_version(), '>' ) |
|
| 129 | + || $install->must_install() ) { |
|
| 130 | 130 | |
| 131 | - $class_name = get_class( $install ); |
|
| 131 | + $class_name = get_class( $install ); |
|
| 132 | 132 | |
| 133 | - $this->log->info( "Current version is {$this->get_current_version()}, installing $class_name..." ); |
|
| 133 | + $this->log->info( "Current version is {$this->get_current_version()}, installing $class_name..." ); |
|
| 134 | 134 | |
| 135 | - // Install version. |
|
| 136 | - $install->install(); |
|
| 135 | + // Install version. |
|
| 136 | + $install->install(); |
|
| 137 | 137 | |
| 138 | - $this->log->info( "$class_name installed." ); |
|
| 138 | + $this->log->info( "$class_name installed." ); |
|
| 139 | 139 | |
| 140 | - // Bump the version. |
|
| 141 | - update_option( 'wl_db_version', $version ); |
|
| 140 | + // Bump the version. |
|
| 141 | + update_option( 'wl_db_version', $version ); |
|
| 142 | 142 | |
| 143 | - } |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - } |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - } |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * Retrieve the current db version. |
|
| 151 | - * |
|
| 152 | - * @return type |
|
| 153 | - */ |
|
| 154 | - private function get_current_version() { |
|
| 155 | - return get_option( 'wl_db_version', '0.0.0' ); |
|
| 156 | - } |
|
| 149 | + /** |
|
| 150 | + * Retrieve the current db version. |
|
| 151 | + * |
|
| 152 | + * @return type |
|
| 153 | + */ |
|
| 154 | + private function get_current_version() { |
|
| 155 | + return get_option( 'wl_db_version', '0.0.0' ); |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | 158 | } |
@@ -17,52 +17,52 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | class Wordlift_Entity_Page_Service { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Set the entity post types as one to be included in archive pages. |
|
| 22 | - * |
|
| 23 | - * In order to have entities show up in standard WP categories (Posts categories) |
|
| 24 | - * we configure the `entity` post type, but we also need to alter the main |
|
| 25 | - * WP query (which by default queries posts only) to include the `entities`. |
|
| 26 | - * |
|
| 27 | - * @since 3.12.0 |
|
| 28 | - * |
|
| 29 | - * @param WP_Query $query WP's {@link WP_Query} instance. |
|
| 30 | - */ |
|
| 31 | - public function pre_get_posts( $query ) { |
|
| 32 | - |
|
| 33 | - // Only for the main query, avoid problems with widgets and what not. |
|
| 34 | - if ( ! $query->is_main_query() ) { |
|
| 35 | - return; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - // We don't want to alter the query if we're in the admin UI, if this is |
|
| 39 | - // not a entity type achieve query, or if the `suppress_filters` is set. |
|
| 40 | - // |
|
| 41 | - // Note that it is unlikely for `suppress_filter` to be set on the front |
|
| 42 | - // end, but let's be safe if it is set the calling code assumes no |
|
| 43 | - // modifications of queries. |
|
| 44 | - |
|
| 45 | - // Ignore admin side request, requests for which filters should be |
|
| 46 | - // suppressed, and when we are not on a entity type archive page. |
|
| 47 | - if ( is_admin() || |
|
| 48 | - ! is_tax( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ) || |
|
| 49 | - ! empty( $query->query_vars['suppress_filters'] ) |
|
| 50 | - ) { |
|
| 51 | - return; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - // Events should be sorted by start date in descending order. |
|
| 55 | - if ( is_tax( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, 'event' ) ) { |
|
| 56 | - |
|
| 57 | - // Update the query to use the start time meta and desc order. |
|
| 58 | - $meta_query[] = array( |
|
| 59 | - 'key' => Wordlift_Schema_Service::FIELD_DATE_START, |
|
| 60 | - ); |
|
| 61 | - $query->set( 'meta_query', $meta_query ); |
|
| 62 | - $query->set( 'orderby', 'meta_value' ); |
|
| 63 | - $query->set( 'order', 'DESC' ); |
|
| 64 | - } else { |
|
| 65 | - /* |
|
| 20 | + /** |
|
| 21 | + * Set the entity post types as one to be included in archive pages. |
|
| 22 | + * |
|
| 23 | + * In order to have entities show up in standard WP categories (Posts categories) |
|
| 24 | + * we configure the `entity` post type, but we also need to alter the main |
|
| 25 | + * WP query (which by default queries posts only) to include the `entities`. |
|
| 26 | + * |
|
| 27 | + * @since 3.12.0 |
|
| 28 | + * |
|
| 29 | + * @param WP_Query $query WP's {@link WP_Query} instance. |
|
| 30 | + */ |
|
| 31 | + public function pre_get_posts( $query ) { |
|
| 32 | + |
|
| 33 | + // Only for the main query, avoid problems with widgets and what not. |
|
| 34 | + if ( ! $query->is_main_query() ) { |
|
| 35 | + return; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + // We don't want to alter the query if we're in the admin UI, if this is |
|
| 39 | + // not a entity type achieve query, or if the `suppress_filters` is set. |
|
| 40 | + // |
|
| 41 | + // Note that it is unlikely for `suppress_filter` to be set on the front |
|
| 42 | + // end, but let's be safe if it is set the calling code assumes no |
|
| 43 | + // modifications of queries. |
|
| 44 | + |
|
| 45 | + // Ignore admin side request, requests for which filters should be |
|
| 46 | + // suppressed, and when we are not on a entity type archive page. |
|
| 47 | + if ( is_admin() || |
|
| 48 | + ! is_tax( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ) || |
|
| 49 | + ! empty( $query->query_vars['suppress_filters'] ) |
|
| 50 | + ) { |
|
| 51 | + return; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + // Events should be sorted by start date in descending order. |
|
| 55 | + if ( is_tax( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, 'event' ) ) { |
|
| 56 | + |
|
| 57 | + // Update the query to use the start time meta and desc order. |
|
| 58 | + $meta_query[] = array( |
|
| 59 | + 'key' => Wordlift_Schema_Service::FIELD_DATE_START, |
|
| 60 | + ); |
|
| 61 | + $query->set( 'meta_query', $meta_query ); |
|
| 62 | + $query->set( 'orderby', 'meta_value' ); |
|
| 63 | + $query->set( 'order', 'DESC' ); |
|
| 64 | + } else { |
|
| 65 | + /* |
|
| 66 | 66 | * All other entity types should be sorted by their connectivity. |
| 67 | 67 | * For this we need to query the relationship table which has |
| 68 | 68 | * to be done by manipulating the SQL generated for the query. |
@@ -70,73 +70,73 @@ discard block |
||
| 70 | 70 | * additional filters to handle it. |
| 71 | 71 | */ |
| 72 | 72 | |
| 73 | - add_filter( 'posts_join', array( $this, 'posts_join' ) ); |
|
| 74 | - add_filter( 'posts_groupby', array( $this, 'posts_groupby' ) ); |
|
| 75 | - add_filter( 'posts_orderby', array( $this, 'posts_orderby' ) ); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Filter handler that sets the join part of a query to include the |
|
| 81 | - * relationship table to be able to use it in the sorting. |
|
| 82 | - * |
|
| 83 | - * @since 3.15.0 |
|
| 84 | - * |
|
| 85 | - * @param string $join_statement The join part of the SQL statement which is used for the query. |
|
| 86 | - * |
|
| 87 | - * @return string An join SQL which add the relationships table to the join. |
|
| 88 | - */ |
|
| 89 | - public function posts_join( $join_statement ) { |
|
| 90 | - |
|
| 91 | - global $wpdb; |
|
| 92 | - |
|
| 93 | - $join_statement .= " LEFT JOIN {$wpdb->prefix}wl_relation_instances ri " |
|
| 94 | - . " ON (ri.object_id = {$wpdb->posts}.ID)"; |
|
| 95 | - |
|
| 96 | - // Remove to make sure it will not run agan in other context. |
|
| 97 | - remove_filter( 'posts_join', array( $this, 'posts_join' ) ); |
|
| 98 | - |
|
| 99 | - return $join_statement; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Filter handler that sets the groupby part of a query to include the |
|
| 104 | - * relationship table to be able to use it in the sorting. |
|
| 105 | - * |
|
| 106 | - * @since 3.15.0 |
|
| 107 | - * |
|
| 108 | - * @param string $groupby_statement The groupby part of the SQL statement which is used for the query. |
|
| 109 | - * |
|
| 110 | - * @return string A groupby SQL which add the relationships table to the join. |
|
| 111 | - */ |
|
| 112 | - public function posts_groupby( $groupby_statement ) { |
|
| 113 | - |
|
| 114 | - $groupby_statement = 'ri.object_id, ' . $groupby_statement; |
|
| 115 | - |
|
| 116 | - // Remove to make sure it will not run agan in other context. |
|
| 117 | - remove_filter( 'posts_groupby', array( $this, 'posts_groupby' ) ); |
|
| 118 | - |
|
| 119 | - return $groupby_statement; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Filter handler that sets the orderby part of a query to sort by number of |
|
| 124 | - * relationships. |
|
| 125 | - * |
|
| 126 | - * @since 3.15.0 |
|
| 127 | - * |
|
| 128 | - * @param string $orderby_statement The orderby part of the SQL statement which is used for the query. |
|
| 129 | - * |
|
| 130 | - * @return string An orderby SQL which sorts by the number of relationships |
|
| 131 | - */ |
|
| 132 | - public function posts_orderby( $orderby_statement ) { |
|
| 133 | - |
|
| 134 | - $orderby_statement = 'COUNT( ri.object_id ) DESC, ' . $orderby_statement; |
|
| 135 | - |
|
| 136 | - // Remove to make sure it will not run agan in other context. |
|
| 137 | - remove_filter( 'posts_orderby', array( $this, 'posts_orderby' ) ); |
|
| 138 | - |
|
| 139 | - return $orderby_statement; |
|
| 140 | - } |
|
| 73 | + add_filter( 'posts_join', array( $this, 'posts_join' ) ); |
|
| 74 | + add_filter( 'posts_groupby', array( $this, 'posts_groupby' ) ); |
|
| 75 | + add_filter( 'posts_orderby', array( $this, 'posts_orderby' ) ); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Filter handler that sets the join part of a query to include the |
|
| 81 | + * relationship table to be able to use it in the sorting. |
|
| 82 | + * |
|
| 83 | + * @since 3.15.0 |
|
| 84 | + * |
|
| 85 | + * @param string $join_statement The join part of the SQL statement which is used for the query. |
|
| 86 | + * |
|
| 87 | + * @return string An join SQL which add the relationships table to the join. |
|
| 88 | + */ |
|
| 89 | + public function posts_join( $join_statement ) { |
|
| 90 | + |
|
| 91 | + global $wpdb; |
|
| 92 | + |
|
| 93 | + $join_statement .= " LEFT JOIN {$wpdb->prefix}wl_relation_instances ri " |
|
| 94 | + . " ON (ri.object_id = {$wpdb->posts}.ID)"; |
|
| 95 | + |
|
| 96 | + // Remove to make sure it will not run agan in other context. |
|
| 97 | + remove_filter( 'posts_join', array( $this, 'posts_join' ) ); |
|
| 98 | + |
|
| 99 | + return $join_statement; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Filter handler that sets the groupby part of a query to include the |
|
| 104 | + * relationship table to be able to use it in the sorting. |
|
| 105 | + * |
|
| 106 | + * @since 3.15.0 |
|
| 107 | + * |
|
| 108 | + * @param string $groupby_statement The groupby part of the SQL statement which is used for the query. |
|
| 109 | + * |
|
| 110 | + * @return string A groupby SQL which add the relationships table to the join. |
|
| 111 | + */ |
|
| 112 | + public function posts_groupby( $groupby_statement ) { |
|
| 113 | + |
|
| 114 | + $groupby_statement = 'ri.object_id, ' . $groupby_statement; |
|
| 115 | + |
|
| 116 | + // Remove to make sure it will not run agan in other context. |
|
| 117 | + remove_filter( 'posts_groupby', array( $this, 'posts_groupby' ) ); |
|
| 118 | + |
|
| 119 | + return $groupby_statement; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Filter handler that sets the orderby part of a query to sort by number of |
|
| 124 | + * relationships. |
|
| 125 | + * |
|
| 126 | + * @since 3.15.0 |
|
| 127 | + * |
|
| 128 | + * @param string $orderby_statement The orderby part of the SQL statement which is used for the query. |
|
| 129 | + * |
|
| 130 | + * @return string An orderby SQL which sorts by the number of relationships |
|
| 131 | + */ |
|
| 132 | + public function posts_orderby( $orderby_statement ) { |
|
| 133 | + |
|
| 134 | + $orderby_statement = 'COUNT( ri.object_id ) DESC, ' . $orderby_statement; |
|
| 135 | + |
|
| 136 | + // Remove to make sure it will not run agan in other context. |
|
| 137 | + remove_filter( 'posts_orderby', array( $this, 'posts_orderby' ) ); |
|
| 138 | + |
|
| 139 | + return $orderby_statement; |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | 142 | } |
@@ -28,10 +28,10 @@ discard block |
||
| 28 | 28 | * |
| 29 | 29 | * @param WP_Query $query WP's {@link WP_Query} instance. |
| 30 | 30 | */ |
| 31 | - public function pre_get_posts( $query ) { |
|
| 31 | + public function pre_get_posts($query) { |
|
| 32 | 32 | |
| 33 | 33 | // Only for the main query, avoid problems with widgets and what not. |
| 34 | - if ( ! $query->is_main_query() ) { |
|
| 34 | + if ( ! $query->is_main_query()) { |
|
| 35 | 35 | return; |
| 36 | 36 | } |
| 37 | 37 | |
@@ -44,23 +44,23 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | // Ignore admin side request, requests for which filters should be |
| 46 | 46 | // suppressed, and when we are not on a entity type archive page. |
| 47 | - if ( is_admin() || |
|
| 48 | - ! is_tax( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ) || |
|
| 49 | - ! empty( $query->query_vars['suppress_filters'] ) |
|
| 47 | + if (is_admin() || |
|
| 48 | + ! is_tax(Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME) || |
|
| 49 | + ! empty($query->query_vars['suppress_filters']) |
|
| 50 | 50 | ) { |
| 51 | 51 | return; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | // Events should be sorted by start date in descending order. |
| 55 | - if ( is_tax( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, 'event' ) ) { |
|
| 55 | + if (is_tax(Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, 'event')) { |
|
| 56 | 56 | |
| 57 | 57 | // Update the query to use the start time meta and desc order. |
| 58 | 58 | $meta_query[] = array( |
| 59 | 59 | 'key' => Wordlift_Schema_Service::FIELD_DATE_START, |
| 60 | 60 | ); |
| 61 | - $query->set( 'meta_query', $meta_query ); |
|
| 62 | - $query->set( 'orderby', 'meta_value' ); |
|
| 63 | - $query->set( 'order', 'DESC' ); |
|
| 61 | + $query->set('meta_query', $meta_query); |
|
| 62 | + $query->set('orderby', 'meta_value'); |
|
| 63 | + $query->set('order', 'DESC'); |
|
| 64 | 64 | } else { |
| 65 | 65 | /* |
| 66 | 66 | * All other entity types should be sorted by their connectivity. |
@@ -70,9 +70,9 @@ discard block |
||
| 70 | 70 | * additional filters to handle it. |
| 71 | 71 | */ |
| 72 | 72 | |
| 73 | - add_filter( 'posts_join', array( $this, 'posts_join' ) ); |
|
| 74 | - add_filter( 'posts_groupby', array( $this, 'posts_groupby' ) ); |
|
| 75 | - add_filter( 'posts_orderby', array( $this, 'posts_orderby' ) ); |
|
| 73 | + add_filter('posts_join', array($this, 'posts_join')); |
|
| 74 | + add_filter('posts_groupby', array($this, 'posts_groupby')); |
|
| 75 | + add_filter('posts_orderby', array($this, 'posts_orderby')); |
|
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * |
| 87 | 87 | * @return string An join SQL which add the relationships table to the join. |
| 88 | 88 | */ |
| 89 | - public function posts_join( $join_statement ) { |
|
| 89 | + public function posts_join($join_statement) { |
|
| 90 | 90 | |
| 91 | 91 | global $wpdb; |
| 92 | 92 | |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | . " ON (ri.object_id = {$wpdb->posts}.ID)"; |
| 95 | 95 | |
| 96 | 96 | // Remove to make sure it will not run agan in other context. |
| 97 | - remove_filter( 'posts_join', array( $this, 'posts_join' ) ); |
|
| 97 | + remove_filter('posts_join', array($this, 'posts_join')); |
|
| 98 | 98 | |
| 99 | 99 | return $join_statement; |
| 100 | 100 | } |
@@ -109,12 +109,12 @@ discard block |
||
| 109 | 109 | * |
| 110 | 110 | * @return string A groupby SQL which add the relationships table to the join. |
| 111 | 111 | */ |
| 112 | - public function posts_groupby( $groupby_statement ) { |
|
| 112 | + public function posts_groupby($groupby_statement) { |
|
| 113 | 113 | |
| 114 | - $groupby_statement = 'ri.object_id, ' . $groupby_statement; |
|
| 114 | + $groupby_statement = 'ri.object_id, '.$groupby_statement; |
|
| 115 | 115 | |
| 116 | 116 | // Remove to make sure it will not run agan in other context. |
| 117 | - remove_filter( 'posts_groupby', array( $this, 'posts_groupby' ) ); |
|
| 117 | + remove_filter('posts_groupby', array($this, 'posts_groupby')); |
|
| 118 | 118 | |
| 119 | 119 | return $groupby_statement; |
| 120 | 120 | } |
@@ -129,12 +129,12 @@ discard block |
||
| 129 | 129 | * |
| 130 | 130 | * @return string An orderby SQL which sorts by the number of relationships |
| 131 | 131 | */ |
| 132 | - public function posts_orderby( $orderby_statement ) { |
|
| 132 | + public function posts_orderby($orderby_statement) { |
|
| 133 | 133 | |
| 134 | - $orderby_statement = 'COUNT( ri.object_id ) DESC, ' . $orderby_statement; |
|
| 134 | + $orderby_statement = 'COUNT( ri.object_id ) DESC, '.$orderby_statement; |
|
| 135 | 135 | |
| 136 | 136 | // Remove to make sure it will not run agan in other context. |
| 137 | - remove_filter( 'posts_orderby', array( $this, 'posts_orderby' ) ); |
|
| 137 | + remove_filter('posts_orderby', array($this, 'posts_orderby')); |
|
| 138 | 138 | |
| 139 | 139 | return $orderby_statement; |
| 140 | 140 | } |