| @@ -6,9 +6,9 @@ | ||
| 6 | 6 | * @author ConvertKit |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | - * Registers a screen at Settings > ConvertKit in the WordPress Administration | |
| 10 | + * Registers a screen at Settings > Kit in the WordPress Administration | |
| 11 | 11 | * interface, and handles saving its data. |
| 12 | 12 | * |
| 13 | 13 | * @package ConvertKit |
| 14 | 14 | * @author ConvertKit |
| @@ -55,25 +55,24 @@ | ||
| 55 | 55 | if ( $hook !== 'settings_page_' . self::SETTINGS_PAGE_SLUG ) { |
| 56 | 56 | return; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - // Enqueue Select2 JS. | |
| 60 | - convertkit_select2_enqueue_scripts(); | |
| 59 | + // Get active settings section / tab that has been requested. | |
| 60 | + $section = $this->get_active_section(); | |
| 61 | 61 | |
| 62 | - // Enqueue Preview Output JS. | |
| 63 | - wp_enqueue_script( 'convertkit-admin-preview-output', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/preview-output.js', array( 'jquery' ), CONVERTKIT_PLUGIN_VERSION, true ); | |
| 64 | - | |
| 65 | 62 | /** |
| 66 | - * Enqueue JavaScript for the Settings Screen at Settings > ConvertKit | |
| 63 | + * Enqueue JavaScript for the Settings Screen at Settings > Kit | |
| 67 | 64 | * |
| 68 | 65 | * @since 1.9.6 |
| 66 | + * | |
| 67 | + * @param string $section Settings section / tab (general|tools|restrict-content). | |
| 69 | 68 | */ |
| 70 | - do_action( 'convertkit_admin_settings_enqueue_scripts' ); | |
| 69 | + do_action( 'convertkit_admin_settings_enqueue_scripts', $section ); | |
| 71 | 70 | |
| 72 | 71 | } |
| 73 | 72 | |
| 74 | 73 | /** |
| 75 | - * Enqueue CSS for the Settings Screens at Settings > ConvertKit | |
| 74 | + * Enqueue CSS for the Settings Screens at Settings > Kit | |
| 76 | 75 | * |
| 77 | 76 | * @since 1.9.6 |
| 78 | 77 | * |
| 79 | 78 | * @param string $hook Hook. |
| @@ -84,20 +83,22 @@ | ||
| 84 | 83 | if ( $hook !== 'settings_page_' . self::SETTINGS_PAGE_SLUG ) { |
| 85 | 84 | return; |
| 86 | 85 | } |
| 87 | 86 | |
| 88 | - // Enqueue Select2 CSS. | |
| 89 | - convertkit_select2_enqueue_styles(); | |
| 87 | + // Get active settings section / tab that has been requested. | |
| 88 | + $section = $this->get_active_section(); | |
| 90 | 89 | |
| 91 | - // Enqueue Settings CSS. | |
| 90 | + // Always enqueue Settings CSS, as this is used for the UI across all settings sections. | |
| 92 | 91 | wp_enqueue_style( 'convertkit-admin-settings', CONVERTKIT_PLUGIN_URL . 'resources/backend/css/settings.css', array(), CONVERTKIT_PLUGIN_VERSION ); |
| 93 | 92 | |
| 94 | 93 | /** |
| 95 | - * Enqueue CSS for the Settings Screen at Settings > ConvertKit | |
| 94 | + * Enqueue CSS for the Settings Screen at Settings > Kit | |
| 96 | 95 | * |
| 97 | 96 | * @since 1.9.6 |
| 97 | + * | |
| 98 | + * @param string $section Settings section / tab (general|tools|restrict-content). | |
| 98 | 99 | */ |
| 99 | - do_action( 'convertkit_admin_settings_enqueue_styles' ); | |
| 100 | + do_action( 'convertkit_admin_settings_enqueue_styles', $section ); | |
| 100 | 101 | |
| 101 | 102 | } |
| 102 | 103 | |
| 103 | 104 | /** |
| @@ -107,10 +108,10 @@ | ||
| 107 | 108 | */ |
| 108 | 109 | public function add_settings_page() { |
| 109 | 110 | |
| 110 | 111 | add_options_page( |
| 111 | - __( 'ConvertKit', 'convertkit' ), | |
| 112 | - __( 'ConvertKit', 'convertkit' ), | |
| 112 | + __( 'Kit', 'convertkit' ), | |
| 113 | + __( 'Kit', 'convertkit' ), | |
| 113 | 114 | 'manage_options', |
| 114 | 115 | self::SETTINGS_PAGE_SLUG, |
| 115 | 116 | array( $this, 'display_settings_page' ) |
| 116 | 117 | ); |
| @@ -127,9 +128,21 @@ | ||
| 127 | 128 | $active_section = $this->get_active_section(); |
| 128 | 129 | ?> |
| 129 | 130 | |
| 130 | 131 | <header> |
| 131 | - <h1><?php esc_html_e( 'ConvertKit', 'convertkit' ); ?></h1> | |
| 132 | + <h1><?php esc_html_e( 'Kit', 'convertkit' ); ?></h1> | |
| 133 | + | |
| 134 | + <?php | |
| 135 | + // Output Help link tab, if it exists. | |
| 136 | + $documentation_url = $this->get_active_section_documentation_url( $active_section ); | |
| 137 | + if ( $documentation_url !== false ) { | |
| 138 | + printf( | |
| 139 | + '<a href="%s" class="convertkit-docs" target="_blank">%s</a>', | |
| 140 | + esc_attr( $documentation_url ), | |
| 141 | + esc_html__( 'Help', 'convertkit' ) | |
| 142 | + ); | |
| 143 | + } | |
| 144 | + ?> | |
| 132 | 145 | </header> |
| 133 | 146 | |
| 134 | 147 | <div class="wrap"> |
| 135 | 148 | <?php |
| @@ -135,11 +148,30 @@ | ||
| 135 | 148 | <?php |
| 136 | 149 | if ( count( $this->sections ) > 1 ) { |
| 137 | 150 | $this->display_section_nav( $active_section ); |
| 138 | 151 | } |
| 152 | + | |
| 153 | + /** | |
| 154 | + * Defines the settings form's method. | |
| 155 | + * | |
| 156 | + * @since 3.0.0 | |
| 157 | + * | |
| 158 | + * @param string $form_method The method of the form. | |
| 159 | + * @param string $active_section The active section. | |
| 160 | + */ | |
| 161 | + $form_method = apply_filters( 'convertkit_admin_settings_form_method', 'post', $active_section ); | |
| 162 | + | |
| 163 | + /** | |
| 164 | + * Defines the settings form's action URL. | |
| 165 | + * | |
| 166 | + * @since 3.0.0 | |
| 167 | + * | |
| 168 | + * @param string $form_action_url The URL to submit the form to. | |
| 169 | + * @param string $active_section The active section. | |
| 170 | + */ | |
| 171 | + $form_action_url = apply_filters( 'convertkit_admin_settings_form_action_url', admin_url( 'options.php' ), $active_section ); | |
| 139 | 172 | ?> |
| 140 | - | |
| 141 | - <form method="post" action="options.php" enctype="multipart/form-data"> | |
| 173 | + <form method="<?php echo esc_attr( $form_method ); ?>" action="<?php echo esc_url( $form_action_url ); ?>" enctype="multipart/form-data"> | |
| 142 | 174 | <?php |
| 143 | 175 | // Iterate through sections to find the active section to render. |
| 144 | 176 | if ( isset( $this->sections[ $active_section ] ) ) { |
| 145 | 177 | $this->sections[ $active_section ]->render(); |
| @@ -148,12 +180,12 @@ | ||
| 148 | 180 | </form> |
| 149 | 181 | |
| 150 | 182 | <p class="description"> |
| 151 | 183 | <?php |
| 152 | - // Output Documentation link, if it exists. | |
| 184 | + // Output Help link, if it exists. | |
| 153 | 185 | $documentation_url = $this->get_active_section_documentation_url( $active_section ); |
| 154 | 186 | if ( $documentation_url !== false ) { |
| 155 | - echo sprintf( | |
| 187 | + printf( | |
| 156 | 188 | '%s <a href="%s" target="_blank">%s</a>', |
| 157 | 189 | esc_html__( 'If you need help setting up the plugin please refer to the', 'convertkit' ), |
| 158 | 190 | esc_attr( $documentation_url ), |
| 159 | 191 | esc_html__( 'plugin documentation', 'convertkit' ) |
| @@ -174,10 +206,10 @@ | ||
| 174 | 206 | * @return string Tab Name |
| 175 | 207 | */ |
| 176 | 208 | private function get_active_section() { |
| 177 | 209 | |
| 178 | - if ( isset( $_GET['tab'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification | |
| 179 | - return sanitize_text_field( wp_unslash( $_GET['tab'] ) ); // phpcs:ignore WordPress.Security.NonceVerification | |
| 210 | + if ( filter_has_var( INPUT_GET, 'tab' ) ) { | |
| 211 | + return filter_input( INPUT_GET, 'tab', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); | |
| 180 | 212 | } |
| 181 | 213 | |
| 182 | 214 | // First registered section will be the active section. |
| 183 | 215 | return current( $this->sections )->name; |
| @@ -236,21 +268,14 @@ | ||
| 236 | 268 | ) |
| 237 | 269 | ), |
| 238 | 270 | ( $active_section === $section->name ? 'convertkit-tab-active' : '' ), |
| 239 | 271 | esc_html( $section->tab_text ), |
| 240 | - $section->is_beta ? $this->get_beta_tab() : '' // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 272 | + wp_kses( | |
| 273 | + $section->is_beta ? $this->get_beta_tab() : '', | |
| 274 | + convertkit_kses_allowed_html() | |
| 275 | + ) | |
| 241 | 276 | ); |
| 242 | 277 | } |
| 243 | - | |
| 244 | - // Output Documentation link tab, if it exists. | |
| 245 | - $documentation_url = $this->get_active_section_documentation_url( $active_section ); | |
| 246 | - if ( $documentation_url !== false ) { | |
| 247 | - printf( | |
| 248 | - '<li class="convertkit-docs"><a href="%s" class="convertkit-tab" target="_blank">%s <span class="dashicons dashicons-external"></span></a></li>', | |
| 249 | - esc_attr( $documentation_url ), | |
| 250 | - esc_html__( 'Documentation', 'convertkit' ) | |
| 251 | - ); | |
| 252 | - } | |
| 253 | 278 | ?> |
| 254 | 279 | </ul> |
| 255 | 280 | <?php |
| 256 | 281 | // WordPress' JS will automatically move any .notice elements to be immediately below .wp-header-end |
| @@ -263,10 +288,9 @@ | ||
| 263 | 288 | |
| 264 | 289 | } |
| 265 | 290 | |
| 266 | 291 | /** |
| 267 | - * Returns a 'beta' tab wrapped in a span, using wp_kses to ensure only permitted | |
| 268 | - * HTML elements are included in the output. | |
| 292 | + * Returns a 'beta' tab wrapped in a span. | |
| 269 | 293 | * |
| 270 | 294 | * @since 2.1.0 |
| 271 | 295 | * |
| 272 | 296 | * @return string |
| @@ -272,21 +296,14 @@ | ||
| 272 | 296 | * @return string |
| 273 | 297 | */ |
| 274 | 298 | private function get_beta_tab() { |
| 275 | 299 | |
| 276 | - return wp_kses( | |
| 277 | - '<span class="convertkit-beta-label">' . esc_html__( 'Beta', 'convertkit' ) . '</span>', | |
| 278 | - array( | |
| 279 | - 'span' => array( | |
| 280 | - 'class' => array(), | |
| 281 | - ), | |
| 282 | - ) | |
| 283 | - ); | |
| 300 | + return '<span class="convertkit-beta-label">' . esc_html__( 'Beta', 'convertkit' ) . '</span>'; | |
| 284 | 301 | |
| 285 | 302 | } |
| 286 | 303 | |
| 287 | 304 | /** |
| 288 | - * Registers settings sections at Settings > ConvertKit. | |
| 305 | + * Registers settings sections at Settings > Kit. | |
| 289 | 306 | * |
| 290 | 307 | * Each section has its own tab. |
| 291 | 308 | * |
| 292 | 309 | * @since 1.9.6 |
| @@ -292,16 +309,31 @@ | ||
| 292 | 309 | * @since 1.9.6 |
| 293 | 310 | */ |
| 294 | 311 | public function register_sections() { |
| 295 | 312 | |
| 313 | + // If no Access Token exists, register a settings section that shows a button | |
| 314 | + // to start the OAuth authentication flow. | |
| 315 | + $settings = new ConvertKit_Settings(); | |
| 316 | + if ( ! $settings->has_access_and_refresh_token() ) { | |
| 317 | + // Just register the OAuth screen. | |
| 318 | + $sections = array( | |
| 319 | + 'oauth' => new ConvertKit_Admin_Section_OAuth(), | |
| 320 | + ); | |
| 321 | + | |
| 322 | + // Assign them to this class. | |
| 323 | + $this->sections = $sections; | |
| 324 | + | |
| 325 | + return; | |
| 326 | + } | |
| 327 | + | |
| 296 | 328 | // Register the General and Tools settings sections. |
| 297 | 329 | $sections = array( |
| 298 | - 'general' => new ConvertKit_Settings_General(), | |
| 299 | - 'tools' => new ConvertKit_Settings_Tools(), | |
| 330 | + 'general' => new ConvertKit_Admin_Section_General(), | |
| 331 | + 'tools' => new ConvertKit_Admin_Section_Tools(), | |
| 300 | 332 | ); |
| 301 | 333 | |
| 302 | 334 | /** |
| 303 | - * Registers settings sections at Settings > ConvertKit. | |
| 335 | + * Registers settings sections at Settings > Kit. | |
| 304 | 336 | * |
| 305 | 337 | * @since 1.9.6 |
| 306 | 338 | * |
| 307 | 339 | * @param array $sections Array of settings classes that handle individual tabs e.g. General, Tools etc. |