Completed
Push — develop ( 9c9e32...c47bcf )
by David
02:45
created
src/admin/class-wordlift-admin-settings-page.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -111,7 +111,7 @@
 block discarded – undo
111 111
 	 * Get the singleton instance of the Notice service.
112 112
 	 *
113 113
 	 * @since 3.14.0
114
-	 * @return \Wordlift_Admin_Settings_Page The singleton instance of the settings page service.
114
+	 * @return Wordlift_Notice_Service The singleton instance of the settings page service.
115 115
 	 */
116 116
 	public static function get_instance() {
117 117
 
Please login to merge, or discard this patch.
Indentation   +316 added lines, -316 removed lines patch added patch discarded remove patch
@@ -18,321 +18,321 @@
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Admin_Settings_Page extends Wordlift_Admin_Page {
20 20
 
21
-	/**
22
-	 * A singleton instance of the Notice service.
23
-	 *
24
-	 * @since 3.2.0
25
-	 * @access private
26
-	 * @var \Wordlift_Notice_Service $instance A singleton instance of the Notice service.
27
-	 */
28
-	private static $instance;
29
-
30
-	/**
31
-	 * A {@link Wordlift_Entity_Service} instance.
32
-	 *
33
-	 * @since  3.11.0
34
-	 * @access private
35
-	 * @var \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance.
36
-	 */
37
-	private $entity_service;
38
-
39
-	/**
40
-	 * A {@link Wordlift_Configuration_Service} instance.
41
-	 *
42
-	 * @since  3.11.0
43
-	 * @access private
44
-	 * @var \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance.
45
-	 */
46
-	private $configuration_service;
47
-
48
-	/**
49
-	 * A {@link Wordlift_Admin_Input_Element} element renderer.
50
-	 *
51
-	 * @since  3.11.0
52
-	 * @access private
53
-	 * @var \Wordlift_Admin_Input_Element $input_element An {@link Wordlift_Admin_Input_Element} element renderer.
54
-	 */
55
-	private $input_element;
56
-
57
-	/**
58
-	 * A {@link Wordlift_Admin_Radio_Input_Element} element renderer.
59
-	 *
60
-	 * @since  3.13.0
61
-	 * @access protected
62
-	 * @var \Wordlift_Admin_Radio_Input_Element $radio_input_element A {@link Wordlift_Admin_Radio_Input_Element} element renderer.
63
-	 */
64
-	private $radio_input_element;
65
-
66
-	/**
67
-	 * A {@link Wordlift_Admin_Language_Select_Element} element renderer.
68
-	 *
69
-	 * @since  3.11.0
70
-	 * @access private
71
-	 * @var \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer.
72
-	 */
73
-	private $language_select_element;
74
-
75
-	/**
76
-	 * A {@link Wordlift_Admin_Publisher_Element} element renderer.
77
-	 *
78
-	 * @since  3.11.0
79
-	 * @access private
80
-	 * @var \Wordlift_Admin_Publisher_Element $publisher_element A {@link Wordlift_Admin_Publisher_Element} element renderer.
81
-	 */
82
-	private $publisher_element;
83
-
84
-	/**
85
-	 * Create a {@link Wordlift_Admin_Settings_Page} instance.
86
-	 *
87
-	 * @since 3.11.0
88
-	 *
89
-	 * @param \Wordlift_Configuration_Service         $configuration_service
90
-	 * @param \Wordlift_Entity_Service                $entity_service
91
-	 * @param \Wordlift_Admin_Input_Element           $input_element
92
-	 * @param \Wordlift_Admin_Language_Select_Element $language_select_element
93
-	 * @param \Wordlift_Admin_Publisher_Element       $publisher_element
94
-	 * @param \Wordlift_Admin_Radio_Input_Element     $radio_input_element
95
-	 */
96
-	function __construct( $configuration_service, $entity_service, $input_element, $language_select_element, $publisher_element, $radio_input_element ) {
97
-
98
-		$this->configuration_service = $configuration_service;
99
-		$this->entity_service        = $entity_service;
100
-
101
-		// Set a reference to the UI elements.
102
-		$this->input_element           = $input_element;
103
-		$this->radio_input_element     = $radio_input_element;
104
-		$this->language_select_element = $language_select_element;
105
-		$this->publisher_element       = $publisher_element;
106
-
107
-		self::$instance = $this;
108
-	}
109
-
110
-	/**
111
-	 * Get the singleton instance of the Notice service.
112
-	 *
113
-	 * @since 3.14.0
114
-	 * @return \Wordlift_Admin_Settings_Page The singleton instance of the settings page service.
115
-	 */
116
-	public static function get_instance() {
117
-
118
-		return self::$instance;
119
-	}
120
-
121
-	/**
122
-	 * @inheritdoc
123
-	 */
124
-	function get_parent_slug() {
125
-
126
-		return 'wl_admin_menu';
127
-	}
128
-
129
-	/**
130
-	 * @inheritdoc
131
-	 */
132
-	function get_capability() {
133
-
134
-		return 'manage_options';
135
-	}
136
-
137
-	/**
138
-	 * @inheritdoc
139
-	 */
140
-	function get_page_title() {
141
-
142
-		return 'WorldLift Settings';
143
-	}
144
-
145
-	/**
146
-	 * @inheritdoc
147
-	 */
148
-	function get_menu_title() {
149
-
150
-		return 'Settings';
151
-	}
152
-
153
-	/**
154
-	 * @inheritdoc
155
-	 */
156
-	function get_menu_slug() {
157
-
158
-		return 'wl_configuration_admin_menu';
159
-	}
160
-
161
-	/**
162
-	 * @inheritdoc
163
-	 */
164
-	function get_partial_name() {
165
-
166
-		return 'wordlift-admin-settings-page.php';
167
-	}
168
-
169
-	/**
170
-	 * @inheritdoc
171
-	 */
172
-	public function enqueue_scripts() {
173
-
174
-		// Enqueue the media scripts to be used for the publisher's logo selection.
175
-		wp_enqueue_media();
176
-
177
-		// JavaScript required for the settings page.
178
-		// @todo: try to move to the `wordlift-admin.bundle.js`.
179
-		wp_enqueue_script( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/wordlift-admin-settings-page.bundle.js', array( 'wp-util' ) );
180
-
181
-	}
182
-
183
-	/**
184
-	 * Configure all the configuration parameters.
185
-	 *
186
-	 * Called by the *admin_init* hook.
187
-	 *
188
-	 * @since 3.11.0
189
-	 */
190
-	function admin_init() {
191
-
192
-		// Register WordLift's general settings, providing our own sanitize callback
193
-		// which will also check whether the user filled the WL Publisher form.
194
-		register_setting(
195
-			'wl_general_settings',
196
-			'wl_general_settings',
197
-			array( $this, 'sanitize_callback', )
198
-		);
199
-
200
-		// Add the general settings section.
201
-		add_settings_section(
202
-			'wl_general_settings_section', // ID used to identify this section and with which to register options.
203
-			'',                            // Section header.
204
-			'',                            // Callback used to render the description of the section.
205
-			'wl_general_settings'          // Page on which to add this section of options.
206
-		);
207
-
208
-		$key_args = array(
209
-			'id'          => 'wl-key',
210
-			'name'        => 'wl_general_settings[' . Wordlift_Configuration_Service::KEY . ']',
211
-			'value'       => $this->configuration_service->get_key(),
212
-			'description' => _x( 'Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift' ),
213
-		);
214
-
215
-		// Set the class for the key field based on the validity of the key.
216
-		// Class should be "untouched" for an empty (virgin) value, "valid"
217
-		// if the key is valid, or "invalid" otherwise.
218
-		$validation_service = new Wordlift_Key_Validation_Service();
219
-
220
-		if ( empty( $key_args['value'] ) ) {
221
-			$key_args['css_class'] = 'untouched';
222
-		} elseif ( $validation_service->is_valid( $key_args['value'] ) ) {
223
-			$key_args['css_class'] = 'valid';
224
-		} else {
225
-			$key_args['css_class'] = 'invalid';
226
-		}
227
-
228
-		// Add the `key` field.
229
-		add_settings_field(
230
-			'wl-key',                                       // Element id used to identify the field throughout the theme.
231
-			_x( 'WordLift Key', 'wordlift' ),               // The label to the left of the option interface element.
232
-			// The name of the function responsible for rendering the option interface.
233
-			array( $this->input_element, 'render', ),
234
-			'wl_general_settings',                          // The page on which this option will be displayed.
235
-			'wl_general_settings_section',                  // The name of the section to which this field belongs.
236
-			$key_args                                       // The array of arguments to pass to the callback. In this case, just a description.
237
-		);
238
-
239
-		// Entity Base Path input.
240
-		$entity_base_path_args = array(
241
-			// The array of arguments to pass to the callback. In this case, just a description.
242
-			'id'          => 'wl-entity-base-path',
243
-			'name'        => 'wl_general_settings[' . Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY . ']',
244
-			'value'       => $this->configuration_service->get_entity_base_path(),
245
-			'description' => sprintf( _x( 'All new pages created with WordLift, will be stored inside your internal vocabulary. You can customize the url pattern of these pages in the field above. Check our <a href="%s">FAQs</a> if you need more info.', 'wordlift' ), 'https://wordlift.io/wordlift-user-faqs/#10-why-and-how-should-i-customize-the-url-of-the-entity-pages-created-in-my-vocabulary' ),
246
-		);
247
-
248
-		$entity_base_path_args['readonly'] = 0 < $this->entity_service->count();
249
-
250
-		// Add the `wl_entity_base_path` field.
251
-		add_settings_field(
252
-			'wl-entity-base-path',                                // ID used to identify the field throughout the theme
253
-			_x( 'Entity Base Path', 'wordlift' ),                 // The label to the left of the option interface element
254
-			// The name of the function responsible for rendering the option interface
255
-			array( $this->input_element, 'render', ),
256
-			'wl_general_settings',                                // The page on which this option will be displayed
257
-			'wl_general_settings_section',                        // The name of the section to which this field belongs
258
-			$entity_base_path_args
259
-		);
260
-
261
-		// Add the `language_name` field.
262
-		add_settings_field(
263
-			'wl-site-language',
264
-			_x( 'Site Language', 'wordlift' ),
265
-			array( $this->language_select_element, 'render' ),
266
-			'wl_general_settings',
267
-			'wl_general_settings_section',
268
-			array(
269
-				// The array of arguments to pass to the callback. In this case, just a description.
270
-				'id'          => 'wl-site-language',
271
-				'name'        => 'wl_general_settings[' . Wordlift_Configuration_Service::LANGUAGE . ']',
272
-				'value'       => $this->configuration_service->get_language_code(),
273
-				'description' => __( 'Each WordLift Key can be used only in one language. Pick yours.', 'wordlift' ),
274
-			)
275
-		);
276
-
277
-		// Add the `publisher` field.
278
-		add_settings_field(
279
-			'wl-publisher-id',
280
-			_x( 'Publisher', 'wordlift' ),
281
-			array( $this->publisher_element, 'render' ),
282
-			'wl_general_settings',
283
-			'wl_general_settings_section',
284
-			array(
285
-				'id'   => 'wl-publisher-id',
286
-				'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::PUBLISHER_ID . ']',
287
-			)
288
-		);
289
-
290
-		// Add the `link by default` field.
291
-		add_settings_field(
292
-			'wl-link-by-default',
293
-			_x( 'Link by Default', 'wordlift' ),
294
-			array( $this->radio_input_element, 'render' ),
295
-			'wl_general_settings',
296
-			'wl_general_settings_section',
297
-			array(
298
-				'id'          => 'wl-link-by-default',
299
-				'name'        => 'wl_general_settings[' . Wordlift_Configuration_Service::LINK_BY_DEFAULT . ']',
300
-				'value'       => $this->configuration_service->is_link_by_default() ? 'yes' : 'no',
301
-				'description' => _x( 'Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift' ),
302
-			)
303
-		);
304
-
305
-	}
306
-
307
-	/**
308
-	 * Sanitize the configuration settings to be stored.
309
-	 *
310
-	 * If a new entity is being created for the publisher, create it and set The
311
-	 * publisher setting.
312
-	 *
313
-	 * @since 3.11.0
314
-	 *
315
-	 * @param array $input The configuration settings array.
316
-	 *
317
-	 * @return array The sanitized input array.
318
-	 */
319
-	function sanitize_callback( $input ) {
320
-
321
-		// Check whether a publisher name has been set.
322
-		if ( isset( $_POST['wl_publisher'] ) && ! empty( $_POST['wl_publisher']['name'] ) ) {
323
-			$name         = $_POST['wl_publisher']['name'];
324
-			$type         = $_POST['wl_publisher']['type'];
325
-			$thumbnail_id = $_POST['wl_publisher']['thumbnail_id'] ?: null;
326
-
327
-			// Set the type URI, either http://schema.org/Person or http://schema.org/Organization.
328
-			$type_uri = sprintf( 'http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person' );
329
-
330
-			// Create an entity for the publisher and assign it to the input
331
-			// parameter which WordPress automatically saves into the settings.
332
-			$input['publisher_id'] = $this->entity_service->create( $name, $type_uri, $thumbnail_id, 'publish' );
333
-		}
334
-
335
-		return $input;
336
-	}
21
+    /**
22
+     * A singleton instance of the Notice service.
23
+     *
24
+     * @since 3.2.0
25
+     * @access private
26
+     * @var \Wordlift_Notice_Service $instance A singleton instance of the Notice service.
27
+     */
28
+    private static $instance;
29
+
30
+    /**
31
+     * A {@link Wordlift_Entity_Service} instance.
32
+     *
33
+     * @since  3.11.0
34
+     * @access private
35
+     * @var \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance.
36
+     */
37
+    private $entity_service;
38
+
39
+    /**
40
+     * A {@link Wordlift_Configuration_Service} instance.
41
+     *
42
+     * @since  3.11.0
43
+     * @access private
44
+     * @var \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance.
45
+     */
46
+    private $configuration_service;
47
+
48
+    /**
49
+     * A {@link Wordlift_Admin_Input_Element} element renderer.
50
+     *
51
+     * @since  3.11.0
52
+     * @access private
53
+     * @var \Wordlift_Admin_Input_Element $input_element An {@link Wordlift_Admin_Input_Element} element renderer.
54
+     */
55
+    private $input_element;
56
+
57
+    /**
58
+     * A {@link Wordlift_Admin_Radio_Input_Element} element renderer.
59
+     *
60
+     * @since  3.13.0
61
+     * @access protected
62
+     * @var \Wordlift_Admin_Radio_Input_Element $radio_input_element A {@link Wordlift_Admin_Radio_Input_Element} element renderer.
63
+     */
64
+    private $radio_input_element;
65
+
66
+    /**
67
+     * A {@link Wordlift_Admin_Language_Select_Element} element renderer.
68
+     *
69
+     * @since  3.11.0
70
+     * @access private
71
+     * @var \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer.
72
+     */
73
+    private $language_select_element;
74
+
75
+    /**
76
+     * A {@link Wordlift_Admin_Publisher_Element} element renderer.
77
+     *
78
+     * @since  3.11.0
79
+     * @access private
80
+     * @var \Wordlift_Admin_Publisher_Element $publisher_element A {@link Wordlift_Admin_Publisher_Element} element renderer.
81
+     */
82
+    private $publisher_element;
83
+
84
+    /**
85
+     * Create a {@link Wordlift_Admin_Settings_Page} instance.
86
+     *
87
+     * @since 3.11.0
88
+     *
89
+     * @param \Wordlift_Configuration_Service         $configuration_service
90
+     * @param \Wordlift_Entity_Service                $entity_service
91
+     * @param \Wordlift_Admin_Input_Element           $input_element
92
+     * @param \Wordlift_Admin_Language_Select_Element $language_select_element
93
+     * @param \Wordlift_Admin_Publisher_Element       $publisher_element
94
+     * @param \Wordlift_Admin_Radio_Input_Element     $radio_input_element
95
+     */
96
+    function __construct( $configuration_service, $entity_service, $input_element, $language_select_element, $publisher_element, $radio_input_element ) {
97
+
98
+        $this->configuration_service = $configuration_service;
99
+        $this->entity_service        = $entity_service;
100
+
101
+        // Set a reference to the UI elements.
102
+        $this->input_element           = $input_element;
103
+        $this->radio_input_element     = $radio_input_element;
104
+        $this->language_select_element = $language_select_element;
105
+        $this->publisher_element       = $publisher_element;
106
+
107
+        self::$instance = $this;
108
+    }
109
+
110
+    /**
111
+     * Get the singleton instance of the Notice service.
112
+     *
113
+     * @since 3.14.0
114
+     * @return \Wordlift_Admin_Settings_Page The singleton instance of the settings page service.
115
+     */
116
+    public static function get_instance() {
117
+
118
+        return self::$instance;
119
+    }
120
+
121
+    /**
122
+     * @inheritdoc
123
+     */
124
+    function get_parent_slug() {
125
+
126
+        return 'wl_admin_menu';
127
+    }
128
+
129
+    /**
130
+     * @inheritdoc
131
+     */
132
+    function get_capability() {
133
+
134
+        return 'manage_options';
135
+    }
136
+
137
+    /**
138
+     * @inheritdoc
139
+     */
140
+    function get_page_title() {
141
+
142
+        return 'WorldLift Settings';
143
+    }
144
+
145
+    /**
146
+     * @inheritdoc
147
+     */
148
+    function get_menu_title() {
149
+
150
+        return 'Settings';
151
+    }
152
+
153
+    /**
154
+     * @inheritdoc
155
+     */
156
+    function get_menu_slug() {
157
+
158
+        return 'wl_configuration_admin_menu';
159
+    }
160
+
161
+    /**
162
+     * @inheritdoc
163
+     */
164
+    function get_partial_name() {
165
+
166
+        return 'wordlift-admin-settings-page.php';
167
+    }
168
+
169
+    /**
170
+     * @inheritdoc
171
+     */
172
+    public function enqueue_scripts() {
173
+
174
+        // Enqueue the media scripts to be used for the publisher's logo selection.
175
+        wp_enqueue_media();
176
+
177
+        // JavaScript required for the settings page.
178
+        // @todo: try to move to the `wordlift-admin.bundle.js`.
179
+        wp_enqueue_script( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/wordlift-admin-settings-page.bundle.js', array( 'wp-util' ) );
180
+
181
+    }
182
+
183
+    /**
184
+     * Configure all the configuration parameters.
185
+     *
186
+     * Called by the *admin_init* hook.
187
+     *
188
+     * @since 3.11.0
189
+     */
190
+    function admin_init() {
191
+
192
+        // Register WordLift's general settings, providing our own sanitize callback
193
+        // which will also check whether the user filled the WL Publisher form.
194
+        register_setting(
195
+            'wl_general_settings',
196
+            'wl_general_settings',
197
+            array( $this, 'sanitize_callback', )
198
+        );
199
+
200
+        // Add the general settings section.
201
+        add_settings_section(
202
+            'wl_general_settings_section', // ID used to identify this section and with which to register options.
203
+            '',                            // Section header.
204
+            '',                            // Callback used to render the description of the section.
205
+            'wl_general_settings'          // Page on which to add this section of options.
206
+        );
207
+
208
+        $key_args = array(
209
+            'id'          => 'wl-key',
210
+            'name'        => 'wl_general_settings[' . Wordlift_Configuration_Service::KEY . ']',
211
+            'value'       => $this->configuration_service->get_key(),
212
+            'description' => _x( 'Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift' ),
213
+        );
214
+
215
+        // Set the class for the key field based on the validity of the key.
216
+        // Class should be "untouched" for an empty (virgin) value, "valid"
217
+        // if the key is valid, or "invalid" otherwise.
218
+        $validation_service = new Wordlift_Key_Validation_Service();
219
+
220
+        if ( empty( $key_args['value'] ) ) {
221
+            $key_args['css_class'] = 'untouched';
222
+        } elseif ( $validation_service->is_valid( $key_args['value'] ) ) {
223
+            $key_args['css_class'] = 'valid';
224
+        } else {
225
+            $key_args['css_class'] = 'invalid';
226
+        }
227
+
228
+        // Add the `key` field.
229
+        add_settings_field(
230
+            'wl-key',                                       // Element id used to identify the field throughout the theme.
231
+            _x( 'WordLift Key', 'wordlift' ),               // The label to the left of the option interface element.
232
+            // The name of the function responsible for rendering the option interface.
233
+            array( $this->input_element, 'render', ),
234
+            'wl_general_settings',                          // The page on which this option will be displayed.
235
+            'wl_general_settings_section',                  // The name of the section to which this field belongs.
236
+            $key_args                                       // The array of arguments to pass to the callback. In this case, just a description.
237
+        );
238
+
239
+        // Entity Base Path input.
240
+        $entity_base_path_args = array(
241
+            // The array of arguments to pass to the callback. In this case, just a description.
242
+            'id'          => 'wl-entity-base-path',
243
+            'name'        => 'wl_general_settings[' . Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY . ']',
244
+            'value'       => $this->configuration_service->get_entity_base_path(),
245
+            'description' => sprintf( _x( 'All new pages created with WordLift, will be stored inside your internal vocabulary. You can customize the url pattern of these pages in the field above. Check our <a href="%s">FAQs</a> if you need more info.', 'wordlift' ), 'https://wordlift.io/wordlift-user-faqs/#10-why-and-how-should-i-customize-the-url-of-the-entity-pages-created-in-my-vocabulary' ),
246
+        );
247
+
248
+        $entity_base_path_args['readonly'] = 0 < $this->entity_service->count();
249
+
250
+        // Add the `wl_entity_base_path` field.
251
+        add_settings_field(
252
+            'wl-entity-base-path',                                // ID used to identify the field throughout the theme
253
+            _x( 'Entity Base Path', 'wordlift' ),                 // The label to the left of the option interface element
254
+            // The name of the function responsible for rendering the option interface
255
+            array( $this->input_element, 'render', ),
256
+            'wl_general_settings',                                // The page on which this option will be displayed
257
+            'wl_general_settings_section',                        // The name of the section to which this field belongs
258
+            $entity_base_path_args
259
+        );
260
+
261
+        // Add the `language_name` field.
262
+        add_settings_field(
263
+            'wl-site-language',
264
+            _x( 'Site Language', 'wordlift' ),
265
+            array( $this->language_select_element, 'render' ),
266
+            'wl_general_settings',
267
+            'wl_general_settings_section',
268
+            array(
269
+                // The array of arguments to pass to the callback. In this case, just a description.
270
+                'id'          => 'wl-site-language',
271
+                'name'        => 'wl_general_settings[' . Wordlift_Configuration_Service::LANGUAGE . ']',
272
+                'value'       => $this->configuration_service->get_language_code(),
273
+                'description' => __( 'Each WordLift Key can be used only in one language. Pick yours.', 'wordlift' ),
274
+            )
275
+        );
276
+
277
+        // Add the `publisher` field.
278
+        add_settings_field(
279
+            'wl-publisher-id',
280
+            _x( 'Publisher', 'wordlift' ),
281
+            array( $this->publisher_element, 'render' ),
282
+            'wl_general_settings',
283
+            'wl_general_settings_section',
284
+            array(
285
+                'id'   => 'wl-publisher-id',
286
+                'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::PUBLISHER_ID . ']',
287
+            )
288
+        );
289
+
290
+        // Add the `link by default` field.
291
+        add_settings_field(
292
+            'wl-link-by-default',
293
+            _x( 'Link by Default', 'wordlift' ),
294
+            array( $this->radio_input_element, 'render' ),
295
+            'wl_general_settings',
296
+            'wl_general_settings_section',
297
+            array(
298
+                'id'          => 'wl-link-by-default',
299
+                'name'        => 'wl_general_settings[' . Wordlift_Configuration_Service::LINK_BY_DEFAULT . ']',
300
+                'value'       => $this->configuration_service->is_link_by_default() ? 'yes' : 'no',
301
+                'description' => _x( 'Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift' ),
302
+            )
303
+        );
304
+
305
+    }
306
+
307
+    /**
308
+     * Sanitize the configuration settings to be stored.
309
+     *
310
+     * If a new entity is being created for the publisher, create it and set The
311
+     * publisher setting.
312
+     *
313
+     * @since 3.11.0
314
+     *
315
+     * @param array $input The configuration settings array.
316
+     *
317
+     * @return array The sanitized input array.
318
+     */
319
+    function sanitize_callback( $input ) {
320
+
321
+        // Check whether a publisher name has been set.
322
+        if ( isset( $_POST['wl_publisher'] ) && ! empty( $_POST['wl_publisher']['name'] ) ) {
323
+            $name         = $_POST['wl_publisher']['name'];
324
+            $type         = $_POST['wl_publisher']['type'];
325
+            $thumbnail_id = $_POST['wl_publisher']['thumbnail_id'] ?: null;
326
+
327
+            // Set the type URI, either http://schema.org/Person or http://schema.org/Organization.
328
+            $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person' );
329
+
330
+            // Create an entity for the publisher and assign it to the input
331
+            // parameter which WordPress automatically saves into the settings.
332
+            $input['publisher_id'] = $this->entity_service->create( $name, $type_uri, $thumbnail_id, 'publish' );
333
+        }
334
+
335
+        return $input;
336
+    }
337 337
 
338 338
 }
Please login to merge, or discard this patch.
src/admin/class-wordlift-admin.php 2 patches
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -22,137 +22,137 @@
 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
-	 * Initialize the class and set its properties.
45
-	 *
46
-	 * @since    1.0.0
47
-	 *
48
-	 * @param   string                           $plugin_name           The name of this plugin.
49
-	 * @param   string                           $version               The version of this plugin.
50
-	 * @param    \Wordlift_Configuration_Service $configuration_service The configuration service.
51
-	 * @param    \Wordlift_Notice_Service        $notice_service        The notice service.
52
-	 */
53
-	public function __construct( $plugin_name, $version, $configuration_service, $notice_service ) {
54
-
55
-		$this->plugin_name = $plugin_name;
56
-		$this->version     = $version;
57
-
58
-		$dataset_uri = $configuration_service->get_dataset_uri();
59
-		$key         = $configuration_service->get_key();
60
-
61
-		if ( empty( $dataset_uri ) ) {
62
-			$settings_page = Wordlift_Admin_Settings_Page::get_instance();
63
-			if ( empty( $key ) ) {
64
-				$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>' );
65
-			} else {
66
-				$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>' );
67
-			}
68
-			$notice_service->add_error( $error );
69
-		}
70
-
71
-	}
72
-
73
-	/**
74
-	 * Register the stylesheets for the admin area.
75
-	 *
76
-	 * @since    1.0.0
77
-	 */
78
-	public function enqueue_styles() {
79
-
80
-		/**
81
-		 * This function is provided for demonstration purposes only.
82
-		 *
83
-		 * An instance of this class should be passed to the run() function
84
-		 * defined in Wordlift_Loader as all of the hooks are defined
85
-		 * in that particular class.
86
-		 *
87
-		 * The Wordlift_Loader will then create the relationship
88
-		 * between the defined hooks and the functions defined in this
89
-		 * class.
90
-		 */
91
-
92
-		wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' );
93
-
94
-	}
95
-
96
-	/**
97
-	 * Register the JavaScript for the admin area.
98
-	 *
99
-	 * @since    1.0.0
100
-	 */
101
-	public function enqueue_scripts() {
102
-
103
-		/**
104
-		 * This function is provided for demonstration purposes only.
105
-		 *
106
-		 * An instance of this class should be passed to the run() function
107
-		 * defined in Wordlift_Loader as all of the hooks are defined
108
-		 * in that particular class.
109
-		 *
110
-		 * The Wordlift_Loader will then create the relationship
111
-		 * between the defined hooks and the functions defined in this
112
-		 * class.
113
-		 */
114
-
115
-		$configuration_service = Wordlift_Configuration_Service::get_instance();
116
-
117
-		// Enqueue the admin scripts.
118
-		wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wordlift-admin.bundle.js', array(
119
-			'jquery',
120
-			'underscore',
121
-			'backbone',
122
-		), $this->version, false );
123
-
124
-		// Set the basic params.
125
-		$params = array(
126
-			// @todo scripts in admin should use wp.post.
127
-			'ajax_url'        => admin_url( 'admin-ajax.php' ),
128
-			// @todo remove specific actions from settings.
129
-			'action'          => 'entity_by_title',
130
-			'datasetUri'      => $configuration_service->get_dataset_uri(),
131
-			'language'        => $configuration_service->get_language_code(),
132
-			'link_by_default' => $configuration_service->is_link_by_default(),
133
-			'l10n'            => array(
134
-				'You already published an entity with the same name' => __( 'You already published an entity with the same name: ', 'wordlift' ),
135
-				'logo_selection_title'                               => __( 'WordLift Choose Logo', 'wordlift' ),
136
-				'logo_selection_button'                              => array( 'text' => __( 'Choose Logo', 'wordlift' ) ),
137
-			),
138
-		);
139
-
140
-		// Set post-related values if there's a current post.
141
-		if ( null !== $post = $entity_being_edited = get_post() ) {
142
-
143
-			$params['post_id']           = $entity_being_edited->ID;
144
-			$params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && Wordlift_Entity_Service::TYPE_NAME == $entity_being_edited->post_type && is_numeric( get_the_ID() );
145
-			// We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it
146
-			// from the results, since we don't want the current entity to be discovered by the analysis.
147
-			//
148
-			// See https://github.com/insideout10/wordlift-plugin/issues/345
149
-			$params['itemId'] = Wordlift_Entity_Service::get_instance()->get_uri( $entity_being_edited->ID );
150
-
151
-		}
152
-
153
-		// Finally output the params as `wlSettings` for JavaScript code.
154
-		wp_localize_script( $this->plugin_name, 'wlSettings', $params );
155
-
156
-	}
25
+    /**
26
+     * The ID of this plugin.
27
+     *
28
+     * @since    1.0.0
29
+     * @access   private
30
+     * @var      string $plugin_name The ID of this plugin.
31
+     */
32
+    private $plugin_name;
33
+
34
+    /**
35
+     * The version of this plugin.
36
+     *
37
+     * @since    1.0.0
38
+     * @access   private
39
+     * @var      string $version The current version of this plugin.
40
+     */
41
+    private $version;
42
+
43
+    /**
44
+     * Initialize the class and set its properties.
45
+     *
46
+     * @since    1.0.0
47
+     *
48
+     * @param   string                           $plugin_name           The name of this plugin.
49
+     * @param   string                           $version               The version of this plugin.
50
+     * @param    \Wordlift_Configuration_Service $configuration_service The configuration service.
51
+     * @param    \Wordlift_Notice_Service        $notice_service        The notice service.
52
+     */
53
+    public function __construct( $plugin_name, $version, $configuration_service, $notice_service ) {
54
+
55
+        $this->plugin_name = $plugin_name;
56
+        $this->version     = $version;
57
+
58
+        $dataset_uri = $configuration_service->get_dataset_uri();
59
+        $key         = $configuration_service->get_key();
60
+
61
+        if ( empty( $dataset_uri ) ) {
62
+            $settings_page = Wordlift_Admin_Settings_Page::get_instance();
63
+            if ( empty( $key ) ) {
64
+                $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>' );
65
+            } else {
66
+                $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>' );
67
+            }
68
+            $notice_service->add_error( $error );
69
+        }
70
+
71
+    }
72
+
73
+    /**
74
+     * Register the stylesheets for the admin area.
75
+     *
76
+     * @since    1.0.0
77
+     */
78
+    public function enqueue_styles() {
79
+
80
+        /**
81
+         * This function is provided for demonstration purposes only.
82
+         *
83
+         * An instance of this class should be passed to the run() function
84
+         * defined in Wordlift_Loader as all of the hooks are defined
85
+         * in that particular class.
86
+         *
87
+         * The Wordlift_Loader will then create the relationship
88
+         * between the defined hooks and the functions defined in this
89
+         * class.
90
+         */
91
+
92
+        wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' );
93
+
94
+    }
95
+
96
+    /**
97
+     * Register the JavaScript for the admin area.
98
+     *
99
+     * @since    1.0.0
100
+     */
101
+    public function enqueue_scripts() {
102
+
103
+        /**
104
+         * This function is provided for demonstration purposes only.
105
+         *
106
+         * An instance of this class should be passed to the run() function
107
+         * defined in Wordlift_Loader as all of the hooks are defined
108
+         * in that particular class.
109
+         *
110
+         * The Wordlift_Loader will then create the relationship
111
+         * between the defined hooks and the functions defined in this
112
+         * class.
113
+         */
114
+
115
+        $configuration_service = Wordlift_Configuration_Service::get_instance();
116
+
117
+        // Enqueue the admin scripts.
118
+        wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wordlift-admin.bundle.js', array(
119
+            'jquery',
120
+            'underscore',
121
+            'backbone',
122
+        ), $this->version, false );
123
+
124
+        // Set the basic params.
125
+        $params = array(
126
+            // @todo scripts in admin should use wp.post.
127
+            'ajax_url'        => admin_url( 'admin-ajax.php' ),
128
+            // @todo remove specific actions from settings.
129
+            'action'          => 'entity_by_title',
130
+            'datasetUri'      => $configuration_service->get_dataset_uri(),
131
+            'language'        => $configuration_service->get_language_code(),
132
+            'link_by_default' => $configuration_service->is_link_by_default(),
133
+            'l10n'            => array(
134
+                'You already published an entity with the same name' => __( 'You already published an entity with the same name: ', 'wordlift' ),
135
+                'logo_selection_title'                               => __( 'WordLift Choose Logo', 'wordlift' ),
136
+                'logo_selection_button'                              => array( 'text' => __( 'Choose Logo', 'wordlift' ) ),
137
+            ),
138
+        );
139
+
140
+        // Set post-related values if there's a current post.
141
+        if ( null !== $post = $entity_being_edited = get_post() ) {
142
+
143
+            $params['post_id']           = $entity_being_edited->ID;
144
+            $params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && Wordlift_Entity_Service::TYPE_NAME == $entity_being_edited->post_type && is_numeric( get_the_ID() );
145
+            // We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it
146
+            // from the results, since we don't want the current entity to be discovered by the analysis.
147
+            //
148
+            // See https://github.com/insideout10/wordlift-plugin/issues/345
149
+            $params['itemId'] = Wordlift_Entity_Service::get_instance()->get_uri( $entity_being_edited->ID );
150
+
151
+        }
152
+
153
+        // Finally output the params as `wlSettings` for JavaScript code.
154
+        wp_localize_script( $this->plugin_name, 'wlSettings', $params );
155
+
156
+    }
157 157
 
158 158
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 	 * @param    \Wordlift_Configuration_Service $configuration_service The configuration service.
51 51
 	 * @param    \Wordlift_Notice_Service        $notice_service        The notice service.
52 52
 	 */
53
-	public function __construct( $plugin_name, $version, $configuration_service, $notice_service ) {
53
+	public function __construct($plugin_name, $version, $configuration_service, $notice_service) {
54 54
 
55 55
 		$this->plugin_name = $plugin_name;
56 56
 		$this->version     = $version;
@@ -58,14 +58,14 @@  discard block
 block discarded – undo
58 58
 		$dataset_uri = $configuration_service->get_dataset_uri();
59 59
 		$key         = $configuration_service->get_key();
60 60
 
61
-		if ( empty( $dataset_uri ) ) {
61
+		if (empty($dataset_uri)) {
62 62
 			$settings_page = Wordlift_Admin_Settings_Page::get_instance();
63
-			if ( empty( $key ) ) {
64
-				$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>' );
63
+			if (empty($key)) {
64
+				$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>');
65 65
 			} else {
66
-				$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>' );
66
+				$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>');
67 67
 			}
68
-			$notice_service->add_error( $error );
68
+			$notice_service->add_error($error);
69 69
 		}
70 70
 
71 71
 	}
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 		 * class.
90 90
 		 */
91 91
 
92
-		wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' );
92
+		wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__).'css/wordlift-admin.css', array(), $this->version, 'all');
93 93
 
94 94
 	}
95 95
 
@@ -115,43 +115,43 @@  discard block
 block discarded – undo
115 115
 		$configuration_service = Wordlift_Configuration_Service::get_instance();
116 116
 
117 117
 		// Enqueue the admin scripts.
118
-		wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wordlift-admin.bundle.js', array(
118
+		wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__).'js/wordlift-admin.bundle.js', array(
119 119
 			'jquery',
120 120
 			'underscore',
121 121
 			'backbone',
122
-		), $this->version, false );
122
+		), $this->version, false);
123 123
 
124 124
 		// Set the basic params.
125 125
 		$params = array(
126 126
 			// @todo scripts in admin should use wp.post.
127
-			'ajax_url'        => admin_url( 'admin-ajax.php' ),
127
+			'ajax_url'        => admin_url('admin-ajax.php'),
128 128
 			// @todo remove specific actions from settings.
129 129
 			'action'          => 'entity_by_title',
130 130
 			'datasetUri'      => $configuration_service->get_dataset_uri(),
131 131
 			'language'        => $configuration_service->get_language_code(),
132 132
 			'link_by_default' => $configuration_service->is_link_by_default(),
133 133
 			'l10n'            => array(
134
-				'You already published an entity with the same name' => __( 'You already published an entity with the same name: ', 'wordlift' ),
135
-				'logo_selection_title'                               => __( 'WordLift Choose Logo', 'wordlift' ),
136
-				'logo_selection_button'                              => array( 'text' => __( 'Choose Logo', 'wordlift' ) ),
134
+				'You already published an entity with the same name' => __('You already published an entity with the same name: ', 'wordlift'),
135
+				'logo_selection_title'                               => __('WordLift Choose Logo', 'wordlift'),
136
+				'logo_selection_button'                              => array('text' => __('Choose Logo', 'wordlift')),
137 137
 			),
138 138
 		);
139 139
 
140 140
 		// Set post-related values if there's a current post.
141
-		if ( null !== $post = $entity_being_edited = get_post() ) {
141
+		if (null !== $post = $entity_being_edited = get_post()) {
142 142
 
143 143
 			$params['post_id']           = $entity_being_edited->ID;
144
-			$params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && Wordlift_Entity_Service::TYPE_NAME == $entity_being_edited->post_type && is_numeric( get_the_ID() );
144
+			$params['entityBeingEdited'] = isset($entity_being_edited->post_type) && Wordlift_Entity_Service::TYPE_NAME == $entity_being_edited->post_type && is_numeric(get_the_ID());
145 145
 			// We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it
146 146
 			// from the results, since we don't want the current entity to be discovered by the analysis.
147 147
 			//
148 148
 			// See https://github.com/insideout10/wordlift-plugin/issues/345
149
-			$params['itemId'] = Wordlift_Entity_Service::get_instance()->get_uri( $entity_being_edited->ID );
149
+			$params['itemId'] = Wordlift_Entity_Service::get_instance()->get_uri($entity_being_edited->ID);
150 150
 
151 151
 		}
152 152
 
153 153
 		// Finally output the params as `wlSettings` for JavaScript code.
154
-		wp_localize_script( $this->plugin_name, 'wlSettings', $params );
154
+		wp_localize_script($this->plugin_name, 'wlSettings', $params);
155 155
 
156 156
 	}
157 157
 
Please login to merge, or discard this patch.
src/admin/class-wordlift-admin-page.php 2 patches
Indentation   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -18,130 +18,130 @@
 block discarded – undo
18 18
  */
19 19
 abstract class Wordlift_Admin_Page {
20 20
 
21
-	/**
22
-	 * Get the parent slug.
23
-	 *
24
-	 * @since 3.11.0
25
-	 *
26
-	 * @return string The parent slug (default 'wl_admin_menu').
27
-	 */
28
-	protected function get_parent_slug() {
29
-
30
-		return 'wl_admin_menu';
31
-	}
32
-
33
-	/**
34
-	 * Get the required capability.
35
-	 *
36
-	 * @since 3.11.0
37
-	 *
38
-	 * @return string The capability (default 'manage_options').
39
-	 */
40
-	protected function get_capability() {
41
-
42
-		return 'manage_options';
43
-	}
44
-
45
-	/**
46
-	 * Get the page title. Will be translated.
47
-	 *
48
-	 * @since 3.11.0
49
-	 *
50
-	 * @return string The page title.
51
-	 */
52
-	abstract function get_page_title();
53
-
54
-	/**
55
-	 * Get the menu title. Will be translated.
56
-	 *
57
-	 * @since 3.11.0
58
-	 *
59
-	 * @return string The menu title.
60
-	 */
61
-	abstract function get_menu_title();
62
-
63
-	/**
64
-	 * Get the menu slug.
65
-	 *
66
-	 * @since 3.11.0
67
-	 *
68
-	 * @return string The menu slug.
69
-	 */
70
-	abstract function get_menu_slug();
71
-
72
-	/**
73
-	 * Get the page url.
74
-	 *
75
-	 * @since 3.14.0
76
-	 *
77
-	 * @return string The escaped url of the admin page
78
-	 */
79
-	function get_url() {
80
-
81
-		// ideally should have used menu_page_url, but it is loaded later than some usages.
82
-		$url = admin_url( 'admin.php?page=' . $this->get_menu_slug() );
83
-
84
-		return esc_url( $url );
85
-	}
86
-
87
-	/**
88
-	 * Get the partial file name, used in the {@link render} function.
89
-	 *
90
-	 * @since 3.11.0
91
-	 *
92
-	 * @return string The partial file name.
93
-	 */
94
-	abstract function get_partial_name();
95
-
96
-	/**
97
-	 * The `admin_menu` callback. Will call {@link add_submenu_page} to add the
98
-	 * page to the admin menu.
99
-	 *
100
-	 * @since 3.11.0
101
-	 *
102
-	 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
103
-	 */
104
-	public function admin_menu() {
105
-
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( 'admin_print_scripts-' . $page, array(
120
-			$this,
121
-			'enqueue_scripts',
122
-		) );
123
-
124
-		// Finally return the page hook_suffix.
125
-		return $page;
126
-	}
127
-
128
-	/**
129
-	 * Enqueue scripts for the specific page. Subclasses can override this function
130
-	 * to provide their own styles/scripts.
131
-	 *
132
-	 * @since 3.11.0
133
-	 */
134
-	public function enqueue_scripts() {
135
-	}
136
-
137
-	/**
138
-	 * Render the page.
139
-	 */
140
-	public function render() {
141
-
142
-		// Include the partial.
143
-		include( plugin_dir_path( __FILE__ ) . 'partials/' . $this->get_partial_name() );
144
-
145
-	}
21
+    /**
22
+     * Get the parent slug.
23
+     *
24
+     * @since 3.11.0
25
+     *
26
+     * @return string The parent slug (default 'wl_admin_menu').
27
+     */
28
+    protected function get_parent_slug() {
29
+
30
+        return 'wl_admin_menu';
31
+    }
32
+
33
+    /**
34
+     * Get the required capability.
35
+     *
36
+     * @since 3.11.0
37
+     *
38
+     * @return string The capability (default 'manage_options').
39
+     */
40
+    protected function get_capability() {
41
+
42
+        return 'manage_options';
43
+    }
44
+
45
+    /**
46
+     * Get the page title. Will be translated.
47
+     *
48
+     * @since 3.11.0
49
+     *
50
+     * @return string The page title.
51
+     */
52
+    abstract function get_page_title();
53
+
54
+    /**
55
+     * Get the menu title. Will be translated.
56
+     *
57
+     * @since 3.11.0
58
+     *
59
+     * @return string The menu title.
60
+     */
61
+    abstract function get_menu_title();
62
+
63
+    /**
64
+     * Get the menu slug.
65
+     *
66
+     * @since 3.11.0
67
+     *
68
+     * @return string The menu slug.
69
+     */
70
+    abstract function get_menu_slug();
71
+
72
+    /**
73
+     * Get the page url.
74
+     *
75
+     * @since 3.14.0
76
+     *
77
+     * @return string The escaped url of the admin page
78
+     */
79
+    function get_url() {
80
+
81
+        // ideally should have used menu_page_url, but it is loaded later than some usages.
82
+        $url = admin_url( 'admin.php?page=' . $this->get_menu_slug() );
83
+
84
+        return esc_url( $url );
85
+    }
86
+
87
+    /**
88
+     * Get the partial file name, used in the {@link render} function.
89
+     *
90
+     * @since 3.11.0
91
+     *
92
+     * @return string The partial file name.
93
+     */
94
+    abstract function get_partial_name();
95
+
96
+    /**
97
+     * The `admin_menu` callback. Will call {@link add_submenu_page} to add the
98
+     * page to the admin menu.
99
+     *
100
+     * @since 3.11.0
101
+     *
102
+     * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
103
+     */
104
+    public function admin_menu() {
105
+
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( 'admin_print_scripts-' . $page, array(
120
+            $this,
121
+            'enqueue_scripts',
122
+        ) );
123
+
124
+        // Finally return the page hook_suffix.
125
+        return $page;
126
+    }
127
+
128
+    /**
129
+     * Enqueue scripts for the specific page. Subclasses can override this function
130
+     * to provide their own styles/scripts.
131
+     *
132
+     * @since 3.11.0
133
+     */
134
+    public function enqueue_scripts() {
135
+    }
136
+
137
+    /**
138
+     * Render the page.
139
+     */
140
+    public function render() {
141
+
142
+        // Include the partial.
143
+        include( plugin_dir_path( __FILE__ ) . 'partials/' . $this->get_partial_name() );
144
+
145
+    }
146 146
 
147 147
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -79,9 +79,9 @@  discard block
 block discarded – undo
79 79
 	function get_url() {
80 80
 
81 81
 		// ideally should have used menu_page_url, but it is loaded later than some usages.
82
-		$url = admin_url( 'admin.php?page=' . $this->get_menu_slug() );
82
+		$url = admin_url('admin.php?page='.$this->get_menu_slug());
83 83
 
84
-		return esc_url( $url );
84
+		return esc_url($url);
85 85
 	}
86 86
 
87 87
 	/**
@@ -110,16 +110,16 @@  discard block
 block discarded – undo
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
-		add_action( 'admin_print_scripts-' . $page, array(
119
+		add_action('admin_print_scripts-'.$page, array(
120 120
 			$this,
121 121
 			'enqueue_scripts',
122
-		) );
122
+		));
123 123
 
124 124
 		// Finally return the page hook_suffix.
125 125
 		return $page;
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 	public function render() {
141 141
 
142 142
 		// Include the partial.
143
-		include( plugin_dir_path( __FILE__ ) . 'partials/' . $this->get_partial_name() );
143
+		include(plugin_dir_path(__FILE__).'partials/'.$this->get_partial_name());
144 144
 
145 145
 	}
146 146
 
Please login to merge, or discard this patch.