| @@ -1,22 +1,38 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 3 | +// Exit if accessed directly. | |
| 4 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | + exit; | |
| 6 | +} | |
| 7 | + | |
| 2 | 8 | /** |
| 3 | 9 | * Display the main settings page wrapper. |
| 4 | 10 | * |
| 5 | 11 | * @author David Bisset |
| 6 | 12 | * @package Charitable/Admin View/Settings |
| 7 | - * @copyright Copyright (c) 2022, WP Charitable LLC | |
| 13 | + * @copyright Copyright (c) 2023, WP Charitable LLC | |
| 8 | 14 | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 | 15 | * @since 1.0.0 |
| 10 | - * @version 1.6.19 | |
| 16 | + * @version 1.8.9 | |
| 11 | 17 | */ |
| 12 | 18 | |
| 13 | -$active_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : 'general'; | |
| 14 | -$group = isset( $_GET['group'] ) ? $_GET['group'] : $active_tab; | |
| 15 | -$sections = charitable_get_admin_settings()->get_sections(); | |
| 16 | -$show_return = $group != $active_tab; | |
| 19 | +$charitable_active_tab = isset( $_GET['tab'] ) ? esc_html( $_GET['tab'] ) : 'general'; // phpcs:ignore | |
| 20 | +$charitable_active_sub_tab = isset( $_GET['sub_tab'] ) ? esc_html( $_GET['sub_tab'] ) : ''; // phpcs:ignore | |
| 21 | +$charitable_tab_no_form_tag = array( 'import', 'export', 'tools' ); | |
| 22 | +$charitable_group = isset( $_GET['group'] ) ? esc_html( $_GET['group'] ) : $charitable_active_tab; // phpcs:ignore | |
| 23 | +$charitable_sections = charitable_get_admin_settings()->get_sections(); | |
| 24 | +$charitable_sub_sections = 'marketing' === $charitable_active_tab ? charitable_get_admin_settings()->get_sub_sections_marketing() : array(); | |
| 25 | +$charitable_newsletter_addon_active = class_exists( 'Charitable_Newsletter_Connect' ); | |
| 26 | +$charitable_show_return = $charitable_group !== $charitable_active_tab; | |
| 27 | +$charitable_css = ''; | |
| 17 | 28 | |
| 18 | -if ( $show_return ) { | |
| 29 | +// Resolve the effective sub_tab for routing. Marketing always has a sub_tab; default to newsletters. | |
| 30 | +if ( 'marketing' === $charitable_active_tab && '' === $charitable_active_sub_tab ) { | |
| 31 | + $charitable_active_sub_tab = 'newsletters'; | |
| 32 | +} | |
| 33 | + | |
| 34 | +if ( $charitable_show_return ) { | |
| 19 | 35 | /** |
| 20 | 36 | * Filter the return link text. |
| 21 | 37 | * |
| 22 | 38 | * @since 1.6.19 |
| @@ -24,17 +40,17 @@ | ||
| 24 | 40 | * @param string $default The default return link text. |
| 25 | 41 | * @param string $active_tab The active tab. |
| 26 | 42 | * @param string $group The current group. |
| 27 | 43 | */ |
| 28 | - $return_tab_text = apply_filters( | |
| 44 | + $charitable_return_tab_text = apply_filters( | |
| 29 | 45 | 'charitable_settings_return_tab_text', |
| 30 | 46 | sprintf( |
| 31 | 47 | /* translators: %s: tab name */ |
| 32 | 48 | __( '← Return to %s', 'charitable' ), |
| 33 | - $active_tab | |
| 49 | + $charitable_active_tab | |
| 34 | 50 | ), |
| 35 | - $active_tab, | |
| 36 | - $group | |
| 51 | + $charitable_active_tab, | |
| 52 | + $charitable_group | |
| 37 | 53 | ); |
| 38 | 54 | |
| 39 | 55 | /** |
| 40 | 56 | * Filter the return link URL. |
| @@ -44,16 +60,16 @@ | ||
| 44 | 60 | * @param string $default The default return link URL |
| 45 | 61 | * @param string $active_tab The active tab. |
| 46 | 62 | * @param string $group The current group. |
| 47 | 63 | */ |
| 48 | - $return_tab_url = apply_filters( | |
| 64 | + $charitable_return_tab_url = apply_filters( | |
| 49 | 65 | 'charitable_settings_return_tab_url', |
| 50 | 66 | add_query_arg( |
| 51 | - array( 'tab' => $active_tab ), | |
| 67 | + array( 'tab' => $charitable_active_tab ), | |
| 52 | 68 | admin_url( 'admin.php?page=charitable-settings' ) |
| 53 | 69 | ), |
| 54 | - $active_tab, | |
| 55 | - $group | |
| 70 | + $charitable_active_tab, | |
| 71 | + $charitable_group | |
| 56 | 72 | ); |
| 57 | 73 | } |
| 58 | 74 | |
| 59 | 75 | ob_start(); |
| @@ -58,18 +74,42 @@ | ||
| 58 | 74 | |
| 59 | 75 | ob_start(); |
| 60 | 76 | ?> |
| 61 | 77 | <div id="charitable-settings" class="wrap"> |
| 62 | - <h1 class="screen-reader-text"><?php echo get_admin_page_title(); ?></h1> | |
| 63 | - <h1><?php echo get_admin_page_title(); ?></h1> | |
| 78 | + <h1 class="screen-reader-text"><?php echo get_admin_page_title(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></h1> | |
| 79 | + <h1><?php echo get_admin_page_title(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></h1> | |
| 80 | + <?php do_action( 'charitable_maybe_show_notification' ); ?> | |
| 64 | 81 | <h2 class="nav-tab-wrapper"> |
| 65 | - <?php foreach ( $sections as $tab => $name ) : ?> | |
| 66 | - <a href="<?php echo esc_url( add_query_arg( array( 'tab' => $tab ), admin_url( 'admin.php?page=charitable-settings' ) ) ); ?>" class="nav-tab <?php echo $active_tab == $tab ? 'nav-tab-active' : ''; ?>"><?php echo $name; ?></a> | |
| 82 | + <?php foreach ( $charitable_sections as $charitable_section_key => $charitable_section_name ) : ?> | |
| 83 | + <?php | |
| 84 | + $charitable_url_query_arg_array = array( 'tab' => $charitable_section_key ); | |
| 85 | + if ( 'marketing' === $charitable_section_key ) { | |
| 86 | + $charitable_url_query_arg_array['sub_tab'] = 'newsletters'; | |
| 87 | + } | |
| 88 | + ?> | |
| 89 | + <a href="<?php echo esc_url( add_query_arg( $charitable_url_query_arg_array, admin_url( 'admin.php?page=charitable-settings' ) ) ); ?>" class="nav-tab nav-tab-<?php echo esc_attr( $charitable_section_key ); ?> <?php echo ( esc_attr( $charitable_active_tab ) === esc_attr( $charitable_section_key ) ) ? ' nav-tab-active' : ''; ?>"><?php echo esc_html( $charitable_section_name ); ?></a> | |
| 67 | 90 | <?php endforeach ?> |
| 68 | 91 | </h2> |
| 69 | - <?php if ( $show_return ) : ?> | |
| 92 | + <?php if ( 'marketing' === $charitable_active_tab && ! empty( $charitable_sub_sections ) ) : ?> | |
| 93 | + <h3 class="nav-sub-tab-wrapper"> | |
| 94 | + <?php foreach ( $charitable_sub_sections as $charitable_sub_section_key => $charitable_sub_section_label ) : | |
| 95 | + $charitable_sub_tab_slug = str_replace( 'marketing__', '', $charitable_sub_section_key ); | |
| 96 | + $charitable_is_active = ( $charitable_active_sub_tab === $charitable_sub_tab_slug ); | |
| 97 | + ?> | |
| 98 | + <a href="<?php echo esc_url( add_query_arg( array( 'tab' => 'marketing', 'sub_tab' => $charitable_sub_tab_slug ), admin_url( 'admin.php?page=charitable-settings' ) ) ); ?>" class="nav-tab nav-tab-marketing nav-sub-tab-<?php echo esc_attr( $charitable_sub_tab_slug ); ?><?php echo $charitable_is_active ? ' nav-tab-active' : ''; ?>"><?php | |
| 99 | + echo wp_kses( | |
| 100 | + $charitable_sub_section_label, | |
| 101 | + array( | |
| 102 | + 'span' => array( 'class' => array() ), | |
| 103 | + ) | |
| 104 | + ); | |
| 105 | + ?></a> | |
| 106 | + <?php endforeach ?> | |
| 107 | + </h3> | |
| 108 | + <?php endif; ?> | |
| 109 | + <?php if ( $charitable_show_return ) : ?> | |
| 70 | 110 | <?php /* translators: %s: active settings tab label */ ?> |
| 71 | - <p><a href="<?php echo esc_url( $return_tab_url ); ?>"><?php echo $return_tab_text; ?></a></p> | |
| 111 | + <p><a href="<?php echo esc_url( $charitable_return_tab_url ); ?>"><?php echo $charitable_return_tab_text; // phpcs:ignore ?></a></p> | |
| 72 | 112 | <?php endif ?> |
| 73 | 113 | <?php |
| 74 | 114 | /** |
| 75 | 115 | * Do or render something right before the settings form. |
| @@ -77,29 +117,70 @@ | ||
| 77 | 117 | * @since 1.0.0 |
| 78 | 118 | * |
| 79 | 119 | * @param string $group The settings group we are viewing. |
| 80 | 120 | */ |
| 81 | - do_action( 'charitable_before_admin_settings', $group ); | |
| 121 | + do_action( 'charitable_before_admin_settings', $charitable_group ); | |
| 122 | + | |
| 82 | 123 | ?> |
| 83 | - <form method="post" action="options.php"> | |
| 84 | - <table class="form-table"> | |
| 85 | - <?php | |
| 86 | - settings_fields( 'charitable_settings' ); | |
| 87 | 124 | |
| 88 | - charitable_do_settings_fields( 'charitable_settings_' . $group, 'charitable_settings_' . $group ); | |
| 125 | + <?php | |
| 126 | + // Donors → always show CTA in Lite. | |
| 127 | + // Marketing → render the real form only on Newsletters sub-tab when the Newsletter | |
| 128 | + // Connect addon is active (it works on Lite). All other Marketing sub-tabs | |
| 129 | + // (conversion_tracking, google_analytics) — and Newsletters with no addon — | |
| 130 | + // render their CTA via the charitable_pro_settings_cta action. | |
| 131 | + $charitable_show_cta = 'donors' === $charitable_active_tab | |
| 132 | + || ( 'marketing' === $charitable_active_tab | |
| 133 | + && ( 'newsletters' !== $charitable_active_sub_tab || ! $charitable_newsletter_addon_active ) | |
| 134 | + ); | |
| 135 | + | |
| 136 | + // When rendering the real form for the Newsletters sub-tab, route fields to the | |
| 137 | + // marketing__newsletters group. The legacy addon still hooks into the extensions | |
| 138 | + // section, so we use 'extensions' as the field-group key for the form (see the | |
| 139 | + // bridge in Charitable_Settings::register_settings()). | |
| 140 | + if ( 'marketing' === $charitable_active_tab && 'newsletters' === $charitable_active_sub_tab && $charitable_newsletter_addon_active && empty( $_GET['group'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 141 | + $charitable_group = 'extensions'; | |
| 142 | + } | |
| 143 | + | |
| 144 | + if ( $charitable_show_cta ) : | |
| 89 | 145 | ?> |
| 90 | - </table> | |
| 91 | - <?php | |
| 92 | - /** | |
| 93 | - * Filter the submit button at the bottom of the settings table. | |
| 94 | - * | |
| 95 | - * @since 1.6.0 | |
| 96 | - * | |
| 97 | - * @param string $button The button output. | |
| 98 | - */ | |
| 99 | - echo apply_filters( 'charitable_settings_button_' . $group, get_submit_button( null, 'primary', 'submit', true, null ) ); | |
| 100 | - ?> | |
| 101 | - </form> | |
| 146 | + <?php do_action( 'charitable_pro_settings_cta', $charitable_active_tab ); ?> | |
| 147 | + <?php else : ?> | |
| 148 | + | |
| 149 | + <?php if ( ! in_array( strtolower( $charitable_active_tab ), $charitable_tab_no_form_tag ) ) : // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict ?> | |
| 150 | + <form method="post" action="options.php"> | |
| 151 | + <?php endif; ?> | |
| 152 | + <table class="form-table"> | |
| 153 | + <?php | |
| 154 | + if ( ! in_array( strtolower( $charitable_active_tab ), $charitable_tab_no_form_tag ) ) : // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict | |
| 155 | + settings_fields( 'charitable_settings' ); | |
| 156 | + endif; | |
| 157 | + | |
| 158 | + charitable_do_settings_fields( 'charitable_settings_' . $charitable_group, 'charitable_settings_' . $charitable_group ); | |
| 159 | + ?> | |
| 160 | + </table> | |
| 161 | + <?php if ( ! in_array( strtolower( $charitable_active_tab ), $charitable_tab_no_form_tag ) ) : // phpcs:ignore ?> | |
| 162 | + <?php | |
| 163 | + /** | |
| 164 | + * Filter the submit button at the bottom of the settings table. | |
| 165 | + * | |
| 166 | + * @since 1.6.0 | |
| 167 | + * | |
| 168 | + * @param string $button The button output. | |
| 169 | + */ | |
| 170 | + echo apply_filters( 'charitable_settings_button_' . $charitable_group, get_submit_button( null, 'primary', 'submit', true, null ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 171 | + ?> | |
| 172 | + <?php endif; ?> | |
| 173 | + <?php if ( ! in_array( strtolower( $charitable_active_tab ), $charitable_tab_no_form_tag ) ) : // phpcs:ignore ?> | |
| 174 | + </form> | |
| 175 | + <?php endif; ?> | |
| 176 | + | |
| 177 | + <?php endif; ?> | |
| 178 | + | |
| 179 | + <?php if ( 'security' === $charitable_active_tab) : ?> | |
| 180 | + <?php do_action( 'charitable_pro_settings_cta', $charitable_active_tab ); ?> | |
| 181 | + <?php endif; ?> | |
| 182 | + | |
| 102 | 183 | <?php |
| 103 | 184 | /** |
| 104 | 185 | * Do or render something right after the settings form. |
| 105 | 186 | * |
| @@ -106,9 +187,10 @@ | ||
| 106 | 187 | * @since 1.0.0 |
| 107 | 188 | * |
| 108 | 189 | * @param string $group The settings group we are viewing. |
| 109 | 190 | */ |
| 110 | - do_action( 'charitable_after_admin_settings', $group ); | |
| 191 | + do_action( 'charitable_after_admin_settings', $charitable_group ); | |
| 111 | 192 | ?> |
| 112 | 193 | </div> |
| 113 | 194 | <?php |
| 114 | -echo ob_get_clean(); | |
| 195 | + | |
| 196 | +echo ob_get_clean(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |