challenge
1 year ago
css
1 month ago
img
1 year ago
js
1 month ago
menu
1 month ago
partials
1 year ago
rest-api
1 month ago
scss
1 year ago
settings
1 month ago
uninstall
1 year ago
wpchill
1 month ago
admin-notices.php
5 months ago
admin.php
1 month ago
class-strong-testimonials-addons.php
1 month 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 month ago
class-strong-testimonials-admin.php
1 month ago
class-strong-testimonials-debug.php
5 months ago
class-strong-testimonials-exporter.php
1 year ago
class-strong-testimonials-help.php
1 year ago
class-strong-testimonials-helper.php
1 month ago
class-strong-testimonials-list-table.php
1 year ago
class-strong-testimonials-lite-vs-pro-page.php
1 month ago
class-strong-testimonials-post-editor.php
6 months ago
class-strong-testimonials-review.php
1 year ago
class-strong-testimonials-updater.php
1 month ago
class-strong-testimonials-upsell.php
1 month ago
class-strong-views-list-table.php
1 month ago
class-walker-strong-category-checklist.php
1 year ago
class-walker-strong-form-category-checklist.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 month ago
views-validate.php
1 year ago
views.php
1 month ago
admin.php
308 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Strong Testimonials admin functions. |
| 4 | * |
| 5 | * 1. Check for required WordPress version. |
| 6 | * 2. Check for plugin update. |
| 7 | * 3. Initialize. |
| 8 | */ |
| 9 | |
| 10 | /** |
| 11 | * Check for required WordPress version. |
| 12 | */ |
| 13 | function wpmtst_version_check() { |
| 14 | global $wp_version; |
| 15 | $require_wp_version = '3.7'; |
| 16 | |
| 17 | if ( version_compare( $wp_version, $require_wp_version ) === -1 ) { |
| 18 | deactivate_plugins( WPMTST_PLUGIN ); |
| 19 | /* translators: %s is the name of the plugin. */ |
| 20 | $message = '<h2>' . sprintf( esc_html_x( 'Unable to load %s', 'installation', 'strong-testimonials' ), 'Strong Testimonials' ) . '</h2>'; |
| 21 | /* translators: %s is a WordPress version number. */ |
| 22 | $message .= '<p>' . sprintf( wp_kses_post( _x( 'This plugin requires <strong>WordPress %s</strong> or higher so it has been deactivated.', 'installation', 'strong-testimonials' ) ), $require_wp_version ) . '</p>'; |
| 23 | $message .= '<p>' . esc_html_x( 'Please upgrade WordPress and try again.', 'installation', 'strong-testimonials' ) . '</p>'; |
| 24 | /* translators: %s is the URL to the "Plugins" page in WordPress. */ |
| 25 | $message .= '<p>' . sprintf( wp_kses_post( _x( 'Back to the WordPress <a href="%s">Plugins page</a>', 'installation', 'strong-testimonials' ) ), esc_url( get_admin_url( null, 'plugins.php' ) ) ) . '</p>'; |
| 26 | wp_die( $message ); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | add_action( 'admin_init', 'wpmtst_version_check', 1 ); |
| 31 | |
| 32 | /** |
| 33 | * Check for plugin update. |
| 34 | * |
| 35 | * @since 2.28.4 Before other admin_init actions. |
| 36 | */ |
| 37 | function wpmtst_update_check() { |
| 38 | $version = get_option( 'wpmtst_plugin_version', false ); |
| 39 | if ( WPMTST_VERSION === $version ) { |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | Strong_Testimonials_Updater::update(); |
| 44 | } |
| 45 | |
| 46 | add_action( 'admin_init', 'wpmtst_update_check', 5 ); |
| 47 | |
| 48 | /** |
| 49 | * Initialize. |
| 50 | */ |
| 51 | function wpmtst_admin_init() { |
| 52 | |
| 53 | /** |
| 54 | * Custom action hooks |
| 55 | * |
| 56 | * @since 1.18.4 |
| 57 | */ |
| 58 | if ( isset( $_REQUEST['action'] ) && '' !== $_REQUEST['action'] ) { |
| 59 | $action = sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ); |
| 60 | do_action( 'wpmtst_' . $action ); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | add_action( 'admin_init', 'wpmtst_admin_init' ); |
| 65 | add_action( 'admin_init', 'wpmtst_create_default_views', 20 ); |
| 66 | |
| 67 | /** |
| 68 | * Are we on a testimonial admin screen? |
| 69 | * |
| 70 | * Used by add-ons too! |
| 71 | * |
| 72 | * @return bool |
| 73 | */ |
| 74 | function wpmtst_is_testimonial_screen() { |
| 75 | $screen = get_current_screen(); |
| 76 | return ( $screen && 'wpm-testimonial' === $screen->post_type ); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Add pending numbers to post types on admin menu. |
| 81 | * Thanks http://wordpress.stackexchange.com/a/105470/32076 |
| 82 | * |
| 83 | * @param $menu |
| 84 | * |
| 85 | * @return mixed |
| 86 | */ |
| 87 | function wpmtst_pending_indicator( $menu ) { |
| 88 | if ( ! current_user_can( 'edit_posts' ) ) { |
| 89 | return $menu; |
| 90 | } |
| 91 | |
| 92 | $options = get_option( 'wpmtst_options' ); |
| 93 | |
| 94 | $pending_indicator = isset( $options['pending_indicator'] ) && ! $options['pending_indicator'] ? false : true; |
| 95 | |
| 96 | if ( ! apply_filters( 'wpmtst_enable_pending_indicator', $pending_indicator ) ) { |
| 97 | return $menu; |
| 98 | } |
| 99 | |
| 100 | $types = array( 'wpm-testimonial' ); |
| 101 | $status = 'pending'; |
| 102 | foreach ( $types as $type ) { |
| 103 | $num_posts = wp_count_posts( $type, 'readable' ); |
| 104 | $pending_count = 0; |
| 105 | if ( ! empty( $num_posts->$status ) ) { |
| 106 | $pending_count = $num_posts->$status; |
| 107 | } |
| 108 | |
| 109 | if ( 'post' === $type ) { |
| 110 | $menu_str = 'edit.php'; |
| 111 | } else { |
| 112 | $menu_str = 'edit.php?post_type=' . $type; |
| 113 | } |
| 114 | foreach ( $menu as $menu_key => $menu_data ) { |
| 115 | if ( $menu_str !== $menu_data[2] ) { |
| 116 | continue; |
| 117 | } |
| 118 | |
| 119 | $menu[ $menu_key ][0] .= " <span class='update-plugins count-$pending_count'><span class='plugin-count'>" . number_format_i18n( $pending_count ) . '</span></span>'; |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | return $menu; |
| 124 | } |
| 125 | add_filter( 'add_menu_classes', 'wpmtst_pending_indicator' ); |
| 126 | |
| 127 | /** |
| 128 | * The [restore default] icon. |
| 129 | * |
| 130 | * @param $for |
| 131 | * |
| 132 | * @since 2.18.0 |
| 133 | */ |
| 134 | function wpmtst_restore_default_icon( $input_for ) { |
| 135 | if ( ! $input_for ) { |
| 136 | return; |
| 137 | } |
| 138 | ?> |
| 139 | <input type="button" class="button secondary restore-default" |
| 140 | title="<?php esc_html_e( 'restore default', 'strong-testimonials' ); ?>" |
| 141 | value="" |
| 142 | data-for="<?php echo esc_attr( $input_for ); ?>"/> |
| 143 | <?php |
| 144 | } |
| 145 | |
| 146 | |
| 147 | |
| 148 | /** |
| 149 | * Check for configuration issues when options are updated. |
| 150 | * |
| 151 | * @since 2.24.0 |
| 152 | * @param $option |
| 153 | * @param $old_value |
| 154 | * @param $value |
| 155 | */ |
| 156 | function wpmtst_updated_option( $option, $old_value, $value ) { |
| 157 | if ( 'wpmtst_' === substr( $option, 0, 7 ) ) { |
| 158 | do_action( 'wpmtst_check_config' ); |
| 159 | } |
| 160 | } |
| 161 | add_action( 'updated_option', 'wpmtst_updated_option', 10, 3 ); |
| 162 | |
| 163 | /** |
| 164 | * Save a View. |
| 165 | * |
| 166 | * @param $view |
| 167 | * @param string $action |
| 168 | * @usedby Strong_Testimonials_Update:update_views |
| 169 | * |
| 170 | * @return bool|false|int |
| 171 | */ |
| 172 | function wpmtst_save_view( $view, $action = 'edit' ) { |
| 173 | global $wpdb; |
| 174 | |
| 175 | if ( ! $view ) { |
| 176 | return false; |
| 177 | } |
| 178 | |
| 179 | $table_name = $wpdb->prefix . 'strong_views'; |
| 180 | $serialized = serialize( $view['data'] ); |
| 181 | |
| 182 | if ( 'add' === $action || 'duplicate' === $action ) { |
| 183 | // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
| 184 | $wpdb->query( $wpdb->prepare( "INSERT INTO {$table_name} (name, value) VALUES (%s, %s)", $view['name'], $serialized ) ); |
| 185 | $view['id'] = $wpdb->insert_id; |
| 186 | $return = $view['id']; |
| 187 | } else { |
| 188 | // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
| 189 | $wpdb->query( $wpdb->prepare( "UPDATE {$table_name} SET name = %s, value = %s WHERE id = %d", $view['name'], $serialized, intval( $view['id'] ) ) ); |
| 190 | $return = $wpdb->last_error ? 0 : 1; |
| 191 | } |
| 192 | |
| 193 | do_action( 'wpmtst_view_saved', $view ); |
| 194 | |
| 195 | return $return; |
| 196 | } |
| 197 | |
| 198 | |
| 199 | /** |
| 200 | * @param $field |
| 201 | * |
| 202 | * @return mixed |
| 203 | */ |
| 204 | function wpmtst_get_field_label( $field ) { |
| 205 | if ( isset( $field['field'] ) ) { |
| 206 | $custom_fields = wpmtst_get_custom_fields(); |
| 207 | if ( isset( $custom_fields[ $field['field'] ]['label'] ) ) { |
| 208 | return $custom_fields[ $field['field'] ]['label']; |
| 209 | } |
| 210 | $builtin_fields = wpmtst_get_builtin_fields(); |
| 211 | if ( isset( $builtin_fields[ $field['field'] ]['label'] ) ) { |
| 212 | return $builtin_fields[ $field['field'] ]['label']; |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | return ''; |
| 217 | } |
| 218 | |
| 219 | function wpmtst_get_field_text( $field ) { |
| 220 | if ( isset( $field['field'] ) ) { |
| 221 | $custom_fields = wpmtst_get_custom_fields(); |
| 222 | if ( isset( $custom_fields[ $field['field'] ]['text'] ) ) { |
| 223 | return $custom_fields[ $field['field'] ]['text']; |
| 224 | } |
| 225 | $builtin_fields = wpmtst_get_builtin_fields(); |
| 226 | if ( isset( $builtin_fields[ $field['field'] ]['text'] ) ) { |
| 227 | return $builtin_fields[ $field['field'] ]['text']; |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | return ''; |
| 232 | } |
| 233 | |
| 234 | |
| 235 | /** |
| 236 | * @param string $field_name |
| 237 | * |
| 238 | * @return mixed |
| 239 | */ |
| 240 | function wpmtst_get_field_by_name( $field_name = '' ) { |
| 241 | if ( $field_name ) { |
| 242 | $custom_fields = wpmtst_get_custom_fields(); |
| 243 | if ( isset( $custom_fields[ $field_name ] ) ) { |
| 244 | return $custom_fields[ $field_name ]; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | return ''; |
| 249 | } |
| 250 | |
| 251 | /** |
| 252 | * Returns true if at least one extension is installed |
| 253 | */ |
| 254 | function wpmtst_extensions_installed() { |
| 255 | |
| 256 | if ( defined( 'WPMTST_CUSTOM_FIELDS_VERSION' ) ) { |
| 257 | return true; |
| 258 | } |
| 259 | if ( defined( 'WPMTST_ASSIGNMENT_VERSION' ) ) { |
| 260 | return true; |
| 261 | } |
| 262 | if ( defined( 'WPMTST_MULTIPLE_FORMS_VERSION' ) ) { |
| 263 | return true; |
| 264 | } |
| 265 | if ( defined( 'WPMTST_PROPERTIES_VERSION' ) ) { |
| 266 | return true; |
| 267 | } |
| 268 | if ( defined( 'WPMTST_COUNTRY_SELECTOR_VERSION' ) ) { |
| 269 | return true; |
| 270 | } |
| 271 | if ( defined( 'WPMTST_REVIEW_MARKUP_VERSION' ) ) { |
| 272 | return true; |
| 273 | } |
| 274 | if ( defined( 'WPMTST_ADVANCED_VIEWS_VERSION' ) ) { |
| 275 | return true; |
| 276 | } |
| 277 | |
| 278 | return false; |
| 279 | } |
| 280 | |
| 281 | /** |
| 282 | * Store configuration error. |
| 283 | * |
| 284 | * @since 2.24.0 |
| 285 | * @param $key |
| 286 | */ |
| 287 | function wpmtst_add_config_error( $key ) { |
| 288 | $errors = get_option( 'wpmtst_config_errors', array() ); |
| 289 | $errors[] = $key; |
| 290 | update_option( 'wpmtst_config_errors', array_unique( $errors ), 'no' ); |
| 291 | |
| 292 | wpmtst_add_admin_notice( $key, true ); |
| 293 | } |
| 294 | |
| 295 | |
| 296 | /** |
| 297 | * Delete configuration error. |
| 298 | * |
| 299 | * @since 2.24.0 |
| 300 | * @param $key |
| 301 | */ |
| 302 | function wpmtst_delete_config_error( $key ) { |
| 303 | $errors = get_option( 'wpmtst_config_errors', array() ); |
| 304 | $errors = array_diff( $errors, array( $key ) ); |
| 305 | update_option( 'wpmtst_config_errors', $errors, 'no' ); |
| 306 | |
| 307 | wpmtst_delete_admin_notice( $key ); |
| 308 | } |