Completed
Push — develop ( fd2432...e25aed )
by David
03:47
created
src/admin/class-wordlift-admin.php 2 patches
Indentation   +287 added lines, -287 removed lines patch added patch discarded remove patch
@@ -22,338 +22,338 @@
 block discarded – undo
22 22
  */
23 23
 class Wordlift_Admin {
24 24
 
25
-	/**
26
-	 * The ID of this plugin.
27
-	 *
28
-	 * @since    1.0.0
29
-	 * @access   private
30
-	 * @var      string $plugin_name The ID of this plugin.
31
-	 */
32
-	private $plugin_name;
33
-
34
-	/**
35
-	 * The version of this plugin.
36
-	 *
37
-	 * @since    1.0.0
38
-	 * @access   private
39
-	 * @var      string $version The current version of this plugin.
40
-	 */
41
-	private $version;
42
-
43
-	/**
44
-	 * The {@link Wordlift_Configuration_Service} instance.
45
-	 *
46
-	 * @since  3.14.0
47
-	 * @access private
48
-	 * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
49
-	 */
50
-	private $configuration_service;
51
-
52
-	/**
53
-	 * The {@link Wordlift_User_Service} instance.
54
-	 *
55
-	 * @since  3.14.0
56
-	 * @access private
57
-	 * @var \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance.
58
-	 */
59
-	private $user_service;
60
-
61
-	/**
62
-	 * The {@link Wordlift_Batch_Operation_Ajax_Adapter} instance.
63
-	 *
64
-	 * @since 3.20.0
65
-	 * @access private
66
-	 * @var \Wordlift_Batch_Operation_Ajax_Adapter $sync_batch_operation_ajax_adapter The {@link Wordlift_Batch_Operation_Ajax_Adapter} instance.
67
-	 */
68
-	private $sync_batch_operation_ajax_adapter;
69
-
70
-	/**
71
-	 * The singleton instance.
72
-	 *
73
-	 * @since 3.19.4
74
-	 * @access private
75
-	 * @var Wordlift_Admin $instance The singleton instance.
76
-	 */
77
-	private static $instance;
78
-
79
-	/**
80
-	 * Initialize the class and set its properties.
81
-	 *
82
-	 * @since  1.0.0
83
-	 *
84
-	 * @param string                          $plugin_name The name of this plugin.
85
-	 * @param string                          $version The version of this plugin.
86
-	 * @param \Wordlift_Configuration_Service $configuration_service The configuration service.
87
-	 * @param \Wordlift_Notice_Service        $notice_service The notice service.
88
-	 * @param \Wordlift_User_Service          $user_service The {@link Wordlift_User_Service} instance.
89
-	 */
90
-	public function __construct( $plugin_name, $version, $configuration_service, $notice_service, $user_service ) {
91
-
92
-		$this->plugin_name = $plugin_name;
93
-		$this->version     = $version;
94
-
95
-		$this->configuration_service = $configuration_service;
96
-		$this->user_service          = $user_service;
97
-
98
-		$dataset_uri = $configuration_service->get_dataset_uri();
99
-		$key         = $configuration_service->get_key();
100
-
101
-		if ( empty( $dataset_uri ) ) {
102
-			$settings_page = Wordlift_Admin_Settings_Page::get_instance();
103
-			if ( empty( $key ) ) {
104
-				$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>' );
105
-			} else {
106
-				$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>' );
107
-			}
108
-			$notice_service->add_error( $error );
109
-		}
110
-
111
-		// Load additional code if we're in the admin UI.
112
-		if ( is_admin() ) {
113
-
114
-			// Require the PHP files for the next code fragment.
115
-			self::require_files();
116
-
117
-			new Wordlift_Dashboard_Latest_News();
118
-
119
-			// Search Rankings.
120
-			$search_rankings_service = new Wordlift_Admin_Search_Rankings_Service( Wordlift_Api_Service::get_instance() );
121
-			new Wordlift_Admin_Search_Rankings_Ajax_Adapter( $search_rankings_service );
122
-
123
-			/*
25
+    /**
26
+     * The ID of this plugin.
27
+     *
28
+     * @since    1.0.0
29
+     * @access   private
30
+     * @var      string $plugin_name The ID of this plugin.
31
+     */
32
+    private $plugin_name;
33
+
34
+    /**
35
+     * The version of this plugin.
36
+     *
37
+     * @since    1.0.0
38
+     * @access   private
39
+     * @var      string $version The current version of this plugin.
40
+     */
41
+    private $version;
42
+
43
+    /**
44
+     * The {@link Wordlift_Configuration_Service} instance.
45
+     *
46
+     * @since  3.14.0
47
+     * @access private
48
+     * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
49
+     */
50
+    private $configuration_service;
51
+
52
+    /**
53
+     * The {@link Wordlift_User_Service} instance.
54
+     *
55
+     * @since  3.14.0
56
+     * @access private
57
+     * @var \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance.
58
+     */
59
+    private $user_service;
60
+
61
+    /**
62
+     * The {@link Wordlift_Batch_Operation_Ajax_Adapter} instance.
63
+     *
64
+     * @since 3.20.0
65
+     * @access private
66
+     * @var \Wordlift_Batch_Operation_Ajax_Adapter $sync_batch_operation_ajax_adapter The {@link Wordlift_Batch_Operation_Ajax_Adapter} instance.
67
+     */
68
+    private $sync_batch_operation_ajax_adapter;
69
+
70
+    /**
71
+     * The singleton instance.
72
+     *
73
+     * @since 3.19.4
74
+     * @access private
75
+     * @var Wordlift_Admin $instance The singleton instance.
76
+     */
77
+    private static $instance;
78
+
79
+    /**
80
+     * Initialize the class and set its properties.
81
+     *
82
+     * @since  1.0.0
83
+     *
84
+     * @param string                          $plugin_name The name of this plugin.
85
+     * @param string                          $version The version of this plugin.
86
+     * @param \Wordlift_Configuration_Service $configuration_service The configuration service.
87
+     * @param \Wordlift_Notice_Service        $notice_service The notice service.
88
+     * @param \Wordlift_User_Service          $user_service The {@link Wordlift_User_Service} instance.
89
+     */
90
+    public function __construct( $plugin_name, $version, $configuration_service, $notice_service, $user_service ) {
91
+
92
+        $this->plugin_name = $plugin_name;
93
+        $this->version     = $version;
94
+
95
+        $this->configuration_service = $configuration_service;
96
+        $this->user_service          = $user_service;
97
+
98
+        $dataset_uri = $configuration_service->get_dataset_uri();
99
+        $key         = $configuration_service->get_key();
100
+
101
+        if ( empty( $dataset_uri ) ) {
102
+            $settings_page = Wordlift_Admin_Settings_Page::get_instance();
103
+            if ( empty( $key ) ) {
104
+                $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>' );
105
+            } else {
106
+                $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>' );
107
+            }
108
+            $notice_service->add_error( $error );
109
+        }
110
+
111
+        // Load additional code if we're in the admin UI.
112
+        if ( is_admin() ) {
113
+
114
+            // Require the PHP files for the next code fragment.
115
+            self::require_files();
116
+
117
+            new Wordlift_Dashboard_Latest_News();
118
+
119
+            // Search Rankings.
120
+            $search_rankings_service = new Wordlift_Admin_Search_Rankings_Service( Wordlift_Api_Service::get_instance() );
121
+            new Wordlift_Admin_Search_Rankings_Ajax_Adapter( $search_rankings_service );
122
+
123
+            /*
124 124
 			 * Add support for `All Entity Types`.
125 125
 			 *
126 126
 			 * @since 3.20.0
127 127
 			 *
128 128
 			 * @see https://github.com/insideout10/wordlift-plugin/issues/835
129 129
 			 */
130
-			if ( WL_ALL_ENTITY_TYPES ) {
131
-				require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-schemaorg-taxonomy-metabox.php';
132
-				require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-schemaorg-property-metabox.php';
130
+            if ( WL_ALL_ENTITY_TYPES ) {
131
+                require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-schemaorg-taxonomy-metabox.php';
132
+                require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-schemaorg-property-metabox.php';
133 133
 
134
-				// new Wordlift_Admin_Schemaorg_Property_Metabox( Wordlift_Schemaorg_Property_Service::get_instance() );
135
-				/*
134
+                // new Wordlift_Admin_Schemaorg_Property_Metabox( Wordlift_Schemaorg_Property_Service::get_instance() );
135
+                /*
136 136
 				 * The `Mappings` admin page.
137 137
 				 */
138
-				require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-mappings-page.php';
139
-				new Wordlift_Admin_Mappings_Page();
138
+                require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-mappings-page.php';
139
+                new Wordlift_Admin_Mappings_Page();
140 140
 
141
-				/*
141
+                /*
142 142
 				 * Allow sync'ing the schema.org taxonomy with the schema.org json file.
143 143
 				 *
144 144
 				 * @since 3.20.0
145 145
 				 */
146
-				require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/schemaorg/class-wordlift-schemaorg-sync-batch-operation.php';
146
+                require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/schemaorg/class-wordlift-schemaorg-sync-batch-operation.php';
147 147
 
148
-				$this->sync_batch_operation_ajax_adapter = new Wordlift_Batch_Operation_Ajax_Adapter( new Wordlift_Schemaorg_Sync_Batch_Operation(), 'wl_schemaorg_sync' );
148
+                $this->sync_batch_operation_ajax_adapter = new Wordlift_Batch_Operation_Ajax_Adapter( new Wordlift_Schemaorg_Sync_Batch_Operation(), 'wl_schemaorg_sync' );
149 149
 
150
-			}
150
+            }
151 151
 
152
-			/*
152
+            /*
153 153
 			 * Add the {@link Wordlift_Admin_Term_Adapter}.
154 154
 			 *
155 155
 			 * @since 3.20.0
156 156
 			 */
157
-			require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-term-adapter.php';
158
-			new Wordlift_Admin_Term_Adapter();
157
+            require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-term-adapter.php';
158
+            new Wordlift_Admin_Term_Adapter();
159 159
 
160
-			/*
160
+            /*
161 161
 			 * The new dashboard.
162 162
 			 *
163 163
 			 * @since 3.20.0
164 164
 			 *
165 165
 			 * @see https://github.com/insideout10/wordlift-plugin/issues/879
166 166
 			 */
167
-			new Wordlift_Admin_Dashboard_V2(
168
-				$search_rankings_service,
169
-				Wordlift::get_instance()->get_dashboard_service(),
170
-				Wordlift_Entity_Service::get_instance()
171
-			);
172
-			new Wordlift_Admin_Not_Enriched_Filter();
173
-
174
-		}
175
-
176
-		// Set the singleton instance.
177
-		self::$instance = $this;
178
-
179
-	}
180
-
181
-	/**
182
-	 * Get the singleton instance.
183
-	 *
184
-	 * @since 3.19.4
185
-	 *
186
-	 * @return \Wordlift_Admin The singleton instance.
187
-	 */
188
-	public static function get_instance() {
189
-
190
-		return self::$instance;
191
-	}
192
-
193
-	/**
194
-	 * Register the stylesheets for the admin area.
195
-	 *
196
-	 * @since    1.0.0
197
-	 */
198
-	public function enqueue_styles() {
199
-
200
-		/**
201
-		 * This function is provided for demonstration purposes only.
202
-		 *
203
-		 * An instance of this class should be passed to the run() function
204
-		 * defined in Wordlift_Loader as all of the hooks are defined
205
-		 * in that particular class.
206
-		 *
207
-		 * The Wordlift_Loader will then create the relationship
208
-		 * between the defined hooks and the functions defined in this
209
-		 * class.
210
-		 */
211
-
212
-		wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' );
213
-
214
-	}
215
-
216
-	/**
217
-	 * Register the JavaScript for the admin area.
218
-	 *
219
-	 * @since    1.0.0
220
-	 */
221
-	public function enqueue_scripts() {
222
-
223
-		/*
167
+            new Wordlift_Admin_Dashboard_V2(
168
+                $search_rankings_service,
169
+                Wordlift::get_instance()->get_dashboard_service(),
170
+                Wordlift_Entity_Service::get_instance()
171
+            );
172
+            new Wordlift_Admin_Not_Enriched_Filter();
173
+
174
+        }
175
+
176
+        // Set the singleton instance.
177
+        self::$instance = $this;
178
+
179
+    }
180
+
181
+    /**
182
+     * Get the singleton instance.
183
+     *
184
+     * @since 3.19.4
185
+     *
186
+     * @return \Wordlift_Admin The singleton instance.
187
+     */
188
+    public static function get_instance() {
189
+
190
+        return self::$instance;
191
+    }
192
+
193
+    /**
194
+     * Register the stylesheets for the admin area.
195
+     *
196
+     * @since    1.0.0
197
+     */
198
+    public function enqueue_styles() {
199
+
200
+        /**
201
+         * This function is provided for demonstration purposes only.
202
+         *
203
+         * An instance of this class should be passed to the run() function
204
+         * defined in Wordlift_Loader as all of the hooks are defined
205
+         * in that particular class.
206
+         *
207
+         * The Wordlift_Loader will then create the relationship
208
+         * between the defined hooks and the functions defined in this
209
+         * class.
210
+         */
211
+
212
+        wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' );
213
+
214
+    }
215
+
216
+    /**
217
+     * Register the JavaScript for the admin area.
218
+     *
219
+     * @since    1.0.0
220
+     */
221
+    public function enqueue_scripts() {
222
+
223
+        /*
224 224
 		 * Do not load our scripts on the Filter Urls plugin admin pages.
225 225
 		 *
226 226
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/901
227 227
 		 * @since 3.20.0
228 228
 		 */
229
-		$screen = get_current_screen();
230
-		if ( is_a( $screen, 'WP_Screen' ) && 'filter-urls_page_filter_urls_form' === $screen->id ) {
231
-			return;
232
-		}
229
+        $screen = get_current_screen();
230
+        if ( is_a( $screen, 'WP_Screen' ) && 'filter-urls_page_filter_urls_form' === $screen->id ) {
231
+            return;
232
+        }
233 233
 
234
-		// Enqueue the admin scripts.
235
-		wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/1/admin.js', array(
236
-			'jquery',
237
-			'underscore',
238
-			'backbone',
239
-		), $this->version, false );
234
+        // Enqueue the admin scripts.
235
+        wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/1/admin.js', array(
236
+            'jquery',
237
+            'underscore',
238
+            'backbone',
239
+        ), $this->version, false );
240 240
 
241 241
 
242
-		$can_edit_wordlift_entities = current_user_can( 'edit_wordlift_entities' );
242
+        $can_edit_wordlift_entities = current_user_can( 'edit_wordlift_entities' );
243 243
 
244
-		/*
244
+        /*
245 245
 		 * People that can create entities will see the scope set in the wp-config.php file (by default `cloud`). People
246 246
 		 * that cannot edit create entities will always see the local entities.
247 247
 		 *
248 248
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/839
249 249
 		 */
250
-		$autocomplete_scope = $can_edit_wordlift_entities ? WL_AUTOCOMPLETE_SCOPE : "local";
251
-
252
-		// Set the basic params.
253
-		$params = array(
254
-			// @todo scripts in admin should use wp.post.
255
-			'ajax_url'                   => admin_url( 'admin-ajax.php' ),
256
-			// @todo remove specific actions from settings.
257
-			'action'                     => 'entity_by_title',
258
-			'datasetUri'                 => $this->configuration_service->get_dataset_uri(),
259
-			'language'                   => $this->configuration_service->get_language_code(),
260
-			'link_by_default'            => $this->configuration_service->is_link_by_default(),
261
-			// Whether the current user is allowed to create new entities.
262
-			//
263
-			// @see https://github.com/insideout10/wordlift-plugin/issues/561
264
-			'can_create_entities'        => $can_edit_wordlift_entities ? 'yes' : 'no',
265
-			'l10n'                       => array(
266
-				'You already published an entity with the same name'                 => __( 'You already published an entity with the same name: ', 'wordlift' ),
267
-				'logo_selection_title'                                               => __( 'WordLift Choose Logo', 'wordlift' ),
268
-				'logo_selection_button'                                              => array( 'text' => __( 'Choose Logo', 'wordlift' ) ),
269
-				'Type at least 3 characters to search...'                            => _x( 'Type at least 3 characters to search...', 'Autocomplete Select', 'wordlift' ),
270
-				'No results found for your search.'                                  => _x( 'No results found: try changing or removing some words.', 'Autocomplete Select', 'wordlift' ),
271
-				'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' ),
272
-				'Add keywords to track'                                              => __( 'Add Keywords to track', 'wordlift' ),
273
-			),
274
-			'wl_autocomplete_nonce'      => wp_create_nonce( 'wordlift_autocomplete' ),
275
-			'autocomplete_scope'         => $autocomplete_scope,
276
-			/**
277
-			 * Allow 3rd parties to define the default editor id. This turns useful if 3rd parties load
278
-			 * or change the TinyMCE id.
279
-			 *
280
-			 * The editor id is currently referenced by `src/coffee/editpost-widget/app.services.EditorAdapter.coffee`.
281
-			 *
282
-			 * @since 3.19.4
283
-			 *
284
-			 * @see https://github.com/insideout10/wordlift-plugin/issues/848
285
-			 *
286
-			 * @param string $editor The default editor id, by default `content`.
287
-			 */
288
-			'default_editor_id'          => apply_filters( 'wl_default_editor_id', 'content' ),
289
-			/**
290
-			 * Add the link to the Search Keywords admin page.
291
-			 *
292
-			 * @since 3.20.0
293
-			 */
294
-			'search_keywords_admin_page' => admin_url( 'admin.php?page=wl_configuration_admin_menu&tab=search-keywords' ),
295
-		);
296
-
297
-		// Set post-related values if there's a current post.
298
-		if ( null !== $post = $entity_being_edited = get_post() ) {
299
-
300
-			$params['post_id']           = $entity_being_edited->ID;
301
-			$entity_service              = Wordlift_Entity_Service::get_instance();
302
-			$params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && $entity_service->is_entity( $post->ID ) && is_numeric( get_the_ID() );
303
-			// We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it
304
-			// from the results, since we don't want the current entity to be discovered by the analysis.
305
-			//
306
-			// See https://github.com/insideout10/wordlift-plugin/issues/345
307
-			$params['itemId']                      = $entity_service->get_uri( $entity_being_edited->ID );
308
-			$params['wl_schemaorg_property_nonce'] = wp_create_nonce( 'wl_schemaorg_property' );
309
-
310
-			/*
250
+        $autocomplete_scope = $can_edit_wordlift_entities ? WL_AUTOCOMPLETE_SCOPE : "local";
251
+
252
+        // Set the basic params.
253
+        $params = array(
254
+            // @todo scripts in admin should use wp.post.
255
+            'ajax_url'                   => admin_url( 'admin-ajax.php' ),
256
+            // @todo remove specific actions from settings.
257
+            'action'                     => 'entity_by_title',
258
+            'datasetUri'                 => $this->configuration_service->get_dataset_uri(),
259
+            'language'                   => $this->configuration_service->get_language_code(),
260
+            'link_by_default'            => $this->configuration_service->is_link_by_default(),
261
+            // Whether the current user is allowed to create new entities.
262
+            //
263
+            // @see https://github.com/insideout10/wordlift-plugin/issues/561
264
+            'can_create_entities'        => $can_edit_wordlift_entities ? 'yes' : 'no',
265
+            'l10n'                       => array(
266
+                'You already published an entity with the same name'                 => __( 'You already published an entity with the same name: ', 'wordlift' ),
267
+                'logo_selection_title'                                               => __( 'WordLift Choose Logo', 'wordlift' ),
268
+                'logo_selection_button'                                              => array( 'text' => __( 'Choose Logo', 'wordlift' ) ),
269
+                'Type at least 3 characters to search...'                            => _x( 'Type at least 3 characters to search...', 'Autocomplete Select', 'wordlift' ),
270
+                'No results found for your search.'                                  => _x( 'No results found: try changing or removing some words.', 'Autocomplete Select', 'wordlift' ),
271
+                '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' ),
272
+                'Add keywords to track'                                              => __( 'Add Keywords to track', 'wordlift' ),
273
+            ),
274
+            'wl_autocomplete_nonce'      => wp_create_nonce( 'wordlift_autocomplete' ),
275
+            'autocomplete_scope'         => $autocomplete_scope,
276
+            /**
277
+             * Allow 3rd parties to define the default editor id. This turns useful if 3rd parties load
278
+             * or change the TinyMCE id.
279
+             *
280
+             * The editor id is currently referenced by `src/coffee/editpost-widget/app.services.EditorAdapter.coffee`.
281
+             *
282
+             * @since 3.19.4
283
+             *
284
+             * @see https://github.com/insideout10/wordlift-plugin/issues/848
285
+             *
286
+             * @param string $editor The default editor id, by default `content`.
287
+             */
288
+            'default_editor_id'          => apply_filters( 'wl_default_editor_id', 'content' ),
289
+            /**
290
+             * Add the link to the Search Keywords admin page.
291
+             *
292
+             * @since 3.20.0
293
+             */
294
+            'search_keywords_admin_page' => admin_url( 'admin.php?page=wl_configuration_admin_menu&tab=search-keywords' ),
295
+        );
296
+
297
+        // Set post-related values if there's a current post.
298
+        if ( null !== $post = $entity_being_edited = get_post() ) {
299
+
300
+            $params['post_id']           = $entity_being_edited->ID;
301
+            $entity_service              = Wordlift_Entity_Service::get_instance();
302
+            $params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && $entity_service->is_entity( $post->ID ) && is_numeric( get_the_ID() );
303
+            // We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it
304
+            // from the results, since we don't want the current entity to be discovered by the analysis.
305
+            //
306
+            // See https://github.com/insideout10/wordlift-plugin/issues/345
307
+            $params['itemId']                      = $entity_service->get_uri( $entity_being_edited->ID );
308
+            $params['wl_schemaorg_property_nonce'] = wp_create_nonce( 'wl_schemaorg_property' );
309
+
310
+            /*
311 311
 			 * Add the `properties` if `WL_ALL_ENTITY_TYPES` is enabled.
312 312
 			 *
313 313
 			 * @see https://github.com/insideout10/wordlift-plugin/issues/835
314 314
 			 */
315
-			if ( WL_ALL_ENTITY_TYPES ) {
316
-				$params['properties'] = Wordlift_Schemaorg_Property_Service::get_instance()->get_all( $post->ID );
317
-			}
318
-
319
-		}
320
-
321
-		// Finally output the params as `wlSettings` for JavaScript code.
322
-		wp_localize_script( $this->plugin_name, 'wlSettings', apply_filters( 'wl_admin_settings', $params ) );
323
-
324
-	}
325
-
326
-	/**
327
-	 * Require files needed for the Admin UI.
328
-	 *
329
-	 * @since 3.20.0
330
-	 */
331
-	private static function require_files() {
332
-
333
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard-latest-news.php';
334
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-search-rankings-service.php';
335
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-search-rankings-ajax-adapter.php';
336
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard-v2.php';
337
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-not-enriched-filter.php';
338
-
339
-	}
340
-
341
-	public static function is_gutenberg() {
342
-		if ( function_exists( 'is_gutenberg_page' ) &&
343
-		     is_gutenberg_page()
344
-		) {
345
-			// The Gutenberg plugin is on.
346
-			return true;
347
-		}
348
-		$current_screen = get_current_screen();
349
-		if ( method_exists( $current_screen, 'is_block_editor' ) &&
350
-		     $current_screen->is_block_editor()
351
-		) {
352
-			// Gutenberg page on 5+.
353
-			return true;
354
-		}
355
-
356
-		return false;
357
-	}
315
+            if ( WL_ALL_ENTITY_TYPES ) {
316
+                $params['properties'] = Wordlift_Schemaorg_Property_Service::get_instance()->get_all( $post->ID );
317
+            }
318
+
319
+        }
320
+
321
+        // Finally output the params as `wlSettings` for JavaScript code.
322
+        wp_localize_script( $this->plugin_name, 'wlSettings', apply_filters( 'wl_admin_settings', $params ) );
323
+
324
+    }
325
+
326
+    /**
327
+     * Require files needed for the Admin UI.
328
+     *
329
+     * @since 3.20.0
330
+     */
331
+    private static function require_files() {
332
+
333
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard-latest-news.php';
334
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-search-rankings-service.php';
335
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-search-rankings-ajax-adapter.php';
336
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard-v2.php';
337
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-not-enriched-filter.php';
338
+
339
+    }
340
+
341
+    public static function is_gutenberg() {
342
+        if ( function_exists( 'is_gutenberg_page' ) &&
343
+             is_gutenberg_page()
344
+        ) {
345
+            // The Gutenberg plugin is on.
346
+            return true;
347
+        }
348
+        $current_screen = get_current_screen();
349
+        if ( method_exists( $current_screen, 'is_block_editor' ) &&
350
+             $current_screen->is_block_editor()
351
+        ) {
352
+            // Gutenberg page on 5+.
353
+            return true;
354
+        }
355
+
356
+        return false;
357
+    }
358 358
 
359 359
 }
Please login to merge, or discard this patch.
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 	 * @param \Wordlift_Notice_Service        $notice_service The notice service.
88 88
 	 * @param \Wordlift_User_Service          $user_service The {@link Wordlift_User_Service} instance.
89 89
 	 */
90
-	public function __construct( $plugin_name, $version, $configuration_service, $notice_service, $user_service ) {
90
+	public function __construct($plugin_name, $version, $configuration_service, $notice_service, $user_service) {
91 91
 
92 92
 		$this->plugin_name = $plugin_name;
93 93
 		$this->version     = $version;
@@ -98,18 +98,18 @@  discard block
 block discarded – undo
98 98
 		$dataset_uri = $configuration_service->get_dataset_uri();
99 99
 		$key         = $configuration_service->get_key();
100 100
 
101
-		if ( empty( $dataset_uri ) ) {
101
+		if (empty($dataset_uri)) {
102 102
 			$settings_page = Wordlift_Admin_Settings_Page::get_instance();
103
-			if ( empty( $key ) ) {
104
-				$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>' );
103
+			if (empty($key)) {
104
+				$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>');
105 105
 			} else {
106
-				$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>' );
106
+				$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>');
107 107
 			}
108
-			$notice_service->add_error( $error );
108
+			$notice_service->add_error($error);
109 109
 		}
110 110
 
111 111
 		// Load additional code if we're in the admin UI.
112
-		if ( is_admin() ) {
112
+		if (is_admin()) {
113 113
 
114 114
 			// Require the PHP files for the next code fragment.
115 115
 			self::require_files();
@@ -117,8 +117,8 @@  discard block
 block discarded – undo
117 117
 			new Wordlift_Dashboard_Latest_News();
118 118
 
119 119
 			// Search Rankings.
120
-			$search_rankings_service = new Wordlift_Admin_Search_Rankings_Service( Wordlift_Api_Service::get_instance() );
121
-			new Wordlift_Admin_Search_Rankings_Ajax_Adapter( $search_rankings_service );
120
+			$search_rankings_service = new Wordlift_Admin_Search_Rankings_Service(Wordlift_Api_Service::get_instance());
121
+			new Wordlift_Admin_Search_Rankings_Ajax_Adapter($search_rankings_service);
122 122
 
123 123
 			/*
124 124
 			 * Add support for `All Entity Types`.
@@ -127,15 +127,15 @@  discard block
 block discarded – undo
127 127
 			 *
128 128
 			 * @see https://github.com/insideout10/wordlift-plugin/issues/835
129 129
 			 */
130
-			if ( WL_ALL_ENTITY_TYPES ) {
131
-				require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-schemaorg-taxonomy-metabox.php';
132
-				require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-schemaorg-property-metabox.php';
130
+			if (WL_ALL_ENTITY_TYPES) {
131
+				require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-schemaorg-taxonomy-metabox.php';
132
+				require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-schemaorg-property-metabox.php';
133 133
 
134 134
 				// new Wordlift_Admin_Schemaorg_Property_Metabox( Wordlift_Schemaorg_Property_Service::get_instance() );
135 135
 				/*
136 136
 				 * The `Mappings` admin page.
137 137
 				 */
138
-				require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-mappings-page.php';
138
+				require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-mappings-page.php';
139 139
 				new Wordlift_Admin_Mappings_Page();
140 140
 
141 141
 				/*
@@ -143,9 +143,9 @@  discard block
 block discarded – undo
143 143
 				 *
144 144
 				 * @since 3.20.0
145 145
 				 */
146
-				require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/schemaorg/class-wordlift-schemaorg-sync-batch-operation.php';
146
+				require_once plugin_dir_path(dirname(__FILE__)).'includes/schemaorg/class-wordlift-schemaorg-sync-batch-operation.php';
147 147
 
148
-				$this->sync_batch_operation_ajax_adapter = new Wordlift_Batch_Operation_Ajax_Adapter( new Wordlift_Schemaorg_Sync_Batch_Operation(), 'wl_schemaorg_sync' );
148
+				$this->sync_batch_operation_ajax_adapter = new Wordlift_Batch_Operation_Ajax_Adapter(new Wordlift_Schemaorg_Sync_Batch_Operation(), 'wl_schemaorg_sync');
149 149
 
150 150
 			}
151 151
 
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 			 *
155 155
 			 * @since 3.20.0
156 156
 			 */
157
-			require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-term-adapter.php';
157
+			require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-term-adapter.php';
158 158
 			new Wordlift_Admin_Term_Adapter();
159 159
 
160 160
 			/*
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 		 * class.
210 210
 		 */
211 211
 
212
-		wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' );
212
+		wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__).'css/wordlift-admin.css', array(), $this->version, 'all');
213 213
 
214 214
 	}
215 215
 
@@ -227,19 +227,19 @@  discard block
 block discarded – undo
227 227
 		 * @since 3.20.0
228 228
 		 */
229 229
 		$screen = get_current_screen();
230
-		if ( is_a( $screen, 'WP_Screen' ) && 'filter-urls_page_filter_urls_form' === $screen->id ) {
230
+		if (is_a($screen, 'WP_Screen') && 'filter-urls_page_filter_urls_form' === $screen->id) {
231 231
 			return;
232 232
 		}
233 233
 
234 234
 		// Enqueue the admin scripts.
235
-		wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/1/admin.js', array(
235
+		wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__).'js/1/admin.js', array(
236 236
 			'jquery',
237 237
 			'underscore',
238 238
 			'backbone',
239
-		), $this->version, false );
239
+		), $this->version, false);
240 240
 
241 241
 
242
-		$can_edit_wordlift_entities = current_user_can( 'edit_wordlift_entities' );
242
+		$can_edit_wordlift_entities = current_user_can('edit_wordlift_entities');
243 243
 
244 244
 		/*
245 245
 		 * People that can create entities will see the scope set in the wp-config.php file (by default `cloud`). People
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 		// Set the basic params.
253 253
 		$params = array(
254 254
 			// @todo scripts in admin should use wp.post.
255
-			'ajax_url'                   => admin_url( 'admin-ajax.php' ),
255
+			'ajax_url'                   => admin_url('admin-ajax.php'),
256 256
 			// @todo remove specific actions from settings.
257 257
 			'action'                     => 'entity_by_title',
258 258
 			'datasetUri'                 => $this->configuration_service->get_dataset_uri(),
@@ -263,15 +263,15 @@  discard block
 block discarded – undo
263 263
 			// @see https://github.com/insideout10/wordlift-plugin/issues/561
264 264
 			'can_create_entities'        => $can_edit_wordlift_entities ? 'yes' : 'no',
265 265
 			'l10n'                       => array(
266
-				'You already published an entity with the same name'                 => __( 'You already published an entity with the same name: ', 'wordlift' ),
267
-				'logo_selection_title'                                               => __( 'WordLift Choose Logo', 'wordlift' ),
268
-				'logo_selection_button'                                              => array( 'text' => __( 'Choose Logo', 'wordlift' ) ),
269
-				'Type at least 3 characters to search...'                            => _x( 'Type at least 3 characters to search...', 'Autocomplete Select', 'wordlift' ),
270
-				'No results found for your search.'                                  => _x( 'No results found: try changing or removing some words.', 'Autocomplete Select', 'wordlift' ),
271
-				'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' ),
272
-				'Add keywords to track'                                              => __( 'Add Keywords to track', 'wordlift' ),
266
+				'You already published an entity with the same name'                 => __('You already published an entity with the same name: ', 'wordlift'),
267
+				'logo_selection_title'                                               => __('WordLift Choose Logo', 'wordlift'),
268
+				'logo_selection_button'                                              => array('text' => __('Choose Logo', 'wordlift')),
269
+				'Type at least 3 characters to search...'                            => _x('Type at least 3 characters to search...', 'Autocomplete Select', 'wordlift'),
270
+				'No results found for your search.'                                  => _x('No results found: try changing or removing some words.', 'Autocomplete Select', 'wordlift'),
271
+				'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'),
272
+				'Add keywords to track'                                              => __('Add Keywords to track', 'wordlift'),
273 273
 			),
274
-			'wl_autocomplete_nonce'      => wp_create_nonce( 'wordlift_autocomplete' ),
274
+			'wl_autocomplete_nonce'      => wp_create_nonce('wordlift_autocomplete'),
275 275
 			'autocomplete_scope'         => $autocomplete_scope,
276 276
 			/**
277 277
 			 * Allow 3rd parties to define the default editor id. This turns useful if 3rd parties load
@@ -285,41 +285,41 @@  discard block
 block discarded – undo
285 285
 			 *
286 286
 			 * @param string $editor The default editor id, by default `content`.
287 287
 			 */
288
-			'default_editor_id'          => apply_filters( 'wl_default_editor_id', 'content' ),
288
+			'default_editor_id'          => apply_filters('wl_default_editor_id', 'content'),
289 289
 			/**
290 290
 			 * Add the link to the Search Keywords admin page.
291 291
 			 *
292 292
 			 * @since 3.20.0
293 293
 			 */
294
-			'search_keywords_admin_page' => admin_url( 'admin.php?page=wl_configuration_admin_menu&tab=search-keywords' ),
294
+			'search_keywords_admin_page' => admin_url('admin.php?page=wl_configuration_admin_menu&tab=search-keywords'),
295 295
 		);
296 296
 
297 297
 		// Set post-related values if there's a current post.
298
-		if ( null !== $post = $entity_being_edited = get_post() ) {
298
+		if (null !== $post = $entity_being_edited = get_post()) {
299 299
 
300 300
 			$params['post_id']           = $entity_being_edited->ID;
301 301
 			$entity_service              = Wordlift_Entity_Service::get_instance();
302
-			$params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && $entity_service->is_entity( $post->ID ) && is_numeric( get_the_ID() );
302
+			$params['entityBeingEdited'] = isset($entity_being_edited->post_type) && $entity_service->is_entity($post->ID) && is_numeric(get_the_ID());
303 303
 			// We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it
304 304
 			// from the results, since we don't want the current entity to be discovered by the analysis.
305 305
 			//
306 306
 			// See https://github.com/insideout10/wordlift-plugin/issues/345
307
-			$params['itemId']                      = $entity_service->get_uri( $entity_being_edited->ID );
308
-			$params['wl_schemaorg_property_nonce'] = wp_create_nonce( 'wl_schemaorg_property' );
307
+			$params['itemId']                      = $entity_service->get_uri($entity_being_edited->ID);
308
+			$params['wl_schemaorg_property_nonce'] = wp_create_nonce('wl_schemaorg_property');
309 309
 
310 310
 			/*
311 311
 			 * Add the `properties` if `WL_ALL_ENTITY_TYPES` is enabled.
312 312
 			 *
313 313
 			 * @see https://github.com/insideout10/wordlift-plugin/issues/835
314 314
 			 */
315
-			if ( WL_ALL_ENTITY_TYPES ) {
316
-				$params['properties'] = Wordlift_Schemaorg_Property_Service::get_instance()->get_all( $post->ID );
315
+			if (WL_ALL_ENTITY_TYPES) {
316
+				$params['properties'] = Wordlift_Schemaorg_Property_Service::get_instance()->get_all($post->ID);
317 317
 			}
318 318
 
319 319
 		}
320 320
 
321 321
 		// Finally output the params as `wlSettings` for JavaScript code.
322
-		wp_localize_script( $this->plugin_name, 'wlSettings', apply_filters( 'wl_admin_settings', $params ) );
322
+		wp_localize_script($this->plugin_name, 'wlSettings', apply_filters('wl_admin_settings', $params));
323 323
 
324 324
 	}
325 325
 
@@ -330,23 +330,23 @@  discard block
 block discarded – undo
330 330
 	 */
331 331
 	private static function require_files() {
332 332
 
333
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard-latest-news.php';
334
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-search-rankings-service.php';
335
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-search-rankings-ajax-adapter.php';
336
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard-v2.php';
337
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-not-enriched-filter.php';
333
+		require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-dashboard-latest-news.php';
334
+		require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-search-rankings-service.php';
335
+		require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-search-rankings-ajax-adapter.php';
336
+		require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-dashboard-v2.php';
337
+		require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-not-enriched-filter.php';
338 338
 
339 339
 	}
340 340
 
341 341
 	public static function is_gutenberg() {
342
-		if ( function_exists( 'is_gutenberg_page' ) &&
342
+		if (function_exists('is_gutenberg_page') &&
343 343
 		     is_gutenberg_page()
344 344
 		) {
345 345
 			// The Gutenberg plugin is on.
346 346
 			return true;
347 347
 		}
348 348
 		$current_screen = get_current_screen();
349
-		if ( method_exists( $current_screen, 'is_block_editor' ) &&
349
+		if (method_exists($current_screen, 'is_block_editor') &&
350 350
 		     $current_screen->is_block_editor()
351 351
 		) {
352 352
 			// Gutenberg page on 5+.
Please login to merge, or discard this patch.