@@ -18,351 +18,351 @@ |
||
| 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/1/settings.js', array( 'wp-util' ) ); |
|
| 180 | - wp_enqueue_style( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/settings.css' ); |
|
| 181 | - |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * Configure all the configuration parameters. |
|
| 186 | - * |
|
| 187 | - * Called by the *admin_init* hook. |
|
| 188 | - * |
|
| 189 | - * @since 3.11.0 |
|
| 190 | - */ |
|
| 191 | - function admin_init() { |
|
| 192 | - |
|
| 193 | - // Register WordLift's general settings, providing our own sanitize callback |
|
| 194 | - // which will also check whether the user filled the WL Publisher form. |
|
| 195 | - register_setting( |
|
| 196 | - 'wl_general_settings', |
|
| 197 | - 'wl_general_settings', |
|
| 198 | - array( $this, 'sanitize_callback', ) |
|
| 199 | - ); |
|
| 200 | - |
|
| 201 | - // Add the general settings section. |
|
| 202 | - add_settings_section( |
|
| 203 | - 'wl_general_settings_section', // ID used to identify this section and with which to register options. |
|
| 204 | - '', // Section header. |
|
| 205 | - '', // Callback used to render the description of the section. |
|
| 206 | - 'wl_general_settings' // Page on which to add this section of options. |
|
| 207 | - ); |
|
| 208 | - |
|
| 209 | - $key_args = array( |
|
| 210 | - 'id' => 'wl-key', |
|
| 211 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::KEY . ']', |
|
| 212 | - 'value' => $this->configuration_service->get_key(), |
|
| 213 | - 'description' => __( 'Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift' ), |
|
| 214 | - ); |
|
| 215 | - |
|
| 216 | - // Before we were used to validate the key beforehand, but this means |
|
| 217 | - // an http call whenever a page is opened in the admin area. Therefore |
|
| 218 | - // we now leave the input `untouched`, leaving to the client to update |
|
| 219 | - // the `css_class`. |
|
| 220 | - // |
|
| 221 | - // See https://github.com/insideout10/wordlift-plugin/issues/669. |
|
| 222 | - $key_args['css_class'] = 'untouched'; |
|
| 223 | - |
|
| 224 | - // Add the `key` field. |
|
| 225 | - add_settings_field( |
|
| 226 | - 'wl-key', // Element id used to identify the field throughout the theme. |
|
| 227 | - _x( 'WordLift Key', 'wordlift' ), // The label to the left of the option interface element. |
|
| 228 | - // The name of the function responsible for rendering the option interface. |
|
| 229 | - array( $this->input_element, 'render', ), |
|
| 230 | - 'wl_general_settings', // The page on which this option will be displayed. |
|
| 231 | - 'wl_general_settings_section', // The name of the section to which this field belongs. |
|
| 232 | - $key_args // The array of arguments to pass to the callback. In this case, just a description. |
|
| 233 | - ); |
|
| 234 | - |
|
| 235 | - // Entity Base Path input. |
|
| 236 | - $entity_base_path_args = array( |
|
| 237 | - // The array of arguments to pass to the callback. In this case, just a description. |
|
| 238 | - 'id' => 'wl-entity-base-path', |
|
| 239 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY . ']', |
|
| 240 | - 'value' => $this->configuration_service->get_entity_base_path(), |
|
| 241 | - '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' ), |
|
| 242 | - ); |
|
| 243 | - |
|
| 244 | - // The following call is very heavy on large web sites and is always run |
|
| 245 | - // also when not needed: |
|
| 246 | - // $entity_base_path_args['readonly'] = 0 < $this->entity_service->count(); |
|
| 247 | - // |
|
| 248 | - // It is now replaced by a filter to add the `readonly` flag to the |
|
| 249 | - // input element when this is actually rendered. |
|
| 250 | - add_filter( 'wl_admin_input_element_params', array( |
|
| 251 | - $this, |
|
| 252 | - 'entity_path_input_element_params', |
|
| 253 | - ) ); |
|
| 254 | - |
|
| 255 | - |
|
| 256 | - // Add the `wl_entity_base_path` field. |
|
| 257 | - add_settings_field( |
|
| 258 | - 'wl-entity-base-path', // ID used to identify the field throughout the theme |
|
| 259 | - _x( 'Entity Base Path', 'wordlift' ), // The label to the left of the option interface element |
|
| 260 | - // The name of the function responsible for rendering the option interface |
|
| 261 | - array( $this->input_element, 'render', ), |
|
| 262 | - 'wl_general_settings', // The page on which this option will be displayed |
|
| 263 | - 'wl_general_settings_section', // The name of the section to which this field belongs |
|
| 264 | - $entity_base_path_args |
|
| 265 | - ); |
|
| 266 | - |
|
| 267 | - // Add the `language_name` field. |
|
| 268 | - add_settings_field( |
|
| 269 | - 'wl-site-language', |
|
| 270 | - _x( 'Site Language', 'wordlift' ), |
|
| 271 | - array( $this->language_select_element, 'render' ), |
|
| 272 | - 'wl_general_settings', |
|
| 273 | - 'wl_general_settings_section', |
|
| 274 | - array( |
|
| 275 | - // The array of arguments to pass to the callback. In this case, just a description. |
|
| 276 | - 'id' => 'wl-site-language', |
|
| 277 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LANGUAGE . ']', |
|
| 278 | - 'value' => $this->configuration_service->get_language_code(), |
|
| 279 | - 'description' => __( 'Each WordLift Key can be used only in one language. Pick yours.', 'wordlift' ), |
|
| 280 | - ) |
|
| 281 | - ); |
|
| 282 | - |
|
| 283 | - // Add the `publisher` field. |
|
| 284 | - add_settings_field( |
|
| 285 | - 'wl-publisher-id', |
|
| 286 | - _x( 'Publisher', 'wordlift' ), |
|
| 287 | - array( $this->publisher_element, 'render' ), |
|
| 288 | - 'wl_general_settings', |
|
| 289 | - 'wl_general_settings_section', |
|
| 290 | - array( |
|
| 291 | - 'id' => 'wl-publisher-id', |
|
| 292 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::PUBLISHER_ID . ']', |
|
| 293 | - ) |
|
| 294 | - ); |
|
| 295 | - |
|
| 296 | - // Add the `link by default` field. |
|
| 297 | - add_settings_field( |
|
| 298 | - 'wl-link-by-default', |
|
| 299 | - _x( 'Link by Default', 'wordlift' ), |
|
| 300 | - array( $this->radio_input_element, 'render' ), |
|
| 301 | - 'wl_general_settings', |
|
| 302 | - 'wl_general_settings_section', |
|
| 303 | - array( |
|
| 304 | - 'id' => 'wl-link-by-default', |
|
| 305 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LINK_BY_DEFAULT . ']', |
|
| 306 | - 'value' => $this->configuration_service->is_link_by_default() ? 'yes' : 'no', |
|
| 307 | - 'description' => _x( 'Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift' ), |
|
| 308 | - ) |
|
| 309 | - ); |
|
| 310 | - |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * Filter the {@link Wordlift_Admin_Input_Element} in order to add the |
|
| 315 | - * `readonly` flag to the `wl-entity-base-path` input. |
|
| 316 | - * |
|
| 317 | - * @since 3.17.0 |
|
| 318 | - * |
|
| 319 | - * @param array $args An array of {@link Wordlift_Admin_Input_Element} parameters. |
|
| 320 | - * |
|
| 321 | - * @return array The updated array. |
|
| 322 | - */ |
|
| 323 | - public function entity_path_input_element_params( $args ) { |
|
| 324 | - |
|
| 325 | - // Bail out if it's not the `wl-entity-base-path`). |
|
| 326 | - if ( 'wl-entity-base-path' !== $args['id'] ) { |
|
| 327 | - return $args; |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - // Set the readonly flag according to the entities count. |
|
| 331 | - $args['readonly'] = 0 < $this->entity_service->count(); |
|
| 332 | - |
|
| 333 | - // Return the updated args. |
|
| 334 | - return $args; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * Sanitize the configuration settings to be stored. |
|
| 339 | - * |
|
| 340 | - * If a new entity is being created for the publisher, create it and set The |
|
| 341 | - * publisher setting. |
|
| 342 | - * |
|
| 343 | - * @since 3.11.0 |
|
| 344 | - * |
|
| 345 | - * @param array $input The configuration settings array. |
|
| 346 | - * |
|
| 347 | - * @return array The sanitized input array. |
|
| 348 | - */ |
|
| 349 | - function sanitize_callback( $input ) { |
|
| 350 | - |
|
| 351 | - // Check whether a publisher name has been set. |
|
| 352 | - if ( isset( $_POST['wl_publisher'] ) && ! empty( $_POST['wl_publisher']['name'] ) ) { |
|
| 353 | - $name = $_POST['wl_publisher']['name']; |
|
| 354 | - $type = $_POST['wl_publisher']['type']; |
|
| 355 | - $thumbnail_id = $_POST['wl_publisher']['thumbnail_id'] ?: null; |
|
| 356 | - |
|
| 357 | - // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
|
| 358 | - $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person' ); |
|
| 359 | - |
|
| 360 | - // Create an entity for the publisher and assign it to the input |
|
| 361 | - // parameter which WordPress automatically saves into the settings. |
|
| 362 | - $input['publisher_id'] = $this->entity_service->create( $name, $type_uri, $thumbnail_id, 'publish' ); |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - return $input; |
|
| 366 | - } |
|
| 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/1/settings.js', array( 'wp-util' ) ); |
|
| 180 | + wp_enqueue_style( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/settings.css' ); |
|
| 181 | + |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * Configure all the configuration parameters. |
|
| 186 | + * |
|
| 187 | + * Called by the *admin_init* hook. |
|
| 188 | + * |
|
| 189 | + * @since 3.11.0 |
|
| 190 | + */ |
|
| 191 | + function admin_init() { |
|
| 192 | + |
|
| 193 | + // Register WordLift's general settings, providing our own sanitize callback |
|
| 194 | + // which will also check whether the user filled the WL Publisher form. |
|
| 195 | + register_setting( |
|
| 196 | + 'wl_general_settings', |
|
| 197 | + 'wl_general_settings', |
|
| 198 | + array( $this, 'sanitize_callback', ) |
|
| 199 | + ); |
|
| 200 | + |
|
| 201 | + // Add the general settings section. |
|
| 202 | + add_settings_section( |
|
| 203 | + 'wl_general_settings_section', // ID used to identify this section and with which to register options. |
|
| 204 | + '', // Section header. |
|
| 205 | + '', // Callback used to render the description of the section. |
|
| 206 | + 'wl_general_settings' // Page on which to add this section of options. |
|
| 207 | + ); |
|
| 208 | + |
|
| 209 | + $key_args = array( |
|
| 210 | + 'id' => 'wl-key', |
|
| 211 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::KEY . ']', |
|
| 212 | + 'value' => $this->configuration_service->get_key(), |
|
| 213 | + 'description' => __( 'Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift' ), |
|
| 214 | + ); |
|
| 215 | + |
|
| 216 | + // Before we were used to validate the key beforehand, but this means |
|
| 217 | + // an http call whenever a page is opened in the admin area. Therefore |
|
| 218 | + // we now leave the input `untouched`, leaving to the client to update |
|
| 219 | + // the `css_class`. |
|
| 220 | + // |
|
| 221 | + // See https://github.com/insideout10/wordlift-plugin/issues/669. |
|
| 222 | + $key_args['css_class'] = 'untouched'; |
|
| 223 | + |
|
| 224 | + // Add the `key` field. |
|
| 225 | + add_settings_field( |
|
| 226 | + 'wl-key', // Element id used to identify the field throughout the theme. |
|
| 227 | + _x( 'WordLift Key', 'wordlift' ), // The label to the left of the option interface element. |
|
| 228 | + // The name of the function responsible for rendering the option interface. |
|
| 229 | + array( $this->input_element, 'render', ), |
|
| 230 | + 'wl_general_settings', // The page on which this option will be displayed. |
|
| 231 | + 'wl_general_settings_section', // The name of the section to which this field belongs. |
|
| 232 | + $key_args // The array of arguments to pass to the callback. In this case, just a description. |
|
| 233 | + ); |
|
| 234 | + |
|
| 235 | + // Entity Base Path input. |
|
| 236 | + $entity_base_path_args = array( |
|
| 237 | + // The array of arguments to pass to the callback. In this case, just a description. |
|
| 238 | + 'id' => 'wl-entity-base-path', |
|
| 239 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY . ']', |
|
| 240 | + 'value' => $this->configuration_service->get_entity_base_path(), |
|
| 241 | + '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' ), |
|
| 242 | + ); |
|
| 243 | + |
|
| 244 | + // The following call is very heavy on large web sites and is always run |
|
| 245 | + // also when not needed: |
|
| 246 | + // $entity_base_path_args['readonly'] = 0 < $this->entity_service->count(); |
|
| 247 | + // |
|
| 248 | + // It is now replaced by a filter to add the `readonly` flag to the |
|
| 249 | + // input element when this is actually rendered. |
|
| 250 | + add_filter( 'wl_admin_input_element_params', array( |
|
| 251 | + $this, |
|
| 252 | + 'entity_path_input_element_params', |
|
| 253 | + ) ); |
|
| 254 | + |
|
| 255 | + |
|
| 256 | + // Add the `wl_entity_base_path` field. |
|
| 257 | + add_settings_field( |
|
| 258 | + 'wl-entity-base-path', // ID used to identify the field throughout the theme |
|
| 259 | + _x( 'Entity Base Path', 'wordlift' ), // The label to the left of the option interface element |
|
| 260 | + // The name of the function responsible for rendering the option interface |
|
| 261 | + array( $this->input_element, 'render', ), |
|
| 262 | + 'wl_general_settings', // The page on which this option will be displayed |
|
| 263 | + 'wl_general_settings_section', // The name of the section to which this field belongs |
|
| 264 | + $entity_base_path_args |
|
| 265 | + ); |
|
| 266 | + |
|
| 267 | + // Add the `language_name` field. |
|
| 268 | + add_settings_field( |
|
| 269 | + 'wl-site-language', |
|
| 270 | + _x( 'Site Language', 'wordlift' ), |
|
| 271 | + array( $this->language_select_element, 'render' ), |
|
| 272 | + 'wl_general_settings', |
|
| 273 | + 'wl_general_settings_section', |
|
| 274 | + array( |
|
| 275 | + // The array of arguments to pass to the callback. In this case, just a description. |
|
| 276 | + 'id' => 'wl-site-language', |
|
| 277 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LANGUAGE . ']', |
|
| 278 | + 'value' => $this->configuration_service->get_language_code(), |
|
| 279 | + 'description' => __( 'Each WordLift Key can be used only in one language. Pick yours.', 'wordlift' ), |
|
| 280 | + ) |
|
| 281 | + ); |
|
| 282 | + |
|
| 283 | + // Add the `publisher` field. |
|
| 284 | + add_settings_field( |
|
| 285 | + 'wl-publisher-id', |
|
| 286 | + _x( 'Publisher', 'wordlift' ), |
|
| 287 | + array( $this->publisher_element, 'render' ), |
|
| 288 | + 'wl_general_settings', |
|
| 289 | + 'wl_general_settings_section', |
|
| 290 | + array( |
|
| 291 | + 'id' => 'wl-publisher-id', |
|
| 292 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::PUBLISHER_ID . ']', |
|
| 293 | + ) |
|
| 294 | + ); |
|
| 295 | + |
|
| 296 | + // Add the `link by default` field. |
|
| 297 | + add_settings_field( |
|
| 298 | + 'wl-link-by-default', |
|
| 299 | + _x( 'Link by Default', 'wordlift' ), |
|
| 300 | + array( $this->radio_input_element, 'render' ), |
|
| 301 | + 'wl_general_settings', |
|
| 302 | + 'wl_general_settings_section', |
|
| 303 | + array( |
|
| 304 | + 'id' => 'wl-link-by-default', |
|
| 305 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LINK_BY_DEFAULT . ']', |
|
| 306 | + 'value' => $this->configuration_service->is_link_by_default() ? 'yes' : 'no', |
|
| 307 | + 'description' => _x( 'Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift' ), |
|
| 308 | + ) |
|
| 309 | + ); |
|
| 310 | + |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * Filter the {@link Wordlift_Admin_Input_Element} in order to add the |
|
| 315 | + * `readonly` flag to the `wl-entity-base-path` input. |
|
| 316 | + * |
|
| 317 | + * @since 3.17.0 |
|
| 318 | + * |
|
| 319 | + * @param array $args An array of {@link Wordlift_Admin_Input_Element} parameters. |
|
| 320 | + * |
|
| 321 | + * @return array The updated array. |
|
| 322 | + */ |
|
| 323 | + public function entity_path_input_element_params( $args ) { |
|
| 324 | + |
|
| 325 | + // Bail out if it's not the `wl-entity-base-path`). |
|
| 326 | + if ( 'wl-entity-base-path' !== $args['id'] ) { |
|
| 327 | + return $args; |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + // Set the readonly flag according to the entities count. |
|
| 331 | + $args['readonly'] = 0 < $this->entity_service->count(); |
|
| 332 | + |
|
| 333 | + // Return the updated args. |
|
| 334 | + return $args; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * Sanitize the configuration settings to be stored. |
|
| 339 | + * |
|
| 340 | + * If a new entity is being created for the publisher, create it and set The |
|
| 341 | + * publisher setting. |
|
| 342 | + * |
|
| 343 | + * @since 3.11.0 |
|
| 344 | + * |
|
| 345 | + * @param array $input The configuration settings array. |
|
| 346 | + * |
|
| 347 | + * @return array The sanitized input array. |
|
| 348 | + */ |
|
| 349 | + function sanitize_callback( $input ) { |
|
| 350 | + |
|
| 351 | + // Check whether a publisher name has been set. |
|
| 352 | + if ( isset( $_POST['wl_publisher'] ) && ! empty( $_POST['wl_publisher']['name'] ) ) { |
|
| 353 | + $name = $_POST['wl_publisher']['name']; |
|
| 354 | + $type = $_POST['wl_publisher']['type']; |
|
| 355 | + $thumbnail_id = $_POST['wl_publisher']['thumbnail_id'] ?: null; |
|
| 356 | + |
|
| 357 | + // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
|
| 358 | + $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person' ); |
|
| 359 | + |
|
| 360 | + // Create an entity for the publisher and assign it to the input |
|
| 361 | + // parameter which WordPress automatically saves into the settings. |
|
| 362 | + $input['publisher_id'] = $this->entity_service->create( $name, $type_uri, $thumbnail_id, 'publish' ); |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + return $input; |
|
| 366 | + } |
|
| 367 | 367 | |
| 368 | 368 | } |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | * @param \Wordlift_Admin_Publisher_Element $publisher_element |
| 94 | 94 | * @param \Wordlift_Admin_Radio_Input_Element $radio_input_element |
| 95 | 95 | */ |
| 96 | - function __construct( $configuration_service, $entity_service, $input_element, $language_select_element, $publisher_element, $radio_input_element ) { |
|
| 96 | + function __construct($configuration_service, $entity_service, $input_element, $language_select_element, $publisher_element, $radio_input_element) { |
|
| 97 | 97 | |
| 98 | 98 | $this->configuration_service = $configuration_service; |
| 99 | 99 | $this->entity_service = $entity_service; |
@@ -176,8 +176,8 @@ discard block |
||
| 176 | 176 | |
| 177 | 177 | // JavaScript required for the settings page. |
| 178 | 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/1/settings.js', array( 'wp-util' ) ); |
|
| 180 | - wp_enqueue_style( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/settings.css' ); |
|
| 179 | + wp_enqueue_script('wordlift-admin-settings-page', plugin_dir_url(dirname(__FILE__)).'admin/js/1/settings.js', array('wp-util')); |
|
| 180 | + wp_enqueue_style('wordlift-admin-settings-page', plugin_dir_url(dirname(__FILE__)).'admin/js/1/settings.css'); |
|
| 181 | 181 | |
| 182 | 182 | } |
| 183 | 183 | |
@@ -195,22 +195,22 @@ discard block |
||
| 195 | 195 | register_setting( |
| 196 | 196 | 'wl_general_settings', |
| 197 | 197 | 'wl_general_settings', |
| 198 | - array( $this, 'sanitize_callback', ) |
|
| 198 | + array($this, 'sanitize_callback',) |
|
| 199 | 199 | ); |
| 200 | 200 | |
| 201 | 201 | // Add the general settings section. |
| 202 | 202 | add_settings_section( |
| 203 | 203 | 'wl_general_settings_section', // ID used to identify this section and with which to register options. |
| 204 | - '', // Section header. |
|
| 205 | - '', // Callback used to render the description of the section. |
|
| 204 | + '', // Section header. |
|
| 205 | + '', // Callback used to render the description of the section. |
|
| 206 | 206 | 'wl_general_settings' // Page on which to add this section of options. |
| 207 | 207 | ); |
| 208 | 208 | |
| 209 | 209 | $key_args = array( |
| 210 | 210 | 'id' => 'wl-key', |
| 211 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::KEY . ']', |
|
| 211 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::KEY.']', |
|
| 212 | 212 | 'value' => $this->configuration_service->get_key(), |
| 213 | - 'description' => __( 'Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift' ), |
|
| 213 | + 'description' => __('Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift'), |
|
| 214 | 214 | ); |
| 215 | 215 | |
| 216 | 216 | // Before we were used to validate the key beforehand, but this means |
@@ -223,12 +223,12 @@ discard block |
||
| 223 | 223 | |
| 224 | 224 | // Add the `key` field. |
| 225 | 225 | add_settings_field( |
| 226 | - 'wl-key', // Element id used to identify the field throughout the theme. |
|
| 227 | - _x( 'WordLift Key', 'wordlift' ), // The label to the left of the option interface element. |
|
| 226 | + 'wl-key', // Element id used to identify the field throughout the theme. |
|
| 227 | + _x('WordLift Key', 'wordlift'), // The label to the left of the option interface element. |
|
| 228 | 228 | // The name of the function responsible for rendering the option interface. |
| 229 | - array( $this->input_element, 'render', ), |
|
| 230 | - 'wl_general_settings', // The page on which this option will be displayed. |
|
| 231 | - 'wl_general_settings_section', // The name of the section to which this field belongs. |
|
| 229 | + array($this->input_element, 'render',), |
|
| 230 | + 'wl_general_settings', // The page on which this option will be displayed. |
|
| 231 | + 'wl_general_settings_section', // The name of the section to which this field belongs. |
|
| 232 | 232 | $key_args // The array of arguments to pass to the callback. In this case, just a description. |
| 233 | 233 | ); |
| 234 | 234 | |
@@ -236,9 +236,9 @@ discard block |
||
| 236 | 236 | $entity_base_path_args = array( |
| 237 | 237 | // The array of arguments to pass to the callback. In this case, just a description. |
| 238 | 238 | 'id' => 'wl-entity-base-path', |
| 239 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY . ']', |
|
| 239 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY.']', |
|
| 240 | 240 | 'value' => $this->configuration_service->get_entity_base_path(), |
| 241 | - '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' ), |
|
| 241 | + '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'), |
|
| 242 | 242 | ); |
| 243 | 243 | |
| 244 | 244 | // The following call is very heavy on large web sites and is always run |
@@ -247,64 +247,64 @@ discard block |
||
| 247 | 247 | // |
| 248 | 248 | // It is now replaced by a filter to add the `readonly` flag to the |
| 249 | 249 | // input element when this is actually rendered. |
| 250 | - add_filter( 'wl_admin_input_element_params', array( |
|
| 250 | + add_filter('wl_admin_input_element_params', array( |
|
| 251 | 251 | $this, |
| 252 | 252 | 'entity_path_input_element_params', |
| 253 | - ) ); |
|
| 253 | + )); |
|
| 254 | 254 | |
| 255 | 255 | |
| 256 | 256 | // Add the `wl_entity_base_path` field. |
| 257 | 257 | add_settings_field( |
| 258 | - 'wl-entity-base-path', // ID used to identify the field throughout the theme |
|
| 259 | - _x( 'Entity Base Path', 'wordlift' ), // The label to the left of the option interface element |
|
| 258 | + 'wl-entity-base-path', // ID used to identify the field throughout the theme |
|
| 259 | + _x('Entity Base Path', 'wordlift'), // The label to the left of the option interface element |
|
| 260 | 260 | // The name of the function responsible for rendering the option interface |
| 261 | - array( $this->input_element, 'render', ), |
|
| 262 | - 'wl_general_settings', // The page on which this option will be displayed |
|
| 263 | - 'wl_general_settings_section', // The name of the section to which this field belongs |
|
| 261 | + array($this->input_element, 'render',), |
|
| 262 | + 'wl_general_settings', // The page on which this option will be displayed |
|
| 263 | + 'wl_general_settings_section', // The name of the section to which this field belongs |
|
| 264 | 264 | $entity_base_path_args |
| 265 | 265 | ); |
| 266 | 266 | |
| 267 | 267 | // Add the `language_name` field. |
| 268 | 268 | add_settings_field( |
| 269 | 269 | 'wl-site-language', |
| 270 | - _x( 'Site Language', 'wordlift' ), |
|
| 271 | - array( $this->language_select_element, 'render' ), |
|
| 270 | + _x('Site Language', 'wordlift'), |
|
| 271 | + array($this->language_select_element, 'render'), |
|
| 272 | 272 | 'wl_general_settings', |
| 273 | 273 | 'wl_general_settings_section', |
| 274 | 274 | array( |
| 275 | 275 | // The array of arguments to pass to the callback. In this case, just a description. |
| 276 | 276 | 'id' => 'wl-site-language', |
| 277 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LANGUAGE . ']', |
|
| 277 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::LANGUAGE.']', |
|
| 278 | 278 | 'value' => $this->configuration_service->get_language_code(), |
| 279 | - 'description' => __( 'Each WordLift Key can be used only in one language. Pick yours.', 'wordlift' ), |
|
| 279 | + 'description' => __('Each WordLift Key can be used only in one language. Pick yours.', 'wordlift'), |
|
| 280 | 280 | ) |
| 281 | 281 | ); |
| 282 | 282 | |
| 283 | 283 | // Add the `publisher` field. |
| 284 | 284 | add_settings_field( |
| 285 | 285 | 'wl-publisher-id', |
| 286 | - _x( 'Publisher', 'wordlift' ), |
|
| 287 | - array( $this->publisher_element, 'render' ), |
|
| 286 | + _x('Publisher', 'wordlift'), |
|
| 287 | + array($this->publisher_element, 'render'), |
|
| 288 | 288 | 'wl_general_settings', |
| 289 | 289 | 'wl_general_settings_section', |
| 290 | 290 | array( |
| 291 | 291 | 'id' => 'wl-publisher-id', |
| 292 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::PUBLISHER_ID . ']', |
|
| 292 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::PUBLISHER_ID.']', |
|
| 293 | 293 | ) |
| 294 | 294 | ); |
| 295 | 295 | |
| 296 | 296 | // Add the `link by default` field. |
| 297 | 297 | add_settings_field( |
| 298 | 298 | 'wl-link-by-default', |
| 299 | - _x( 'Link by Default', 'wordlift' ), |
|
| 300 | - array( $this->radio_input_element, 'render' ), |
|
| 299 | + _x('Link by Default', 'wordlift'), |
|
| 300 | + array($this->radio_input_element, 'render'), |
|
| 301 | 301 | 'wl_general_settings', |
| 302 | 302 | 'wl_general_settings_section', |
| 303 | 303 | array( |
| 304 | 304 | 'id' => 'wl-link-by-default', |
| 305 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LINK_BY_DEFAULT . ']', |
|
| 305 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::LINK_BY_DEFAULT.']', |
|
| 306 | 306 | 'value' => $this->configuration_service->is_link_by_default() ? 'yes' : 'no', |
| 307 | - 'description' => _x( 'Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift' ), |
|
| 307 | + 'description' => _x('Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift'), |
|
| 308 | 308 | ) |
| 309 | 309 | ); |
| 310 | 310 | |
@@ -320,10 +320,10 @@ discard block |
||
| 320 | 320 | * |
| 321 | 321 | * @return array The updated array. |
| 322 | 322 | */ |
| 323 | - public function entity_path_input_element_params( $args ) { |
|
| 323 | + public function entity_path_input_element_params($args) { |
|
| 324 | 324 | |
| 325 | 325 | // Bail out if it's not the `wl-entity-base-path`). |
| 326 | - if ( 'wl-entity-base-path' !== $args['id'] ) { |
|
| 326 | + if ('wl-entity-base-path' !== $args['id']) { |
|
| 327 | 327 | return $args; |
| 328 | 328 | } |
| 329 | 329 | |
@@ -346,20 +346,20 @@ discard block |
||
| 346 | 346 | * |
| 347 | 347 | * @return array The sanitized input array. |
| 348 | 348 | */ |
| 349 | - function sanitize_callback( $input ) { |
|
| 349 | + function sanitize_callback($input) { |
|
| 350 | 350 | |
| 351 | 351 | // Check whether a publisher name has been set. |
| 352 | - if ( isset( $_POST['wl_publisher'] ) && ! empty( $_POST['wl_publisher']['name'] ) ) { |
|
| 352 | + if (isset($_POST['wl_publisher']) && ! empty($_POST['wl_publisher']['name'])) { |
|
| 353 | 353 | $name = $_POST['wl_publisher']['name']; |
| 354 | 354 | $type = $_POST['wl_publisher']['type']; |
| 355 | 355 | $thumbnail_id = $_POST['wl_publisher']['thumbnail_id'] ?: null; |
| 356 | 356 | |
| 357 | 357 | // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
| 358 | - $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person' ); |
|
| 358 | + $type_uri = sprintf('http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person'); |
|
| 359 | 359 | |
| 360 | 360 | // Create an entity for the publisher and assign it to the input |
| 361 | 361 | // parameter which WordPress automatically saves into the settings. |
| 362 | - $input['publisher_id'] = $this->entity_service->create( $name, $type_uri, $thumbnail_id, 'publish' ); |
|
| 362 | + $input['publisher_id'] = $this->entity_service->create($name, $type_uri, $thumbnail_id, 'publish'); |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | return $input; |
@@ -18,53 +18,53 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | class Wordlift_Admin_Input_Element implements Wordlift_Admin_Element { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Output the HTML for an input box type settings_page |
|
| 23 | - * |
|
| 24 | - * @param array $args An array with the following keys: |
|
| 25 | - * Parameters controlling the result. |
|
| 26 | - * |
|
| 27 | - * @type string name The name attribute of the input element. Mandatory. |
|
| 28 | - * |
|
| 29 | - * @type string id The id attribute of the input element. Optional. |
|
| 30 | - * @type string id The id attribute of the input element. |
|
| 31 | - * Optional, randomly generated one is used if not supplied. |
|
| 32 | - * @type string value The value of the input element. |
|
| 33 | - * Optional, defaults to empty string. |
|
| 34 | - * @type bool readonly Indicates whether the input is read only. |
|
| 35 | - * Optional, defaults to read-write |
|
| 36 | - * @type string css_class The class attribute for the input element. |
|
| 37 | - * If empty string no class attribute will be added. |
|
| 38 | - * Optional, defaults to empty string. |
|
| 39 | - * @type string description The descriptio text to be displayed below the element. |
|
| 40 | - * Can include some HTML element. |
|
| 41 | - * If empty string no description will be displayed. |
|
| 42 | - * Optional, defaults to empty string. |
|
| 43 | - * |
|
| 44 | - * @return $this|Wordlift_Admin_Element |
|
| 45 | - */ |
|
| 46 | - public function render( $args ) { |
|
| 21 | + /** |
|
| 22 | + * Output the HTML for an input box type settings_page |
|
| 23 | + * |
|
| 24 | + * @param array $args An array with the following keys: |
|
| 25 | + * Parameters controlling the result. |
|
| 26 | + * |
|
| 27 | + * @type string name The name attribute of the input element. Mandatory. |
|
| 28 | + * |
|
| 29 | + * @type string id The id attribute of the input element. Optional. |
|
| 30 | + * @type string id The id attribute of the input element. |
|
| 31 | + * Optional, randomly generated one is used if not supplied. |
|
| 32 | + * @type string value The value of the input element. |
|
| 33 | + * Optional, defaults to empty string. |
|
| 34 | + * @type bool readonly Indicates whether the input is read only. |
|
| 35 | + * Optional, defaults to read-write |
|
| 36 | + * @type string css_class The class attribute for the input element. |
|
| 37 | + * If empty string no class attribute will be added. |
|
| 38 | + * Optional, defaults to empty string. |
|
| 39 | + * @type string description The descriptio text to be displayed below the element. |
|
| 40 | + * Can include some HTML element. |
|
| 41 | + * If empty string no description will be displayed. |
|
| 42 | + * Optional, defaults to empty string. |
|
| 43 | + * |
|
| 44 | + * @return $this|Wordlift_Admin_Element |
|
| 45 | + */ |
|
| 46 | + public function render( $args ) { |
|
| 47 | 47 | |
| 48 | - /* |
|
| 48 | + /* |
|
| 49 | 49 | * Parse the arguments and merge with default values. |
| 50 | 50 | * Name intentionally do not have a default as it has to be in SyncEvent |
| 51 | 51 | * with form handling code |
| 52 | 52 | */ |
| 53 | - $pre_params = wp_parse_args( $args, array( |
|
| 54 | - 'id' => uniqid( 'wl-input-' ), |
|
| 55 | - 'value' => '', |
|
| 56 | - 'readonly' => false, |
|
| 57 | - 'css_class' => '', |
|
| 58 | - 'description' => '', |
|
| 59 | - ) ); |
|
| 60 | - $params = apply_filters( 'wl_admin_input_element_params', $pre_params ); |
|
| 53 | + $pre_params = wp_parse_args( $args, array( |
|
| 54 | + 'id' => uniqid( 'wl-input-' ), |
|
| 55 | + 'value' => '', |
|
| 56 | + 'readonly' => false, |
|
| 57 | + 'css_class' => '', |
|
| 58 | + 'description' => '', |
|
| 59 | + ) ); |
|
| 60 | + $params = apply_filters( 'wl_admin_input_element_params', $pre_params ); |
|
| 61 | 61 | |
| 62 | - // Set the readonly and class attributes and the description. |
|
| 63 | - $readonly = $params['readonly'] ? ' readonly="readonly"' : ''; |
|
| 64 | - $css_class = ! empty( $params['css_class'] ) ? ' class="' . esc_attr( $params['css_class'] ) . '"' : ''; |
|
| 65 | - $description = ! empty( $params['description'] ) ? '<p>' . wp_kses( $params['description'], array( 'a' => array( 'href' => array() ) ) ) . '</p>' : ''; |
|
| 62 | + // Set the readonly and class attributes and the description. |
|
| 63 | + $readonly = $params['readonly'] ? ' readonly="readonly"' : ''; |
|
| 64 | + $css_class = ! empty( $params['css_class'] ) ? ' class="' . esc_attr( $params['css_class'] ) . '"' : ''; |
|
| 65 | + $description = ! empty( $params['description'] ) ? '<p>' . wp_kses( $params['description'], array( 'a' => array( 'href' => array() ) ) ) . '</p>' : ''; |
|
| 66 | 66 | |
| 67 | - ?> |
|
| 67 | + ?> |
|
| 68 | 68 | |
| 69 | 69 | <input type="text" |
| 70 | 70 | id="<?php echo esc_attr( $params['id'] ); ?>" |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | |
| 78 | 78 | <?php |
| 79 | 79 | |
| 80 | - return $this; |
|
| 81 | - } |
|
| 80 | + return $this; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | 83 | } |
@@ -43,33 +43,33 @@ |
||
| 43 | 43 | * |
| 44 | 44 | * @return $this|Wordlift_Admin_Element |
| 45 | 45 | */ |
| 46 | - public function render( $args ) { |
|
| 46 | + public function render($args) { |
|
| 47 | 47 | |
| 48 | 48 | /* |
| 49 | 49 | * Parse the arguments and merge with default values. |
| 50 | 50 | * Name intentionally do not have a default as it has to be in SyncEvent |
| 51 | 51 | * with form handling code |
| 52 | 52 | */ |
| 53 | - $pre_params = wp_parse_args( $args, array( |
|
| 54 | - 'id' => uniqid( 'wl-input-' ), |
|
| 53 | + $pre_params = wp_parse_args($args, array( |
|
| 54 | + 'id' => uniqid('wl-input-'), |
|
| 55 | 55 | 'value' => '', |
| 56 | 56 | 'readonly' => false, |
| 57 | 57 | 'css_class' => '', |
| 58 | 58 | 'description' => '', |
| 59 | - ) ); |
|
| 60 | - $params = apply_filters( 'wl_admin_input_element_params', $pre_params ); |
|
| 59 | + )); |
|
| 60 | + $params = apply_filters('wl_admin_input_element_params', $pre_params); |
|
| 61 | 61 | |
| 62 | 62 | // Set the readonly and class attributes and the description. |
| 63 | 63 | $readonly = $params['readonly'] ? ' readonly="readonly"' : ''; |
| 64 | - $css_class = ! empty( $params['css_class'] ) ? ' class="' . esc_attr( $params['css_class'] ) . '"' : ''; |
|
| 65 | - $description = ! empty( $params['description'] ) ? '<p>' . wp_kses( $params['description'], array( 'a' => array( 'href' => array() ) ) ) . '</p>' : ''; |
|
| 64 | + $css_class = ! empty($params['css_class']) ? ' class="'.esc_attr($params['css_class']).'"' : ''; |
|
| 65 | + $description = ! empty($params['description']) ? '<p>'.wp_kses($params['description'], array('a' => array('href' => array()))).'</p>' : ''; |
|
| 66 | 66 | |
| 67 | 67 | ?> |
| 68 | 68 | |
| 69 | 69 | <input type="text" |
| 70 | - id="<?php echo esc_attr( $params['id'] ); ?>" |
|
| 71 | - name="<?php echo esc_attr( $params['name'] ); ?>" |
|
| 72 | - value="<?php echo esc_attr( $params['value'] ); ?>" |
|
| 70 | + id="<?php echo esc_attr($params['id']); ?>" |
|
| 71 | + name="<?php echo esc_attr($params['name']); ?>" |
|
| 72 | + value="<?php echo esc_attr($params['value']); ?>" |
|
| 73 | 73 | <?php echo $readonly; ?> |
| 74 | 74 | <?php echo $css_class; ?> |
| 75 | 75 | /> |