@@ -9,29 +9,29 @@ |
||
| 9 | 9 | </p> |
| 10 | 10 | |
| 11 | 11 | <?php |
| 12 | - // Get WP's locale. |
|
| 13 | - $locale = get_locale(); |
|
| 12 | + // Get WP's locale. |
|
| 13 | + $locale = get_locale(); |
|
| 14 | 14 | |
| 15 | - // Get the language locale part. |
|
| 16 | - $parts = explode( '_', $locale ); |
|
| 17 | - $language = isset( $parts[0] ) ? $parts[0] : ''; |
|
| 18 | - $country = isset( $parts[1] ) ? strtolower( $parts[1] ) : ''; |
|
| 19 | - ?> |
|
| 15 | + // Get the language locale part. |
|
| 16 | + $parts = explode( '_', $locale ); |
|
| 17 | + $language = isset( $parts[0] ) ? $parts[0] : ''; |
|
| 18 | + $country = isset( $parts[1] ) ? strtolower( $parts[1] ) : ''; |
|
| 19 | + ?> |
|
| 20 | 20 | |
| 21 | 21 | <br> |
| 22 | 22 | |
| 23 | 23 | <?php |
| 24 | - // Render country select element. |
|
| 25 | - $country_select->render( |
|
| 26 | - array( |
|
| 27 | - 'id' => 'wl-country-code', |
|
| 28 | - 'name' => 'wl-country-code', |
|
| 29 | - 'lang' => $language, |
|
| 30 | - 'value' => $country, |
|
| 31 | - 'notice' => __( 'The selected language is not supported in this country.</br>Please choose another country or language.', 'wordlift' ), |
|
| 32 | - ) |
|
| 33 | - ); |
|
| 34 | - ?> |
|
| 24 | + // Render country select element. |
|
| 25 | + $country_select->render( |
|
| 26 | + array( |
|
| 27 | + 'id' => 'wl-country-code', |
|
| 28 | + 'name' => 'wl-country-code', |
|
| 29 | + 'lang' => $language, |
|
| 30 | + 'value' => $country, |
|
| 31 | + 'notice' => __( 'The selected language is not supported in this country.</br>Please choose another country or language.', 'wordlift' ), |
|
| 32 | + ) |
|
| 33 | + ); |
|
| 34 | + ?> |
|
| 35 | 35 | |
| 36 | 36 | <div class="btn-wrapper"> |
| 37 | 37 | <input |
@@ -1,11 +1,11 @@ discard block |
||
| 1 | 1 | <!-- Pane 5 content --> |
| 2 | 2 | <script type="text/html" id="page-4"> |
| 3 | 3 | <h2 class="page-title"> |
| 4 | - <?php esc_html_e( 'Country', 'wordlift' ); ?> |
|
| 4 | + <?php esc_html_e('Country', 'wordlift'); ?> |
|
| 5 | 5 | </h2> |
| 6 | 6 | |
| 7 | 7 | <p class="page-txt"> |
| 8 | - <?php esc_html_e( 'Each WordLift key can be used only in one language.', 'wordlift' ); ?> |
|
| 8 | + <?php esc_html_e('Each WordLift key can be used only in one language.', 'wordlift'); ?> |
|
| 9 | 9 | </p> |
| 10 | 10 | |
| 11 | 11 | <?php |
@@ -13,9 +13,9 @@ discard block |
||
| 13 | 13 | $locale = get_locale(); |
| 14 | 14 | |
| 15 | 15 | // Get the language locale part. |
| 16 | - $parts = explode( '_', $locale ); |
|
| 17 | - $language = isset( $parts[0] ) ? $parts[0] : ''; |
|
| 18 | - $country = isset( $parts[1] ) ? strtolower( $parts[1] ) : ''; |
|
| 16 | + $parts = explode('_', $locale); |
|
| 17 | + $language = isset($parts[0]) ? $parts[0] : ''; |
|
| 18 | + $country = isset($parts[1]) ? strtolower($parts[1]) : ''; |
|
| 19 | 19 | ?> |
| 20 | 20 | |
| 21 | 21 | <br> |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | 'name' => 'wl-country-code', |
| 29 | 29 | 'lang' => $language, |
| 30 | 30 | 'value' => $country, |
| 31 | - 'notice' => __( 'The selected language is not supported in this country.</br>Please choose another country or language.', 'wordlift' ), |
|
| 31 | + 'notice' => __('The selected language is not supported in this country.</br>Please choose another country or language.', 'wordlift'), |
|
| 32 | 32 | ) |
| 33 | 33 | ); |
| 34 | 34 | ?> |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | type="button" |
| 39 | 39 | data-wl-next="wl-next" |
| 40 | 40 | class="wl-default-action" |
| 41 | - value="<?php esc_attr_e( 'Next', 'wordlift' ); ?>" |
|
| 41 | + value="<?php esc_attr_e('Next', 'wordlift'); ?>" |
|
| 42 | 42 | > |
| 43 | 43 | </div> |
| 44 | 44 | </script> |
@@ -18,436 +18,436 @@ |
||
| 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_Country_Select_Element} element renderer. |
|
| 77 | - * |
|
| 78 | - * @since 3.18.0 |
|
| 79 | - * @access private |
|
| 80 | - * @var \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
| 81 | - */ |
|
| 82 | - private $country_select_element; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
| 86 | - * |
|
| 87 | - * @since 3.11.0 |
|
| 88 | - * @access private |
|
| 89 | - * @var \Wordlift_Admin_Publisher_Element $publisher_element A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
| 90 | - */ |
|
| 91 | - private $publisher_element; |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Create a {@link Wordlift_Admin_Settings_Page} instance. |
|
| 95 | - * |
|
| 96 | - * @param \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance. |
|
| 97 | - * @param \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
| 98 | - * @param \Wordlift_Admin_Input_Element $input_element A {@link Wordlift_Admin_Input_Element} element renderer. |
|
| 99 | - * @param \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
| 100 | - * @param \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
| 101 | - * @param \Wordlift_Admin_Publisher_Element $publisher_element A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
| 102 | - * @param \Wordlift_Admin_Radio_Input_Element $radio_input_element A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
| 103 | - * |
|
| 104 | - * @since 3.11.0 |
|
| 105 | - * |
|
| 106 | - */ |
|
| 107 | - function __construct( $configuration_service, $entity_service, $input_element, $language_select_element, $country_select_element, $publisher_element, $radio_input_element ) { |
|
| 108 | - |
|
| 109 | - $this->configuration_service = $configuration_service; |
|
| 110 | - $this->entity_service = $entity_service; |
|
| 111 | - |
|
| 112 | - // Set a reference to the UI elements. |
|
| 113 | - $this->input_element = $input_element; |
|
| 114 | - $this->radio_input_element = $radio_input_element; |
|
| 115 | - $this->language_select_element = $language_select_element; |
|
| 116 | - $this->country_select_element = $country_select_element; |
|
| 117 | - $this->publisher_element = $publisher_element; |
|
| 118 | - |
|
| 119 | - self::$instance = $this; |
|
| 120 | - |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Get the singleton instance of the Notice service. |
|
| 125 | - * |
|
| 126 | - * @return \Wordlift_Admin_Settings_Page The singleton instance of the settings page service. |
|
| 127 | - * @since 3.14.0 |
|
| 128 | - */ |
|
| 129 | - public static function get_instance() { |
|
| 130 | - |
|
| 131 | - return self::$instance; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * @inheritdoc |
|
| 136 | - */ |
|
| 137 | - function get_parent_slug() { |
|
| 138 | - |
|
| 139 | - return 'wl_admin_menu'; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @inheritdoc |
|
| 144 | - */ |
|
| 145 | - function get_capability() { |
|
| 146 | - |
|
| 147 | - return 'manage_options'; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * @inheritdoc |
|
| 152 | - */ |
|
| 153 | - function get_page_title() { |
|
| 154 | - |
|
| 155 | - return 'WordLift Settings'; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * @inheritdoc |
|
| 160 | - */ |
|
| 161 | - function get_menu_title() { |
|
| 162 | - |
|
| 163 | - return 'Settings'; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * @inheritdoc |
|
| 168 | - */ |
|
| 169 | - function get_menu_slug() { |
|
| 170 | - |
|
| 171 | - return 'wl_configuration_admin_menu'; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * @inheritdoc |
|
| 176 | - */ |
|
| 177 | - function get_partial_name() { |
|
| 178 | - |
|
| 179 | - return 'wordlift-admin-settings-page.php'; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * @inheritdoc |
|
| 184 | - */ |
|
| 185 | - public function enqueue_scripts() { |
|
| 186 | - |
|
| 187 | - // Enqueue the media scripts to be used for the publisher's logo selection. |
|
| 188 | - wp_enqueue_media(); |
|
| 189 | - |
|
| 190 | - // JavaScript required for the settings page. |
|
| 191 | - // @todo: try to move to the `wordlift-admin.bundle.js`. |
|
| 192 | - wp_enqueue_script( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/settings.js', array( 'wp-util' ) ); |
|
| 193 | - wp_enqueue_style( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/settings.css' ); |
|
| 194 | - |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * Configure all the configuration parameters. |
|
| 199 | - * |
|
| 200 | - * Called by the *admin_init* hook. |
|
| 201 | - * |
|
| 202 | - * @since 3.11.0 |
|
| 203 | - */ |
|
| 204 | - function admin_init() { |
|
| 205 | - // Register WordLift's general settings, providing our own sanitize callback |
|
| 206 | - // which will also check whether the user filled the WL Publisher form. |
|
| 207 | - register_setting( |
|
| 208 | - 'wl_general_settings', |
|
| 209 | - 'wl_general_settings', |
|
| 210 | - array( $this, 'sanitize_callback' ) |
|
| 211 | - ); |
|
| 212 | - |
|
| 213 | - // Add the general settings section. |
|
| 214 | - add_settings_section( |
|
| 215 | - 'wl_general_settings_section', // ID used to identify this section and with which to register options. |
|
| 216 | - '', // Section header. |
|
| 217 | - '', // Callback used to render the description of the section. |
|
| 218 | - 'wl_general_settings' // Page on which to add this section of options. |
|
| 219 | - ); |
|
| 220 | - |
|
| 221 | - $key_args = array( |
|
| 222 | - 'id' => 'wl-key', |
|
| 223 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::KEY . ']', |
|
| 224 | - 'value' => $this->configuration_service->get_key(), |
|
| 225 | - 'description' => __( 'Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift' ) |
|
| 226 | - . ' [' . get_option( 'home' ) . ']', |
|
| 227 | - ); |
|
| 228 | - |
|
| 229 | - // Before we were used to validate the key beforehand, but this means |
|
| 230 | - // an http call whenever a page is opened in the admin area. Therefore |
|
| 231 | - // we now leave the input `untouched`, leaving to the client to update |
|
| 232 | - // the `css_class`. |
|
| 233 | - // |
|
| 234 | - // See https://github.com/insideout10/wordlift-plugin/issues/669. |
|
| 235 | - $key_args['css_class'] = 'untouched'; |
|
| 236 | - |
|
| 237 | - // Add the `key` field. |
|
| 238 | - add_settings_field( |
|
| 239 | - 'wl-key', // Element id used to identify the field throughout the theme. |
|
| 240 | - __( 'WordLift Key', 'wordlift' ), // The label to the left of the option interface element. |
|
| 241 | - // The name of the function responsible for rendering the option interface. |
|
| 242 | - array( $this->input_element, 'render' ), |
|
| 243 | - 'wl_general_settings', // The page on which this option will be displayed. |
|
| 244 | - 'wl_general_settings_section', // The name of the section to which this field belongs. |
|
| 245 | - $key_args // The array of arguments to pass to the callback. In this case, just a description. |
|
| 246 | - ); |
|
| 247 | - |
|
| 248 | - // Entity Base Path input. |
|
| 249 | - $entity_base_path_args = array( |
|
| 250 | - // The array of arguments to pass to the callback. In this case, just a description. |
|
| 251 | - 'id' => 'wl-entity-base-path', |
|
| 252 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY . ']', |
|
| 253 | - 'value' => $this->configuration_service->get_entity_base_path(), |
|
| 254 | - /* translators: Placeholders: %s - a link to FAQ's page. */ |
|
| 255 | - 'description' => sprintf( __( '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' ), |
|
| 256 | - ); |
|
| 257 | - |
|
| 258 | - // The following call is very heavy on large web sites and is always run |
|
| 259 | - // also when not needed: |
|
| 260 | - // $entity_base_path_args['readonly'] = 0 < $this->entity_service->count(); |
|
| 261 | - // |
|
| 262 | - // It is now replaced by a filter to add the `readonly` flag to the |
|
| 263 | - // input element when this is actually rendered. |
|
| 264 | - add_filter( 'wl_admin_input_element_params', array( |
|
| 265 | - $this, |
|
| 266 | - 'entity_path_input_element_params', |
|
| 267 | - ) ); |
|
| 268 | - |
|
| 269 | - // Add the `wl_entity_base_path` field. |
|
| 270 | - add_settings_field( |
|
| 271 | - 'wl-entity-base-path', // ID used to identify the field throughout the theme |
|
| 272 | - __( 'Entity Base Path', 'wordlift' ), // The label to the left of the option interface element |
|
| 273 | - // The name of the function responsible for rendering the option interface |
|
| 274 | - array( $this->input_element, 'render', ), |
|
| 275 | - 'wl_general_settings', // The page on which this option will be displayed |
|
| 276 | - 'wl_general_settings_section', // The name of the section to which this field belongs |
|
| 277 | - $entity_base_path_args |
|
| 278 | - ); |
|
| 279 | - |
|
| 280 | - |
|
| 281 | - $language_name = Wordlift_Languages::get_language_name( |
|
| 282 | - $this->configuration_service->get_language_code() |
|
| 283 | - ); |
|
| 284 | - |
|
| 285 | - // Add the `language_name` field. |
|
| 286 | - add_settings_field( |
|
| 287 | - 'wl-site-language', |
|
| 288 | - __( 'Site Language', 'wordlift' ), |
|
| 289 | - function () use ( $language_name ) { |
|
| 290 | - echo sprintf( '<p><label>%s</label></p>', esc_html( $language_name )); |
|
| 291 | - echo sprintf( __( '<br/><p>WordLift uses the site language, You can change the language from <a href="%s">settings.</a></p>', 'wordlift' ), |
|
| 292 | - admin_url('options-general.php#WPLANG') |
|
| 293 | - ); |
|
| 294 | - }, |
|
| 295 | - 'wl_general_settings', |
|
| 296 | - 'wl_general_settings_section' |
|
| 297 | - ); |
|
| 298 | - |
|
| 299 | - // Add the `country_code` field. |
|
| 300 | - add_settings_field( |
|
| 301 | - 'wl-country-code', |
|
| 302 | - _x( 'Country', 'wordlift' ), |
|
| 303 | - array( $this->country_select_element, 'render' ), |
|
| 304 | - 'wl_general_settings', |
|
| 305 | - 'wl_general_settings_section', |
|
| 306 | - array( |
|
| 307 | - 'id' => 'wl-country-code', |
|
| 308 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::COUNTRY_CODE . ']', |
|
| 309 | - 'value' => $this->configuration_service->get_country_code(), |
|
| 310 | - 'description' => __( 'Please select a country.', 'wordlift' ), |
|
| 311 | - 'notice' => __( 'The selected language is not supported in this country.</br>Please choose another country or language.', 'wordlift' ), |
|
| 312 | - ) |
|
| 313 | - ); |
|
| 314 | - |
|
| 315 | - // Add the `publisher` field. |
|
| 316 | - add_settings_field( |
|
| 317 | - 'wl-publisher-id', |
|
| 318 | - __( 'Publisher', 'wordlift' ), |
|
| 319 | - array( $this->publisher_element, 'render' ), |
|
| 320 | - 'wl_general_settings', |
|
| 321 | - 'wl_general_settings_section', |
|
| 322 | - array( |
|
| 323 | - 'id' => 'wl-publisher-id', |
|
| 324 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::PUBLISHER_ID . ']', |
|
| 325 | - ) |
|
| 326 | - ); |
|
| 327 | - |
|
| 328 | - // Add the `link by default` field. |
|
| 329 | - add_settings_field( |
|
| 330 | - 'wl-link-by-default', |
|
| 331 | - __( 'Link by Default', 'wordlift' ), |
|
| 332 | - array( $this->radio_input_element, 'render' ), |
|
| 333 | - 'wl_general_settings', |
|
| 334 | - 'wl_general_settings_section', |
|
| 335 | - array( |
|
| 336 | - 'id' => 'wl-link-by-default', |
|
| 337 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LINK_BY_DEFAULT . ']', |
|
| 338 | - 'value' => $this->configuration_service->is_link_by_default() ? 'yes' : 'no', |
|
| 339 | - 'description' => __( 'Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift' ), |
|
| 340 | - ) |
|
| 341 | - ); |
|
| 342 | - |
|
| 343 | - // Add the `diagnostic data` field. |
|
| 344 | - add_settings_field( |
|
| 345 | - 'wl-send-diagnostic', |
|
| 346 | - __( 'Send Diagnostic Data', 'wordlift' ), |
|
| 347 | - array( $this->radio_input_element, 'render' ), |
|
| 348 | - 'wl_general_settings', |
|
| 349 | - 'wl_general_settings_section', |
|
| 350 | - array( |
|
| 351 | - 'id' => 'wl-send-diagnostic', |
|
| 352 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::SEND_DIAGNOSTIC . ']', |
|
| 353 | - 'value' => 'yes' === $this->configuration_service->get_diagnostic_preferences() ? 'yes' : 'no', |
|
| 354 | - 'description' => __( 'Whether to send diagnostic data or not.', 'wordlift' ), |
|
| 355 | - ) |
|
| 356 | - ); |
|
| 357 | - |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * Filter the {@link Wordlift_Admin_Input_Element} in order to add the |
|
| 362 | - * `readonly` flag to the `wl-entity-base-path` input. |
|
| 363 | - * |
|
| 364 | - * @param array $args An array of {@link Wordlift_Admin_Input_Element} parameters. |
|
| 365 | - * |
|
| 366 | - * @return array The updated array. |
|
| 367 | - * @since 3.17.0 |
|
| 368 | - * |
|
| 369 | - */ |
|
| 370 | - public function entity_path_input_element_params( $args ) { |
|
| 371 | - |
|
| 372 | - // Bail out if it's not the `wl-entity-base-path`). |
|
| 373 | - if ( 'wl-entity-base-path' !== $args['id'] ) { |
|
| 374 | - return $args; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - // Set the readonly flag according to the entities count. |
|
| 378 | - $args['readonly'] = 0 < $this->entity_service->count(); |
|
| 379 | - |
|
| 380 | - // Return the updated args. |
|
| 381 | - return $args; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * Sanitize the configuration settings to be stored. |
|
| 386 | - * |
|
| 387 | - * If a new entity is being created for the publisher, create it and set The |
|
| 388 | - * publisher setting. |
|
| 389 | - * |
|
| 390 | - * @param array $input The configuration settings array. |
|
| 391 | - * |
|
| 392 | - * @return array The sanitized input array. |
|
| 393 | - * @since 3.11.0 |
|
| 394 | - * |
|
| 395 | - */ |
|
| 396 | - function sanitize_callback( $input ) { |
|
| 397 | - |
|
| 398 | - // Validate the selected country. |
|
| 399 | - $this->validate_country(); |
|
| 400 | - |
|
| 401 | - // Check whether a publisher name has been set. |
|
| 402 | - if ( isset( $_POST['wl_publisher'] ) && ! empty( $_POST['wl_publisher']['name'] ) ) { // WPCS: CSRF, input var, sanitization ok. |
|
| 403 | - $name = isset( $_POST['wl_publisher']['name'] ) ? (string) $_POST['wl_publisher']['name'] : ''; |
|
| 404 | - $type = isset( $_POST['wl_publisher']['type'] ) ? (string) $_POST['wl_publisher']['type'] : ''; |
|
| 405 | - $thumbnail_id = isset( $_POST['wl_publisher']['thumbnail_id'] ) ? $_POST['wl_publisher']['thumbnail_id'] : null; // WPCS: CSRF, input var, sanitization ok. |
|
| 406 | - |
|
| 407 | - // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
|
| 408 | - $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person' ); |
|
| 409 | - |
|
| 410 | - // Create an entity for the publisher and assign it to the input |
|
| 411 | - // parameter which WordPress automatically saves into the settings. |
|
| 412 | - $input['publisher_id'] = $this->entity_service->create( $name, $type_uri, $thumbnail_id, 'publish' ); |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - return $input; |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - /** |
|
| 419 | - * Check whether the currently selected country supports the site language. |
|
| 420 | - * |
|
| 421 | - * @since 3.18.0 |
|
| 422 | - */ |
|
| 423 | - private function validate_country() { |
|
| 424 | - |
|
| 425 | - // Bail out if for some reason the country and language are not set. |
|
| 426 | - if ( |
|
| 427 | - empty( $_POST['wl_general_settings']['site_language'] ) && // WPCS: CSRF, input var, sanitization ok. |
|
| 428 | - empty( $_POST['wl_general_settings']['country_code'] ) // WPCS: CSRF, input var, sanitization ok. |
|
| 429 | - ) { |
|
| 430 | - return; |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - // Get the values. |
|
| 434 | - $language = $_POST['wl_general_settings']['site_language']; // WPCS: CSRF, input var, sanitization ok. |
|
| 435 | - $country = $_POST['wl_general_settings']['country_code']; // WPCS: CSRF, input var, sanitization ok. |
|
| 436 | - $codes = Wordlift_Countries::get_codes(); |
|
| 437 | - |
|
| 438 | - // Check whether the chosen country has language limitations |
|
| 439 | - // and whether the chosen language is supported for that country. |
|
| 440 | - if ( |
|
| 441 | - ! empty( $codes[ $country ] ) && |
|
| 442 | - ! in_array( $language, $codes[ $country ] ) |
|
| 443 | - ) { |
|
| 444 | - // Otherwise add an error. |
|
| 445 | - add_settings_error( |
|
| 446 | - 'wl-country-code', |
|
| 447 | - esc_attr( 'settings_updated' ), |
|
| 448 | - _x( 'The selected language is not supported for the currently chosen country. Please choose another country or language.', 'wordlift' ) |
|
| 449 | - ); |
|
| 450 | - } |
|
| 451 | - } |
|
| 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_Country_Select_Element} element renderer. |
|
| 77 | + * |
|
| 78 | + * @since 3.18.0 |
|
| 79 | + * @access private |
|
| 80 | + * @var \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
| 81 | + */ |
|
| 82 | + private $country_select_element; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
| 86 | + * |
|
| 87 | + * @since 3.11.0 |
|
| 88 | + * @access private |
|
| 89 | + * @var \Wordlift_Admin_Publisher_Element $publisher_element A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
| 90 | + */ |
|
| 91 | + private $publisher_element; |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Create a {@link Wordlift_Admin_Settings_Page} instance. |
|
| 95 | + * |
|
| 96 | + * @param \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance. |
|
| 97 | + * @param \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
| 98 | + * @param \Wordlift_Admin_Input_Element $input_element A {@link Wordlift_Admin_Input_Element} element renderer. |
|
| 99 | + * @param \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
| 100 | + * @param \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
| 101 | + * @param \Wordlift_Admin_Publisher_Element $publisher_element A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
| 102 | + * @param \Wordlift_Admin_Radio_Input_Element $radio_input_element A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
| 103 | + * |
|
| 104 | + * @since 3.11.0 |
|
| 105 | + * |
|
| 106 | + */ |
|
| 107 | + function __construct( $configuration_service, $entity_service, $input_element, $language_select_element, $country_select_element, $publisher_element, $radio_input_element ) { |
|
| 108 | + |
|
| 109 | + $this->configuration_service = $configuration_service; |
|
| 110 | + $this->entity_service = $entity_service; |
|
| 111 | + |
|
| 112 | + // Set a reference to the UI elements. |
|
| 113 | + $this->input_element = $input_element; |
|
| 114 | + $this->radio_input_element = $radio_input_element; |
|
| 115 | + $this->language_select_element = $language_select_element; |
|
| 116 | + $this->country_select_element = $country_select_element; |
|
| 117 | + $this->publisher_element = $publisher_element; |
|
| 118 | + |
|
| 119 | + self::$instance = $this; |
|
| 120 | + |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Get the singleton instance of the Notice service. |
|
| 125 | + * |
|
| 126 | + * @return \Wordlift_Admin_Settings_Page The singleton instance of the settings page service. |
|
| 127 | + * @since 3.14.0 |
|
| 128 | + */ |
|
| 129 | + public static function get_instance() { |
|
| 130 | + |
|
| 131 | + return self::$instance; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * @inheritdoc |
|
| 136 | + */ |
|
| 137 | + function get_parent_slug() { |
|
| 138 | + |
|
| 139 | + return 'wl_admin_menu'; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @inheritdoc |
|
| 144 | + */ |
|
| 145 | + function get_capability() { |
|
| 146 | + |
|
| 147 | + return 'manage_options'; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * @inheritdoc |
|
| 152 | + */ |
|
| 153 | + function get_page_title() { |
|
| 154 | + |
|
| 155 | + return 'WordLift Settings'; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * @inheritdoc |
|
| 160 | + */ |
|
| 161 | + function get_menu_title() { |
|
| 162 | + |
|
| 163 | + return 'Settings'; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * @inheritdoc |
|
| 168 | + */ |
|
| 169 | + function get_menu_slug() { |
|
| 170 | + |
|
| 171 | + return 'wl_configuration_admin_menu'; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * @inheritdoc |
|
| 176 | + */ |
|
| 177 | + function get_partial_name() { |
|
| 178 | + |
|
| 179 | + return 'wordlift-admin-settings-page.php'; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * @inheritdoc |
|
| 184 | + */ |
|
| 185 | + public function enqueue_scripts() { |
|
| 186 | + |
|
| 187 | + // Enqueue the media scripts to be used for the publisher's logo selection. |
|
| 188 | + wp_enqueue_media(); |
|
| 189 | + |
|
| 190 | + // JavaScript required for the settings page. |
|
| 191 | + // @todo: try to move to the `wordlift-admin.bundle.js`. |
|
| 192 | + wp_enqueue_script( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/settings.js', array( 'wp-util' ) ); |
|
| 193 | + wp_enqueue_style( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/settings.css' ); |
|
| 194 | + |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * Configure all the configuration parameters. |
|
| 199 | + * |
|
| 200 | + * Called by the *admin_init* hook. |
|
| 201 | + * |
|
| 202 | + * @since 3.11.0 |
|
| 203 | + */ |
|
| 204 | + function admin_init() { |
|
| 205 | + // Register WordLift's general settings, providing our own sanitize callback |
|
| 206 | + // which will also check whether the user filled the WL Publisher form. |
|
| 207 | + register_setting( |
|
| 208 | + 'wl_general_settings', |
|
| 209 | + 'wl_general_settings', |
|
| 210 | + array( $this, 'sanitize_callback' ) |
|
| 211 | + ); |
|
| 212 | + |
|
| 213 | + // Add the general settings section. |
|
| 214 | + add_settings_section( |
|
| 215 | + 'wl_general_settings_section', // ID used to identify this section and with which to register options. |
|
| 216 | + '', // Section header. |
|
| 217 | + '', // Callback used to render the description of the section. |
|
| 218 | + 'wl_general_settings' // Page on which to add this section of options. |
|
| 219 | + ); |
|
| 220 | + |
|
| 221 | + $key_args = array( |
|
| 222 | + 'id' => 'wl-key', |
|
| 223 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::KEY . ']', |
|
| 224 | + 'value' => $this->configuration_service->get_key(), |
|
| 225 | + 'description' => __( 'Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift' ) |
|
| 226 | + . ' [' . get_option( 'home' ) . ']', |
|
| 227 | + ); |
|
| 228 | + |
|
| 229 | + // Before we were used to validate the key beforehand, but this means |
|
| 230 | + // an http call whenever a page is opened in the admin area. Therefore |
|
| 231 | + // we now leave the input `untouched`, leaving to the client to update |
|
| 232 | + // the `css_class`. |
|
| 233 | + // |
|
| 234 | + // See https://github.com/insideout10/wordlift-plugin/issues/669. |
|
| 235 | + $key_args['css_class'] = 'untouched'; |
|
| 236 | + |
|
| 237 | + // Add the `key` field. |
|
| 238 | + add_settings_field( |
|
| 239 | + 'wl-key', // Element id used to identify the field throughout the theme. |
|
| 240 | + __( 'WordLift Key', 'wordlift' ), // The label to the left of the option interface element. |
|
| 241 | + // The name of the function responsible for rendering the option interface. |
|
| 242 | + array( $this->input_element, 'render' ), |
|
| 243 | + 'wl_general_settings', // The page on which this option will be displayed. |
|
| 244 | + 'wl_general_settings_section', // The name of the section to which this field belongs. |
|
| 245 | + $key_args // The array of arguments to pass to the callback. In this case, just a description. |
|
| 246 | + ); |
|
| 247 | + |
|
| 248 | + // Entity Base Path input. |
|
| 249 | + $entity_base_path_args = array( |
|
| 250 | + // The array of arguments to pass to the callback. In this case, just a description. |
|
| 251 | + 'id' => 'wl-entity-base-path', |
|
| 252 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY . ']', |
|
| 253 | + 'value' => $this->configuration_service->get_entity_base_path(), |
|
| 254 | + /* translators: Placeholders: %s - a link to FAQ's page. */ |
|
| 255 | + 'description' => sprintf( __( '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' ), |
|
| 256 | + ); |
|
| 257 | + |
|
| 258 | + // The following call is very heavy on large web sites and is always run |
|
| 259 | + // also when not needed: |
|
| 260 | + // $entity_base_path_args['readonly'] = 0 < $this->entity_service->count(); |
|
| 261 | + // |
|
| 262 | + // It is now replaced by a filter to add the `readonly` flag to the |
|
| 263 | + // input element when this is actually rendered. |
|
| 264 | + add_filter( 'wl_admin_input_element_params', array( |
|
| 265 | + $this, |
|
| 266 | + 'entity_path_input_element_params', |
|
| 267 | + ) ); |
|
| 268 | + |
|
| 269 | + // Add the `wl_entity_base_path` field. |
|
| 270 | + add_settings_field( |
|
| 271 | + 'wl-entity-base-path', // ID used to identify the field throughout the theme |
|
| 272 | + __( 'Entity Base Path', 'wordlift' ), // The label to the left of the option interface element |
|
| 273 | + // The name of the function responsible for rendering the option interface |
|
| 274 | + array( $this->input_element, 'render', ), |
|
| 275 | + 'wl_general_settings', // The page on which this option will be displayed |
|
| 276 | + 'wl_general_settings_section', // The name of the section to which this field belongs |
|
| 277 | + $entity_base_path_args |
|
| 278 | + ); |
|
| 279 | + |
|
| 280 | + |
|
| 281 | + $language_name = Wordlift_Languages::get_language_name( |
|
| 282 | + $this->configuration_service->get_language_code() |
|
| 283 | + ); |
|
| 284 | + |
|
| 285 | + // Add the `language_name` field. |
|
| 286 | + add_settings_field( |
|
| 287 | + 'wl-site-language', |
|
| 288 | + __( 'Site Language', 'wordlift' ), |
|
| 289 | + function () use ( $language_name ) { |
|
| 290 | + echo sprintf( '<p><label>%s</label></p>', esc_html( $language_name )); |
|
| 291 | + echo sprintf( __( '<br/><p>WordLift uses the site language, You can change the language from <a href="%s">settings.</a></p>', 'wordlift' ), |
|
| 292 | + admin_url('options-general.php#WPLANG') |
|
| 293 | + ); |
|
| 294 | + }, |
|
| 295 | + 'wl_general_settings', |
|
| 296 | + 'wl_general_settings_section' |
|
| 297 | + ); |
|
| 298 | + |
|
| 299 | + // Add the `country_code` field. |
|
| 300 | + add_settings_field( |
|
| 301 | + 'wl-country-code', |
|
| 302 | + _x( 'Country', 'wordlift' ), |
|
| 303 | + array( $this->country_select_element, 'render' ), |
|
| 304 | + 'wl_general_settings', |
|
| 305 | + 'wl_general_settings_section', |
|
| 306 | + array( |
|
| 307 | + 'id' => 'wl-country-code', |
|
| 308 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::COUNTRY_CODE . ']', |
|
| 309 | + 'value' => $this->configuration_service->get_country_code(), |
|
| 310 | + 'description' => __( 'Please select a country.', 'wordlift' ), |
|
| 311 | + 'notice' => __( 'The selected language is not supported in this country.</br>Please choose another country or language.', 'wordlift' ), |
|
| 312 | + ) |
|
| 313 | + ); |
|
| 314 | + |
|
| 315 | + // Add the `publisher` field. |
|
| 316 | + add_settings_field( |
|
| 317 | + 'wl-publisher-id', |
|
| 318 | + __( 'Publisher', 'wordlift' ), |
|
| 319 | + array( $this->publisher_element, 'render' ), |
|
| 320 | + 'wl_general_settings', |
|
| 321 | + 'wl_general_settings_section', |
|
| 322 | + array( |
|
| 323 | + 'id' => 'wl-publisher-id', |
|
| 324 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::PUBLISHER_ID . ']', |
|
| 325 | + ) |
|
| 326 | + ); |
|
| 327 | + |
|
| 328 | + // Add the `link by default` field. |
|
| 329 | + add_settings_field( |
|
| 330 | + 'wl-link-by-default', |
|
| 331 | + __( 'Link by Default', 'wordlift' ), |
|
| 332 | + array( $this->radio_input_element, 'render' ), |
|
| 333 | + 'wl_general_settings', |
|
| 334 | + 'wl_general_settings_section', |
|
| 335 | + array( |
|
| 336 | + 'id' => 'wl-link-by-default', |
|
| 337 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LINK_BY_DEFAULT . ']', |
|
| 338 | + 'value' => $this->configuration_service->is_link_by_default() ? 'yes' : 'no', |
|
| 339 | + 'description' => __( 'Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift' ), |
|
| 340 | + ) |
|
| 341 | + ); |
|
| 342 | + |
|
| 343 | + // Add the `diagnostic data` field. |
|
| 344 | + add_settings_field( |
|
| 345 | + 'wl-send-diagnostic', |
|
| 346 | + __( 'Send Diagnostic Data', 'wordlift' ), |
|
| 347 | + array( $this->radio_input_element, 'render' ), |
|
| 348 | + 'wl_general_settings', |
|
| 349 | + 'wl_general_settings_section', |
|
| 350 | + array( |
|
| 351 | + 'id' => 'wl-send-diagnostic', |
|
| 352 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::SEND_DIAGNOSTIC . ']', |
|
| 353 | + 'value' => 'yes' === $this->configuration_service->get_diagnostic_preferences() ? 'yes' : 'no', |
|
| 354 | + 'description' => __( 'Whether to send diagnostic data or not.', 'wordlift' ), |
|
| 355 | + ) |
|
| 356 | + ); |
|
| 357 | + |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * Filter the {@link Wordlift_Admin_Input_Element} in order to add the |
|
| 362 | + * `readonly` flag to the `wl-entity-base-path` input. |
|
| 363 | + * |
|
| 364 | + * @param array $args An array of {@link Wordlift_Admin_Input_Element} parameters. |
|
| 365 | + * |
|
| 366 | + * @return array The updated array. |
|
| 367 | + * @since 3.17.0 |
|
| 368 | + * |
|
| 369 | + */ |
|
| 370 | + public function entity_path_input_element_params( $args ) { |
|
| 371 | + |
|
| 372 | + // Bail out if it's not the `wl-entity-base-path`). |
|
| 373 | + if ( 'wl-entity-base-path' !== $args['id'] ) { |
|
| 374 | + return $args; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + // Set the readonly flag according to the entities count. |
|
| 378 | + $args['readonly'] = 0 < $this->entity_service->count(); |
|
| 379 | + |
|
| 380 | + // Return the updated args. |
|
| 381 | + return $args; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * Sanitize the configuration settings to be stored. |
|
| 386 | + * |
|
| 387 | + * If a new entity is being created for the publisher, create it and set The |
|
| 388 | + * publisher setting. |
|
| 389 | + * |
|
| 390 | + * @param array $input The configuration settings array. |
|
| 391 | + * |
|
| 392 | + * @return array The sanitized input array. |
|
| 393 | + * @since 3.11.0 |
|
| 394 | + * |
|
| 395 | + */ |
|
| 396 | + function sanitize_callback( $input ) { |
|
| 397 | + |
|
| 398 | + // Validate the selected country. |
|
| 399 | + $this->validate_country(); |
|
| 400 | + |
|
| 401 | + // Check whether a publisher name has been set. |
|
| 402 | + if ( isset( $_POST['wl_publisher'] ) && ! empty( $_POST['wl_publisher']['name'] ) ) { // WPCS: CSRF, input var, sanitization ok. |
|
| 403 | + $name = isset( $_POST['wl_publisher']['name'] ) ? (string) $_POST['wl_publisher']['name'] : ''; |
|
| 404 | + $type = isset( $_POST['wl_publisher']['type'] ) ? (string) $_POST['wl_publisher']['type'] : ''; |
|
| 405 | + $thumbnail_id = isset( $_POST['wl_publisher']['thumbnail_id'] ) ? $_POST['wl_publisher']['thumbnail_id'] : null; // WPCS: CSRF, input var, sanitization ok. |
|
| 406 | + |
|
| 407 | + // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
|
| 408 | + $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person' ); |
|
| 409 | + |
|
| 410 | + // Create an entity for the publisher and assign it to the input |
|
| 411 | + // parameter which WordPress automatically saves into the settings. |
|
| 412 | + $input['publisher_id'] = $this->entity_service->create( $name, $type_uri, $thumbnail_id, 'publish' ); |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + return $input; |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + /** |
|
| 419 | + * Check whether the currently selected country supports the site language. |
|
| 420 | + * |
|
| 421 | + * @since 3.18.0 |
|
| 422 | + */ |
|
| 423 | + private function validate_country() { |
|
| 424 | + |
|
| 425 | + // Bail out if for some reason the country and language are not set. |
|
| 426 | + if ( |
|
| 427 | + empty( $_POST['wl_general_settings']['site_language'] ) && // WPCS: CSRF, input var, sanitization ok. |
|
| 428 | + empty( $_POST['wl_general_settings']['country_code'] ) // WPCS: CSRF, input var, sanitization ok. |
|
| 429 | + ) { |
|
| 430 | + return; |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + // Get the values. |
|
| 434 | + $language = $_POST['wl_general_settings']['site_language']; // WPCS: CSRF, input var, sanitization ok. |
|
| 435 | + $country = $_POST['wl_general_settings']['country_code']; // WPCS: CSRF, input var, sanitization ok. |
|
| 436 | + $codes = Wordlift_Countries::get_codes(); |
|
| 437 | + |
|
| 438 | + // Check whether the chosen country has language limitations |
|
| 439 | + // and whether the chosen language is supported for that country. |
|
| 440 | + if ( |
|
| 441 | + ! empty( $codes[ $country ] ) && |
|
| 442 | + ! in_array( $language, $codes[ $country ] ) |
|
| 443 | + ) { |
|
| 444 | + // Otherwise add an error. |
|
| 445 | + add_settings_error( |
|
| 446 | + 'wl-country-code', |
|
| 447 | + esc_attr( 'settings_updated' ), |
|
| 448 | + _x( 'The selected language is not supported for the currently chosen country. Please choose another country or language.', 'wordlift' ) |
|
| 449 | + ); |
|
| 450 | + } |
|
| 451 | + } |
|
| 452 | 452 | |
| 453 | 453 | } |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * @since 3.11.0 |
| 105 | 105 | * |
| 106 | 106 | */ |
| 107 | - function __construct( $configuration_service, $entity_service, $input_element, $language_select_element, $country_select_element, $publisher_element, $radio_input_element ) { |
|
| 107 | + function __construct($configuration_service, $entity_service, $input_element, $language_select_element, $country_select_element, $publisher_element, $radio_input_element) { |
|
| 108 | 108 | |
| 109 | 109 | $this->configuration_service = $configuration_service; |
| 110 | 110 | $this->entity_service = $entity_service; |
@@ -189,8 +189,8 @@ discard block |
||
| 189 | 189 | |
| 190 | 190 | // JavaScript required for the settings page. |
| 191 | 191 | // @todo: try to move to the `wordlift-admin.bundle.js`. |
| 192 | - wp_enqueue_script( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/settings.js', array( 'wp-util' ) ); |
|
| 193 | - wp_enqueue_style( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/settings.css' ); |
|
| 192 | + wp_enqueue_script('wordlift-admin-settings-page', plugin_dir_url(dirname(__FILE__)).'admin/js/1/settings.js', array('wp-util')); |
|
| 193 | + wp_enqueue_style('wordlift-admin-settings-page', plugin_dir_url(dirname(__FILE__)).'admin/js/1/settings.css'); |
|
| 194 | 194 | |
| 195 | 195 | } |
| 196 | 196 | |
@@ -207,23 +207,23 @@ discard block |
||
| 207 | 207 | register_setting( |
| 208 | 208 | 'wl_general_settings', |
| 209 | 209 | 'wl_general_settings', |
| 210 | - array( $this, 'sanitize_callback' ) |
|
| 210 | + array($this, 'sanitize_callback') |
|
| 211 | 211 | ); |
| 212 | 212 | |
| 213 | 213 | // Add the general settings section. |
| 214 | 214 | add_settings_section( |
| 215 | 215 | 'wl_general_settings_section', // ID used to identify this section and with which to register options. |
| 216 | - '', // Section header. |
|
| 217 | - '', // Callback used to render the description of the section. |
|
| 216 | + '', // Section header. |
|
| 217 | + '', // Callback used to render the description of the section. |
|
| 218 | 218 | 'wl_general_settings' // Page on which to add this section of options. |
| 219 | 219 | ); |
| 220 | 220 | |
| 221 | 221 | $key_args = array( |
| 222 | 222 | 'id' => 'wl-key', |
| 223 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::KEY . ']', |
|
| 223 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::KEY.']', |
|
| 224 | 224 | 'value' => $this->configuration_service->get_key(), |
| 225 | - 'description' => __( 'Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift' ) |
|
| 226 | - . ' [' . get_option( 'home' ) . ']', |
|
| 225 | + 'description' => __('Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift') |
|
| 226 | + . ' ['.get_option('home').']', |
|
| 227 | 227 | ); |
| 228 | 228 | |
| 229 | 229 | // Before we were used to validate the key beforehand, but this means |
@@ -236,12 +236,12 @@ discard block |
||
| 236 | 236 | |
| 237 | 237 | // Add the `key` field. |
| 238 | 238 | add_settings_field( |
| 239 | - 'wl-key', // Element id used to identify the field throughout the theme. |
|
| 240 | - __( 'WordLift Key', 'wordlift' ), // The label to the left of the option interface element. |
|
| 239 | + 'wl-key', // Element id used to identify the field throughout the theme. |
|
| 240 | + __('WordLift Key', 'wordlift'), // The label to the left of the option interface element. |
|
| 241 | 241 | // The name of the function responsible for rendering the option interface. |
| 242 | - array( $this->input_element, 'render' ), |
|
| 243 | - 'wl_general_settings', // The page on which this option will be displayed. |
|
| 244 | - 'wl_general_settings_section', // The name of the section to which this field belongs. |
|
| 242 | + array($this->input_element, 'render'), |
|
| 243 | + 'wl_general_settings', // The page on which this option will be displayed. |
|
| 244 | + 'wl_general_settings_section', // The name of the section to which this field belongs. |
|
| 245 | 245 | $key_args // The array of arguments to pass to the callback. In this case, just a description. |
| 246 | 246 | ); |
| 247 | 247 | |
@@ -249,10 +249,10 @@ discard block |
||
| 249 | 249 | $entity_base_path_args = array( |
| 250 | 250 | // The array of arguments to pass to the callback. In this case, just a description. |
| 251 | 251 | 'id' => 'wl-entity-base-path', |
| 252 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY . ']', |
|
| 252 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY.']', |
|
| 253 | 253 | 'value' => $this->configuration_service->get_entity_base_path(), |
| 254 | 254 | /* translators: Placeholders: %s - a link to FAQ's page. */ |
| 255 | - 'description' => sprintf( __( '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' ), |
|
| 255 | + 'description' => sprintf(__('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'), |
|
| 256 | 256 | ); |
| 257 | 257 | |
| 258 | 258 | // The following call is very heavy on large web sites and is always run |
@@ -261,19 +261,19 @@ discard block |
||
| 261 | 261 | // |
| 262 | 262 | // It is now replaced by a filter to add the `readonly` flag to the |
| 263 | 263 | // input element when this is actually rendered. |
| 264 | - add_filter( 'wl_admin_input_element_params', array( |
|
| 264 | + add_filter('wl_admin_input_element_params', array( |
|
| 265 | 265 | $this, |
| 266 | 266 | 'entity_path_input_element_params', |
| 267 | - ) ); |
|
| 267 | + )); |
|
| 268 | 268 | |
| 269 | 269 | // Add the `wl_entity_base_path` field. |
| 270 | 270 | add_settings_field( |
| 271 | - 'wl-entity-base-path', // ID used to identify the field throughout the theme |
|
| 272 | - __( 'Entity Base Path', 'wordlift' ), // The label to the left of the option interface element |
|
| 271 | + 'wl-entity-base-path', // ID used to identify the field throughout the theme |
|
| 272 | + __('Entity Base Path', 'wordlift'), // The label to the left of the option interface element |
|
| 273 | 273 | // The name of the function responsible for rendering the option interface |
| 274 | - array( $this->input_element, 'render', ), |
|
| 275 | - 'wl_general_settings', // The page on which this option will be displayed |
|
| 276 | - 'wl_general_settings_section', // The name of the section to which this field belongs |
|
| 274 | + array($this->input_element, 'render',), |
|
| 275 | + 'wl_general_settings', // The page on which this option will be displayed |
|
| 276 | + 'wl_general_settings_section', // The name of the section to which this field belongs |
|
| 277 | 277 | $entity_base_path_args |
| 278 | 278 | ); |
| 279 | 279 | |
@@ -285,10 +285,10 @@ discard block |
||
| 285 | 285 | // Add the `language_name` field. |
| 286 | 286 | add_settings_field( |
| 287 | 287 | 'wl-site-language', |
| 288 | - __( 'Site Language', 'wordlift' ), |
|
| 289 | - function () use ( $language_name ) { |
|
| 290 | - echo sprintf( '<p><label>%s</label></p>', esc_html( $language_name )); |
|
| 291 | - echo sprintf( __( '<br/><p>WordLift uses the site language, You can change the language from <a href="%s">settings.</a></p>', 'wordlift' ), |
|
| 288 | + __('Site Language', 'wordlift'), |
|
| 289 | + function() use ($language_name) { |
|
| 290 | + echo sprintf('<p><label>%s</label></p>', esc_html($language_name)); |
|
| 291 | + echo sprintf(__('<br/><p>WordLift uses the site language, You can change the language from <a href="%s">settings.</a></p>', 'wordlift'), |
|
| 292 | 292 | admin_url('options-general.php#WPLANG') |
| 293 | 293 | ); |
| 294 | 294 | }, |
@@ -299,59 +299,59 @@ discard block |
||
| 299 | 299 | // Add the `country_code` field. |
| 300 | 300 | add_settings_field( |
| 301 | 301 | 'wl-country-code', |
| 302 | - _x( 'Country', 'wordlift' ), |
|
| 303 | - array( $this->country_select_element, 'render' ), |
|
| 302 | + _x('Country', 'wordlift'), |
|
| 303 | + array($this->country_select_element, 'render'), |
|
| 304 | 304 | 'wl_general_settings', |
| 305 | 305 | 'wl_general_settings_section', |
| 306 | 306 | array( |
| 307 | 307 | 'id' => 'wl-country-code', |
| 308 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::COUNTRY_CODE . ']', |
|
| 308 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::COUNTRY_CODE.']', |
|
| 309 | 309 | 'value' => $this->configuration_service->get_country_code(), |
| 310 | - 'description' => __( 'Please select a country.', 'wordlift' ), |
|
| 311 | - 'notice' => __( 'The selected language is not supported in this country.</br>Please choose another country or language.', 'wordlift' ), |
|
| 310 | + 'description' => __('Please select a country.', 'wordlift'), |
|
| 311 | + 'notice' => __('The selected language is not supported in this country.</br>Please choose another country or language.', 'wordlift'), |
|
| 312 | 312 | ) |
| 313 | 313 | ); |
| 314 | 314 | |
| 315 | 315 | // Add the `publisher` field. |
| 316 | 316 | add_settings_field( |
| 317 | 317 | 'wl-publisher-id', |
| 318 | - __( 'Publisher', 'wordlift' ), |
|
| 319 | - array( $this->publisher_element, 'render' ), |
|
| 318 | + __('Publisher', 'wordlift'), |
|
| 319 | + array($this->publisher_element, 'render'), |
|
| 320 | 320 | 'wl_general_settings', |
| 321 | 321 | 'wl_general_settings_section', |
| 322 | 322 | array( |
| 323 | 323 | 'id' => 'wl-publisher-id', |
| 324 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::PUBLISHER_ID . ']', |
|
| 324 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::PUBLISHER_ID.']', |
|
| 325 | 325 | ) |
| 326 | 326 | ); |
| 327 | 327 | |
| 328 | 328 | // Add the `link by default` field. |
| 329 | 329 | add_settings_field( |
| 330 | 330 | 'wl-link-by-default', |
| 331 | - __( 'Link by Default', 'wordlift' ), |
|
| 332 | - array( $this->radio_input_element, 'render' ), |
|
| 331 | + __('Link by Default', 'wordlift'), |
|
| 332 | + array($this->radio_input_element, 'render'), |
|
| 333 | 333 | 'wl_general_settings', |
| 334 | 334 | 'wl_general_settings_section', |
| 335 | 335 | array( |
| 336 | 336 | 'id' => 'wl-link-by-default', |
| 337 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LINK_BY_DEFAULT . ']', |
|
| 337 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::LINK_BY_DEFAULT.']', |
|
| 338 | 338 | 'value' => $this->configuration_service->is_link_by_default() ? 'yes' : 'no', |
| 339 | - 'description' => __( 'Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift' ), |
|
| 339 | + 'description' => __('Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift'), |
|
| 340 | 340 | ) |
| 341 | 341 | ); |
| 342 | 342 | |
| 343 | 343 | // Add the `diagnostic data` field. |
| 344 | 344 | add_settings_field( |
| 345 | 345 | 'wl-send-diagnostic', |
| 346 | - __( 'Send Diagnostic Data', 'wordlift' ), |
|
| 347 | - array( $this->radio_input_element, 'render' ), |
|
| 346 | + __('Send Diagnostic Data', 'wordlift'), |
|
| 347 | + array($this->radio_input_element, 'render'), |
|
| 348 | 348 | 'wl_general_settings', |
| 349 | 349 | 'wl_general_settings_section', |
| 350 | 350 | array( |
| 351 | 351 | 'id' => 'wl-send-diagnostic', |
| 352 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::SEND_DIAGNOSTIC . ']', |
|
| 352 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::SEND_DIAGNOSTIC.']', |
|
| 353 | 353 | 'value' => 'yes' === $this->configuration_service->get_diagnostic_preferences() ? 'yes' : 'no', |
| 354 | - 'description' => __( 'Whether to send diagnostic data or not.', 'wordlift' ), |
|
| 354 | + 'description' => __('Whether to send diagnostic data or not.', 'wordlift'), |
|
| 355 | 355 | ) |
| 356 | 356 | ); |
| 357 | 357 | |
@@ -367,10 +367,10 @@ discard block |
||
| 367 | 367 | * @since 3.17.0 |
| 368 | 368 | * |
| 369 | 369 | */ |
| 370 | - public function entity_path_input_element_params( $args ) { |
|
| 370 | + public function entity_path_input_element_params($args) { |
|
| 371 | 371 | |
| 372 | 372 | // Bail out if it's not the `wl-entity-base-path`). |
| 373 | - if ( 'wl-entity-base-path' !== $args['id'] ) { |
|
| 373 | + if ('wl-entity-base-path' !== $args['id']) { |
|
| 374 | 374 | return $args; |
| 375 | 375 | } |
| 376 | 376 | |
@@ -393,23 +393,23 @@ discard block |
||
| 393 | 393 | * @since 3.11.0 |
| 394 | 394 | * |
| 395 | 395 | */ |
| 396 | - function sanitize_callback( $input ) { |
|
| 396 | + function sanitize_callback($input) { |
|
| 397 | 397 | |
| 398 | 398 | // Validate the selected country. |
| 399 | 399 | $this->validate_country(); |
| 400 | 400 | |
| 401 | 401 | // Check whether a publisher name has been set. |
| 402 | - if ( isset( $_POST['wl_publisher'] ) && ! empty( $_POST['wl_publisher']['name'] ) ) { // WPCS: CSRF, input var, sanitization ok. |
|
| 403 | - $name = isset( $_POST['wl_publisher']['name'] ) ? (string) $_POST['wl_publisher']['name'] : ''; |
|
| 404 | - $type = isset( $_POST['wl_publisher']['type'] ) ? (string) $_POST['wl_publisher']['type'] : ''; |
|
| 405 | - $thumbnail_id = isset( $_POST['wl_publisher']['thumbnail_id'] ) ? $_POST['wl_publisher']['thumbnail_id'] : null; // WPCS: CSRF, input var, sanitization ok. |
|
| 402 | + if (isset($_POST['wl_publisher']) && ! empty($_POST['wl_publisher']['name'])) { // WPCS: CSRF, input var, sanitization ok. |
|
| 403 | + $name = isset($_POST['wl_publisher']['name']) ? (string) $_POST['wl_publisher']['name'] : ''; |
|
| 404 | + $type = isset($_POST['wl_publisher']['type']) ? (string) $_POST['wl_publisher']['type'] : ''; |
|
| 405 | + $thumbnail_id = isset($_POST['wl_publisher']['thumbnail_id']) ? $_POST['wl_publisher']['thumbnail_id'] : null; // WPCS: CSRF, input var, sanitization ok. |
|
| 406 | 406 | |
| 407 | 407 | // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
| 408 | - $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person' ); |
|
| 408 | + $type_uri = sprintf('http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person'); |
|
| 409 | 409 | |
| 410 | 410 | // Create an entity for the publisher and assign it to the input |
| 411 | 411 | // parameter which WordPress automatically saves into the settings. |
| 412 | - $input['publisher_id'] = $this->entity_service->create( $name, $type_uri, $thumbnail_id, 'publish' ); |
|
| 412 | + $input['publisher_id'] = $this->entity_service->create($name, $type_uri, $thumbnail_id, 'publish'); |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | return $input; |
@@ -424,8 +424,8 @@ discard block |
||
| 424 | 424 | |
| 425 | 425 | // Bail out if for some reason the country and language are not set. |
| 426 | 426 | if ( |
| 427 | - empty( $_POST['wl_general_settings']['site_language'] ) && // WPCS: CSRF, input var, sanitization ok. |
|
| 428 | - empty( $_POST['wl_general_settings']['country_code'] ) // WPCS: CSRF, input var, sanitization ok. |
|
| 427 | + empty($_POST['wl_general_settings']['site_language']) && // WPCS: CSRF, input var, sanitization ok. |
|
| 428 | + empty($_POST['wl_general_settings']['country_code']) // WPCS: CSRF, input var, sanitization ok. |
|
| 429 | 429 | ) { |
| 430 | 430 | return; |
| 431 | 431 | } |
@@ -438,14 +438,14 @@ discard block |
||
| 438 | 438 | // Check whether the chosen country has language limitations |
| 439 | 439 | // and whether the chosen language is supported for that country. |
| 440 | 440 | if ( |
| 441 | - ! empty( $codes[ $country ] ) && |
|
| 442 | - ! in_array( $language, $codes[ $country ] ) |
|
| 441 | + ! empty($codes[$country]) && |
|
| 442 | + ! in_array($language, $codes[$country]) |
|
| 443 | 443 | ) { |
| 444 | 444 | // Otherwise add an error. |
| 445 | 445 | add_settings_error( |
| 446 | 446 | 'wl-country-code', |
| 447 | - esc_attr( 'settings_updated' ), |
|
| 448 | - _x( 'The selected language is not supported for the currently chosen country. Please choose another country or language.', 'wordlift' ) |
|
| 447 | + esc_attr('settings_updated'), |
|
| 448 | + _x('The selected language is not supported for the currently chosen country. Please choose another country or language.', 'wordlift') |
|
| 449 | 449 | ); |
| 450 | 450 | } |
| 451 | 451 | } |