@@ -49,6 +49,11 @@ |
||
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | + /** |
|
| 53 | + * @param string $url |
|
| 54 | + * |
|
| 55 | + * @return integer|null |
|
| 56 | + */ |
|
| 52 | 57 | private function url_to_postid( $url ) { |
| 53 | 58 | // Try with url_to_postid |
| 54 | 59 | $post_id = url_to_postid( $url ); |
@@ -9,58 +9,58 @@ |
||
| 9 | 9 | |
| 10 | 10 | class Wordlift_Context_Cards_Service { |
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * @var string |
|
| 14 | - */ |
|
| 15 | - private $endpoint; |
|
| 12 | + /** |
|
| 13 | + * @var string |
|
| 14 | + */ |
|
| 15 | + private $endpoint; |
|
| 16 | 16 | |
| 17 | - function __construct() { |
|
| 17 | + function __construct() { |
|
| 18 | 18 | |
| 19 | - $this->endpoint = '/jsonld'; |
|
| 19 | + $this->endpoint = '/jsonld'; |
|
| 20 | 20 | |
| 21 | - // PHP 5.3 compatibility as `$this` cannot be used in closures. |
|
| 22 | - $that = $this; |
|
| 21 | + // PHP 5.3 compatibility as `$this` cannot be used in closures. |
|
| 22 | + $that = $this; |
|
| 23 | 23 | |
| 24 | - add_action( 'rest_api_init', function () use ( $that ) { |
|
| 25 | - register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, $that->endpoint, array( |
|
| 26 | - 'methods' => 'GET', |
|
| 27 | - 'callback' => array( $that, 'context_data' ), |
|
| 28 | - ) ); |
|
| 29 | - } ); |
|
| 24 | + add_action( 'rest_api_init', function () use ( $that ) { |
|
| 25 | + register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, $that->endpoint, array( |
|
| 26 | + 'methods' => 'GET', |
|
| 27 | + 'callback' => array( $that, 'context_data' ), |
|
| 28 | + ) ); |
|
| 29 | + } ); |
|
| 30 | 30 | |
| 31 | - } |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - public function context_data( $request ) { |
|
| 33 | + public function context_data( $request ) { |
|
| 34 | 34 | |
| 35 | - $entity_uri = urldecode( $request->get_param( 'entity_url' ) ); |
|
| 36 | - $entity_id = $this->url_to_postid( $entity_uri ); |
|
| 37 | - $jsonld = Wordlift_Jsonld_Service::get_instance()->get_jsonld( false, $entity_id ); |
|
| 35 | + $entity_uri = urldecode( $request->get_param( 'entity_url' ) ); |
|
| 36 | + $entity_id = $this->url_to_postid( $entity_uri ); |
|
| 37 | + $jsonld = Wordlift_Jsonld_Service::get_instance()->get_jsonld( false, $entity_id ); |
|
| 38 | 38 | |
| 39 | - return $jsonld; |
|
| 39 | + return $jsonld; |
|
| 40 | 40 | |
| 41 | - } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public function enqueue_scripts() { |
|
| 44 | - $show_context_cards = true; |
|
| 45 | - $show_context_cards = apply_filters( 'wl_show_context_cards', $show_context_cards ); |
|
| 46 | - if ( $show_context_cards ) { |
|
| 47 | - wp_enqueue_script( 'wordlift-cloud' ); |
|
| 48 | - wp_add_inline_script( 'wordlift-cloud', "window.addEventListener( 'load', function() { wordliftCloud.contextCards('a.wl-entity-page-link', '" . get_rest_url() . WL_REST_ROUTE_DEFAULT_NAMESPACE . $this->endpoint . "'); } );" ); |
|
| 49 | - } |
|
| 50 | - } |
|
| 43 | + public function enqueue_scripts() { |
|
| 44 | + $show_context_cards = true; |
|
| 45 | + $show_context_cards = apply_filters( 'wl_show_context_cards', $show_context_cards ); |
|
| 46 | + if ( $show_context_cards ) { |
|
| 47 | + wp_enqueue_script( 'wordlift-cloud' ); |
|
| 48 | + wp_add_inline_script( 'wordlift-cloud', "window.addEventListener( 'load', function() { wordliftCloud.contextCards('a.wl-entity-page-link', '" . get_rest_url() . WL_REST_ROUTE_DEFAULT_NAMESPACE . $this->endpoint . "'); } );" ); |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - private function url_to_postid( $url ) { |
|
| 53 | - // Try with url_to_postid |
|
| 54 | - $post_id = url_to_postid( $url ); |
|
| 55 | - if ( $post_id == 0 ) { |
|
| 56 | - // Try with get_page_by_path |
|
| 57 | - $post = get_page_by_path( basename( untrailingslashit( $url ) ), OBJECT, 'entity' ); |
|
| 58 | - if ( $post ) { |
|
| 59 | - $post_id = $post->ID; |
|
| 60 | - } |
|
| 61 | - } |
|
| 52 | + private function url_to_postid( $url ) { |
|
| 53 | + // Try with url_to_postid |
|
| 54 | + $post_id = url_to_postid( $url ); |
|
| 55 | + if ( $post_id == 0 ) { |
|
| 56 | + // Try with get_page_by_path |
|
| 57 | + $post = get_page_by_path( basename( untrailingslashit( $url ) ), OBJECT, 'entity' ); |
|
| 58 | + if ( $post ) { |
|
| 59 | + $post_id = $post->ID; |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - return $post_id; |
|
| 64 | - } |
|
| 63 | + return $post_id; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | 66 | } |
@@ -21,20 +21,20 @@ discard block |
||
| 21 | 21 | // PHP 5.3 compatibility as `$this` cannot be used in closures. |
| 22 | 22 | $that = $this; |
| 23 | 23 | |
| 24 | - add_action( 'rest_api_init', function () use ( $that ) { |
|
| 25 | - register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, $that->endpoint, array( |
|
| 24 | + add_action('rest_api_init', function() use ($that) { |
|
| 25 | + register_rest_route(WL_REST_ROUTE_DEFAULT_NAMESPACE, $that->endpoint, array( |
|
| 26 | 26 | 'methods' => 'GET', |
| 27 | - 'callback' => array( $that, 'context_data' ), |
|
| 28 | - ) ); |
|
| 27 | + 'callback' => array($that, 'context_data'), |
|
| 28 | + )); |
|
| 29 | 29 | } ); |
| 30 | 30 | |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - public function context_data( $request ) { |
|
| 33 | + public function context_data($request) { |
|
| 34 | 34 | |
| 35 | - $entity_uri = urldecode( $request->get_param( 'entity_url' ) ); |
|
| 36 | - $entity_id = $this->url_to_postid( $entity_uri ); |
|
| 37 | - $jsonld = Wordlift_Jsonld_Service::get_instance()->get_jsonld( false, $entity_id ); |
|
| 35 | + $entity_uri = urldecode($request->get_param('entity_url')); |
|
| 36 | + $entity_id = $this->url_to_postid($entity_uri); |
|
| 37 | + $jsonld = Wordlift_Jsonld_Service::get_instance()->get_jsonld(false, $entity_id); |
|
| 38 | 38 | |
| 39 | 39 | return $jsonld; |
| 40 | 40 | |
@@ -42,20 +42,20 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | public function enqueue_scripts() { |
| 44 | 44 | $show_context_cards = true; |
| 45 | - $show_context_cards = apply_filters( 'wl_show_context_cards', $show_context_cards ); |
|
| 46 | - if ( $show_context_cards ) { |
|
| 47 | - wp_enqueue_script( 'wordlift-cloud' ); |
|
| 48 | - wp_add_inline_script( 'wordlift-cloud', "window.addEventListener( 'load', function() { wordliftCloud.contextCards('a.wl-entity-page-link', '" . get_rest_url() . WL_REST_ROUTE_DEFAULT_NAMESPACE . $this->endpoint . "'); } );" ); |
|
| 45 | + $show_context_cards = apply_filters('wl_show_context_cards', $show_context_cards); |
|
| 46 | + if ($show_context_cards) { |
|
| 47 | + wp_enqueue_script('wordlift-cloud'); |
|
| 48 | + wp_add_inline_script('wordlift-cloud', "window.addEventListener( 'load', function() { wordliftCloud.contextCards('a.wl-entity-page-link', '".get_rest_url().WL_REST_ROUTE_DEFAULT_NAMESPACE.$this->endpoint."'); } );"); |
|
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - private function url_to_postid( $url ) { |
|
| 52 | + private function url_to_postid($url) { |
|
| 53 | 53 | // Try with url_to_postid |
| 54 | - $post_id = url_to_postid( $url ); |
|
| 55 | - if ( $post_id == 0 ) { |
|
| 54 | + $post_id = url_to_postid($url); |
|
| 55 | + if ($post_id == 0) { |
|
| 56 | 56 | // Try with get_page_by_path |
| 57 | - $post = get_page_by_path( basename( untrailingslashit( $url ) ), OBJECT, 'entity' ); |
|
| 58 | - if ( $post ) { |
|
| 57 | + $post = get_page_by_path(basename(untrailingslashit($url)), OBJECT, 'entity'); |
|
| 58 | + if ($post) { |
|
| 59 | 59 | $post_id = $post->ID; |
| 60 | 60 | } |
| 61 | 61 | } |
@@ -21,162 +21,162 @@ |
||
| 21 | 21 | |
| 22 | 22 | class Ttl_Cache_Cleaner { |
| 23 | 23 | |
| 24 | - const PATH = 0; |
|
| 25 | - const MTIME = 1; |
|
| 26 | - const SIZE = 2; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * The max TTL in seconds. |
|
| 30 | - * |
|
| 31 | - * @access private |
|
| 32 | - * @var int $ttl The max TTL in seconds. |
|
| 33 | - */ |
|
| 34 | - private $ttl; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * The max size in bytes. |
|
| 38 | - * |
|
| 39 | - * @access private |
|
| 40 | - * @var int $ttl The max size in bytes. |
|
| 41 | - */ |
|
| 42 | - private $max_size; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Ttl_Cache_Cleaner constructor. |
|
| 46 | - * |
|
| 47 | - * @param int $ttl The max TTL in seconds. |
|
| 48 | - * @param int $max_size The max size in bytes. |
|
| 49 | - */ |
|
| 50 | - public function __construct( $ttl = WORDLIFT_CACHE_DEFAULT_TTL, $max_size = WORDLIFT_CACHE_DEFAULT_MAX_SIZE ) { |
|
| 51 | - |
|
| 52 | - $this->ttl = $ttl; |
|
| 53 | - $this->max_size = $max_size; |
|
| 54 | - |
|
| 55 | - add_action( 'wp_ajax_wl_ttl_cache_cleaner__cleanup', array( $this, 'cleanup' ) ); |
|
| 56 | - add_action( 'wl_ttl_cache_cleaner__cleanup', array( $this, 'cleanup' ) ); |
|
| 57 | - |
|
| 58 | - // Do not bother to configure scheduled tasks while running on the front-end. |
|
| 59 | - if ( is_admin() && ! wp_next_scheduled( 'wl_ttl_cache_cleaner__cleanup' ) ) { |
|
| 60 | - wp_schedule_event( time(), 'hourly', 'wl_ttl_cache_cleaner__cleanup' ); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - public static function deactivate() { |
|
| 66 | - |
|
| 67 | - $timestamp = wp_next_scheduled( 'wl_ttl_cache_cleaner__cleanup' ); |
|
| 68 | - wp_unschedule_event( $timestamp, 'wl_ttl_cache_cleaner__cleanup' ); |
|
| 69 | - |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - public function cleanup() { |
|
| 73 | - |
|
| 74 | - // Get all the files, recursive. |
|
| 75 | - $files = $this->reduce( array(), Ttl_Cache::get_cache_folder() ); |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - // Get the max mtime. |
|
| 79 | - $max_mtime = time() - WORDLIFT_CACHE_DEFAULT_TTL; |
|
| 80 | - |
|
| 81 | - // Keep the original count for statistics that we're going to send the client. |
|
| 82 | - $original_count = count( $files ); |
|
| 83 | - |
|
| 84 | - // Sort by size ascending. |
|
| 85 | - usort( $files, function ( $f1, $f2 ) { |
|
| 86 | - if ( $f1[ Ttl_Cache_Cleaner::MTIME ] === $f2[ Ttl_Cache_Cleaner::MTIME ] ) { |
|
| 87 | - return 0; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - return ( $f1[ Ttl_Cache_Cleaner::MTIME ] < $f2[ Ttl_Cache_Cleaner::MTIME ] ) ? - 1 : 1; |
|
| 91 | - } ); |
|
| 92 | - |
|
| 93 | - // Start removing stale files. |
|
| 94 | - for ( $i = 0; $i < count( $files ); $i ++ ) { |
|
| 95 | - $file = $files[ $i ]; |
|
| 96 | - // Break if the mtime is within the range. |
|
| 97 | - if ( $file[ Ttl_Cache_Cleaner::MTIME ] > $max_mtime ) { |
|
| 98 | - break; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - unset( $files[ $i ] ); |
|
| 102 | - @unlink( $file[ Ttl_Cache_Cleaner::PATH ] ); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - // Calculate the size. |
|
| 106 | - $total_size = array_reduce( $files, function ( $carry, $item ) { |
|
| 107 | - |
|
| 108 | - return $carry + $item[ Ttl_Cache_Cleaner::SIZE ]; |
|
| 109 | - }, 0 ); |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - // Remove files until we're within the max size. |
|
| 113 | - while ( $total_size > $this->max_size ) { |
|
| 114 | - $file = array_shift( $files ); |
|
| 115 | - $total_size -= $file[ Ttl_Cache_Cleaner::SIZE ]; |
|
| 116 | - @unlink( $file[ Ttl_Cache_Cleaner::PATH ] ); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - // Send back some stats. |
|
| 120 | - wp_send_json_success( array( |
|
| 121 | - 'initial_count' => $original_count, |
|
| 122 | - 'current_count' => count( $files ), |
|
| 123 | - 'current_size' => $total_size, |
|
| 124 | - ) ); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - private function reduce( $accumulator, $path ) { |
|
| 128 | - |
|
| 129 | - // Open the dir handle. |
|
| 130 | - $handle = opendir( $path ); |
|
| 131 | - |
|
| 132 | - // Catch exceptions to be sure to close the dir handle. |
|
| 133 | - try { |
|
| 134 | - $accumulator = @$this->_reduce( $accumulator, $path, $handle ); |
|
| 135 | - } catch ( Exception $e ) { |
|
| 136 | - // Do nothing. |
|
| 137 | - } |
|
| 24 | + const PATH = 0; |
|
| 25 | + const MTIME = 1; |
|
| 26 | + const SIZE = 2; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * The max TTL in seconds. |
|
| 30 | + * |
|
| 31 | + * @access private |
|
| 32 | + * @var int $ttl The max TTL in seconds. |
|
| 33 | + */ |
|
| 34 | + private $ttl; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * The max size in bytes. |
|
| 38 | + * |
|
| 39 | + * @access private |
|
| 40 | + * @var int $ttl The max size in bytes. |
|
| 41 | + */ |
|
| 42 | + private $max_size; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Ttl_Cache_Cleaner constructor. |
|
| 46 | + * |
|
| 47 | + * @param int $ttl The max TTL in seconds. |
|
| 48 | + * @param int $max_size The max size in bytes. |
|
| 49 | + */ |
|
| 50 | + public function __construct( $ttl = WORDLIFT_CACHE_DEFAULT_TTL, $max_size = WORDLIFT_CACHE_DEFAULT_MAX_SIZE ) { |
|
| 51 | + |
|
| 52 | + $this->ttl = $ttl; |
|
| 53 | + $this->max_size = $max_size; |
|
| 54 | + |
|
| 55 | + add_action( 'wp_ajax_wl_ttl_cache_cleaner__cleanup', array( $this, 'cleanup' ) ); |
|
| 56 | + add_action( 'wl_ttl_cache_cleaner__cleanup', array( $this, 'cleanup' ) ); |
|
| 57 | + |
|
| 58 | + // Do not bother to configure scheduled tasks while running on the front-end. |
|
| 59 | + if ( is_admin() && ! wp_next_scheduled( 'wl_ttl_cache_cleaner__cleanup' ) ) { |
|
| 60 | + wp_schedule_event( time(), 'hourly', 'wl_ttl_cache_cleaner__cleanup' ); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + public static function deactivate() { |
|
| 66 | + |
|
| 67 | + $timestamp = wp_next_scheduled( 'wl_ttl_cache_cleaner__cleanup' ); |
|
| 68 | + wp_unschedule_event( $timestamp, 'wl_ttl_cache_cleaner__cleanup' ); |
|
| 69 | + |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + public function cleanup() { |
|
| 73 | + |
|
| 74 | + // Get all the files, recursive. |
|
| 75 | + $files = $this->reduce( array(), Ttl_Cache::get_cache_folder() ); |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + // Get the max mtime. |
|
| 79 | + $max_mtime = time() - WORDLIFT_CACHE_DEFAULT_TTL; |
|
| 80 | + |
|
| 81 | + // Keep the original count for statistics that we're going to send the client. |
|
| 82 | + $original_count = count( $files ); |
|
| 83 | + |
|
| 84 | + // Sort by size ascending. |
|
| 85 | + usort( $files, function ( $f1, $f2 ) { |
|
| 86 | + if ( $f1[ Ttl_Cache_Cleaner::MTIME ] === $f2[ Ttl_Cache_Cleaner::MTIME ] ) { |
|
| 87 | + return 0; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + return ( $f1[ Ttl_Cache_Cleaner::MTIME ] < $f2[ Ttl_Cache_Cleaner::MTIME ] ) ? - 1 : 1; |
|
| 91 | + } ); |
|
| 92 | + |
|
| 93 | + // Start removing stale files. |
|
| 94 | + for ( $i = 0; $i < count( $files ); $i ++ ) { |
|
| 95 | + $file = $files[ $i ]; |
|
| 96 | + // Break if the mtime is within the range. |
|
| 97 | + if ( $file[ Ttl_Cache_Cleaner::MTIME ] > $max_mtime ) { |
|
| 98 | + break; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + unset( $files[ $i ] ); |
|
| 102 | + @unlink( $file[ Ttl_Cache_Cleaner::PATH ] ); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + // Calculate the size. |
|
| 106 | + $total_size = array_reduce( $files, function ( $carry, $item ) { |
|
| 107 | + |
|
| 108 | + return $carry + $item[ Ttl_Cache_Cleaner::SIZE ]; |
|
| 109 | + }, 0 ); |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + // Remove files until we're within the max size. |
|
| 113 | + while ( $total_size > $this->max_size ) { |
|
| 114 | + $file = array_shift( $files ); |
|
| 115 | + $total_size -= $file[ Ttl_Cache_Cleaner::SIZE ]; |
|
| 116 | + @unlink( $file[ Ttl_Cache_Cleaner::PATH ] ); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + // Send back some stats. |
|
| 120 | + wp_send_json_success( array( |
|
| 121 | + 'initial_count' => $original_count, |
|
| 122 | + 'current_count' => count( $files ), |
|
| 123 | + 'current_size' => $total_size, |
|
| 124 | + ) ); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + private function reduce( $accumulator, $path ) { |
|
| 128 | + |
|
| 129 | + // Open the dir handle. |
|
| 130 | + $handle = opendir( $path ); |
|
| 131 | + |
|
| 132 | + // Catch exceptions to be sure to close the dir handle. |
|
| 133 | + try { |
|
| 134 | + $accumulator = @$this->_reduce( $accumulator, $path, $handle ); |
|
| 135 | + } catch ( Exception $e ) { |
|
| 136 | + // Do nothing. |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - // Finally close the directory handle. |
|
| 140 | - closedir( $handle ); |
|
| 139 | + // Finally close the directory handle. |
|
| 140 | + closedir( $handle ); |
|
| 141 | 141 | |
| 142 | - return $accumulator; |
|
| 143 | - } |
|
| 142 | + return $accumulator; |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - /** |
|
| 146 | - * @param $accumulator |
|
| 147 | - * @param $path |
|
| 148 | - * @param $handle |
|
| 149 | - * |
|
| 150 | - * @return array |
|
| 151 | - */ |
|
| 152 | - private function _reduce( $accumulator, $path, $handle ) { |
|
| 145 | + /** |
|
| 146 | + * @param $accumulator |
|
| 147 | + * @param $path |
|
| 148 | + * @param $handle |
|
| 149 | + * |
|
| 150 | + * @return array |
|
| 151 | + */ |
|
| 152 | + private function _reduce( $accumulator, $path, $handle ) { |
|
| 153 | 153 | |
| 154 | - while ( false !== ( $entry = readdir( $handle ) ) ) { |
|
| 154 | + while ( false !== ( $entry = readdir( $handle ) ) ) { |
|
| 155 | 155 | |
| 156 | - // Skip to the next one. |
|
| 157 | - if ( 0 === strpos( $entry, '.' ) ) { |
|
| 158 | - continue; |
|
| 159 | - } |
|
| 156 | + // Skip to the next one. |
|
| 157 | + if ( 0 === strpos( $entry, '.' ) ) { |
|
| 158 | + continue; |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - // Set the full path to the entry. |
|
| 162 | - $entry_path = $path . DIRECTORY_SEPARATOR . $entry; |
|
| 161 | + // Set the full path to the entry. |
|
| 162 | + $entry_path = $path . DIRECTORY_SEPARATOR . $entry; |
|
| 163 | 163 | |
| 164 | - // Handle directories. |
|
| 165 | - if ( is_dir( $entry_path ) ) { |
|
| 166 | - $accumulator = $this->reduce( $accumulator, $entry_path ); |
|
| 164 | + // Handle directories. |
|
| 165 | + if ( is_dir( $entry_path ) ) { |
|
| 166 | + $accumulator = $this->reduce( $accumulator, $entry_path ); |
|
| 167 | 167 | |
| 168 | - continue; |
|
| 169 | - } |
|
| 168 | + continue; |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - // Store the file data. |
|
| 172 | - $accumulator[] = array( |
|
| 173 | - $entry_path, |
|
| 174 | - filemtime( $entry_path ), |
|
| 175 | - filesize( $entry_path ), |
|
| 176 | - ); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - return $accumulator; |
|
| 180 | - } |
|
| 171 | + // Store the file data. |
|
| 172 | + $accumulator[] = array( |
|
| 173 | + $entry_path, |
|
| 174 | + filemtime( $entry_path ), |
|
| 175 | + filesize( $entry_path ), |
|
| 176 | + ); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + return $accumulator; |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | 182 | } |
@@ -16,8 +16,8 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | use Exception; |
| 18 | 18 | |
| 19 | -defined( 'WORDLIFT_CACHE_DEFAULT_TTL' ) || define( 'WORDLIFT_CACHE_DEFAULT_TTL', 86400 ); // 24 hours |
|
| 20 | -defined( 'WORDLIFT_CACHE_DEFAULT_MAX_SIZE' ) || define( 'WORDLIFT_CACHE_DEFAULT_MAX_SIZE', 104857600 ); // 100 M |
|
| 19 | +defined('WORDLIFT_CACHE_DEFAULT_TTL') || define('WORDLIFT_CACHE_DEFAULT_TTL', 86400); // 24 hours |
|
| 20 | +defined('WORDLIFT_CACHE_DEFAULT_MAX_SIZE') || define('WORDLIFT_CACHE_DEFAULT_MAX_SIZE', 104857600); // 100 M |
|
| 21 | 21 | |
| 22 | 22 | class Ttl_Cache_Cleaner { |
| 23 | 23 | |
@@ -47,97 +47,97 @@ discard block |
||
| 47 | 47 | * @param int $ttl The max TTL in seconds. |
| 48 | 48 | * @param int $max_size The max size in bytes. |
| 49 | 49 | */ |
| 50 | - public function __construct( $ttl = WORDLIFT_CACHE_DEFAULT_TTL, $max_size = WORDLIFT_CACHE_DEFAULT_MAX_SIZE ) { |
|
| 50 | + public function __construct($ttl = WORDLIFT_CACHE_DEFAULT_TTL, $max_size = WORDLIFT_CACHE_DEFAULT_MAX_SIZE) { |
|
| 51 | 51 | |
| 52 | 52 | $this->ttl = $ttl; |
| 53 | 53 | $this->max_size = $max_size; |
| 54 | 54 | |
| 55 | - add_action( 'wp_ajax_wl_ttl_cache_cleaner__cleanup', array( $this, 'cleanup' ) ); |
|
| 56 | - add_action( 'wl_ttl_cache_cleaner__cleanup', array( $this, 'cleanup' ) ); |
|
| 55 | + add_action('wp_ajax_wl_ttl_cache_cleaner__cleanup', array($this, 'cleanup')); |
|
| 56 | + add_action('wl_ttl_cache_cleaner__cleanup', array($this, 'cleanup')); |
|
| 57 | 57 | |
| 58 | 58 | // Do not bother to configure scheduled tasks while running on the front-end. |
| 59 | - if ( is_admin() && ! wp_next_scheduled( 'wl_ttl_cache_cleaner__cleanup' ) ) { |
|
| 60 | - wp_schedule_event( time(), 'hourly', 'wl_ttl_cache_cleaner__cleanup' ); |
|
| 59 | + if (is_admin() && ! wp_next_scheduled('wl_ttl_cache_cleaner__cleanup')) { |
|
| 60 | + wp_schedule_event(time(), 'hourly', 'wl_ttl_cache_cleaner__cleanup'); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | public static function deactivate() { |
| 66 | 66 | |
| 67 | - $timestamp = wp_next_scheduled( 'wl_ttl_cache_cleaner__cleanup' ); |
|
| 68 | - wp_unschedule_event( $timestamp, 'wl_ttl_cache_cleaner__cleanup' ); |
|
| 67 | + $timestamp = wp_next_scheduled('wl_ttl_cache_cleaner__cleanup'); |
|
| 68 | + wp_unschedule_event($timestamp, 'wl_ttl_cache_cleaner__cleanup'); |
|
| 69 | 69 | |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | public function cleanup() { |
| 73 | 73 | |
| 74 | 74 | // Get all the files, recursive. |
| 75 | - $files = $this->reduce( array(), Ttl_Cache::get_cache_folder() ); |
|
| 75 | + $files = $this->reduce(array(), Ttl_Cache::get_cache_folder()); |
|
| 76 | 76 | |
| 77 | 77 | |
| 78 | 78 | // Get the max mtime. |
| 79 | 79 | $max_mtime = time() - WORDLIFT_CACHE_DEFAULT_TTL; |
| 80 | 80 | |
| 81 | 81 | // Keep the original count for statistics that we're going to send the client. |
| 82 | - $original_count = count( $files ); |
|
| 82 | + $original_count = count($files); |
|
| 83 | 83 | |
| 84 | 84 | // Sort by size ascending. |
| 85 | - usort( $files, function ( $f1, $f2 ) { |
|
| 86 | - if ( $f1[ Ttl_Cache_Cleaner::MTIME ] === $f2[ Ttl_Cache_Cleaner::MTIME ] ) { |
|
| 85 | + usort($files, function($f1, $f2) { |
|
| 86 | + if ($f1[Ttl_Cache_Cleaner::MTIME] === $f2[Ttl_Cache_Cleaner::MTIME]) { |
|
| 87 | 87 | return 0; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - return ( $f1[ Ttl_Cache_Cleaner::MTIME ] < $f2[ Ttl_Cache_Cleaner::MTIME ] ) ? - 1 : 1; |
|
| 90 | + return ($f1[Ttl_Cache_Cleaner::MTIME] < $f2[Ttl_Cache_Cleaner::MTIME]) ? -1 : 1; |
|
| 91 | 91 | } ); |
| 92 | 92 | |
| 93 | 93 | // Start removing stale files. |
| 94 | - for ( $i = 0; $i < count( $files ); $i ++ ) { |
|
| 95 | - $file = $files[ $i ]; |
|
| 94 | + for ($i = 0; $i < count($files); $i++) { |
|
| 95 | + $file = $files[$i]; |
|
| 96 | 96 | // Break if the mtime is within the range. |
| 97 | - if ( $file[ Ttl_Cache_Cleaner::MTIME ] > $max_mtime ) { |
|
| 97 | + if ($file[Ttl_Cache_Cleaner::MTIME] > $max_mtime) { |
|
| 98 | 98 | break; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - unset( $files[ $i ] ); |
|
| 102 | - @unlink( $file[ Ttl_Cache_Cleaner::PATH ] ); |
|
| 101 | + unset($files[$i]); |
|
| 102 | + @unlink($file[Ttl_Cache_Cleaner::PATH]); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | // Calculate the size. |
| 106 | - $total_size = array_reduce( $files, function ( $carry, $item ) { |
|
| 106 | + $total_size = array_reduce($files, function($carry, $item) { |
|
| 107 | 107 | |
| 108 | - return $carry + $item[ Ttl_Cache_Cleaner::SIZE ]; |
|
| 109 | - }, 0 ); |
|
| 108 | + return $carry + $item[Ttl_Cache_Cleaner::SIZE]; |
|
| 109 | + }, 0); |
|
| 110 | 110 | |
| 111 | 111 | |
| 112 | 112 | // Remove files until we're within the max size. |
| 113 | - while ( $total_size > $this->max_size ) { |
|
| 114 | - $file = array_shift( $files ); |
|
| 115 | - $total_size -= $file[ Ttl_Cache_Cleaner::SIZE ]; |
|
| 116 | - @unlink( $file[ Ttl_Cache_Cleaner::PATH ] ); |
|
| 113 | + while ($total_size > $this->max_size) { |
|
| 114 | + $file = array_shift($files); |
|
| 115 | + $total_size -= $file[Ttl_Cache_Cleaner::SIZE]; |
|
| 116 | + @unlink($file[Ttl_Cache_Cleaner::PATH]); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | // Send back some stats. |
| 120 | - wp_send_json_success( array( |
|
| 120 | + wp_send_json_success(array( |
|
| 121 | 121 | 'initial_count' => $original_count, |
| 122 | - 'current_count' => count( $files ), |
|
| 122 | + 'current_count' => count($files), |
|
| 123 | 123 | 'current_size' => $total_size, |
| 124 | - ) ); |
|
| 124 | + )); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - private function reduce( $accumulator, $path ) { |
|
| 127 | + private function reduce($accumulator, $path) { |
|
| 128 | 128 | |
| 129 | 129 | // Open the dir handle. |
| 130 | - $handle = opendir( $path ); |
|
| 130 | + $handle = opendir($path); |
|
| 131 | 131 | |
| 132 | 132 | // Catch exceptions to be sure to close the dir handle. |
| 133 | 133 | try { |
| 134 | - $accumulator = @$this->_reduce( $accumulator, $path, $handle ); |
|
| 135 | - } catch ( Exception $e ) { |
|
| 134 | + $accumulator = @$this->_reduce($accumulator, $path, $handle); |
|
| 135 | + } catch (Exception $e) { |
|
| 136 | 136 | // Do nothing. |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | // Finally close the directory handle. |
| 140 | - closedir( $handle ); |
|
| 140 | + closedir($handle); |
|
| 141 | 141 | |
| 142 | 142 | return $accumulator; |
| 143 | 143 | } |
@@ -149,21 +149,21 @@ discard block |
||
| 149 | 149 | * |
| 150 | 150 | * @return array |
| 151 | 151 | */ |
| 152 | - private function _reduce( $accumulator, $path, $handle ) { |
|
| 152 | + private function _reduce($accumulator, $path, $handle) { |
|
| 153 | 153 | |
| 154 | - while ( false !== ( $entry = readdir( $handle ) ) ) { |
|
| 154 | + while (false !== ($entry = readdir($handle))) { |
|
| 155 | 155 | |
| 156 | 156 | // Skip to the next one. |
| 157 | - if ( 0 === strpos( $entry, '.' ) ) { |
|
| 157 | + if (0 === strpos($entry, '.')) { |
|
| 158 | 158 | continue; |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | // Set the full path to the entry. |
| 162 | - $entry_path = $path . DIRECTORY_SEPARATOR . $entry; |
|
| 162 | + $entry_path = $path.DIRECTORY_SEPARATOR.$entry; |
|
| 163 | 163 | |
| 164 | 164 | // Handle directories. |
| 165 | - if ( is_dir( $entry_path ) ) { |
|
| 166 | - $accumulator = $this->reduce( $accumulator, $entry_path ); |
|
| 165 | + if (is_dir($entry_path)) { |
|
| 166 | + $accumulator = $this->reduce($accumulator, $entry_path); |
|
| 167 | 167 | |
| 168 | 168 | continue; |
| 169 | 169 | } |
@@ -171,8 +171,8 @@ discard block |
||
| 171 | 171 | // Store the file data. |
| 172 | 172 | $accumulator[] = array( |
| 173 | 173 | $entry_path, |
| 174 | - filemtime( $entry_path ), |
|
| 175 | - filesize( $entry_path ), |
|
| 174 | + filemtime($entry_path), |
|
| 175 | + filesize($entry_path), |
|
| 176 | 176 | ); |
| 177 | 177 | } |
| 178 | 178 | |
@@ -16,129 +16,129 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | function wl_shortcode_navigator_data() { |
| 18 | 18 | |
| 19 | - // Create the cache key. |
|
| 20 | - $cache_key_params = $_REQUEST; |
|
| 21 | - unset( $cache_key_params['uniqid'] ); |
|
| 22 | - $cache_key = array( 'request_params' => $cache_key_params ); |
|
| 19 | + // Create the cache key. |
|
| 20 | + $cache_key_params = $_REQUEST; |
|
| 21 | + unset( $cache_key_params['uniqid'] ); |
|
| 22 | + $cache_key = array( 'request_params' => $cache_key_params ); |
|
| 23 | 23 | |
| 24 | - // Create the TTL cache and try to get the results. |
|
| 25 | - $cache = new Ttl_Cache( "navigator", 24 * 60 * 60 ); // 24 hours. |
|
| 26 | - $cache_results = $cache->get( $cache_key ); |
|
| 24 | + // Create the TTL cache and try to get the results. |
|
| 25 | + $cache = new Ttl_Cache( "navigator", 24 * 60 * 60 ); // 24 hours. |
|
| 26 | + $cache_results = $cache->get( $cache_key ); |
|
| 27 | 27 | |
| 28 | - if ( isset( $cache_results ) ) { |
|
| 29 | - header( 'X-WordLift-Cache: HIT' ); |
|
| 28 | + if ( isset( $cache_results ) ) { |
|
| 29 | + header( 'X-WordLift-Cache: HIT' ); |
|
| 30 | 30 | |
| 31 | - return $cache_results; |
|
| 32 | - } |
|
| 31 | + return $cache_results; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - header( 'X-WordLift-Cache: MISS' ); |
|
| 34 | + header( 'X-WordLift-Cache: MISS' ); |
|
| 35 | 35 | |
| 36 | - $results = _wl_navigator_get_data(); |
|
| 36 | + $results = _wl_navigator_get_data(); |
|
| 37 | 37 | |
| 38 | - // Put the result before sending the json to the client, since sending the json will terminate us. |
|
| 39 | - $cache->put( $cache_key, $results ); |
|
| 38 | + // Put the result before sending the json to the client, since sending the json will terminate us. |
|
| 39 | + $cache->put( $cache_key, $results ); |
|
| 40 | 40 | |
| 41 | - return $results; |
|
| 41 | + return $results; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | function _wl_navigator_get_data() { |
| 45 | 45 | |
| 46 | - // Post ID must be defined |
|
| 47 | - if ( ! isset( $_GET['post_id'] ) ) { |
|
| 48 | - wp_send_json_error( 'No post_id given' ); |
|
| 46 | + // Post ID must be defined |
|
| 47 | + if ( ! isset( $_GET['post_id'] ) ) { |
|
| 48 | + wp_send_json_error( 'No post_id given' ); |
|
| 49 | 49 | |
| 50 | - return array(); |
|
| 51 | - } |
|
| 50 | + return array(); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - // Limit the results (defaults to 4) |
|
| 54 | - $navigator_length = isset( $_GET['limit'] ) ? intval( $_GET['limit'] ) : 4; |
|
| 55 | - $navigator_offset = isset( $_GET['offset'] ) ? intval( $_GET['offset'] ) : 0; |
|
| 53 | + // Limit the results (defaults to 4) |
|
| 54 | + $navigator_length = isset( $_GET['limit'] ) ? intval( $_GET['limit'] ) : 4; |
|
| 55 | + $navigator_offset = isset( $_GET['offset'] ) ? intval( $_GET['offset'] ) : 0; |
|
| 56 | 56 | |
| 57 | - $current_post_id = $_GET['post_id']; |
|
| 58 | - $current_post = get_post( $current_post_id ); |
|
| 57 | + $current_post_id = $_GET['post_id']; |
|
| 58 | + $current_post = get_post( $current_post_id ); |
|
| 59 | 59 | |
| 60 | - $navigator_id = $_GET['uniqid']; |
|
| 60 | + $navigator_id = $_GET['uniqid']; |
|
| 61 | 61 | |
| 62 | - // Post ID has to match an existing item |
|
| 63 | - if ( null === $current_post ) { |
|
| 64 | - wp_die( 'No valid post_id given' ); |
|
| 62 | + // Post ID has to match an existing item |
|
| 63 | + if ( null === $current_post ) { |
|
| 64 | + wp_die( 'No valid post_id given' ); |
|
| 65 | 65 | |
| 66 | - return array(); |
|
| 67 | - } |
|
| 66 | + return array(); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - $referencing_posts = _wl_navigator_get_results( $current_post_id, array( |
|
| 70 | - 'ID', |
|
| 71 | - 'post_title', |
|
| 72 | - ), 'ID DESC', $navigator_length, $navigator_offset ); |
|
| 69 | + $referencing_posts = _wl_navigator_get_results( $current_post_id, array( |
|
| 70 | + 'ID', |
|
| 71 | + 'post_title', |
|
| 72 | + ), 'ID DESC', $navigator_length, $navigator_offset ); |
|
| 73 | 73 | |
| 74 | - // loop over them and take the first one which is not already in the $related_posts |
|
| 75 | - $results = array(); |
|
| 76 | - foreach ( $referencing_posts as $referencing_post ) { |
|
| 77 | - $serialized_entity = wl_serialize_entity( $referencing_post->entity_id ); |
|
| 74 | + // loop over them and take the first one which is not already in the $related_posts |
|
| 75 | + $results = array(); |
|
| 76 | + foreach ( $referencing_posts as $referencing_post ) { |
|
| 77 | + $serialized_entity = wl_serialize_entity( $referencing_post->entity_id ); |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Use the thumbnail. |
|
| 81 | - * |
|
| 82 | - * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue. |
|
| 83 | - * @see https://github.com/insideout10/wordlift-plugin/issues/837 |
|
| 84 | - * |
|
| 85 | - * @since 3.19.3 We're using the medium size image. |
|
| 86 | - */ |
|
| 87 | - $thumbnail = get_the_post_thumbnail_url( $referencing_post, 'medium' ); |
|
| 79 | + /** |
|
| 80 | + * Use the thumbnail. |
|
| 81 | + * |
|
| 82 | + * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue. |
|
| 83 | + * @see https://github.com/insideout10/wordlift-plugin/issues/837 |
|
| 84 | + * |
|
| 85 | + * @since 3.19.3 We're using the medium size image. |
|
| 86 | + */ |
|
| 87 | + $thumbnail = get_the_post_thumbnail_url( $referencing_post, 'medium' ); |
|
| 88 | 88 | |
| 89 | 89 | // if ( $thumbnail ) { |
| 90 | 90 | |
| 91 | - $result = array( |
|
| 92 | - 'post' => array( |
|
| 93 | - 'permalink' => get_permalink( $referencing_post->ID ), |
|
| 94 | - 'title' => $referencing_post->post_title, |
|
| 95 | - 'thumbnail' => $thumbnail, |
|
| 96 | - ), |
|
| 97 | - 'entity' => array( |
|
| 98 | - 'label' => $serialized_entity['label'], |
|
| 99 | - 'mainType' => $serialized_entity['mainType'], |
|
| 100 | - 'permalink' => get_permalink( $referencing_post->entity_id ), |
|
| 101 | - ), |
|
| 102 | - ); |
|
| 103 | - |
|
| 104 | - $result['post'] = apply_filters( 'wl_navigator_data_post', $result['post'], intval( $referencing_post->ID ), $navigator_id ); |
|
| 105 | - $result['entity'] = apply_filters( 'wl_navigator_data_entity', $result['entity'], intval( $referencing_post->entity_id ), $navigator_id ); |
|
| 106 | - |
|
| 107 | - $results[] = $result; |
|
| 108 | - |
|
| 109 | - // Be sure no more than 1 post for entity is returned |
|
| 91 | + $result = array( |
|
| 92 | + 'post' => array( |
|
| 93 | + 'permalink' => get_permalink( $referencing_post->ID ), |
|
| 94 | + 'title' => $referencing_post->post_title, |
|
| 95 | + 'thumbnail' => $thumbnail, |
|
| 96 | + ), |
|
| 97 | + 'entity' => array( |
|
| 98 | + 'label' => $serialized_entity['label'], |
|
| 99 | + 'mainType' => $serialized_entity['mainType'], |
|
| 100 | + 'permalink' => get_permalink( $referencing_post->entity_id ), |
|
| 101 | + ), |
|
| 102 | + ); |
|
| 103 | + |
|
| 104 | + $result['post'] = apply_filters( 'wl_navigator_data_post', $result['post'], intval( $referencing_post->ID ), $navigator_id ); |
|
| 105 | + $result['entity'] = apply_filters( 'wl_navigator_data_entity', $result['entity'], intval( $referencing_post->entity_id ), $navigator_id ); |
|
| 106 | + |
|
| 107 | + $results[] = $result; |
|
| 108 | + |
|
| 109 | + // Be sure no more than 1 post for entity is returned |
|
| 110 | 110 | // break; |
| 111 | 111 | // } |
| 112 | - } |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - if ( count( $results ) < $navigator_length ) { |
|
| 115 | - $results = apply_filters( 'wl_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length ); |
|
| 116 | - } |
|
| 114 | + if ( count( $results ) < $navigator_length ) { |
|
| 115 | + $results = apply_filters( 'wl_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length ); |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - // Return first 4 results in json accordingly to 4 columns layout |
|
| 119 | - return $results; |
|
| 118 | + // Return first 4 results in json accordingly to 4 columns layout |
|
| 119 | + return $results; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | |
| 123 | 123 | function _wl_navigator_get_results( |
| 124 | - $post_id, $fields = array( |
|
| 125 | - 'ID', |
|
| 126 | - 'post_title', |
|
| 124 | + $post_id, $fields = array( |
|
| 125 | + 'ID', |
|
| 126 | + 'post_title', |
|
| 127 | 127 | ), $order_by = 'ID DESC', $limit = 10, $offset = 0 |
| 128 | 128 | ) { |
| 129 | - global $wpdb; |
|
| 129 | + global $wpdb; |
|
| 130 | 130 | |
| 131 | - $select = implode( ', ', array_map( function ( $item ) { |
|
| 132 | - return "p.$item AS $item"; |
|
| 133 | - }, (array) $fields ) ); |
|
| 131 | + $select = implode( ', ', array_map( function ( $item ) { |
|
| 132 | + return "p.$item AS $item"; |
|
| 133 | + }, (array) $fields ) ); |
|
| 134 | 134 | |
| 135 | - $order_by = implode( ', ', array_map( function ( $item ) { |
|
| 136 | - return "p.$item"; |
|
| 137 | - }, (array) $order_by ) ); |
|
| 135 | + $order_by = implode( ', ', array_map( function ( $item ) { |
|
| 136 | + return "p.$item"; |
|
| 137 | + }, (array) $order_by ) ); |
|
| 138 | 138 | |
| 139 | - /** @noinspection SqlNoDataSourceInspection */ |
|
| 140 | - return $wpdb->get_results( |
|
| 141 | - $wpdb->prepare( <<<EOF |
|
| 139 | + /** @noinspection SqlNoDataSourceInspection */ |
|
| 140 | + return $wpdb->get_results( |
|
| 141 | + $wpdb->prepare( <<<EOF |
|
| 142 | 142 | SELECT %4\$s, p2.ID as entity_id |
| 143 | 143 | FROM {$wpdb->prefix}wl_relation_instances r1 |
| 144 | 144 | INNER JOIN {$wpdb->prefix}wl_relation_instances r2 |
@@ -170,8 +170,8 @@ discard block |
||
| 170 | 170 | LIMIT %2\$d |
| 171 | 171 | OFFSET %3\$d |
| 172 | 172 | EOF |
| 173 | - , $post_id, $limit, $offset, $select, $order_by ) |
|
| 174 | - ); |
|
| 173 | + , $post_id, $limit, $offset, $select, $order_by ) |
|
| 174 | + ); |
|
| 175 | 175 | |
| 176 | 176 | } |
| 177 | 177 | |
@@ -182,9 +182,9 @@ discard block |
||
| 182 | 182 | */ |
| 183 | 183 | function wl_shortcode_navigator_ajax() { |
| 184 | 184 | |
| 185 | - // Temporary blocking the Navigator. |
|
| 186 | - $results = wl_shortcode_navigator_data(); |
|
| 187 | - wl_core_send_json( $results ); |
|
| 185 | + // Temporary blocking the Navigator. |
|
| 186 | + $results = wl_shortcode_navigator_data(); |
|
| 187 | + wl_core_send_json( $results ); |
|
| 188 | 188 | |
| 189 | 189 | } |
| 190 | 190 | |
@@ -196,16 +196,16 @@ discard block |
||
| 196 | 196 | */ |
| 197 | 197 | function wl_shortcode_navigator_wp_json() { |
| 198 | 198 | |
| 199 | - $results = wl_shortcode_navigator_data(); |
|
| 200 | - if ( ob_get_contents() ) { |
|
| 201 | - ob_clean(); |
|
| 202 | - } |
|
| 199 | + $results = wl_shortcode_navigator_data(); |
|
| 200 | + if ( ob_get_contents() ) { |
|
| 201 | + ob_clean(); |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - return array( |
|
| 205 | - 'items' => array( |
|
| 206 | - array( 'values' => $results ), |
|
| 207 | - ), |
|
| 208 | - ); |
|
| 204 | + return array( |
|
| 205 | + 'items' => array( |
|
| 206 | + array( 'values' => $results ), |
|
| 207 | + ), |
|
| 208 | + ); |
|
| 209 | 209 | |
| 210 | 210 | } |
| 211 | 211 | |
@@ -213,56 +213,56 @@ discard block |
||
| 213 | 213 | * Adding `rest_api_init` action for amp backend of navigator |
| 214 | 214 | */ |
| 215 | 215 | add_action( 'rest_api_init', function () { |
| 216 | - register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/navigator', array( |
|
| 217 | - 'methods' => 'GET', |
|
| 218 | - 'callback' => 'wl_shortcode_navigator_wp_json', |
|
| 219 | - ) ); |
|
| 216 | + register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/navigator', array( |
|
| 217 | + 'methods' => 'GET', |
|
| 218 | + 'callback' => 'wl_shortcode_navigator_wp_json', |
|
| 219 | + ) ); |
|
| 220 | 220 | } ); |
| 221 | 221 | |
| 222 | 222 | /** |
| 223 | 223 | * register_block_type for Gutenberg blocks |
| 224 | 224 | */ |
| 225 | 225 | add_action( 'init', function () { |
| 226 | - // Bail out if the `register_block_type` function isn't available. |
|
| 227 | - if ( ! function_exists( 'register_block_type' ) ) { |
|
| 228 | - return; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - register_block_type( 'wordlift/navigator', array( |
|
| 232 | - 'editor_script' => 'wordlift-admin-edit-gutenberg', |
|
| 233 | - 'render_callback' => function ( $attributes ) { |
|
| 234 | - $attr_code = ''; |
|
| 235 | - foreach ( $attributes as $key => $value ) { |
|
| 236 | - $attr_code .= $key . '="' . $value . '" '; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return '[wl_navigator ' . $attr_code . ']'; |
|
| 240 | - }, |
|
| 241 | - 'attributes' => array( |
|
| 242 | - 'title' => array( |
|
| 243 | - 'type' => 'string', |
|
| 244 | - 'default' => __( 'Related articles', 'wordlift' ), |
|
| 245 | - ), |
|
| 246 | - 'limit' => array( |
|
| 247 | - 'type' => 'number', |
|
| 248 | - 'default' => 4, |
|
| 249 | - ), |
|
| 250 | - 'template_id' => array( |
|
| 251 | - 'type' => 'string', |
|
| 252 | - ), |
|
| 253 | - 'post_id' => array( |
|
| 254 | - 'type' => 'number', |
|
| 255 | - ), |
|
| 256 | - 'offset' => array( |
|
| 257 | - 'type' => 'number', |
|
| 258 | - 'default' => 0, |
|
| 259 | - ), |
|
| 260 | - 'uniqid' => array( |
|
| 261 | - 'type' => 'string', |
|
| 262 | - 'default' => uniqid( 'wl-navigator-widget-' ), |
|
| 263 | - ), |
|
| 264 | - ), |
|
| 265 | - ) ); |
|
| 226 | + // Bail out if the `register_block_type` function isn't available. |
|
| 227 | + if ( ! function_exists( 'register_block_type' ) ) { |
|
| 228 | + return; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + register_block_type( 'wordlift/navigator', array( |
|
| 232 | + 'editor_script' => 'wordlift-admin-edit-gutenberg', |
|
| 233 | + 'render_callback' => function ( $attributes ) { |
|
| 234 | + $attr_code = ''; |
|
| 235 | + foreach ( $attributes as $key => $value ) { |
|
| 236 | + $attr_code .= $key . '="' . $value . '" '; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return '[wl_navigator ' . $attr_code . ']'; |
|
| 240 | + }, |
|
| 241 | + 'attributes' => array( |
|
| 242 | + 'title' => array( |
|
| 243 | + 'type' => 'string', |
|
| 244 | + 'default' => __( 'Related articles', 'wordlift' ), |
|
| 245 | + ), |
|
| 246 | + 'limit' => array( |
|
| 247 | + 'type' => 'number', |
|
| 248 | + 'default' => 4, |
|
| 249 | + ), |
|
| 250 | + 'template_id' => array( |
|
| 251 | + 'type' => 'string', |
|
| 252 | + ), |
|
| 253 | + 'post_id' => array( |
|
| 254 | + 'type' => 'number', |
|
| 255 | + ), |
|
| 256 | + 'offset' => array( |
|
| 257 | + 'type' => 'number', |
|
| 258 | + 'default' => 0, |
|
| 259 | + ), |
|
| 260 | + 'uniqid' => array( |
|
| 261 | + 'type' => 'string', |
|
| 262 | + 'default' => uniqid( 'wl-navigator-widget-' ), |
|
| 263 | + ), |
|
| 264 | + ), |
|
| 265 | + ) ); |
|
| 266 | 266 | } ); |
| 267 | 267 | |
| 268 | 268 | /** |
@@ -272,22 +272,22 @@ discard block |
||
| 272 | 272 | */ |
| 273 | 273 | add_action( 'plugins_loaded', function () { |
| 274 | 274 | |
| 275 | - if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action'] ) { |
|
| 276 | - return; |
|
| 277 | - } |
|
| 275 | + if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action'] ) { |
|
| 276 | + return; |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | - remove_action( 'plugins_loaded', 'rocket_init' ); |
|
| 280 | - remove_action( 'plugins_loaded', 'wpseo_premium_init', 14 ); |
|
| 281 | - remove_action( 'plugins_loaded', 'wpseo_init', 14 ); |
|
| 279 | + remove_action( 'plugins_loaded', 'rocket_init' ); |
|
| 280 | + remove_action( 'plugins_loaded', 'wpseo_premium_init', 14 ); |
|
| 281 | + remove_action( 'plugins_loaded', 'wpseo_init', 14 ); |
|
| 282 | 282 | }, 0 ); |
| 283 | 283 | |
| 284 | 284 | add_action( 'init', function () { |
| 285 | 285 | |
| 286 | - if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action'] ) { |
|
| 287 | - return; |
|
| 288 | - } |
|
| 286 | + if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action'] ) { |
|
| 287 | + return; |
|
| 288 | + } |
|
| 289 | 289 | |
| 290 | - remove_action( 'init', 'wp_widgets_init', 1 ); |
|
| 291 | - remove_action( 'init', 'gglcptch_init' ); |
|
| 290 | + remove_action( 'init', 'wp_widgets_init', 1 ); |
|
| 291 | + remove_action( 'init', 'gglcptch_init' ); |
|
| 292 | 292 | }, 0 ); |
| 293 | 293 | |
@@ -18,25 +18,25 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | // Create the cache key. |
| 20 | 20 | $cache_key_params = $_REQUEST; |
| 21 | - unset( $cache_key_params['uniqid'] ); |
|
| 22 | - $cache_key = array( 'request_params' => $cache_key_params ); |
|
| 21 | + unset($cache_key_params['uniqid']); |
|
| 22 | + $cache_key = array('request_params' => $cache_key_params); |
|
| 23 | 23 | |
| 24 | 24 | // Create the TTL cache and try to get the results. |
| 25 | - $cache = new Ttl_Cache( "navigator", 24 * 60 * 60 ); // 24 hours. |
|
| 26 | - $cache_results = $cache->get( $cache_key ); |
|
| 25 | + $cache = new Ttl_Cache("navigator", 24 * 60 * 60); // 24 hours. |
|
| 26 | + $cache_results = $cache->get($cache_key); |
|
| 27 | 27 | |
| 28 | - if ( isset( $cache_results ) ) { |
|
| 29 | - header( 'X-WordLift-Cache: HIT' ); |
|
| 28 | + if (isset($cache_results)) { |
|
| 29 | + header('X-WordLift-Cache: HIT'); |
|
| 30 | 30 | |
| 31 | 31 | return $cache_results; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - header( 'X-WordLift-Cache: MISS' ); |
|
| 34 | + header('X-WordLift-Cache: MISS'); |
|
| 35 | 35 | |
| 36 | 36 | $results = _wl_navigator_get_data(); |
| 37 | 37 | |
| 38 | 38 | // Put the result before sending the json to the client, since sending the json will terminate us. |
| 39 | - $cache->put( $cache_key, $results ); |
|
| 39 | + $cache->put($cache_key, $results); |
|
| 40 | 40 | |
| 41 | 41 | return $results; |
| 42 | 42 | } |
@@ -44,37 +44,37 @@ discard block |
||
| 44 | 44 | function _wl_navigator_get_data() { |
| 45 | 45 | |
| 46 | 46 | // Post ID must be defined |
| 47 | - if ( ! isset( $_GET['post_id'] ) ) { |
|
| 48 | - wp_send_json_error( 'No post_id given' ); |
|
| 47 | + if ( ! isset($_GET['post_id'])) { |
|
| 48 | + wp_send_json_error('No post_id given'); |
|
| 49 | 49 | |
| 50 | 50 | return array(); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | // Limit the results (defaults to 4) |
| 54 | - $navigator_length = isset( $_GET['limit'] ) ? intval( $_GET['limit'] ) : 4; |
|
| 55 | - $navigator_offset = isset( $_GET['offset'] ) ? intval( $_GET['offset'] ) : 0; |
|
| 54 | + $navigator_length = isset($_GET['limit']) ? intval($_GET['limit']) : 4; |
|
| 55 | + $navigator_offset = isset($_GET['offset']) ? intval($_GET['offset']) : 0; |
|
| 56 | 56 | |
| 57 | 57 | $current_post_id = $_GET['post_id']; |
| 58 | - $current_post = get_post( $current_post_id ); |
|
| 58 | + $current_post = get_post($current_post_id); |
|
| 59 | 59 | |
| 60 | 60 | $navigator_id = $_GET['uniqid']; |
| 61 | 61 | |
| 62 | 62 | // Post ID has to match an existing item |
| 63 | - if ( null === $current_post ) { |
|
| 64 | - wp_die( 'No valid post_id given' ); |
|
| 63 | + if (null === $current_post) { |
|
| 64 | + wp_die('No valid post_id given'); |
|
| 65 | 65 | |
| 66 | 66 | return array(); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - $referencing_posts = _wl_navigator_get_results( $current_post_id, array( |
|
| 69 | + $referencing_posts = _wl_navigator_get_results($current_post_id, array( |
|
| 70 | 70 | 'ID', |
| 71 | 71 | 'post_title', |
| 72 | - ), 'ID DESC', $navigator_length, $navigator_offset ); |
|
| 72 | + ), 'ID DESC', $navigator_length, $navigator_offset); |
|
| 73 | 73 | |
| 74 | 74 | // loop over them and take the first one which is not already in the $related_posts |
| 75 | 75 | $results = array(); |
| 76 | - foreach ( $referencing_posts as $referencing_post ) { |
|
| 77 | - $serialized_entity = wl_serialize_entity( $referencing_post->entity_id ); |
|
| 76 | + foreach ($referencing_posts as $referencing_post) { |
|
| 77 | + $serialized_entity = wl_serialize_entity($referencing_post->entity_id); |
|
| 78 | 78 | |
| 79 | 79 | /** |
| 80 | 80 | * Use the thumbnail. |
@@ -84,25 +84,25 @@ discard block |
||
| 84 | 84 | * |
| 85 | 85 | * @since 3.19.3 We're using the medium size image. |
| 86 | 86 | */ |
| 87 | - $thumbnail = get_the_post_thumbnail_url( $referencing_post, 'medium' ); |
|
| 87 | + $thumbnail = get_the_post_thumbnail_url($referencing_post, 'medium'); |
|
| 88 | 88 | |
| 89 | 89 | // if ( $thumbnail ) { |
| 90 | 90 | |
| 91 | 91 | $result = array( |
| 92 | 92 | 'post' => array( |
| 93 | - 'permalink' => get_permalink( $referencing_post->ID ), |
|
| 93 | + 'permalink' => get_permalink($referencing_post->ID), |
|
| 94 | 94 | 'title' => $referencing_post->post_title, |
| 95 | 95 | 'thumbnail' => $thumbnail, |
| 96 | 96 | ), |
| 97 | 97 | 'entity' => array( |
| 98 | 98 | 'label' => $serialized_entity['label'], |
| 99 | 99 | 'mainType' => $serialized_entity['mainType'], |
| 100 | - 'permalink' => get_permalink( $referencing_post->entity_id ), |
|
| 100 | + 'permalink' => get_permalink($referencing_post->entity_id), |
|
| 101 | 101 | ), |
| 102 | 102 | ); |
| 103 | 103 | |
| 104 | - $result['post'] = apply_filters( 'wl_navigator_data_post', $result['post'], intval( $referencing_post->ID ), $navigator_id ); |
|
| 105 | - $result['entity'] = apply_filters( 'wl_navigator_data_entity', $result['entity'], intval( $referencing_post->entity_id ), $navigator_id ); |
|
| 104 | + $result['post'] = apply_filters('wl_navigator_data_post', $result['post'], intval($referencing_post->ID), $navigator_id); |
|
| 105 | + $result['entity'] = apply_filters('wl_navigator_data_entity', $result['entity'], intval($referencing_post->entity_id), $navigator_id); |
|
| 106 | 106 | |
| 107 | 107 | $results[] = $result; |
| 108 | 108 | |
@@ -111,8 +111,8 @@ discard block |
||
| 111 | 111 | // } |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - if ( count( $results ) < $navigator_length ) { |
|
| 115 | - $results = apply_filters( 'wl_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length ); |
|
| 114 | + if (count($results) < $navigator_length) { |
|
| 115 | + $results = apply_filters('wl_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | // Return first 4 results in json accordingly to 4 columns layout |
@@ -128,17 +128,17 @@ discard block |
||
| 128 | 128 | ) { |
| 129 | 129 | global $wpdb; |
| 130 | 130 | |
| 131 | - $select = implode( ', ', array_map( function ( $item ) { |
|
| 131 | + $select = implode(', ', array_map(function($item) { |
|
| 132 | 132 | return "p.$item AS $item"; |
| 133 | - }, (array) $fields ) ); |
|
| 133 | + }, (array) $fields)); |
|
| 134 | 134 | |
| 135 | - $order_by = implode( ', ', array_map( function ( $item ) { |
|
| 135 | + $order_by = implode(', ', array_map(function($item) { |
|
| 136 | 136 | return "p.$item"; |
| 137 | - }, (array) $order_by ) ); |
|
| 137 | + }, (array) $order_by)); |
|
| 138 | 138 | |
| 139 | 139 | /** @noinspection SqlNoDataSourceInspection */ |
| 140 | 140 | return $wpdb->get_results( |
| 141 | - $wpdb->prepare( <<<EOF |
|
| 141 | + $wpdb->prepare(<<<EOF |
|
| 142 | 142 | SELECT %4\$s, p2.ID as entity_id |
| 143 | 143 | FROM {$wpdb->prefix}wl_relation_instances r1 |
| 144 | 144 | INNER JOIN {$wpdb->prefix}wl_relation_instances r2 |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | LIMIT %2\$d |
| 171 | 171 | OFFSET %3\$d |
| 172 | 172 | EOF |
| 173 | - , $post_id, $limit, $offset, $select, $order_by ) |
|
| 173 | + , $post_id, $limit, $offset, $select, $order_by) |
|
| 174 | 174 | ); |
| 175 | 175 | |
| 176 | 176 | } |
@@ -184,12 +184,12 @@ discard block |
||
| 184 | 184 | |
| 185 | 185 | // Temporary blocking the Navigator. |
| 186 | 186 | $results = wl_shortcode_navigator_data(); |
| 187 | - wl_core_send_json( $results ); |
|
| 187 | + wl_core_send_json($results); |
|
| 188 | 188 | |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | -add_action( 'wp_ajax_wl_navigator', 'wl_shortcode_navigator_ajax' ); |
|
| 192 | -add_action( 'wp_ajax_nopriv_wl_navigator', 'wl_shortcode_navigator_ajax' ); |
|
| 191 | +add_action('wp_ajax_wl_navigator', 'wl_shortcode_navigator_ajax'); |
|
| 192 | +add_action('wp_ajax_nopriv_wl_navigator', 'wl_shortcode_navigator_ajax'); |
|
| 193 | 193 | |
| 194 | 194 | /** |
| 195 | 195 | * wp-json call for the navigator widget |
@@ -197,13 +197,13 @@ discard block |
||
| 197 | 197 | function wl_shortcode_navigator_wp_json() { |
| 198 | 198 | |
| 199 | 199 | $results = wl_shortcode_navigator_data(); |
| 200 | - if ( ob_get_contents() ) { |
|
| 200 | + if (ob_get_contents()) { |
|
| 201 | 201 | ob_clean(); |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | return array( |
| 205 | 205 | 'items' => array( |
| 206 | - array( 'values' => $results ), |
|
| 206 | + array('values' => $results), |
|
| 207 | 207 | ), |
| 208 | 208 | ); |
| 209 | 209 | |
@@ -212,36 +212,36 @@ discard block |
||
| 212 | 212 | /** |
| 213 | 213 | * Adding `rest_api_init` action for amp backend of navigator |
| 214 | 214 | */ |
| 215 | -add_action( 'rest_api_init', function () { |
|
| 216 | - register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/navigator', array( |
|
| 215 | +add_action('rest_api_init', function() { |
|
| 216 | + register_rest_route(WL_REST_ROUTE_DEFAULT_NAMESPACE, '/navigator', array( |
|
| 217 | 217 | 'methods' => 'GET', |
| 218 | 218 | 'callback' => 'wl_shortcode_navigator_wp_json', |
| 219 | - ) ); |
|
| 219 | + )); |
|
| 220 | 220 | } ); |
| 221 | 221 | |
| 222 | 222 | /** |
| 223 | 223 | * register_block_type for Gutenberg blocks |
| 224 | 224 | */ |
| 225 | -add_action( 'init', function () { |
|
| 225 | +add_action('init', function() { |
|
| 226 | 226 | // Bail out if the `register_block_type` function isn't available. |
| 227 | - if ( ! function_exists( 'register_block_type' ) ) { |
|
| 227 | + if ( ! function_exists('register_block_type')) { |
|
| 228 | 228 | return; |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - register_block_type( 'wordlift/navigator', array( |
|
| 231 | + register_block_type('wordlift/navigator', array( |
|
| 232 | 232 | 'editor_script' => 'wordlift-admin-edit-gutenberg', |
| 233 | - 'render_callback' => function ( $attributes ) { |
|
| 233 | + 'render_callback' => function($attributes) { |
|
| 234 | 234 | $attr_code = ''; |
| 235 | - foreach ( $attributes as $key => $value ) { |
|
| 236 | - $attr_code .= $key . '="' . $value . '" '; |
|
| 235 | + foreach ($attributes as $key => $value) { |
|
| 236 | + $attr_code .= $key.'="'.$value.'" '; |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | - return '[wl_navigator ' . $attr_code . ']'; |
|
| 239 | + return '[wl_navigator '.$attr_code.']'; |
|
| 240 | 240 | }, |
| 241 | 241 | 'attributes' => array( |
| 242 | 242 | 'title' => array( |
| 243 | 243 | 'type' => 'string', |
| 244 | - 'default' => __( 'Related articles', 'wordlift' ), |
|
| 244 | + 'default' => __('Related articles', 'wordlift'), |
|
| 245 | 245 | ), |
| 246 | 246 | 'limit' => array( |
| 247 | 247 | 'type' => 'number', |
@@ -259,10 +259,10 @@ discard block |
||
| 259 | 259 | ), |
| 260 | 260 | 'uniqid' => array( |
| 261 | 261 | 'type' => 'string', |
| 262 | - 'default' => uniqid( 'wl-navigator-widget-' ), |
|
| 262 | + 'default' => uniqid('wl-navigator-widget-'), |
|
| 263 | 263 | ), |
| 264 | 264 | ), |
| 265 | - ) ); |
|
| 265 | + )); |
|
| 266 | 266 | } ); |
| 267 | 267 | |
| 268 | 268 | /** |
@@ -270,24 +270,24 @@ discard block |
||
| 270 | 270 | * |
| 271 | 271 | * @since 2.2.0 |
| 272 | 272 | */ |
| 273 | -add_action( 'plugins_loaded', function () { |
|
| 273 | +add_action('plugins_loaded', function() { |
|
| 274 | 274 | |
| 275 | - if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action'] ) { |
|
| 275 | + if ( ! defined('DOING_AJAX') || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action']) { |
|
| 276 | 276 | return; |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | - remove_action( 'plugins_loaded', 'rocket_init' ); |
|
| 280 | - remove_action( 'plugins_loaded', 'wpseo_premium_init', 14 ); |
|
| 281 | - remove_action( 'plugins_loaded', 'wpseo_init', 14 ); |
|
| 282 | -}, 0 ); |
|
| 279 | + remove_action('plugins_loaded', 'rocket_init'); |
|
| 280 | + remove_action('plugins_loaded', 'wpseo_premium_init', 14); |
|
| 281 | + remove_action('plugins_loaded', 'wpseo_init', 14); |
|
| 282 | +}, 0); |
|
| 283 | 283 | |
| 284 | -add_action( 'init', function () { |
|
| 284 | +add_action('init', function() { |
|
| 285 | 285 | |
| 286 | - if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action'] ) { |
|
| 286 | + if ( ! defined('DOING_AJAX') || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action']) { |
|
| 287 | 287 | return; |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | - remove_action( 'init', 'wp_widgets_init', 1 ); |
|
| 291 | - remove_action( 'init', 'gglcptch_init' ); |
|
| 292 | -}, 0 ); |
|
| 290 | + remove_action('init', 'wp_widgets_init', 1); |
|
| 291 | + remove_action('init', 'gglcptch_init'); |
|
| 292 | +}, 0); |
|
| 293 | 293 | |