@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | use Wordlift\Autocomplete\Autocomplete_Service; |
14 | 14 | |
15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
16 | - exit; |
|
16 | + exit; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -23,79 +23,79 @@ discard block |
||
23 | 23 | */ |
24 | 24 | class Wordlift_Autocomplete_Adapter { |
25 | 25 | |
26 | - /** |
|
27 | - * The {@link Autocomplete_Service} instance. |
|
28 | - * |
|
29 | - * @since 3.15.0 |
|
30 | - * @access private |
|
31 | - * @var Autocomplete_Service $configuration_service The {@link Autocomplete_Service} instance. |
|
32 | - */ |
|
33 | - private $autocomplete_service; |
|
34 | - |
|
35 | - /** |
|
36 | - * Wordlift_Autocomplete_Adapter constructor. |
|
37 | - * |
|
38 | - * @param Autocomplete_Service $autocomplete_service The {@link Autocomplete_Service} instance. |
|
39 | - * |
|
40 | - * @since 3.14.2 |
|
41 | - */ |
|
42 | - public function __construct( $autocomplete_service ) { |
|
43 | - $this->autocomplete_service = $autocomplete_service; |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * Handle the autocomplete ajax request. |
|
48 | - * |
|
49 | - * @since 3.15.0 |
|
50 | - */ |
|
51 | - public function wl_autocomplete() { |
|
52 | - |
|
53 | - check_ajax_referer( 'wl_autocomplete' ); |
|
54 | - |
|
55 | - // Return error if the query param is empty. |
|
56 | - if ( ! empty( $_REQUEST['query'] ) ) { // Input var okay. |
|
57 | - $query = sanitize_text_field( wp_unslash( $_REQUEST['query'] ) ); // Input var okay. |
|
58 | - } else { |
|
59 | - wp_send_json_error( |
|
60 | - array( |
|
61 | - 'message' => __( 'The query param is empty.', 'wordlift' ), |
|
62 | - ) |
|
63 | - ); |
|
64 | - } |
|
65 | - |
|
66 | - // Get the exclude parameter. |
|
67 | - $exclude = ! empty( $_REQUEST['exclude'] ) |
|
68 | - ? sanitize_text_field( wp_unslash( $_REQUEST['exclude'] ) ) : ''; |
|
69 | - |
|
70 | - $scope = ! empty( $_REQUEST['scope'] ) |
|
71 | - ? sanitize_text_field( wp_unslash( $_REQUEST['scope'] ) ) : WL_AUTOCOMPLETE_SCOPE; |
|
72 | - |
|
73 | - /** |
|
74 | - * @since 3.26.1 |
|
75 | - * Providing a way for term pages to show and save local entities. |
|
76 | - */ |
|
77 | - $show_local_entities = false; |
|
78 | - |
|
79 | - if ( isset( $_REQUEST['show_local_entities'] ) |
|
80 | - && ! empty( $_REQUEST['show_local_entities'] ) ) { // Make request. |
|
81 | - $show_local_entities = filter_var( wp_unslash( $_REQUEST['show_local_entities'] ), FILTER_VALIDATE_BOOLEAN ); |
|
82 | - } |
|
83 | - |
|
84 | - // Add the filter to check if we need to show local entities or not. |
|
85 | - add_filter( |
|
86 | - 'wl_show_local_entities', |
|
87 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
88 | - function ( $state ) use ( $show_local_entities ) { |
|
89 | - return $show_local_entities; |
|
90 | - } |
|
91 | - ); |
|
92 | - |
|
93 | - $results = $this->autocomplete_service->query( $query, $scope, $exclude ); |
|
94 | - |
|
95 | - // Clear any buffer. |
|
96 | - ob_clean(); |
|
97 | - |
|
98 | - wp_send_json_success( $results ); |
|
99 | - |
|
100 | - } |
|
26 | + /** |
|
27 | + * The {@link Autocomplete_Service} instance. |
|
28 | + * |
|
29 | + * @since 3.15.0 |
|
30 | + * @access private |
|
31 | + * @var Autocomplete_Service $configuration_service The {@link Autocomplete_Service} instance. |
|
32 | + */ |
|
33 | + private $autocomplete_service; |
|
34 | + |
|
35 | + /** |
|
36 | + * Wordlift_Autocomplete_Adapter constructor. |
|
37 | + * |
|
38 | + * @param Autocomplete_Service $autocomplete_service The {@link Autocomplete_Service} instance. |
|
39 | + * |
|
40 | + * @since 3.14.2 |
|
41 | + */ |
|
42 | + public function __construct( $autocomplete_service ) { |
|
43 | + $this->autocomplete_service = $autocomplete_service; |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * Handle the autocomplete ajax request. |
|
48 | + * |
|
49 | + * @since 3.15.0 |
|
50 | + */ |
|
51 | + public function wl_autocomplete() { |
|
52 | + |
|
53 | + check_ajax_referer( 'wl_autocomplete' ); |
|
54 | + |
|
55 | + // Return error if the query param is empty. |
|
56 | + if ( ! empty( $_REQUEST['query'] ) ) { // Input var okay. |
|
57 | + $query = sanitize_text_field( wp_unslash( $_REQUEST['query'] ) ); // Input var okay. |
|
58 | + } else { |
|
59 | + wp_send_json_error( |
|
60 | + array( |
|
61 | + 'message' => __( 'The query param is empty.', 'wordlift' ), |
|
62 | + ) |
|
63 | + ); |
|
64 | + } |
|
65 | + |
|
66 | + // Get the exclude parameter. |
|
67 | + $exclude = ! empty( $_REQUEST['exclude'] ) |
|
68 | + ? sanitize_text_field( wp_unslash( $_REQUEST['exclude'] ) ) : ''; |
|
69 | + |
|
70 | + $scope = ! empty( $_REQUEST['scope'] ) |
|
71 | + ? sanitize_text_field( wp_unslash( $_REQUEST['scope'] ) ) : WL_AUTOCOMPLETE_SCOPE; |
|
72 | + |
|
73 | + /** |
|
74 | + * @since 3.26.1 |
|
75 | + * Providing a way for term pages to show and save local entities. |
|
76 | + */ |
|
77 | + $show_local_entities = false; |
|
78 | + |
|
79 | + if ( isset( $_REQUEST['show_local_entities'] ) |
|
80 | + && ! empty( $_REQUEST['show_local_entities'] ) ) { // Make request. |
|
81 | + $show_local_entities = filter_var( wp_unslash( $_REQUEST['show_local_entities'] ), FILTER_VALIDATE_BOOLEAN ); |
|
82 | + } |
|
83 | + |
|
84 | + // Add the filter to check if we need to show local entities or not. |
|
85 | + add_filter( |
|
86 | + 'wl_show_local_entities', |
|
87 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
88 | + function ( $state ) use ( $show_local_entities ) { |
|
89 | + return $show_local_entities; |
|
90 | + } |
|
91 | + ); |
|
92 | + |
|
93 | + $results = $this->autocomplete_service->query( $query, $scope, $exclude ); |
|
94 | + |
|
95 | + // Clear any buffer. |
|
96 | + ob_clean(); |
|
97 | + |
|
98 | + wp_send_json_success( $results ); |
|
99 | + |
|
100 | + } |
|
101 | 101 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | use Wordlift\Autocomplete\Autocomplete_Service; |
14 | 14 | |
15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
15 | +if ( ! defined('ABSPATH')) { |
|
16 | 16 | exit; |
17 | 17 | } |
18 | 18 | |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * |
40 | 40 | * @since 3.14.2 |
41 | 41 | */ |
42 | - public function __construct( $autocomplete_service ) { |
|
42 | + public function __construct($autocomplete_service) { |
|
43 | 43 | $this->autocomplete_service = $autocomplete_service; |
44 | 44 | } |
45 | 45 | |
@@ -50,25 +50,25 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function wl_autocomplete() { |
52 | 52 | |
53 | - check_ajax_referer( 'wl_autocomplete' ); |
|
53 | + check_ajax_referer('wl_autocomplete'); |
|
54 | 54 | |
55 | 55 | // Return error if the query param is empty. |
56 | - if ( ! empty( $_REQUEST['query'] ) ) { // Input var okay. |
|
57 | - $query = sanitize_text_field( wp_unslash( $_REQUEST['query'] ) ); // Input var okay. |
|
56 | + if ( ! empty($_REQUEST['query'])) { // Input var okay. |
|
57 | + $query = sanitize_text_field(wp_unslash($_REQUEST['query'])); // Input var okay. |
|
58 | 58 | } else { |
59 | 59 | wp_send_json_error( |
60 | 60 | array( |
61 | - 'message' => __( 'The query param is empty.', 'wordlift' ), |
|
61 | + 'message' => __('The query param is empty.', 'wordlift'), |
|
62 | 62 | ) |
63 | 63 | ); |
64 | 64 | } |
65 | 65 | |
66 | 66 | // Get the exclude parameter. |
67 | - $exclude = ! empty( $_REQUEST['exclude'] ) |
|
68 | - ? sanitize_text_field( wp_unslash( $_REQUEST['exclude'] ) ) : ''; |
|
67 | + $exclude = ! empty($_REQUEST['exclude']) |
|
68 | + ? sanitize_text_field(wp_unslash($_REQUEST['exclude'])) : ''; |
|
69 | 69 | |
70 | - $scope = ! empty( $_REQUEST['scope'] ) |
|
71 | - ? sanitize_text_field( wp_unslash( $_REQUEST['scope'] ) ) : WL_AUTOCOMPLETE_SCOPE; |
|
70 | + $scope = ! empty($_REQUEST['scope']) |
|
71 | + ? sanitize_text_field(wp_unslash($_REQUEST['scope'])) : WL_AUTOCOMPLETE_SCOPE; |
|
72 | 72 | |
73 | 73 | /** |
74 | 74 | * @since 3.26.1 |
@@ -76,26 +76,26 @@ discard block |
||
76 | 76 | */ |
77 | 77 | $show_local_entities = false; |
78 | 78 | |
79 | - if ( isset( $_REQUEST['show_local_entities'] ) |
|
80 | - && ! empty( $_REQUEST['show_local_entities'] ) ) { // Make request. |
|
81 | - $show_local_entities = filter_var( wp_unslash( $_REQUEST['show_local_entities'] ), FILTER_VALIDATE_BOOLEAN ); |
|
79 | + if (isset($_REQUEST['show_local_entities']) |
|
80 | + && ! empty($_REQUEST['show_local_entities'])) { // Make request. |
|
81 | + $show_local_entities = filter_var(wp_unslash($_REQUEST['show_local_entities']), FILTER_VALIDATE_BOOLEAN); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | // Add the filter to check if we need to show local entities or not. |
85 | 85 | add_filter( |
86 | 86 | 'wl_show_local_entities', |
87 | 87 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
88 | - function ( $state ) use ( $show_local_entities ) { |
|
88 | + function($state) use ($show_local_entities) { |
|
89 | 89 | return $show_local_entities; |
90 | 90 | } |
91 | 91 | ); |
92 | 92 | |
93 | - $results = $this->autocomplete_service->query( $query, $scope, $exclude ); |
|
93 | + $results = $this->autocomplete_service->query($query, $scope, $exclude); |
|
94 | 94 | |
95 | 95 | // Clear any buffer. |
96 | 96 | ob_clean(); |
97 | 97 | |
98 | - wp_send_json_success( $results ); |
|
98 | + wp_send_json_success($results); |
|
99 | 99 | |
100 | 100 | } |
101 | 101 | } |
@@ -13,87 +13,87 @@ |
||
13 | 13 | */ |
14 | 14 | class Wordlift_Schema_Location_Property_Service extends Wordlift_Property_Service { |
15 | 15 | |
16 | - /** |
|
17 | - * The meta key used to store data for this property. We don't use wl_url to |
|
18 | - * avoid potential confusion about other URLs. |
|
19 | - * |
|
20 | - * @since 3.7.0 |
|
21 | - */ |
|
22 | - const META_KEY = 'wl_location'; |
|
23 | - |
|
24 | - /** |
|
25 | - * {@inheritdoc} |
|
26 | - */ |
|
27 | - public function get_rdf_predicate() { |
|
28 | - |
|
29 | - return 'http://schema.org/location'; |
|
30 | - } |
|
31 | - |
|
32 | - /** |
|
33 | - * {@inheritdoc} |
|
34 | - */ |
|
35 | - public function get_rdf_data_type() { |
|
36 | - |
|
37 | - return 'xsd:anyURI'; |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * {@inheritdoc} |
|
42 | - */ |
|
43 | - public function get_data_type() { |
|
44 | - |
|
45 | - return Wordlift_Schema_Service::DATA_TYPE_URI; |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * {@inheritdoc} |
|
50 | - */ |
|
51 | - public function get_cardinality() { |
|
52 | - |
|
53 | - return INF; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * {@inheritdoc} |
|
58 | - */ |
|
59 | - public function get_metabox_class() { |
|
60 | - |
|
61 | - return 'Wl_Metabox_Field'; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * {@inheritdoc} |
|
66 | - */ |
|
67 | - public function get_metabox_label() { |
|
68 | - |
|
69 | - return 'Location(s)'; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Get the schema:url value for the specified post/entity. |
|
74 | - * |
|
75 | - * @param int $post_id The post id. |
|
76 | - * |
|
77 | - * @return array|NULL The schema:url value or NULL if not set. |
|
78 | - * @since 3.7.0 |
|
79 | - */ |
|
80 | - public function get( $post_id ) { |
|
81 | - |
|
82 | - // Get the schema:url values set in WP. |
|
83 | - $values = get_post_meta( $post_id, self::META_KEY, false ); |
|
84 | - |
|
85 | - // Finally return whatever values the editor set. |
|
86 | - return $values; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * {@inheritdoc} |
|
91 | - */ |
|
92 | - public function sanitize( $value ) { |
|
93 | - |
|
94 | - // TODO: check that it's an URL or that is <permalink> |
|
95 | - |
|
96 | - return $value; |
|
97 | - } |
|
16 | + /** |
|
17 | + * The meta key used to store data for this property. We don't use wl_url to |
|
18 | + * avoid potential confusion about other URLs. |
|
19 | + * |
|
20 | + * @since 3.7.0 |
|
21 | + */ |
|
22 | + const META_KEY = 'wl_location'; |
|
23 | + |
|
24 | + /** |
|
25 | + * {@inheritdoc} |
|
26 | + */ |
|
27 | + public function get_rdf_predicate() { |
|
28 | + |
|
29 | + return 'http://schema.org/location'; |
|
30 | + } |
|
31 | + |
|
32 | + /** |
|
33 | + * {@inheritdoc} |
|
34 | + */ |
|
35 | + public function get_rdf_data_type() { |
|
36 | + |
|
37 | + return 'xsd:anyURI'; |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * {@inheritdoc} |
|
42 | + */ |
|
43 | + public function get_data_type() { |
|
44 | + |
|
45 | + return Wordlift_Schema_Service::DATA_TYPE_URI; |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * {@inheritdoc} |
|
50 | + */ |
|
51 | + public function get_cardinality() { |
|
52 | + |
|
53 | + return INF; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * {@inheritdoc} |
|
58 | + */ |
|
59 | + public function get_metabox_class() { |
|
60 | + |
|
61 | + return 'Wl_Metabox_Field'; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * {@inheritdoc} |
|
66 | + */ |
|
67 | + public function get_metabox_label() { |
|
68 | + |
|
69 | + return 'Location(s)'; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Get the schema:url value for the specified post/entity. |
|
74 | + * |
|
75 | + * @param int $post_id The post id. |
|
76 | + * |
|
77 | + * @return array|NULL The schema:url value or NULL if not set. |
|
78 | + * @since 3.7.0 |
|
79 | + */ |
|
80 | + public function get( $post_id ) { |
|
81 | + |
|
82 | + // Get the schema:url values set in WP. |
|
83 | + $values = get_post_meta( $post_id, self::META_KEY, false ); |
|
84 | + |
|
85 | + // Finally return whatever values the editor set. |
|
86 | + return $values; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * {@inheritdoc} |
|
91 | + */ |
|
92 | + public function sanitize( $value ) { |
|
93 | + |
|
94 | + // TODO: check that it's an URL or that is <permalink> |
|
95 | + |
|
96 | + return $value; |
|
97 | + } |
|
98 | 98 | |
99 | 99 | } |
@@ -77,10 +77,10 @@ discard block |
||
77 | 77 | * @return array|NULL The schema:url value or NULL if not set. |
78 | 78 | * @since 3.7.0 |
79 | 79 | */ |
80 | - public function get( $post_id ) { |
|
80 | + public function get($post_id) { |
|
81 | 81 | |
82 | 82 | // Get the schema:url values set in WP. |
83 | - $values = get_post_meta( $post_id, self::META_KEY, false ); |
|
83 | + $values = get_post_meta($post_id, self::META_KEY, false); |
|
84 | 84 | |
85 | 85 | // Finally return whatever values the editor set. |
86 | 86 | return $values; |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | /** |
90 | 90 | * {@inheritdoc} |
91 | 91 | */ |
92 | - public function sanitize( $value ) { |
|
92 | + public function sanitize($value) { |
|
93 | 93 | |
94 | 94 | // TODO: check that it's an URL or that is <permalink> |
95 | 95 |
@@ -17,52 +17,52 @@ |
||
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 | - public 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 | + public 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 | - public 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 | + public 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 | - public 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 | + public function set_cache( $id, $contents ); |
|
51 | 51 | |
52 | - /** |
|
53 | - * Delete the cache for the specified `id`. |
|
54 | - * |
|
55 | - * @since 3.16.0 |
|
56 | - * |
|
57 | - * @param string $id The cache `id`. |
|
58 | - */ |
|
59 | - public function delete_cache( $id ); |
|
52 | + /** |
|
53 | + * Delete the cache for the specified `id`. |
|
54 | + * |
|
55 | + * @since 3.16.0 |
|
56 | + * |
|
57 | + * @param string $id The cache `id`. |
|
58 | + */ |
|
59 | + public function delete_cache( $id ); |
|
60 | 60 | |
61 | - /** |
|
62 | - * Flush the whole cache. |
|
63 | - * |
|
64 | - * @since 3.16.0 |
|
65 | - */ |
|
66 | - public function flush(); |
|
61 | + /** |
|
62 | + * Flush the whole cache. |
|
63 | + * |
|
64 | + * @since 3.16.0 |
|
65 | + */ |
|
66 | + public function flush(); |
|
67 | 67 | |
68 | 68 | } |
@@ -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 | - public function get_cache( $id ); |
|
29 | + public 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 | - public function has_cache( $id ); |
|
40 | + public 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 | - public function set_cache( $id, $contents ); |
|
50 | + public function set_cache($id, $contents); |
|
51 | 51 | |
52 | 52 | /** |
53 | 53 | * Delete the cache for the specified `id`. |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * |
57 | 57 | * @param string $id The cache `id`. |
58 | 58 | */ |
59 | - public function delete_cache( $id ); |
|
59 | + public function delete_cache($id); |
|
60 | 60 | |
61 | 61 | /** |
62 | 62 | * Flush the whole cache. |
@@ -8,7 +8,7 @@ |
||
8 | 8 | * @package Wordlift |
9 | 9 | * @subpackage Wordlift/includes/cache |
10 | 10 | */ |
11 | -require_once plugin_dir_path( dirname( __DIR__ ) ) . 'includes/cache/intf-wordlift-cache-service.php'; |
|
12 | -require_once plugin_dir_path( dirname( __DIR__ ) ) . 'includes/cache/class-wordlift-file-cache-service.php'; |
|
13 | -require_once plugin_dir_path( dirname( __DIR__ ) ) . 'includes/cache/class-wordlift-cached-post-converter.php'; |
|
14 | -require_once plugin_dir_path( dirname( __DIR__ ) ) . 'includes/cache/class-wordlift-cached-entity-uri-service.php'; |
|
11 | +require_once plugin_dir_path(dirname(__DIR__)).'includes/cache/intf-wordlift-cache-service.php'; |
|
12 | +require_once plugin_dir_path(dirname(__DIR__)).'includes/cache/class-wordlift-file-cache-service.php'; |
|
13 | +require_once plugin_dir_path(dirname(__DIR__)).'includes/cache/class-wordlift-cached-post-converter.php'; |
|
14 | +require_once plugin_dir_path(dirname(__DIR__)).'includes/cache/class-wordlift-cached-entity-uri-service.php'; |
@@ -14,203 +14,203 @@ |
||
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 | - * @param \Wordlift_Cache_Service $cache_service |
|
39 | - * |
|
40 | - * @since 3.16.3 |
|
41 | - */ |
|
42 | - public function __construct( $cache_service ) { |
|
43 | - parent::__construct(); |
|
44 | - |
|
45 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
46 | - |
|
47 | - // Add hooks for meta being added/modified/deleted. |
|
48 | - $this->cache_service = $cache_service; |
|
49 | - |
|
50 | - add_action( 'add_post_meta', array( $this, 'on_before_post_meta_add' ), 10, 3 ); |
|
51 | - add_action( 'update_post_meta', array( $this, 'on_before_post_meta_change' ), 10, 4 ); |
|
52 | - add_action( 'delete_post_meta', array( $this, 'on_before_post_meta_change' ), 10, 4 ); |
|
53 | - |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Preload the URIs. |
|
58 | - * |
|
59 | - * @param array $uris Preload an array of URIs. |
|
60 | - * |
|
61 | - * @since 3.16.3 |
|
62 | - */ |
|
63 | - public function preload_uris( $uris ) { |
|
64 | - |
|
65 | - // Filter the URIs which aren't yet cached. |
|
66 | - $cache_service = $this->cache_service; |
|
67 | - $uris_to_cache = array_filter( |
|
68 | - (array) $uris, |
|
69 | - function ( $item ) use ( $cache_service ) { |
|
70 | - return ! $cache_service->has_cache( $item ); |
|
71 | - } |
|
72 | - ); |
|
73 | - |
|
74 | - // Preload the URIs. |
|
75 | - parent::preload_uris( $uris_to_cache ); |
|
76 | - |
|
77 | - // Store them in cache. |
|
78 | - if ( is_array( $this->uri_to_post ) && ! empty( $this->uri_to_post ) ) { |
|
79 | - foreach ( $this->uri_to_post as $uri => $post_id ) { |
|
80 | - $this->set_cache( $uri, $post_id ); |
|
81 | - } |
|
82 | - } |
|
83 | - |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Get the entity post for the specified URI. |
|
88 | - * |
|
89 | - * @param string $uri The URI. |
|
90 | - * |
|
91 | - * @return null|WP_Post The {@link WP_Post} or null if not found. |
|
92 | - * @since 3.16.3 |
|
93 | - */ |
|
94 | - public function get_entity( $uri ) { |
|
95 | - |
|
96 | - $this->log->trace( "Getting entity for uri $uri..." ); |
|
97 | - |
|
98 | - // Get the cached post for the specified URI. |
|
99 | - $cache = $this->cache_service->get_cache( $uri ); |
|
100 | - |
|
101 | - // Return the cached data if valid. |
|
102 | - if ( false !== $cache && is_numeric( $cache ) ) { |
|
103 | - $this->log->debug( "Cached entity $cache for uri $uri found." ); |
|
104 | - |
|
105 | - return get_post( $cache ); |
|
106 | - } |
|
107 | - |
|
108 | - // Get the actual result. |
|
109 | - $post = parent::get_entity( $uri ); |
|
110 | - |
|
111 | - // Cache the result. |
|
112 | - if ( null !== $post ) { |
|
113 | - $this->set_cache( $uri, $post->ID ); |
|
114 | - } |
|
115 | - |
|
116 | - // Return the result. |
|
117 | - return $post; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Set the cached URI for the specified {@link WP_Post}. |
|
122 | - * |
|
123 | - * @param string $uri The URI. |
|
124 | - * @param int $post_id The post ID. |
|
125 | - * |
|
126 | - * @since 3.16.3 |
|
127 | - * @since 3.29.0 takes a post ID as input. |
|
128 | - */ |
|
129 | - private function set_cache( $uri, $post_id ) { |
|
130 | - |
|
131 | - // Cache the result. |
|
132 | - $this->cache_service->set_cache( $uri, $post_id ); |
|
133 | - |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Delete the cache for the specified URIs. |
|
138 | - * |
|
139 | - * @param array $uris An array of URIs. |
|
140 | - * |
|
141 | - * @since 3.16.3 |
|
142 | - */ |
|
143 | - private function delete_cache( $uris ) { |
|
144 | - |
|
145 | - // Delete the cache for each URI. |
|
146 | - foreach ( $uris as $uri ) { |
|
147 | - // Delete the single cache file. |
|
148 | - $this->cache_service->delete_cache( $uri ); |
|
149 | - } |
|
150 | - |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Before post meta change. |
|
155 | - * |
|
156 | - * When a post meta is going to be changed, we check if the `meta_key` is |
|
157 | - * either the `entity_url` or the `same_as` in which case we delete the cache |
|
158 | - * for all the associated URIs. |
|
159 | - * |
|
160 | - * @param int|array $meta_ids The {@link WP_Post} meta id(s). |
|
161 | - * @param int $post_id The {@link WP_Post} id. |
|
162 | - * @param string $meta_key The meta key. |
|
163 | - * @param mixed $meta_value The meta value(s). |
|
164 | - * |
|
165 | - * @since 3.16.3 |
|
166 | - */ |
|
167 | - public function on_before_post_meta_change( $meta_ids, $post_id, $meta_key, $meta_value ) { |
|
168 | - |
|
169 | - // Bail out if we're not interested in the meta key. |
|
170 | - if ( WL_ENTITY_URL_META_NAME !== $meta_key && Wordlift_Schema_Service::FIELD_SAME_AS !== $meta_key ) { |
|
171 | - return; |
|
172 | - } |
|
173 | - |
|
174 | - $this->log->trace( "Updating/deleting $meta_key for post $post_id ($meta_key), invalidating cache..." ); |
|
175 | - |
|
176 | - // The list of existing URIs, plus the list of URIs being deleted/updated. |
|
177 | - $old_value = get_post_meta( $post_id, $meta_key ); |
|
178 | - |
|
179 | - // We expect an array here from the `get_post_meta` signature. However `get_post_meta` is prone to side effects |
|
180 | - // because of filters. So if it's not we return an empty array. |
|
181 | - if ( ! is_array( $old_value ) ) { |
|
182 | - $old_value = array(); |
|
183 | - } |
|
184 | - $new_value = isset( $meta_value ) ? (array) $meta_value : array(); |
|
185 | - $uris = array_merge( $old_value, $new_value ); |
|
186 | - |
|
187 | - // Delete the cache for those URIs. |
|
188 | - $this->delete_cache( $uris ); |
|
189 | - |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * Hook to meta add for a {@link WP_Post}, will cause the cache to |
|
194 | - * invalidate. |
|
195 | - * |
|
196 | - * @param int $post_id The {@link WP_Post} id. |
|
197 | - * @param string $meta_key The meta key. |
|
198 | - * @param mixed $meta_value The meta value(s). |
|
199 | - * |
|
200 | - * @since 3.16.3 |
|
201 | - */ |
|
202 | - public function on_before_post_meta_add( $post_id, $meta_key, $meta_value ) { |
|
203 | - |
|
204 | - // Bail out if we're not interested in the meta key. |
|
205 | - if ( WL_ENTITY_URL_META_NAME !== $meta_key && Wordlift_Schema_Service::FIELD_SAME_AS !== $meta_key ) { |
|
206 | - return; |
|
207 | - } |
|
208 | - |
|
209 | - $this->log->trace( "Adding $meta_key for post $post_id ($meta_key), invalidating cache..." ); |
|
210 | - |
|
211 | - // Delete the cache for the URIs being added. |
|
212 | - $this->delete_cache( (array) $meta_value ); |
|
213 | - |
|
214 | - } |
|
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 | + * @param \Wordlift_Cache_Service $cache_service |
|
39 | + * |
|
40 | + * @since 3.16.3 |
|
41 | + */ |
|
42 | + public function __construct( $cache_service ) { |
|
43 | + parent::__construct(); |
|
44 | + |
|
45 | + $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
46 | + |
|
47 | + // Add hooks for meta being added/modified/deleted. |
|
48 | + $this->cache_service = $cache_service; |
|
49 | + |
|
50 | + add_action( 'add_post_meta', array( $this, 'on_before_post_meta_add' ), 10, 3 ); |
|
51 | + add_action( 'update_post_meta', array( $this, 'on_before_post_meta_change' ), 10, 4 ); |
|
52 | + add_action( 'delete_post_meta', array( $this, 'on_before_post_meta_change' ), 10, 4 ); |
|
53 | + |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Preload the URIs. |
|
58 | + * |
|
59 | + * @param array $uris Preload an array of URIs. |
|
60 | + * |
|
61 | + * @since 3.16.3 |
|
62 | + */ |
|
63 | + public function preload_uris( $uris ) { |
|
64 | + |
|
65 | + // Filter the URIs which aren't yet cached. |
|
66 | + $cache_service = $this->cache_service; |
|
67 | + $uris_to_cache = array_filter( |
|
68 | + (array) $uris, |
|
69 | + function ( $item ) use ( $cache_service ) { |
|
70 | + return ! $cache_service->has_cache( $item ); |
|
71 | + } |
|
72 | + ); |
|
73 | + |
|
74 | + // Preload the URIs. |
|
75 | + parent::preload_uris( $uris_to_cache ); |
|
76 | + |
|
77 | + // Store them in cache. |
|
78 | + if ( is_array( $this->uri_to_post ) && ! empty( $this->uri_to_post ) ) { |
|
79 | + foreach ( $this->uri_to_post as $uri => $post_id ) { |
|
80 | + $this->set_cache( $uri, $post_id ); |
|
81 | + } |
|
82 | + } |
|
83 | + |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Get the entity post for the specified URI. |
|
88 | + * |
|
89 | + * @param string $uri The URI. |
|
90 | + * |
|
91 | + * @return null|WP_Post The {@link WP_Post} or null if not found. |
|
92 | + * @since 3.16.3 |
|
93 | + */ |
|
94 | + public function get_entity( $uri ) { |
|
95 | + |
|
96 | + $this->log->trace( "Getting entity for uri $uri..." ); |
|
97 | + |
|
98 | + // Get the cached post for the specified URI. |
|
99 | + $cache = $this->cache_service->get_cache( $uri ); |
|
100 | + |
|
101 | + // Return the cached data if valid. |
|
102 | + if ( false !== $cache && is_numeric( $cache ) ) { |
|
103 | + $this->log->debug( "Cached entity $cache for uri $uri found." ); |
|
104 | + |
|
105 | + return get_post( $cache ); |
|
106 | + } |
|
107 | + |
|
108 | + // Get the actual result. |
|
109 | + $post = parent::get_entity( $uri ); |
|
110 | + |
|
111 | + // Cache the result. |
|
112 | + if ( null !== $post ) { |
|
113 | + $this->set_cache( $uri, $post->ID ); |
|
114 | + } |
|
115 | + |
|
116 | + // Return the result. |
|
117 | + return $post; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Set the cached URI for the specified {@link WP_Post}. |
|
122 | + * |
|
123 | + * @param string $uri The URI. |
|
124 | + * @param int $post_id The post ID. |
|
125 | + * |
|
126 | + * @since 3.16.3 |
|
127 | + * @since 3.29.0 takes a post ID as input. |
|
128 | + */ |
|
129 | + private function set_cache( $uri, $post_id ) { |
|
130 | + |
|
131 | + // Cache the result. |
|
132 | + $this->cache_service->set_cache( $uri, $post_id ); |
|
133 | + |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Delete the cache for the specified URIs. |
|
138 | + * |
|
139 | + * @param array $uris An array of URIs. |
|
140 | + * |
|
141 | + * @since 3.16.3 |
|
142 | + */ |
|
143 | + private function delete_cache( $uris ) { |
|
144 | + |
|
145 | + // Delete the cache for each URI. |
|
146 | + foreach ( $uris as $uri ) { |
|
147 | + // Delete the single cache file. |
|
148 | + $this->cache_service->delete_cache( $uri ); |
|
149 | + } |
|
150 | + |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Before post meta change. |
|
155 | + * |
|
156 | + * When a post meta is going to be changed, we check if the `meta_key` is |
|
157 | + * either the `entity_url` or the `same_as` in which case we delete the cache |
|
158 | + * for all the associated URIs. |
|
159 | + * |
|
160 | + * @param int|array $meta_ids The {@link WP_Post} meta id(s). |
|
161 | + * @param int $post_id The {@link WP_Post} id. |
|
162 | + * @param string $meta_key The meta key. |
|
163 | + * @param mixed $meta_value The meta value(s). |
|
164 | + * |
|
165 | + * @since 3.16.3 |
|
166 | + */ |
|
167 | + public function on_before_post_meta_change( $meta_ids, $post_id, $meta_key, $meta_value ) { |
|
168 | + |
|
169 | + // Bail out if we're not interested in the meta key. |
|
170 | + if ( WL_ENTITY_URL_META_NAME !== $meta_key && Wordlift_Schema_Service::FIELD_SAME_AS !== $meta_key ) { |
|
171 | + return; |
|
172 | + } |
|
173 | + |
|
174 | + $this->log->trace( "Updating/deleting $meta_key for post $post_id ($meta_key), invalidating cache..." ); |
|
175 | + |
|
176 | + // The list of existing URIs, plus the list of URIs being deleted/updated. |
|
177 | + $old_value = get_post_meta( $post_id, $meta_key ); |
|
178 | + |
|
179 | + // We expect an array here from the `get_post_meta` signature. However `get_post_meta` is prone to side effects |
|
180 | + // because of filters. So if it's not we return an empty array. |
|
181 | + if ( ! is_array( $old_value ) ) { |
|
182 | + $old_value = array(); |
|
183 | + } |
|
184 | + $new_value = isset( $meta_value ) ? (array) $meta_value : array(); |
|
185 | + $uris = array_merge( $old_value, $new_value ); |
|
186 | + |
|
187 | + // Delete the cache for those URIs. |
|
188 | + $this->delete_cache( $uris ); |
|
189 | + |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * Hook to meta add for a {@link WP_Post}, will cause the cache to |
|
194 | + * invalidate. |
|
195 | + * |
|
196 | + * @param int $post_id The {@link WP_Post} id. |
|
197 | + * @param string $meta_key The meta key. |
|
198 | + * @param mixed $meta_value The meta value(s). |
|
199 | + * |
|
200 | + * @since 3.16.3 |
|
201 | + */ |
|
202 | + public function on_before_post_meta_add( $post_id, $meta_key, $meta_value ) { |
|
203 | + |
|
204 | + // Bail out if we're not interested in the meta key. |
|
205 | + if ( WL_ENTITY_URL_META_NAME !== $meta_key && Wordlift_Schema_Service::FIELD_SAME_AS !== $meta_key ) { |
|
206 | + return; |
|
207 | + } |
|
208 | + |
|
209 | + $this->log->trace( "Adding $meta_key for post $post_id ($meta_key), invalidating cache..." ); |
|
210 | + |
|
211 | + // Delete the cache for the URIs being added. |
|
212 | + $this->delete_cache( (array) $meta_value ); |
|
213 | + |
|
214 | + } |
|
215 | 215 | |
216 | 216 | } |
@@ -39,17 +39,17 @@ discard block |
||
39 | 39 | * |
40 | 40 | * @since 3.16.3 |
41 | 41 | */ |
42 | - public function __construct( $cache_service ) { |
|
42 | + public function __construct($cache_service) { |
|
43 | 43 | parent::__construct(); |
44 | 44 | |
45 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
45 | + $this->log = Wordlift_Log_Service::get_logger(get_class()); |
|
46 | 46 | |
47 | 47 | // Add hooks for meta being added/modified/deleted. |
48 | 48 | $this->cache_service = $cache_service; |
49 | 49 | |
50 | - add_action( 'add_post_meta', array( $this, 'on_before_post_meta_add' ), 10, 3 ); |
|
51 | - add_action( 'update_post_meta', array( $this, 'on_before_post_meta_change' ), 10, 4 ); |
|
52 | - add_action( 'delete_post_meta', array( $this, 'on_before_post_meta_change' ), 10, 4 ); |
|
50 | + add_action('add_post_meta', array($this, 'on_before_post_meta_add'), 10, 3); |
|
51 | + add_action('update_post_meta', array($this, 'on_before_post_meta_change'), 10, 4); |
|
52 | + add_action('delete_post_meta', array($this, 'on_before_post_meta_change'), 10, 4); |
|
53 | 53 | |
54 | 54 | } |
55 | 55 | |
@@ -60,24 +60,24 @@ discard block |
||
60 | 60 | * |
61 | 61 | * @since 3.16.3 |
62 | 62 | */ |
63 | - public function preload_uris( $uris ) { |
|
63 | + public function preload_uris($uris) { |
|
64 | 64 | |
65 | 65 | // Filter the URIs which aren't yet cached. |
66 | 66 | $cache_service = $this->cache_service; |
67 | 67 | $uris_to_cache = array_filter( |
68 | 68 | (array) $uris, |
69 | - function ( $item ) use ( $cache_service ) { |
|
70 | - return ! $cache_service->has_cache( $item ); |
|
69 | + function($item) use ($cache_service) { |
|
70 | + return ! $cache_service->has_cache($item); |
|
71 | 71 | } |
72 | 72 | ); |
73 | 73 | |
74 | 74 | // Preload the URIs. |
75 | - parent::preload_uris( $uris_to_cache ); |
|
75 | + parent::preload_uris($uris_to_cache); |
|
76 | 76 | |
77 | 77 | // Store them in cache. |
78 | - if ( is_array( $this->uri_to_post ) && ! empty( $this->uri_to_post ) ) { |
|
79 | - foreach ( $this->uri_to_post as $uri => $post_id ) { |
|
80 | - $this->set_cache( $uri, $post_id ); |
|
78 | + if (is_array($this->uri_to_post) && ! empty($this->uri_to_post)) { |
|
79 | + foreach ($this->uri_to_post as $uri => $post_id) { |
|
80 | + $this->set_cache($uri, $post_id); |
|
81 | 81 | } |
82 | 82 | } |
83 | 83 | |
@@ -91,26 +91,26 @@ discard block |
||
91 | 91 | * @return null|WP_Post The {@link WP_Post} or null if not found. |
92 | 92 | * @since 3.16.3 |
93 | 93 | */ |
94 | - public function get_entity( $uri ) { |
|
94 | + public function get_entity($uri) { |
|
95 | 95 | |
96 | - $this->log->trace( "Getting entity for uri $uri..." ); |
|
96 | + $this->log->trace("Getting entity for uri $uri..."); |
|
97 | 97 | |
98 | 98 | // Get the cached post for the specified URI. |
99 | - $cache = $this->cache_service->get_cache( $uri ); |
|
99 | + $cache = $this->cache_service->get_cache($uri); |
|
100 | 100 | |
101 | 101 | // Return the cached data if valid. |
102 | - if ( false !== $cache && is_numeric( $cache ) ) { |
|
103 | - $this->log->debug( "Cached entity $cache for uri $uri found." ); |
|
102 | + if (false !== $cache && is_numeric($cache)) { |
|
103 | + $this->log->debug("Cached entity $cache for uri $uri found."); |
|
104 | 104 | |
105 | - return get_post( $cache ); |
|
105 | + return get_post($cache); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | // Get the actual result. |
109 | - $post = parent::get_entity( $uri ); |
|
109 | + $post = parent::get_entity($uri); |
|
110 | 110 | |
111 | 111 | // Cache the result. |
112 | - if ( null !== $post ) { |
|
113 | - $this->set_cache( $uri, $post->ID ); |
|
112 | + if (null !== $post) { |
|
113 | + $this->set_cache($uri, $post->ID); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | // Return the result. |
@@ -126,10 +126,10 @@ discard block |
||
126 | 126 | * @since 3.16.3 |
127 | 127 | * @since 3.29.0 takes a post ID as input. |
128 | 128 | */ |
129 | - private function set_cache( $uri, $post_id ) { |
|
129 | + private function set_cache($uri, $post_id) { |
|
130 | 130 | |
131 | 131 | // Cache the result. |
132 | - $this->cache_service->set_cache( $uri, $post_id ); |
|
132 | + $this->cache_service->set_cache($uri, $post_id); |
|
133 | 133 | |
134 | 134 | } |
135 | 135 | |
@@ -140,12 +140,12 @@ discard block |
||
140 | 140 | * |
141 | 141 | * @since 3.16.3 |
142 | 142 | */ |
143 | - private function delete_cache( $uris ) { |
|
143 | + private function delete_cache($uris) { |
|
144 | 144 | |
145 | 145 | // Delete the cache for each URI. |
146 | - foreach ( $uris as $uri ) { |
|
146 | + foreach ($uris as $uri) { |
|
147 | 147 | // Delete the single cache file. |
148 | - $this->cache_service->delete_cache( $uri ); |
|
148 | + $this->cache_service->delete_cache($uri); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | } |
@@ -164,28 +164,28 @@ discard block |
||
164 | 164 | * |
165 | 165 | * @since 3.16.3 |
166 | 166 | */ |
167 | - public function on_before_post_meta_change( $meta_ids, $post_id, $meta_key, $meta_value ) { |
|
167 | + public function on_before_post_meta_change($meta_ids, $post_id, $meta_key, $meta_value) { |
|
168 | 168 | |
169 | 169 | // Bail out if we're not interested in the meta key. |
170 | - if ( WL_ENTITY_URL_META_NAME !== $meta_key && Wordlift_Schema_Service::FIELD_SAME_AS !== $meta_key ) { |
|
170 | + if (WL_ENTITY_URL_META_NAME !== $meta_key && Wordlift_Schema_Service::FIELD_SAME_AS !== $meta_key) { |
|
171 | 171 | return; |
172 | 172 | } |
173 | 173 | |
174 | - $this->log->trace( "Updating/deleting $meta_key for post $post_id ($meta_key), invalidating cache..." ); |
|
174 | + $this->log->trace("Updating/deleting $meta_key for post $post_id ($meta_key), invalidating cache..."); |
|
175 | 175 | |
176 | 176 | // The list of existing URIs, plus the list of URIs being deleted/updated. |
177 | - $old_value = get_post_meta( $post_id, $meta_key ); |
|
177 | + $old_value = get_post_meta($post_id, $meta_key); |
|
178 | 178 | |
179 | 179 | // We expect an array here from the `get_post_meta` signature. However `get_post_meta` is prone to side effects |
180 | 180 | // because of filters. So if it's not we return an empty array. |
181 | - if ( ! is_array( $old_value ) ) { |
|
181 | + if ( ! is_array($old_value)) { |
|
182 | 182 | $old_value = array(); |
183 | 183 | } |
184 | - $new_value = isset( $meta_value ) ? (array) $meta_value : array(); |
|
185 | - $uris = array_merge( $old_value, $new_value ); |
|
184 | + $new_value = isset($meta_value) ? (array) $meta_value : array(); |
|
185 | + $uris = array_merge($old_value, $new_value); |
|
186 | 186 | |
187 | 187 | // Delete the cache for those URIs. |
188 | - $this->delete_cache( $uris ); |
|
188 | + $this->delete_cache($uris); |
|
189 | 189 | |
190 | 190 | } |
191 | 191 | |
@@ -199,17 +199,17 @@ discard block |
||
199 | 199 | * |
200 | 200 | * @since 3.16.3 |
201 | 201 | */ |
202 | - public function on_before_post_meta_add( $post_id, $meta_key, $meta_value ) { |
|
202 | + public function on_before_post_meta_add($post_id, $meta_key, $meta_value) { |
|
203 | 203 | |
204 | 204 | // Bail out if we're not interested in the meta key. |
205 | - if ( WL_ENTITY_URL_META_NAME !== $meta_key && Wordlift_Schema_Service::FIELD_SAME_AS !== $meta_key ) { |
|
205 | + if (WL_ENTITY_URL_META_NAME !== $meta_key && Wordlift_Schema_Service::FIELD_SAME_AS !== $meta_key) { |
|
206 | 206 | return; |
207 | 207 | } |
208 | 208 | |
209 | - $this->log->trace( "Adding $meta_key for post $post_id ($meta_key), invalidating cache..." ); |
|
209 | + $this->log->trace("Adding $meta_key for post $post_id ($meta_key), invalidating cache..."); |
|
210 | 210 | |
211 | 211 | // Delete the cache for the URIs being added. |
212 | - $this->delete_cache( (array) $meta_value ); |
|
212 | + $this->delete_cache((array) $meta_value); |
|
213 | 213 | |
214 | 214 | } |
215 | 215 |
@@ -16,185 +16,185 @@ |
||
16 | 16 | */ |
17 | 17 | class Wordlift_Http_Api { |
18 | 18 | |
19 | - /** |
|
20 | - * A {@link Wordlift_Log_Service} instance. |
|
21 | - * |
|
22 | - * @since 3.15.3 |
|
23 | - * |
|
24 | - * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
25 | - */ |
|
26 | - private $log; |
|
27 | - |
|
28 | - /** |
|
29 | - * Create a {@link Wordlift_End_Point} instance. |
|
30 | - * |
|
31 | - * @since 3.15.3 |
|
32 | - */ |
|
33 | - public function __construct() { |
|
34 | - |
|
35 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
36 | - |
|
37 | - add_action( 'init', array( $this, 'add_rewrite_endpoint' ) ); |
|
38 | - add_action( 'template_redirect', array( $this, 'template_redirect' ) ); |
|
39 | - |
|
40 | - // region SAMPLE ACTIONS. |
|
41 | - add_action( |
|
42 | - 'admin_post_wl_hello_world', |
|
43 | - array( |
|
44 | - $this, |
|
45 | - 'hello_world', |
|
46 | - ) |
|
47 | - ); |
|
48 | - add_action( |
|
49 | - 'admin_post_nopriv_wl_hello_world', |
|
50 | - array( |
|
51 | - $this, |
|
52 | - 'nopriv_hello_world', |
|
53 | - ) |
|
54 | - ); |
|
55 | - // endregion |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Add the `wl-api` rewrite end-point. |
|
60 | - * |
|
61 | - * @since 3.15.3 |
|
62 | - */ |
|
63 | - public function add_rewrite_endpoint() { |
|
64 | - |
|
65 | - add_rewrite_endpoint( 'wl-api', EP_ROOT ); |
|
66 | - $this->ensure_rewrite_rules_are_flushed(); |
|
67 | - |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Handle `template_redirect` hooks. |
|
72 | - * |
|
73 | - * @since 3.15.3 |
|
74 | - */ |
|
75 | - public function template_redirect() { |
|
76 | - |
|
77 | - global $wp_query; |
|
78 | - |
|
79 | - if ( ! isset( $wp_query->query_vars['wl-api'] ) ) { |
|
80 | - $this->log->trace( 'Skipping, not a `wl-api` call.' ); |
|
81 | - |
|
82 | - return; |
|
83 | - } |
|
84 | - |
|
85 | - $action = isset( $_REQUEST['action'] ) ? sanitize_text_field( wp_unslash( (string) $_REQUEST['action'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
86 | - $this->do_action( $action ); |
|
87 | - |
|
88 | - exit; |
|
89 | - |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Do the requested action. |
|
94 | - * |
|
95 | - * @param string $action The action to execute. |
|
96 | - * |
|
97 | - * @since 3.15.3 |
|
98 | - */ |
|
99 | - private function do_action( $action ) { |
|
100 | - |
|
101 | - if ( empty( $action ) ) { |
|
102 | - return; |
|
103 | - } |
|
104 | - |
|
105 | - if ( ! wp_validate_auth_cookie( '', 'logged_in' ) ) { |
|
106 | - /** |
|
107 | - * Fires on a non-authenticated admin post request for the given action. |
|
108 | - * |
|
109 | - * The dynamic portion of the hook name, `$action`, refers to the given |
|
110 | - * request action. |
|
111 | - * |
|
112 | - * @since 2.6.0 |
|
113 | - */ |
|
114 | - do_action( "admin_post_nopriv_{$action}" ); |
|
115 | - } else { |
|
116 | - /** |
|
117 | - * Fires on an authenticated admin post request for the given action. |
|
118 | - * |
|
119 | - * The dynamic portion of the hook name, `$action`, refers to the given |
|
120 | - * request action. |
|
121 | - * |
|
122 | - * @since 2.6.0 |
|
123 | - */ |
|
124 | - do_action( "admin_post_{$action}" ); |
|
125 | - } |
|
126 | - |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Test function, anonymous. |
|
131 | - * |
|
132 | - * @since 3.15.3 |
|
133 | - */ |
|
134 | - public function nopriv_hello_world() { |
|
135 | - |
|
136 | - wp_die( 'Hello World! (from anonymous)' ); |
|
137 | - |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Test function, authenticated. |
|
142 | - * |
|
143 | - * @since 3.15.3 |
|
144 | - */ |
|
145 | - public function hello_world() { |
|
146 | - |
|
147 | - wp_die( 'Hello World! (from authenticated)' ); |
|
148 | - |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Ensure that the rewrite rules are flushed the first time. |
|
153 | - * |
|
154 | - * @since 3.16.0 changed the value from 1 to `yes` to avoid type juggling issues. |
|
155 | - * @since 3.15.3 |
|
156 | - */ |
|
157 | - public static function ensure_rewrite_rules_are_flushed() { |
|
158 | - |
|
159 | - // See https://github.com/insideout10/wordlift-plugin/issues/698. |
|
160 | - if ( 'yes' !== get_option( 'wl_http_api' ) ) { |
|
161 | - update_option( 'wl_http_api', 'yes' ); |
|
162 | - add_action( |
|
163 | - 'wp_loaded', |
|
164 | - function () { |
|
165 | - flush_rewrite_rules(); |
|
166 | - } |
|
167 | - ); |
|
168 | - } |
|
169 | - |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * Called by {@see activate_wordlift}, resets the `wl_http_api` option flag in order to force WordLift to |
|
174 | - * reinitialize the `wl-api` route. |
|
175 | - * |
|
176 | - * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue. |
|
177 | - * |
|
178 | - * @since 3.19.2 |
|
179 | - */ |
|
180 | - public static function activate() { |
|
181 | - |
|
182 | - // Force the plugin to reinitialize the rewrite rules. |
|
183 | - update_option( 'wl_http_api', 'no' ); |
|
184 | - |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Delete the option when the plugin is deactivated. |
|
189 | - * |
|
190 | - * @since 3.19.4 |
|
191 | - * |
|
192 | - * @see https://github.com/insideout10/wordlift-plugin/issues/846 |
|
193 | - */ |
|
194 | - public static function deactivate() { |
|
195 | - |
|
196 | - delete_option( 'wl_http_api' ); |
|
197 | - |
|
198 | - } |
|
19 | + /** |
|
20 | + * A {@link Wordlift_Log_Service} instance. |
|
21 | + * |
|
22 | + * @since 3.15.3 |
|
23 | + * |
|
24 | + * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
25 | + */ |
|
26 | + private $log; |
|
27 | + |
|
28 | + /** |
|
29 | + * Create a {@link Wordlift_End_Point} instance. |
|
30 | + * |
|
31 | + * @since 3.15.3 |
|
32 | + */ |
|
33 | + public function __construct() { |
|
34 | + |
|
35 | + $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
36 | + |
|
37 | + add_action( 'init', array( $this, 'add_rewrite_endpoint' ) ); |
|
38 | + add_action( 'template_redirect', array( $this, 'template_redirect' ) ); |
|
39 | + |
|
40 | + // region SAMPLE ACTIONS. |
|
41 | + add_action( |
|
42 | + 'admin_post_wl_hello_world', |
|
43 | + array( |
|
44 | + $this, |
|
45 | + 'hello_world', |
|
46 | + ) |
|
47 | + ); |
|
48 | + add_action( |
|
49 | + 'admin_post_nopriv_wl_hello_world', |
|
50 | + array( |
|
51 | + $this, |
|
52 | + 'nopriv_hello_world', |
|
53 | + ) |
|
54 | + ); |
|
55 | + // endregion |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Add the `wl-api` rewrite end-point. |
|
60 | + * |
|
61 | + * @since 3.15.3 |
|
62 | + */ |
|
63 | + public function add_rewrite_endpoint() { |
|
64 | + |
|
65 | + add_rewrite_endpoint( 'wl-api', EP_ROOT ); |
|
66 | + $this->ensure_rewrite_rules_are_flushed(); |
|
67 | + |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Handle `template_redirect` hooks. |
|
72 | + * |
|
73 | + * @since 3.15.3 |
|
74 | + */ |
|
75 | + public function template_redirect() { |
|
76 | + |
|
77 | + global $wp_query; |
|
78 | + |
|
79 | + if ( ! isset( $wp_query->query_vars['wl-api'] ) ) { |
|
80 | + $this->log->trace( 'Skipping, not a `wl-api` call.' ); |
|
81 | + |
|
82 | + return; |
|
83 | + } |
|
84 | + |
|
85 | + $action = isset( $_REQUEST['action'] ) ? sanitize_text_field( wp_unslash( (string) $_REQUEST['action'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
86 | + $this->do_action( $action ); |
|
87 | + |
|
88 | + exit; |
|
89 | + |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Do the requested action. |
|
94 | + * |
|
95 | + * @param string $action The action to execute. |
|
96 | + * |
|
97 | + * @since 3.15.3 |
|
98 | + */ |
|
99 | + private function do_action( $action ) { |
|
100 | + |
|
101 | + if ( empty( $action ) ) { |
|
102 | + return; |
|
103 | + } |
|
104 | + |
|
105 | + if ( ! wp_validate_auth_cookie( '', 'logged_in' ) ) { |
|
106 | + /** |
|
107 | + * Fires on a non-authenticated admin post request for the given action. |
|
108 | + * |
|
109 | + * The dynamic portion of the hook name, `$action`, refers to the given |
|
110 | + * request action. |
|
111 | + * |
|
112 | + * @since 2.6.0 |
|
113 | + */ |
|
114 | + do_action( "admin_post_nopriv_{$action}" ); |
|
115 | + } else { |
|
116 | + /** |
|
117 | + * Fires on an authenticated admin post request for the given action. |
|
118 | + * |
|
119 | + * The dynamic portion of the hook name, `$action`, refers to the given |
|
120 | + * request action. |
|
121 | + * |
|
122 | + * @since 2.6.0 |
|
123 | + */ |
|
124 | + do_action( "admin_post_{$action}" ); |
|
125 | + } |
|
126 | + |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Test function, anonymous. |
|
131 | + * |
|
132 | + * @since 3.15.3 |
|
133 | + */ |
|
134 | + public function nopriv_hello_world() { |
|
135 | + |
|
136 | + wp_die( 'Hello World! (from anonymous)' ); |
|
137 | + |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Test function, authenticated. |
|
142 | + * |
|
143 | + * @since 3.15.3 |
|
144 | + */ |
|
145 | + public function hello_world() { |
|
146 | + |
|
147 | + wp_die( 'Hello World! (from authenticated)' ); |
|
148 | + |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Ensure that the rewrite rules are flushed the first time. |
|
153 | + * |
|
154 | + * @since 3.16.0 changed the value from 1 to `yes` to avoid type juggling issues. |
|
155 | + * @since 3.15.3 |
|
156 | + */ |
|
157 | + public static function ensure_rewrite_rules_are_flushed() { |
|
158 | + |
|
159 | + // See https://github.com/insideout10/wordlift-plugin/issues/698. |
|
160 | + if ( 'yes' !== get_option( 'wl_http_api' ) ) { |
|
161 | + update_option( 'wl_http_api', 'yes' ); |
|
162 | + add_action( |
|
163 | + 'wp_loaded', |
|
164 | + function () { |
|
165 | + flush_rewrite_rules(); |
|
166 | + } |
|
167 | + ); |
|
168 | + } |
|
169 | + |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * Called by {@see activate_wordlift}, resets the `wl_http_api` option flag in order to force WordLift to |
|
174 | + * reinitialize the `wl-api` route. |
|
175 | + * |
|
176 | + * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue. |
|
177 | + * |
|
178 | + * @since 3.19.2 |
|
179 | + */ |
|
180 | + public static function activate() { |
|
181 | + |
|
182 | + // Force the plugin to reinitialize the rewrite rules. |
|
183 | + update_option( 'wl_http_api', 'no' ); |
|
184 | + |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Delete the option when the plugin is deactivated. |
|
189 | + * |
|
190 | + * @since 3.19.4 |
|
191 | + * |
|
192 | + * @see https://github.com/insideout10/wordlift-plugin/issues/846 |
|
193 | + */ |
|
194 | + public static function deactivate() { |
|
195 | + |
|
196 | + delete_option( 'wl_http_api' ); |
|
197 | + |
|
198 | + } |
|
199 | 199 | |
200 | 200 | } |
@@ -32,10 +32,10 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function __construct() { |
34 | 34 | |
35 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
35 | + $this->log = Wordlift_Log_Service::get_logger(get_class()); |
|
36 | 36 | |
37 | - add_action( 'init', array( $this, 'add_rewrite_endpoint' ) ); |
|
38 | - add_action( 'template_redirect', array( $this, 'template_redirect' ) ); |
|
37 | + add_action('init', array($this, 'add_rewrite_endpoint')); |
|
38 | + add_action('template_redirect', array($this, 'template_redirect')); |
|
39 | 39 | |
40 | 40 | // region SAMPLE ACTIONS. |
41 | 41 | add_action( |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function add_rewrite_endpoint() { |
64 | 64 | |
65 | - add_rewrite_endpoint( 'wl-api', EP_ROOT ); |
|
65 | + add_rewrite_endpoint('wl-api', EP_ROOT); |
|
66 | 66 | $this->ensure_rewrite_rules_are_flushed(); |
67 | 67 | |
68 | 68 | } |
@@ -76,14 +76,14 @@ discard block |
||
76 | 76 | |
77 | 77 | global $wp_query; |
78 | 78 | |
79 | - if ( ! isset( $wp_query->query_vars['wl-api'] ) ) { |
|
80 | - $this->log->trace( 'Skipping, not a `wl-api` call.' ); |
|
79 | + if ( ! isset($wp_query->query_vars['wl-api'])) { |
|
80 | + $this->log->trace('Skipping, not a `wl-api` call.'); |
|
81 | 81 | |
82 | 82 | return; |
83 | 83 | } |
84 | 84 | |
85 | - $action = isset( $_REQUEST['action'] ) ? sanitize_text_field( wp_unslash( (string) $_REQUEST['action'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
86 | - $this->do_action( $action ); |
|
85 | + $action = isset($_REQUEST['action']) ? sanitize_text_field(wp_unslash((string) $_REQUEST['action'])) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
86 | + $this->do_action($action); |
|
87 | 87 | |
88 | 88 | exit; |
89 | 89 | |
@@ -96,13 +96,13 @@ discard block |
||
96 | 96 | * |
97 | 97 | * @since 3.15.3 |
98 | 98 | */ |
99 | - private function do_action( $action ) { |
|
99 | + private function do_action($action) { |
|
100 | 100 | |
101 | - if ( empty( $action ) ) { |
|
101 | + if (empty($action)) { |
|
102 | 102 | return; |
103 | 103 | } |
104 | 104 | |
105 | - if ( ! wp_validate_auth_cookie( '', 'logged_in' ) ) { |
|
105 | + if ( ! wp_validate_auth_cookie('', 'logged_in')) { |
|
106 | 106 | /** |
107 | 107 | * Fires on a non-authenticated admin post request for the given action. |
108 | 108 | * |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * |
112 | 112 | * @since 2.6.0 |
113 | 113 | */ |
114 | - do_action( "admin_post_nopriv_{$action}" ); |
|
114 | + do_action("admin_post_nopriv_{$action}"); |
|
115 | 115 | } else { |
116 | 116 | /** |
117 | 117 | * Fires on an authenticated admin post request for the given action. |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * |
122 | 122 | * @since 2.6.0 |
123 | 123 | */ |
124 | - do_action( "admin_post_{$action}" ); |
|
124 | + do_action("admin_post_{$action}"); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | } |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | */ |
134 | 134 | public function nopriv_hello_world() { |
135 | 135 | |
136 | - wp_die( 'Hello World! (from anonymous)' ); |
|
136 | + wp_die('Hello World! (from anonymous)'); |
|
137 | 137 | |
138 | 138 | } |
139 | 139 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | */ |
145 | 145 | public function hello_world() { |
146 | 146 | |
147 | - wp_die( 'Hello World! (from authenticated)' ); |
|
147 | + wp_die('Hello World! (from authenticated)'); |
|
148 | 148 | |
149 | 149 | } |
150 | 150 | |
@@ -157,11 +157,11 @@ discard block |
||
157 | 157 | public static function ensure_rewrite_rules_are_flushed() { |
158 | 158 | |
159 | 159 | // See https://github.com/insideout10/wordlift-plugin/issues/698. |
160 | - if ( 'yes' !== get_option( 'wl_http_api' ) ) { |
|
161 | - update_option( 'wl_http_api', 'yes' ); |
|
160 | + if ('yes' !== get_option('wl_http_api')) { |
|
161 | + update_option('wl_http_api', 'yes'); |
|
162 | 162 | add_action( |
163 | 163 | 'wp_loaded', |
164 | - function () { |
|
164 | + function() { |
|
165 | 165 | flush_rewrite_rules(); |
166 | 166 | } |
167 | 167 | ); |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | public static function activate() { |
181 | 181 | |
182 | 182 | // Force the plugin to reinitialize the rewrite rules. |
183 | - update_option( 'wl_http_api', 'no' ); |
|
183 | + update_option('wl_http_api', 'no'); |
|
184 | 184 | |
185 | 185 | } |
186 | 186 | |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | */ |
194 | 194 | public static function deactivate() { |
195 | 195 | |
196 | - delete_option( 'wl_http_api' ); |
|
196 | + delete_option('wl_http_api'); |
|
197 | 197 | |
198 | 198 | } |
199 | 199 |
@@ -8,80 +8,80 @@ |
||
8 | 8 | |
9 | 9 | class Wordlift_Mapping_Ajax_Adapter { |
10 | 10 | |
11 | - /** |
|
12 | - * The {@link Wordlift_Mapping_Service} instance. |
|
13 | - * |
|
14 | - * @since 3.20.0 |
|
15 | - * @access private |
|
16 | - * @var \Wordlift_Mapping_Service $mapping_service The {@link Wordlift_Mapping_Service} instance. |
|
17 | - */ |
|
18 | - private $mapping_service; |
|
11 | + /** |
|
12 | + * The {@link Wordlift_Mapping_Service} instance. |
|
13 | + * |
|
14 | + * @since 3.20.0 |
|
15 | + * @access private |
|
16 | + * @var \Wordlift_Mapping_Service $mapping_service The {@link Wordlift_Mapping_Service} instance. |
|
17 | + */ |
|
18 | + private $mapping_service; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Create a {@link Wordlift_Mapping_Ajax_Adapter} instance. |
|
22 | - * |
|
23 | - * @param Wordlift_Mapping_Service $mapping_service The {@link Wordlift_Mapping_Service} instance. |
|
24 | - * |
|
25 | - * @since 3.20.0 |
|
26 | - */ |
|
27 | - public function __construct( $mapping_service ) { |
|
20 | + /** |
|
21 | + * Create a {@link Wordlift_Mapping_Ajax_Adapter} instance. |
|
22 | + * |
|
23 | + * @param Wordlift_Mapping_Service $mapping_service The {@link Wordlift_Mapping_Service} instance. |
|
24 | + * |
|
25 | + * @since 3.20.0 |
|
26 | + */ |
|
27 | + public function __construct( $mapping_service ) { |
|
28 | 28 | |
29 | - $this->mapping_service = $mapping_service; |
|
29 | + $this->mapping_service = $mapping_service; |
|
30 | 30 | |
31 | - add_action( 'wp_ajax_wl_set_entity_types_for_post_type', array( $this, 'set_entity_types_for_post_type' ) ); |
|
32 | - add_action( 'wp_ajax_wl_update_post_type_entity_types', array( $this, 'update_post_type_entity_types' ) ); |
|
31 | + add_action( 'wp_ajax_wl_set_entity_types_for_post_type', array( $this, 'set_entity_types_for_post_type' ) ); |
|
32 | + add_action( 'wp_ajax_wl_update_post_type_entity_types', array( $this, 'update_post_type_entity_types' ) ); |
|
33 | 33 | |
34 | - } |
|
34 | + } |
|
35 | 35 | |
36 | - public function set_entity_types_for_post_type() { |
|
36 | + public function set_entity_types_for_post_type() { |
|
37 | 37 | |
38 | - if ( ! isset( $_REQUEST['post_type'] ) || ! isset( $_REQUEST['entity_types'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
39 | - return; |
|
40 | - } |
|
38 | + if ( ! isset( $_REQUEST['post_type'] ) || ! isset( $_REQUEST['entity_types'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
39 | + return; |
|
40 | + } |
|
41 | 41 | |
42 | - $post_type = sanitize_text_field( wp_unslash( $_REQUEST['post_type'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
43 | - $entity_types = array_map( 'sanitize_text_field', wp_unslash( (array) $_REQUEST['entity_types'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
42 | + $post_type = sanitize_text_field( wp_unslash( $_REQUEST['post_type'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
43 | + $entity_types = array_map( 'sanitize_text_field', wp_unslash( (array) $_REQUEST['entity_types'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
44 | 44 | |
45 | - $this->mapping_service->set_entity_types_for_post_type( $post_type, $entity_types ); |
|
45 | + $this->mapping_service->set_entity_types_for_post_type( $post_type, $entity_types ); |
|
46 | 46 | |
47 | - wp_send_json_success(); |
|
47 | + wp_send_json_success(); |
|
48 | 48 | |
49 | - } |
|
49 | + } |
|
50 | 50 | |
51 | - public function update_post_type_entity_types() { |
|
51 | + public function update_post_type_entity_types() { |
|
52 | 52 | |
53 | - // If the nonce is invalid, return an error. |
|
54 | - $nonce = isset( $_REQUEST['_nonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_nonce'] ) ) : ''; |
|
55 | - if ( ! wp_verify_nonce( $nonce, 'update_post_type_entity_types' ) ) { |
|
56 | - wp_send_json_error( __( 'Nonce Security Check Failed!', 'wordlift' ) ); |
|
57 | - } |
|
53 | + // If the nonce is invalid, return an error. |
|
54 | + $nonce = isset( $_REQUEST['_nonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_nonce'] ) ) : ''; |
|
55 | + if ( ! wp_verify_nonce( $nonce, 'update_post_type_entity_types' ) ) { |
|
56 | + wp_send_json_error( __( 'Nonce Security Check Failed!', 'wordlift' ) ); |
|
57 | + } |
|
58 | 58 | |
59 | - if ( empty( $_REQUEST['post_type'] ) ) { |
|
60 | - wp_send_json_error( __( '`post_type` is required', 'wordlift' ) ); |
|
61 | - } |
|
59 | + if ( empty( $_REQUEST['post_type'] ) ) { |
|
60 | + wp_send_json_error( __( '`post_type` is required', 'wordlift' ) ); |
|
61 | + } |
|
62 | 62 | |
63 | - if ( empty( $_REQUEST['entity_types'] ) ) { |
|
64 | - wp_send_json_error( __( '`entity_types` is required', 'wordlift' ) ); |
|
65 | - } |
|
63 | + if ( empty( $_REQUEST['entity_types'] ) ) { |
|
64 | + wp_send_json_error( __( '`entity_types` is required', 'wordlift' ) ); |
|
65 | + } |
|
66 | 66 | |
67 | - // Get the post type. |
|
68 | - $post_type = isset( $_REQUEST['post_type'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['post_type'] ) ) : ''; |
|
67 | + // Get the post type. |
|
68 | + $post_type = isset( $_REQUEST['post_type'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['post_type'] ) ) : ''; |
|
69 | 69 | |
70 | - // Get the entity types URIs. |
|
71 | - $entity_types = isset( $_REQUEST['entity_types'] ) ? filter_var( wp_unslash( $_REQUEST['entity_types'] ), FILTER_REQUIRE_ARRAY ) : array(); |
|
70 | + // Get the entity types URIs. |
|
71 | + $entity_types = isset( $_REQUEST['entity_types'] ) ? filter_var( wp_unslash( $_REQUEST['entity_types'] ), FILTER_REQUIRE_ARRAY ) : array(); |
|
72 | 72 | |
73 | - // Get the offset. |
|
74 | - $offset = isset( $_REQUEST['offset'] ) ? intval( $_REQUEST['offset'] ) : 0; |
|
73 | + // Get the offset. |
|
74 | + $offset = isset( $_REQUEST['offset'] ) ? intval( $_REQUEST['offset'] ) : 0; |
|
75 | 75 | |
76 | - // Update and get the results. |
|
77 | - $result = $this->mapping_service->update( $post_type, $entity_types, $offset ); |
|
76 | + // Update and get the results. |
|
77 | + $result = $this->mapping_service->update( $post_type, $entity_types, $offset ); |
|
78 | 78 | |
79 | - // Add our nonce to the result. |
|
80 | - $result['_nonce'] = wp_create_nonce( 'update_post_type_entity_types' ); |
|
79 | + // Add our nonce to the result. |
|
80 | + $result['_nonce'] = wp_create_nonce( 'update_post_type_entity_types' ); |
|
81 | 81 | |
82 | - // Finally send the results. |
|
83 | - wp_send_json_success( $result ); |
|
82 | + // Finally send the results. |
|
83 | + wp_send_json_success( $result ); |
|
84 | 84 | |
85 | - } |
|
85 | + } |
|
86 | 86 | |
87 | 87 | } |
@@ -24,25 +24,25 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @since 3.20.0 |
26 | 26 | */ |
27 | - public function __construct( $mapping_service ) { |
|
27 | + public function __construct($mapping_service) { |
|
28 | 28 | |
29 | 29 | $this->mapping_service = $mapping_service; |
30 | 30 | |
31 | - add_action( 'wp_ajax_wl_set_entity_types_for_post_type', array( $this, 'set_entity_types_for_post_type' ) ); |
|
32 | - add_action( 'wp_ajax_wl_update_post_type_entity_types', array( $this, 'update_post_type_entity_types' ) ); |
|
31 | + add_action('wp_ajax_wl_set_entity_types_for_post_type', array($this, 'set_entity_types_for_post_type')); |
|
32 | + add_action('wp_ajax_wl_update_post_type_entity_types', array($this, 'update_post_type_entity_types')); |
|
33 | 33 | |
34 | 34 | } |
35 | 35 | |
36 | 36 | public function set_entity_types_for_post_type() { |
37 | 37 | |
38 | - if ( ! isset( $_REQUEST['post_type'] ) || ! isset( $_REQUEST['entity_types'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
38 | + if ( ! isset($_REQUEST['post_type']) || ! isset($_REQUEST['entity_types'])) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
39 | 39 | return; |
40 | 40 | } |
41 | 41 | |
42 | - $post_type = sanitize_text_field( wp_unslash( $_REQUEST['post_type'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
43 | - $entity_types = array_map( 'sanitize_text_field', wp_unslash( (array) $_REQUEST['entity_types'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
42 | + $post_type = sanitize_text_field(wp_unslash($_REQUEST['post_type'])); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
43 | + $entity_types = array_map('sanitize_text_field', wp_unslash((array) $_REQUEST['entity_types'])); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
44 | 44 | |
45 | - $this->mapping_service->set_entity_types_for_post_type( $post_type, $entity_types ); |
|
45 | + $this->mapping_service->set_entity_types_for_post_type($post_type, $entity_types); |
|
46 | 46 | |
47 | 47 | wp_send_json_success(); |
48 | 48 | |
@@ -51,36 +51,36 @@ discard block |
||
51 | 51 | public function update_post_type_entity_types() { |
52 | 52 | |
53 | 53 | // If the nonce is invalid, return an error. |
54 | - $nonce = isset( $_REQUEST['_nonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_nonce'] ) ) : ''; |
|
55 | - if ( ! wp_verify_nonce( $nonce, 'update_post_type_entity_types' ) ) { |
|
56 | - wp_send_json_error( __( 'Nonce Security Check Failed!', 'wordlift' ) ); |
|
54 | + $nonce = isset($_REQUEST['_nonce']) ? sanitize_text_field(wp_unslash($_REQUEST['_nonce'])) : ''; |
|
55 | + if ( ! wp_verify_nonce($nonce, 'update_post_type_entity_types')) { |
|
56 | + wp_send_json_error(__('Nonce Security Check Failed!', 'wordlift')); |
|
57 | 57 | } |
58 | 58 | |
59 | - if ( empty( $_REQUEST['post_type'] ) ) { |
|
60 | - wp_send_json_error( __( '`post_type` is required', 'wordlift' ) ); |
|
59 | + if (empty($_REQUEST['post_type'])) { |
|
60 | + wp_send_json_error(__('`post_type` is required', 'wordlift')); |
|
61 | 61 | } |
62 | 62 | |
63 | - if ( empty( $_REQUEST['entity_types'] ) ) { |
|
64 | - wp_send_json_error( __( '`entity_types` is required', 'wordlift' ) ); |
|
63 | + if (empty($_REQUEST['entity_types'])) { |
|
64 | + wp_send_json_error(__('`entity_types` is required', 'wordlift')); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | // Get the post type. |
68 | - $post_type = isset( $_REQUEST['post_type'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['post_type'] ) ) : ''; |
|
68 | + $post_type = isset($_REQUEST['post_type']) ? sanitize_text_field(wp_unslash($_REQUEST['post_type'])) : ''; |
|
69 | 69 | |
70 | 70 | // Get the entity types URIs. |
71 | - $entity_types = isset( $_REQUEST['entity_types'] ) ? filter_var( wp_unslash( $_REQUEST['entity_types'] ), FILTER_REQUIRE_ARRAY ) : array(); |
|
71 | + $entity_types = isset($_REQUEST['entity_types']) ? filter_var(wp_unslash($_REQUEST['entity_types']), FILTER_REQUIRE_ARRAY) : array(); |
|
72 | 72 | |
73 | 73 | // Get the offset. |
74 | - $offset = isset( $_REQUEST['offset'] ) ? intval( $_REQUEST['offset'] ) : 0; |
|
74 | + $offset = isset($_REQUEST['offset']) ? intval($_REQUEST['offset']) : 0; |
|
75 | 75 | |
76 | 76 | // Update and get the results. |
77 | - $result = $this->mapping_service->update( $post_type, $entity_types, $offset ); |
|
77 | + $result = $this->mapping_service->update($post_type, $entity_types, $offset); |
|
78 | 78 | |
79 | 79 | // Add our nonce to the result. |
80 | - $result['_nonce'] = wp_create_nonce( 'update_post_type_entity_types' ); |
|
80 | + $result['_nonce'] = wp_create_nonce('update_post_type_entity_types'); |
|
81 | 81 | |
82 | 82 | // Finally send the results. |
83 | - wp_send_json_success( $result ); |
|
83 | + wp_send_json_success($result); |
|
84 | 84 | |
85 | 85 | } |
86 | 86 |
@@ -14,223 +14,223 @@ |
||
14 | 14 | */ |
15 | 15 | class Wordlift_Mapping_Service { |
16 | 16 | |
17 | - /** |
|
18 | - * The mapping's options. |
|
19 | - * |
|
20 | - * @since 3.20.0 |
|
21 | - * @access private |
|
22 | - * @var array $options The mapping's options. |
|
23 | - */ |
|
24 | - private $options; |
|
25 | - |
|
26 | - /** |
|
27 | - * The {@link Wordlift_Entity_Type_Service} instance. |
|
28 | - * |
|
29 | - * @since 3.20.0 |
|
30 | - * @access private |
|
31 | - * @var \Wordlift_Entity_Type_Service $entity_type_service The {@link Wordlift_Entity_Type_Service} instance. |
|
32 | - */ |
|
33 | - private $entity_type_service; |
|
34 | - |
|
35 | - /** |
|
36 | - * The singleton instance. |
|
37 | - * |
|
38 | - * @since 3.20.0 |
|
39 | - * @access private |
|
40 | - * @var \Wordlift_Mapping_Service $instance The singleton instance. |
|
41 | - */ |
|
42 | - private static $instance; |
|
43 | - |
|
44 | - /** |
|
45 | - * Create a {@link Wordlift_Mapping_Service} instance. |
|
46 | - * |
|
47 | - * @since 3.20.0 |
|
48 | - * |
|
49 | - * @param \Wordlift_Entity_Type_Service $entity_type_service The {@link Wordlift_Entity_Type_Service} instance. |
|
50 | - */ |
|
51 | - public function __construct( $entity_type_service ) { |
|
52 | - |
|
53 | - // Set the entity type service instance. |
|
54 | - $this->entity_type_service = $entity_type_service; |
|
55 | - |
|
56 | - // Load the options. |
|
57 | - $this->options = get_option( 'wl_mappings', array() ); |
|
58 | - |
|
59 | - // Hook to `wl_valid_entity_post_types` and to `wl_default_entity_types_for_post_type`. |
|
60 | - add_filter( 'wl_valid_entity_post_types', array( $this, 'valid_entity_post_types' ), 9 ); |
|
61 | - add_filter( |
|
62 | - 'wl_default_entity_types_for_post_type', |
|
63 | - array( |
|
64 | - $this, |
|
65 | - 'default_entity_types_for_post_type', |
|
66 | - ), |
|
67 | - 9, |
|
68 | - 2 |
|
69 | - ); |
|
70 | - |
|
71 | - // Set the singleton instance. |
|
72 | - self::$instance = $this; |
|
73 | - |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Get the singleton instance. |
|
78 | - * |
|
79 | - * @since 3.20.0 |
|
80 | - * |
|
81 | - * @return \Wordlift_Mapping_Service The singleton instance. |
|
82 | - */ |
|
83 | - public static function get_instance() { |
|
84 | - |
|
85 | - return self::$instance; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Save the options. |
|
90 | - * |
|
91 | - * @since 3.20.0 |
|
92 | - */ |
|
93 | - private function save_options() { |
|
94 | - |
|
95 | - update_option( 'wl_mappings', $this->options, true ); |
|
96 | - |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Set the default entity types for a post type. |
|
101 | - * |
|
102 | - * @since 3.20.0 |
|
103 | - * |
|
104 | - * @param string $post_type Post type. |
|
105 | - * @param array $entity_types An array of entity types slugs. |
|
106 | - */ |
|
107 | - public function set_entity_types_for_post_type( $post_type, $entity_types ) { |
|
108 | - |
|
109 | - $this->options[ $post_type ] = $entity_types; |
|
110 | - $this->save_options(); |
|
111 | - |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Hook to `wl_valid_entity_post_types` to declare schema.org support for the configured post types. |
|
116 | - * |
|
117 | - * @since 3.20.0 |
|
118 | - * |
|
119 | - * @param array $post_types The default post types. |
|
120 | - * |
|
121 | - * @return array The supported post types. |
|
122 | - */ |
|
123 | - public function valid_entity_post_types( $post_types ) { |
|
124 | - |
|
125 | - return array_merge( $post_types, array_keys( $this->options ) ); |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Hook to `wl_default_entity_types_for_post_type` to declare the entity types for a post type. |
|
130 | - * |
|
131 | - * @since 3.20.0 |
|
132 | - * |
|
133 | - * @param array $default The default entity types. |
|
134 | - * @param string $post_type The post type. |
|
135 | - * |
|
136 | - * @return array The default entity types. |
|
137 | - */ |
|
138 | - public function default_entity_types_for_post_type( $default, $post_type ) { |
|
139 | - |
|
140 | - return isset( $this->options[ $post_type ] ) ? $this->options[ $post_type ] : $default; |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Update the post type with the entity types, starting at the specified offset. |
|
145 | - * |
|
146 | - * @since 3.20.0 |
|
147 | - * |
|
148 | - * @param string $post_type The post type. |
|
149 | - * @param array $entity_types The entity types. |
|
150 | - * @param int $offset The offset (0 by default). |
|
151 | - * |
|
152 | - * @return array { |
|
153 | - * The result array. |
|
154 | - * |
|
155 | - * @type int $current The current offset. |
|
156 | - * @type int $next The next offset. |
|
157 | - * @type int $count The total element count. |
|
158 | - * } |
|
159 | - */ |
|
160 | - public function update( $post_type, $entity_types, $offset = 0 ) { |
|
161 | - |
|
162 | - $entity_type_service = $this->entity_type_service; |
|
163 | - $tax_query = $this->get_tax_query( $entity_types ); |
|
164 | - |
|
165 | - return Wordlift_Batch_Action::process( |
|
166 | - $post_type, |
|
167 | - $offset, |
|
168 | - $tax_query, |
|
169 | - function ( $post_id ) use ( $entity_type_service, $entity_types ) { |
|
170 | - foreach ( $entity_types as $entity_type ) { |
|
171 | - $entity_type_service->set( $post_id, $entity_type, false ); |
|
172 | - } |
|
173 | - } |
|
174 | - ); |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * Count the number of posts that need to be assigned with the entity types. |
|
179 | - * |
|
180 | - * @since 3.20.0 |
|
181 | - * |
|
182 | - * @param string $post_type The post type. |
|
183 | - * @param array $entity_types An array of entity types. |
|
184 | - * |
|
185 | - * @return int The number of posts to be assigned with entity types. |
|
186 | - */ |
|
187 | - public function count( $post_type, $entity_types ) { |
|
188 | - |
|
189 | - $tax_query = $this->get_tax_query( $entity_types ); |
|
190 | - |
|
191 | - return Wordlift_Batch_Action::count( $post_type, $tax_query ); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Get the taxonomy query for the specified entity types. |
|
196 | - * |
|
197 | - * @since 3.20.0 |
|
198 | - * |
|
199 | - * @param array $entity_types The entity types. |
|
200 | - * |
|
201 | - * @return array The tax query. |
|
202 | - */ |
|
203 | - private function get_tax_query( $entity_types ) { |
|
204 | - |
|
205 | - $entity_type_service = $this->entity_type_service; |
|
206 | - $entity_types_terms = array_filter( |
|
207 | - array_map( |
|
208 | - function ( $item ) use ( $entity_type_service ) { |
|
209 | - return $entity_type_service->get_term_by_uri( $item ); |
|
210 | - }, |
|
211 | - $entity_types |
|
212 | - ) |
|
213 | - ); |
|
214 | - |
|
215 | - $entity_types_terms_ids = array_map( |
|
216 | - function ( $term ) { |
|
217 | - return $term->term_id; |
|
218 | - }, |
|
219 | - $entity_types_terms |
|
220 | - ); |
|
221 | - |
|
222 | - $tax_query = array( |
|
223 | - 'tax_query' => array( |
|
224 | - array( |
|
225 | - 'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
|
226 | - 'field' => 'term_id', |
|
227 | - 'terms' => $entity_types_terms_ids, |
|
228 | - 'operator' => 'NOT IN', |
|
229 | - ), |
|
230 | - ), |
|
231 | - ); |
|
232 | - |
|
233 | - return $tax_query; |
|
234 | - } |
|
17 | + /** |
|
18 | + * The mapping's options. |
|
19 | + * |
|
20 | + * @since 3.20.0 |
|
21 | + * @access private |
|
22 | + * @var array $options The mapping's options. |
|
23 | + */ |
|
24 | + private $options; |
|
25 | + |
|
26 | + /** |
|
27 | + * The {@link Wordlift_Entity_Type_Service} instance. |
|
28 | + * |
|
29 | + * @since 3.20.0 |
|
30 | + * @access private |
|
31 | + * @var \Wordlift_Entity_Type_Service $entity_type_service The {@link Wordlift_Entity_Type_Service} instance. |
|
32 | + */ |
|
33 | + private $entity_type_service; |
|
34 | + |
|
35 | + /** |
|
36 | + * The singleton instance. |
|
37 | + * |
|
38 | + * @since 3.20.0 |
|
39 | + * @access private |
|
40 | + * @var \Wordlift_Mapping_Service $instance The singleton instance. |
|
41 | + */ |
|
42 | + private static $instance; |
|
43 | + |
|
44 | + /** |
|
45 | + * Create a {@link Wordlift_Mapping_Service} instance. |
|
46 | + * |
|
47 | + * @since 3.20.0 |
|
48 | + * |
|
49 | + * @param \Wordlift_Entity_Type_Service $entity_type_service The {@link Wordlift_Entity_Type_Service} instance. |
|
50 | + */ |
|
51 | + public function __construct( $entity_type_service ) { |
|
52 | + |
|
53 | + // Set the entity type service instance. |
|
54 | + $this->entity_type_service = $entity_type_service; |
|
55 | + |
|
56 | + // Load the options. |
|
57 | + $this->options = get_option( 'wl_mappings', array() ); |
|
58 | + |
|
59 | + // Hook to `wl_valid_entity_post_types` and to `wl_default_entity_types_for_post_type`. |
|
60 | + add_filter( 'wl_valid_entity_post_types', array( $this, 'valid_entity_post_types' ), 9 ); |
|
61 | + add_filter( |
|
62 | + 'wl_default_entity_types_for_post_type', |
|
63 | + array( |
|
64 | + $this, |
|
65 | + 'default_entity_types_for_post_type', |
|
66 | + ), |
|
67 | + 9, |
|
68 | + 2 |
|
69 | + ); |
|
70 | + |
|
71 | + // Set the singleton instance. |
|
72 | + self::$instance = $this; |
|
73 | + |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Get the singleton instance. |
|
78 | + * |
|
79 | + * @since 3.20.0 |
|
80 | + * |
|
81 | + * @return \Wordlift_Mapping_Service The singleton instance. |
|
82 | + */ |
|
83 | + public static function get_instance() { |
|
84 | + |
|
85 | + return self::$instance; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Save the options. |
|
90 | + * |
|
91 | + * @since 3.20.0 |
|
92 | + */ |
|
93 | + private function save_options() { |
|
94 | + |
|
95 | + update_option( 'wl_mappings', $this->options, true ); |
|
96 | + |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Set the default entity types for a post type. |
|
101 | + * |
|
102 | + * @since 3.20.0 |
|
103 | + * |
|
104 | + * @param string $post_type Post type. |
|
105 | + * @param array $entity_types An array of entity types slugs. |
|
106 | + */ |
|
107 | + public function set_entity_types_for_post_type( $post_type, $entity_types ) { |
|
108 | + |
|
109 | + $this->options[ $post_type ] = $entity_types; |
|
110 | + $this->save_options(); |
|
111 | + |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Hook to `wl_valid_entity_post_types` to declare schema.org support for the configured post types. |
|
116 | + * |
|
117 | + * @since 3.20.0 |
|
118 | + * |
|
119 | + * @param array $post_types The default post types. |
|
120 | + * |
|
121 | + * @return array The supported post types. |
|
122 | + */ |
|
123 | + public function valid_entity_post_types( $post_types ) { |
|
124 | + |
|
125 | + return array_merge( $post_types, array_keys( $this->options ) ); |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Hook to `wl_default_entity_types_for_post_type` to declare the entity types for a post type. |
|
130 | + * |
|
131 | + * @since 3.20.0 |
|
132 | + * |
|
133 | + * @param array $default The default entity types. |
|
134 | + * @param string $post_type The post type. |
|
135 | + * |
|
136 | + * @return array The default entity types. |
|
137 | + */ |
|
138 | + public function default_entity_types_for_post_type( $default, $post_type ) { |
|
139 | + |
|
140 | + return isset( $this->options[ $post_type ] ) ? $this->options[ $post_type ] : $default; |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Update the post type with the entity types, starting at the specified offset. |
|
145 | + * |
|
146 | + * @since 3.20.0 |
|
147 | + * |
|
148 | + * @param string $post_type The post type. |
|
149 | + * @param array $entity_types The entity types. |
|
150 | + * @param int $offset The offset (0 by default). |
|
151 | + * |
|
152 | + * @return array { |
|
153 | + * The result array. |
|
154 | + * |
|
155 | + * @type int $current The current offset. |
|
156 | + * @type int $next The next offset. |
|
157 | + * @type int $count The total element count. |
|
158 | + * } |
|
159 | + */ |
|
160 | + public function update( $post_type, $entity_types, $offset = 0 ) { |
|
161 | + |
|
162 | + $entity_type_service = $this->entity_type_service; |
|
163 | + $tax_query = $this->get_tax_query( $entity_types ); |
|
164 | + |
|
165 | + return Wordlift_Batch_Action::process( |
|
166 | + $post_type, |
|
167 | + $offset, |
|
168 | + $tax_query, |
|
169 | + function ( $post_id ) use ( $entity_type_service, $entity_types ) { |
|
170 | + foreach ( $entity_types as $entity_type ) { |
|
171 | + $entity_type_service->set( $post_id, $entity_type, false ); |
|
172 | + } |
|
173 | + } |
|
174 | + ); |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * Count the number of posts that need to be assigned with the entity types. |
|
179 | + * |
|
180 | + * @since 3.20.0 |
|
181 | + * |
|
182 | + * @param string $post_type The post type. |
|
183 | + * @param array $entity_types An array of entity types. |
|
184 | + * |
|
185 | + * @return int The number of posts to be assigned with entity types. |
|
186 | + */ |
|
187 | + public function count( $post_type, $entity_types ) { |
|
188 | + |
|
189 | + $tax_query = $this->get_tax_query( $entity_types ); |
|
190 | + |
|
191 | + return Wordlift_Batch_Action::count( $post_type, $tax_query ); |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Get the taxonomy query for the specified entity types. |
|
196 | + * |
|
197 | + * @since 3.20.0 |
|
198 | + * |
|
199 | + * @param array $entity_types The entity types. |
|
200 | + * |
|
201 | + * @return array The tax query. |
|
202 | + */ |
|
203 | + private function get_tax_query( $entity_types ) { |
|
204 | + |
|
205 | + $entity_type_service = $this->entity_type_service; |
|
206 | + $entity_types_terms = array_filter( |
|
207 | + array_map( |
|
208 | + function ( $item ) use ( $entity_type_service ) { |
|
209 | + return $entity_type_service->get_term_by_uri( $item ); |
|
210 | + }, |
|
211 | + $entity_types |
|
212 | + ) |
|
213 | + ); |
|
214 | + |
|
215 | + $entity_types_terms_ids = array_map( |
|
216 | + function ( $term ) { |
|
217 | + return $term->term_id; |
|
218 | + }, |
|
219 | + $entity_types_terms |
|
220 | + ); |
|
221 | + |
|
222 | + $tax_query = array( |
|
223 | + 'tax_query' => array( |
|
224 | + array( |
|
225 | + 'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
|
226 | + 'field' => 'term_id', |
|
227 | + 'terms' => $entity_types_terms_ids, |
|
228 | + 'operator' => 'NOT IN', |
|
229 | + ), |
|
230 | + ), |
|
231 | + ); |
|
232 | + |
|
233 | + return $tax_query; |
|
234 | + } |
|
235 | 235 | |
236 | 236 | } |
@@ -48,16 +48,16 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @param \Wordlift_Entity_Type_Service $entity_type_service The {@link Wordlift_Entity_Type_Service} instance. |
50 | 50 | */ |
51 | - public function __construct( $entity_type_service ) { |
|
51 | + public function __construct($entity_type_service) { |
|
52 | 52 | |
53 | 53 | // Set the entity type service instance. |
54 | 54 | $this->entity_type_service = $entity_type_service; |
55 | 55 | |
56 | 56 | // Load the options. |
57 | - $this->options = get_option( 'wl_mappings', array() ); |
|
57 | + $this->options = get_option('wl_mappings', array()); |
|
58 | 58 | |
59 | 59 | // Hook to `wl_valid_entity_post_types` and to `wl_default_entity_types_for_post_type`. |
60 | - add_filter( 'wl_valid_entity_post_types', array( $this, 'valid_entity_post_types' ), 9 ); |
|
60 | + add_filter('wl_valid_entity_post_types', array($this, 'valid_entity_post_types'), 9); |
|
61 | 61 | add_filter( |
62 | 62 | 'wl_default_entity_types_for_post_type', |
63 | 63 | array( |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | */ |
93 | 93 | private function save_options() { |
94 | 94 | |
95 | - update_option( 'wl_mappings', $this->options, true ); |
|
95 | + update_option('wl_mappings', $this->options, true); |
|
96 | 96 | |
97 | 97 | } |
98 | 98 | |
@@ -104,9 +104,9 @@ discard block |
||
104 | 104 | * @param string $post_type Post type. |
105 | 105 | * @param array $entity_types An array of entity types slugs. |
106 | 106 | */ |
107 | - public function set_entity_types_for_post_type( $post_type, $entity_types ) { |
|
107 | + public function set_entity_types_for_post_type($post_type, $entity_types) { |
|
108 | 108 | |
109 | - $this->options[ $post_type ] = $entity_types; |
|
109 | + $this->options[$post_type] = $entity_types; |
|
110 | 110 | $this->save_options(); |
111 | 111 | |
112 | 112 | } |
@@ -120,9 +120,9 @@ discard block |
||
120 | 120 | * |
121 | 121 | * @return array The supported post types. |
122 | 122 | */ |
123 | - public function valid_entity_post_types( $post_types ) { |
|
123 | + public function valid_entity_post_types($post_types) { |
|
124 | 124 | |
125 | - return array_merge( $post_types, array_keys( $this->options ) ); |
|
125 | + return array_merge($post_types, array_keys($this->options)); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -135,9 +135,9 @@ discard block |
||
135 | 135 | * |
136 | 136 | * @return array The default entity types. |
137 | 137 | */ |
138 | - public function default_entity_types_for_post_type( $default, $post_type ) { |
|
138 | + public function default_entity_types_for_post_type($default, $post_type) { |
|
139 | 139 | |
140 | - return isset( $this->options[ $post_type ] ) ? $this->options[ $post_type ] : $default; |
|
140 | + return isset($this->options[$post_type]) ? $this->options[$post_type] : $default; |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
@@ -157,18 +157,18 @@ discard block |
||
157 | 157 | * @type int $count The total element count. |
158 | 158 | * } |
159 | 159 | */ |
160 | - public function update( $post_type, $entity_types, $offset = 0 ) { |
|
160 | + public function update($post_type, $entity_types, $offset = 0) { |
|
161 | 161 | |
162 | 162 | $entity_type_service = $this->entity_type_service; |
163 | - $tax_query = $this->get_tax_query( $entity_types ); |
|
163 | + $tax_query = $this->get_tax_query($entity_types); |
|
164 | 164 | |
165 | 165 | return Wordlift_Batch_Action::process( |
166 | 166 | $post_type, |
167 | 167 | $offset, |
168 | 168 | $tax_query, |
169 | - function ( $post_id ) use ( $entity_type_service, $entity_types ) { |
|
170 | - foreach ( $entity_types as $entity_type ) { |
|
171 | - $entity_type_service->set( $post_id, $entity_type, false ); |
|
169 | + function($post_id) use ($entity_type_service, $entity_types) { |
|
170 | + foreach ($entity_types as $entity_type) { |
|
171 | + $entity_type_service->set($post_id, $entity_type, false); |
|
172 | 172 | } |
173 | 173 | } |
174 | 174 | ); |
@@ -184,11 +184,11 @@ discard block |
||
184 | 184 | * |
185 | 185 | * @return int The number of posts to be assigned with entity types. |
186 | 186 | */ |
187 | - public function count( $post_type, $entity_types ) { |
|
187 | + public function count($post_type, $entity_types) { |
|
188 | 188 | |
189 | - $tax_query = $this->get_tax_query( $entity_types ); |
|
189 | + $tax_query = $this->get_tax_query($entity_types); |
|
190 | 190 | |
191 | - return Wordlift_Batch_Action::count( $post_type, $tax_query ); |
|
191 | + return Wordlift_Batch_Action::count($post_type, $tax_query); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -200,20 +200,20 @@ discard block |
||
200 | 200 | * |
201 | 201 | * @return array The tax query. |
202 | 202 | */ |
203 | - private function get_tax_query( $entity_types ) { |
|
203 | + private function get_tax_query($entity_types) { |
|
204 | 204 | |
205 | 205 | $entity_type_service = $this->entity_type_service; |
206 | 206 | $entity_types_terms = array_filter( |
207 | 207 | array_map( |
208 | - function ( $item ) use ( $entity_type_service ) { |
|
209 | - return $entity_type_service->get_term_by_uri( $item ); |
|
208 | + function($item) use ($entity_type_service) { |
|
209 | + return $entity_type_service->get_term_by_uri($item); |
|
210 | 210 | }, |
211 | 211 | $entity_types |
212 | 212 | ) |
213 | 213 | ); |
214 | 214 | |
215 | 215 | $entity_types_terms_ids = array_map( |
216 | - function ( $term ) { |
|
216 | + function($term) { |
|
217 | 217 | return $term->term_id; |
218 | 218 | }, |
219 | 219 | $entity_types_terms |
@@ -7,148 +7,148 @@ |
||
7 | 7 | */ |
8 | 8 | class Wordlift_Log_Service { |
9 | 9 | |
10 | - const MESSAGE_TEMPLATE = '%-6s [%-40.40s] %s'; |
|
11 | - |
|
12 | - const ERROR = 4; |
|
13 | - const WARN = 3; |
|
14 | - const INFO = 2; |
|
15 | - const DEBUG = 1; |
|
16 | - const TRACE = 0; |
|
17 | - |
|
18 | - /** |
|
19 | - * The class related to the logs. |
|
20 | - * |
|
21 | - * @since 1.0.0 |
|
22 | - * @access private |
|
23 | - * @var string $class_name The class related to the logs. |
|
24 | - */ |
|
25 | - private $class_name; |
|
26 | - |
|
27 | - /** |
|
28 | - * The log levels for printing in log lines. |
|
29 | - * |
|
30 | - * @var array $levels An array of log levels. |
|
31 | - */ |
|
32 | - private static $levels = array( |
|
33 | - self::TRACE => 'TRACE', |
|
34 | - self::DEBUG => 'DEBUG', |
|
35 | - self::INFO => 'INFO', |
|
36 | - self::WARN => 'WARN', |
|
37 | - self::ERROR => 'ERROR', |
|
38 | - ); |
|
39 | - |
|
40 | - /** |
|
41 | - * A singleton instance for legacy logging. |
|
42 | - * |
|
43 | - * @since 3.10.0 |
|
44 | - * @access private |
|
45 | - * @var \Wordlift_Log_Service $instance A singleton instance for legacy logging. |
|
46 | - */ |
|
47 | - private static $instance = null; |
|
10 | + const MESSAGE_TEMPLATE = '%-6s [%-40.40s] %s'; |
|
11 | + |
|
12 | + const ERROR = 4; |
|
13 | + const WARN = 3; |
|
14 | + const INFO = 2; |
|
15 | + const DEBUG = 1; |
|
16 | + const TRACE = 0; |
|
17 | + |
|
18 | + /** |
|
19 | + * The class related to the logs. |
|
20 | + * |
|
21 | + * @since 1.0.0 |
|
22 | + * @access private |
|
23 | + * @var string $class_name The class related to the logs. |
|
24 | + */ |
|
25 | + private $class_name; |
|
26 | + |
|
27 | + /** |
|
28 | + * The log levels for printing in log lines. |
|
29 | + * |
|
30 | + * @var array $levels An array of log levels. |
|
31 | + */ |
|
32 | + private static $levels = array( |
|
33 | + self::TRACE => 'TRACE', |
|
34 | + self::DEBUG => 'DEBUG', |
|
35 | + self::INFO => 'INFO', |
|
36 | + self::WARN => 'WARN', |
|
37 | + self::ERROR => 'ERROR', |
|
38 | + ); |
|
39 | + |
|
40 | + /** |
|
41 | + * A singleton instance for legacy logging. |
|
42 | + * |
|
43 | + * @since 3.10.0 |
|
44 | + * @access private |
|
45 | + * @var \Wordlift_Log_Service $instance A singleton instance for legacy logging. |
|
46 | + */ |
|
47 | + private static $instance = null; |
|
48 | 48 | |
49 | - /** |
|
50 | - * Create an instance of the Log service. |
|
51 | - * |
|
52 | - * @param string $class_name The class related to the logs. |
|
53 | - * |
|
54 | - * @since 1.0.0 |
|
55 | - */ |
|
56 | - public function __construct( $class_name ) { |
|
49 | + /** |
|
50 | + * Create an instance of the Log service. |
|
51 | + * |
|
52 | + * @param string $class_name The class related to the logs. |
|
53 | + * |
|
54 | + * @since 1.0.0 |
|
55 | + */ |
|
56 | + public function __construct( $class_name ) { |
|
57 | 57 | |
58 | - $this->class_name = $class_name; |
|
58 | + $this->class_name = $class_name; |
|
59 | 59 | |
60 | - } |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Get the ROOT logger. |
|
64 | - * |
|
65 | - * @return \Wordlift_Log_Service A singleton instance for legacy logging. |
|
66 | - * @since 3.10.0 |
|
67 | - */ |
|
68 | - public static function get_instance() { |
|
62 | + /** |
|
63 | + * Get the ROOT logger. |
|
64 | + * |
|
65 | + * @return \Wordlift_Log_Service A singleton instance for legacy logging. |
|
66 | + * @since 3.10.0 |
|
67 | + */ |
|
68 | + public static function get_instance() { |
|
69 | 69 | |
70 | - if ( ! isset( self::$instance ) ) { |
|
71 | - self::$instance = new Wordlift_Log_Service( 'ROOT' ); |
|
72 | - } |
|
70 | + if ( ! isset( self::$instance ) ) { |
|
71 | + self::$instance = new Wordlift_Log_Service( 'ROOT' ); |
|
72 | + } |
|
73 | 73 | |
74 | - return self::$instance; |
|
75 | - } |
|
74 | + return self::$instance; |
|
75 | + } |
|
76 | 76 | |
77 | - public static function get_logger( $class_name ) { |
|
77 | + public static function get_logger( $class_name ) { |
|
78 | 78 | |
79 | - return new Wordlift_Log_Service( $class_name ); |
|
79 | + return new Wordlift_Log_Service( $class_name ); |
|
80 | 80 | |
81 | - } |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Log a message. |
|
85 | - * |
|
86 | - * @param string $level The log level. |
|
87 | - * @param string $message The message to log. |
|
88 | - * |
|
89 | - * @since 1.0.0 |
|
90 | - */ |
|
91 | - public function log( $level, $message ) { |
|
83 | + /** |
|
84 | + * Log a message. |
|
85 | + * |
|
86 | + * @param string $level The log level. |
|
87 | + * @param string $message The message to log. |
|
88 | + * |
|
89 | + * @since 1.0.0 |
|
90 | + */ |
|
91 | + public function log( $level, $message ) { |
|
92 | 92 | |
93 | - // echo( sprintf( self::MESSAGE_TEMPLATE . "\n", self::$levels[ $level ], $this->class_name, is_array( $message ) ? implode( ', ', $message ) : $message ) ); |
|
93 | + // echo( sprintf( self::MESSAGE_TEMPLATE . "\n", self::$levels[ $level ], $this->class_name, is_array( $message ) ? implode( ', ', $message ) : $message ) ); |
|
94 | 94 | |
95 | - // Bail out if `WL_DEBUG` isn't defined or it's false. |
|
96 | - if ( ! defined( 'WL_DEBUG' ) || false === WL_DEBUG ) { |
|
97 | - return; |
|
98 | - } |
|
95 | + // Bail out if `WL_DEBUG` isn't defined or it's false. |
|
96 | + if ( ! defined( 'WL_DEBUG' ) || false === WL_DEBUG ) { |
|
97 | + return; |
|
98 | + } |
|
99 | 99 | |
100 | - // Bail out if WordLift log level isn't defined, and WP debug is disabled. |
|
101 | - if ( ! defined( 'WL_LOG_LEVEL' ) && $level < self::ERROR |
|
102 | - && ( ! defined( 'WP_DEBUG' ) || false === WP_DEBUG ) ) { |
|
103 | - return; |
|
104 | - } |
|
100 | + // Bail out if WordLift log level isn't defined, and WP debug is disabled. |
|
101 | + if ( ! defined( 'WL_LOG_LEVEL' ) && $level < self::ERROR |
|
102 | + && ( ! defined( 'WP_DEBUG' ) || false === WP_DEBUG ) ) { |
|
103 | + return; |
|
104 | + } |
|
105 | 105 | |
106 | - // Bail out if the log message is below the minimum log level. |
|
107 | - if ( defined( 'WL_LOG_LEVEL' ) && $level < intval( WL_LOG_LEVEL ) ) { |
|
108 | - return; |
|
109 | - } |
|
106 | + // Bail out if the log message is below the minimum log level. |
|
107 | + if ( defined( 'WL_LOG_LEVEL' ) && $level < intval( WL_LOG_LEVEL ) ) { |
|
108 | + return; |
|
109 | + } |
|
110 | 110 | |
111 | - // Bail out if there's a filter and we don't match it. |
|
112 | - $class_name = wp_slash( $this->class_name ); |
|
113 | - if ( defined( 'WL_LOG_FILTER' ) && 1 !== preg_match( "/(^|,)$class_name($|,)/", WL_LOG_FILTER ) ) { |
|
114 | - return; |
|
115 | - } |
|
111 | + // Bail out if there's a filter and we don't match it. |
|
112 | + $class_name = wp_slash( $this->class_name ); |
|
113 | + if ( defined( 'WL_LOG_FILTER' ) && 1 !== preg_match( "/(^|,)$class_name($|,)/", WL_LOG_FILTER ) ) { |
|
114 | + return; |
|
115 | + } |
|
116 | 116 | |
117 | - // Finally log the message. |
|
118 | - // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log |
|
119 | - error_log( sprintf( self::MESSAGE_TEMPLATE, self::$levels[ $level ], $this->class_name, is_array( $message ) ? implode( ', ', $message ) : $message ) ); |
|
117 | + // Finally log the message. |
|
118 | + // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log |
|
119 | + error_log( sprintf( self::MESSAGE_TEMPLATE, self::$levels[ $level ], $this->class_name, is_array( $message ) ? implode( ', ', $message ) : $message ) ); |
|
120 | 120 | |
121 | - } |
|
121 | + } |
|
122 | 122 | |
123 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
124 | - public function error( $message, $exception = null ) { |
|
123 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
124 | + public function error( $message, $exception = null ) { |
|
125 | 125 | |
126 | - $this->log( self::ERROR, $message ); |
|
126 | + $this->log( self::ERROR, $message ); |
|
127 | 127 | |
128 | - } |
|
128 | + } |
|
129 | 129 | |
130 | - public function warn( $message ) { |
|
130 | + public function warn( $message ) { |
|
131 | 131 | |
132 | - $this->log( self::WARN, $message ); |
|
132 | + $this->log( self::WARN, $message ); |
|
133 | 133 | |
134 | - } |
|
134 | + } |
|
135 | 135 | |
136 | - public function info( $message ) { |
|
136 | + public function info( $message ) { |
|
137 | 137 | |
138 | - $this->log( self::INFO, $message ); |
|
138 | + $this->log( self::INFO, $message ); |
|
139 | 139 | |
140 | - } |
|
140 | + } |
|
141 | 141 | |
142 | - public function debug( $message ) { |
|
142 | + public function debug( $message ) { |
|
143 | 143 | |
144 | - $this->log( self::DEBUG, $message ); |
|
144 | + $this->log( self::DEBUG, $message ); |
|
145 | 145 | |
146 | - } |
|
146 | + } |
|
147 | 147 | |
148 | - public function trace( $message ) { |
|
148 | + public function trace( $message ) { |
|
149 | 149 | |
150 | - $this->log( self::TRACE, $message ); |
|
150 | + $this->log( self::TRACE, $message ); |
|
151 | 151 | |
152 | - } |
|
152 | + } |
|
153 | 153 | |
154 | 154 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @since 1.0.0 |
55 | 55 | */ |
56 | - public function __construct( $class_name ) { |
|
56 | + public function __construct($class_name) { |
|
57 | 57 | |
58 | 58 | $this->class_name = $class_name; |
59 | 59 | |
@@ -67,16 +67,16 @@ discard block |
||
67 | 67 | */ |
68 | 68 | public static function get_instance() { |
69 | 69 | |
70 | - if ( ! isset( self::$instance ) ) { |
|
71 | - self::$instance = new Wordlift_Log_Service( 'ROOT' ); |
|
70 | + if ( ! isset(self::$instance)) { |
|
71 | + self::$instance = new Wordlift_Log_Service('ROOT'); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | return self::$instance; |
75 | 75 | } |
76 | 76 | |
77 | - public static function get_logger( $class_name ) { |
|
77 | + public static function get_logger($class_name) { |
|
78 | 78 | |
79 | - return new Wordlift_Log_Service( $class_name ); |
|
79 | + return new Wordlift_Log_Service($class_name); |
|
80 | 80 | |
81 | 81 | } |
82 | 82 | |
@@ -88,66 +88,66 @@ discard block |
||
88 | 88 | * |
89 | 89 | * @since 1.0.0 |
90 | 90 | */ |
91 | - public function log( $level, $message ) { |
|
91 | + public function log($level, $message) { |
|
92 | 92 | |
93 | 93 | // echo( sprintf( self::MESSAGE_TEMPLATE . "\n", self::$levels[ $level ], $this->class_name, is_array( $message ) ? implode( ', ', $message ) : $message ) ); |
94 | 94 | |
95 | 95 | // Bail out if `WL_DEBUG` isn't defined or it's false. |
96 | - if ( ! defined( 'WL_DEBUG' ) || false === WL_DEBUG ) { |
|
96 | + if ( ! defined('WL_DEBUG') || false === WL_DEBUG) { |
|
97 | 97 | return; |
98 | 98 | } |
99 | 99 | |
100 | 100 | // Bail out if WordLift log level isn't defined, and WP debug is disabled. |
101 | - if ( ! defined( 'WL_LOG_LEVEL' ) && $level < self::ERROR |
|
102 | - && ( ! defined( 'WP_DEBUG' ) || false === WP_DEBUG ) ) { |
|
101 | + if ( ! defined('WL_LOG_LEVEL') && $level < self::ERROR |
|
102 | + && ( ! defined('WP_DEBUG') || false === WP_DEBUG)) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | // Bail out if the log message is below the minimum log level. |
107 | - if ( defined( 'WL_LOG_LEVEL' ) && $level < intval( WL_LOG_LEVEL ) ) { |
|
107 | + if (defined('WL_LOG_LEVEL') && $level < intval(WL_LOG_LEVEL)) { |
|
108 | 108 | return; |
109 | 109 | } |
110 | 110 | |
111 | 111 | // Bail out if there's a filter and we don't match it. |
112 | - $class_name = wp_slash( $this->class_name ); |
|
113 | - if ( defined( 'WL_LOG_FILTER' ) && 1 !== preg_match( "/(^|,)$class_name($|,)/", WL_LOG_FILTER ) ) { |
|
112 | + $class_name = wp_slash($this->class_name); |
|
113 | + if (defined('WL_LOG_FILTER') && 1 !== preg_match("/(^|,)$class_name($|,)/", WL_LOG_FILTER)) { |
|
114 | 114 | return; |
115 | 115 | } |
116 | 116 | |
117 | 117 | // Finally log the message. |
118 | 118 | // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log |
119 | - error_log( sprintf( self::MESSAGE_TEMPLATE, self::$levels[ $level ], $this->class_name, is_array( $message ) ? implode( ', ', $message ) : $message ) ); |
|
119 | + error_log(sprintf(self::MESSAGE_TEMPLATE, self::$levels[$level], $this->class_name, is_array($message) ? implode(', ', $message) : $message)); |
|
120 | 120 | |
121 | 121 | } |
122 | 122 | |
123 | 123 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
124 | - public function error( $message, $exception = null ) { |
|
124 | + public function error($message, $exception = null) { |
|
125 | 125 | |
126 | - $this->log( self::ERROR, $message ); |
|
126 | + $this->log(self::ERROR, $message); |
|
127 | 127 | |
128 | 128 | } |
129 | 129 | |
130 | - public function warn( $message ) { |
|
130 | + public function warn($message) { |
|
131 | 131 | |
132 | - $this->log( self::WARN, $message ); |
|
132 | + $this->log(self::WARN, $message); |
|
133 | 133 | |
134 | 134 | } |
135 | 135 | |
136 | - public function info( $message ) { |
|
136 | + public function info($message) { |
|
137 | 137 | |
138 | - $this->log( self::INFO, $message ); |
|
138 | + $this->log(self::INFO, $message); |
|
139 | 139 | |
140 | 140 | } |
141 | 141 | |
142 | - public function debug( $message ) { |
|
142 | + public function debug($message) { |
|
143 | 143 | |
144 | - $this->log( self::DEBUG, $message ); |
|
144 | + $this->log(self::DEBUG, $message); |
|
145 | 145 | |
146 | 146 | } |
147 | 147 | |
148 | - public function trace( $message ) { |
|
148 | + public function trace($message) { |
|
149 | 149 | |
150 | - $this->log( self::TRACE, $message ); |
|
150 | + $this->log(self::TRACE, $message); |
|
151 | 151 | |
152 | 152 | } |
153 | 153 |