challenge
1 year ago
css
1 year ago
img
1 year ago
js
1 year ago
menu
1 year ago
partials
1 year ago
scss
1 year ago
settings
1 year ago
uninstall
1 year ago
admin-notices.php
1 year ago
admin.php
1 year ago
class-strong-testimonials-addons.php
1 year ago
class-strong-testimonials-admin-category-list.php
1 year ago
class-strong-testimonials-admin-list.php
1 year ago
class-strong-testimonials-admin-scripts.php
1 year ago
class-strong-testimonials-debug.php
1 year ago
class-strong-testimonials-defaults.php
1 year ago
class-strong-testimonials-exporter.php
1 year ago
class-strong-testimonials-help.php
1 year ago
class-strong-testimonials-helper.php
1 year ago
class-strong-testimonials-list-table.php
1 year ago
class-strong-testimonials-lite-vs-pro-page.php
1 year ago
class-strong-testimonials-page-shortcodes.php
1 year ago
class-strong-testimonials-post-editor.php
1 year ago
class-strong-testimonials-review.php
1 year ago
class-strong-testimonials-updater.php
1 year ago
class-strong-testimonials-upsell.php
1 year ago
class-strong-testimonials-wpchill-upsells.php
1 year ago
class-strong-views-list-table.php
1 year ago
class-walker-strong-category-checklist.php
1 year ago
class-walker-strong-form-category-checklist.php
1 year ago
class-wpmtst-admin-helpers.php
1 year ago
class-wpmtst-onboarding.php
1 year ago
compat.php
1 year ago
custom-fields-ajax.php
1 year ago
custom-fields.php
1 year ago
form-preview.php
1 year ago
view-list-order.php
1 year ago
views-ajax.php
1 year ago
views-validate.php
1 year ago
views.php
1 year ago
admin-notices.php
196 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Admin notices |
| 4 | */ |
| 5 | |
| 6 | |
| 7 | /** |
| 8 | * Dismiss persistent notices. |
| 9 | * |
| 10 | * @since 2.29.0 |
| 11 | */ |
| 12 | function wpmtst_dismiss_notice_ajax() { |
| 13 | if ( ! isset( $_POST['key'] ) || ! $_POST['key'] ) { |
| 14 | echo 0; |
| 15 | wp_die(); |
| 16 | } |
| 17 | |
| 18 | check_ajax_referer( 'wpmtst-admin', 'nonce' ); |
| 19 | wpmtst_delete_admin_notice( sanitize_text_field( wp_unslash( $_POST['key'] ) ) ); |
| 20 | wp_die(); |
| 21 | } |
| 22 | |
| 23 | add_action( 'wp_ajax_wpmtst_dismiss_notice', 'wpmtst_dismiss_notice_ajax' ); |
| 24 | |
| 25 | /** |
| 26 | * Print admin notices. |
| 27 | * |
| 28 | * @since 2.24.0 |
| 29 | */ |
| 30 | function wpmtst_admin_notices() { |
| 31 | $notices = get_option( 'wpmtst_admin_notices' ); |
| 32 | if ( ! $notices ) { |
| 33 | return; |
| 34 | } |
| 35 | |
| 36 | foreach ( $notices as $key => $notice ) { |
| 37 | $message = apply_filters( 'wpmtst_admin_notice', '', $key ); |
| 38 | if ( $message ) { |
| 39 | echo wp_kses_post( $message ); |
| 40 | } |
| 41 | if ( ! $notice['persist'] ) { |
| 42 | wpmtst_delete_admin_notice( $key ); |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | add_action( 'admin_notices', 'wpmtst_admin_notices' ); |
| 47 | |
| 48 | |
| 49 | /** |
| 50 | * Return specific admin notice text. |
| 51 | * |
| 52 | * @since 2.28.5 |
| 53 | * @param string $html |
| 54 | * @param $key |
| 55 | * |
| 56 | * @return string |
| 57 | */ |
| 58 | function wpmtst_admin_notice_text( $html, $key, $persist = false ) { |
| 59 | |
| 60 | switch ( $key ) { |
| 61 | case 'defaults-restored': |
| 62 | ob_start(); |
| 63 | ?> |
| 64 | <div class="wpmtst notice notice-success is-dismissible" data-key="<?php echo esc_attr( $key ); ?>"> |
| 65 | <p> |
| 66 | <?php esc_html_e( 'Defaults restored.', 'strong-testimonials' ); ?> |
| 67 | </p> |
| 68 | </div> |
| 69 | <?php |
| 70 | $html = ob_get_clean(); |
| 71 | break; |
| 72 | |
| 73 | case 'fields-saved': |
| 74 | ob_start(); |
| 75 | ?> |
| 76 | <div class="wpmtst notice notice-success is-dismissible" data-key="<?php echo esc_attr( $key ); ?>"> |
| 77 | <p> |
| 78 | <?php esc_html_e( 'Fields saved.', 'strong-testimonials' ); ?> |
| 79 | </p> |
| 80 | </div> |
| 81 | <?php |
| 82 | $html = ob_get_clean(); |
| 83 | break; |
| 84 | |
| 85 | case 'changes-cancelled': |
| 86 | ob_start(); |
| 87 | ?> |
| 88 | <div class="wpmtst notice notice-success is-dismissible" data-key="<?php echo esc_attr( $key ); ?>"> |
| 89 | <p> |
| 90 | <?php esc_html_e( 'Changes cancelled.', 'strong-testimonials' ); ?> |
| 91 | </p> |
| 92 | </div> |
| 93 | <?php |
| 94 | $html = ob_get_clean(); |
| 95 | break; |
| 96 | |
| 97 | case 'captcha-options-changed': |
| 98 | $tags = array( |
| 99 | 'a' => array( |
| 100 | 'class' => array(), |
| 101 | 'href' => array(), |
| 102 | ), |
| 103 | ); |
| 104 | |
| 105 | $settings_url = admin_url( '?action=captcha-options-changed' ); |
| 106 | |
| 107 | $settings_link = sprintf( |
| 108 | wp_kses( |
| 109 | // translators: %1$s is the URL to the settings page, and %2$s is the text "settings". |
| 110 | __( 'Please check your <a href="%1$s">%2$s</a>.', 'strong-testimonials' ), |
| 111 | $tags |
| 112 | ), |
| 113 | esc_url( $settings_url ), |
| 114 | esc_html__( 'settings', 'strong-testimonials' ) |
| 115 | ); |
| 116 | |
| 117 | ob_start(); |
| 118 | ?> |
| 119 | <div class="wpmtst notice notice-warning is-dismissible" data-key="<?php echo esc_attr( $key ); ?>"> |
| 120 | <p> |
| 121 | <?php echo wp_kses_post( __( 'Captcha options have changed in <strong>Strong Testimonials</strong>.', 'strong-testimonials' ) ); ?> |
| 122 | <?php echo esc_url( $settings_link ); ?> |
| 123 | </p> |
| 124 | </div> |
| 125 | <?php |
| 126 | $html = ob_get_clean(); |
| 127 | break; |
| 128 | |
| 129 | default: |
| 130 | $html = apply_filters( 'wpmtst_' . $key . '_notice', '' ); |
| 131 | // nothing |
| 132 | } |
| 133 | |
| 134 | return $html; |
| 135 | } |
| 136 | add_filter( 'wpmtst_admin_notice', 'wpmtst_admin_notice_text', 10, 2 ); |
| 137 | |
| 138 | |
| 139 | /** |
| 140 | * Add admin notice to queue. |
| 141 | * |
| 142 | * @since 2.24.0 |
| 143 | * |
| 144 | * @param $key |
| 145 | * @param $persist |
| 146 | */ |
| 147 | function wpmtst_add_admin_notice( $key, $persist = false ) { |
| 148 | $notices = get_option( 'wpmtst_admin_notices', array() ); |
| 149 | $notices[ $key ] = array( 'persist' => $persist ); |
| 150 | update_option( 'wpmtst_admin_notices', $notices, 'no' ); |
| 151 | } |
| 152 | |
| 153 | |
| 154 | /** |
| 155 | * Delete admin notice from queue. |
| 156 | * |
| 157 | * @since 2.24.0 |
| 158 | * |
| 159 | * @param $key |
| 160 | */ |
| 161 | function wpmtst_delete_admin_notice( $key ) { |
| 162 | $notices = get_option( 'wpmtst_admin_notices', array() ); |
| 163 | if ( isset( $notices[ $key ] ) ) { |
| 164 | unset( $notices[ $key ] ); |
| 165 | update_option( 'wpmtst_admin_notices', $notices, 'no' ); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | |
| 170 | /** |
| 171 | * Automatically dismiss specific notices when settings are saved. |
| 172 | * |
| 173 | * @since 2.29.0 |
| 174 | * @param $option |
| 175 | * @param $old_value |
| 176 | * @param $value |
| 177 | */ |
| 178 | function wpmtst_auto_dismiss_notices( $option, $old_value, $value ) { |
| 179 | if ( ! function_exists( 'get_current_screen' ) ) { |
| 180 | return; |
| 181 | } |
| 182 | |
| 183 | $screen = get_current_screen(); |
| 184 | if ( $screen && 'options' === $screen->base ) { |
| 185 | if ( 'wpmtst_form_options' === $option ) { |
| 186 | $notices = get_option( 'wpmtst_admin_notices', array() ); |
| 187 | if ( isset( $notices['captcha-options-changed'] ) ) { |
| 188 | unset( $notices['captcha-options-changed'] ); |
| 189 | update_option( 'wpmtst_admin_notices', $notices, 'no' ); |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | add_action( 'update_option', 'wpmtst_auto_dismiss_notices', 10, 3 ); |
| 195 | |
| 196 |