@@ -10,19 +10,19 @@ |
||
10 | 10 | */ |
11 | 11 | abstract class Edit_Post_Loader { |
12 | 12 | |
13 | - public function init() { |
|
13 | + public function init() { |
|
14 | 14 | |
15 | - add_action( 'admin_enqueue_scripts', array( $this, 'post_edit_screen' ) ); |
|
16 | - } |
|
15 | + add_action( 'admin_enqueue_scripts', array( $this, 'post_edit_screen' ) ); |
|
16 | + } |
|
17 | 17 | |
18 | - public function post_edit_screen( $hook ) { |
|
18 | + public function post_edit_screen( $hook ) { |
|
19 | 19 | |
20 | - if ( 'post.php' === $hook || 'post-new.php' === $hook ) { |
|
21 | - $this->run_on_edit_post_screen(); |
|
22 | - } |
|
20 | + if ( 'post.php' === $hook || 'post-new.php' === $hook ) { |
|
21 | + $this->run_on_edit_post_screen(); |
|
22 | + } |
|
23 | 23 | |
24 | - } |
|
24 | + } |
|
25 | 25 | |
26 | - abstract public function run_on_edit_post_screen(); |
|
26 | + abstract public function run_on_edit_post_screen(); |
|
27 | 27 | |
28 | 28 | } |
@@ -12,12 +12,12 @@ |
||
12 | 12 | |
13 | 13 | public function init() { |
14 | 14 | |
15 | - add_action( 'admin_enqueue_scripts', array( $this, 'post_edit_screen' ) ); |
|
15 | + add_action('admin_enqueue_scripts', array($this, 'post_edit_screen')); |
|
16 | 16 | } |
17 | 17 | |
18 | - public function post_edit_screen( $hook ) { |
|
18 | + public function post_edit_screen($hook) { |
|
19 | 19 | |
20 | - if ( 'post.php' === $hook || 'post-new.php' === $hook ) { |
|
20 | + if ('post.php' === $hook || 'post-new.php' === $hook) { |
|
21 | 21 | $this->run_on_edit_post_screen(); |
22 | 22 | } |
23 | 23 |
@@ -10,36 +10,36 @@ |
||
10 | 10 | */ |
11 | 11 | class Term_Checklist { |
12 | 12 | |
13 | - /** |
|
14 | - * @param $input_name string The name of the input field assigned to checkbox. |
|
15 | - * @param $terms array<\WP_Term> |
|
16 | - * @param $selected_term_slugs array<string> The list of selected term slugs. |
|
17 | - * |
|
18 | - * @return string Html string to be rendered. |
|
19 | - */ |
|
20 | - public static function render( $input_name, $terms, $selected_term_slugs ) { |
|
21 | - |
|
22 | - $terms_html = ''; |
|
23 | - |
|
24 | - $input_name = esc_html( $input_name ); |
|
25 | - |
|
26 | - foreach ( $terms as $term ) { |
|
27 | - |
|
28 | - /** |
|
29 | - * @var $term \WP_Term |
|
30 | - */ |
|
31 | - $term_name = esc_html( $term->name ); |
|
32 | - $checked = in_array( $term->slug, $selected_term_slugs, true ) ? 'checked' : ''; |
|
33 | - $terms_html .= "<li id=\"wl_entity_type-{$term->term_id}\"> |
|
13 | + /** |
|
14 | + * @param $input_name string The name of the input field assigned to checkbox. |
|
15 | + * @param $terms array<\WP_Term> |
|
16 | + * @param $selected_term_slugs array<string> The list of selected term slugs. |
|
17 | + * |
|
18 | + * @return string Html string to be rendered. |
|
19 | + */ |
|
20 | + public static function render( $input_name, $terms, $selected_term_slugs ) { |
|
21 | + |
|
22 | + $terms_html = ''; |
|
23 | + |
|
24 | + $input_name = esc_html( $input_name ); |
|
25 | + |
|
26 | + foreach ( $terms as $term ) { |
|
27 | + |
|
28 | + /** |
|
29 | + * @var $term \WP_Term |
|
30 | + */ |
|
31 | + $term_name = esc_html( $term->name ); |
|
32 | + $checked = in_array( $term->slug, $selected_term_slugs, true ) ? 'checked' : ''; |
|
33 | + $terms_html .= "<li id=\"wl_entity_type-{$term->term_id}\"> |
|
34 | 34 | <label class=\"selectit\"> |
35 | 35 | <input value=\"{$term->slug}\" type=\"checkbox\" name=\"{$input_name}[]\" id=\"in-wl_entity_type-{$term->term_id}\" $checked> |
36 | 36 | ${term_name} |
37 | 37 | </label> |
38 | 38 | </li>"; |
39 | 39 | |
40 | - } |
|
40 | + } |
|
41 | 41 | |
42 | - return '<input type="text" id="wl_entity_type_search" placeholder="Search Entity Types.." /><ul id="wl-entity-type__ul">' . $terms_html . '</ul>'; |
|
43 | - } |
|
42 | + return '<input type="text" id="wl_entity_type_search" placeholder="Search Entity Types.." /><ul id="wl-entity-type__ul">' . $terms_html . '</ul>'; |
|
43 | + } |
|
44 | 44 | |
45 | 45 | } |
@@ -17,19 +17,19 @@ discard block |
||
17 | 17 | * |
18 | 18 | * @return string Html string to be rendered. |
19 | 19 | */ |
20 | - public static function render( $input_name, $terms, $selected_term_slugs ) { |
|
20 | + public static function render($input_name, $terms, $selected_term_slugs) { |
|
21 | 21 | |
22 | 22 | $terms_html = ''; |
23 | 23 | |
24 | - $input_name = esc_html( $input_name ); |
|
24 | + $input_name = esc_html($input_name); |
|
25 | 25 | |
26 | - foreach ( $terms as $term ) { |
|
26 | + foreach ($terms as $term) { |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * @var $term \WP_Term |
30 | 30 | */ |
31 | - $term_name = esc_html( $term->name ); |
|
32 | - $checked = in_array( $term->slug, $selected_term_slugs, true ) ? 'checked' : ''; |
|
31 | + $term_name = esc_html($term->name); |
|
32 | + $checked = in_array($term->slug, $selected_term_slugs, true) ? 'checked' : ''; |
|
33 | 33 | $terms_html .= "<li id=\"wl_entity_type-{$term->term_id}\"> |
34 | 34 | <label class=\"selectit\"> |
35 | 35 | <input value=\"{$term->slug}\" type=\"checkbox\" name=\"{$input_name}[]\" id=\"in-wl_entity_type-{$term->term_id}\" $checked> |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | |
40 | 40 | } |
41 | 41 | |
42 | - return '<input type="text" id="wl_entity_type_search" placeholder="Search Entity Types.." /><ul id="wl-entity-type__ul">' . $terms_html . '</ul>'; |
|
42 | + return '<input type="text" id="wl_entity_type_search" placeholder="Search Entity Types.." /><ul id="wl-entity-type__ul">'.$terms_html.'</ul>'; |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | } |
@@ -3,201 +3,201 @@ |
||
3 | 3 | namespace Wordlift\Common\Background_Process; |
4 | 4 | |
5 | 5 | abstract class Background_Process extends \Wordlift_Plugin_WP_Background_Process { |
6 | - /** |
|
7 | - * @var \Wordlift_Log_Service |
|
8 | - */ |
|
9 | - private $log; |
|
10 | - /** |
|
11 | - * @var Data_Source |
|
12 | - */ |
|
13 | - protected $data_source; |
|
14 | - |
|
15 | - /** |
|
16 | - * Background_Process constructor. |
|
17 | - * |
|
18 | - * @param $data_source Data_Source |
|
19 | - */ |
|
20 | - public function __construct( $data_source ) { |
|
21 | - parent::__construct(); |
|
22 | - $this->data_source = $data_source; |
|
23 | - $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
24 | - // Set value for action key. |
|
25 | - $this->action = $this->get_action_key(); |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * The key which is used to store the Sync_State class for the current process |
|
30 | - * |
|
31 | - * @return string |
|
32 | - */ |
|
33 | - abstract protected function get_state_storage_key(); |
|
34 | - |
|
35 | - /** |
|
36 | - * The key which is used as prefix to store the options. |
|
37 | - * |
|
38 | - * @return string |
|
39 | - */ |
|
40 | - abstract protected function get_action_key(); |
|
41 | - |
|
42 | - /** |
|
43 | - * Check whether the process must cancel or not. |
|
44 | - * |
|
45 | - * @return bool Whether to cancel or not the process. |
|
46 | - */ |
|
47 | - private function must_cancel() { |
|
48 | - |
|
49 | - return get_transient( "{$this->action}__cancel" ); |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * Check whether the provided state is `started` or not. |
|
54 | - * |
|
55 | - * @param Sync_State $state The {@link Sync_State}. |
|
56 | - * |
|
57 | - * @return bool True if the state is started. |
|
58 | - */ |
|
59 | - private function is_started( $state ) { |
|
60 | - return $state instanceof Sync_State && 'started' === $state->state && 30 > ( time() - $state->last_update ); |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Start the background processing. |
|
65 | - * |
|
66 | - * @return bool True if the process has been started, otherwise false. |
|
67 | - */ |
|
68 | - public function start() { |
|
69 | - $action = $this->get_action_key(); |
|
70 | - $this->log->debug( "Trying to start ${action}..." ); |
|
71 | - // Create a new Sync_Model state of `started`. |
|
72 | - if ( ! $this->is_started( self::get_state() ) ) { |
|
73 | - $this->log->debug( 'Starting...' ); |
|
74 | - |
|
75 | - $sync_state = new Sync_State( time(), 0, $this->data_source->count(), time(), 'started' ); |
|
76 | - update_option( $this->get_state_storage_key(), $sync_state, false ); |
|
77 | - |
|
78 | - $next = $this->data_source->next(); |
|
79 | - |
|
80 | - $this->push_to_queue( $next ); |
|
81 | - $this->save()->dispatch(); |
|
82 | - |
|
83 | - if ( $next && is_array( $next ) ) { |
|
84 | - $this->log->debug( sprintf( 'Started with term IDs %s.', implode( ', ', $next ) ) ); |
|
85 | - } |
|
86 | - |
|
87 | - return true; |
|
88 | - } |
|
89 | - |
|
90 | - return false; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Cancels the current process. |
|
95 | - */ |
|
96 | - public function cancel() { |
|
97 | - |
|
98 | - $action = $this->action; |
|
99 | - $this->log->debug( "Cancelling ${action}..." ); |
|
100 | - |
|
101 | - // Cleanup the process data. |
|
102 | - $this->cancel_process(); |
|
103 | - |
|
104 | - // Set the state to cancelled. |
|
105 | - $state = $this->get_state(); |
|
106 | - $state->set_state( 'cancelled' ); |
|
107 | - update_option( $this->get_state_storage_key(), $state, false ); |
|
108 | - |
|
109 | - // Finally delete the transient. |
|
110 | - delete_transient( "{$this->action}__cancel" ); |
|
111 | - |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Get the sync state. |
|
116 | - * |
|
117 | - * @return Sync_State The {@link Sync_State}. |
|
118 | - */ |
|
119 | - public function get_state() { |
|
120 | - |
|
121 | - try { |
|
122 | - return get_option( $this->get_state_storage_key(), Sync_State::unknown() ); |
|
123 | - } catch ( \Exception $e ) { |
|
124 | - return Sync_State::unknown(); |
|
125 | - } |
|
126 | - |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * This function is called: |
|
131 | - * - To start a new Synchronization, by passing a {@link Sync_Start_Message} instance. |
|
132 | - * - To process a item, by passing a numeric ID. |
|
133 | - * |
|
134 | - * This function returns the parameter for the next call or NULL if there are no more items to process. |
|
135 | - * |
|
136 | - * @param int[] $items An array of item IDs. |
|
137 | - * |
|
138 | - * @return int[]|false The next IDs or false if there are no more. |
|
139 | - */ |
|
140 | - protected function task( $items ) { |
|
141 | - |
|
142 | - // Check if we must cancel. |
|
143 | - if ( $this->must_cancel() || ! $items ) { |
|
144 | - $this->log->debug( 'Cancelling background process ' . $this->action . ' due to no items inside task() method' ); |
|
145 | - $this->cancel(); |
|
146 | - |
|
147 | - return false; |
|
148 | - } |
|
149 | - |
|
150 | - if ( $items && is_array( $items ) ) { |
|
151 | - $this->log->debug( sprintf( 'Synchronizing items %s...', implode( ', ', $items ) ) ); |
|
152 | - } |
|
153 | - // Sync the item. |
|
154 | - if ( $this->process_items( $items ) ) { |
|
155 | - // Update the process state, set the index in state in order |
|
156 | - // to reflect the new items. |
|
157 | - $this->update_batch_index(); |
|
158 | - |
|
159 | - // Get the next batch for processing. |
|
160 | - return $this->get_next_batch(); |
|
161 | - } else { |
|
162 | - // Return the failed term ids again. |
|
163 | - return $items; |
|
164 | - } |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Process all the items in the current batch. |
|
169 | - * |
|
170 | - * @param $items |
|
171 | - * |
|
172 | - * @return bool If all items are successfully processed. |
|
173 | - */ |
|
174 | - abstract protected function process_items( $items ); |
|
175 | - |
|
176 | - /** |
|
177 | - * Return next batch of items after processing. |
|
178 | - * |
|
179 | - * @return int[] or false |
|
180 | - */ |
|
181 | - protected function get_next_batch() { |
|
182 | - return $this->data_source->next(); |
|
183 | - } |
|
184 | - |
|
185 | - private function update_batch_index() { |
|
186 | - $next = $this->data_source->next(); |
|
187 | - |
|
188 | - $next_state = isset( $next ) ? 'started' : 'ended'; |
|
189 | - |
|
190 | - /** |
|
191 | - * Update the synchronization meta data, by increasing the current index. |
|
192 | - * |
|
193 | - * @var Sync_State $sync The {@link Sync_State}. |
|
194 | - */ |
|
195 | - $state = self::get_state() |
|
196 | - ->increment_index( $this->data_source->get_batch_size() ) |
|
197 | - ->set_state( $next_state ); |
|
198 | - |
|
199 | - update_option( $this->get_state_storage_key(), $state, false ); |
|
200 | - |
|
201 | - } |
|
6 | + /** |
|
7 | + * @var \Wordlift_Log_Service |
|
8 | + */ |
|
9 | + private $log; |
|
10 | + /** |
|
11 | + * @var Data_Source |
|
12 | + */ |
|
13 | + protected $data_source; |
|
14 | + |
|
15 | + /** |
|
16 | + * Background_Process constructor. |
|
17 | + * |
|
18 | + * @param $data_source Data_Source |
|
19 | + */ |
|
20 | + public function __construct( $data_source ) { |
|
21 | + parent::__construct(); |
|
22 | + $this->data_source = $data_source; |
|
23 | + $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
24 | + // Set value for action key. |
|
25 | + $this->action = $this->get_action_key(); |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * The key which is used to store the Sync_State class for the current process |
|
30 | + * |
|
31 | + * @return string |
|
32 | + */ |
|
33 | + abstract protected function get_state_storage_key(); |
|
34 | + |
|
35 | + /** |
|
36 | + * The key which is used as prefix to store the options. |
|
37 | + * |
|
38 | + * @return string |
|
39 | + */ |
|
40 | + abstract protected function get_action_key(); |
|
41 | + |
|
42 | + /** |
|
43 | + * Check whether the process must cancel or not. |
|
44 | + * |
|
45 | + * @return bool Whether to cancel or not the process. |
|
46 | + */ |
|
47 | + private function must_cancel() { |
|
48 | + |
|
49 | + return get_transient( "{$this->action}__cancel" ); |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * Check whether the provided state is `started` or not. |
|
54 | + * |
|
55 | + * @param Sync_State $state The {@link Sync_State}. |
|
56 | + * |
|
57 | + * @return bool True if the state is started. |
|
58 | + */ |
|
59 | + private function is_started( $state ) { |
|
60 | + return $state instanceof Sync_State && 'started' === $state->state && 30 > ( time() - $state->last_update ); |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Start the background processing. |
|
65 | + * |
|
66 | + * @return bool True if the process has been started, otherwise false. |
|
67 | + */ |
|
68 | + public function start() { |
|
69 | + $action = $this->get_action_key(); |
|
70 | + $this->log->debug( "Trying to start ${action}..." ); |
|
71 | + // Create a new Sync_Model state of `started`. |
|
72 | + if ( ! $this->is_started( self::get_state() ) ) { |
|
73 | + $this->log->debug( 'Starting...' ); |
|
74 | + |
|
75 | + $sync_state = new Sync_State( time(), 0, $this->data_source->count(), time(), 'started' ); |
|
76 | + update_option( $this->get_state_storage_key(), $sync_state, false ); |
|
77 | + |
|
78 | + $next = $this->data_source->next(); |
|
79 | + |
|
80 | + $this->push_to_queue( $next ); |
|
81 | + $this->save()->dispatch(); |
|
82 | + |
|
83 | + if ( $next && is_array( $next ) ) { |
|
84 | + $this->log->debug( sprintf( 'Started with term IDs %s.', implode( ', ', $next ) ) ); |
|
85 | + } |
|
86 | + |
|
87 | + return true; |
|
88 | + } |
|
89 | + |
|
90 | + return false; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Cancels the current process. |
|
95 | + */ |
|
96 | + public function cancel() { |
|
97 | + |
|
98 | + $action = $this->action; |
|
99 | + $this->log->debug( "Cancelling ${action}..." ); |
|
100 | + |
|
101 | + // Cleanup the process data. |
|
102 | + $this->cancel_process(); |
|
103 | + |
|
104 | + // Set the state to cancelled. |
|
105 | + $state = $this->get_state(); |
|
106 | + $state->set_state( 'cancelled' ); |
|
107 | + update_option( $this->get_state_storage_key(), $state, false ); |
|
108 | + |
|
109 | + // Finally delete the transient. |
|
110 | + delete_transient( "{$this->action}__cancel" ); |
|
111 | + |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Get the sync state. |
|
116 | + * |
|
117 | + * @return Sync_State The {@link Sync_State}. |
|
118 | + */ |
|
119 | + public function get_state() { |
|
120 | + |
|
121 | + try { |
|
122 | + return get_option( $this->get_state_storage_key(), Sync_State::unknown() ); |
|
123 | + } catch ( \Exception $e ) { |
|
124 | + return Sync_State::unknown(); |
|
125 | + } |
|
126 | + |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * This function is called: |
|
131 | + * - To start a new Synchronization, by passing a {@link Sync_Start_Message} instance. |
|
132 | + * - To process a item, by passing a numeric ID. |
|
133 | + * |
|
134 | + * This function returns the parameter for the next call or NULL if there are no more items to process. |
|
135 | + * |
|
136 | + * @param int[] $items An array of item IDs. |
|
137 | + * |
|
138 | + * @return int[]|false The next IDs or false if there are no more. |
|
139 | + */ |
|
140 | + protected function task( $items ) { |
|
141 | + |
|
142 | + // Check if we must cancel. |
|
143 | + if ( $this->must_cancel() || ! $items ) { |
|
144 | + $this->log->debug( 'Cancelling background process ' . $this->action . ' due to no items inside task() method' ); |
|
145 | + $this->cancel(); |
|
146 | + |
|
147 | + return false; |
|
148 | + } |
|
149 | + |
|
150 | + if ( $items && is_array( $items ) ) { |
|
151 | + $this->log->debug( sprintf( 'Synchronizing items %s...', implode( ', ', $items ) ) ); |
|
152 | + } |
|
153 | + // Sync the item. |
|
154 | + if ( $this->process_items( $items ) ) { |
|
155 | + // Update the process state, set the index in state in order |
|
156 | + // to reflect the new items. |
|
157 | + $this->update_batch_index(); |
|
158 | + |
|
159 | + // Get the next batch for processing. |
|
160 | + return $this->get_next_batch(); |
|
161 | + } else { |
|
162 | + // Return the failed term ids again. |
|
163 | + return $items; |
|
164 | + } |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Process all the items in the current batch. |
|
169 | + * |
|
170 | + * @param $items |
|
171 | + * |
|
172 | + * @return bool If all items are successfully processed. |
|
173 | + */ |
|
174 | + abstract protected function process_items( $items ); |
|
175 | + |
|
176 | + /** |
|
177 | + * Return next batch of items after processing. |
|
178 | + * |
|
179 | + * @return int[] or false |
|
180 | + */ |
|
181 | + protected function get_next_batch() { |
|
182 | + return $this->data_source->next(); |
|
183 | + } |
|
184 | + |
|
185 | + private function update_batch_index() { |
|
186 | + $next = $this->data_source->next(); |
|
187 | + |
|
188 | + $next_state = isset( $next ) ? 'started' : 'ended'; |
|
189 | + |
|
190 | + /** |
|
191 | + * Update the synchronization meta data, by increasing the current index. |
|
192 | + * |
|
193 | + * @var Sync_State $sync The {@link Sync_State}. |
|
194 | + */ |
|
195 | + $state = self::get_state() |
|
196 | + ->increment_index( $this->data_source->get_batch_size() ) |
|
197 | + ->set_state( $next_state ); |
|
198 | + |
|
199 | + update_option( $this->get_state_storage_key(), $state, false ); |
|
200 | + |
|
201 | + } |
|
202 | 202 | |
203 | 203 | } |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | * |
18 | 18 | * @param $data_source Data_Source |
19 | 19 | */ |
20 | - public function __construct( $data_source ) { |
|
20 | + public function __construct($data_source) { |
|
21 | 21 | parent::__construct(); |
22 | 22 | $this->data_source = $data_source; |
23 | - $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
23 | + $this->log = \Wordlift_Log_Service::get_logger(get_class()); |
|
24 | 24 | // Set value for action key. |
25 | 25 | $this->action = $this->get_action_key(); |
26 | 26 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | private function must_cancel() { |
48 | 48 | |
49 | - return get_transient( "{$this->action}__cancel" ); |
|
49 | + return get_transient("{$this->action}__cancel"); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | * |
57 | 57 | * @return bool True if the state is started. |
58 | 58 | */ |
59 | - private function is_started( $state ) { |
|
60 | - return $state instanceof Sync_State && 'started' === $state->state && 30 > ( time() - $state->last_update ); |
|
59 | + private function is_started($state) { |
|
60 | + return $state instanceof Sync_State && 'started' === $state->state && 30 > (time() - $state->last_update); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -67,21 +67,21 @@ discard block |
||
67 | 67 | */ |
68 | 68 | public function start() { |
69 | 69 | $action = $this->get_action_key(); |
70 | - $this->log->debug( "Trying to start ${action}..." ); |
|
70 | + $this->log->debug("Trying to start ${action}..."); |
|
71 | 71 | // Create a new Sync_Model state of `started`. |
72 | - if ( ! $this->is_started( self::get_state() ) ) { |
|
73 | - $this->log->debug( 'Starting...' ); |
|
72 | + if ( ! $this->is_started(self::get_state())) { |
|
73 | + $this->log->debug('Starting...'); |
|
74 | 74 | |
75 | - $sync_state = new Sync_State( time(), 0, $this->data_source->count(), time(), 'started' ); |
|
76 | - update_option( $this->get_state_storage_key(), $sync_state, false ); |
|
75 | + $sync_state = new Sync_State(time(), 0, $this->data_source->count(), time(), 'started'); |
|
76 | + update_option($this->get_state_storage_key(), $sync_state, false); |
|
77 | 77 | |
78 | 78 | $next = $this->data_source->next(); |
79 | 79 | |
80 | - $this->push_to_queue( $next ); |
|
80 | + $this->push_to_queue($next); |
|
81 | 81 | $this->save()->dispatch(); |
82 | 82 | |
83 | - if ( $next && is_array( $next ) ) { |
|
84 | - $this->log->debug( sprintf( 'Started with term IDs %s.', implode( ', ', $next ) ) ); |
|
83 | + if ($next && is_array($next)) { |
|
84 | + $this->log->debug(sprintf('Started with term IDs %s.', implode(', ', $next))); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | return true; |
@@ -96,18 +96,18 @@ discard block |
||
96 | 96 | public function cancel() { |
97 | 97 | |
98 | 98 | $action = $this->action; |
99 | - $this->log->debug( "Cancelling ${action}..." ); |
|
99 | + $this->log->debug("Cancelling ${action}..."); |
|
100 | 100 | |
101 | 101 | // Cleanup the process data. |
102 | 102 | $this->cancel_process(); |
103 | 103 | |
104 | 104 | // Set the state to cancelled. |
105 | 105 | $state = $this->get_state(); |
106 | - $state->set_state( 'cancelled' ); |
|
107 | - update_option( $this->get_state_storage_key(), $state, false ); |
|
106 | + $state->set_state('cancelled'); |
|
107 | + update_option($this->get_state_storage_key(), $state, false); |
|
108 | 108 | |
109 | 109 | // Finally delete the transient. |
110 | - delete_transient( "{$this->action}__cancel" ); |
|
110 | + delete_transient("{$this->action}__cancel"); |
|
111 | 111 | |
112 | 112 | } |
113 | 113 | |
@@ -119,8 +119,8 @@ discard block |
||
119 | 119 | public function get_state() { |
120 | 120 | |
121 | 121 | try { |
122 | - return get_option( $this->get_state_storage_key(), Sync_State::unknown() ); |
|
123 | - } catch ( \Exception $e ) { |
|
122 | + return get_option($this->get_state_storage_key(), Sync_State::unknown()); |
|
123 | + } catch (\Exception $e) { |
|
124 | 124 | return Sync_State::unknown(); |
125 | 125 | } |
126 | 126 | |
@@ -137,21 +137,21 @@ discard block |
||
137 | 137 | * |
138 | 138 | * @return int[]|false The next IDs or false if there are no more. |
139 | 139 | */ |
140 | - protected function task( $items ) { |
|
140 | + protected function task($items) { |
|
141 | 141 | |
142 | 142 | // Check if we must cancel. |
143 | - if ( $this->must_cancel() || ! $items ) { |
|
144 | - $this->log->debug( 'Cancelling background process ' . $this->action . ' due to no items inside task() method' ); |
|
143 | + if ($this->must_cancel() || ! $items) { |
|
144 | + $this->log->debug('Cancelling background process '.$this->action.' due to no items inside task() method'); |
|
145 | 145 | $this->cancel(); |
146 | 146 | |
147 | 147 | return false; |
148 | 148 | } |
149 | 149 | |
150 | - if ( $items && is_array( $items ) ) { |
|
151 | - $this->log->debug( sprintf( 'Synchronizing items %s...', implode( ', ', $items ) ) ); |
|
150 | + if ($items && is_array($items)) { |
|
151 | + $this->log->debug(sprintf('Synchronizing items %s...', implode(', ', $items))); |
|
152 | 152 | } |
153 | 153 | // Sync the item. |
154 | - if ( $this->process_items( $items ) ) { |
|
154 | + if ($this->process_items($items)) { |
|
155 | 155 | // Update the process state, set the index in state in order |
156 | 156 | // to reflect the new items. |
157 | 157 | $this->update_batch_index(); |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | * |
172 | 172 | * @return bool If all items are successfully processed. |
173 | 173 | */ |
174 | - abstract protected function process_items( $items ); |
|
174 | + abstract protected function process_items($items); |
|
175 | 175 | |
176 | 176 | /** |
177 | 177 | * Return next batch of items after processing. |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | private function update_batch_index() { |
186 | 186 | $next = $this->data_source->next(); |
187 | 187 | |
188 | - $next_state = isset( $next ) ? 'started' : 'ended'; |
|
188 | + $next_state = isset($next) ? 'started' : 'ended'; |
|
189 | 189 | |
190 | 190 | /** |
191 | 191 | * Update the synchronization meta data, by increasing the current index. |
@@ -193,10 +193,10 @@ discard block |
||
193 | 193 | * @var Sync_State $sync The {@link Sync_State}. |
194 | 194 | */ |
195 | 195 | $state = self::get_state() |
196 | - ->increment_index( $this->data_source->get_batch_size() ) |
|
197 | - ->set_state( $next_state ); |
|
196 | + ->increment_index($this->data_source->get_batch_size()) |
|
197 | + ->set_state($next_state); |
|
198 | 198 | |
199 | - update_option( $this->get_state_storage_key(), $state, false ); |
|
199 | + update_option($this->get_state_storage_key(), $state, false); |
|
200 | 200 | |
201 | 201 | } |
202 | 202 |
@@ -9,11 +9,11 @@ |
||
9 | 9 | |
10 | 10 | interface Loader { |
11 | 11 | |
12 | - /** |
|
13 | - * The loader should register the feature to feature registry. |
|
14 | - * |
|
15 | - * @return void |
|
16 | - */ |
|
17 | - public function init_feature(); |
|
12 | + /** |
|
13 | + * The loader should register the feature to feature registry. |
|
14 | + * |
|
15 | + * @return void |
|
16 | + */ |
|
17 | + public function init_feature(); |
|
18 | 18 | |
19 | 19 | } |
@@ -9,32 +9,32 @@ discard block |
||
9 | 9 | */ |
10 | 10 | function wordlift_mce_css( $mce_css ) { |
11 | 11 | |
12 | - /* |
|
12 | + /* |
|
13 | 13 | * Call the `wl_can_see_classification_box` filter to determine whether we can display the classification box. |
14 | 14 | * |
15 | 15 | * @since 3.20.3 |
16 | 16 | * |
17 | 17 | * @see https://github.com/insideout10/wordlift-plugin/issues/914 |
18 | 18 | */ |
19 | - if ( ! apply_filters( 'wl_can_see_classification_box', true ) ) { |
|
20 | - return $mce_css; |
|
21 | - } |
|
22 | - |
|
23 | - if ( ! empty( $mce_css ) ) { |
|
24 | - $mce_css .= ','; |
|
25 | - } |
|
26 | - |
|
27 | - /** |
|
28 | - * Replacing the legacy `wordlift-reloaded.min.css` with tiny-mce.css. |
|
29 | - * |
|
30 | - * tiny-mce.css is generated using the new webpack project and its rules are shared with Gutenberg. |
|
31 | - * |
|
32 | - * @author David Riccitelli <[email protected]> |
|
33 | - * @since 3.23.0 |
|
34 | - */ |
|
35 | - $mce_css .= plugin_dir_url( __FILE__ ) . 'js/dist/tiny-mce.css'; |
|
36 | - |
|
37 | - return $mce_css; |
|
19 | + if ( ! apply_filters( 'wl_can_see_classification_box', true ) ) { |
|
20 | + return $mce_css; |
|
21 | + } |
|
22 | + |
|
23 | + if ( ! empty( $mce_css ) ) { |
|
24 | + $mce_css .= ','; |
|
25 | + } |
|
26 | + |
|
27 | + /** |
|
28 | + * Replacing the legacy `wordlift-reloaded.min.css` with tiny-mce.css. |
|
29 | + * |
|
30 | + * tiny-mce.css is generated using the new webpack project and its rules are shared with Gutenberg. |
|
31 | + * |
|
32 | + * @author David Riccitelli <[email protected]> |
|
33 | + * @since 3.23.0 |
|
34 | + */ |
|
35 | + $mce_css .= plugin_dir_url( __FILE__ ) . 'js/dist/tiny-mce.css'; |
|
36 | + |
|
37 | + return $mce_css; |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | // hook the TinyMCE custom styles function. |
@@ -49,13 +49,13 @@ discard block |
||
49 | 49 | */ |
50 | 50 | function wordlift_filter_tiny_mce_before_init( $options ) { |
51 | 51 | |
52 | - if ( ! isset( $options['extended_valid_elements'] ) ) { |
|
53 | - $options['extended_valid_elements'] = ''; |
|
54 | - } |
|
52 | + if ( ! isset( $options['extended_valid_elements'] ) ) { |
|
53 | + $options['extended_valid_elements'] = ''; |
|
54 | + } |
|
55 | 55 | |
56 | - $options['extended_valid_elements'] .= ',span[*]'; |
|
56 | + $options['extended_valid_elements'] .= ',span[*]'; |
|
57 | 57 | |
58 | - return $options; |
|
58 | + return $options; |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | add_filter( 'tiny_mce_before_init', 'wordlift_filter_tiny_mce_before_init', PHP_INT_MAX ); |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | * @return string The updated list of styles, including the custom style provided by WordLift. |
9 | 9 | */ |
10 | -function wordlift_mce_css( $mce_css ) { |
|
10 | +function wordlift_mce_css($mce_css) { |
|
11 | 11 | |
12 | 12 | /* |
13 | 13 | * Call the `wl_can_see_classification_box` filter to determine whether we can display the classification box. |
@@ -16,11 +16,11 @@ discard block |
||
16 | 16 | * |
17 | 17 | * @see https://github.com/insideout10/wordlift-plugin/issues/914 |
18 | 18 | */ |
19 | - if ( ! apply_filters( 'wl_can_see_classification_box', true ) ) { |
|
19 | + if ( ! apply_filters('wl_can_see_classification_box', true)) { |
|
20 | 20 | return $mce_css; |
21 | 21 | } |
22 | 22 | |
23 | - if ( ! empty( $mce_css ) ) { |
|
23 | + if ( ! empty($mce_css)) { |
|
24 | 24 | $mce_css .= ','; |
25 | 25 | } |
26 | 26 | |
@@ -32,13 +32,13 @@ discard block |
||
32 | 32 | * @author David Riccitelli <[email protected]> |
33 | 33 | * @since 3.23.0 |
34 | 34 | */ |
35 | - $mce_css .= plugin_dir_url( __FILE__ ) . 'js/dist/tiny-mce.css'; |
|
35 | + $mce_css .= plugin_dir_url(__FILE__).'js/dist/tiny-mce.css'; |
|
36 | 36 | |
37 | 37 | return $mce_css; |
38 | 38 | } |
39 | 39 | |
40 | 40 | // hook the TinyMCE custom styles function. |
41 | -add_filter( 'mce_css', 'wordlift_mce_css' ); |
|
41 | +add_filter('mce_css', 'wordlift_mce_css'); |
|
42 | 42 | |
43 | 43 | /** |
44 | 44 | * Set TinyMCE options, in particular enable microdata tagging. |
@@ -47,9 +47,9 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @return mixed |
49 | 49 | */ |
50 | -function wordlift_filter_tiny_mce_before_init( $options ) { |
|
50 | +function wordlift_filter_tiny_mce_before_init($options) { |
|
51 | 51 | |
52 | - if ( ! isset( $options['extended_valid_elements'] ) ) { |
|
52 | + if ( ! isset($options['extended_valid_elements'])) { |
|
53 | 53 | $options['extended_valid_elements'] = ''; |
54 | 54 | } |
55 | 55 | |
@@ -58,4 +58,4 @@ discard block |
||
58 | 58 | return $options; |
59 | 59 | } |
60 | 60 | |
61 | -add_filter( 'tiny_mce_before_init', 'wordlift_filter_tiny_mce_before_init', PHP_INT_MAX ); |
|
61 | +add_filter('tiny_mce_before_init', 'wordlift_filter_tiny_mce_before_init', PHP_INT_MAX); |
@@ -21,76 +21,76 @@ |
||
21 | 21 | */ |
22 | 22 | class Wordlift_AMP_Service { |
23 | 23 | |
24 | - /** |
|
25 | - * The {@link \Wordlift_Jsonld_Service} instance. |
|
26 | - * |
|
27 | - * @since 3.19.1 |
|
28 | - * @access private |
|
29 | - * @var \Wordlift_Jsonld_Service $jsonld_service The {@link \Wordlift_Jsonld_Service} instance. |
|
30 | - */ |
|
31 | - private $jsonld_service; |
|
24 | + /** |
|
25 | + * The {@link \Wordlift_Jsonld_Service} instance. |
|
26 | + * |
|
27 | + * @since 3.19.1 |
|
28 | + * @access private |
|
29 | + * @var \Wordlift_Jsonld_Service $jsonld_service The {@link \Wordlift_Jsonld_Service} instance. |
|
30 | + */ |
|
31 | + private $jsonld_service; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Create a {@link Wordlift_AMP_Service} instance. |
|
35 | - * |
|
36 | - * @since 3.19.1 |
|
37 | - * |
|
38 | - * @param \Wordlift_Jsonld_Service $jsonld_service |
|
39 | - */ |
|
40 | - public function __construct( $jsonld_service ) { |
|
33 | + /** |
|
34 | + * Create a {@link Wordlift_AMP_Service} instance. |
|
35 | + * |
|
36 | + * @since 3.19.1 |
|
37 | + * |
|
38 | + * @param \Wordlift_Jsonld_Service $jsonld_service |
|
39 | + */ |
|
40 | + public function __construct( $jsonld_service ) { |
|
41 | 41 | |
42 | - $this->jsonld_service = $jsonld_service; |
|
42 | + $this->jsonld_service = $jsonld_service; |
|
43 | 43 | |
44 | - add_action( 'amp_init', array( $this, 'register_entity_cpt_with_amp_plugin' ) ); |
|
45 | - add_filter( 'amp_post_template_metadata', array( $this, 'amp_post_template_metadata' ), 99, 2 ); |
|
44 | + add_action( 'amp_init', array( $this, 'register_entity_cpt_with_amp_plugin' ) ); |
|
45 | + add_filter( 'amp_post_template_metadata', array( $this, 'amp_post_template_metadata' ), 99, 2 ); |
|
46 | 46 | |
47 | - } |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Register the `entity` post type with the AMP plugin. |
|
51 | - * |
|
52 | - * @since 3.12.0 |
|
53 | - */ |
|
54 | - public function register_entity_cpt_with_amp_plugin() { |
|
49 | + /** |
|
50 | + * Register the `entity` post type with the AMP plugin. |
|
51 | + * |
|
52 | + * @since 3.12.0 |
|
53 | + */ |
|
54 | + public function register_entity_cpt_with_amp_plugin() { |
|
55 | 55 | |
56 | - if ( ! defined( 'AMP_QUERY_VAR' ) ) { |
|
57 | - return; |
|
58 | - } |
|
56 | + if ( ! defined( 'AMP_QUERY_VAR' ) ) { |
|
57 | + return; |
|
58 | + } |
|
59 | 59 | |
60 | - foreach ( Wordlift_Entity_Service::valid_entity_post_types() as $post_type ) { |
|
61 | - // Do not change anything for posts and pages. |
|
62 | - if ( 'post' === $post_type || 'page' === $post_type ) { |
|
63 | - continue; |
|
64 | - } |
|
65 | - add_post_type_support( $post_type, AMP_QUERY_VAR ); |
|
66 | - } |
|
60 | + foreach ( Wordlift_Entity_Service::valid_entity_post_types() as $post_type ) { |
|
61 | + // Do not change anything for posts and pages. |
|
62 | + if ( 'post' === $post_type || 'page' === $post_type ) { |
|
63 | + continue; |
|
64 | + } |
|
65 | + add_post_type_support( $post_type, AMP_QUERY_VAR ); |
|
66 | + } |
|
67 | 67 | |
68 | - } |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Filters Schema.org metadata for a post. |
|
72 | - * |
|
73 | - * @since 3.19.1 |
|
74 | - * |
|
75 | - * @param array $metadata Metadata. |
|
76 | - * @param WP_Post $post Post. |
|
77 | - * |
|
78 | - * @return array Return WordLift's generated JSON-LD. |
|
79 | - */ |
|
80 | - public function amp_post_template_metadata( $metadata, $post ) { |
|
70 | + /** |
|
71 | + * Filters Schema.org metadata for a post. |
|
72 | + * |
|
73 | + * @since 3.19.1 |
|
74 | + * |
|
75 | + * @param array $metadata Metadata. |
|
76 | + * @param WP_Post $post Post. |
|
77 | + * |
|
78 | + * @return array Return WordLift's generated JSON-LD. |
|
79 | + */ |
|
80 | + public function amp_post_template_metadata( $metadata, $post ) { |
|
81 | 81 | |
82 | - return $this->jsonld_service->get_jsonld( false, $post->ID ); |
|
83 | - } |
|
82 | + return $this->jsonld_service->get_jsonld( false, $post->ID ); |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * Check if current page is amp endpoint. |
|
87 | - * |
|
88 | - * @since 3.20.0 |
|
89 | - * |
|
90 | - * @return bool |
|
91 | - */ |
|
92 | - public static function is_amp_endpoint() { |
|
93 | - return function_exists( 'is_amp_endpoint' ) && is_amp_endpoint(); |
|
94 | - } |
|
85 | + /** |
|
86 | + * Check if current page is amp endpoint. |
|
87 | + * |
|
88 | + * @since 3.20.0 |
|
89 | + * |
|
90 | + * @return bool |
|
91 | + */ |
|
92 | + public static function is_amp_endpoint() { |
|
93 | + return function_exists( 'is_amp_endpoint' ) && is_amp_endpoint(); |
|
94 | + } |
|
95 | 95 | |
96 | 96 | } |
@@ -37,12 +37,12 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @param \Wordlift_Jsonld_Service $jsonld_service |
39 | 39 | */ |
40 | - public function __construct( $jsonld_service ) { |
|
40 | + public function __construct($jsonld_service) { |
|
41 | 41 | |
42 | 42 | $this->jsonld_service = $jsonld_service; |
43 | 43 | |
44 | - add_action( 'amp_init', array( $this, 'register_entity_cpt_with_amp_plugin' ) ); |
|
45 | - add_filter( 'amp_post_template_metadata', array( $this, 'amp_post_template_metadata' ), 99, 2 ); |
|
44 | + add_action('amp_init', array($this, 'register_entity_cpt_with_amp_plugin')); |
|
45 | + add_filter('amp_post_template_metadata', array($this, 'amp_post_template_metadata'), 99, 2); |
|
46 | 46 | |
47 | 47 | } |
48 | 48 | |
@@ -53,16 +53,16 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function register_entity_cpt_with_amp_plugin() { |
55 | 55 | |
56 | - if ( ! defined( 'AMP_QUERY_VAR' ) ) { |
|
56 | + if ( ! defined('AMP_QUERY_VAR')) { |
|
57 | 57 | return; |
58 | 58 | } |
59 | 59 | |
60 | - foreach ( Wordlift_Entity_Service::valid_entity_post_types() as $post_type ) { |
|
60 | + foreach (Wordlift_Entity_Service::valid_entity_post_types() as $post_type) { |
|
61 | 61 | // Do not change anything for posts and pages. |
62 | - if ( 'post' === $post_type || 'page' === $post_type ) { |
|
62 | + if ('post' === $post_type || 'page' === $post_type) { |
|
63 | 63 | continue; |
64 | 64 | } |
65 | - add_post_type_support( $post_type, AMP_QUERY_VAR ); |
|
65 | + add_post_type_support($post_type, AMP_QUERY_VAR); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | } |
@@ -77,9 +77,9 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @return array Return WordLift's generated JSON-LD. |
79 | 79 | */ |
80 | - public function amp_post_template_metadata( $metadata, $post ) { |
|
80 | + public function amp_post_template_metadata($metadata, $post) { |
|
81 | 81 | |
82 | - return $this->jsonld_service->get_jsonld( false, $post->ID ); |
|
82 | + return $this->jsonld_service->get_jsonld(false, $post->ID); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @return bool |
91 | 91 | */ |
92 | 92 | public static function is_amp_endpoint() { |
93 | - return function_exists( 'is_amp_endpoint' ) && is_amp_endpoint(); |
|
93 | + return function_exists('is_amp_endpoint') && is_amp_endpoint(); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | } |
@@ -17,116 +17,116 @@ |
||
17 | 17 | */ |
18 | 18 | class Wordlift_ShareThis_Service { |
19 | 19 | |
20 | - /** |
|
21 | - * The ShareThis function which prints the buttons. |
|
22 | - * |
|
23 | - * @since 3.2.0 |
|
24 | - */ |
|
25 | - const ADD_WIDGET_FUNCTION_NAME = 'st_add_widget'; |
|
26 | - |
|
27 | - /** |
|
28 | - * The Log service. |
|
29 | - * |
|
30 | - * @since 3.2.0 |
|
31 | - * @access private |
|
32 | - * @var \Wordlift_Log_Service $log_service The Log service. |
|
33 | - */ |
|
34 | - private $log_service; |
|
35 | - |
|
36 | - /** |
|
37 | - * Create an instance of the ShareThis service. |
|
38 | - * |
|
39 | - * @since 3.2.0 |
|
40 | - */ |
|
41 | - public function __construct() { |
|
42 | - |
|
43 | - $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_ShareThis_Service' ); |
|
44 | - |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Receive <em>the_content</em> filter calls from WordPress. |
|
49 | - * |
|
50 | - * @since 3.2.0 |
|
51 | - * |
|
52 | - * @param string $content The post content. |
|
53 | - * |
|
54 | - * @return string The updated post content. |
|
55 | - */ |
|
56 | - public function the_content( $content ) { |
|
57 | - |
|
58 | - return $this->call_sharethis( 'the_content', $content ); |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Receive <em>the_excerpt</em> filter calls from WordPress. |
|
63 | - * |
|
64 | - * @since 3.2.0 |
|
65 | - * |
|
66 | - * @param string $content The post excerpt. |
|
67 | - * |
|
68 | - * @return string The updated post excerpt. |
|
69 | - */ |
|
70 | - public function the_excerpt( $content ) { |
|
71 | - |
|
72 | - return $this->call_sharethis( 'the_excerpt', $content ); |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Call the ShareThis function. |
|
77 | - * |
|
78 | - * @since 3.2.0 |
|
79 | - * |
|
80 | - * @param string $tag The filter tag. |
|
81 | - * @param string $content The post content. |
|
82 | - * |
|
83 | - * @return string The updated post content. |
|
84 | - */ |
|
85 | - private function call_sharethis( $tag, $content ) { |
|
86 | - |
|
87 | - // Get the current post. |
|
88 | - global $post; |
|
89 | - |
|
90 | - // Bail out if the global $post instance isn't set. |
|
91 | - if ( ! isset( $post ) ) { |
|
92 | - return $content; |
|
93 | - } |
|
94 | - |
|
95 | - // Bail out if the current entity is a post/page since this is already handled by ShareThis. |
|
96 | - // |
|
97 | - // See https://github.com/insideout10/wordlift-plugin/issues/819 |
|
98 | - if ( 'post' === $post->post_type || 'page' === $post->post_type ) { |
|
99 | - return $content; |
|
100 | - } |
|
101 | - |
|
102 | - // If it's not the entity type, return. |
|
103 | - $entity_service = Wordlift_Entity_Service::get_instance(); |
|
104 | - if ( null === $post || ! $entity_service->is_entity( get_the_ID() ) ) { |
|
105 | - return $content; |
|
106 | - } |
|
107 | - |
|
108 | - // If the ShareThis function doesn't exist, return. |
|
109 | - if ( ! function_exists( self::ADD_WIDGET_FUNCTION_NAME ) ) { |
|
110 | - return $content; |
|
111 | - } |
|
112 | - |
|
113 | - // If ShareThis hasn't been added as a filter, return. |
|
114 | - if ( ! has_filter( $tag, self::ADD_WIDGET_FUNCTION_NAME ) ) { |
|
115 | - return $content; |
|
116 | - } |
|
117 | - |
|
118 | - // Temporary pop the post type and replace it with post. |
|
119 | - $post_type = $post->post_type; |
|
120 | - $post->post_type = 'post'; |
|
121 | - |
|
122 | - // Call ShareThis (disguised as a post). |
|
123 | - $content = call_user_func_array( self::ADD_WIDGET_FUNCTION_NAME, array( $content ) ); |
|
124 | - |
|
125 | - // Restore our post type. |
|
126 | - $post->post_type = $post_type; |
|
127 | - |
|
128 | - // Finally return the content. |
|
129 | - return $content; |
|
130 | - } |
|
20 | + /** |
|
21 | + * The ShareThis function which prints the buttons. |
|
22 | + * |
|
23 | + * @since 3.2.0 |
|
24 | + */ |
|
25 | + const ADD_WIDGET_FUNCTION_NAME = 'st_add_widget'; |
|
26 | + |
|
27 | + /** |
|
28 | + * The Log service. |
|
29 | + * |
|
30 | + * @since 3.2.0 |
|
31 | + * @access private |
|
32 | + * @var \Wordlift_Log_Service $log_service The Log service. |
|
33 | + */ |
|
34 | + private $log_service; |
|
35 | + |
|
36 | + /** |
|
37 | + * Create an instance of the ShareThis service. |
|
38 | + * |
|
39 | + * @since 3.2.0 |
|
40 | + */ |
|
41 | + public function __construct() { |
|
42 | + |
|
43 | + $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_ShareThis_Service' ); |
|
44 | + |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Receive <em>the_content</em> filter calls from WordPress. |
|
49 | + * |
|
50 | + * @since 3.2.0 |
|
51 | + * |
|
52 | + * @param string $content The post content. |
|
53 | + * |
|
54 | + * @return string The updated post content. |
|
55 | + */ |
|
56 | + public function the_content( $content ) { |
|
57 | + |
|
58 | + return $this->call_sharethis( 'the_content', $content ); |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Receive <em>the_excerpt</em> filter calls from WordPress. |
|
63 | + * |
|
64 | + * @since 3.2.0 |
|
65 | + * |
|
66 | + * @param string $content The post excerpt. |
|
67 | + * |
|
68 | + * @return string The updated post excerpt. |
|
69 | + */ |
|
70 | + public function the_excerpt( $content ) { |
|
71 | + |
|
72 | + return $this->call_sharethis( 'the_excerpt', $content ); |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Call the ShareThis function. |
|
77 | + * |
|
78 | + * @since 3.2.0 |
|
79 | + * |
|
80 | + * @param string $tag The filter tag. |
|
81 | + * @param string $content The post content. |
|
82 | + * |
|
83 | + * @return string The updated post content. |
|
84 | + */ |
|
85 | + private function call_sharethis( $tag, $content ) { |
|
86 | + |
|
87 | + // Get the current post. |
|
88 | + global $post; |
|
89 | + |
|
90 | + // Bail out if the global $post instance isn't set. |
|
91 | + if ( ! isset( $post ) ) { |
|
92 | + return $content; |
|
93 | + } |
|
94 | + |
|
95 | + // Bail out if the current entity is a post/page since this is already handled by ShareThis. |
|
96 | + // |
|
97 | + // See https://github.com/insideout10/wordlift-plugin/issues/819 |
|
98 | + if ( 'post' === $post->post_type || 'page' === $post->post_type ) { |
|
99 | + return $content; |
|
100 | + } |
|
101 | + |
|
102 | + // If it's not the entity type, return. |
|
103 | + $entity_service = Wordlift_Entity_Service::get_instance(); |
|
104 | + if ( null === $post || ! $entity_service->is_entity( get_the_ID() ) ) { |
|
105 | + return $content; |
|
106 | + } |
|
107 | + |
|
108 | + // If the ShareThis function doesn't exist, return. |
|
109 | + if ( ! function_exists( self::ADD_WIDGET_FUNCTION_NAME ) ) { |
|
110 | + return $content; |
|
111 | + } |
|
112 | + |
|
113 | + // If ShareThis hasn't been added as a filter, return. |
|
114 | + if ( ! has_filter( $tag, self::ADD_WIDGET_FUNCTION_NAME ) ) { |
|
115 | + return $content; |
|
116 | + } |
|
117 | + |
|
118 | + // Temporary pop the post type and replace it with post. |
|
119 | + $post_type = $post->post_type; |
|
120 | + $post->post_type = 'post'; |
|
121 | + |
|
122 | + // Call ShareThis (disguised as a post). |
|
123 | + $content = call_user_func_array( self::ADD_WIDGET_FUNCTION_NAME, array( $content ) ); |
|
124 | + |
|
125 | + // Restore our post type. |
|
126 | + $post->post_type = $post_type; |
|
127 | + |
|
128 | + // Finally return the content. |
|
129 | + return $content; |
|
130 | + } |
|
131 | 131 | |
132 | 132 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function __construct() { |
42 | 42 | |
43 | - $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_ShareThis_Service' ); |
|
43 | + $this->log_service = Wordlift_Log_Service::get_logger('Wordlift_ShareThis_Service'); |
|
44 | 44 | |
45 | 45 | } |
46 | 46 | |
@@ -53,9 +53,9 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @return string The updated post content. |
55 | 55 | */ |
56 | - public function the_content( $content ) { |
|
56 | + public function the_content($content) { |
|
57 | 57 | |
58 | - return $this->call_sharethis( 'the_content', $content ); |
|
58 | + return $this->call_sharethis('the_content', $content); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -67,9 +67,9 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @return string The updated post excerpt. |
69 | 69 | */ |
70 | - public function the_excerpt( $content ) { |
|
70 | + public function the_excerpt($content) { |
|
71 | 71 | |
72 | - return $this->call_sharethis( 'the_excerpt', $content ); |
|
72 | + return $this->call_sharethis('the_excerpt', $content); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -82,36 +82,36 @@ discard block |
||
82 | 82 | * |
83 | 83 | * @return string The updated post content. |
84 | 84 | */ |
85 | - private function call_sharethis( $tag, $content ) { |
|
85 | + private function call_sharethis($tag, $content) { |
|
86 | 86 | |
87 | 87 | // Get the current post. |
88 | 88 | global $post; |
89 | 89 | |
90 | 90 | // Bail out if the global $post instance isn't set. |
91 | - if ( ! isset( $post ) ) { |
|
91 | + if ( ! isset($post)) { |
|
92 | 92 | return $content; |
93 | 93 | } |
94 | 94 | |
95 | 95 | // Bail out if the current entity is a post/page since this is already handled by ShareThis. |
96 | 96 | // |
97 | 97 | // See https://github.com/insideout10/wordlift-plugin/issues/819 |
98 | - if ( 'post' === $post->post_type || 'page' === $post->post_type ) { |
|
98 | + if ('post' === $post->post_type || 'page' === $post->post_type) { |
|
99 | 99 | return $content; |
100 | 100 | } |
101 | 101 | |
102 | 102 | // If it's not the entity type, return. |
103 | 103 | $entity_service = Wordlift_Entity_Service::get_instance(); |
104 | - if ( null === $post || ! $entity_service->is_entity( get_the_ID() ) ) { |
|
104 | + if (null === $post || ! $entity_service->is_entity(get_the_ID())) { |
|
105 | 105 | return $content; |
106 | 106 | } |
107 | 107 | |
108 | 108 | // If the ShareThis function doesn't exist, return. |
109 | - if ( ! function_exists( self::ADD_WIDGET_FUNCTION_NAME ) ) { |
|
109 | + if ( ! function_exists(self::ADD_WIDGET_FUNCTION_NAME)) { |
|
110 | 110 | return $content; |
111 | 111 | } |
112 | 112 | |
113 | 113 | // If ShareThis hasn't been added as a filter, return. |
114 | - if ( ! has_filter( $tag, self::ADD_WIDGET_FUNCTION_NAME ) ) { |
|
114 | + if ( ! has_filter($tag, self::ADD_WIDGET_FUNCTION_NAME)) { |
|
115 | 115 | return $content; |
116 | 116 | } |
117 | 117 | |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | $post->post_type = 'post'; |
121 | 121 | |
122 | 122 | // Call ShareThis (disguised as a post). |
123 | - $content = call_user_func_array( self::ADD_WIDGET_FUNCTION_NAME, array( $content ) ); |
|
123 | + $content = call_user_func_array(self::ADD_WIDGET_FUNCTION_NAME, array($content)); |
|
124 | 124 | |
125 | 125 | // Restore our post type. |
126 | 126 | $post->post_type = $post_type; |
@@ -22,106 +22,106 @@ discard block |
||
22 | 22 | */ |
23 | 23 | class Wordlift_Public { |
24 | 24 | |
25 | - /** |
|
26 | - * The ID of this plugin. |
|
27 | - * |
|
28 | - * @since 1.0.0 |
|
29 | - * @access private |
|
30 | - * @var string $plugin_name The ID of this plugin. |
|
31 | - */ |
|
32 | - private $plugin_name; |
|
33 | - |
|
34 | - /** |
|
35 | - * The version of this plugin. |
|
36 | - * |
|
37 | - * @since 1.0.0 |
|
38 | - * @access private |
|
39 | - * @var string $version The current version of this plugin. |
|
40 | - */ |
|
41 | - private $version; |
|
42 | - |
|
43 | - /** |
|
44 | - * Initialize the class and set its properties. |
|
45 | - * |
|
46 | - * @param string $plugin_name The name of the plugin. |
|
47 | - * @param string $version The version of this plugin. |
|
48 | - * |
|
49 | - * @since 1.0.0 |
|
50 | - */ |
|
51 | - public function __construct( $plugin_name, $version ) { |
|
52 | - |
|
53 | - $this->plugin_name = $plugin_name; |
|
54 | - $this->version = $version; |
|
55 | - |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Register the stylesheets for the public-facing side of the site. |
|
60 | - * |
|
61 | - * @since 3.19.3 Register the `wordlift-ui` css. |
|
62 | - * @since 3.19.2 The call to this function is commented out in `class-wordlift.php` because `wordlift-public.css` |
|
63 | - * is empty. |
|
64 | - * @since 1.0.0 |
|
65 | - */ |
|
66 | - public function enqueue_styles() { |
|
67 | - |
|
68 | - /** |
|
69 | - * An instance of this class should be passed to the run() function |
|
70 | - * defined in Wordlift_Loader as all of the hooks are defined |
|
71 | - * in that particular class. |
|
72 | - * |
|
73 | - * The Wordlift_Loader will then create the relationship |
|
74 | - * between the defined hooks and the functions defined in this |
|
75 | - * class. |
|
76 | - */ |
|
77 | - |
|
78 | - /** |
|
79 | - * Add the `wordlift-font-awesome` unless some 3rd party sets the flag to false. |
|
80 | - * |
|
81 | - * @param bool $include Whether to include or not font-awesome (default true). |
|
82 | - * |
|
83 | - * @since 3.19.3 |
|
84 | - */ |
|
85 | - $deps = apply_filters( 'wl_include_font_awesome', true ) |
|
86 | - ? array( 'wordlift-font-awesome' ) |
|
87 | - : array(); |
|
88 | - wp_register_style( 'wordlift-font-awesome', plugin_dir_url( __DIR__ ) . 'css/wordlift-font-awesome' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', array(), $this->version, 'all' ); |
|
89 | - wp_register_style( 'wordlift-ui', plugin_dir_url( __DIR__ ) . 'css/wordlift-ui' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', $deps, $this->version, 'all' ); |
|
90 | - |
|
91 | - // You need to re-enable the enqueue_styles in `class-wordlift.php` to make this effective. |
|
92 | - // |
|
93 | - // @see https://github.com/insideout10/wordlift-plugin/issues/821 |
|
94 | - // |
|
95 | - // wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-public.css', array(), $this->version, 'all' ); |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Register the stylesheets for the public-facing side of the site. |
|
100 | - * |
|
101 | - * @since 1.0.0 |
|
102 | - */ |
|
103 | - public function enqueue_scripts() { |
|
104 | - |
|
105 | - /** |
|
106 | - * This function is provided for demonstration purposes only. |
|
107 | - * |
|
108 | - * An instance of this class should be passed to the run() function |
|
109 | - * defined in Wordlift_Loader as all of the hooks are defined |
|
110 | - * in that particular class. |
|
111 | - * |
|
112 | - * The Wordlift_Loader will then create the relationship |
|
113 | - * between the defined hooks and the functions defined in this |
|
114 | - * class. |
|
115 | - */ |
|
116 | - |
|
117 | - $settings = self::get_settings(); |
|
118 | - |
|
119 | - // Note that we switched the js to be loaded in footer, since it is loading |
|
120 | - // the json-ld representation. |
|
121 | - wp_enqueue_script( $this->plugin_name, self::get_public_js_url(), array(), $this->version, true ); |
|
122 | - wp_localize_script( $this->plugin_name, 'wlSettings', $settings ); |
|
123 | - |
|
124 | - /* |
|
25 | + /** |
|
26 | + * The ID of this plugin. |
|
27 | + * |
|
28 | + * @since 1.0.0 |
|
29 | + * @access private |
|
30 | + * @var string $plugin_name The ID of this plugin. |
|
31 | + */ |
|
32 | + private $plugin_name; |
|
33 | + |
|
34 | + /** |
|
35 | + * The version of this plugin. |
|
36 | + * |
|
37 | + * @since 1.0.0 |
|
38 | + * @access private |
|
39 | + * @var string $version The current version of this plugin. |
|
40 | + */ |
|
41 | + private $version; |
|
42 | + |
|
43 | + /** |
|
44 | + * Initialize the class and set its properties. |
|
45 | + * |
|
46 | + * @param string $plugin_name The name of the plugin. |
|
47 | + * @param string $version The version of this plugin. |
|
48 | + * |
|
49 | + * @since 1.0.0 |
|
50 | + */ |
|
51 | + public function __construct( $plugin_name, $version ) { |
|
52 | + |
|
53 | + $this->plugin_name = $plugin_name; |
|
54 | + $this->version = $version; |
|
55 | + |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Register the stylesheets for the public-facing side of the site. |
|
60 | + * |
|
61 | + * @since 3.19.3 Register the `wordlift-ui` css. |
|
62 | + * @since 3.19.2 The call to this function is commented out in `class-wordlift.php` because `wordlift-public.css` |
|
63 | + * is empty. |
|
64 | + * @since 1.0.0 |
|
65 | + */ |
|
66 | + public function enqueue_styles() { |
|
67 | + |
|
68 | + /** |
|
69 | + * An instance of this class should be passed to the run() function |
|
70 | + * defined in Wordlift_Loader as all of the hooks are defined |
|
71 | + * in that particular class. |
|
72 | + * |
|
73 | + * The Wordlift_Loader will then create the relationship |
|
74 | + * between the defined hooks and the functions defined in this |
|
75 | + * class. |
|
76 | + */ |
|
77 | + |
|
78 | + /** |
|
79 | + * Add the `wordlift-font-awesome` unless some 3rd party sets the flag to false. |
|
80 | + * |
|
81 | + * @param bool $include Whether to include or not font-awesome (default true). |
|
82 | + * |
|
83 | + * @since 3.19.3 |
|
84 | + */ |
|
85 | + $deps = apply_filters( 'wl_include_font_awesome', true ) |
|
86 | + ? array( 'wordlift-font-awesome' ) |
|
87 | + : array(); |
|
88 | + wp_register_style( 'wordlift-font-awesome', plugin_dir_url( __DIR__ ) . 'css/wordlift-font-awesome' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', array(), $this->version, 'all' ); |
|
89 | + wp_register_style( 'wordlift-ui', plugin_dir_url( __DIR__ ) . 'css/wordlift-ui' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', $deps, $this->version, 'all' ); |
|
90 | + |
|
91 | + // You need to re-enable the enqueue_styles in `class-wordlift.php` to make this effective. |
|
92 | + // |
|
93 | + // @see https://github.com/insideout10/wordlift-plugin/issues/821 |
|
94 | + // |
|
95 | + // wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-public.css', array(), $this->version, 'all' ); |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Register the stylesheets for the public-facing side of the site. |
|
100 | + * |
|
101 | + * @since 1.0.0 |
|
102 | + */ |
|
103 | + public function enqueue_scripts() { |
|
104 | + |
|
105 | + /** |
|
106 | + * This function is provided for demonstration purposes only. |
|
107 | + * |
|
108 | + * An instance of this class should be passed to the run() function |
|
109 | + * defined in Wordlift_Loader as all of the hooks are defined |
|
110 | + * in that particular class. |
|
111 | + * |
|
112 | + * The Wordlift_Loader will then create the relationship |
|
113 | + * between the defined hooks and the functions defined in this |
|
114 | + * class. |
|
115 | + */ |
|
116 | + |
|
117 | + $settings = self::get_settings(); |
|
118 | + |
|
119 | + // Note that we switched the js to be loaded in footer, since it is loading |
|
120 | + // the json-ld representation. |
|
121 | + wp_enqueue_script( $this->plugin_name, self::get_public_js_url(), array(), $this->version, true ); |
|
122 | + wp_localize_script( $this->plugin_name, 'wlSettings', $settings ); |
|
123 | + |
|
124 | + /* |
|
125 | 125 | * Add WordLift's version. |
126 | 126 | * Can be disabled via filter 'wl_disable_version_js' since 3.21.1 |
127 | 127 | * |
@@ -130,133 +130,133 @@ discard block |
||
130 | 130 | * @see https://github.com/insideout10/wordlift-plugin/issues/843. |
131 | 131 | * @see https://github.com/insideout10/wordlift-plugin/issues/926. |
132 | 132 | */ |
133 | - $show_version_default = false; |
|
134 | - $show_version = apply_filters( 'wl_disable_version_js', $show_version_default ); |
|
135 | - |
|
136 | - if ( $show_version ) { |
|
137 | - wp_localize_script( |
|
138 | - $this->plugin_name, |
|
139 | - 'wordlift', |
|
140 | - array( |
|
141 | - 'version' => $this->version, |
|
142 | - ) |
|
143 | - ); |
|
144 | - } |
|
145 | - |
|
146 | - /* |
|
133 | + $show_version_default = false; |
|
134 | + $show_version = apply_filters( 'wl_disable_version_js', $show_version_default ); |
|
135 | + |
|
136 | + if ( $show_version ) { |
|
137 | + wp_localize_script( |
|
138 | + $this->plugin_name, |
|
139 | + 'wordlift', |
|
140 | + array( |
|
141 | + 'version' => $this->version, |
|
142 | + ) |
|
143 | + ); |
|
144 | + } |
|
145 | + |
|
146 | + /* |
|
147 | 147 | * Register wordlift-cloud script which is shared by |
148 | 148 | * Navigator, Products Navigator, Faceted Search, Context Cards |
149 | 149 | * |
150 | 150 | * @since 3.22.0 |
151 | 151 | * |
152 | 152 | */ |
153 | - $deps = $this->wp_version_compare( '>=', '5.0' ) ? array( 'wp-hooks' ) : array(); |
|
153 | + $deps = $this->wp_version_compare( '>=', '5.0' ) ? array( 'wp-hooks' ) : array(); |
|
154 | 154 | |
155 | - /* |
|
155 | + /* |
|
156 | 156 | * Added defer to wordlift-cloud |
157 | 157 | * |
158 | 158 | * @since 3.27.4 |
159 | 159 | */ |
160 | - add_filter( |
|
161 | - 'script_loader_tag', |
|
162 | - function ( $tag, $handle ) { |
|
163 | - if ( 'wordlift-cloud' !== $handle ) { |
|
164 | - return $tag; |
|
165 | - } |
|
166 | - |
|
167 | - return str_replace( ' src', ' defer="defer" src', $tag ); |
|
168 | - }, |
|
169 | - 10, |
|
170 | - 2 |
|
171 | - ); |
|
172 | - wp_register_script( 'wordlift-cloud', self::get_cloud_js_url(), $deps, Wordlift::get_instance()->get_version(), true ); |
|
173 | - |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Get the settings array. |
|
178 | - * |
|
179 | - * @return array An array with the settings. |
|
180 | - * @since 3.19.1 |
|
181 | - */ |
|
182 | - public static function get_settings() { |
|
183 | - |
|
184 | - // Prepare a settings array for client-side functions. |
|
185 | - $settings = array( |
|
186 | - 'ajaxUrl' => admin_url( 'admin-ajax.php' ), |
|
187 | - 'apiUrl' => get_home_url( null, 'wl-api/' ), |
|
188 | - 'jsonld_url' => rest_url( '/wordlift/v1/jsonld/' ), |
|
189 | - ); |
|
190 | - |
|
191 | - // If we're in a single page, then print out the post id. |
|
192 | - if ( is_singular() ) { |
|
193 | - $settings['postId'] = get_the_ID(); |
|
194 | - } |
|
195 | - |
|
196 | - // Add flag that we are on home/blog page. |
|
197 | - if ( is_home() || is_front_page() ) { |
|
198 | - $settings['isHome'] = true; |
|
199 | - } |
|
200 | - |
|
201 | - // As of 2020-02-15, we publish the JSON-LD in the head, see Jsonld_Adaper. |
|
202 | - $settings['jsonld_enabled'] = false; |
|
203 | - |
|
204 | - // By default only enable JSON-LD on supported entity pages (includes |
|
205 | - // `page`, `post` and `entity` by default) and on the home page. |
|
206 | - // |
|
207 | - // @see https://github.com/insideout10/wordlift-plugin/issues/733 |
|
208 | - // $jsonld_enabled = is_home() || is_front_page() || Wordlift_Entity_Type_Service::is_valid_entity_post_type( get_post_type() ); |
|
209 | - |
|
210 | - // Add the JSON-LD enabled flag, when set to false, the JSON-LD won't |
|
211 | - // be loaded. |
|
212 | - // |
|
213 | - // @see https://github.com/insideout10/wordlift-plugin/issues/642. |
|
214 | - // $settings['jsonld_enabled'] = apply_filters( 'wl_jsonld_enabled', $jsonld_enabled ); |
|
215 | - |
|
216 | - return $settings; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Get the public JavaScript URL. |
|
221 | - * |
|
222 | - * Using this function is encouraged, since the public JavaScript is also used by the {@link Wordlift_WpRocket_Adapter} |
|
223 | - * in order to avoid breaking optimizations. |
|
224 | - * |
|
225 | - * @return string The URL to the public JavaScript. |
|
226 | - * @see https://github.com/insideout10/wordlift-plugin/issues/842. |
|
227 | - * |
|
228 | - * @since 3.19.4 |
|
229 | - */ |
|
230 | - public static function get_public_js_url() { |
|
231 | - |
|
232 | - return plugin_dir_url( __DIR__ ) . 'js/dist/bundle.js'; |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Get the Cloud JavaScript URL. |
|
237 | - * |
|
238 | - * @see https://github.com/insideout10/wordlift-plugin/issues/971 |
|
239 | - * @since 3.23.0 |
|
240 | - * @return string The URL to the Cloud JavaScript. |
|
241 | - */ |
|
242 | - public static function get_cloud_js_url() { |
|
243 | - |
|
244 | - return plugin_dir_url( __DIR__ ) . 'js/dist/wordlift-cloud.js'; |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * Helper function to check WP version |
|
249 | - * |
|
250 | - * @since 3.26.0 |
|
251 | - * |
|
252 | - * @param string $operator |
|
253 | - * @param string $version |
|
254 | - * |
|
255 | - * @return mixed |
|
256 | - */ |
|
257 | - private function wp_version_compare( $operator = '>', $version = '5.0' ) { |
|
258 | - global $wp_version; |
|
259 | - |
|
260 | - return version_compare( $wp_version, $version, $operator ); |
|
261 | - } |
|
160 | + add_filter( |
|
161 | + 'script_loader_tag', |
|
162 | + function ( $tag, $handle ) { |
|
163 | + if ( 'wordlift-cloud' !== $handle ) { |
|
164 | + return $tag; |
|
165 | + } |
|
166 | + |
|
167 | + return str_replace( ' src', ' defer="defer" src', $tag ); |
|
168 | + }, |
|
169 | + 10, |
|
170 | + 2 |
|
171 | + ); |
|
172 | + wp_register_script( 'wordlift-cloud', self::get_cloud_js_url(), $deps, Wordlift::get_instance()->get_version(), true ); |
|
173 | + |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Get the settings array. |
|
178 | + * |
|
179 | + * @return array An array with the settings. |
|
180 | + * @since 3.19.1 |
|
181 | + */ |
|
182 | + public static function get_settings() { |
|
183 | + |
|
184 | + // Prepare a settings array for client-side functions. |
|
185 | + $settings = array( |
|
186 | + 'ajaxUrl' => admin_url( 'admin-ajax.php' ), |
|
187 | + 'apiUrl' => get_home_url( null, 'wl-api/' ), |
|
188 | + 'jsonld_url' => rest_url( '/wordlift/v1/jsonld/' ), |
|
189 | + ); |
|
190 | + |
|
191 | + // If we're in a single page, then print out the post id. |
|
192 | + if ( is_singular() ) { |
|
193 | + $settings['postId'] = get_the_ID(); |
|
194 | + } |
|
195 | + |
|
196 | + // Add flag that we are on home/blog page. |
|
197 | + if ( is_home() || is_front_page() ) { |
|
198 | + $settings['isHome'] = true; |
|
199 | + } |
|
200 | + |
|
201 | + // As of 2020-02-15, we publish the JSON-LD in the head, see Jsonld_Adaper. |
|
202 | + $settings['jsonld_enabled'] = false; |
|
203 | + |
|
204 | + // By default only enable JSON-LD on supported entity pages (includes |
|
205 | + // `page`, `post` and `entity` by default) and on the home page. |
|
206 | + // |
|
207 | + // @see https://github.com/insideout10/wordlift-plugin/issues/733 |
|
208 | + // $jsonld_enabled = is_home() || is_front_page() || Wordlift_Entity_Type_Service::is_valid_entity_post_type( get_post_type() ); |
|
209 | + |
|
210 | + // Add the JSON-LD enabled flag, when set to false, the JSON-LD won't |
|
211 | + // be loaded. |
|
212 | + // |
|
213 | + // @see https://github.com/insideout10/wordlift-plugin/issues/642. |
|
214 | + // $settings['jsonld_enabled'] = apply_filters( 'wl_jsonld_enabled', $jsonld_enabled ); |
|
215 | + |
|
216 | + return $settings; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Get the public JavaScript URL. |
|
221 | + * |
|
222 | + * Using this function is encouraged, since the public JavaScript is also used by the {@link Wordlift_WpRocket_Adapter} |
|
223 | + * in order to avoid breaking optimizations. |
|
224 | + * |
|
225 | + * @return string The URL to the public JavaScript. |
|
226 | + * @see https://github.com/insideout10/wordlift-plugin/issues/842. |
|
227 | + * |
|
228 | + * @since 3.19.4 |
|
229 | + */ |
|
230 | + public static function get_public_js_url() { |
|
231 | + |
|
232 | + return plugin_dir_url( __DIR__ ) . 'js/dist/bundle.js'; |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Get the Cloud JavaScript URL. |
|
237 | + * |
|
238 | + * @see https://github.com/insideout10/wordlift-plugin/issues/971 |
|
239 | + * @since 3.23.0 |
|
240 | + * @return string The URL to the Cloud JavaScript. |
|
241 | + */ |
|
242 | + public static function get_cloud_js_url() { |
|
243 | + |
|
244 | + return plugin_dir_url( __DIR__ ) . 'js/dist/wordlift-cloud.js'; |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * Helper function to check WP version |
|
249 | + * |
|
250 | + * @since 3.26.0 |
|
251 | + * |
|
252 | + * @param string $operator |
|
253 | + * @param string $version |
|
254 | + * |
|
255 | + * @return mixed |
|
256 | + */ |
|
257 | + private function wp_version_compare( $operator = '>', $version = '5.0' ) { |
|
258 | + global $wp_version; |
|
259 | + |
|
260 | + return version_compare( $wp_version, $version, $operator ); |
|
261 | + } |
|
262 | 262 | } |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @since 1.0.0 |
50 | 50 | */ |
51 | - public function __construct( $plugin_name, $version ) { |
|
51 | + public function __construct($plugin_name, $version) { |
|
52 | 52 | |
53 | 53 | $this->plugin_name = $plugin_name; |
54 | 54 | $this->version = $version; |
@@ -82,11 +82,11 @@ discard block |
||
82 | 82 | * |
83 | 83 | * @since 3.19.3 |
84 | 84 | */ |
85 | - $deps = apply_filters( 'wl_include_font_awesome', true ) |
|
86 | - ? array( 'wordlift-font-awesome' ) |
|
85 | + $deps = apply_filters('wl_include_font_awesome', true) |
|
86 | + ? array('wordlift-font-awesome') |
|
87 | 87 | : array(); |
88 | - wp_register_style( 'wordlift-font-awesome', plugin_dir_url( __DIR__ ) . 'css/wordlift-font-awesome' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', array(), $this->version, 'all' ); |
|
89 | - wp_register_style( 'wordlift-ui', plugin_dir_url( __DIR__ ) . 'css/wordlift-ui' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', $deps, $this->version, 'all' ); |
|
88 | + wp_register_style('wordlift-font-awesome', plugin_dir_url(__DIR__).'css/wordlift-font-awesome'.( ! defined('SCRIPT_DEBUG') || ! SCRIPT_DEBUG ? '.min' : '').'.css', array(), $this->version, 'all'); |
|
89 | + wp_register_style('wordlift-ui', plugin_dir_url(__DIR__).'css/wordlift-ui'.( ! defined('SCRIPT_DEBUG') || ! SCRIPT_DEBUG ? '.min' : '').'.css', $deps, $this->version, 'all'); |
|
90 | 90 | |
91 | 91 | // You need to re-enable the enqueue_styles in `class-wordlift.php` to make this effective. |
92 | 92 | // |
@@ -118,8 +118,8 @@ discard block |
||
118 | 118 | |
119 | 119 | // Note that we switched the js to be loaded in footer, since it is loading |
120 | 120 | // the json-ld representation. |
121 | - wp_enqueue_script( $this->plugin_name, self::get_public_js_url(), array(), $this->version, true ); |
|
122 | - wp_localize_script( $this->plugin_name, 'wlSettings', $settings ); |
|
121 | + wp_enqueue_script($this->plugin_name, self::get_public_js_url(), array(), $this->version, true); |
|
122 | + wp_localize_script($this->plugin_name, 'wlSettings', $settings); |
|
123 | 123 | |
124 | 124 | /* |
125 | 125 | * Add WordLift's version. |
@@ -131,9 +131,9 @@ discard block |
||
131 | 131 | * @see https://github.com/insideout10/wordlift-plugin/issues/926. |
132 | 132 | */ |
133 | 133 | $show_version_default = false; |
134 | - $show_version = apply_filters( 'wl_disable_version_js', $show_version_default ); |
|
134 | + $show_version = apply_filters('wl_disable_version_js', $show_version_default); |
|
135 | 135 | |
136 | - if ( $show_version ) { |
|
136 | + if ($show_version) { |
|
137 | 137 | wp_localize_script( |
138 | 138 | $this->plugin_name, |
139 | 139 | 'wordlift', |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | * @since 3.22.0 |
151 | 151 | * |
152 | 152 | */ |
153 | - $deps = $this->wp_version_compare( '>=', '5.0' ) ? array( 'wp-hooks' ) : array(); |
|
153 | + $deps = $this->wp_version_compare('>=', '5.0') ? array('wp-hooks') : array(); |
|
154 | 154 | |
155 | 155 | /* |
156 | 156 | * Added defer to wordlift-cloud |
@@ -159,17 +159,17 @@ discard block |
||
159 | 159 | */ |
160 | 160 | add_filter( |
161 | 161 | 'script_loader_tag', |
162 | - function ( $tag, $handle ) { |
|
163 | - if ( 'wordlift-cloud' !== $handle ) { |
|
162 | + function($tag, $handle) { |
|
163 | + if ('wordlift-cloud' !== $handle) { |
|
164 | 164 | return $tag; |
165 | 165 | } |
166 | 166 | |
167 | - return str_replace( ' src', ' defer="defer" src', $tag ); |
|
167 | + return str_replace(' src', ' defer="defer" src', $tag); |
|
168 | 168 | }, |
169 | 169 | 10, |
170 | 170 | 2 |
171 | 171 | ); |
172 | - wp_register_script( 'wordlift-cloud', self::get_cloud_js_url(), $deps, Wordlift::get_instance()->get_version(), true ); |
|
172 | + wp_register_script('wordlift-cloud', self::get_cloud_js_url(), $deps, Wordlift::get_instance()->get_version(), true); |
|
173 | 173 | |
174 | 174 | } |
175 | 175 | |
@@ -183,18 +183,18 @@ discard block |
||
183 | 183 | |
184 | 184 | // Prepare a settings array for client-side functions. |
185 | 185 | $settings = array( |
186 | - 'ajaxUrl' => admin_url( 'admin-ajax.php' ), |
|
187 | - 'apiUrl' => get_home_url( null, 'wl-api/' ), |
|
188 | - 'jsonld_url' => rest_url( '/wordlift/v1/jsonld/' ), |
|
186 | + 'ajaxUrl' => admin_url('admin-ajax.php'), |
|
187 | + 'apiUrl' => get_home_url(null, 'wl-api/'), |
|
188 | + 'jsonld_url' => rest_url('/wordlift/v1/jsonld/'), |
|
189 | 189 | ); |
190 | 190 | |
191 | 191 | // If we're in a single page, then print out the post id. |
192 | - if ( is_singular() ) { |
|
192 | + if (is_singular()) { |
|
193 | 193 | $settings['postId'] = get_the_ID(); |
194 | 194 | } |
195 | 195 | |
196 | 196 | // Add flag that we are on home/blog page. |
197 | - if ( is_home() || is_front_page() ) { |
|
197 | + if (is_home() || is_front_page()) { |
|
198 | 198 | $settings['isHome'] = true; |
199 | 199 | } |
200 | 200 | |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | */ |
230 | 230 | public static function get_public_js_url() { |
231 | 231 | |
232 | - return plugin_dir_url( __DIR__ ) . 'js/dist/bundle.js'; |
|
232 | + return plugin_dir_url(__DIR__).'js/dist/bundle.js'; |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | /** |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | */ |
242 | 242 | public static function get_cloud_js_url() { |
243 | 243 | |
244 | - return plugin_dir_url( __DIR__ ) . 'js/dist/wordlift-cloud.js'; |
|
244 | + return plugin_dir_url(__DIR__).'js/dist/wordlift-cloud.js'; |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
@@ -254,9 +254,9 @@ discard block |
||
254 | 254 | * |
255 | 255 | * @return mixed |
256 | 256 | */ |
257 | - private function wp_version_compare( $operator = '>', $version = '5.0' ) { |
|
257 | + private function wp_version_compare($operator = '>', $version = '5.0') { |
|
258 | 258 | global $wp_version; |
259 | 259 | |
260 | - return version_compare( $wp_version, $version, $operator ); |
|
260 | + return version_compare($wp_version, $version, $operator); |
|
261 | 261 | } |
262 | 262 | } |
@@ -17,134 +17,134 @@ discard block |
||
17 | 17 | */ |
18 | 18 | class Wordlift_Navigator_Shortcode extends Wordlift_Shortcode { |
19 | 19 | |
20 | - /** |
|
21 | - * {@inheritdoc} |
|
22 | - */ |
|
23 | - const SHORTCODE = 'wl_navigator'; |
|
20 | + /** |
|
21 | + * {@inheritdoc} |
|
22 | + */ |
|
23 | + const SHORTCODE = 'wl_navigator'; |
|
24 | 24 | |
25 | - public function __construct() { |
|
26 | - parent::__construct(); |
|
27 | - $this->register_block_type(); |
|
28 | - } |
|
25 | + public function __construct() { |
|
26 | + parent::__construct(); |
|
27 | + $this->register_block_type(); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - public function render( $atts ) { |
|
34 | - return Wordlift_AMP_Service::is_amp_endpoint() ? $this->amp_shortcode( $atts ) |
|
35 | - : $this->web_shortcode( $atts ); |
|
36 | - } |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + public function render( $atts ) { |
|
34 | + return Wordlift_AMP_Service::is_amp_endpoint() ? $this->amp_shortcode( $atts ) |
|
35 | + : $this->web_shortcode( $atts ); |
|
36 | + } |
|
37 | 37 | |
38 | - private function register_block_type() { |
|
38 | + private function register_block_type() { |
|
39 | 39 | |
40 | - $scope = $this; |
|
40 | + $scope = $this; |
|
41 | 41 | |
42 | - add_action( |
|
43 | - 'init', |
|
44 | - function () use ( $scope ) { |
|
45 | - if ( ! function_exists( 'register_block_type' ) ) { |
|
46 | - // Gutenberg is not active. |
|
47 | - return; |
|
48 | - } |
|
42 | + add_action( |
|
43 | + 'init', |
|
44 | + function () use ( $scope ) { |
|
45 | + if ( ! function_exists( 'register_block_type' ) ) { |
|
46 | + // Gutenberg is not active. |
|
47 | + return; |
|
48 | + } |
|
49 | 49 | |
50 | - register_block_type( |
|
51 | - 'wordlift/navigator', |
|
52 | - array( |
|
53 | - 'editor_script' => 'wl-block-editor', |
|
54 | - 'render_callback' => function ( $attributes ) use ( $scope ) { |
|
55 | - $attr_code = ''; |
|
56 | - foreach ( $attributes as $key => $value ) { |
|
57 | - $attr_code .= $key . '="' . htmlentities( $value ) . '" '; |
|
58 | - } |
|
50 | + register_block_type( |
|
51 | + 'wordlift/navigator', |
|
52 | + array( |
|
53 | + 'editor_script' => 'wl-block-editor', |
|
54 | + 'render_callback' => function ( $attributes ) use ( $scope ) { |
|
55 | + $attr_code = ''; |
|
56 | + foreach ( $attributes as $key => $value ) { |
|
57 | + $attr_code .= $key . '="' . htmlentities( $value ) . '" '; |
|
58 | + } |
|
59 | 59 | |
60 | - return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']'; |
|
61 | - }, |
|
62 | - 'attributes' => $scope->get_navigator_block_attributes(), |
|
63 | - ) |
|
64 | - ); |
|
65 | - } |
|
66 | - ); |
|
67 | - } |
|
60 | + return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']'; |
|
61 | + }, |
|
62 | + 'attributes' => $scope->get_navigator_block_attributes(), |
|
63 | + ) |
|
64 | + ); |
|
65 | + } |
|
66 | + ); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * Shared function used by web_shortcode and amp_shortcode |
|
71 | - * Bootstrap logic for attributes extraction and boolean filtering |
|
72 | - * |
|
73 | - * @param array $atts Shortcode attributes. |
|
74 | - * |
|
75 | - * @return array $shortcode_atts |
|
76 | - * @since 3.20.0 |
|
77 | - */ |
|
78 | - private function make_shortcode_atts( $atts ) { |
|
69 | + /** |
|
70 | + * Shared function used by web_shortcode and amp_shortcode |
|
71 | + * Bootstrap logic for attributes extraction and boolean filtering |
|
72 | + * |
|
73 | + * @param array $atts Shortcode attributes. |
|
74 | + * |
|
75 | + * @return array $shortcode_atts |
|
76 | + * @since 3.20.0 |
|
77 | + */ |
|
78 | + private function make_shortcode_atts( $atts ) { |
|
79 | 79 | |
80 | - // Extract attributes and set default values. |
|
81 | - $shortcode_atts = shortcode_atts( |
|
82 | - array( |
|
83 | - 'title' => __( 'Related articles', 'wordlift' ), |
|
84 | - 'limit' => 4, |
|
85 | - 'offset' => 0, |
|
86 | - 'template_id' => '', |
|
87 | - 'post_id' => '', |
|
88 | - 'uniqid' => uniqid( 'wl-navigator-widget-' ), |
|
89 | - 'order_by' => 'ID DESC', |
|
90 | - 'post_types' => '', |
|
91 | - ), |
|
92 | - $atts |
|
93 | - ); |
|
80 | + // Extract attributes and set default values. |
|
81 | + $shortcode_atts = shortcode_atts( |
|
82 | + array( |
|
83 | + 'title' => __( 'Related articles', 'wordlift' ), |
|
84 | + 'limit' => 4, |
|
85 | + 'offset' => 0, |
|
86 | + 'template_id' => '', |
|
87 | + 'post_id' => '', |
|
88 | + 'uniqid' => uniqid( 'wl-navigator-widget-' ), |
|
89 | + 'order_by' => 'ID DESC', |
|
90 | + 'post_types' => '', |
|
91 | + ), |
|
92 | + $atts |
|
93 | + ); |
|
94 | 94 | |
95 | - return $shortcode_atts; |
|
96 | - } |
|
95 | + return $shortcode_atts; |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * Function in charge of displaying the [wl-navigator] in web mode. |
|
100 | - * |
|
101 | - * @param array $atts Shortcode attributes. |
|
102 | - * |
|
103 | - * @return string Shortcode HTML for web |
|
104 | - * @since 3.20.0 |
|
105 | - */ |
|
106 | - private function web_shortcode( $atts ) { |
|
98 | + /** |
|
99 | + * Function in charge of displaying the [wl-navigator] in web mode. |
|
100 | + * |
|
101 | + * @param array $atts Shortcode attributes. |
|
102 | + * |
|
103 | + * @return string Shortcode HTML for web |
|
104 | + * @since 3.20.0 |
|
105 | + */ |
|
106 | + private function web_shortcode( $atts ) { |
|
107 | 107 | |
108 | - // attributes extraction and boolean filtering |
|
109 | - $shortcode_atts = $this->make_shortcode_atts( $atts ); |
|
108 | + // attributes extraction and boolean filtering |
|
109 | + $shortcode_atts = $this->make_shortcode_atts( $atts ); |
|
110 | 110 | |
111 | - // avoid building the widget when no post_id is specified and there is a list of posts. |
|
112 | - if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) { |
|
113 | - return; |
|
114 | - } |
|
111 | + // avoid building the widget when no post_id is specified and there is a list of posts. |
|
112 | + if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) { |
|
113 | + return; |
|
114 | + } |
|
115 | 115 | |
116 | - $post = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( $shortcode_atts['post_id'] ) ) : get_post(); |
|
117 | - $title = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) ); |
|
118 | - $template_id = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) ); |
|
119 | - $limit = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) ); |
|
120 | - $offset = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) ); |
|
121 | - $sort = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) ); |
|
122 | - $navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-navigator-widget-' ); |
|
116 | + $post = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( $shortcode_atts['post_id'] ) ) : get_post(); |
|
117 | + $title = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) ); |
|
118 | + $template_id = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) ); |
|
119 | + $limit = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) ); |
|
120 | + $offset = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) ); |
|
121 | + $sort = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) ); |
|
122 | + $navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-navigator-widget-' ); |
|
123 | 123 | |
124 | - $rest_url = $post ? admin_url( |
|
125 | - 'admin-ajax.php?' . build_query( |
|
126 | - array( |
|
127 | - 'action' => 'wl_navigator', |
|
128 | - 'uniqid' => $navigator_id, |
|
129 | - 'post_id' => $post->ID, |
|
130 | - 'limit' => $limit, |
|
131 | - 'offset' => $offset, |
|
132 | - 'sort' => $sort, |
|
133 | - 'post_types' => $shortcode_atts['post_types'], |
|
134 | - '_wpnonce' => wp_create_nonce( 'wl_navigator' ), |
|
135 | - ) |
|
136 | - ) |
|
137 | - ) : false; |
|
124 | + $rest_url = $post ? admin_url( |
|
125 | + 'admin-ajax.php?' . build_query( |
|
126 | + array( |
|
127 | + 'action' => 'wl_navigator', |
|
128 | + 'uniqid' => $navigator_id, |
|
129 | + 'post_id' => $post->ID, |
|
130 | + 'limit' => $limit, |
|
131 | + 'offset' => $offset, |
|
132 | + 'sort' => $sort, |
|
133 | + 'post_types' => $shortcode_atts['post_types'], |
|
134 | + '_wpnonce' => wp_create_nonce( 'wl_navigator' ), |
|
135 | + ) |
|
136 | + ) |
|
137 | + ) : false; |
|
138 | 138 | |
139 | - // avoid building the widget when no valid $rest_url |
|
140 | - if ( ! $rest_url ) { |
|
141 | - return; |
|
142 | - } |
|
139 | + // avoid building the widget when no valid $rest_url |
|
140 | + if ( ! $rest_url ) { |
|
141 | + return; |
|
142 | + } |
|
143 | 143 | |
144 | - wp_enqueue_script( 'wordlift-cloud' ); |
|
145 | - $template_url = get_rest_url( null, '/wordlift/v1/navigator/template' ); |
|
144 | + wp_enqueue_script( 'wordlift-cloud' ); |
|
145 | + $template_url = get_rest_url( null, '/wordlift/v1/navigator/template' ); |
|
146 | 146 | |
147 | - return <<<HTML |
|
147 | + return <<<HTML |
|
148 | 148 | <!-- Navigator {$navigator_id} --> |
149 | 149 | <div id="{$navigator_id}" |
150 | 150 | class="wl-navigator" |
@@ -155,63 +155,63 @@ discard block |
||
155 | 155 | data-limit="{$limit}"></div> |
156 | 156 | <!-- /Navigator {$navigator_id} --> |
157 | 157 | HTML; |
158 | - } |
|
158 | + } |
|
159 | 159 | |
160 | - /** |
|
161 | - * Function in charge of diplaying the [wl-faceted-search] in amp mode. |
|
162 | - * |
|
163 | - * @param array $atts Shortcode attributes. |
|
164 | - * |
|
165 | - * @return string Shortcode HTML for amp |
|
166 | - * @since 3.20.0 |
|
167 | - */ |
|
168 | - private function amp_shortcode( $atts ) { |
|
169 | - // attributes extraction and boolean filtering |
|
170 | - $shortcode_atts = $this->make_shortcode_atts( $atts ); |
|
160 | + /** |
|
161 | + * Function in charge of diplaying the [wl-faceted-search] in amp mode. |
|
162 | + * |
|
163 | + * @param array $atts Shortcode attributes. |
|
164 | + * |
|
165 | + * @return string Shortcode HTML for amp |
|
166 | + * @since 3.20.0 |
|
167 | + */ |
|
168 | + private function amp_shortcode( $atts ) { |
|
169 | + // attributes extraction and boolean filtering |
|
170 | + $shortcode_atts = $this->make_shortcode_atts( $atts ); |
|
171 | 171 | |
172 | - // avoid building the widget when no post_id is specified and there is a list of posts. |
|
173 | - if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) { |
|
174 | - return; |
|
175 | - } |
|
172 | + // avoid building the widget when no post_id is specified and there is a list of posts. |
|
173 | + if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) { |
|
174 | + return; |
|
175 | + } |
|
176 | 176 | |
177 | - $post = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( $shortcode_atts['post_id'] ) ) : get_post(); |
|
178 | - $title = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) ); |
|
179 | - $template_id = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) ); |
|
180 | - $limit = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) ); |
|
181 | - $offset = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) ); |
|
182 | - $sort = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) ); |
|
183 | - $navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-navigator-widget-' ); |
|
177 | + $post = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( $shortcode_atts['post_id'] ) ) : get_post(); |
|
178 | + $title = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) ); |
|
179 | + $template_id = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) ); |
|
180 | + $limit = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) ); |
|
181 | + $offset = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) ); |
|
182 | + $sort = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) ); |
|
183 | + $navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-navigator-widget-' ); |
|
184 | 184 | |
185 | - $permalink_structure = get_option( 'permalink_structure' ); |
|
186 | - $delimiter = empty( $permalink_structure ) ? '&' : '?'; |
|
187 | - $rest_url = $post ? rest_url( |
|
188 | - WL_REST_ROUTE_DEFAULT_NAMESPACE . '/navigator' . $delimiter . build_query( |
|
189 | - array( |
|
190 | - 'uniqid' => $navigator_id, |
|
191 | - 'post_id' => $post->ID, |
|
192 | - 'limit' => $limit, |
|
193 | - 'offset' => $offset, |
|
194 | - 'sort' => $sort, |
|
195 | - '_wpnonce' => wp_create_nonce( 'wl_navigator' ), |
|
196 | - ) |
|
197 | - ) |
|
198 | - ) : false; |
|
185 | + $permalink_structure = get_option( 'permalink_structure' ); |
|
186 | + $delimiter = empty( $permalink_structure ) ? '&' : '?'; |
|
187 | + $rest_url = $post ? rest_url( |
|
188 | + WL_REST_ROUTE_DEFAULT_NAMESPACE . '/navigator' . $delimiter . build_query( |
|
189 | + array( |
|
190 | + 'uniqid' => $navigator_id, |
|
191 | + 'post_id' => $post->ID, |
|
192 | + 'limit' => $limit, |
|
193 | + 'offset' => $offset, |
|
194 | + 'sort' => $sort, |
|
195 | + '_wpnonce' => wp_create_nonce( 'wl_navigator' ), |
|
196 | + ) |
|
197 | + ) |
|
198 | + ) : false; |
|
199 | 199 | |
200 | - // avoid building the widget when no valid $rest_url |
|
201 | - if ( ! $rest_url ) { |
|
202 | - return; |
|
203 | - } |
|
200 | + // avoid building the widget when no valid $rest_url |
|
201 | + if ( ! $rest_url ) { |
|
202 | + return; |
|
203 | + } |
|
204 | 204 | |
205 | - // Use a protocol-relative URL as amp-list spec says that URL's protocol must be HTTPS. |
|
206 | - // This is a hackish way, but this works for http and https URLs |
|
207 | - $rest_url = str_replace( array( 'http:', 'https:' ), '', $rest_url ); |
|
205 | + // Use a protocol-relative URL as amp-list spec says that URL's protocol must be HTTPS. |
|
206 | + // This is a hackish way, but this works for http and https URLs |
|
207 | + $rest_url = str_replace( array( 'http:', 'https:' ), '', $rest_url ); |
|
208 | 208 | |
209 | - if ( empty( $template_id ) ) { |
|
210 | - $template_id = 'template-' . $navigator_id; |
|
211 | - wp_enqueue_style( 'wordlift-amp-custom', plugin_dir_url( __DIR__ ) . '/css/wordlift-amp-custom.min.css', array(), WORDLIFT_VERSION ); |
|
212 | - } |
|
209 | + if ( empty( $template_id ) ) { |
|
210 | + $template_id = 'template-' . $navigator_id; |
|
211 | + wp_enqueue_style( 'wordlift-amp-custom', plugin_dir_url( __DIR__ ) . '/css/wordlift-amp-custom.min.css', array(), WORDLIFT_VERSION ); |
|
212 | + } |
|
213 | 213 | |
214 | - return <<<HTML |
|
214 | + return <<<HTML |
|
215 | 215 | <div id="{$navigator_id}" class="wl-amp-navigator" style="width: 100%"> |
216 | 216 | <h3 class="wl-headline">{$title}</h3> |
217 | 217 | <amp-list |
@@ -244,54 +244,54 @@ discard block |
||
244 | 244 | </div> |
245 | 245 | </template> |
246 | 246 | HTML; |
247 | - } |
|
247 | + } |
|
248 | 248 | |
249 | - /** |
|
250 | - * @return array |
|
251 | - */ |
|
252 | - public function get_navigator_block_attributes() { |
|
253 | - return array( |
|
254 | - 'title' => array( |
|
255 | - 'type' => 'string', |
|
256 | - 'default' => __( 'Related articles', 'wordlift' ), |
|
257 | - ), |
|
258 | - 'limit' => array( |
|
259 | - 'type' => 'number', |
|
260 | - 'default' => 4, |
|
261 | - ), |
|
262 | - 'template_id' => array( |
|
263 | - 'type' => 'string', |
|
264 | - 'default' => '', |
|
265 | - ), |
|
266 | - 'post_id' => array( |
|
267 | - 'type' => 'number', |
|
268 | - 'default' => '', |
|
269 | - ), |
|
270 | - 'offset' => array( |
|
271 | - 'type' => 'number', |
|
272 | - 'default' => 0, |
|
273 | - ), |
|
274 | - 'uniqid' => array( |
|
275 | - 'type' => 'string', |
|
276 | - 'default' => '', |
|
277 | - ), |
|
278 | - 'order_by' => array( |
|
279 | - 'type' => 'string', |
|
280 | - 'default' => 'ID DESC', |
|
281 | - ), |
|
282 | - 'preview' => array( |
|
283 | - 'type' => 'boolean', |
|
284 | - 'default' => false, |
|
285 | - ), |
|
286 | - 'preview_src' => array( |
|
287 | - 'type' => 'string', |
|
288 | - 'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/navigator.png', |
|
289 | - ), |
|
290 | - 'post_types' => array( |
|
291 | - 'type' => 'string', |
|
292 | - 'default' => '', |
|
293 | - ), |
|
294 | - ); |
|
295 | - } |
|
249 | + /** |
|
250 | + * @return array |
|
251 | + */ |
|
252 | + public function get_navigator_block_attributes() { |
|
253 | + return array( |
|
254 | + 'title' => array( |
|
255 | + 'type' => 'string', |
|
256 | + 'default' => __( 'Related articles', 'wordlift' ), |
|
257 | + ), |
|
258 | + 'limit' => array( |
|
259 | + 'type' => 'number', |
|
260 | + 'default' => 4, |
|
261 | + ), |
|
262 | + 'template_id' => array( |
|
263 | + 'type' => 'string', |
|
264 | + 'default' => '', |
|
265 | + ), |
|
266 | + 'post_id' => array( |
|
267 | + 'type' => 'number', |
|
268 | + 'default' => '', |
|
269 | + ), |
|
270 | + 'offset' => array( |
|
271 | + 'type' => 'number', |
|
272 | + 'default' => 0, |
|
273 | + ), |
|
274 | + 'uniqid' => array( |
|
275 | + 'type' => 'string', |
|
276 | + 'default' => '', |
|
277 | + ), |
|
278 | + 'order_by' => array( |
|
279 | + 'type' => 'string', |
|
280 | + 'default' => 'ID DESC', |
|
281 | + ), |
|
282 | + 'preview' => array( |
|
283 | + 'type' => 'boolean', |
|
284 | + 'default' => false, |
|
285 | + ), |
|
286 | + 'preview_src' => array( |
|
287 | + 'type' => 'string', |
|
288 | + 'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/navigator.png', |
|
289 | + ), |
|
290 | + 'post_types' => array( |
|
291 | + 'type' => 'string', |
|
292 | + 'default' => '', |
|
293 | + ), |
|
294 | + ); |
|
295 | + } |
|
296 | 296 | |
297 | 297 | } |
@@ -30,9 +30,9 @@ discard block |
||
30 | 30 | /** |
31 | 31 | * {@inheritdoc} |
32 | 32 | */ |
33 | - public function render( $atts ) { |
|
34 | - return Wordlift_AMP_Service::is_amp_endpoint() ? $this->amp_shortcode( $atts ) |
|
35 | - : $this->web_shortcode( $atts ); |
|
33 | + public function render($atts) { |
|
34 | + return Wordlift_AMP_Service::is_amp_endpoint() ? $this->amp_shortcode($atts) |
|
35 | + : $this->web_shortcode($atts); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | private function register_block_type() { |
@@ -41,8 +41,8 @@ discard block |
||
41 | 41 | |
42 | 42 | add_action( |
43 | 43 | 'init', |
44 | - function () use ( $scope ) { |
|
45 | - if ( ! function_exists( 'register_block_type' ) ) { |
|
44 | + function() use ($scope) { |
|
45 | + if ( ! function_exists('register_block_type')) { |
|
46 | 46 | // Gutenberg is not active. |
47 | 47 | return; |
48 | 48 | } |
@@ -51,13 +51,13 @@ discard block |
||
51 | 51 | 'wordlift/navigator', |
52 | 52 | array( |
53 | 53 | 'editor_script' => 'wl-block-editor', |
54 | - 'render_callback' => function ( $attributes ) use ( $scope ) { |
|
54 | + 'render_callback' => function($attributes) use ($scope) { |
|
55 | 55 | $attr_code = ''; |
56 | - foreach ( $attributes as $key => $value ) { |
|
57 | - $attr_code .= $key . '="' . htmlentities( $value ) . '" '; |
|
56 | + foreach ($attributes as $key => $value) { |
|
57 | + $attr_code .= $key.'="'.htmlentities($value).'" '; |
|
58 | 58 | } |
59 | 59 | |
60 | - return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']'; |
|
60 | + return '['.$scope::SHORTCODE.' '.$attr_code.']'; |
|
61 | 61 | }, |
62 | 62 | 'attributes' => $scope->get_navigator_block_attributes(), |
63 | 63 | ) |
@@ -75,17 +75,17 @@ discard block |
||
75 | 75 | * @return array $shortcode_atts |
76 | 76 | * @since 3.20.0 |
77 | 77 | */ |
78 | - private function make_shortcode_atts( $atts ) { |
|
78 | + private function make_shortcode_atts($atts) { |
|
79 | 79 | |
80 | 80 | // Extract attributes and set default values. |
81 | 81 | $shortcode_atts = shortcode_atts( |
82 | 82 | array( |
83 | - 'title' => __( 'Related articles', 'wordlift' ), |
|
83 | + 'title' => __('Related articles', 'wordlift'), |
|
84 | 84 | 'limit' => 4, |
85 | 85 | 'offset' => 0, |
86 | 86 | 'template_id' => '', |
87 | 87 | 'post_id' => '', |
88 | - 'uniqid' => uniqid( 'wl-navigator-widget-' ), |
|
88 | + 'uniqid' => uniqid('wl-navigator-widget-'), |
|
89 | 89 | 'order_by' => 'ID DESC', |
90 | 90 | 'post_types' => '', |
91 | 91 | ), |
@@ -103,26 +103,26 @@ discard block |
||
103 | 103 | * @return string Shortcode HTML for web |
104 | 104 | * @since 3.20.0 |
105 | 105 | */ |
106 | - private function web_shortcode( $atts ) { |
|
106 | + private function web_shortcode($atts) { |
|
107 | 107 | |
108 | 108 | // attributes extraction and boolean filtering |
109 | - $shortcode_atts = $this->make_shortcode_atts( $atts ); |
|
109 | + $shortcode_atts = $this->make_shortcode_atts($atts); |
|
110 | 110 | |
111 | 111 | // avoid building the widget when no post_id is specified and there is a list of posts. |
112 | - if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) { |
|
112 | + if (empty($shortcode_atts['post_id']) && ! is_singular()) { |
|
113 | 113 | return; |
114 | 114 | } |
115 | 115 | |
116 | - $post = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( $shortcode_atts['post_id'] ) ) : get_post(); |
|
117 | - $title = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) ); |
|
118 | - $template_id = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) ); |
|
119 | - $limit = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) ); |
|
120 | - $offset = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) ); |
|
121 | - $sort = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) ); |
|
122 | - $navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-navigator-widget-' ); |
|
116 | + $post = ! empty($shortcode_atts['post_id']) ? get_post(intval($shortcode_atts['post_id'])) : get_post(); |
|
117 | + $title = esc_attr(sanitize_text_field($shortcode_atts['title'])); |
|
118 | + $template_id = esc_attr(sanitize_text_field($shortcode_atts['template_id'])); |
|
119 | + $limit = esc_attr(sanitize_text_field($shortcode_atts['limit'])); |
|
120 | + $offset = esc_attr(sanitize_text_field($shortcode_atts['offset'])); |
|
121 | + $sort = esc_attr(sanitize_sql_orderby(sanitize_text_field($shortcode_atts['order_by']))); |
|
122 | + $navigator_id = ! empty($shortcode_atts['uniqid']) ? esc_attr(sanitize_text_field($shortcode_atts['uniqid'])) : uniqid('wl-navigator-widget-'); |
|
123 | 123 | |
124 | 124 | $rest_url = $post ? admin_url( |
125 | - 'admin-ajax.php?' . build_query( |
|
125 | + 'admin-ajax.php?'.build_query( |
|
126 | 126 | array( |
127 | 127 | 'action' => 'wl_navigator', |
128 | 128 | 'uniqid' => $navigator_id, |
@@ -131,18 +131,18 @@ discard block |
||
131 | 131 | 'offset' => $offset, |
132 | 132 | 'sort' => $sort, |
133 | 133 | 'post_types' => $shortcode_atts['post_types'], |
134 | - '_wpnonce' => wp_create_nonce( 'wl_navigator' ), |
|
134 | + '_wpnonce' => wp_create_nonce('wl_navigator'), |
|
135 | 135 | ) |
136 | 136 | ) |
137 | 137 | ) : false; |
138 | 138 | |
139 | 139 | // avoid building the widget when no valid $rest_url |
140 | - if ( ! $rest_url ) { |
|
140 | + if ( ! $rest_url) { |
|
141 | 141 | return; |
142 | 142 | } |
143 | 143 | |
144 | - wp_enqueue_script( 'wordlift-cloud' ); |
|
145 | - $template_url = get_rest_url( null, '/wordlift/v1/navigator/template' ); |
|
144 | + wp_enqueue_script('wordlift-cloud'); |
|
145 | + $template_url = get_rest_url(null, '/wordlift/v1/navigator/template'); |
|
146 | 146 | |
147 | 147 | return <<<HTML |
148 | 148 | <!-- Navigator {$navigator_id} --> |
@@ -165,50 +165,50 @@ discard block |
||
165 | 165 | * @return string Shortcode HTML for amp |
166 | 166 | * @since 3.20.0 |
167 | 167 | */ |
168 | - private function amp_shortcode( $atts ) { |
|
168 | + private function amp_shortcode($atts) { |
|
169 | 169 | // attributes extraction and boolean filtering |
170 | - $shortcode_atts = $this->make_shortcode_atts( $atts ); |
|
170 | + $shortcode_atts = $this->make_shortcode_atts($atts); |
|
171 | 171 | |
172 | 172 | // avoid building the widget when no post_id is specified and there is a list of posts. |
173 | - if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) { |
|
173 | + if (empty($shortcode_atts['post_id']) && ! is_singular()) { |
|
174 | 174 | return; |
175 | 175 | } |
176 | 176 | |
177 | - $post = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( $shortcode_atts['post_id'] ) ) : get_post(); |
|
178 | - $title = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) ); |
|
179 | - $template_id = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) ); |
|
180 | - $limit = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) ); |
|
181 | - $offset = esc_attr( sanitize_text_field( $shortcode_atts['offset'] ) ); |
|
182 | - $sort = esc_attr( sanitize_sql_orderby( sanitize_text_field( $shortcode_atts['order_by'] ) ) ); |
|
183 | - $navigator_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-navigator-widget-' ); |
|
177 | + $post = ! empty($shortcode_atts['post_id']) ? get_post(intval($shortcode_atts['post_id'])) : get_post(); |
|
178 | + $title = esc_attr(sanitize_text_field($shortcode_atts['title'])); |
|
179 | + $template_id = esc_attr(sanitize_text_field($shortcode_atts['template_id'])); |
|
180 | + $limit = esc_attr(sanitize_text_field($shortcode_atts['limit'])); |
|
181 | + $offset = esc_attr(sanitize_text_field($shortcode_atts['offset'])); |
|
182 | + $sort = esc_attr(sanitize_sql_orderby(sanitize_text_field($shortcode_atts['order_by']))); |
|
183 | + $navigator_id = ! empty($shortcode_atts['uniqid']) ? esc_attr(sanitize_text_field($shortcode_atts['uniqid'])) : uniqid('wl-navigator-widget-'); |
|
184 | 184 | |
185 | - $permalink_structure = get_option( 'permalink_structure' ); |
|
186 | - $delimiter = empty( $permalink_structure ) ? '&' : '?'; |
|
185 | + $permalink_structure = get_option('permalink_structure'); |
|
186 | + $delimiter = empty($permalink_structure) ? '&' : '?'; |
|
187 | 187 | $rest_url = $post ? rest_url( |
188 | - WL_REST_ROUTE_DEFAULT_NAMESPACE . '/navigator' . $delimiter . build_query( |
|
188 | + WL_REST_ROUTE_DEFAULT_NAMESPACE.'/navigator'.$delimiter.build_query( |
|
189 | 189 | array( |
190 | 190 | 'uniqid' => $navigator_id, |
191 | 191 | 'post_id' => $post->ID, |
192 | 192 | 'limit' => $limit, |
193 | 193 | 'offset' => $offset, |
194 | 194 | 'sort' => $sort, |
195 | - '_wpnonce' => wp_create_nonce( 'wl_navigator' ), |
|
195 | + '_wpnonce' => wp_create_nonce('wl_navigator'), |
|
196 | 196 | ) |
197 | 197 | ) |
198 | 198 | ) : false; |
199 | 199 | |
200 | 200 | // avoid building the widget when no valid $rest_url |
201 | - if ( ! $rest_url ) { |
|
201 | + if ( ! $rest_url) { |
|
202 | 202 | return; |
203 | 203 | } |
204 | 204 | |
205 | 205 | // Use a protocol-relative URL as amp-list spec says that URL's protocol must be HTTPS. |
206 | 206 | // This is a hackish way, but this works for http and https URLs |
207 | - $rest_url = str_replace( array( 'http:', 'https:' ), '', $rest_url ); |
|
207 | + $rest_url = str_replace(array('http:', 'https:'), '', $rest_url); |
|
208 | 208 | |
209 | - if ( empty( $template_id ) ) { |
|
210 | - $template_id = 'template-' . $navigator_id; |
|
211 | - wp_enqueue_style( 'wordlift-amp-custom', plugin_dir_url( __DIR__ ) . '/css/wordlift-amp-custom.min.css', array(), WORDLIFT_VERSION ); |
|
209 | + if (empty($template_id)) { |
|
210 | + $template_id = 'template-'.$navigator_id; |
|
211 | + wp_enqueue_style('wordlift-amp-custom', plugin_dir_url(__DIR__).'/css/wordlift-amp-custom.min.css', array(), WORDLIFT_VERSION); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | return <<<HTML |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | return array( |
254 | 254 | 'title' => array( |
255 | 255 | 'type' => 'string', |
256 | - 'default' => __( 'Related articles', 'wordlift' ), |
|
256 | + 'default' => __('Related articles', 'wordlift'), |
|
257 | 257 | ), |
258 | 258 | 'limit' => array( |
259 | 259 | 'type' => 'number', |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | ), |
286 | 286 | 'preview_src' => array( |
287 | 287 | 'type' => 'string', |
288 | - 'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/navigator.png', |
|
288 | + 'default' => WP_CONTENT_URL.'/plugins/wordlift/images/block-previews/navigator.png', |
|
289 | 289 | ), |
290 | 290 | 'post_types' => array( |
291 | 291 | 'type' => 'string', |