@@ -14,13 +14,13 @@ discard block |
||
14 | 14 | */ |
15 | 15 | function wl_register_metaboxes() { |
16 | 16 | |
17 | - new Wl_Metabox(); // Everything is done inside here with the correct timing. |
|
17 | + new Wl_Metabox(); // Everything is done inside here with the correct timing. |
|
18 | 18 | |
19 | 19 | } |
20 | 20 | |
21 | 21 | if ( is_admin() ) { |
22 | - add_action( 'load-post.php', 'wl_register_metaboxes' ); |
|
23 | - add_action( 'load-post-new.php', 'wl_register_metaboxes' ); |
|
22 | + add_action( 'load-post.php', 'wl_register_metaboxes' ); |
|
23 | + add_action( 'load-post-new.php', 'wl_register_metaboxes' ); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -31,41 +31,41 @@ discard block |
||
31 | 31 | */ |
32 | 32 | function wl_admin_add_entities_meta_box( $post_type, $post ) { |
33 | 33 | |
34 | - /* |
|
34 | + /* |
|
35 | 35 | * Call the `wl_can_see_classification_box` filter to determine whether we can display the classification box. |
36 | 36 | * |
37 | 37 | * @since 3.20.3 |
38 | 38 | * |
39 | 39 | * @see https://github.com/insideout10/wordlift-plugin/issues/914 |
40 | 40 | */ |
41 | - if ( ! apply_filters( 'wl_can_see_classification_box', true ) ) { |
|
42 | - return; |
|
43 | - } |
|
44 | - |
|
45 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
46 | - if ( ! apply_filters( 'wl_feature__enable__classification-sidebar', true ) ) { |
|
47 | - return; |
|
48 | - } |
|
49 | - |
|
50 | - // Bail out if the post type doesn't support a TinyMCE editor. |
|
51 | - if ( ! wl_post_type_supports_editor( $post_type ) ) { |
|
52 | - return; |
|
53 | - } |
|
54 | - |
|
55 | - // If the editor is not gutenberg and not any other custom editor then we use the sidebar. |
|
56 | - if ( ! Wordlift_Admin::is_gutenberg() && ! No_Editor_Analysis_Feature::can_no_editor_analysis_be_used( |
|
57 | - $post->ID |
|
58 | - ) ) { |
|
59 | - // Add main meta box for related entities and 4W only if not Gutenberg |
|
60 | - add_meta_box( |
|
61 | - 'wordlift_entities_box', |
|
62 | - __( 'WordLift', 'wordlift' ), |
|
63 | - 'wl_entities_box_content', |
|
64 | - $post_type, |
|
65 | - 'side', |
|
66 | - 'high' |
|
67 | - ); |
|
68 | - } |
|
41 | + if ( ! apply_filters( 'wl_can_see_classification_box', true ) ) { |
|
42 | + return; |
|
43 | + } |
|
44 | + |
|
45 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
46 | + if ( ! apply_filters( 'wl_feature__enable__classification-sidebar', true ) ) { |
|
47 | + return; |
|
48 | + } |
|
49 | + |
|
50 | + // Bail out if the post type doesn't support a TinyMCE editor. |
|
51 | + if ( ! wl_post_type_supports_editor( $post_type ) ) { |
|
52 | + return; |
|
53 | + } |
|
54 | + |
|
55 | + // If the editor is not gutenberg and not any other custom editor then we use the sidebar. |
|
56 | + if ( ! Wordlift_Admin::is_gutenberg() && ! No_Editor_Analysis_Feature::can_no_editor_analysis_be_used( |
|
57 | + $post->ID |
|
58 | + ) ) { |
|
59 | + // Add main meta box for related entities and 4W only if not Gutenberg |
|
60 | + add_meta_box( |
|
61 | + 'wordlift_entities_box', |
|
62 | + __( 'WordLift', 'wordlift' ), |
|
63 | + 'wl_entities_box_content', |
|
64 | + $post_type, |
|
65 | + 'side', |
|
66 | + 'high' |
|
67 | + ); |
|
68 | + } |
|
69 | 69 | |
70 | 70 | } |
71 | 71 | |
@@ -82,18 +82,18 @@ discard block |
||
82 | 82 | */ |
83 | 83 | function wl_post_type_supports_editor( $post_type ) { |
84 | 84 | |
85 | - $default = post_type_supports( $post_type, 'editor' ); |
|
86 | - |
|
87 | - /** |
|
88 | - * Allow 3rd parties to force the classification to load. |
|
89 | - * |
|
90 | - * @param bool $default The preset value as gathered by the `post_type_supports` call. |
|
91 | - * |
|
92 | - * @see https://github.com/insideout10/wordlift-plugin/issues/847. |
|
93 | - * |
|
94 | - * @since 3.19.4 |
|
95 | - */ |
|
96 | - return apply_filters( 'wl_post_type_supports_editor', $default, $post_type ); |
|
85 | + $default = post_type_supports( $post_type, 'editor' ); |
|
86 | + |
|
87 | + /** |
|
88 | + * Allow 3rd parties to force the classification to load. |
|
89 | + * |
|
90 | + * @param bool $default The preset value as gathered by the `post_type_supports` call. |
|
91 | + * |
|
92 | + * @see https://github.com/insideout10/wordlift-plugin/issues/847. |
|
93 | + * |
|
94 | + * @since 3.19.4 |
|
95 | + */ |
|
96 | + return apply_filters( 'wl_post_type_supports_editor', $default, $post_type ); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -103,141 +103,141 @@ discard block |
||
103 | 103 | */ |
104 | 104 | function wl_entities_box_content( $post, $wrapper = true ) { |
105 | 105 | |
106 | - // Angularjs edit-post widget wrapper. |
|
107 | - if ( $wrapper ) { |
|
108 | - echo '<div id="wordlift-edit-post-outer-wrapper"></div>'; |
|
109 | - } |
|
106 | + // Angularjs edit-post widget wrapper. |
|
107 | + if ( $wrapper ) { |
|
108 | + echo '<div id="wordlift-edit-post-outer-wrapper"></div>'; |
|
109 | + } |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | function wl_entities_box_content_scripts() { |
113 | - $post = get_post(); |
|
113 | + $post = get_post(); |
|
114 | 114 | |
115 | - // Angularjs edit-post widget classification boxes configuration. |
|
116 | - // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize |
|
117 | - $classification_boxes = unserialize( WL_CORE_POST_CLASSIFICATION_BOXES ); |
|
115 | + // Angularjs edit-post widget classification boxes configuration. |
|
116 | + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize |
|
117 | + $classification_boxes = unserialize( WL_CORE_POST_CLASSIFICATION_BOXES ); |
|
118 | 118 | |
119 | - // Array to store all related entities ids. |
|
120 | - $all_referenced_entities_ids = array(); |
|
119 | + // Array to store all related entities ids. |
|
120 | + $all_referenced_entities_ids = array(); |
|
121 | 121 | |
122 | - // Add selected entities to classification_boxes. |
|
123 | - foreach ( $classification_boxes as $i => $box ) { |
|
122 | + // Add selected entities to classification_boxes. |
|
123 | + foreach ( $classification_boxes as $i => $box ) { |
|
124 | 124 | |
125 | - // Get the entity referenced from the post content. |
|
126 | - /* |
|
125 | + // Get the entity referenced from the post content. |
|
126 | + /* |
|
127 | 127 | * Allow 3rd parties to provide another post content. |
128 | 128 | * |
129 | 129 | * @since 3.20.0 |
130 | 130 | */ |
131 | - $post_content = apply_filters( 'wl_post_content', $post->post_content, $post ); |
|
132 | - $entity_uris = Wordlift_Content_Filter_Service::get_instance()->get_entity_uris( $post_content ); |
|
133 | - |
|
134 | - // Enhance current box selected entities. |
|
135 | - $classification_boxes[ $i ]['selectedEntities'] = $entity_uris; |
|
136 | - |
|
137 | - // Maps the URIs to entity posts. |
|
138 | - $entity_service = Wordlift_Entity_Service::get_instance(); |
|
139 | - |
|
140 | - // Replace all entity URI's with post ID's if found or null if there is no related post. |
|
141 | - $entity_ids = array_map( |
|
142 | - function ( $item ) use ( $entity_service ) { |
|
143 | - // Return entity post by the entity URI or null. |
|
144 | - $post = $entity_service->get_entity_post_by_uri( $item ); |
|
145 | - |
|
146 | - // Check that the post object is not null. |
|
147 | - if ( ! empty( $post ) ) { |
|
148 | - return $post->ID; |
|
149 | - } |
|
150 | - }, |
|
151 | - $entity_uris |
|
152 | - ); |
|
153 | - // Store the entity ids for all the 4W. |
|
154 | - $all_referenced_entities_ids = array_merge( $all_referenced_entities_ids, $entity_ids ); |
|
155 | - |
|
156 | - } |
|
157 | - |
|
158 | - // Json encoding for classification boxes structure. |
|
159 | - $classification_boxes = wp_json_encode( $classification_boxes ); |
|
160 | - |
|
161 | - // Ensure there are no repetitions of the referenced entities. |
|
162 | - $all_referenced_entities_ids = array_unique( $all_referenced_entities_ids ); |
|
163 | - |
|
164 | - // Remove all null, false and empty strings. |
|
165 | - // NULL is being returned in some cases, when there is not related post, so we need to remove it. |
|
166 | - $all_referenced_entities_ids = array_filter( $all_referenced_entities_ids ); |
|
167 | - |
|
168 | - // Build the entity storage object. |
|
169 | - $referenced_entities_obj = array(); |
|
170 | - foreach ( $all_referenced_entities_ids as $referenced_entity ) { |
|
171 | - $entity = wl_serialize_entity( $referenced_entity ); |
|
172 | - // Set a default confidence of `PHP_INT_MAX` for already annotated entities. |
|
173 | - $referenced_entities_obj[ $entity['id'] ] = $entity |
|
174 | - + array( 'confidence' => PHP_INT_MAX ); |
|
175 | - } |
|
176 | - |
|
177 | - $referenced_entities_obj = empty( $referenced_entities_obj ) ? |
|
178 | - '{}' : wp_json_encode( $referenced_entities_obj ); |
|
179 | - |
|
180 | - $published_place_id = get_post_meta( |
|
181 | - $post->ID, |
|
182 | - Wordlift_Schema_Service::FIELD_LOCATION_CREATED, |
|
183 | - true |
|
184 | - ); |
|
185 | - $published_place_obj = ( $published_place_id ) ? |
|
186 | - wp_json_encode( wl_serialize_entity( $published_place_id ) ) : |
|
187 | - null; |
|
188 | - |
|
189 | - $topic_id = get_post_meta( |
|
190 | - $post->ID, |
|
191 | - Wordlift_Schema_Service::FIELD_TOPIC, |
|
192 | - true |
|
193 | - ); |
|
194 | - $topic_obj = ( $topic_id ) ? |
|
195 | - wp_json_encode( wl_serialize_entity( $topic_id ) ) : |
|
196 | - null; |
|
197 | - |
|
198 | - $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
199 | - |
|
200 | - $default_thumbnail_path = WL_DEFAULT_THUMBNAIL_PATH; |
|
201 | - $default_path = WL_DEFAULT_PATH; |
|
202 | - $dataset_uri = $configuration_service->get_dataset_uri(); |
|
203 | - $current_post_uri = Wordlift_Entity_Service::get_instance()->get_uri( $post->ID ); |
|
204 | - $is_entity = Wordlift_Entity_Service::get_instance()->is_entity( $post->ID ); |
|
205 | - |
|
206 | - // Retrieve the current post author. |
|
207 | - $post_author = get_userdata( $post->post_author )->display_name; |
|
208 | - // Retrive the published date. |
|
209 | - $published_date = get_the_time( 'Y-m-d', $post->ID ); |
|
210 | - // Current language. |
|
211 | - $current_language = $configuration_service->get_language_code(); |
|
212 | - $wordlift_timeline_shortcode = new Wordlift_Timeline_Shortcode(); |
|
213 | - $timelinejs_default_options = wp_json_encode( $wordlift_timeline_shortcode->get_timelinejs_default_options(), JSON_PRETTY_PRINT ); |
|
214 | - $addslashes_post_author = addslashes( $post_author ); |
|
215 | - |
|
216 | - $metabox_settings = array( |
|
217 | - 'classificationBoxes' => json_decode( $classification_boxes ), |
|
218 | - 'entities' => json_decode( $referenced_entities_obj ), |
|
219 | - 'currentPostId' => intval( $post->ID ), |
|
220 | - 'currentPostUri' => $current_post_uri, |
|
221 | - 'currentPostType' => $post->post_type, |
|
222 | - 'isEntity' => ! empty( $is_entity ), |
|
223 | - 'defaultThumbnailPath' => $default_thumbnail_path, |
|
224 | - 'defaultWordLiftPath' => $default_path, |
|
225 | - 'datasetUri' => $dataset_uri, |
|
226 | - 'currentUser' => $addslashes_post_author, |
|
227 | - 'publishedDate' => $published_date, |
|
228 | - 'publishedPlace' => $published_place_obj, |
|
229 | - 'topic' => json_decode( $topic_obj ), |
|
230 | - 'currentLanguage' => $current_language, |
|
231 | - 'timelinejsDefaultOptions' => json_decode( $timelinejs_default_options ), |
|
232 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
233 | - ); |
|
234 | - |
|
235 | - // Allow Classic and Block Editor scripts to register first. |
|
236 | - // Hook to the Block Editor script. |
|
237 | - wp_localize_script( 'wl-block-editor', '_wlMetaBoxSettings', array( 'settings' => $metabox_settings ) ); |
|
238 | - |
|
239 | - // Hook to the Classic Editor script, see Wordlift_Admin_Post_Edit_Page. |
|
240 | - wp_localize_script( 'wl-classic-editor', '_wlMetaBoxSettings', array( 'settings' => $metabox_settings ) ); |
|
131 | + $post_content = apply_filters( 'wl_post_content', $post->post_content, $post ); |
|
132 | + $entity_uris = Wordlift_Content_Filter_Service::get_instance()->get_entity_uris( $post_content ); |
|
133 | + |
|
134 | + // Enhance current box selected entities. |
|
135 | + $classification_boxes[ $i ]['selectedEntities'] = $entity_uris; |
|
136 | + |
|
137 | + // Maps the URIs to entity posts. |
|
138 | + $entity_service = Wordlift_Entity_Service::get_instance(); |
|
139 | + |
|
140 | + // Replace all entity URI's with post ID's if found or null if there is no related post. |
|
141 | + $entity_ids = array_map( |
|
142 | + function ( $item ) use ( $entity_service ) { |
|
143 | + // Return entity post by the entity URI or null. |
|
144 | + $post = $entity_service->get_entity_post_by_uri( $item ); |
|
145 | + |
|
146 | + // Check that the post object is not null. |
|
147 | + if ( ! empty( $post ) ) { |
|
148 | + return $post->ID; |
|
149 | + } |
|
150 | + }, |
|
151 | + $entity_uris |
|
152 | + ); |
|
153 | + // Store the entity ids for all the 4W. |
|
154 | + $all_referenced_entities_ids = array_merge( $all_referenced_entities_ids, $entity_ids ); |
|
155 | + |
|
156 | + } |
|
157 | + |
|
158 | + // Json encoding for classification boxes structure. |
|
159 | + $classification_boxes = wp_json_encode( $classification_boxes ); |
|
160 | + |
|
161 | + // Ensure there are no repetitions of the referenced entities. |
|
162 | + $all_referenced_entities_ids = array_unique( $all_referenced_entities_ids ); |
|
163 | + |
|
164 | + // Remove all null, false and empty strings. |
|
165 | + // NULL is being returned in some cases, when there is not related post, so we need to remove it. |
|
166 | + $all_referenced_entities_ids = array_filter( $all_referenced_entities_ids ); |
|
167 | + |
|
168 | + // Build the entity storage object. |
|
169 | + $referenced_entities_obj = array(); |
|
170 | + foreach ( $all_referenced_entities_ids as $referenced_entity ) { |
|
171 | + $entity = wl_serialize_entity( $referenced_entity ); |
|
172 | + // Set a default confidence of `PHP_INT_MAX` for already annotated entities. |
|
173 | + $referenced_entities_obj[ $entity['id'] ] = $entity |
|
174 | + + array( 'confidence' => PHP_INT_MAX ); |
|
175 | + } |
|
176 | + |
|
177 | + $referenced_entities_obj = empty( $referenced_entities_obj ) ? |
|
178 | + '{}' : wp_json_encode( $referenced_entities_obj ); |
|
179 | + |
|
180 | + $published_place_id = get_post_meta( |
|
181 | + $post->ID, |
|
182 | + Wordlift_Schema_Service::FIELD_LOCATION_CREATED, |
|
183 | + true |
|
184 | + ); |
|
185 | + $published_place_obj = ( $published_place_id ) ? |
|
186 | + wp_json_encode( wl_serialize_entity( $published_place_id ) ) : |
|
187 | + null; |
|
188 | + |
|
189 | + $topic_id = get_post_meta( |
|
190 | + $post->ID, |
|
191 | + Wordlift_Schema_Service::FIELD_TOPIC, |
|
192 | + true |
|
193 | + ); |
|
194 | + $topic_obj = ( $topic_id ) ? |
|
195 | + wp_json_encode( wl_serialize_entity( $topic_id ) ) : |
|
196 | + null; |
|
197 | + |
|
198 | + $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
199 | + |
|
200 | + $default_thumbnail_path = WL_DEFAULT_THUMBNAIL_PATH; |
|
201 | + $default_path = WL_DEFAULT_PATH; |
|
202 | + $dataset_uri = $configuration_service->get_dataset_uri(); |
|
203 | + $current_post_uri = Wordlift_Entity_Service::get_instance()->get_uri( $post->ID ); |
|
204 | + $is_entity = Wordlift_Entity_Service::get_instance()->is_entity( $post->ID ); |
|
205 | + |
|
206 | + // Retrieve the current post author. |
|
207 | + $post_author = get_userdata( $post->post_author )->display_name; |
|
208 | + // Retrive the published date. |
|
209 | + $published_date = get_the_time( 'Y-m-d', $post->ID ); |
|
210 | + // Current language. |
|
211 | + $current_language = $configuration_service->get_language_code(); |
|
212 | + $wordlift_timeline_shortcode = new Wordlift_Timeline_Shortcode(); |
|
213 | + $timelinejs_default_options = wp_json_encode( $wordlift_timeline_shortcode->get_timelinejs_default_options(), JSON_PRETTY_PRINT ); |
|
214 | + $addslashes_post_author = addslashes( $post_author ); |
|
215 | + |
|
216 | + $metabox_settings = array( |
|
217 | + 'classificationBoxes' => json_decode( $classification_boxes ), |
|
218 | + 'entities' => json_decode( $referenced_entities_obj ), |
|
219 | + 'currentPostId' => intval( $post->ID ), |
|
220 | + 'currentPostUri' => $current_post_uri, |
|
221 | + 'currentPostType' => $post->post_type, |
|
222 | + 'isEntity' => ! empty( $is_entity ), |
|
223 | + 'defaultThumbnailPath' => $default_thumbnail_path, |
|
224 | + 'defaultWordLiftPath' => $default_path, |
|
225 | + 'datasetUri' => $dataset_uri, |
|
226 | + 'currentUser' => $addslashes_post_author, |
|
227 | + 'publishedDate' => $published_date, |
|
228 | + 'publishedPlace' => $published_place_obj, |
|
229 | + 'topic' => json_decode( $topic_obj ), |
|
230 | + 'currentLanguage' => $current_language, |
|
231 | + 'timelinejsDefaultOptions' => json_decode( $timelinejs_default_options ), |
|
232 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
233 | + ); |
|
234 | + |
|
235 | + // Allow Classic and Block Editor scripts to register first. |
|
236 | + // Hook to the Block Editor script. |
|
237 | + wp_localize_script( 'wl-block-editor', '_wlMetaBoxSettings', array( 'settings' => $metabox_settings ) ); |
|
238 | + |
|
239 | + // Hook to the Classic Editor script, see Wordlift_Admin_Post_Edit_Page. |
|
240 | + wp_localize_script( 'wl-classic-editor', '_wlMetaBoxSettings', array( 'settings' => $metabox_settings ) ); |
|
241 | 241 | |
242 | 242 | } |
243 | 243 |
@@ -14,13 +14,13 @@ discard block |
||
14 | 14 | */ |
15 | 15 | function wl_register_metaboxes() { |
16 | 16 | |
17 | - new Wl_Metabox(); // Everything is done inside here with the correct timing. |
|
17 | + new Wl_Metabox(); // Everything is done inside here with the correct timing. |
|
18 | 18 | |
19 | 19 | } |
20 | 20 | |
21 | -if ( is_admin() ) { |
|
22 | - add_action( 'load-post.php', 'wl_register_metaboxes' ); |
|
23 | - add_action( 'load-post-new.php', 'wl_register_metaboxes' ); |
|
21 | +if (is_admin()) { |
|
22 | + add_action('load-post.php', 'wl_register_metaboxes'); |
|
23 | + add_action('load-post-new.php', 'wl_register_metaboxes'); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @param string $post_type The type of the current open post. |
30 | 30 | * @param WP_Post $post WordPress post. |
31 | 31 | */ |
32 | -function wl_admin_add_entities_meta_box( $post_type, $post ) { |
|
32 | +function wl_admin_add_entities_meta_box($post_type, $post) { |
|
33 | 33 | |
34 | 34 | /* |
35 | 35 | * Call the `wl_can_see_classification_box` filter to determine whether we can display the classification box. |
@@ -38,28 +38,28 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @see https://github.com/insideout10/wordlift-plugin/issues/914 |
40 | 40 | */ |
41 | - if ( ! apply_filters( 'wl_can_see_classification_box', true ) ) { |
|
41 | + if ( ! apply_filters('wl_can_see_classification_box', true)) { |
|
42 | 42 | return; |
43 | 43 | } |
44 | 44 | |
45 | 45 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
46 | - if ( ! apply_filters( 'wl_feature__enable__classification-sidebar', true ) ) { |
|
46 | + if ( ! apply_filters('wl_feature__enable__classification-sidebar', true)) { |
|
47 | 47 | return; |
48 | 48 | } |
49 | 49 | |
50 | 50 | // Bail out if the post type doesn't support a TinyMCE editor. |
51 | - if ( ! wl_post_type_supports_editor( $post_type ) ) { |
|
51 | + if ( ! wl_post_type_supports_editor($post_type)) { |
|
52 | 52 | return; |
53 | 53 | } |
54 | 54 | |
55 | 55 | // If the editor is not gutenberg and not any other custom editor then we use the sidebar. |
56 | 56 | if ( ! Wordlift_Admin::is_gutenberg() && ! No_Editor_Analysis_Feature::can_no_editor_analysis_be_used( |
57 | 57 | $post->ID |
58 | - ) ) { |
|
58 | + )) { |
|
59 | 59 | // Add main meta box for related entities and 4W only if not Gutenberg |
60 | 60 | add_meta_box( |
61 | 61 | 'wordlift_entities_box', |
62 | - __( 'WordLift', 'wordlift' ), |
|
62 | + __('WordLift', 'wordlift'), |
|
63 | 63 | 'wl_entities_box_content', |
64 | 64 | $post_type, |
65 | 65 | 'side', |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | |
70 | 70 | } |
71 | 71 | |
72 | -add_action( 'add_meta_boxes', 'wl_admin_add_entities_meta_box', 10, 2 ); |
|
72 | +add_action('add_meta_boxes', 'wl_admin_add_entities_meta_box', 10, 2); |
|
73 | 73 | |
74 | 74 | /** |
75 | 75 | * Whether the post type supports the editor UI. |
@@ -80,9 +80,9 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @return bool True if the editor UI is supported otherwise false. |
82 | 82 | */ |
83 | -function wl_post_type_supports_editor( $post_type ) { |
|
83 | +function wl_post_type_supports_editor($post_type) { |
|
84 | 84 | |
85 | - $default = post_type_supports( $post_type, 'editor' ); |
|
85 | + $default = post_type_supports($post_type, 'editor'); |
|
86 | 86 | |
87 | 87 | /** |
88 | 88 | * Allow 3rd parties to force the classification to load. |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * |
94 | 94 | * @since 3.19.4 |
95 | 95 | */ |
96 | - return apply_filters( 'wl_post_type_supports_editor', $default, $post_type ); |
|
96 | + return apply_filters('wl_post_type_supports_editor', $default, $post_type); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -101,10 +101,10 @@ discard block |
||
101 | 101 | * |
102 | 102 | * @param WP_Post $post The current post. |
103 | 103 | */ |
104 | -function wl_entities_box_content( $post, $wrapper = true ) { |
|
104 | +function wl_entities_box_content($post, $wrapper = true) { |
|
105 | 105 | |
106 | 106 | // Angularjs edit-post widget wrapper. |
107 | - if ( $wrapper ) { |
|
107 | + if ($wrapper) { |
|
108 | 108 | echo '<div id="wordlift-edit-post-outer-wrapper"></div>'; |
109 | 109 | } |
110 | 110 | } |
@@ -114,13 +114,13 @@ discard block |
||
114 | 114 | |
115 | 115 | // Angularjs edit-post widget classification boxes configuration. |
116 | 116 | // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize |
117 | - $classification_boxes = unserialize( WL_CORE_POST_CLASSIFICATION_BOXES ); |
|
117 | + $classification_boxes = unserialize(WL_CORE_POST_CLASSIFICATION_BOXES); |
|
118 | 118 | |
119 | 119 | // Array to store all related entities ids. |
120 | 120 | $all_referenced_entities_ids = array(); |
121 | 121 | |
122 | 122 | // Add selected entities to classification_boxes. |
123 | - foreach ( $classification_boxes as $i => $box ) { |
|
123 | + foreach ($classification_boxes as $i => $box) { |
|
124 | 124 | |
125 | 125 | // Get the entity referenced from the post content. |
126 | 126 | /* |
@@ -128,118 +128,116 @@ discard block |
||
128 | 128 | * |
129 | 129 | * @since 3.20.0 |
130 | 130 | */ |
131 | - $post_content = apply_filters( 'wl_post_content', $post->post_content, $post ); |
|
132 | - $entity_uris = Wordlift_Content_Filter_Service::get_instance()->get_entity_uris( $post_content ); |
|
131 | + $post_content = apply_filters('wl_post_content', $post->post_content, $post); |
|
132 | + $entity_uris = Wordlift_Content_Filter_Service::get_instance()->get_entity_uris($post_content); |
|
133 | 133 | |
134 | 134 | // Enhance current box selected entities. |
135 | - $classification_boxes[ $i ]['selectedEntities'] = $entity_uris; |
|
135 | + $classification_boxes[$i]['selectedEntities'] = $entity_uris; |
|
136 | 136 | |
137 | 137 | // Maps the URIs to entity posts. |
138 | 138 | $entity_service = Wordlift_Entity_Service::get_instance(); |
139 | 139 | |
140 | 140 | // Replace all entity URI's with post ID's if found or null if there is no related post. |
141 | 141 | $entity_ids = array_map( |
142 | - function ( $item ) use ( $entity_service ) { |
|
142 | + function($item) use ($entity_service) { |
|
143 | 143 | // Return entity post by the entity URI or null. |
144 | - $post = $entity_service->get_entity_post_by_uri( $item ); |
|
144 | + $post = $entity_service->get_entity_post_by_uri($item); |
|
145 | 145 | |
146 | 146 | // Check that the post object is not null. |
147 | - if ( ! empty( $post ) ) { |
|
147 | + if ( ! empty($post)) { |
|
148 | 148 | return $post->ID; |
149 | 149 | } |
150 | 150 | }, |
151 | 151 | $entity_uris |
152 | 152 | ); |
153 | 153 | // Store the entity ids for all the 4W. |
154 | - $all_referenced_entities_ids = array_merge( $all_referenced_entities_ids, $entity_ids ); |
|
154 | + $all_referenced_entities_ids = array_merge($all_referenced_entities_ids, $entity_ids); |
|
155 | 155 | |
156 | 156 | } |
157 | 157 | |
158 | 158 | // Json encoding for classification boxes structure. |
159 | - $classification_boxes = wp_json_encode( $classification_boxes ); |
|
159 | + $classification_boxes = wp_json_encode($classification_boxes); |
|
160 | 160 | |
161 | 161 | // Ensure there are no repetitions of the referenced entities. |
162 | - $all_referenced_entities_ids = array_unique( $all_referenced_entities_ids ); |
|
162 | + $all_referenced_entities_ids = array_unique($all_referenced_entities_ids); |
|
163 | 163 | |
164 | 164 | // Remove all null, false and empty strings. |
165 | 165 | // NULL is being returned in some cases, when there is not related post, so we need to remove it. |
166 | - $all_referenced_entities_ids = array_filter( $all_referenced_entities_ids ); |
|
166 | + $all_referenced_entities_ids = array_filter($all_referenced_entities_ids); |
|
167 | 167 | |
168 | 168 | // Build the entity storage object. |
169 | 169 | $referenced_entities_obj = array(); |
170 | - foreach ( $all_referenced_entities_ids as $referenced_entity ) { |
|
171 | - $entity = wl_serialize_entity( $referenced_entity ); |
|
170 | + foreach ($all_referenced_entities_ids as $referenced_entity) { |
|
171 | + $entity = wl_serialize_entity($referenced_entity); |
|
172 | 172 | // Set a default confidence of `PHP_INT_MAX` for already annotated entities. |
173 | - $referenced_entities_obj[ $entity['id'] ] = $entity |
|
174 | - + array( 'confidence' => PHP_INT_MAX ); |
|
173 | + $referenced_entities_obj[$entity['id']] = $entity |
|
174 | + + array('confidence' => PHP_INT_MAX); |
|
175 | 175 | } |
176 | 176 | |
177 | - $referenced_entities_obj = empty( $referenced_entities_obj ) ? |
|
178 | - '{}' : wp_json_encode( $referenced_entities_obj ); |
|
177 | + $referenced_entities_obj = empty($referenced_entities_obj) ? |
|
178 | + '{}' : wp_json_encode($referenced_entities_obj); |
|
179 | 179 | |
180 | - $published_place_id = get_post_meta( |
|
180 | + $published_place_id = get_post_meta( |
|
181 | 181 | $post->ID, |
182 | 182 | Wordlift_Schema_Service::FIELD_LOCATION_CREATED, |
183 | 183 | true |
184 | 184 | ); |
185 | - $published_place_obj = ( $published_place_id ) ? |
|
186 | - wp_json_encode( wl_serialize_entity( $published_place_id ) ) : |
|
187 | - null; |
|
185 | + $published_place_obj = ($published_place_id) ? |
|
186 | + wp_json_encode(wl_serialize_entity($published_place_id)) : null; |
|
188 | 187 | |
189 | - $topic_id = get_post_meta( |
|
188 | + $topic_id = get_post_meta( |
|
190 | 189 | $post->ID, |
191 | 190 | Wordlift_Schema_Service::FIELD_TOPIC, |
192 | 191 | true |
193 | 192 | ); |
194 | - $topic_obj = ( $topic_id ) ? |
|
195 | - wp_json_encode( wl_serialize_entity( $topic_id ) ) : |
|
196 | - null; |
|
193 | + $topic_obj = ($topic_id) ? |
|
194 | + wp_json_encode(wl_serialize_entity($topic_id)) : null; |
|
197 | 195 | |
198 | 196 | $configuration_service = Wordlift_Configuration_Service::get_instance(); |
199 | 197 | |
200 | 198 | $default_thumbnail_path = WL_DEFAULT_THUMBNAIL_PATH; |
201 | 199 | $default_path = WL_DEFAULT_PATH; |
202 | 200 | $dataset_uri = $configuration_service->get_dataset_uri(); |
203 | - $current_post_uri = Wordlift_Entity_Service::get_instance()->get_uri( $post->ID ); |
|
204 | - $is_entity = Wordlift_Entity_Service::get_instance()->is_entity( $post->ID ); |
|
201 | + $current_post_uri = Wordlift_Entity_Service::get_instance()->get_uri($post->ID); |
|
202 | + $is_entity = Wordlift_Entity_Service::get_instance()->is_entity($post->ID); |
|
205 | 203 | |
206 | 204 | // Retrieve the current post author. |
207 | - $post_author = get_userdata( $post->post_author )->display_name; |
|
205 | + $post_author = get_userdata($post->post_author)->display_name; |
|
208 | 206 | // Retrive the published date. |
209 | - $published_date = get_the_time( 'Y-m-d', $post->ID ); |
|
207 | + $published_date = get_the_time('Y-m-d', $post->ID); |
|
210 | 208 | // Current language. |
211 | 209 | $current_language = $configuration_service->get_language_code(); |
212 | 210 | $wordlift_timeline_shortcode = new Wordlift_Timeline_Shortcode(); |
213 | - $timelinejs_default_options = wp_json_encode( $wordlift_timeline_shortcode->get_timelinejs_default_options(), JSON_PRETTY_PRINT ); |
|
214 | - $addslashes_post_author = addslashes( $post_author ); |
|
211 | + $timelinejs_default_options = wp_json_encode($wordlift_timeline_shortcode->get_timelinejs_default_options(), JSON_PRETTY_PRINT); |
|
212 | + $addslashes_post_author = addslashes($post_author); |
|
215 | 213 | |
216 | 214 | $metabox_settings = array( |
217 | - 'classificationBoxes' => json_decode( $classification_boxes ), |
|
218 | - 'entities' => json_decode( $referenced_entities_obj ), |
|
219 | - 'currentPostId' => intval( $post->ID ), |
|
215 | + 'classificationBoxes' => json_decode($classification_boxes), |
|
216 | + 'entities' => json_decode($referenced_entities_obj), |
|
217 | + 'currentPostId' => intval($post->ID), |
|
220 | 218 | 'currentPostUri' => $current_post_uri, |
221 | 219 | 'currentPostType' => $post->post_type, |
222 | - 'isEntity' => ! empty( $is_entity ), |
|
220 | + 'isEntity' => ! empty($is_entity), |
|
223 | 221 | 'defaultThumbnailPath' => $default_thumbnail_path, |
224 | 222 | 'defaultWordLiftPath' => $default_path, |
225 | 223 | 'datasetUri' => $dataset_uri, |
226 | 224 | 'currentUser' => $addslashes_post_author, |
227 | 225 | 'publishedDate' => $published_date, |
228 | 226 | 'publishedPlace' => $published_place_obj, |
229 | - 'topic' => json_decode( $topic_obj ), |
|
227 | + 'topic' => json_decode($topic_obj), |
|
230 | 228 | 'currentLanguage' => $current_language, |
231 | - 'timelinejsDefaultOptions' => json_decode( $timelinejs_default_options ), |
|
232 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
229 | + 'timelinejsDefaultOptions' => json_decode($timelinejs_default_options), |
|
230 | + 'ajax_url' => admin_url('admin-ajax.php'), |
|
233 | 231 | ); |
234 | 232 | |
235 | 233 | // Allow Classic and Block Editor scripts to register first. |
236 | 234 | // Hook to the Block Editor script. |
237 | - wp_localize_script( 'wl-block-editor', '_wlMetaBoxSettings', array( 'settings' => $metabox_settings ) ); |
|
235 | + wp_localize_script('wl-block-editor', '_wlMetaBoxSettings', array('settings' => $metabox_settings)); |
|
238 | 236 | |
239 | 237 | // Hook to the Classic Editor script, see Wordlift_Admin_Post_Edit_Page. |
240 | - wp_localize_script( 'wl-classic-editor', '_wlMetaBoxSettings', array( 'settings' => $metabox_settings ) ); |
|
238 | + wp_localize_script('wl-classic-editor', '_wlMetaBoxSettings', array('settings' => $metabox_settings)); |
|
241 | 239 | |
242 | 240 | } |
243 | 241 | |
244 | -add_action( 'admin_print_scripts-post.php', 'wl_entities_box_content_scripts', 11 ); |
|
245 | -add_action( 'admin_print_scripts-post-new.php', 'wl_entities_box_content_scripts', 11 ); |
|
242 | +add_action('admin_print_scripts-post.php', 'wl_entities_box_content_scripts', 11); |
|
243 | +add_action('admin_print_scripts-post-new.php', 'wl_entities_box_content_scripts', 11); |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | */ |
14 | 14 | |
15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
16 | - exit; |
|
16 | + exit; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -28,126 +28,126 @@ discard block |
||
28 | 28 | */ |
29 | 29 | class Wordlift_Admin_Setup { |
30 | 30 | |
31 | - /** |
|
32 | - * A {@link Wordlift_Key_Validation_Service} instance. |
|
33 | - * |
|
34 | - * @since 3.9.0 |
|
35 | - * @access private |
|
36 | - * @var Wordlift_Key_Validation_Service A {@link Wordlift_Key_Validation_Service} instance. |
|
37 | - */ |
|
38 | - private $key_validation_service; |
|
39 | - |
|
40 | - /** |
|
41 | - * A {@link Wordlift_Entity_Service} instance. |
|
42 | - * |
|
43 | - * @since 3.9.0 |
|
44 | - * @access private |
|
45 | - * @var Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
46 | - */ |
|
47 | - private $entity_service; |
|
48 | - |
|
49 | - /** |
|
50 | - * A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
51 | - * |
|
52 | - * @since 3.20.0 |
|
53 | - * @access private |
|
54 | - * @var \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
55 | - */ |
|
56 | - private $language_select_element; |
|
57 | - |
|
58 | - /** |
|
59 | - * A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
60 | - * |
|
61 | - * @since 3.20.0 |
|
62 | - * @access private |
|
63 | - * @var \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
64 | - */ |
|
65 | - private $country_select_element; |
|
66 | - |
|
67 | - /** |
|
68 | - * Initialize the class and set its properties. |
|
69 | - * |
|
70 | - * @param \Wordlift_Key_Validation_Service $key_validation_service A {@link Wordlift_Key_Validation_Service} instance. |
|
71 | - * @param \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
72 | - * @param \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
73 | - * @param \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
74 | - * |
|
75 | - * @since 3.9.0 |
|
76 | - */ |
|
77 | - public function __construct( $key_validation_service, $entity_service, $language_select_element, $country_select_element ) { |
|
78 | - |
|
79 | - // Set a reference to the key validation service. |
|
80 | - $this->key_validation_service = $key_validation_service; |
|
81 | - |
|
82 | - // Set a reference to the entity service. |
|
83 | - $this->entity_service = $entity_service; |
|
84 | - |
|
85 | - // Set a reference to the UI elements language and country. |
|
86 | - $this->language_select_element = $language_select_element; |
|
87 | - $this->country_select_element = $country_select_element; |
|
88 | - |
|
89 | - // Hook to some WP's events: |
|
90 | - // When WP is loaded check whether the user decided to skip the set-up, i.e. don't show us even if WL is not set up. |
|
91 | - add_action( 'wp_loaded', array( $this, 'hide_notices' ) ); |
|
92 | - |
|
93 | - // Hook to `admin_menu` in order to add our own setup wizard page. |
|
94 | - add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
|
95 | - |
|
96 | - // Triggered when the user accesses the admin area, we decide whether to show our own wizard. |
|
97 | - add_action( 'admin_init', array( $this, 'show_page' ) ); |
|
98 | - |
|
99 | - /** |
|
100 | - * Filter: wl_feature__enable__notices. |
|
101 | - * |
|
102 | - * @param bool whether the notices needs to be enabled or not. |
|
103 | - * |
|
104 | - * @return bool |
|
105 | - * @since 3.27.6 |
|
106 | - */ |
|
107 | - if ( apply_filters( 'wl_feature__enable__notices', true ) ) { |
|
108 | - // Hook to `admin_notices` to display our notices. |
|
109 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
110 | - } |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Hook to `admin_init` and redirect to WordLift's setup page if the `_wl_activation_redirect` transient flag is set. |
|
115 | - * |
|
116 | - * @since 3.9.0 |
|
117 | - */ |
|
118 | - public function admin_init() { |
|
119 | - |
|
120 | - // If the `_wl_activation_redirect` is set, the redirect to the setup page. |
|
121 | - if ( get_transient( '_wl_activation_redirect' ) ) { |
|
122 | - delete_transient( '_wl_activation_redirect' ); |
|
123 | - |
|
124 | - // If the user asked to skip the wizard then comply. |
|
125 | - if ( Wordlift_Configuration_Service::get_instance()->is_skip_wizard() ) { |
|
126 | - return; |
|
127 | - } |
|
128 | - |
|
129 | - // If we're already on the page or the user doesn't have permissions, return. |
|
130 | - if ( ( ! empty( $_GET['page'] ) && 'wl-setup' === $_GET['page'] ) || is_network_admin() || isset( $_GET['activate-multi'] ) || ! current_user_can( 'manage_options' ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
131 | - return; |
|
132 | - } |
|
133 | - |
|
134 | - // Finally redirect to the setup page. |
|
135 | - wp_safe_redirect( admin_url( 'index.php?page=wl-setup' ) ); |
|
136 | - |
|
137 | - exit; |
|
138 | - } |
|
139 | - |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Generate an admin notice suggesting to start the wizard if there is no configuration. |
|
144 | - * |
|
145 | - * @since 3.9.0 |
|
146 | - */ |
|
147 | - public function admin_notices() { |
|
148 | - |
|
149 | - // Use `wl_configuration_get_key` to check whether WL's key is set and that the user didn't disable the wizard. |
|
150 | - if ( '' === Wordlift_Configuration_Service::get_instance()->get_key() && ! Wordlift_Configuration_Service::get_instance()->is_skip_wizard() ) { ?> |
|
31 | + /** |
|
32 | + * A {@link Wordlift_Key_Validation_Service} instance. |
|
33 | + * |
|
34 | + * @since 3.9.0 |
|
35 | + * @access private |
|
36 | + * @var Wordlift_Key_Validation_Service A {@link Wordlift_Key_Validation_Service} instance. |
|
37 | + */ |
|
38 | + private $key_validation_service; |
|
39 | + |
|
40 | + /** |
|
41 | + * A {@link Wordlift_Entity_Service} instance. |
|
42 | + * |
|
43 | + * @since 3.9.0 |
|
44 | + * @access private |
|
45 | + * @var Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
46 | + */ |
|
47 | + private $entity_service; |
|
48 | + |
|
49 | + /** |
|
50 | + * A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
51 | + * |
|
52 | + * @since 3.20.0 |
|
53 | + * @access private |
|
54 | + * @var \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
55 | + */ |
|
56 | + private $language_select_element; |
|
57 | + |
|
58 | + /** |
|
59 | + * A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
60 | + * |
|
61 | + * @since 3.20.0 |
|
62 | + * @access private |
|
63 | + * @var \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
64 | + */ |
|
65 | + private $country_select_element; |
|
66 | + |
|
67 | + /** |
|
68 | + * Initialize the class and set its properties. |
|
69 | + * |
|
70 | + * @param \Wordlift_Key_Validation_Service $key_validation_service A {@link Wordlift_Key_Validation_Service} instance. |
|
71 | + * @param \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
72 | + * @param \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
73 | + * @param \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
74 | + * |
|
75 | + * @since 3.9.0 |
|
76 | + */ |
|
77 | + public function __construct( $key_validation_service, $entity_service, $language_select_element, $country_select_element ) { |
|
78 | + |
|
79 | + // Set a reference to the key validation service. |
|
80 | + $this->key_validation_service = $key_validation_service; |
|
81 | + |
|
82 | + // Set a reference to the entity service. |
|
83 | + $this->entity_service = $entity_service; |
|
84 | + |
|
85 | + // Set a reference to the UI elements language and country. |
|
86 | + $this->language_select_element = $language_select_element; |
|
87 | + $this->country_select_element = $country_select_element; |
|
88 | + |
|
89 | + // Hook to some WP's events: |
|
90 | + // When WP is loaded check whether the user decided to skip the set-up, i.e. don't show us even if WL is not set up. |
|
91 | + add_action( 'wp_loaded', array( $this, 'hide_notices' ) ); |
|
92 | + |
|
93 | + // Hook to `admin_menu` in order to add our own setup wizard page. |
|
94 | + add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
|
95 | + |
|
96 | + // Triggered when the user accesses the admin area, we decide whether to show our own wizard. |
|
97 | + add_action( 'admin_init', array( $this, 'show_page' ) ); |
|
98 | + |
|
99 | + /** |
|
100 | + * Filter: wl_feature__enable__notices. |
|
101 | + * |
|
102 | + * @param bool whether the notices needs to be enabled or not. |
|
103 | + * |
|
104 | + * @return bool |
|
105 | + * @since 3.27.6 |
|
106 | + */ |
|
107 | + if ( apply_filters( 'wl_feature__enable__notices', true ) ) { |
|
108 | + // Hook to `admin_notices` to display our notices. |
|
109 | + add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
110 | + } |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Hook to `admin_init` and redirect to WordLift's setup page if the `_wl_activation_redirect` transient flag is set. |
|
115 | + * |
|
116 | + * @since 3.9.0 |
|
117 | + */ |
|
118 | + public function admin_init() { |
|
119 | + |
|
120 | + // If the `_wl_activation_redirect` is set, the redirect to the setup page. |
|
121 | + if ( get_transient( '_wl_activation_redirect' ) ) { |
|
122 | + delete_transient( '_wl_activation_redirect' ); |
|
123 | + |
|
124 | + // If the user asked to skip the wizard then comply. |
|
125 | + if ( Wordlift_Configuration_Service::get_instance()->is_skip_wizard() ) { |
|
126 | + return; |
|
127 | + } |
|
128 | + |
|
129 | + // If we're already on the page or the user doesn't have permissions, return. |
|
130 | + if ( ( ! empty( $_GET['page'] ) && 'wl-setup' === $_GET['page'] ) || is_network_admin() || isset( $_GET['activate-multi'] ) || ! current_user_can( 'manage_options' ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
131 | + return; |
|
132 | + } |
|
133 | + |
|
134 | + // Finally redirect to the setup page. |
|
135 | + wp_safe_redirect( admin_url( 'index.php?page=wl-setup' ) ); |
|
136 | + |
|
137 | + exit; |
|
138 | + } |
|
139 | + |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Generate an admin notice suggesting to start the wizard if there is no configuration. |
|
144 | + * |
|
145 | + * @since 3.9.0 |
|
146 | + */ |
|
147 | + public function admin_notices() { |
|
148 | + |
|
149 | + // Use `wl_configuration_get_key` to check whether WL's key is set and that the user didn't disable the wizard. |
|
150 | + if ( '' === Wordlift_Configuration_Service::get_instance()->get_key() && ! Wordlift_Configuration_Service::get_instance()->is_skip_wizard() ) { ?> |
|
151 | 151 | <div id="wl-message" class="updated"> |
152 | 152 | <p><?php esc_html_e( 'Welcome to WordLift – You‘re almost ready to start', 'wordlift' ); ?></p> |
153 | 153 | <p class="submit"> |
@@ -158,138 +158,138 @@ discard block |
||
158 | 158 | </p> |
159 | 159 | </div> |
160 | 160 | <?php |
161 | - } |
|
162 | - |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Handle hiding the wizard notices by user request. |
|
167 | - * |
|
168 | - * @since 3.9.0 |
|
169 | - */ |
|
170 | - public function hide_notices() { |
|
171 | - |
|
172 | - // If it's not a `wl-hide-notice` or the nonce is not set, return. |
|
173 | - if ( ! isset( $_GET['wl-hide-notice'], $_GET['_wl_notice_nonce'] ) ) { |
|
174 | - return; |
|
175 | - } |
|
176 | - |
|
177 | - // If the nonce is invalid, return an error. |
|
178 | - if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wl_notice_nonce'] ) ), 'wordlift_hide_notices_nonce' ) ) { |
|
179 | - wp_die( esc_html__( 'Action failed. Please refresh the page and retry.', 'wordlift' ) ); |
|
180 | - } |
|
181 | - |
|
182 | - // If the user doesn't have the right privileges, return an error. |
|
183 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
184 | - wp_die( esc_html__( 'Cheatin’ huh?', 'wordlift' ) ); |
|
185 | - } |
|
186 | - |
|
187 | - // Store a flag telling to skip the wizard. |
|
188 | - Wordlift_Configuration_Service::get_instance()->set_skip_wizard( true ); |
|
189 | - |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * Register the wizard page to be able to access it. |
|
194 | - * |
|
195 | - * @since 3.9.0 |
|
196 | - */ |
|
197 | - public function admin_menu() { |
|
198 | - /** |
|
199 | - * |
|
200 | - * @see https://github.com/insideout10/wordlift-plugin/issues/1209 |
|
201 | - * @since 3.27.7 |
|
202 | - */ |
|
203 | - // @todo: find another way to do this, since this is adding an empty space in WP's dashboard menu. |
|
204 | - add_dashboard_page( '', '', 'manage_options', 'wl-setup', '' ); |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Displays the wizard page. |
|
209 | - * |
|
210 | - * @since 3.9.0 |
|
211 | - */ |
|
212 | - public function show_page() { |
|
213 | - |
|
214 | - // First check if we are in the wizard page at all, if not do nothing. |
|
215 | - if ( empty( $_GET['page'] ) || 'wl-setup' !== $_GET['page'] ) { |
|
216 | - return; |
|
217 | - } |
|
218 | - |
|
219 | - // If it's a POST and the `wl-save-configuration` action is set, save the configuration. |
|
220 | - if ( isset( $_POST['action'] ) && 'wl-save-configuration' === $_POST['action'] ) { |
|
221 | - |
|
222 | - // Check the nonce and the user capabilities. |
|
223 | - check_admin_referer( 'wl-save-configuration' ); |
|
224 | - |
|
225 | - // Check if the user has the right privileges. |
|
226 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
227 | - wp_die( esc_html__( 'Sorry, you do not have a permission to save the settings', 'wordlift' ) ); |
|
228 | - } |
|
229 | - |
|
230 | - // Save the configuration. |
|
231 | - $this->save_configuration( $_POST ); |
|
232 | - |
|
233 | - // Redirect to the admin's page. |
|
234 | - wp_safe_redirect( admin_url() ); |
|
235 | - exit(); |
|
236 | - } |
|
161 | + } |
|
162 | + |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Handle hiding the wizard notices by user request. |
|
167 | + * |
|
168 | + * @since 3.9.0 |
|
169 | + */ |
|
170 | + public function hide_notices() { |
|
171 | + |
|
172 | + // If it's not a `wl-hide-notice` or the nonce is not set, return. |
|
173 | + if ( ! isset( $_GET['wl-hide-notice'], $_GET['_wl_notice_nonce'] ) ) { |
|
174 | + return; |
|
175 | + } |
|
176 | + |
|
177 | + // If the nonce is invalid, return an error. |
|
178 | + if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wl_notice_nonce'] ) ), 'wordlift_hide_notices_nonce' ) ) { |
|
179 | + wp_die( esc_html__( 'Action failed. Please refresh the page and retry.', 'wordlift' ) ); |
|
180 | + } |
|
181 | + |
|
182 | + // If the user doesn't have the right privileges, return an error. |
|
183 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
184 | + wp_die( esc_html__( 'Cheatin’ huh?', 'wordlift' ) ); |
|
185 | + } |
|
186 | + |
|
187 | + // Store a flag telling to skip the wizard. |
|
188 | + Wordlift_Configuration_Service::get_instance()->set_skip_wizard( true ); |
|
189 | + |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * Register the wizard page to be able to access it. |
|
194 | + * |
|
195 | + * @since 3.9.0 |
|
196 | + */ |
|
197 | + public function admin_menu() { |
|
198 | + /** |
|
199 | + * |
|
200 | + * @see https://github.com/insideout10/wordlift-plugin/issues/1209 |
|
201 | + * @since 3.27.7 |
|
202 | + */ |
|
203 | + // @todo: find another way to do this, since this is adding an empty space in WP's dashboard menu. |
|
204 | + add_dashboard_page( '', '', 'manage_options', 'wl-setup', '' ); |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Displays the wizard page. |
|
209 | + * |
|
210 | + * @since 3.9.0 |
|
211 | + */ |
|
212 | + public function show_page() { |
|
213 | + |
|
214 | + // First check if we are in the wizard page at all, if not do nothing. |
|
215 | + if ( empty( $_GET['page'] ) || 'wl-setup' !== $_GET['page'] ) { |
|
216 | + return; |
|
217 | + } |
|
218 | + |
|
219 | + // If it's a POST and the `wl-save-configuration` action is set, save the configuration. |
|
220 | + if ( isset( $_POST['action'] ) && 'wl-save-configuration' === $_POST['action'] ) { |
|
221 | + |
|
222 | + // Check the nonce and the user capabilities. |
|
223 | + check_admin_referer( 'wl-save-configuration' ); |
|
224 | + |
|
225 | + // Check if the user has the right privileges. |
|
226 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
227 | + wp_die( esc_html__( 'Sorry, you do not have a permission to save the settings', 'wordlift' ) ); |
|
228 | + } |
|
229 | + |
|
230 | + // Save the configuration. |
|
231 | + $this->save_configuration( $_POST ); |
|
232 | + |
|
233 | + // Redirect to the admin's page. |
|
234 | + wp_safe_redirect( admin_url() ); |
|
235 | + exit(); |
|
236 | + } |
|
237 | 237 | |
238 | 238 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
239 | - $language_select = $this->language_select_element; |
|
240 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
241 | - $country_select = $this->country_select_element; |
|
239 | + $language_select = $this->language_select_element; |
|
240 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
241 | + $country_select = $this->country_select_element; |
|
242 | 242 | |
243 | - include plugin_dir_path( __DIR__ ) . 'admin/partials/wordlift-admin-setup.php'; |
|
243 | + include plugin_dir_path( __DIR__ ) . 'admin/partials/wordlift-admin-setup.php'; |
|
244 | 244 | |
245 | - exit; |
|
246 | - } |
|
245 | + exit; |
|
246 | + } |
|
247 | 247 | |
248 | - /** |
|
249 | - * Save WordLift's configuration using the provided parameters. |
|
250 | - * |
|
251 | - * @param array $params An array of configuration parameters. |
|
252 | - * |
|
253 | - * @since 3.9.0 |
|
254 | - */ |
|
255 | - public function save_configuration( $params ) { |
|
248 | + /** |
|
249 | + * Save WordLift's configuration using the provided parameters. |
|
250 | + * |
|
251 | + * @param array $params An array of configuration parameters. |
|
252 | + * |
|
253 | + * @since 3.9.0 |
|
254 | + */ |
|
255 | + public function save_configuration( $params ) { |
|
256 | 256 | |
257 | - // We have the following parameters: |
|
258 | - // `key`, holding WL's key, |
|
259 | - // `vocabulary`, holding the vocabulary path, |
|
260 | - // `wl-country-code` with the country code (e.g. `us`), |
|
261 | - // `share-diagnostic`, the user preferences about sharing data with us. |
|
262 | - // `user_type`, the user type either `personal` or `company`, |
|
263 | - // `name`, with the `personal` or `company`'s name, |
|
264 | - // `logo`, the attachment id for the `personal` or `company` entity. |
|
257 | + // We have the following parameters: |
|
258 | + // `key`, holding WL's key, |
|
259 | + // `vocabulary`, holding the vocabulary path, |
|
260 | + // `wl-country-code` with the country code (e.g. `us`), |
|
261 | + // `share-diagnostic`, the user preferences about sharing data with us. |
|
262 | + // `user_type`, the user type either `personal` or `company`, |
|
263 | + // `name`, with the `personal` or `company`'s name, |
|
264 | + // `logo`, the attachment id for the `personal` or `company` entity. |
|
265 | 265 | |
266 | - // Store the key: |
|
267 | - Wordlift_Configuration_Service::get_instance()->set_key( $params['key'] ); |
|
266 | + // Store the key: |
|
267 | + Wordlift_Configuration_Service::get_instance()->set_key( $params['key'] ); |
|
268 | 268 | |
269 | - // Store the vocabulary path: |
|
270 | - Wordlift_Configuration_Service::get_instance()->set_entity_base_path( $params['vocabulary'] ); |
|
269 | + // Store the vocabulary path: |
|
270 | + Wordlift_Configuration_Service::get_instance()->set_entity_base_path( $params['vocabulary'] ); |
|
271 | 271 | |
272 | - // Store the site's country: |
|
273 | - Wordlift_Configuration_Service::get_instance()->set_country_code( $params['wl-country-code'] ); |
|
272 | + // Store the site's country: |
|
273 | + Wordlift_Configuration_Service::get_instance()->set_country_code( $params['wl-country-code'] ); |
|
274 | 274 | |
275 | - // Store the preferences in variable, because if the checkbox is not checked |
|
276 | - // the `share-diagnostic` will not exists in `$params` array. |
|
277 | - $share_diagnostic_preferences = empty( $params['share-diagnostic'] ) ? 'no' : 'yes'; |
|
275 | + // Store the preferences in variable, because if the checkbox is not checked |
|
276 | + // the `share-diagnostic` will not exists in `$params` array. |
|
277 | + $share_diagnostic_preferences = empty( $params['share-diagnostic'] ) ? 'no' : 'yes'; |
|
278 | 278 | |
279 | - // Store the diagnostic preferences: |
|
280 | - Wordlift_Configuration_Service::get_instance()->set_diagnostic_preferences( $share_diagnostic_preferences ); |
|
279 | + // Store the diagnostic preferences: |
|
280 | + Wordlift_Configuration_Service::get_instance()->set_diagnostic_preferences( $share_diagnostic_preferences ); |
|
281 | 281 | |
282 | - // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
|
283 | - $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $params['user_type'] ? 'Organization' : 'Person' ); |
|
282 | + // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
|
283 | + $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $params['user_type'] ? 'Organization' : 'Person' ); |
|
284 | 284 | |
285 | - // Create an entity for the publisher. |
|
286 | - $publisher_post_id = $this->entity_service->create( $params['name'], $type_uri, $params['logo'], 'publish' ); |
|
285 | + // Create an entity for the publisher. |
|
286 | + $publisher_post_id = $this->entity_service->create( $params['name'], $type_uri, $params['logo'], 'publish' ); |
|
287 | 287 | |
288 | - // Store the publisher entity post id in the configuration. |
|
289 | - Wordlift_Configuration_Service::get_instance()->set_publisher_id( $publisher_post_id ); |
|
288 | + // Store the publisher entity post id in the configuration. |
|
289 | + Wordlift_Configuration_Service::get_instance()->set_publisher_id( $publisher_post_id ); |
|
290 | 290 | |
291 | - flush_rewrite_rules(); // Needed because of possible change to the entity base path. |
|
291 | + flush_rewrite_rules(); // Needed because of possible change to the entity base path. |
|
292 | 292 | |
293 | - } |
|
293 | + } |
|
294 | 294 | |
295 | 295 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * @since 3.9.0 |
13 | 13 | */ |
14 | 14 | |
15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
15 | +if ( ! defined('ABSPATH')) { |
|
16 | 16 | exit; |
17 | 17 | } |
18 | 18 | |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * |
75 | 75 | * @since 3.9.0 |
76 | 76 | */ |
77 | - public function __construct( $key_validation_service, $entity_service, $language_select_element, $country_select_element ) { |
|
77 | + public function __construct($key_validation_service, $entity_service, $language_select_element, $country_select_element) { |
|
78 | 78 | |
79 | 79 | // Set a reference to the key validation service. |
80 | 80 | $this->key_validation_service = $key_validation_service; |
@@ -88,13 +88,13 @@ discard block |
||
88 | 88 | |
89 | 89 | // Hook to some WP's events: |
90 | 90 | // When WP is loaded check whether the user decided to skip the set-up, i.e. don't show us even if WL is not set up. |
91 | - add_action( 'wp_loaded', array( $this, 'hide_notices' ) ); |
|
91 | + add_action('wp_loaded', array($this, 'hide_notices')); |
|
92 | 92 | |
93 | 93 | // Hook to `admin_menu` in order to add our own setup wizard page. |
94 | - add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
|
94 | + add_action('admin_menu', array($this, 'admin_menu')); |
|
95 | 95 | |
96 | 96 | // Triggered when the user accesses the admin area, we decide whether to show our own wizard. |
97 | - add_action( 'admin_init', array( $this, 'show_page' ) ); |
|
97 | + add_action('admin_init', array($this, 'show_page')); |
|
98 | 98 | |
99 | 99 | /** |
100 | 100 | * Filter: wl_feature__enable__notices. |
@@ -104,9 +104,9 @@ discard block |
||
104 | 104 | * @return bool |
105 | 105 | * @since 3.27.6 |
106 | 106 | */ |
107 | - if ( apply_filters( 'wl_feature__enable__notices', true ) ) { |
|
107 | + if (apply_filters('wl_feature__enable__notices', true)) { |
|
108 | 108 | // Hook to `admin_notices` to display our notices. |
109 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
109 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
110 | 110 | } |
111 | 111 | } |
112 | 112 | |
@@ -118,21 +118,21 @@ discard block |
||
118 | 118 | public function admin_init() { |
119 | 119 | |
120 | 120 | // If the `_wl_activation_redirect` is set, the redirect to the setup page. |
121 | - if ( get_transient( '_wl_activation_redirect' ) ) { |
|
122 | - delete_transient( '_wl_activation_redirect' ); |
|
121 | + if (get_transient('_wl_activation_redirect')) { |
|
122 | + delete_transient('_wl_activation_redirect'); |
|
123 | 123 | |
124 | 124 | // If the user asked to skip the wizard then comply. |
125 | - if ( Wordlift_Configuration_Service::get_instance()->is_skip_wizard() ) { |
|
125 | + if (Wordlift_Configuration_Service::get_instance()->is_skip_wizard()) { |
|
126 | 126 | return; |
127 | 127 | } |
128 | 128 | |
129 | 129 | // If we're already on the page or the user doesn't have permissions, return. |
130 | - if ( ( ! empty( $_GET['page'] ) && 'wl-setup' === $_GET['page'] ) || is_network_admin() || isset( $_GET['activate-multi'] ) || ! current_user_can( 'manage_options' ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
130 | + if (( ! empty($_GET['page']) && 'wl-setup' === $_GET['page']) || is_network_admin() || isset($_GET['activate-multi']) || ! current_user_can('manage_options')) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
131 | 131 | return; |
132 | 132 | } |
133 | 133 | |
134 | 134 | // Finally redirect to the setup page. |
135 | - wp_safe_redirect( admin_url( 'index.php?page=wl-setup' ) ); |
|
135 | + wp_safe_redirect(admin_url('index.php?page=wl-setup')); |
|
136 | 136 | |
137 | 137 | exit; |
138 | 138 | } |
@@ -147,14 +147,14 @@ discard block |
||
147 | 147 | public function admin_notices() { |
148 | 148 | |
149 | 149 | // Use `wl_configuration_get_key` to check whether WL's key is set and that the user didn't disable the wizard. |
150 | - if ( '' === Wordlift_Configuration_Service::get_instance()->get_key() && ! Wordlift_Configuration_Service::get_instance()->is_skip_wizard() ) { ?> |
|
150 | + if ('' === Wordlift_Configuration_Service::get_instance()->get_key() && ! Wordlift_Configuration_Service::get_instance()->is_skip_wizard()) { ?> |
|
151 | 151 | <div id="wl-message" class="updated"> |
152 | - <p><?php esc_html_e( 'Welcome to WordLift – You‘re almost ready to start', 'wordlift' ); ?></p> |
|
152 | + <p><?php esc_html_e('Welcome to WordLift – You‘re almost ready to start', 'wordlift'); ?></p> |
|
153 | 153 | <p class="submit"> |
154 | - <a href="<?php echo esc_url( admin_url( 'admin.php?page=wl-setup' ) ); ?>" |
|
155 | - class="button-primary"><?php esc_html_e( 'Run the Setup Wizard', 'wordlift' ); ?></a> |
|
154 | + <a href="<?php echo esc_url(admin_url('admin.php?page=wl-setup')); ?>" |
|
155 | + class="button-primary"><?php esc_html_e('Run the Setup Wizard', 'wordlift'); ?></a> |
|
156 | 156 | <a class="button-secondary skip" |
157 | - href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wl-hide-notice', 'install' ), 'wordlift_hide_notices_nonce', '_wl_notice_nonce' ) ); ?>"><?php esc_html_e( 'Skip Setup', 'wordlift' ); ?></a> |
|
157 | + href="<?php echo esc_url(wp_nonce_url(add_query_arg('wl-hide-notice', 'install'), 'wordlift_hide_notices_nonce', '_wl_notice_nonce')); ?>"><?php esc_html_e('Skip Setup', 'wordlift'); ?></a> |
|
158 | 158 | </p> |
159 | 159 | </div> |
160 | 160 | <?php |
@@ -170,22 +170,22 @@ discard block |
||
170 | 170 | public function hide_notices() { |
171 | 171 | |
172 | 172 | // If it's not a `wl-hide-notice` or the nonce is not set, return. |
173 | - if ( ! isset( $_GET['wl-hide-notice'], $_GET['_wl_notice_nonce'] ) ) { |
|
173 | + if ( ! isset($_GET['wl-hide-notice'], $_GET['_wl_notice_nonce'])) { |
|
174 | 174 | return; |
175 | 175 | } |
176 | 176 | |
177 | 177 | // If the nonce is invalid, return an error. |
178 | - if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wl_notice_nonce'] ) ), 'wordlift_hide_notices_nonce' ) ) { |
|
179 | - wp_die( esc_html__( 'Action failed. Please refresh the page and retry.', 'wordlift' ) ); |
|
178 | + if ( ! wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['_wl_notice_nonce'])), 'wordlift_hide_notices_nonce')) { |
|
179 | + wp_die(esc_html__('Action failed. Please refresh the page and retry.', 'wordlift')); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | // If the user doesn't have the right privileges, return an error. |
183 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
184 | - wp_die( esc_html__( 'Cheatin’ huh?', 'wordlift' ) ); |
|
183 | + if ( ! current_user_can('manage_options')) { |
|
184 | + wp_die(esc_html__('Cheatin’ huh?', 'wordlift')); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | // Store a flag telling to skip the wizard. |
188 | - Wordlift_Configuration_Service::get_instance()->set_skip_wizard( true ); |
|
188 | + Wordlift_Configuration_Service::get_instance()->set_skip_wizard(true); |
|
189 | 189 | |
190 | 190 | } |
191 | 191 | |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | * @since 3.27.7 |
202 | 202 | */ |
203 | 203 | // @todo: find another way to do this, since this is adding an empty space in WP's dashboard menu. |
204 | - add_dashboard_page( '', '', 'manage_options', 'wl-setup', '' ); |
|
204 | + add_dashboard_page('', '', 'manage_options', 'wl-setup', ''); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -212,26 +212,26 @@ discard block |
||
212 | 212 | public function show_page() { |
213 | 213 | |
214 | 214 | // First check if we are in the wizard page at all, if not do nothing. |
215 | - if ( empty( $_GET['page'] ) || 'wl-setup' !== $_GET['page'] ) { |
|
215 | + if (empty($_GET['page']) || 'wl-setup' !== $_GET['page']) { |
|
216 | 216 | return; |
217 | 217 | } |
218 | 218 | |
219 | 219 | // If it's a POST and the `wl-save-configuration` action is set, save the configuration. |
220 | - if ( isset( $_POST['action'] ) && 'wl-save-configuration' === $_POST['action'] ) { |
|
220 | + if (isset($_POST['action']) && 'wl-save-configuration' === $_POST['action']) { |
|
221 | 221 | |
222 | 222 | // Check the nonce and the user capabilities. |
223 | - check_admin_referer( 'wl-save-configuration' ); |
|
223 | + check_admin_referer('wl-save-configuration'); |
|
224 | 224 | |
225 | 225 | // Check if the user has the right privileges. |
226 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
227 | - wp_die( esc_html__( 'Sorry, you do not have a permission to save the settings', 'wordlift' ) ); |
|
226 | + if ( ! current_user_can('manage_options')) { |
|
227 | + wp_die(esc_html__('Sorry, you do not have a permission to save the settings', 'wordlift')); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | // Save the configuration. |
231 | - $this->save_configuration( $_POST ); |
|
231 | + $this->save_configuration($_POST); |
|
232 | 232 | |
233 | 233 | // Redirect to the admin's page. |
234 | - wp_safe_redirect( admin_url() ); |
|
234 | + wp_safe_redirect(admin_url()); |
|
235 | 235 | exit(); |
236 | 236 | } |
237 | 237 | |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
241 | 241 | $country_select = $this->country_select_element; |
242 | 242 | |
243 | - include plugin_dir_path( __DIR__ ) . 'admin/partials/wordlift-admin-setup.php'; |
|
243 | + include plugin_dir_path(__DIR__).'admin/partials/wordlift-admin-setup.php'; |
|
244 | 244 | |
245 | 245 | exit; |
246 | 246 | } |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | * |
253 | 253 | * @since 3.9.0 |
254 | 254 | */ |
255 | - public function save_configuration( $params ) { |
|
255 | + public function save_configuration($params) { |
|
256 | 256 | |
257 | 257 | // We have the following parameters: |
258 | 258 | // `key`, holding WL's key, |
@@ -264,29 +264,29 @@ discard block |
||
264 | 264 | // `logo`, the attachment id for the `personal` or `company` entity. |
265 | 265 | |
266 | 266 | // Store the key: |
267 | - Wordlift_Configuration_Service::get_instance()->set_key( $params['key'] ); |
|
267 | + Wordlift_Configuration_Service::get_instance()->set_key($params['key']); |
|
268 | 268 | |
269 | 269 | // Store the vocabulary path: |
270 | - Wordlift_Configuration_Service::get_instance()->set_entity_base_path( $params['vocabulary'] ); |
|
270 | + Wordlift_Configuration_Service::get_instance()->set_entity_base_path($params['vocabulary']); |
|
271 | 271 | |
272 | 272 | // Store the site's country: |
273 | - Wordlift_Configuration_Service::get_instance()->set_country_code( $params['wl-country-code'] ); |
|
273 | + Wordlift_Configuration_Service::get_instance()->set_country_code($params['wl-country-code']); |
|
274 | 274 | |
275 | 275 | // Store the preferences in variable, because if the checkbox is not checked |
276 | 276 | // the `share-diagnostic` will not exists in `$params` array. |
277 | - $share_diagnostic_preferences = empty( $params['share-diagnostic'] ) ? 'no' : 'yes'; |
|
277 | + $share_diagnostic_preferences = empty($params['share-diagnostic']) ? 'no' : 'yes'; |
|
278 | 278 | |
279 | 279 | // Store the diagnostic preferences: |
280 | - Wordlift_Configuration_Service::get_instance()->set_diagnostic_preferences( $share_diagnostic_preferences ); |
|
280 | + Wordlift_Configuration_Service::get_instance()->set_diagnostic_preferences($share_diagnostic_preferences); |
|
281 | 281 | |
282 | 282 | // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
283 | - $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $params['user_type'] ? 'Organization' : 'Person' ); |
|
283 | + $type_uri = sprintf('http://schema.org/%s', 'organization' === $params['user_type'] ? 'Organization' : 'Person'); |
|
284 | 284 | |
285 | 285 | // Create an entity for the publisher. |
286 | - $publisher_post_id = $this->entity_service->create( $params['name'], $type_uri, $params['logo'], 'publish' ); |
|
286 | + $publisher_post_id = $this->entity_service->create($params['name'], $type_uri, $params['logo'], 'publish'); |
|
287 | 287 | |
288 | 288 | // Store the publisher entity post id in the configuration. |
289 | - Wordlift_Configuration_Service::get_instance()->set_publisher_id( $publisher_post_id ); |
|
289 | + Wordlift_Configuration_Service::get_instance()->set_publisher_id($publisher_post_id); |
|
290 | 290 | |
291 | 291 | flush_rewrite_rules(); // Needed because of possible change to the entity base path. |
292 | 292 |
@@ -7,194 +7,194 @@ |
||
7 | 7 | */ |
8 | 8 | class Wordlift_Notice_Service { |
9 | 9 | |
10 | - /** |
|
11 | - * The template used to display notices. The <em>notice dismissible</em> style classes make this notice dismissible |
|
12 | - * on the WordPress UI (via a small X button on the right side of the notice). |
|
13 | - * |
|
14 | - * @since 3.2.0 |
|
15 | - */ |
|
16 | - const TEMPLATE = '<div class="wl-notice notice is-dismissible %s"><p>%s</p></div>'; |
|
17 | - |
|
18 | - /** |
|
19 | - * The standard WordPress <em>update</em> style class. |
|
20 | - * |
|
21 | - * @since 3.2.0 |
|
22 | - */ |
|
23 | - const UPDATE = 'update'; |
|
24 | - |
|
25 | - /** |
|
26 | - * The standard WordPress <em>update-nag</em> style class. |
|
27 | - * |
|
28 | - * @since 3.2.0 |
|
29 | - */ |
|
30 | - const UPDATE_NAG = 'update-nag'; |
|
31 | - |
|
32 | - /** |
|
33 | - * The standard WordPress <em>error</em> style class. |
|
34 | - * |
|
35 | - * @since 3.2.0 |
|
36 | - */ |
|
37 | - const ERROR = 'error'; |
|
38 | - |
|
39 | - /** |
|
40 | - * A custom WordLift css style class used for WordLift suggestions. |
|
41 | - * |
|
42 | - * @since 3.3.0 |
|
43 | - */ |
|
44 | - const SUGGESTION = 'wl-suggestion'; |
|
45 | - |
|
46 | - /** |
|
47 | - * The array of notices. |
|
48 | - * |
|
49 | - * @since 3.2.0 |
|
50 | - * @access private |
|
51 | - * @var array $notices The array of notices. |
|
52 | - */ |
|
53 | - private $notices = array(); |
|
54 | - |
|
55 | - /** |
|
56 | - * A singleton instance of the Notice service. |
|
57 | - * |
|
58 | - * @since 3.2.0 |
|
59 | - * @access private |
|
60 | - * @var \Wordlift_Notice_Service $instance A singleton instance of the Notice service. |
|
61 | - */ |
|
62 | - private static $instance; |
|
63 | - |
|
64 | - /** |
|
65 | - * Create an instance of the Notice service. |
|
66 | - * |
|
67 | - * @since 3.2.0 |
|
68 | - */ |
|
69 | - public function __construct() { |
|
70 | - /** |
|
71 | - * Filter: wl_feature__enable__notices. |
|
72 | - * |
|
73 | - * @param bool whether the notices needs to be enabled or not. |
|
74 | - * |
|
75 | - * @return bool |
|
76 | - * @since 3.27.6 |
|
77 | - */ |
|
78 | - if ( apply_filters( 'wl_feature__enable__notices', true ) ) { |
|
79 | - // Hook to be called when to display notices. |
|
80 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
81 | - } |
|
82 | - self::$instance = $this; |
|
83 | - |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Get the singleton instance of the Notice service. |
|
88 | - * |
|
89 | - * @return \Wordlift_Notice_Service The singleton instance of the Notice service. |
|
90 | - * @since 3.2.0 |
|
91 | - */ |
|
92 | - public static function get_instance() { |
|
93 | - |
|
94 | - return self::$instance; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Add a notice. |
|
99 | - * |
|
100 | - * @param string $class The css class. |
|
101 | - * @param string $message The message. |
|
102 | - * |
|
103 | - * @since 3.2.0 |
|
104 | - */ |
|
105 | - public function add( $class, $message ) { |
|
106 | - |
|
107 | - $this->notices[] = sprintf( self::TEMPLATE, $class, $this->transform( $message ) ); |
|
108 | - |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * Add an update notice (message with a white background and a green left border). |
|
113 | - * |
|
114 | - * @param string $message The message to display. |
|
115 | - * |
|
116 | - * @since 3.2.0 |
|
117 | - */ |
|
118 | - public function add_update( $message ) { |
|
119 | - |
|
120 | - $this->add( self::UPDATE, $message ); |
|
121 | - |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Add an update nag notice (message with a white background and a yellow left border). |
|
126 | - * |
|
127 | - * @param string $message The message to display. |
|
128 | - * |
|
129 | - * @since 3.2.0 |
|
130 | - */ |
|
131 | - public function add_update_nag( $message ) { |
|
132 | - |
|
133 | - $this->add( self::UPDATE_NAG, $message ); |
|
134 | - |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Add an error notice (message with a white background and a red left border). |
|
139 | - * |
|
140 | - * @param string $message The message to display. |
|
141 | - * |
|
142 | - * @since 3.2.0 |
|
143 | - */ |
|
144 | - public function add_error( $message ) { |
|
145 | - |
|
146 | - $this->add( self::ERROR, $message ); |
|
147 | - |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Add a suggestion notice (message with a white background and a WordLift brand colored left border). |
|
152 | - * |
|
153 | - * @param string $message The message to display. |
|
154 | - * |
|
155 | - * @since 3.3.0 |
|
156 | - */ |
|
157 | - public function add_suggestion( $message ) { |
|
158 | - |
|
159 | - $this->add( self::SUGGESTION, $message ); |
|
160 | - |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Print out the notices when the admin_notices action is called. |
|
165 | - * |
|
166 | - * @since 3.2.0 |
|
167 | - */ |
|
168 | - public function admin_notices() { |
|
169 | - |
|
170 | - foreach ( $this->notices as $notice ) { |
|
171 | - echo wp_kses( |
|
172 | - $notice, |
|
173 | - array( |
|
174 | - 'div' => array( 'class' => array() ), |
|
175 | - 'p' => array(), |
|
176 | - ) |
|
177 | - ); |
|
178 | - } |
|
179 | - |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * Transform message depending on message type. Return a string |
|
184 | - * |
|
185 | - * @param string $message The message. |
|
186 | - * |
|
187 | - * @since 3.3.0 |
|
188 | - */ |
|
189 | - private function transform( $message ) { |
|
190 | - |
|
191 | - switch ( gettype( $message ) ) { |
|
192 | - case 'array': |
|
193 | - return implode( '<br />', $message ); |
|
194 | - default: |
|
195 | - return $message; |
|
196 | - } |
|
197 | - |
|
198 | - } |
|
10 | + /** |
|
11 | + * The template used to display notices. The <em>notice dismissible</em> style classes make this notice dismissible |
|
12 | + * on the WordPress UI (via a small X button on the right side of the notice). |
|
13 | + * |
|
14 | + * @since 3.2.0 |
|
15 | + */ |
|
16 | + const TEMPLATE = '<div class="wl-notice notice is-dismissible %s"><p>%s</p></div>'; |
|
17 | + |
|
18 | + /** |
|
19 | + * The standard WordPress <em>update</em> style class. |
|
20 | + * |
|
21 | + * @since 3.2.0 |
|
22 | + */ |
|
23 | + const UPDATE = 'update'; |
|
24 | + |
|
25 | + /** |
|
26 | + * The standard WordPress <em>update-nag</em> style class. |
|
27 | + * |
|
28 | + * @since 3.2.0 |
|
29 | + */ |
|
30 | + const UPDATE_NAG = 'update-nag'; |
|
31 | + |
|
32 | + /** |
|
33 | + * The standard WordPress <em>error</em> style class. |
|
34 | + * |
|
35 | + * @since 3.2.0 |
|
36 | + */ |
|
37 | + const ERROR = 'error'; |
|
38 | + |
|
39 | + /** |
|
40 | + * A custom WordLift css style class used for WordLift suggestions. |
|
41 | + * |
|
42 | + * @since 3.3.0 |
|
43 | + */ |
|
44 | + const SUGGESTION = 'wl-suggestion'; |
|
45 | + |
|
46 | + /** |
|
47 | + * The array of notices. |
|
48 | + * |
|
49 | + * @since 3.2.0 |
|
50 | + * @access private |
|
51 | + * @var array $notices The array of notices. |
|
52 | + */ |
|
53 | + private $notices = array(); |
|
54 | + |
|
55 | + /** |
|
56 | + * A singleton instance of the Notice service. |
|
57 | + * |
|
58 | + * @since 3.2.0 |
|
59 | + * @access private |
|
60 | + * @var \Wordlift_Notice_Service $instance A singleton instance of the Notice service. |
|
61 | + */ |
|
62 | + private static $instance; |
|
63 | + |
|
64 | + /** |
|
65 | + * Create an instance of the Notice service. |
|
66 | + * |
|
67 | + * @since 3.2.0 |
|
68 | + */ |
|
69 | + public function __construct() { |
|
70 | + /** |
|
71 | + * Filter: wl_feature__enable__notices. |
|
72 | + * |
|
73 | + * @param bool whether the notices needs to be enabled or not. |
|
74 | + * |
|
75 | + * @return bool |
|
76 | + * @since 3.27.6 |
|
77 | + */ |
|
78 | + if ( apply_filters( 'wl_feature__enable__notices', true ) ) { |
|
79 | + // Hook to be called when to display notices. |
|
80 | + add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
81 | + } |
|
82 | + self::$instance = $this; |
|
83 | + |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Get the singleton instance of the Notice service. |
|
88 | + * |
|
89 | + * @return \Wordlift_Notice_Service The singleton instance of the Notice service. |
|
90 | + * @since 3.2.0 |
|
91 | + */ |
|
92 | + public static function get_instance() { |
|
93 | + |
|
94 | + return self::$instance; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Add a notice. |
|
99 | + * |
|
100 | + * @param string $class The css class. |
|
101 | + * @param string $message The message. |
|
102 | + * |
|
103 | + * @since 3.2.0 |
|
104 | + */ |
|
105 | + public function add( $class, $message ) { |
|
106 | + |
|
107 | + $this->notices[] = sprintf( self::TEMPLATE, $class, $this->transform( $message ) ); |
|
108 | + |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Add an update notice (message with a white background and a green left border). |
|
113 | + * |
|
114 | + * @param string $message The message to display. |
|
115 | + * |
|
116 | + * @since 3.2.0 |
|
117 | + */ |
|
118 | + public function add_update( $message ) { |
|
119 | + |
|
120 | + $this->add( self::UPDATE, $message ); |
|
121 | + |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Add an update nag notice (message with a white background and a yellow left border). |
|
126 | + * |
|
127 | + * @param string $message The message to display. |
|
128 | + * |
|
129 | + * @since 3.2.0 |
|
130 | + */ |
|
131 | + public function add_update_nag( $message ) { |
|
132 | + |
|
133 | + $this->add( self::UPDATE_NAG, $message ); |
|
134 | + |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Add an error notice (message with a white background and a red left border). |
|
139 | + * |
|
140 | + * @param string $message The message to display. |
|
141 | + * |
|
142 | + * @since 3.2.0 |
|
143 | + */ |
|
144 | + public function add_error( $message ) { |
|
145 | + |
|
146 | + $this->add( self::ERROR, $message ); |
|
147 | + |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Add a suggestion notice (message with a white background and a WordLift brand colored left border). |
|
152 | + * |
|
153 | + * @param string $message The message to display. |
|
154 | + * |
|
155 | + * @since 3.3.0 |
|
156 | + */ |
|
157 | + public function add_suggestion( $message ) { |
|
158 | + |
|
159 | + $this->add( self::SUGGESTION, $message ); |
|
160 | + |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Print out the notices when the admin_notices action is called. |
|
165 | + * |
|
166 | + * @since 3.2.0 |
|
167 | + */ |
|
168 | + public function admin_notices() { |
|
169 | + |
|
170 | + foreach ( $this->notices as $notice ) { |
|
171 | + echo wp_kses( |
|
172 | + $notice, |
|
173 | + array( |
|
174 | + 'div' => array( 'class' => array() ), |
|
175 | + 'p' => array(), |
|
176 | + ) |
|
177 | + ); |
|
178 | + } |
|
179 | + |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * Transform message depending on message type. Return a string |
|
184 | + * |
|
185 | + * @param string $message The message. |
|
186 | + * |
|
187 | + * @since 3.3.0 |
|
188 | + */ |
|
189 | + private function transform( $message ) { |
|
190 | + |
|
191 | + switch ( gettype( $message ) ) { |
|
192 | + case 'array': |
|
193 | + return implode( '<br />', $message ); |
|
194 | + default: |
|
195 | + return $message; |
|
196 | + } |
|
197 | + |
|
198 | + } |
|
199 | 199 | |
200 | 200 | } |
@@ -75,9 +75,9 @@ discard block |
||
75 | 75 | * @return bool |
76 | 76 | * @since 3.27.6 |
77 | 77 | */ |
78 | - if ( apply_filters( 'wl_feature__enable__notices', true ) ) { |
|
78 | + if (apply_filters('wl_feature__enable__notices', true)) { |
|
79 | 79 | // Hook to be called when to display notices. |
80 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
80 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
81 | 81 | } |
82 | 82 | self::$instance = $this; |
83 | 83 | |
@@ -102,9 +102,9 @@ discard block |
||
102 | 102 | * |
103 | 103 | * @since 3.2.0 |
104 | 104 | */ |
105 | - public function add( $class, $message ) { |
|
105 | + public function add($class, $message) { |
|
106 | 106 | |
107 | - $this->notices[] = sprintf( self::TEMPLATE, $class, $this->transform( $message ) ); |
|
107 | + $this->notices[] = sprintf(self::TEMPLATE, $class, $this->transform($message)); |
|
108 | 108 | |
109 | 109 | } |
110 | 110 | |
@@ -115,9 +115,9 @@ discard block |
||
115 | 115 | * |
116 | 116 | * @since 3.2.0 |
117 | 117 | */ |
118 | - public function add_update( $message ) { |
|
118 | + public function add_update($message) { |
|
119 | 119 | |
120 | - $this->add( self::UPDATE, $message ); |
|
120 | + $this->add(self::UPDATE, $message); |
|
121 | 121 | |
122 | 122 | } |
123 | 123 | |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | * |
129 | 129 | * @since 3.2.0 |
130 | 130 | */ |
131 | - public function add_update_nag( $message ) { |
|
131 | + public function add_update_nag($message) { |
|
132 | 132 | |
133 | - $this->add( self::UPDATE_NAG, $message ); |
|
133 | + $this->add(self::UPDATE_NAG, $message); |
|
134 | 134 | |
135 | 135 | } |
136 | 136 | |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | * |
142 | 142 | * @since 3.2.0 |
143 | 143 | */ |
144 | - public function add_error( $message ) { |
|
144 | + public function add_error($message) { |
|
145 | 145 | |
146 | - $this->add( self::ERROR, $message ); |
|
146 | + $this->add(self::ERROR, $message); |
|
147 | 147 | |
148 | 148 | } |
149 | 149 | |
@@ -154,9 +154,9 @@ discard block |
||
154 | 154 | * |
155 | 155 | * @since 3.3.0 |
156 | 156 | */ |
157 | - public function add_suggestion( $message ) { |
|
157 | + public function add_suggestion($message) { |
|
158 | 158 | |
159 | - $this->add( self::SUGGESTION, $message ); |
|
159 | + $this->add(self::SUGGESTION, $message); |
|
160 | 160 | |
161 | 161 | } |
162 | 162 | |
@@ -167,11 +167,11 @@ discard block |
||
167 | 167 | */ |
168 | 168 | public function admin_notices() { |
169 | 169 | |
170 | - foreach ( $this->notices as $notice ) { |
|
170 | + foreach ($this->notices as $notice) { |
|
171 | 171 | echo wp_kses( |
172 | 172 | $notice, |
173 | 173 | array( |
174 | - 'div' => array( 'class' => array() ), |
|
174 | + 'div' => array('class' => array()), |
|
175 | 175 | 'p' => array(), |
176 | 176 | ) |
177 | 177 | ); |
@@ -186,11 +186,11 @@ discard block |
||
186 | 186 | * |
187 | 187 | * @since 3.3.0 |
188 | 188 | */ |
189 | - private function transform( $message ) { |
|
189 | + private function transform($message) { |
|
190 | 190 | |
191 | - switch ( gettype( $message ) ) { |
|
191 | + switch (gettype($message)) { |
|
192 | 192 | case 'array': |
193 | - return implode( '<br />', $message ); |
|
193 | + return implode('<br />', $message); |
|
194 | 194 | default: |
195 | 195 | return $message; |
196 | 196 | } |
@@ -18,133 +18,133 @@ |
||
18 | 18 | */ |
19 | 19 | abstract class Wordlift_Admin_Page { |
20 | 20 | |
21 | - /** |
|
22 | - * Define the {@link Wordlift_Admin_Page} constructor. |
|
23 | - * |
|
24 | - * @since 3.20.0 |
|
25 | - */ |
|
26 | - public function __construct() { |
|
27 | - add_action( 'admin_menu', array( $this, 'admin_menu' ), 10, 0 ); |
|
28 | - } |
|
29 | - |
|
30 | - /** |
|
31 | - * Get the parent slug. |
|
32 | - * |
|
33 | - * @return string The parent slug (default 'wl_admin_menu'). |
|
34 | - * @since 3.11.0 |
|
35 | - */ |
|
36 | - protected function get_parent_slug() { |
|
37 | - |
|
38 | - return 'wl_admin_menu'; |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * Get the required capability. |
|
43 | - * |
|
44 | - * @return string The capability (default 'manage_options'). |
|
45 | - * @since 3.11.0 |
|
46 | - */ |
|
47 | - protected function get_capability() { |
|
48 | - |
|
49 | - return 'manage_options'; |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * Get the page title. Will be translated. |
|
54 | - * |
|
55 | - * @return string The page title. |
|
56 | - * @since 3.11.0 |
|
57 | - */ |
|
58 | - abstract public function get_page_title(); |
|
59 | - |
|
60 | - /** |
|
61 | - * Get the menu title. Will be translated. |
|
62 | - * |
|
63 | - * @return string The menu title. |
|
64 | - * @since 3.11.0 |
|
65 | - */ |
|
66 | - abstract public function get_menu_title(); |
|
67 | - |
|
68 | - /** |
|
69 | - * Get the menu slug. |
|
70 | - * |
|
71 | - * @return string The menu slug. |
|
72 | - * @since 3.11.0 |
|
73 | - */ |
|
74 | - abstract public function get_menu_slug(); |
|
75 | - |
|
76 | - /** |
|
77 | - * Get the page url. |
|
78 | - * |
|
79 | - * @return string The escaped url of the admin page |
|
80 | - * @since 3.14.0 |
|
81 | - */ |
|
82 | - public function get_url() { |
|
83 | - |
|
84 | - // ideally should have used menu_page_url, but it is loaded later than some usages. |
|
85 | - $url = admin_url( 'admin.php?page=' . $this->get_menu_slug() ); |
|
86 | - |
|
87 | - return esc_url( $url ); |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Get the partial file name, used in the {@link render} function. |
|
92 | - * |
|
93 | - * @return string The partial file name. |
|
94 | - * @since 3.11.0 |
|
95 | - */ |
|
96 | - abstract public function get_partial_name(); |
|
97 | - |
|
98 | - /** |
|
99 | - * The `admin_menu` callback. Will call {@link add_submenu_page} to add the |
|
100 | - * page to the admin menu. |
|
101 | - * |
|
102 | - * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. |
|
103 | - * @since 3.11.0 |
|
104 | - */ |
|
105 | - public function admin_menu() { |
|
106 | - // Add the sub-menu page. |
|
107 | - // |
|
108 | - // See http://codex.wordpress.org/Function_Reference/add_submenu_page |
|
109 | - $page = add_submenu_page( |
|
110 | - $this->get_parent_slug(), |
|
111 | - $this->get_page_title(), |
|
112 | - $this->get_menu_title(), |
|
113 | - $this->get_capability(), // The required capability, provided by the calling hook. |
|
114 | - $this->get_menu_slug(), |
|
115 | - array( $this, 'render' ) |
|
116 | - ); |
|
117 | - |
|
118 | - // Set a hook to enqueue scripts only when the settings page is displayed. |
|
119 | - add_action( |
|
120 | - 'admin_print_scripts-' . $page, |
|
121 | - array( |
|
122 | - $this, |
|
123 | - 'enqueue_scripts', |
|
124 | - ) |
|
125 | - ); |
|
126 | - |
|
127 | - // Finally return the page hook_suffix. |
|
128 | - return $page; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Enqueue scripts for the specific page. Subclasses can override this function |
|
133 | - * to provide their own styles/scripts. |
|
134 | - * |
|
135 | - * @since 3.11.0 |
|
136 | - */ |
|
137 | - public function enqueue_scripts() { |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Render the page. |
|
142 | - */ |
|
143 | - public function render() { |
|
144 | - |
|
145 | - // Include the partial. |
|
146 | - include plugin_dir_path( __FILE__ ) . 'partials/' . $this->get_partial_name(); |
|
147 | - |
|
148 | - } |
|
21 | + /** |
|
22 | + * Define the {@link Wordlift_Admin_Page} constructor. |
|
23 | + * |
|
24 | + * @since 3.20.0 |
|
25 | + */ |
|
26 | + public function __construct() { |
|
27 | + add_action( 'admin_menu', array( $this, 'admin_menu' ), 10, 0 ); |
|
28 | + } |
|
29 | + |
|
30 | + /** |
|
31 | + * Get the parent slug. |
|
32 | + * |
|
33 | + * @return string The parent slug (default 'wl_admin_menu'). |
|
34 | + * @since 3.11.0 |
|
35 | + */ |
|
36 | + protected function get_parent_slug() { |
|
37 | + |
|
38 | + return 'wl_admin_menu'; |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * Get the required capability. |
|
43 | + * |
|
44 | + * @return string The capability (default 'manage_options'). |
|
45 | + * @since 3.11.0 |
|
46 | + */ |
|
47 | + protected function get_capability() { |
|
48 | + |
|
49 | + return 'manage_options'; |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * Get the page title. Will be translated. |
|
54 | + * |
|
55 | + * @return string The page title. |
|
56 | + * @since 3.11.0 |
|
57 | + */ |
|
58 | + abstract public function get_page_title(); |
|
59 | + |
|
60 | + /** |
|
61 | + * Get the menu title. Will be translated. |
|
62 | + * |
|
63 | + * @return string The menu title. |
|
64 | + * @since 3.11.0 |
|
65 | + */ |
|
66 | + abstract public function get_menu_title(); |
|
67 | + |
|
68 | + /** |
|
69 | + * Get the menu slug. |
|
70 | + * |
|
71 | + * @return string The menu slug. |
|
72 | + * @since 3.11.0 |
|
73 | + */ |
|
74 | + abstract public function get_menu_slug(); |
|
75 | + |
|
76 | + /** |
|
77 | + * Get the page url. |
|
78 | + * |
|
79 | + * @return string The escaped url of the admin page |
|
80 | + * @since 3.14.0 |
|
81 | + */ |
|
82 | + public function get_url() { |
|
83 | + |
|
84 | + // ideally should have used menu_page_url, but it is loaded later than some usages. |
|
85 | + $url = admin_url( 'admin.php?page=' . $this->get_menu_slug() ); |
|
86 | + |
|
87 | + return esc_url( $url ); |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Get the partial file name, used in the {@link render} function. |
|
92 | + * |
|
93 | + * @return string The partial file name. |
|
94 | + * @since 3.11.0 |
|
95 | + */ |
|
96 | + abstract public function get_partial_name(); |
|
97 | + |
|
98 | + /** |
|
99 | + * The `admin_menu` callback. Will call {@link add_submenu_page} to add the |
|
100 | + * page to the admin menu. |
|
101 | + * |
|
102 | + * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. |
|
103 | + * @since 3.11.0 |
|
104 | + */ |
|
105 | + public function admin_menu() { |
|
106 | + // Add the sub-menu page. |
|
107 | + // |
|
108 | + // See http://codex.wordpress.org/Function_Reference/add_submenu_page |
|
109 | + $page = add_submenu_page( |
|
110 | + $this->get_parent_slug(), |
|
111 | + $this->get_page_title(), |
|
112 | + $this->get_menu_title(), |
|
113 | + $this->get_capability(), // The required capability, provided by the calling hook. |
|
114 | + $this->get_menu_slug(), |
|
115 | + array( $this, 'render' ) |
|
116 | + ); |
|
117 | + |
|
118 | + // Set a hook to enqueue scripts only when the settings page is displayed. |
|
119 | + add_action( |
|
120 | + 'admin_print_scripts-' . $page, |
|
121 | + array( |
|
122 | + $this, |
|
123 | + 'enqueue_scripts', |
|
124 | + ) |
|
125 | + ); |
|
126 | + |
|
127 | + // Finally return the page hook_suffix. |
|
128 | + return $page; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Enqueue scripts for the specific page. Subclasses can override this function |
|
133 | + * to provide their own styles/scripts. |
|
134 | + * |
|
135 | + * @since 3.11.0 |
|
136 | + */ |
|
137 | + public function enqueue_scripts() { |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Render the page. |
|
142 | + */ |
|
143 | + public function render() { |
|
144 | + |
|
145 | + // Include the partial. |
|
146 | + include plugin_dir_path( __FILE__ ) . 'partials/' . $this->get_partial_name(); |
|
147 | + |
|
148 | + } |
|
149 | 149 | |
150 | 150 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * @since 3.20.0 |
25 | 25 | */ |
26 | 26 | public function __construct() { |
27 | - add_action( 'admin_menu', array( $this, 'admin_menu' ), 10, 0 ); |
|
27 | + add_action('admin_menu', array($this, 'admin_menu'), 10, 0); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | public function get_url() { |
83 | 83 | |
84 | 84 | // ideally should have used menu_page_url, but it is loaded later than some usages. |
85 | - $url = admin_url( 'admin.php?page=' . $this->get_menu_slug() ); |
|
85 | + $url = admin_url('admin.php?page='.$this->get_menu_slug()); |
|
86 | 86 | |
87 | - return esc_url( $url ); |
|
87 | + return esc_url($url); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -110,14 +110,14 @@ discard block |
||
110 | 110 | $this->get_parent_slug(), |
111 | 111 | $this->get_page_title(), |
112 | 112 | $this->get_menu_title(), |
113 | - $this->get_capability(), // The required capability, provided by the calling hook. |
|
113 | + $this->get_capability(), // The required capability, provided by the calling hook. |
|
114 | 114 | $this->get_menu_slug(), |
115 | - array( $this, 'render' ) |
|
115 | + array($this, 'render') |
|
116 | 116 | ); |
117 | 117 | |
118 | 118 | // Set a hook to enqueue scripts only when the settings page is displayed. |
119 | 119 | add_action( |
120 | - 'admin_print_scripts-' . $page, |
|
120 | + 'admin_print_scripts-'.$page, |
|
121 | 121 | array( |
122 | 122 | $this, |
123 | 123 | 'enqueue_scripts', |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | public function render() { |
144 | 144 | |
145 | 145 | // Include the partial. |
146 | - include plugin_dir_path( __FILE__ ) . 'partials/' . $this->get_partial_name(); |
|
146 | + include plugin_dir_path(__FILE__).'partials/'.$this->get_partial_name(); |
|
147 | 147 | |
148 | 148 | } |
149 | 149 |
@@ -30,393 +30,393 @@ |
||
30 | 30 | */ |
31 | 31 | class Wordlift_Admin { |
32 | 32 | |
33 | - /** |
|
34 | - * The singleton instance. |
|
35 | - * |
|
36 | - * @since 3.19.4 |
|
37 | - * @access private |
|
38 | - * @var Wordlift_Admin $instance The singleton instance. |
|
39 | - */ |
|
40 | - private static $instance; |
|
41 | - /** |
|
42 | - * The ID of this plugin. |
|
43 | - * |
|
44 | - * @since 1.0.0 |
|
45 | - * @access private |
|
46 | - * @var string $plugin_name The ID of this plugin. |
|
47 | - */ |
|
48 | - private $plugin_name; |
|
49 | - /** |
|
50 | - * The version of this plugin. |
|
51 | - * |
|
52 | - * @since 1.0.0 |
|
53 | - * @access private |
|
54 | - * @var string $version The current version of this plugin. |
|
55 | - */ |
|
56 | - private $version; |
|
57 | - /** |
|
58 | - * The {@link Wordlift_User_Service} instance. |
|
59 | - * |
|
60 | - * @since 3.14.0 |
|
61 | - * @access private |
|
62 | - * @var Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance. |
|
63 | - */ |
|
64 | - private $user_service; |
|
65 | - /** |
|
66 | - * The {@link Wordlift_Batch_Operation_Ajax_Adapter} instance. |
|
67 | - * |
|
68 | - * @since 3.20.0 |
|
69 | - * @access private |
|
70 | - * @var Wordlift_Batch_Operation_Ajax_Adapter $sync_batch_operation_ajax_adapter The {@link Wordlift_Batch_Operation_Ajax_Adapter} instance. |
|
71 | - */ |
|
72 | - private $sync_batch_operation_ajax_adapter; |
|
73 | - |
|
74 | - /** |
|
75 | - * Initialize the class and set its properties. |
|
76 | - * |
|
77 | - * @param string $plugin_name The name of this plugin. |
|
78 | - * @param string $version The version of this plugin. |
|
79 | - * @param Wordlift_Notice_Service $notice_service The notice service. |
|
80 | - * @param Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance. |
|
81 | - * |
|
82 | - * @since 1.0.0 |
|
83 | - */ |
|
84 | - public function __construct( $plugin_name, $version, $notice_service, $user_service ) { |
|
85 | - |
|
86 | - $this->plugin_name = $plugin_name; |
|
87 | - $this->version = $version; |
|
88 | - |
|
89 | - $this->user_service = $user_service; |
|
90 | - |
|
91 | - $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
92 | - $dataset_uri = $configuration_service->get_dataset_uri(); |
|
93 | - $key = $configuration_service->get_key(); |
|
94 | - $features_registry = Features_Registry::get_instance(); |
|
95 | - if ( empty( $dataset_uri ) ) { |
|
96 | - $settings_page = Wordlift_Admin_Settings_Page::get_instance(); |
|
97 | - if ( empty( $key ) ) { |
|
98 | - /* translators: %s: The link to the settings page. */ |
|
99 | - $error = sprintf( esc_html__( "WordLift's key isn't set, please open the %s to set WordLift's key.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' ); |
|
100 | - } else { |
|
101 | - /* translators: %s: The link to the settings page. */ |
|
102 | - $error = sprintf( esc_html__( "WordLift's dataset URI is not configured: please open the %s to set WordLift's key again.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' ); |
|
103 | - } |
|
104 | - $notice_service->add_error( $error ); |
|
105 | - } |
|
106 | - |
|
107 | - // Load additional code if we're in the admin UI. |
|
108 | - if ( is_admin() ) { |
|
109 | - |
|
110 | - // Require the PHP files for the next code fragment. |
|
111 | - self::require_files(); |
|
112 | - |
|
113 | - /* |
|
33 | + /** |
|
34 | + * The singleton instance. |
|
35 | + * |
|
36 | + * @since 3.19.4 |
|
37 | + * @access private |
|
38 | + * @var Wordlift_Admin $instance The singleton instance. |
|
39 | + */ |
|
40 | + private static $instance; |
|
41 | + /** |
|
42 | + * The ID of this plugin. |
|
43 | + * |
|
44 | + * @since 1.0.0 |
|
45 | + * @access private |
|
46 | + * @var string $plugin_name The ID of this plugin. |
|
47 | + */ |
|
48 | + private $plugin_name; |
|
49 | + /** |
|
50 | + * The version of this plugin. |
|
51 | + * |
|
52 | + * @since 1.0.0 |
|
53 | + * @access private |
|
54 | + * @var string $version The current version of this plugin. |
|
55 | + */ |
|
56 | + private $version; |
|
57 | + /** |
|
58 | + * The {@link Wordlift_User_Service} instance. |
|
59 | + * |
|
60 | + * @since 3.14.0 |
|
61 | + * @access private |
|
62 | + * @var Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance. |
|
63 | + */ |
|
64 | + private $user_service; |
|
65 | + /** |
|
66 | + * The {@link Wordlift_Batch_Operation_Ajax_Adapter} instance. |
|
67 | + * |
|
68 | + * @since 3.20.0 |
|
69 | + * @access private |
|
70 | + * @var Wordlift_Batch_Operation_Ajax_Adapter $sync_batch_operation_ajax_adapter The {@link Wordlift_Batch_Operation_Ajax_Adapter} instance. |
|
71 | + */ |
|
72 | + private $sync_batch_operation_ajax_adapter; |
|
73 | + |
|
74 | + /** |
|
75 | + * Initialize the class and set its properties. |
|
76 | + * |
|
77 | + * @param string $plugin_name The name of this plugin. |
|
78 | + * @param string $version The version of this plugin. |
|
79 | + * @param Wordlift_Notice_Service $notice_service The notice service. |
|
80 | + * @param Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance. |
|
81 | + * |
|
82 | + * @since 1.0.0 |
|
83 | + */ |
|
84 | + public function __construct( $plugin_name, $version, $notice_service, $user_service ) { |
|
85 | + |
|
86 | + $this->plugin_name = $plugin_name; |
|
87 | + $this->version = $version; |
|
88 | + |
|
89 | + $this->user_service = $user_service; |
|
90 | + |
|
91 | + $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
92 | + $dataset_uri = $configuration_service->get_dataset_uri(); |
|
93 | + $key = $configuration_service->get_key(); |
|
94 | + $features_registry = Features_Registry::get_instance(); |
|
95 | + if ( empty( $dataset_uri ) ) { |
|
96 | + $settings_page = Wordlift_Admin_Settings_Page::get_instance(); |
|
97 | + if ( empty( $key ) ) { |
|
98 | + /* translators: %s: The link to the settings page. */ |
|
99 | + $error = sprintf( esc_html__( "WordLift's key isn't set, please open the %s to set WordLift's key.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' ); |
|
100 | + } else { |
|
101 | + /* translators: %s: The link to the settings page. */ |
|
102 | + $error = sprintf( esc_html__( "WordLift's dataset URI is not configured: please open the %s to set WordLift's key again.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' ); |
|
103 | + } |
|
104 | + $notice_service->add_error( $error ); |
|
105 | + } |
|
106 | + |
|
107 | + // Load additional code if we're in the admin UI. |
|
108 | + if ( is_admin() ) { |
|
109 | + |
|
110 | + // Require the PHP files for the next code fragment. |
|
111 | + self::require_files(); |
|
112 | + |
|
113 | + /* |
|
114 | 114 | * @since 3.24.2 This function isn't called anymore because it was causing the Block Category to |
115 | 115 | * multiply in Block Editor. |
116 | 116 | * |
117 | 117 | * @see https://github.com/insideout10/wordlift-plugin/issues/1004 |
118 | 118 | */ |
119 | - // Add Wordlift custom block category. |
|
120 | - // self::add_block_category(); |
|
119 | + // Add Wordlift custom block category. |
|
120 | + // self::add_block_category(); |
|
121 | 121 | |
122 | - new Wordlift_Dashboard_Latest_News(); |
|
122 | + new Wordlift_Dashboard_Latest_News(); |
|
123 | 123 | |
124 | - /* |
|
124 | + /* |
|
125 | 125 | * Add support for `All Entity Types`. |
126 | 126 | * |
127 | 127 | * @since 3.20.0 |
128 | 128 | * |
129 | 129 | * @see https://github.com/insideout10/wordlift-plugin/issues/835 |
130 | 130 | */ |
131 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
132 | - if ( apply_filters( 'wl_feature__enable__all-entity-types', WL_ALL_ENTITY_TYPES ) ) { |
|
131 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
132 | + if ( apply_filters( 'wl_feature__enable__all-entity-types', WL_ALL_ENTITY_TYPES ) ) { |
|
133 | 133 | |
134 | - require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-schemaorg-taxonomy-metabox.php'; |
|
135 | - /* |
|
134 | + require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-schemaorg-taxonomy-metabox.php'; |
|
135 | + /* |
|
136 | 136 | * The `Mappings` admin page. |
137 | 137 | */ |
138 | - require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-mappings-page.php'; |
|
138 | + require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-mappings-page.php'; |
|
139 | 139 | |
140 | - new Wordlift_Admin_Mappings_Page(); |
|
140 | + new Wordlift_Admin_Mappings_Page(); |
|
141 | 141 | |
142 | - /* |
|
142 | + /* |
|
143 | 143 | * Allow sync'ing the schema.org taxonomy with the schema.org json file. |
144 | 144 | * |
145 | 145 | * @since 3.20.0 |
146 | 146 | */ |
147 | - require_once plugin_dir_path( __DIR__ ) . 'includes/schemaorg/class-wordlift-schemaorg-sync-batch-operation.php'; |
|
147 | + require_once plugin_dir_path( __DIR__ ) . 'includes/schemaorg/class-wordlift-schemaorg-sync-batch-operation.php'; |
|
148 | 148 | |
149 | - $this->sync_batch_operation_ajax_adapter = new Wordlift_Batch_Operation_Ajax_Adapter( new Wordlift_Schemaorg_Sync_Batch_Operation(), 'wl_schemaorg_sync' ); |
|
149 | + $this->sync_batch_operation_ajax_adapter = new Wordlift_Batch_Operation_Ajax_Adapter( new Wordlift_Schemaorg_Sync_Batch_Operation(), 'wl_schemaorg_sync' ); |
|
150 | 150 | |
151 | - } |
|
151 | + } |
|
152 | 152 | |
153 | - /* |
|
153 | + /* |
|
154 | 154 | * Add the {@link Wordlift_Admin_Term_Adapter}. |
155 | 155 | * |
156 | 156 | * @since 3.20.0 |
157 | 157 | */ |
158 | - require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-term-adapter.php'; |
|
159 | - new Wordlift_Admin_Term_Adapter(); |
|
158 | + require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-term-adapter.php'; |
|
159 | + new Wordlift_Admin_Term_Adapter(); |
|
160 | 160 | |
161 | - /* |
|
161 | + /* |
|
162 | 162 | * The new dashboard. |
163 | 163 | * |
164 | 164 | * @since 3.20.0 |
165 | 165 | * |
166 | 166 | * @see https://github.com/insideout10/wordlift-plugin/issues/879 |
167 | 167 | */ |
168 | - new Wordlift_Admin_Dashboard_V2( |
|
169 | - Wordlift_Entity_Service::get_instance() |
|
170 | - ); |
|
171 | - new Wordlift_Admin_Not_Enriched_Filter(); |
|
172 | - |
|
173 | - } |
|
174 | - |
|
175 | - // @@todo only load this class if ACF is available. |
|
176 | - // Add support for ACF mappings, so that the admin edit mappings page can pick up ACF support when ACF is available. |
|
177 | - new Acf_Mappings(); |
|
178 | - |
|
179 | - // Add the Mappings' REST Controller. |
|
180 | - new Mappings_REST_Controller(); |
|
181 | - |
|
182 | - $features_registry->register_feature_from_slug( |
|
183 | - 'mappings', |
|
184 | - ( defined( 'WL_ENABLE_MAPPINGS' ) && WL_ENABLE_MAPPINGS ), |
|
185 | - array( $this, 'init_mappings' ) |
|
186 | - ); |
|
187 | - |
|
188 | - // Set the singleton instance. |
|
189 | - self::$instance = $this; |
|
190 | - |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Require files needed for the Admin UI. |
|
195 | - * |
|
196 | - * @since 3.20.0 |
|
197 | - */ |
|
198 | - private static function require_files() { |
|
199 | - |
|
200 | - require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-dashboard-latest-news.php'; |
|
201 | - require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-dashboard-v2.php'; |
|
202 | - require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-not-enriched-filter.php'; |
|
203 | - |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * Get the singleton instance. |
|
208 | - * |
|
209 | - * @return Wordlift_Admin The singleton instance. |
|
210 | - * @since 3.19.4 |
|
211 | - */ |
|
212 | - public static function get_instance() { |
|
213 | - |
|
214 | - return self::$instance; |
|
215 | - } |
|
216 | - |
|
217 | - public static function is_gutenberg() { |
|
218 | - if ( function_exists( 'is_gutenberg_page' ) && |
|
219 | - is_gutenberg_page() |
|
220 | - ) { |
|
221 | - // The Gutenberg plugin is on. |
|
222 | - return true; |
|
223 | - } |
|
224 | - $current_screen = get_current_screen(); |
|
225 | - if ( method_exists( $current_screen, 'is_block_editor' ) && |
|
226 | - $current_screen->is_block_editor() |
|
227 | - ) { |
|
228 | - // Gutenberg page on 5+. |
|
229 | - return true; |
|
230 | - } |
|
231 | - |
|
232 | - return false; |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Register the stylesheets for the admin area. |
|
237 | - * |
|
238 | - * @since 1.0.0 |
|
239 | - */ |
|
240 | - public function enqueue_styles() { |
|
241 | - |
|
242 | - /** |
|
243 | - * This function is provided for demonstration purposes only. |
|
244 | - * |
|
245 | - * An instance of this class should be passed to the run() function |
|
246 | - * defined in Wordlift_Loader as all of the hooks are defined |
|
247 | - * in that particular class. |
|
248 | - * |
|
249 | - * The Wordlift_Loader will then create the relationship |
|
250 | - * between the defined hooks and the functions defined in this |
|
251 | - * class. |
|
252 | - */ |
|
253 | - |
|
254 | - wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' ); |
|
255 | - |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Register the JavaScript for the admin area. |
|
260 | - * |
|
261 | - * @since 1.0.0 |
|
262 | - */ |
|
263 | - public function enqueue_scripts() { |
|
264 | - |
|
265 | - /* |
|
168 | + new Wordlift_Admin_Dashboard_V2( |
|
169 | + Wordlift_Entity_Service::get_instance() |
|
170 | + ); |
|
171 | + new Wordlift_Admin_Not_Enriched_Filter(); |
|
172 | + |
|
173 | + } |
|
174 | + |
|
175 | + // @@todo only load this class if ACF is available. |
|
176 | + // Add support for ACF mappings, so that the admin edit mappings page can pick up ACF support when ACF is available. |
|
177 | + new Acf_Mappings(); |
|
178 | + |
|
179 | + // Add the Mappings' REST Controller. |
|
180 | + new Mappings_REST_Controller(); |
|
181 | + |
|
182 | + $features_registry->register_feature_from_slug( |
|
183 | + 'mappings', |
|
184 | + ( defined( 'WL_ENABLE_MAPPINGS' ) && WL_ENABLE_MAPPINGS ), |
|
185 | + array( $this, 'init_mappings' ) |
|
186 | + ); |
|
187 | + |
|
188 | + // Set the singleton instance. |
|
189 | + self::$instance = $this; |
|
190 | + |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Require files needed for the Admin UI. |
|
195 | + * |
|
196 | + * @since 3.20.0 |
|
197 | + */ |
|
198 | + private static function require_files() { |
|
199 | + |
|
200 | + require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-dashboard-latest-news.php'; |
|
201 | + require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-dashboard-v2.php'; |
|
202 | + require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-not-enriched-filter.php'; |
|
203 | + |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * Get the singleton instance. |
|
208 | + * |
|
209 | + * @return Wordlift_Admin The singleton instance. |
|
210 | + * @since 3.19.4 |
|
211 | + */ |
|
212 | + public static function get_instance() { |
|
213 | + |
|
214 | + return self::$instance; |
|
215 | + } |
|
216 | + |
|
217 | + public static function is_gutenberg() { |
|
218 | + if ( function_exists( 'is_gutenberg_page' ) && |
|
219 | + is_gutenberg_page() |
|
220 | + ) { |
|
221 | + // The Gutenberg plugin is on. |
|
222 | + return true; |
|
223 | + } |
|
224 | + $current_screen = get_current_screen(); |
|
225 | + if ( method_exists( $current_screen, 'is_block_editor' ) && |
|
226 | + $current_screen->is_block_editor() |
|
227 | + ) { |
|
228 | + // Gutenberg page on 5+. |
|
229 | + return true; |
|
230 | + } |
|
231 | + |
|
232 | + return false; |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Register the stylesheets for the admin area. |
|
237 | + * |
|
238 | + * @since 1.0.0 |
|
239 | + */ |
|
240 | + public function enqueue_styles() { |
|
241 | + |
|
242 | + /** |
|
243 | + * This function is provided for demonstration purposes only. |
|
244 | + * |
|
245 | + * An instance of this class should be passed to the run() function |
|
246 | + * defined in Wordlift_Loader as all of the hooks are defined |
|
247 | + * in that particular class. |
|
248 | + * |
|
249 | + * The Wordlift_Loader will then create the relationship |
|
250 | + * between the defined hooks and the functions defined in this |
|
251 | + * class. |
|
252 | + */ |
|
253 | + |
|
254 | + wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' ); |
|
255 | + |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Register the JavaScript for the admin area. |
|
260 | + * |
|
261 | + * @since 1.0.0 |
|
262 | + */ |
|
263 | + public function enqueue_scripts() { |
|
264 | + |
|
265 | + /* |
|
266 | 266 | * Do not load our scripts on the Filter Urls plugin admin pages. |
267 | 267 | * |
268 | 268 | * @see https://github.com/insideout10/wordlift-plugin/issues/901 |
269 | 269 | * @since 3.20.0 |
270 | 270 | */ |
271 | - $screen = get_current_screen(); |
|
272 | - if ( is_a( $screen, 'WP_Screen' ) && 'filter-urls_page_filter_urls_form' === $screen->id ) { |
|
273 | - return; |
|
274 | - } |
|
275 | - |
|
276 | - // Enqueue the admin scripts. |
|
277 | - wp_enqueue_script( |
|
278 | - $this->plugin_name, |
|
279 | - plugin_dir_url( __FILE__ ) . 'js/1/admin.js', |
|
280 | - array( |
|
281 | - 'jquery', |
|
282 | - 'underscore', |
|
283 | - 'backbone', |
|
284 | - ), |
|
285 | - $this->version, |
|
286 | - false |
|
287 | - ); |
|
288 | - |
|
289 | - $params = $this->get_params(); |
|
290 | - |
|
291 | - // Finally output the params as `wlSettings` for JavaScript code. |
|
292 | - wp_localize_script( $this->plugin_name, 'wlSettings', apply_filters( 'wl_admin_settings', $params ) ); |
|
293 | - |
|
294 | - } |
|
295 | - |
|
296 | - /** |
|
297 | - * Return the settings array by applying filters. |
|
298 | - * |
|
299 | - * @return array |
|
300 | - */ |
|
301 | - public function get_params() { |
|
302 | - $can_edit_wordlift_entities = current_user_can( 'edit_wordlift_entities' ); |
|
303 | - /* |
|
271 | + $screen = get_current_screen(); |
|
272 | + if ( is_a( $screen, 'WP_Screen' ) && 'filter-urls_page_filter_urls_form' === $screen->id ) { |
|
273 | + return; |
|
274 | + } |
|
275 | + |
|
276 | + // Enqueue the admin scripts. |
|
277 | + wp_enqueue_script( |
|
278 | + $this->plugin_name, |
|
279 | + plugin_dir_url( __FILE__ ) . 'js/1/admin.js', |
|
280 | + array( |
|
281 | + 'jquery', |
|
282 | + 'underscore', |
|
283 | + 'backbone', |
|
284 | + ), |
|
285 | + $this->version, |
|
286 | + false |
|
287 | + ); |
|
288 | + |
|
289 | + $params = $this->get_params(); |
|
290 | + |
|
291 | + // Finally output the params as `wlSettings` for JavaScript code. |
|
292 | + wp_localize_script( $this->plugin_name, 'wlSettings', apply_filters( 'wl_admin_settings', $params ) ); |
|
293 | + |
|
294 | + } |
|
295 | + |
|
296 | + /** |
|
297 | + * Return the settings array by applying filters. |
|
298 | + * |
|
299 | + * @return array |
|
300 | + */ |
|
301 | + public function get_params() { |
|
302 | + $can_edit_wordlift_entities = current_user_can( 'edit_wordlift_entities' ); |
|
303 | + /* |
|
304 | 304 | * People that can create entities will see the scope set in the wp-config.php file (by default `cloud`). People |
305 | 305 | * that cannot edit create entities will always see the local entities. |
306 | 306 | * |
307 | 307 | * @see https://github.com/insideout10/wordlift-plugin/issues/839 |
308 | 308 | */ |
309 | - $autocomplete_scope = $can_edit_wordlift_entities ? WL_AUTOCOMPLETE_SCOPE : 'local'; |
|
310 | - |
|
311 | - // Set the basic params. |
|
312 | - $params = array( |
|
313 | - // @todo scripts in admin should use wp.post. |
|
314 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
315 | - // @todo remove specific actions from settings. |
|
316 | - 'action' => 'entity_by_title', |
|
317 | - 'datasetUri' => Wordlift_Configuration_Service::get_instance()->get_dataset_uri(), |
|
318 | - 'language' => Wordlift_Configuration_Service::get_instance()->get_language_code(), |
|
319 | - 'link_by_default' => Wordlift_Configuration_Service::get_instance()->is_link_by_default(), |
|
320 | - // Whether the current user is allowed to create new entities. |
|
321 | - // |
|
322 | - // @see https://github.com/insideout10/wordlift-plugin/issues/561 |
|
323 | - // @see https://github.com/insideout10/wordlift-plugin/issues/1267 |
|
324 | - 'can_create_entities' => apply_filters( 'wl_feature__enable__dataset', true ) ? ( $can_edit_wordlift_entities ? 'yes' : 'no' ) : 'no', |
|
325 | - 'l10n' => array( |
|
326 | - 'You already published an entity with the same name' => __( 'You already published an entity with the same name: ', 'wordlift' ), |
|
327 | - 'logo_selection_title' => __( 'WordLift Choose Logo', 'wordlift' ), |
|
328 | - 'logo_selection_button' => array( 'text' => __( 'Choose Logo', 'wordlift' ) ), |
|
329 | - 'Type at least 3 characters to search...' => _x( 'Type at least 3 characters to search...', 'Autocomplete Select', 'wordlift' ), |
|
330 | - 'No results found for your search.' => _x( 'No results found: try changing or removing some words.', 'Autocomplete Select', 'wordlift' ), |
|
331 | - 'Please wait while we look for entities in the linked data cloud...' => _x( 'Please wait while we look for entities in the linked data cloud...', 'Autocomplete Select', 'wordlift' ), |
|
332 | - 'Add keywords to track' => __( 'Add Keywords to track', 'wordlift' ), |
|
333 | - ), |
|
334 | - 'wl_autocomplete_nonce' => wp_create_nonce( 'wl_autocomplete' ), |
|
335 | - 'autocomplete_scope' => $autocomplete_scope, |
|
336 | - /** |
|
337 | - * Allow 3rd parties to define the default editor id. This turns useful if 3rd parties load |
|
338 | - * or change the TinyMCE id. |
|
339 | - * |
|
340 | - * The editor id is currently referenced by `src/coffee/editpost-widget/app.services.EditorAdapter.coffee`. |
|
341 | - * |
|
342 | - * @param string $editor The default editor id, by default `content`. |
|
343 | - * |
|
344 | - * @see https://github.com/insideout10/wordlift-plugin/issues/848 |
|
345 | - * |
|
346 | - * @since 3.19.4 |
|
347 | - */ |
|
348 | - 'default_editor_id' => apply_filters( 'wl_default_editor_id', 'content' ), |
|
349 | - |
|
350 | - 'analysis' => array( '_wpnonce' => wp_create_nonce( 'wl_analyze' ) ), |
|
351 | - /** |
|
352 | - * Faceted search default limit |
|
353 | - * |
|
354 | - * @since 3.26.1 |
|
355 | - */ |
|
356 | - 'faceted_search_default_limit' => apply_filters( 'wl_faceted_search_default_limit', 10 ), |
|
357 | - /** |
|
358 | - * WL Root path, to access in JS |
|
359 | - * |
|
360 | - * @since 3.27.3 |
|
361 | - */ |
|
362 | - 'wl_root' => plugin_dir_url( __DIR__ ), |
|
363 | - /** |
|
364 | - * Enable synonyms, to access in JS |
|
365 | - * Show classification sidebar, to access in JS |
|
366 | - * |
|
367 | - * @since 3.30.0 |
|
368 | - */ |
|
369 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
370 | - 'can_add_synonyms' => apply_filters( 'wl_feature__enable__add-synonyms', true ), |
|
371 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
372 | - 'show_classification_sidebar' => apply_filters( 'wl_feature__enable__classification-sidebar', true ), |
|
373 | - // By default the videoobject should not show. |
|
374 | - 'show_videoobject' => apply_filters( 'wl_feature__enable__videoobject', false ), |
|
375 | - ); |
|
376 | - |
|
377 | - // Set post-related values if there's a current post. |
|
378 | - $entity_being_edited = get_post(); |
|
379 | - $post = $entity_being_edited; |
|
380 | - if ( null !== $post ) { |
|
381 | - |
|
382 | - $params['post_id'] = $entity_being_edited->ID; |
|
383 | - $entity_service = Wordlift_Entity_Service::get_instance(); |
|
384 | - $params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && $entity_service->is_entity( $post->ID ) && is_numeric( get_the_ID() ); |
|
385 | - // We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it |
|
386 | - // from the results, since we don't want the current entity to be discovered by the analysis. |
|
387 | - // |
|
388 | - // See https://github.com/insideout10/wordlift-plugin/issues/345 |
|
389 | - $params['itemId'] = $entity_service->get_uri( $entity_being_edited->ID ); |
|
390 | - $params['wl_schemaorg_property_nonce'] = wp_create_nonce( 'wl_schemaorg_property' ); |
|
391 | - |
|
392 | - /* |
|
309 | + $autocomplete_scope = $can_edit_wordlift_entities ? WL_AUTOCOMPLETE_SCOPE : 'local'; |
|
310 | + |
|
311 | + // Set the basic params. |
|
312 | + $params = array( |
|
313 | + // @todo scripts in admin should use wp.post. |
|
314 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
315 | + // @todo remove specific actions from settings. |
|
316 | + 'action' => 'entity_by_title', |
|
317 | + 'datasetUri' => Wordlift_Configuration_Service::get_instance()->get_dataset_uri(), |
|
318 | + 'language' => Wordlift_Configuration_Service::get_instance()->get_language_code(), |
|
319 | + 'link_by_default' => Wordlift_Configuration_Service::get_instance()->is_link_by_default(), |
|
320 | + // Whether the current user is allowed to create new entities. |
|
321 | + // |
|
322 | + // @see https://github.com/insideout10/wordlift-plugin/issues/561 |
|
323 | + // @see https://github.com/insideout10/wordlift-plugin/issues/1267 |
|
324 | + 'can_create_entities' => apply_filters( 'wl_feature__enable__dataset', true ) ? ( $can_edit_wordlift_entities ? 'yes' : 'no' ) : 'no', |
|
325 | + 'l10n' => array( |
|
326 | + 'You already published an entity with the same name' => __( 'You already published an entity with the same name: ', 'wordlift' ), |
|
327 | + 'logo_selection_title' => __( 'WordLift Choose Logo', 'wordlift' ), |
|
328 | + 'logo_selection_button' => array( 'text' => __( 'Choose Logo', 'wordlift' ) ), |
|
329 | + 'Type at least 3 characters to search...' => _x( 'Type at least 3 characters to search...', 'Autocomplete Select', 'wordlift' ), |
|
330 | + 'No results found for your search.' => _x( 'No results found: try changing or removing some words.', 'Autocomplete Select', 'wordlift' ), |
|
331 | + 'Please wait while we look for entities in the linked data cloud...' => _x( 'Please wait while we look for entities in the linked data cloud...', 'Autocomplete Select', 'wordlift' ), |
|
332 | + 'Add keywords to track' => __( 'Add Keywords to track', 'wordlift' ), |
|
333 | + ), |
|
334 | + 'wl_autocomplete_nonce' => wp_create_nonce( 'wl_autocomplete' ), |
|
335 | + 'autocomplete_scope' => $autocomplete_scope, |
|
336 | + /** |
|
337 | + * Allow 3rd parties to define the default editor id. This turns useful if 3rd parties load |
|
338 | + * or change the TinyMCE id. |
|
339 | + * |
|
340 | + * The editor id is currently referenced by `src/coffee/editpost-widget/app.services.EditorAdapter.coffee`. |
|
341 | + * |
|
342 | + * @param string $editor The default editor id, by default `content`. |
|
343 | + * |
|
344 | + * @see https://github.com/insideout10/wordlift-plugin/issues/848 |
|
345 | + * |
|
346 | + * @since 3.19.4 |
|
347 | + */ |
|
348 | + 'default_editor_id' => apply_filters( 'wl_default_editor_id', 'content' ), |
|
349 | + |
|
350 | + 'analysis' => array( '_wpnonce' => wp_create_nonce( 'wl_analyze' ) ), |
|
351 | + /** |
|
352 | + * Faceted search default limit |
|
353 | + * |
|
354 | + * @since 3.26.1 |
|
355 | + */ |
|
356 | + 'faceted_search_default_limit' => apply_filters( 'wl_faceted_search_default_limit', 10 ), |
|
357 | + /** |
|
358 | + * WL Root path, to access in JS |
|
359 | + * |
|
360 | + * @since 3.27.3 |
|
361 | + */ |
|
362 | + 'wl_root' => plugin_dir_url( __DIR__ ), |
|
363 | + /** |
|
364 | + * Enable synonyms, to access in JS |
|
365 | + * Show classification sidebar, to access in JS |
|
366 | + * |
|
367 | + * @since 3.30.0 |
|
368 | + */ |
|
369 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
370 | + 'can_add_synonyms' => apply_filters( 'wl_feature__enable__add-synonyms', true ), |
|
371 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
372 | + 'show_classification_sidebar' => apply_filters( 'wl_feature__enable__classification-sidebar', true ), |
|
373 | + // By default the videoobject should not show. |
|
374 | + 'show_videoobject' => apply_filters( 'wl_feature__enable__videoobject', false ), |
|
375 | + ); |
|
376 | + |
|
377 | + // Set post-related values if there's a current post. |
|
378 | + $entity_being_edited = get_post(); |
|
379 | + $post = $entity_being_edited; |
|
380 | + if ( null !== $post ) { |
|
381 | + |
|
382 | + $params['post_id'] = $entity_being_edited->ID; |
|
383 | + $entity_service = Wordlift_Entity_Service::get_instance(); |
|
384 | + $params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && $entity_service->is_entity( $post->ID ) && is_numeric( get_the_ID() ); |
|
385 | + // We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it |
|
386 | + // from the results, since we don't want the current entity to be discovered by the analysis. |
|
387 | + // |
|
388 | + // See https://github.com/insideout10/wordlift-plugin/issues/345 |
|
389 | + $params['itemId'] = $entity_service->get_uri( $entity_being_edited->ID ); |
|
390 | + $params['wl_schemaorg_property_nonce'] = wp_create_nonce( 'wl_schemaorg_property' ); |
|
391 | + |
|
392 | + /* |
|
393 | 393 | * Add the `properties` if `WL_ALL_ENTITY_TYPES` is enabled. |
394 | 394 | * |
395 | 395 | * @see https://github.com/insideout10/wordlift-plugin/issues/835 |
396 | 396 | */ |
397 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
398 | - if ( apply_filters( 'wl_feature__enable__all-entity-types', WL_ALL_ENTITY_TYPES ) ) { |
|
399 | - $params['properties'] = Wordlift_Schemaorg_Property_Service::get_instance()->get_all( $post->ID ); |
|
400 | - } |
|
401 | - } |
|
402 | - |
|
403 | - return $params; |
|
404 | - } |
|
405 | - |
|
406 | - /** |
|
407 | - * Initialize the mappings. |
|
408 | - * |
|
409 | - * @return void |
|
410 | - */ |
|
411 | - public function init_mappings() { |
|
412 | - new Admin_Mappings_Page(); |
|
413 | - /** |
|
414 | - * @since 3.27.0 |
|
415 | - * Hooks in to ui of edit mapping screen, add taxonomy as a option. |
|
416 | - */ |
|
417 | - $taxonomy_option = new Taxonomy_Option(); |
|
418 | - $taxonomy_option->add_taxonomy_option(); |
|
419 | - new Edit_Mappings_Page( new Mappings_Transform_Functions_Registry() ); |
|
420 | - } |
|
397 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
398 | + if ( apply_filters( 'wl_feature__enable__all-entity-types', WL_ALL_ENTITY_TYPES ) ) { |
|
399 | + $params['properties'] = Wordlift_Schemaorg_Property_Service::get_instance()->get_all( $post->ID ); |
|
400 | + } |
|
401 | + } |
|
402 | + |
|
403 | + return $params; |
|
404 | + } |
|
405 | + |
|
406 | + /** |
|
407 | + * Initialize the mappings. |
|
408 | + * |
|
409 | + * @return void |
|
410 | + */ |
|
411 | + public function init_mappings() { |
|
412 | + new Admin_Mappings_Page(); |
|
413 | + /** |
|
414 | + * @since 3.27.0 |
|
415 | + * Hooks in to ui of edit mapping screen, add taxonomy as a option. |
|
416 | + */ |
|
417 | + $taxonomy_option = new Taxonomy_Option(); |
|
418 | + $taxonomy_option->add_taxonomy_option(); |
|
419 | + new Edit_Mappings_Page( new Mappings_Transform_Functions_Registry() ); |
|
420 | + } |
|
421 | 421 | |
422 | 422 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | * |
82 | 82 | * @since 1.0.0 |
83 | 83 | */ |
84 | - public function __construct( $plugin_name, $version, $notice_service, $user_service ) { |
|
84 | + public function __construct($plugin_name, $version, $notice_service, $user_service) { |
|
85 | 85 | |
86 | 86 | $this->plugin_name = $plugin_name; |
87 | 87 | $this->version = $version; |
@@ -92,20 +92,20 @@ discard block |
||
92 | 92 | $dataset_uri = $configuration_service->get_dataset_uri(); |
93 | 93 | $key = $configuration_service->get_key(); |
94 | 94 | $features_registry = Features_Registry::get_instance(); |
95 | - if ( empty( $dataset_uri ) ) { |
|
95 | + if (empty($dataset_uri)) { |
|
96 | 96 | $settings_page = Wordlift_Admin_Settings_Page::get_instance(); |
97 | - if ( empty( $key ) ) { |
|
97 | + if (empty($key)) { |
|
98 | 98 | /* translators: %s: The link to the settings page. */ |
99 | - $error = sprintf( esc_html__( "WordLift's key isn't set, please open the %s to set WordLift's key.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' ); |
|
99 | + $error = sprintf(esc_html__("WordLift's key isn't set, please open the %s to set WordLift's key.", 'wordlift'), '<a href="'.$settings_page->get_url().'">'.esc_html__('settings page', 'wordlift').'</a>'); |
|
100 | 100 | } else { |
101 | 101 | /* translators: %s: The link to the settings page. */ |
102 | - $error = sprintf( esc_html__( "WordLift's dataset URI is not configured: please open the %s to set WordLift's key again.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' ); |
|
102 | + $error = sprintf(esc_html__("WordLift's dataset URI is not configured: please open the %s to set WordLift's key again.", 'wordlift'), '<a href="'.$settings_page->get_url().'">'.esc_html__('settings page', 'wordlift').'</a>'); |
|
103 | 103 | } |
104 | - $notice_service->add_error( $error ); |
|
104 | + $notice_service->add_error($error); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | // Load additional code if we're in the admin UI. |
108 | - if ( is_admin() ) { |
|
108 | + if (is_admin()) { |
|
109 | 109 | |
110 | 110 | // Require the PHP files for the next code fragment. |
111 | 111 | self::require_files(); |
@@ -129,13 +129,13 @@ discard block |
||
129 | 129 | * @see https://github.com/insideout10/wordlift-plugin/issues/835 |
130 | 130 | */ |
131 | 131 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
132 | - if ( apply_filters( 'wl_feature__enable__all-entity-types', WL_ALL_ENTITY_TYPES ) ) { |
|
132 | + if (apply_filters('wl_feature__enable__all-entity-types', WL_ALL_ENTITY_TYPES)) { |
|
133 | 133 | |
134 | - require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-schemaorg-taxonomy-metabox.php'; |
|
134 | + require_once plugin_dir_path(__DIR__).'admin/class-wordlift-admin-schemaorg-taxonomy-metabox.php'; |
|
135 | 135 | /* |
136 | 136 | * The `Mappings` admin page. |
137 | 137 | */ |
138 | - require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-mappings-page.php'; |
|
138 | + require_once plugin_dir_path(__DIR__).'admin/class-wordlift-admin-mappings-page.php'; |
|
139 | 139 | |
140 | 140 | new Wordlift_Admin_Mappings_Page(); |
141 | 141 | |
@@ -144,9 +144,9 @@ discard block |
||
144 | 144 | * |
145 | 145 | * @since 3.20.0 |
146 | 146 | */ |
147 | - require_once plugin_dir_path( __DIR__ ) . 'includes/schemaorg/class-wordlift-schemaorg-sync-batch-operation.php'; |
|
147 | + require_once plugin_dir_path(__DIR__).'includes/schemaorg/class-wordlift-schemaorg-sync-batch-operation.php'; |
|
148 | 148 | |
149 | - $this->sync_batch_operation_ajax_adapter = new Wordlift_Batch_Operation_Ajax_Adapter( new Wordlift_Schemaorg_Sync_Batch_Operation(), 'wl_schemaorg_sync' ); |
|
149 | + $this->sync_batch_operation_ajax_adapter = new Wordlift_Batch_Operation_Ajax_Adapter(new Wordlift_Schemaorg_Sync_Batch_Operation(), 'wl_schemaorg_sync'); |
|
150 | 150 | |
151 | 151 | } |
152 | 152 | |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | * |
156 | 156 | * @since 3.20.0 |
157 | 157 | */ |
158 | - require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-term-adapter.php'; |
|
158 | + require_once plugin_dir_path(__DIR__).'admin/class-wordlift-admin-term-adapter.php'; |
|
159 | 159 | new Wordlift_Admin_Term_Adapter(); |
160 | 160 | |
161 | 161 | /* |
@@ -181,8 +181,8 @@ discard block |
||
181 | 181 | |
182 | 182 | $features_registry->register_feature_from_slug( |
183 | 183 | 'mappings', |
184 | - ( defined( 'WL_ENABLE_MAPPINGS' ) && WL_ENABLE_MAPPINGS ), |
|
185 | - array( $this, 'init_mappings' ) |
|
184 | + (defined('WL_ENABLE_MAPPINGS') && WL_ENABLE_MAPPINGS), |
|
185 | + array($this, 'init_mappings') |
|
186 | 186 | ); |
187 | 187 | |
188 | 188 | // Set the singleton instance. |
@@ -197,9 +197,9 @@ discard block |
||
197 | 197 | */ |
198 | 198 | private static function require_files() { |
199 | 199 | |
200 | - require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-dashboard-latest-news.php'; |
|
201 | - require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-dashboard-v2.php'; |
|
202 | - require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-not-enriched-filter.php'; |
|
200 | + require_once plugin_dir_path(__DIR__).'admin/class-wordlift-dashboard-latest-news.php'; |
|
201 | + require_once plugin_dir_path(__DIR__).'admin/class-wordlift-admin-dashboard-v2.php'; |
|
202 | + require_once plugin_dir_path(__DIR__).'admin/class-wordlift-admin-not-enriched-filter.php'; |
|
203 | 203 | |
204 | 204 | } |
205 | 205 | |
@@ -215,14 +215,14 @@ discard block |
||
215 | 215 | } |
216 | 216 | |
217 | 217 | public static function is_gutenberg() { |
218 | - if ( function_exists( 'is_gutenberg_page' ) && |
|
218 | + if (function_exists('is_gutenberg_page') && |
|
219 | 219 | is_gutenberg_page() |
220 | 220 | ) { |
221 | 221 | // The Gutenberg plugin is on. |
222 | 222 | return true; |
223 | 223 | } |
224 | 224 | $current_screen = get_current_screen(); |
225 | - if ( method_exists( $current_screen, 'is_block_editor' ) && |
|
225 | + if (method_exists($current_screen, 'is_block_editor') && |
|
226 | 226 | $current_screen->is_block_editor() |
227 | 227 | ) { |
228 | 228 | // Gutenberg page on 5+. |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | * class. |
252 | 252 | */ |
253 | 253 | |
254 | - wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' ); |
|
254 | + wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__).'css/wordlift-admin.css', array(), $this->version, 'all'); |
|
255 | 255 | |
256 | 256 | } |
257 | 257 | |
@@ -269,14 +269,14 @@ discard block |
||
269 | 269 | * @since 3.20.0 |
270 | 270 | */ |
271 | 271 | $screen = get_current_screen(); |
272 | - if ( is_a( $screen, 'WP_Screen' ) && 'filter-urls_page_filter_urls_form' === $screen->id ) { |
|
272 | + if (is_a($screen, 'WP_Screen') && 'filter-urls_page_filter_urls_form' === $screen->id) { |
|
273 | 273 | return; |
274 | 274 | } |
275 | 275 | |
276 | 276 | // Enqueue the admin scripts. |
277 | 277 | wp_enqueue_script( |
278 | 278 | $this->plugin_name, |
279 | - plugin_dir_url( __FILE__ ) . 'js/1/admin.js', |
|
279 | + plugin_dir_url(__FILE__).'js/1/admin.js', |
|
280 | 280 | array( |
281 | 281 | 'jquery', |
282 | 282 | 'underscore', |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | $params = $this->get_params(); |
290 | 290 | |
291 | 291 | // Finally output the params as `wlSettings` for JavaScript code. |
292 | - wp_localize_script( $this->plugin_name, 'wlSettings', apply_filters( 'wl_admin_settings', $params ) ); |
|
292 | + wp_localize_script($this->plugin_name, 'wlSettings', apply_filters('wl_admin_settings', $params)); |
|
293 | 293 | |
294 | 294 | } |
295 | 295 | |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | * @return array |
300 | 300 | */ |
301 | 301 | public function get_params() { |
302 | - $can_edit_wordlift_entities = current_user_can( 'edit_wordlift_entities' ); |
|
302 | + $can_edit_wordlift_entities = current_user_can('edit_wordlift_entities'); |
|
303 | 303 | /* |
304 | 304 | * People that can create entities will see the scope set in the wp-config.php file (by default `cloud`). People |
305 | 305 | * that cannot edit create entities will always see the local entities. |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | // Set the basic params. |
312 | 312 | $params = array( |
313 | 313 | // @todo scripts in admin should use wp.post. |
314 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
314 | + 'ajax_url' => admin_url('admin-ajax.php'), |
|
315 | 315 | // @todo remove specific actions from settings. |
316 | 316 | 'action' => 'entity_by_title', |
317 | 317 | 'datasetUri' => Wordlift_Configuration_Service::get_instance()->get_dataset_uri(), |
@@ -321,17 +321,17 @@ discard block |
||
321 | 321 | // |
322 | 322 | // @see https://github.com/insideout10/wordlift-plugin/issues/561 |
323 | 323 | // @see https://github.com/insideout10/wordlift-plugin/issues/1267 |
324 | - 'can_create_entities' => apply_filters( 'wl_feature__enable__dataset', true ) ? ( $can_edit_wordlift_entities ? 'yes' : 'no' ) : 'no', |
|
324 | + 'can_create_entities' => apply_filters('wl_feature__enable__dataset', true) ? ($can_edit_wordlift_entities ? 'yes' : 'no') : 'no', |
|
325 | 325 | 'l10n' => array( |
326 | - 'You already published an entity with the same name' => __( 'You already published an entity with the same name: ', 'wordlift' ), |
|
327 | - 'logo_selection_title' => __( 'WordLift Choose Logo', 'wordlift' ), |
|
328 | - 'logo_selection_button' => array( 'text' => __( 'Choose Logo', 'wordlift' ) ), |
|
329 | - 'Type at least 3 characters to search...' => _x( 'Type at least 3 characters to search...', 'Autocomplete Select', 'wordlift' ), |
|
330 | - 'No results found for your search.' => _x( 'No results found: try changing or removing some words.', 'Autocomplete Select', 'wordlift' ), |
|
331 | - 'Please wait while we look for entities in the linked data cloud...' => _x( 'Please wait while we look for entities in the linked data cloud...', 'Autocomplete Select', 'wordlift' ), |
|
332 | - 'Add keywords to track' => __( 'Add Keywords to track', 'wordlift' ), |
|
326 | + 'You already published an entity with the same name' => __('You already published an entity with the same name: ', 'wordlift'), |
|
327 | + 'logo_selection_title' => __('WordLift Choose Logo', 'wordlift'), |
|
328 | + 'logo_selection_button' => array('text' => __('Choose Logo', 'wordlift')), |
|
329 | + 'Type at least 3 characters to search...' => _x('Type at least 3 characters to search...', 'Autocomplete Select', 'wordlift'), |
|
330 | + 'No results found for your search.' => _x('No results found: try changing or removing some words.', 'Autocomplete Select', 'wordlift'), |
|
331 | + 'Please wait while we look for entities in the linked data cloud...' => _x('Please wait while we look for entities in the linked data cloud...', 'Autocomplete Select', 'wordlift'), |
|
332 | + 'Add keywords to track' => __('Add Keywords to track', 'wordlift'), |
|
333 | 333 | ), |
334 | - 'wl_autocomplete_nonce' => wp_create_nonce( 'wl_autocomplete' ), |
|
334 | + 'wl_autocomplete_nonce' => wp_create_nonce('wl_autocomplete'), |
|
335 | 335 | 'autocomplete_scope' => $autocomplete_scope, |
336 | 336 | /** |
337 | 337 | * Allow 3rd parties to define the default editor id. This turns useful if 3rd parties load |
@@ -345,21 +345,21 @@ discard block |
||
345 | 345 | * |
346 | 346 | * @since 3.19.4 |
347 | 347 | */ |
348 | - 'default_editor_id' => apply_filters( 'wl_default_editor_id', 'content' ), |
|
348 | + 'default_editor_id' => apply_filters('wl_default_editor_id', 'content'), |
|
349 | 349 | |
350 | - 'analysis' => array( '_wpnonce' => wp_create_nonce( 'wl_analyze' ) ), |
|
350 | + 'analysis' => array('_wpnonce' => wp_create_nonce('wl_analyze')), |
|
351 | 351 | /** |
352 | 352 | * Faceted search default limit |
353 | 353 | * |
354 | 354 | * @since 3.26.1 |
355 | 355 | */ |
356 | - 'faceted_search_default_limit' => apply_filters( 'wl_faceted_search_default_limit', 10 ), |
|
356 | + 'faceted_search_default_limit' => apply_filters('wl_faceted_search_default_limit', 10), |
|
357 | 357 | /** |
358 | 358 | * WL Root path, to access in JS |
359 | 359 | * |
360 | 360 | * @since 3.27.3 |
361 | 361 | */ |
362 | - 'wl_root' => plugin_dir_url( __DIR__ ), |
|
362 | + 'wl_root' => plugin_dir_url(__DIR__), |
|
363 | 363 | /** |
364 | 364 | * Enable synonyms, to access in JS |
365 | 365 | * Show classification sidebar, to access in JS |
@@ -367,27 +367,27 @@ discard block |
||
367 | 367 | * @since 3.30.0 |
368 | 368 | */ |
369 | 369 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
370 | - 'can_add_synonyms' => apply_filters( 'wl_feature__enable__add-synonyms', true ), |
|
370 | + 'can_add_synonyms' => apply_filters('wl_feature__enable__add-synonyms', true), |
|
371 | 371 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
372 | - 'show_classification_sidebar' => apply_filters( 'wl_feature__enable__classification-sidebar', true ), |
|
372 | + 'show_classification_sidebar' => apply_filters('wl_feature__enable__classification-sidebar', true), |
|
373 | 373 | // By default the videoobject should not show. |
374 | - 'show_videoobject' => apply_filters( 'wl_feature__enable__videoobject', false ), |
|
374 | + 'show_videoobject' => apply_filters('wl_feature__enable__videoobject', false), |
|
375 | 375 | ); |
376 | 376 | |
377 | 377 | // Set post-related values if there's a current post. |
378 | 378 | $entity_being_edited = get_post(); |
379 | 379 | $post = $entity_being_edited; |
380 | - if ( null !== $post ) { |
|
380 | + if (null !== $post) { |
|
381 | 381 | |
382 | 382 | $params['post_id'] = $entity_being_edited->ID; |
383 | 383 | $entity_service = Wordlift_Entity_Service::get_instance(); |
384 | - $params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && $entity_service->is_entity( $post->ID ) && is_numeric( get_the_ID() ); |
|
384 | + $params['entityBeingEdited'] = isset($entity_being_edited->post_type) && $entity_service->is_entity($post->ID) && is_numeric(get_the_ID()); |
|
385 | 385 | // We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it |
386 | 386 | // from the results, since we don't want the current entity to be discovered by the analysis. |
387 | 387 | // |
388 | 388 | // See https://github.com/insideout10/wordlift-plugin/issues/345 |
389 | - $params['itemId'] = $entity_service->get_uri( $entity_being_edited->ID ); |
|
390 | - $params['wl_schemaorg_property_nonce'] = wp_create_nonce( 'wl_schemaorg_property' ); |
|
389 | + $params['itemId'] = $entity_service->get_uri($entity_being_edited->ID); |
|
390 | + $params['wl_schemaorg_property_nonce'] = wp_create_nonce('wl_schemaorg_property'); |
|
391 | 391 | |
392 | 392 | /* |
393 | 393 | * Add the `properties` if `WL_ALL_ENTITY_TYPES` is enabled. |
@@ -395,8 +395,8 @@ discard block |
||
395 | 395 | * @see https://github.com/insideout10/wordlift-plugin/issues/835 |
396 | 396 | */ |
397 | 397 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
398 | - if ( apply_filters( 'wl_feature__enable__all-entity-types', WL_ALL_ENTITY_TYPES ) ) { |
|
399 | - $params['properties'] = Wordlift_Schemaorg_Property_Service::get_instance()->get_all( $post->ID ); |
|
398 | + if (apply_filters('wl_feature__enable__all-entity-types', WL_ALL_ENTITY_TYPES)) { |
|
399 | + $params['properties'] = Wordlift_Schemaorg_Property_Service::get_instance()->get_all($post->ID); |
|
400 | 400 | } |
401 | 401 | } |
402 | 402 | |
@@ -416,7 +416,7 @@ discard block |
||
416 | 416 | */ |
417 | 417 | $taxonomy_option = new Taxonomy_Option(); |
418 | 418 | $taxonomy_option->add_taxonomy_option(); |
419 | - new Edit_Mappings_Page( new Mappings_Transform_Functions_Registry() ); |
|
419 | + new Edit_Mappings_Page(new Mappings_Transform_Functions_Registry()); |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | } |
@@ -19,125 +19,125 @@ |
||
19 | 19 | */ |
20 | 20 | class Wordlift_Admin_Author_Element implements Wordlift_Admin_Element { |
21 | 21 | |
22 | - /** |
|
23 | - * The {@link Wordlift_Publisher_Service} instance. |
|
24 | - * |
|
25 | - * @since 3.14.0 |
|
26 | - * @access private |
|
27 | - * @var \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance. |
|
28 | - */ |
|
29 | - private $publisher_service; |
|
30 | - |
|
31 | - /** |
|
32 | - * A {@link Wordlift_Admin_Select2_Element} instance. |
|
33 | - * |
|
34 | - * @since 3.14.0 |
|
35 | - * @access private |
|
36 | - * @var \Wordlift_Admin_Select2_Element $select_element A {@link Wordlift_Admin_Select2_Element} instance. |
|
37 | - */ |
|
38 | - private $select_element; |
|
39 | - |
|
40 | - /** |
|
41 | - * Create a {@link Wordlift_Admin_Person_Element} instance. |
|
42 | - * |
|
43 | - * @param \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance. |
|
44 | - * @param \Wordlift_Admin_Select2_Element $select_element The {@link Wordlift_Admin_Select_Element} instance. |
|
45 | - * |
|
46 | - * @since 3.14.0 |
|
47 | - */ |
|
48 | - public function __construct( $publisher_service, $select_element ) { |
|
49 | - |
|
50 | - $this->publisher_service = $publisher_service; |
|
51 | - |
|
52 | - // Child elements. |
|
53 | - $this->select_element = $select_element; |
|
54 | - |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @inheritdoc |
|
59 | - */ |
|
60 | - public function render( $args ) { |
|
61 | - |
|
62 | - // Parse the arguments and merge with default values. |
|
63 | - $params = wp_parse_args( |
|
64 | - $args, |
|
65 | - array( |
|
66 | - 'id' => uniqid( 'wl-input-' ), |
|
67 | - 'name' => uniqid( 'wl-input-' ), |
|
68 | - 'current_entity' => 0, |
|
69 | - ) |
|
70 | - ); |
|
71 | - |
|
72 | - $current_entity_id = $params['current_entity']; |
|
73 | - $data = $this->publisher_service->query(); |
|
74 | - |
|
75 | - // Set a default to show when no entity is associated and a way to unassign. |
|
76 | - array_unshift( |
|
77 | - $data, |
|
78 | - array( |
|
79 | - 'id' => '0', |
|
80 | - 'text' => '<em>' . __( '(none)', 'wordlift' ) . '</em>', |
|
81 | - 'type' => '', |
|
82 | - 'thumbnail_url' => plugin_dir_url( __DIR__ ) . 'images/pixel.png', |
|
83 | - ) |
|
84 | - ); |
|
85 | - |
|
86 | - // Finally do the render, passing along also the current selected entity |
|
87 | - // id and the options data. |
|
88 | - return $this->do_render( $params, $current_entity_id, $data ); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Render the `select` using the provided parameters. |
|
93 | - * |
|
94 | - * @param array $params The array of parameters from the `render` function. |
|
95 | - * @param int $current_post_id The currently selected {@link WP_Post} `id`. |
|
96 | - * @param array $data An array of Select2 options. |
|
97 | - * |
|
98 | - * @return \Wordlift_Admin_Author_Element $this Return this element. |
|
99 | - * @since 3.14.0 |
|
100 | - */ |
|
101 | - protected function do_render( $params, $current_post_id, $data ) { |
|
102 | - |
|
103 | - // Queue the script which will initialize the select and style it. |
|
104 | - wp_enqueue_script( 'wl-author-element', plugin_dir_url( __DIR__ ) . 'js/1/author.js', array( 'wordlift-select2' ), WORDLIFT_VERSION, false ); |
|
105 | - wp_enqueue_style( 'wl-author-element', plugin_dir_url( __DIR__ ) . 'js/1/author.css', array(), WORDLIFT_VERSION ); |
|
106 | - |
|
107 | - // Prepare the URLs for entities which don't have logos. |
|
108 | - $person_thumbnail_url = plugin_dir_url( __DIR__ ) . '../images/person.png'; |
|
109 | - $organization_thumbnail_url = plugin_dir_url( __DIR__ ) . '../images/organization.png'; |
|
110 | - |
|
111 | - // Get the current post. |
|
112 | - $current_post = $current_post_id ? get_post( $current_post_id ) : null; |
|
113 | - |
|
114 | - // Finally render the Select. |
|
115 | - $this->select_element->render( |
|
116 | - array( |
|
117 | - // Id. |
|
118 | - 'id' => $params['id'], |
|
119 | - // Name. |
|
120 | - 'name' => $params['name'], |
|
121 | - // Class names. |
|
122 | - 'class' => 'wl-select2-element', |
|
123 | - // The selected id. |
|
124 | - 'value' => $current_post_id, |
|
125 | - // The selected item (must be in the options for Select2 to display it). |
|
126 | - 'options' => $current_post ? array( $current_post->ID => $current_post->post_title ) : array(), |
|
127 | - // Data attributes. |
|
128 | - 'data' => array( |
|
129 | - // The list of available options. |
|
130 | - 'wl-select2-data' => wp_json_encode( $data ), |
|
131 | - // The HTML template for each option. |
|
132 | - 'wl-select2-template-result' => "<div class='wl-select2-result'><span class='wl-select2-thumbnail' style='background-image: url( <%- obj.thumbnail_url || ( 'Organization' === obj.type ? '$organization_thumbnail_url' : '$person_thumbnail_url' ) %> );'> </span><span class='wl-select2'><%- obj.text %></span><span class='wl-select2-type'><%- obj.type %></span></div>", |
|
133 | - // The HTML template for the selected option. |
|
134 | - 'wl-select2-template-selection' => "<div class='wl-select2-selection'><span class='wl-select2-thumbnail' style='background-image: url( <%- obj.thumbnail_url || ( 'Organization' === obj.type ? '$organization_thumbnail_url' : '$person_thumbnail_url' ) %> );'> </span><span class='wl-select2'><%- obj.text %></span><span class='wl-select2-type'><%- obj.type %></span></div>", |
|
135 | - ), |
|
136 | - ) |
|
137 | - ); |
|
138 | - |
|
139 | - // Finally return the element instance. |
|
140 | - return $this; |
|
141 | - } |
|
22 | + /** |
|
23 | + * The {@link Wordlift_Publisher_Service} instance. |
|
24 | + * |
|
25 | + * @since 3.14.0 |
|
26 | + * @access private |
|
27 | + * @var \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance. |
|
28 | + */ |
|
29 | + private $publisher_service; |
|
30 | + |
|
31 | + /** |
|
32 | + * A {@link Wordlift_Admin_Select2_Element} instance. |
|
33 | + * |
|
34 | + * @since 3.14.0 |
|
35 | + * @access private |
|
36 | + * @var \Wordlift_Admin_Select2_Element $select_element A {@link Wordlift_Admin_Select2_Element} instance. |
|
37 | + */ |
|
38 | + private $select_element; |
|
39 | + |
|
40 | + /** |
|
41 | + * Create a {@link Wordlift_Admin_Person_Element} instance. |
|
42 | + * |
|
43 | + * @param \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance. |
|
44 | + * @param \Wordlift_Admin_Select2_Element $select_element The {@link Wordlift_Admin_Select_Element} instance. |
|
45 | + * |
|
46 | + * @since 3.14.0 |
|
47 | + */ |
|
48 | + public function __construct( $publisher_service, $select_element ) { |
|
49 | + |
|
50 | + $this->publisher_service = $publisher_service; |
|
51 | + |
|
52 | + // Child elements. |
|
53 | + $this->select_element = $select_element; |
|
54 | + |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @inheritdoc |
|
59 | + */ |
|
60 | + public function render( $args ) { |
|
61 | + |
|
62 | + // Parse the arguments and merge with default values. |
|
63 | + $params = wp_parse_args( |
|
64 | + $args, |
|
65 | + array( |
|
66 | + 'id' => uniqid( 'wl-input-' ), |
|
67 | + 'name' => uniqid( 'wl-input-' ), |
|
68 | + 'current_entity' => 0, |
|
69 | + ) |
|
70 | + ); |
|
71 | + |
|
72 | + $current_entity_id = $params['current_entity']; |
|
73 | + $data = $this->publisher_service->query(); |
|
74 | + |
|
75 | + // Set a default to show when no entity is associated and a way to unassign. |
|
76 | + array_unshift( |
|
77 | + $data, |
|
78 | + array( |
|
79 | + 'id' => '0', |
|
80 | + 'text' => '<em>' . __( '(none)', 'wordlift' ) . '</em>', |
|
81 | + 'type' => '', |
|
82 | + 'thumbnail_url' => plugin_dir_url( __DIR__ ) . 'images/pixel.png', |
|
83 | + ) |
|
84 | + ); |
|
85 | + |
|
86 | + // Finally do the render, passing along also the current selected entity |
|
87 | + // id and the options data. |
|
88 | + return $this->do_render( $params, $current_entity_id, $data ); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Render the `select` using the provided parameters. |
|
93 | + * |
|
94 | + * @param array $params The array of parameters from the `render` function. |
|
95 | + * @param int $current_post_id The currently selected {@link WP_Post} `id`. |
|
96 | + * @param array $data An array of Select2 options. |
|
97 | + * |
|
98 | + * @return \Wordlift_Admin_Author_Element $this Return this element. |
|
99 | + * @since 3.14.0 |
|
100 | + */ |
|
101 | + protected function do_render( $params, $current_post_id, $data ) { |
|
102 | + |
|
103 | + // Queue the script which will initialize the select and style it. |
|
104 | + wp_enqueue_script( 'wl-author-element', plugin_dir_url( __DIR__ ) . 'js/1/author.js', array( 'wordlift-select2' ), WORDLIFT_VERSION, false ); |
|
105 | + wp_enqueue_style( 'wl-author-element', plugin_dir_url( __DIR__ ) . 'js/1/author.css', array(), WORDLIFT_VERSION ); |
|
106 | + |
|
107 | + // Prepare the URLs for entities which don't have logos. |
|
108 | + $person_thumbnail_url = plugin_dir_url( __DIR__ ) . '../images/person.png'; |
|
109 | + $organization_thumbnail_url = plugin_dir_url( __DIR__ ) . '../images/organization.png'; |
|
110 | + |
|
111 | + // Get the current post. |
|
112 | + $current_post = $current_post_id ? get_post( $current_post_id ) : null; |
|
113 | + |
|
114 | + // Finally render the Select. |
|
115 | + $this->select_element->render( |
|
116 | + array( |
|
117 | + // Id. |
|
118 | + 'id' => $params['id'], |
|
119 | + // Name. |
|
120 | + 'name' => $params['name'], |
|
121 | + // Class names. |
|
122 | + 'class' => 'wl-select2-element', |
|
123 | + // The selected id. |
|
124 | + 'value' => $current_post_id, |
|
125 | + // The selected item (must be in the options for Select2 to display it). |
|
126 | + 'options' => $current_post ? array( $current_post->ID => $current_post->post_title ) : array(), |
|
127 | + // Data attributes. |
|
128 | + 'data' => array( |
|
129 | + // The list of available options. |
|
130 | + 'wl-select2-data' => wp_json_encode( $data ), |
|
131 | + // The HTML template for each option. |
|
132 | + 'wl-select2-template-result' => "<div class='wl-select2-result'><span class='wl-select2-thumbnail' style='background-image: url( <%- obj.thumbnail_url || ( 'Organization' === obj.type ? '$organization_thumbnail_url' : '$person_thumbnail_url' ) %> );'> </span><span class='wl-select2'><%- obj.text %></span><span class='wl-select2-type'><%- obj.type %></span></div>", |
|
133 | + // The HTML template for the selected option. |
|
134 | + 'wl-select2-template-selection' => "<div class='wl-select2-selection'><span class='wl-select2-thumbnail' style='background-image: url( <%- obj.thumbnail_url || ( 'Organization' === obj.type ? '$organization_thumbnail_url' : '$person_thumbnail_url' ) %> );'> </span><span class='wl-select2'><%- obj.text %></span><span class='wl-select2-type'><%- obj.type %></span></div>", |
|
135 | + ), |
|
136 | + ) |
|
137 | + ); |
|
138 | + |
|
139 | + // Finally return the element instance. |
|
140 | + return $this; |
|
141 | + } |
|
142 | 142 | |
143 | 143 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | * |
46 | 46 | * @since 3.14.0 |
47 | 47 | */ |
48 | - public function __construct( $publisher_service, $select_element ) { |
|
48 | + public function __construct($publisher_service, $select_element) { |
|
49 | 49 | |
50 | 50 | $this->publisher_service = $publisher_service; |
51 | 51 | |
@@ -57,14 +57,14 @@ discard block |
||
57 | 57 | /** |
58 | 58 | * @inheritdoc |
59 | 59 | */ |
60 | - public function render( $args ) { |
|
60 | + public function render($args) { |
|
61 | 61 | |
62 | 62 | // Parse the arguments and merge with default values. |
63 | 63 | $params = wp_parse_args( |
64 | 64 | $args, |
65 | 65 | array( |
66 | - 'id' => uniqid( 'wl-input-' ), |
|
67 | - 'name' => uniqid( 'wl-input-' ), |
|
66 | + 'id' => uniqid('wl-input-'), |
|
67 | + 'name' => uniqid('wl-input-'), |
|
68 | 68 | 'current_entity' => 0, |
69 | 69 | ) |
70 | 70 | ); |
@@ -77,15 +77,15 @@ discard block |
||
77 | 77 | $data, |
78 | 78 | array( |
79 | 79 | 'id' => '0', |
80 | - 'text' => '<em>' . __( '(none)', 'wordlift' ) . '</em>', |
|
80 | + 'text' => '<em>'.__('(none)', 'wordlift').'</em>', |
|
81 | 81 | 'type' => '', |
82 | - 'thumbnail_url' => plugin_dir_url( __DIR__ ) . 'images/pixel.png', |
|
82 | + 'thumbnail_url' => plugin_dir_url(__DIR__).'images/pixel.png', |
|
83 | 83 | ) |
84 | 84 | ); |
85 | 85 | |
86 | 86 | // Finally do the render, passing along also the current selected entity |
87 | 87 | // id and the options data. |
88 | - return $this->do_render( $params, $current_entity_id, $data ); |
|
88 | + return $this->do_render($params, $current_entity_id, $data); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -98,18 +98,18 @@ discard block |
||
98 | 98 | * @return \Wordlift_Admin_Author_Element $this Return this element. |
99 | 99 | * @since 3.14.0 |
100 | 100 | */ |
101 | - protected function do_render( $params, $current_post_id, $data ) { |
|
101 | + protected function do_render($params, $current_post_id, $data) { |
|
102 | 102 | |
103 | 103 | // Queue the script which will initialize the select and style it. |
104 | - wp_enqueue_script( 'wl-author-element', plugin_dir_url( __DIR__ ) . 'js/1/author.js', array( 'wordlift-select2' ), WORDLIFT_VERSION, false ); |
|
105 | - wp_enqueue_style( 'wl-author-element', plugin_dir_url( __DIR__ ) . 'js/1/author.css', array(), WORDLIFT_VERSION ); |
|
104 | + wp_enqueue_script('wl-author-element', plugin_dir_url(__DIR__).'js/1/author.js', array('wordlift-select2'), WORDLIFT_VERSION, false); |
|
105 | + wp_enqueue_style('wl-author-element', plugin_dir_url(__DIR__).'js/1/author.css', array(), WORDLIFT_VERSION); |
|
106 | 106 | |
107 | 107 | // Prepare the URLs for entities which don't have logos. |
108 | - $person_thumbnail_url = plugin_dir_url( __DIR__ ) . '../images/person.png'; |
|
109 | - $organization_thumbnail_url = plugin_dir_url( __DIR__ ) . '../images/organization.png'; |
|
108 | + $person_thumbnail_url = plugin_dir_url(__DIR__).'../images/person.png'; |
|
109 | + $organization_thumbnail_url = plugin_dir_url(__DIR__).'../images/organization.png'; |
|
110 | 110 | |
111 | 111 | // Get the current post. |
112 | - $current_post = $current_post_id ? get_post( $current_post_id ) : null; |
|
112 | + $current_post = $current_post_id ? get_post($current_post_id) : null; |
|
113 | 113 | |
114 | 114 | // Finally render the Select. |
115 | 115 | $this->select_element->render( |
@@ -123,11 +123,11 @@ discard block |
||
123 | 123 | // The selected id. |
124 | 124 | 'value' => $current_post_id, |
125 | 125 | // The selected item (must be in the options for Select2 to display it). |
126 | - 'options' => $current_post ? array( $current_post->ID => $current_post->post_title ) : array(), |
|
126 | + 'options' => $current_post ? array($current_post->ID => $current_post->post_title) : array(), |
|
127 | 127 | // Data attributes. |
128 | 128 | 'data' => array( |
129 | 129 | // The list of available options. |
130 | - 'wl-select2-data' => wp_json_encode( $data ), |
|
130 | + 'wl-select2-data' => wp_json_encode($data), |
|
131 | 131 | // The HTML template for each option. |
132 | 132 | 'wl-select2-template-result' => "<div class='wl-select2-result'><span class='wl-select2-thumbnail' style='background-image: url( <%- obj.thumbnail_url || ( 'Organization' === obj.type ? '$organization_thumbnail_url' : '$person_thumbnail_url' ) %> );'> </span><span class='wl-select2'><%- obj.text %></span><span class='wl-select2-type'><%- obj.type %></span></div>", |
133 | 133 | // The HTML template for the selected option. |
@@ -18,54 +18,54 @@ discard block |
||
18 | 18 | */ |
19 | 19 | class Wordlift_Admin_Radio_Input_Element implements Wordlift_Admin_Element { |
20 | 20 | |
21 | - /** |
|
22 | - * Output the HTML for an input box type settings_page. |
|
23 | - * |
|
24 | - * @param array $args { |
|
25 | - * An array of arguments. |
|
26 | - * |
|
27 | - * @type string $name The name attribute of the input element. Mandatory. |
|
28 | - * @type string $id The id attribute of the input element. Optional, |
|
29 | - * randomly generated one is used if not supplied. |
|
30 | - * @type string $value The value of the input element. Optional, defaults |
|
31 | - * to empty string. |
|
32 | - * @type string $css_class The class attribute for the input element. If empty |
|
33 | - * string no class attribute will be added. Optional, |
|
34 | - * defaults to empty string. |
|
35 | - * @type string $description The description text to be displayed below the element. |
|
36 | - * Can include some HTML element. If empty string no |
|
37 | - * description will be displayed. Optional, defaults to |
|
38 | - * empty string. |
|
39 | - * } |
|
40 | - * @return $this|Wordlift_Admin_Element |
|
41 | - * @since 3.13.0 |
|
42 | - */ |
|
43 | - public function render( $args ) { |
|
44 | - /* |
|
21 | + /** |
|
22 | + * Output the HTML for an input box type settings_page. |
|
23 | + * |
|
24 | + * @param array $args { |
|
25 | + * An array of arguments. |
|
26 | + * |
|
27 | + * @type string $name The name attribute of the input element. Mandatory. |
|
28 | + * @type string $id The id attribute of the input element. Optional, |
|
29 | + * randomly generated one is used if not supplied. |
|
30 | + * @type string $value The value of the input element. Optional, defaults |
|
31 | + * to empty string. |
|
32 | + * @type string $css_class The class attribute for the input element. If empty |
|
33 | + * string no class attribute will be added. Optional, |
|
34 | + * defaults to empty string. |
|
35 | + * @type string $description The description text to be displayed below the element. |
|
36 | + * Can include some HTML element. If empty string no |
|
37 | + * description will be displayed. Optional, defaults to |
|
38 | + * empty string. |
|
39 | + * } |
|
40 | + * @return $this|Wordlift_Admin_Element |
|
41 | + * @since 3.13.0 |
|
42 | + */ |
|
43 | + public function render( $args ) { |
|
44 | + /* |
|
45 | 45 | * Parse the arguments and merge with default values. |
46 | 46 | * Name intentionally do not have a default as it has to be in SyncEvent |
47 | 47 | * with form handling code |
48 | 48 | */ |
49 | - $params = wp_parse_args( |
|
50 | - $args, |
|
51 | - array( |
|
52 | - 'id' => uniqid( 'wl-input-' ), |
|
53 | - 'value' => '', |
|
54 | - 'css_class' => '', |
|
55 | - 'description' => '', |
|
56 | - ) |
|
57 | - ); |
|
49 | + $params = wp_parse_args( |
|
50 | + $args, |
|
51 | + array( |
|
52 | + 'id' => uniqid( 'wl-input-' ), |
|
53 | + 'value' => '', |
|
54 | + 'css_class' => '', |
|
55 | + 'description' => '', |
|
56 | + ) |
|
57 | + ); |
|
58 | 58 | |
59 | - // Set the readonly and class attributes and the description. |
|
60 | - $value = $params['value']; |
|
61 | - ?> |
|
59 | + // Set the readonly and class attributes and the description. |
|
60 | + $value = $params['value']; |
|
61 | + ?> |
|
62 | 62 | |
63 | 63 | <input type="radio" id="<?php echo esc_attr( $params['id'] ); ?>" |
64 | 64 | name="<?php echo esc_attr( $params['name'] ); ?>" |
65 | 65 | value="yes" |
66 | 66 | <?php |
67 | - if ( ! empty( $params['css_class'] ) ) { |
|
68 | - ?> |
|
67 | + if ( ! empty( $params['css_class'] ) ) { |
|
68 | + ?> |
|
69 | 69 | class="<?php echo esc_attr( $params['css_class'] ); ?>" <?php } ?> |
70 | 70 | <?php checked( $value, 'yes' ); ?> |
71 | 71 | /> Yes |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | name="<?php echo esc_attr( $params['name'] ); ?>" |
74 | 74 | value="no" |
75 | 75 | <?php |
76 | - if ( ! empty( $params['css_class'] ) ) { |
|
77 | - ?> |
|
76 | + if ( ! empty( $params['css_class'] ) ) { |
|
77 | + ?> |
|
78 | 78 | class="<?php echo esc_attr( $params['css_class'] ); ?>" <?php } ?> |
79 | 79 | <?php checked( $value, 'no' ); ?> |
80 | 80 | /> No |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | <p><?php echo wp_kses( $params['description'], array( 'a' => array( 'href' => array() ) ) ); ?></p><?php } ?> |
83 | 83 | <?php |
84 | 84 | |
85 | - return $this; |
|
86 | - } |
|
85 | + return $this; |
|
86 | + } |
|
87 | 87 | |
88 | 88 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | * @return $this|Wordlift_Admin_Element |
41 | 41 | * @since 3.13.0 |
42 | 42 | */ |
43 | - public function render( $args ) { |
|
43 | + public function render($args) { |
|
44 | 44 | /* |
45 | 45 | * Parse the arguments and merge with default values. |
46 | 46 | * Name intentionally do not have a default as it has to be in SyncEvent |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | $params = wp_parse_args( |
50 | 50 | $args, |
51 | 51 | array( |
52 | - 'id' => uniqid( 'wl-input-' ), |
|
52 | + 'id' => uniqid('wl-input-'), |
|
53 | 53 | 'value' => '', |
54 | 54 | 'css_class' => '', |
55 | 55 | 'description' => '', |
@@ -60,26 +60,26 @@ discard block |
||
60 | 60 | $value = $params['value']; |
61 | 61 | ?> |
62 | 62 | |
63 | - <input type="radio" id="<?php echo esc_attr( $params['id'] ); ?>" |
|
64 | - name="<?php echo esc_attr( $params['name'] ); ?>" |
|
63 | + <input type="radio" id="<?php echo esc_attr($params['id']); ?>" |
|
64 | + name="<?php echo esc_attr($params['name']); ?>" |
|
65 | 65 | value="yes" |
66 | 66 | <?php |
67 | - if ( ! empty( $params['css_class'] ) ) { |
|
67 | + if ( ! empty($params['css_class'])) { |
|
68 | 68 | ?> |
69 | - class="<?php echo esc_attr( $params['css_class'] ); ?>" <?php } ?> |
|
70 | - <?php checked( $value, 'yes' ); ?> |
|
69 | + class="<?php echo esc_attr($params['css_class']); ?>" <?php } ?> |
|
70 | + <?php checked($value, 'yes'); ?> |
|
71 | 71 | /> Yes |
72 | - <input type="radio" id="<?php echo esc_attr( $params['id'] ); ?>" |
|
73 | - name="<?php echo esc_attr( $params['name'] ); ?>" |
|
72 | + <input type="radio" id="<?php echo esc_attr($params['id']); ?>" |
|
73 | + name="<?php echo esc_attr($params['name']); ?>" |
|
74 | 74 | value="no" |
75 | 75 | <?php |
76 | - if ( ! empty( $params['css_class'] ) ) { |
|
76 | + if ( ! empty($params['css_class'])) { |
|
77 | 77 | ?> |
78 | - class="<?php echo esc_attr( $params['css_class'] ); ?>" <?php } ?> |
|
79 | - <?php checked( $value, 'no' ); ?> |
|
78 | + class="<?php echo esc_attr($params['css_class']); ?>" <?php } ?> |
|
79 | + <?php checked($value, 'no'); ?> |
|
80 | 80 | /> No |
81 | - <?php if ( ! empty( $params['description'] ) ) { ?> |
|
82 | - <p><?php echo wp_kses( $params['description'], array( 'a' => array( 'href' => array() ) ) ); ?></p><?php } ?> |
|
81 | + <?php if ( ! empty($params['description'])) { ?> |
|
82 | + <p><?php echo wp_kses($params['description'], array('a' => array('href' => array()))); ?></p><?php } ?> |
|
83 | 83 | <?php |
84 | 84 | |
85 | 85 | return $this; |
@@ -18,37 +18,37 @@ discard block |
||
18 | 18 | */ |
19 | 19 | class Wordlift_Admin_Country_Select_Element extends Wordlift_Admin_Select_Element { |
20 | 20 | |
21 | - /** |
|
22 | - * Adds a filter that will add data `country-codes` attrbiute to the country select |
|
23 | - * to allow front-end validation. |
|
24 | - * |
|
25 | - * @since 3.18.0 |
|
26 | - */ |
|
27 | - public function __construct() { |
|
28 | - // Adds the country codes as data attribute to allow front-end validation. |
|
29 | - add_filter( 'wl_admin_select_element_data_attributes', array( $this, 'add_country_codes_data' ), 10, 1 ); |
|
30 | - } |
|
21 | + /** |
|
22 | + * Adds a filter that will add data `country-codes` attrbiute to the country select |
|
23 | + * to allow front-end validation. |
|
24 | + * |
|
25 | + * @since 3.18.0 |
|
26 | + */ |
|
27 | + public function __construct() { |
|
28 | + // Adds the country codes as data attribute to allow front-end validation. |
|
29 | + add_filter( 'wl_admin_select_element_data_attributes', array( $this, 'add_country_codes_data' ), 10, 1 ); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * @inheritdoc |
|
34 | - */ |
|
35 | - public function render_options( $params ) { |
|
36 | - // Print all the supported countries, preselecting the one configured |
|
37 | - // in WP (or United Kingdom if not supported). We now use the `Wordlift_Countries` |
|
38 | - // class which provides the list of countries supported by WordLift. |
|
39 | - // |
|
40 | - // https://github.com/insideout10/wordlift-plugin/issues/713 |
|
32 | + /** |
|
33 | + * @inheritdoc |
|
34 | + */ |
|
35 | + public function render_options( $params ) { |
|
36 | + // Print all the supported countries, preselecting the one configured |
|
37 | + // in WP (or United Kingdom if not supported). We now use the `Wordlift_Countries` |
|
38 | + // class which provides the list of countries supported by WordLift. |
|
39 | + // |
|
40 | + // https://github.com/insideout10/wordlift-plugin/issues/713 |
|
41 | 41 | |
42 | - $lang = ( isset( $params['lang'] ) ) ? $params['lang'] : false; |
|
42 | + $lang = ( isset( $params['lang'] ) ) ? $params['lang'] : false; |
|
43 | 43 | |
44 | - // Get WordLift's supported countries. |
|
45 | - $countries = Wordlift_Countries::get_countries( $lang ); |
|
44 | + // Get WordLift's supported countries. |
|
45 | + $countries = Wordlift_Countries::get_countries( $lang ); |
|
46 | 46 | |
47 | - // If we support WP's configured language, then use that, otherwise use English by default. |
|
48 | - $language = isset( $countries[ $params['value'] ] ) ? $params['value'] : 'uk'; |
|
47 | + // If we support WP's configured language, then use that, otherwise use English by default. |
|
48 | + $language = isset( $countries[ $params['value'] ] ) ? $params['value'] : 'uk'; |
|
49 | 49 | |
50 | - foreach ( $countries as $code => $label ) : |
|
51 | - ?> |
|
50 | + foreach ( $countries as $code => $label ) : |
|
51 | + ?> |
|
52 | 52 | <option |
53 | 53 | value="<?php echo esc_attr( $code ); ?>" |
54 | 54 | <?php echo selected( $code, $language, false ); ?> |
@@ -56,50 +56,50 @@ discard block |
||
56 | 56 | <?php echo esc_html( $label ); ?> |
57 | 57 | </option> |
58 | 58 | <?php |
59 | - endforeach; |
|
60 | - } |
|
59 | + endforeach; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Returns select options html. |
|
64 | - * |
|
65 | - * @since 3.18.0 |
|
66 | - * |
|
67 | - * @return void Echoes select options or empty string if required params are not set. |
|
68 | - */ |
|
69 | - public function get_options_html() { |
|
70 | - $html = ''; |
|
62 | + /** |
|
63 | + * Returns select options html. |
|
64 | + * |
|
65 | + * @since 3.18.0 |
|
66 | + * |
|
67 | + * @return void Echoes select options or empty string if required params are not set. |
|
68 | + */ |
|
69 | + public function get_options_html() { |
|
70 | + $html = ''; |
|
71 | 71 | |
72 | - // Check whether the required params are set. |
|
72 | + // Check whether the required params are set. |
|
73 | 73 | // phpcs:ignore Standard.Category.SniffName.ErrorCode |
74 | - if ( ! empty( $_POST['lang'] ) && ! empty( $_POST['value'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
75 | - ob_start(); |
|
76 | - // Get the new options. |
|
77 | - // phpcs:ignore Standard.Category.SniffName.ErrorCode |
|
78 | - $this->render_options( $_POST ); //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
74 | + if ( ! empty( $_POST['lang'] ) && ! empty( $_POST['value'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
75 | + ob_start(); |
|
76 | + // Get the new options. |
|
77 | + // phpcs:ignore Standard.Category.SniffName.ErrorCode |
|
78 | + $this->render_options( $_POST ); //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
79 | 79 | |
80 | - $html = ob_get_clean(); |
|
81 | - } |
|
80 | + $html = ob_get_clean(); |
|
81 | + } |
|
82 | 82 | |
83 | - // Return the html. |
|
84 | - wp_send_json_success( $html ); |
|
85 | - } |
|
83 | + // Return the html. |
|
84 | + wp_send_json_success( $html ); |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * Modify the field data attributes by adding`country-code` |
|
89 | - * to existing attributes. |
|
90 | - * |
|
91 | - * @param array $attributes Current data attributes. |
|
92 | - * |
|
93 | - * @since 3.18.0 |
|
94 | - * |
|
95 | - * @return array $attributes Modified attributes. |
|
96 | - */ |
|
97 | - public function add_country_codes_data( $attributes ) { |
|
98 | - // Add the country codes. |
|
99 | - $attributes['country-codes'] = wp_json_encode( Wordlift_Countries::get_codes() ); |
|
87 | + /** |
|
88 | + * Modify the field data attributes by adding`country-code` |
|
89 | + * to existing attributes. |
|
90 | + * |
|
91 | + * @param array $attributes Current data attributes. |
|
92 | + * |
|
93 | + * @since 3.18.0 |
|
94 | + * |
|
95 | + * @return array $attributes Modified attributes. |
|
96 | + */ |
|
97 | + public function add_country_codes_data( $attributes ) { |
|
98 | + // Add the country codes. |
|
99 | + $attributes['country-codes'] = wp_json_encode( Wordlift_Countries::get_codes() ); |
|
100 | 100 | |
101 | - // Return the attributes. |
|
102 | - return $attributes; |
|
103 | - } |
|
101 | + // Return the attributes. |
|
102 | + return $attributes; |
|
103 | + } |
|
104 | 104 | |
105 | 105 | } |
@@ -26,34 +26,34 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public function __construct() { |
28 | 28 | // Adds the country codes as data attribute to allow front-end validation. |
29 | - add_filter( 'wl_admin_select_element_data_attributes', array( $this, 'add_country_codes_data' ), 10, 1 ); |
|
29 | + add_filter('wl_admin_select_element_data_attributes', array($this, 'add_country_codes_data'), 10, 1); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
33 | 33 | * @inheritdoc |
34 | 34 | */ |
35 | - public function render_options( $params ) { |
|
35 | + public function render_options($params) { |
|
36 | 36 | // Print all the supported countries, preselecting the one configured |
37 | 37 | // in WP (or United Kingdom if not supported). We now use the `Wordlift_Countries` |
38 | 38 | // class which provides the list of countries supported by WordLift. |
39 | 39 | // |
40 | 40 | // https://github.com/insideout10/wordlift-plugin/issues/713 |
41 | 41 | |
42 | - $lang = ( isset( $params['lang'] ) ) ? $params['lang'] : false; |
|
42 | + $lang = (isset($params['lang'])) ? $params['lang'] : false; |
|
43 | 43 | |
44 | 44 | // Get WordLift's supported countries. |
45 | - $countries = Wordlift_Countries::get_countries( $lang ); |
|
45 | + $countries = Wordlift_Countries::get_countries($lang); |
|
46 | 46 | |
47 | 47 | // If we support WP's configured language, then use that, otherwise use English by default. |
48 | - $language = isset( $countries[ $params['value'] ] ) ? $params['value'] : 'uk'; |
|
48 | + $language = isset($countries[$params['value']]) ? $params['value'] : 'uk'; |
|
49 | 49 | |
50 | - foreach ( $countries as $code => $label ) : |
|
50 | + foreach ($countries as $code => $label) : |
|
51 | 51 | ?> |
52 | 52 | <option |
53 | - value="<?php echo esc_attr( $code ); ?>" |
|
54 | - <?php echo selected( $code, $language, false ); ?> |
|
53 | + value="<?php echo esc_attr($code); ?>" |
|
54 | + <?php echo selected($code, $language, false); ?> |
|
55 | 55 | > |
56 | - <?php echo esc_html( $label ); ?> |
|
56 | + <?php echo esc_html($label); ?> |
|
57 | 57 | </option> |
58 | 58 | <?php |
59 | 59 | endforeach; |
@@ -71,17 +71,17 @@ discard block |
||
71 | 71 | |
72 | 72 | // Check whether the required params are set. |
73 | 73 | // phpcs:ignore Standard.Category.SniffName.ErrorCode |
74 | - if ( ! empty( $_POST['lang'] ) && ! empty( $_POST['value'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
74 | + if ( ! empty($_POST['lang']) && ! empty($_POST['value'])) { //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
75 | 75 | ob_start(); |
76 | 76 | // Get the new options. |
77 | 77 | // phpcs:ignore Standard.Category.SniffName.ErrorCode |
78 | - $this->render_options( $_POST ); //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
78 | + $this->render_options($_POST); //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
79 | 79 | |
80 | 80 | $html = ob_get_clean(); |
81 | 81 | } |
82 | 82 | |
83 | 83 | // Return the html. |
84 | - wp_send_json_success( $html ); |
|
84 | + wp_send_json_success($html); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -94,9 +94,9 @@ discard block |
||
94 | 94 | * |
95 | 95 | * @return array $attributes Modified attributes. |
96 | 96 | */ |
97 | - public function add_country_codes_data( $attributes ) { |
|
97 | + public function add_country_codes_data($attributes) { |
|
98 | 98 | // Add the country codes. |
99 | - $attributes['country-codes'] = wp_json_encode( Wordlift_Countries::get_codes() ); |
|
99 | + $attributes['country-codes'] = wp_json_encode(Wordlift_Countries::get_codes()); |
|
100 | 100 | |
101 | 101 | // Return the attributes. |
102 | 102 | return $attributes; |
@@ -18,75 +18,75 @@ |
||
18 | 18 | */ |
19 | 19 | class Wordlift_Admin_Input_Element implements Wordlift_Admin_Element { |
20 | 20 | |
21 | - /** |
|
22 | - * Output the HTML for an input box type settings_page |
|
23 | - * |
|
24 | - * @param array $args An array with the following keys: |
|
25 | - * Parameters controlling the result. |
|
26 | - * |
|
27 | - * @type string name The name attribute of the input element. Mandatory. |
|
28 | - * |
|
29 | - * @type string id The id attribute of the input element. Optional. |
|
30 | - * @type string id The id attribute of the input element. |
|
31 | - * Optional, randomly generated one is used if not supplied. |
|
32 | - * @type string value The value of the input element. |
|
33 | - * Optional, defaults to empty string. |
|
34 | - * @type bool readonly Indicates whether the input is read only. |
|
35 | - * Optional, defaults to read-write |
|
36 | - * @type string css_class The class attribute for the input element. |
|
37 | - * If empty string no class attribute will be added. |
|
38 | - * Optional, defaults to empty string. |
|
39 | - * @type string description The descriptio text to be displayed below the element. |
|
40 | - * Can include some HTML element. |
|
41 | - * If empty string no description will be displayed. |
|
42 | - * Optional, defaults to empty string. |
|
43 | - * @since 3.21.0 added the ability to use a $type arg. |
|
44 | - * |
|
45 | - * @return $this|Wordlift_Admin_Element |
|
46 | - */ |
|
47 | - public function render( $args ) { |
|
21 | + /** |
|
22 | + * Output the HTML for an input box type settings_page |
|
23 | + * |
|
24 | + * @param array $args An array with the following keys: |
|
25 | + * Parameters controlling the result. |
|
26 | + * |
|
27 | + * @type string name The name attribute of the input element. Mandatory. |
|
28 | + * |
|
29 | + * @type string id The id attribute of the input element. Optional. |
|
30 | + * @type string id The id attribute of the input element. |
|
31 | + * Optional, randomly generated one is used if not supplied. |
|
32 | + * @type string value The value of the input element. |
|
33 | + * Optional, defaults to empty string. |
|
34 | + * @type bool readonly Indicates whether the input is read only. |
|
35 | + * Optional, defaults to read-write |
|
36 | + * @type string css_class The class attribute for the input element. |
|
37 | + * If empty string no class attribute will be added. |
|
38 | + * Optional, defaults to empty string. |
|
39 | + * @type string description The descriptio text to be displayed below the element. |
|
40 | + * Can include some HTML element. |
|
41 | + * If empty string no description will be displayed. |
|
42 | + * Optional, defaults to empty string. |
|
43 | + * @since 3.21.0 added the ability to use a $type arg. |
|
44 | + * |
|
45 | + * @return $this|Wordlift_Admin_Element |
|
46 | + */ |
|
47 | + public function render( $args ) { |
|
48 | 48 | |
49 | - /* |
|
49 | + /* |
|
50 | 50 | * Parse the arguments and merge with default values. |
51 | 51 | * Name intentionally do not have a default as it has to be in SyncEvent |
52 | 52 | * with form handling code |
53 | 53 | */ |
54 | - $pre_params = wp_parse_args( |
|
55 | - $args, |
|
56 | - array( |
|
57 | - 'id' => uniqid( 'wl-input-' ), |
|
58 | - 'value' => '', |
|
59 | - 'readonly' => false, |
|
60 | - 'css_class' => '', |
|
61 | - 'description' => '', |
|
62 | - ) |
|
63 | - ); |
|
64 | - $params = apply_filters( 'wl_admin_input_element_params', $pre_params ); |
|
65 | - // allow different types of input - default to 'text'. |
|
66 | - $input_type = ! empty( $params['type'] ) ? $params['type'] : 'text'; |
|
67 | - ?> |
|
54 | + $pre_params = wp_parse_args( |
|
55 | + $args, |
|
56 | + array( |
|
57 | + 'id' => uniqid( 'wl-input-' ), |
|
58 | + 'value' => '', |
|
59 | + 'readonly' => false, |
|
60 | + 'css_class' => '', |
|
61 | + 'description' => '', |
|
62 | + ) |
|
63 | + ); |
|
64 | + $params = apply_filters( 'wl_admin_input_element_params', $pre_params ); |
|
65 | + // allow different types of input - default to 'text'. |
|
66 | + $input_type = ! empty( $params['type'] ) ? $params['type'] : 'text'; |
|
67 | + ?> |
|
68 | 68 | |
69 | 69 | <input type="<?php echo esc_attr( $input_type ); ?>" |
70 | 70 | id="<?php echo esc_attr( $params['id'] ); ?>" |
71 | 71 | name="<?php echo esc_attr( $params['name'] ); ?>" |
72 | 72 | value="<?php echo esc_attr( $params['value'] ); ?>" |
73 | 73 | <?php |
74 | - if ( ! empty( $params['readonly'] ) ) { |
|
75 | - ?> |
|
74 | + if ( ! empty( $params['readonly'] ) ) { |
|
75 | + ?> |
|
76 | 76 | readonly="readonly" <?php } ?> |
77 | 77 | <?php |
78 | - if ( ! empty( $params['css_class'] ) ) { |
|
79 | - ?> |
|
78 | + if ( ! empty( $params['css_class'] ) ) { |
|
79 | + ?> |
|
80 | 80 | class="<?php echo esc_attr( $params['css_class'] ); ?>" <?php } ?> |
81 | 81 | /> |
82 | 82 | <?php |
83 | - if ( ! empty( $params['description'] ) ) { |
|
84 | - ?> |
|
83 | + if ( ! empty( $params['description'] ) ) { |
|
84 | + ?> |
|
85 | 85 | <p><?php echo wp_kses( $params['description'], array( 'a' => array( 'href' => array() ) ) ); ?></p><?php } ?> |
86 | 86 | |
87 | 87 | <?php |
88 | 88 | |
89 | - return $this; |
|
90 | - } |
|
89 | + return $this; |
|
90 | + } |
|
91 | 91 | |
92 | 92 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * |
45 | 45 | * @return $this|Wordlift_Admin_Element |
46 | 46 | */ |
47 | - public function render( $args ) { |
|
47 | + public function render($args) { |
|
48 | 48 | |
49 | 49 | /* |
50 | 50 | * Parse the arguments and merge with default values. |
@@ -54,35 +54,35 @@ discard block |
||
54 | 54 | $pre_params = wp_parse_args( |
55 | 55 | $args, |
56 | 56 | array( |
57 | - 'id' => uniqid( 'wl-input-' ), |
|
57 | + 'id' => uniqid('wl-input-'), |
|
58 | 58 | 'value' => '', |
59 | 59 | 'readonly' => false, |
60 | 60 | 'css_class' => '', |
61 | 61 | 'description' => '', |
62 | 62 | ) |
63 | 63 | ); |
64 | - $params = apply_filters( 'wl_admin_input_element_params', $pre_params ); |
|
64 | + $params = apply_filters('wl_admin_input_element_params', $pre_params); |
|
65 | 65 | // allow different types of input - default to 'text'. |
66 | - $input_type = ! empty( $params['type'] ) ? $params['type'] : 'text'; |
|
66 | + $input_type = ! empty($params['type']) ? $params['type'] : 'text'; |
|
67 | 67 | ?> |
68 | 68 | |
69 | - <input type="<?php echo esc_attr( $input_type ); ?>" |
|
70 | - id="<?php echo esc_attr( $params['id'] ); ?>" |
|
71 | - name="<?php echo esc_attr( $params['name'] ); ?>" |
|
72 | - value="<?php echo esc_attr( $params['value'] ); ?>" |
|
69 | + <input type="<?php echo esc_attr($input_type); ?>" |
|
70 | + id="<?php echo esc_attr($params['id']); ?>" |
|
71 | + name="<?php echo esc_attr($params['name']); ?>" |
|
72 | + value="<?php echo esc_attr($params['value']); ?>" |
|
73 | 73 | <?php |
74 | - if ( ! empty( $params['readonly'] ) ) { |
|
74 | + if ( ! empty($params['readonly'])) { |
|
75 | 75 | ?> |
76 | 76 | readonly="readonly" <?php } ?> |
77 | 77 | <?php |
78 | - if ( ! empty( $params['css_class'] ) ) { |
|
78 | + if ( ! empty($params['css_class'])) { |
|
79 | 79 | ?> |
80 | - class="<?php echo esc_attr( $params['css_class'] ); ?>" <?php } ?> |
|
80 | + class="<?php echo esc_attr($params['css_class']); ?>" <?php } ?> |
|
81 | 81 | /> |
82 | 82 | <?php |
83 | - if ( ! empty( $params['description'] ) ) { |
|
83 | + if ( ! empty($params['description'])) { |
|
84 | 84 | ?> |
85 | - <p><?php echo wp_kses( $params['description'], array( 'a' => array( 'href' => array() ) ) ); ?></p><?php } ?> |
|
85 | + <p><?php echo wp_kses($params['description'], array('a' => array('href' => array()))); ?></p><?php } ?> |
|
86 | 86 | |
87 | 87 | <?php |
88 | 88 |