PluginProbe ʕ •ᴥ•ʔ
Strong Testimonials / 2.38
Strong Testimonials v2.38
3.3.1 trunk 1.0.1 2.30.9 2.31.10 2.32 2.32.1 2.32.2 2.32.3 2.32.4 2.33 2.34 2.35 2.36 2.37 2.38 2.38.1 2.39 2.39.1 2.39.2 2.39.3 2.40.0 2.40.1 2.40.2 2.40.3 2.40.4 2.40.5 2.40.6 2.40.7 2.41.0 2.41.1 2.50.0 2.50.1 2.50.2 2.50.3 2.50.4 2.51.0 2.51.1 2.51.2 2.51.3 2.51.4 2.51.5 2.51.6 2.51.7 2.51.8 2.51.9 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.20 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.17 3.2.18 3.2.19 3.2.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0
strong-testimonials / admin / admin.php
strong-testimonials / admin Last commit date
about 7 years ago css 7 years ago img 7 years ago js 7 years ago menu 7 years ago partials 7 years ago scss 7 years ago settings 7 years ago admin-notices.php 7 years ago admin.php 7 years ago class-strong-testimonials-addons.php 7 years ago class-strong-testimonials-admin-category-list.php 7 years ago class-strong-testimonials-admin-list.php 7 years ago class-strong-testimonials-admin-scripts.php 7 years ago class-strong-testimonials-defaults.php 7 years ago class-strong-testimonials-exporter.php 7 years ago class-strong-testimonials-help.php 7 years ago class-strong-testimonials-list-table.php 7 years ago class-strong-testimonials-page-shortcodes.php 7 years ago class-strong-testimonials-post-editor.php 7 years ago class-strong-testimonials-updater.php 7 years ago class-strong-testimonials-upsell.php 7 years ago class-strong-views-list-table.php 7 years ago class-walker-strong-category-checklist.php 7 years ago class-walker-strong-form-category-checklist.php 7 years ago compat.php 7 years ago custom-fields-ajax.php 7 years ago custom-fields.php 7 years ago form-preview.php 7 years ago view-list-order.php 7 years ago views-ajax.php 7 years ago views-validate.php 7 years ago views.php 7 years ago
admin.php
323 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( _x( 'Unable to load %s', 'installation', 'strong-testimonials' ), 'Strong Testimonials' ) . '</h2>';
21 /* translators: %s is a WordPress version number. */
22 $message .= '<p>' . sprintf( _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>' . _x( 'Please upgrade WordPress and try again.', 'installation', 'strong-testimonials' ) . '</p>';
24 $message .= '<p>' . sprintf( _x( 'Back to the WordPress <a href="%s">Plugins page</a>', 'installation', 'strong-testimonials' ), get_admin_url( null, 'plugins.php' ) ) . '</p>';
25 wp_die( $message );
26 }
27 }
28
29 add_action( 'admin_init', 'wpmtst_version_check', 1 );
30
31 /**
32 * Check for plugin update.
33 *
34 * @since 2.28.4 Before other admin_init actions.
35 */
36 function wpmtst_update_check() {
37 $version = get_option( 'wpmtst_plugin_version', false );
38 if ( $version == WPMTST_VERSION ) {
39 return;
40 }
41 // Redirect to About page afterwards. On new install or (de)activation only.
42 if ( false === $version ) {
43 add_option( 'wpmtst_do_activation_redirect', true );
44 }
45
46 require_once WPMTST_ADMIN . 'class-strong-testimonials-updater.php';
47 $updater = new Strong_Testimonials_Updater();
48 $updater->update();
49 }
50
51 add_action( 'admin_init', 'wpmtst_update_check', 5 );
52
53 /**
54 * Initialize.
55 */
56 function wpmtst_admin_init() {
57 /**
58 * Redirect to About page for new installs only
59 *
60 * @since 2.28.4
61 */
62 wpmtst_activation_redirect();
63
64 /**
65 * Custom action hooks
66 *
67 * @since 1.18.4
68 */
69 if ( isset( $_REQUEST['action'] ) && '' != $_REQUEST['action'] ) {
70 do_action( 'wpmtst_' . $_REQUEST['action'] );
71 }
72 }
73
74 add_action( 'admin_init', 'wpmtst_admin_init' );
75
76 /**
77 * Custom action link in admin notice.
78 *
79 * @since 2.29.0
80 */
81 function wpmtst_action_captcha_options_changed() {
82 wpmtst_delete_admin_notice( 'captcha-options-changed' );
83 wp_redirect( admin_url( 'edit.php?post_type=wpm-testimonial&page=testimonial-settings&tab=form#captcha-section' ) );
84 exit;
85 }
86
87 add_action( 'admin_action_captcha-options-changed', 'wpmtst_action_captcha_options_changed' );
88
89 /**
90 * Redirect to About page.
91 *
92 * @since 2.28.4
93 */
94 function wpmtst_activation_redirect() {
95 if ( get_option( 'wpmtst_do_activation_redirect', false ) ) {
96 delete_option( 'wpmtst_do_activation_redirect' );
97 wp_redirect( admin_url( 'edit.php?post_type=wpm-testimonial&page=about-strong-testimonials' ) );
98 exit;
99 }
100 }
101
102 /**
103 * Are we on a testimonial admin screen?
104 *
105 * Used by add-ons too!
106 *
107 * @return bool
108 */
109 function wpmtst_is_testimonial_screen() {
110 $screen = get_current_screen();
111 return ( $screen && 'wpm-testimonial' == $screen->post_type );
112 }
113
114 /**
115 * Add pending numbers to post types on admin menu.
116 * Thanks http://wordpress.stackexchange.com/a/105470/32076
117 *
118 * @param $menu
119 *
120 * @return mixed
121 */
122 function wpmtst_pending_indicator( $menu ) {
123 if ( ! current_user_can( 'edit_posts' ) )
124 return $menu;
125
126 $options = get_option( 'wpmtst_options' );
127 if ( ! isset( $options['pending_indicator'] ) || ! $options['pending_indicator'] )
128 return $menu;
129
130 $types = array( 'wpm-testimonial' );
131 $status = 'pending';
132 foreach ( $types as $type ) {
133 $num_posts = wp_count_posts( $type, 'readable' );
134 $pending_count = 0;
135 if ( ! empty( $num_posts->$status ) )
136 $pending_count = $num_posts->$status;
137
138 if ( $type == 'post' )
139 $menu_str = 'edit.php';
140 else
141 $menu_str = 'edit.php?post_type=' . $type;
142
143 foreach ( $menu as $menu_key => $menu_data ) {
144 if ( $menu_str != $menu_data[2] )
145 continue;
146 $menu[ $menu_key ][0] .= " <span class='update-plugins count-$pending_count'><span class='plugin-count'>" . number_format_i18n( $pending_count ) . '</span></span>';
147 }
148 }
149
150 return $menu;
151 }
152 add_filter( 'add_menu_classes', 'wpmtst_pending_indicator' );
153
154 /**
155 * The [restore default] icon.
156 *
157 * @param $for
158 *
159 * @since 2.18.0
160 */
161 function wpmtst_restore_default_icon( $for ) {
162 if ( !$for ) return;
163 ?>
164 <input type="button" class="button secondary restore-default"
165 title="<?php _e( 'restore default', 'strong-testimonials' ); ?>"
166 value="&#xf171"
167 data-for="<?php echo $for; ?>"/>
168 <?php
169 }
170
171
172
173 /**
174 * Check for configuration issues when options are updated.
175 *
176 * @since 2.24.0
177 * @param $option
178 * @param $old_value
179 * @param $value
180 */
181 function wpmtst_updated_option( $option, $old_value, $value ) {
182 if ( 'wpmtst_' == substr( $option, 0, 7 ) ) {
183 do_action( 'wpmtst_check_config' );
184 }
185 }
186 add_action( 'updated_option', 'wpmtst_updated_option', 10, 3 );
187
188
189 /**
190 * Store configuration error.
191 *
192 * @since 2.24.0
193 * @param $key
194 */
195 function wpmtst_add_config_error( $key ) {
196 $errors = get_option( 'wpmtst_config_errors', array() );
197 $errors[] = $key;
198 update_option( 'wpmtst_config_errors', array_unique( $errors ) );
199
200 wpmtst_add_admin_notice( $key, true );
201 }
202
203
204 /**
205 * Delete configuration error.
206 *
207 * @since 2.24.0
208 * @param $key
209 */
210 function wpmtst_delete_config_error( $key ) {
211 $errors = get_option( 'wpmtst_config_errors', array() );
212 $errors = array_diff( $errors, array ( $key ) );
213 update_option( 'wpmtst_config_errors', $errors );
214
215 wpmtst_delete_admin_notice( $key );
216 }
217
218
219 /**
220 * Save a View.
221 *
222 * @param $view
223 * @param string $action
224 * @usedby Strong_Testimonials_Update:update_views
225 *
226 * @return bool|false|int
227 */
228 function wpmtst_save_view( $view, $action = 'edit' ) {
229 global $wpdb;
230
231 if ( ! $view ) return false;
232
233 $table_name = $wpdb->prefix . 'strong_views';
234 $serialized = serialize( $view['data'] );
235
236 if ( 'add' == $action || 'duplicate' == $action ) {
237 $sql = "INSERT INTO {$table_name} (name, value) VALUES (%s, %s)";
238 $sql = $wpdb->prepare( $sql, $view['name'], $serialized );
239 $wpdb->query( $sql );
240 $view['id'] = $wpdb->insert_id;
241 $return = $view['id'];
242 }
243 else {
244 $sql = "UPDATE {$table_name} SET name = %s, value = %s WHERE id = %d";
245 $sql = $wpdb->prepare( $sql, $view['name'], $serialized, intval( $view['id'] ) );
246 $wpdb->query( $sql );
247 $return = $wpdb->last_error ? 0 : 1;
248 }
249
250 do_action( 'wpmtst_view_saved', $view );
251
252 return $return;
253 }
254
255
256 /**
257 * @param $field
258 *
259 * @return mixed
260 */
261 function wpmtst_get_field_label( $field ) {
262 if ( isset( $field['field'] ) ) {
263 $custom_fields = wpmtst_get_custom_fields();
264 if ( isset( $custom_fields[ $field['field'] ]['label'] ) ) {
265 return $custom_fields[ $field['field'] ]['label'];
266 }
267 $builtin_fields = wpmtst_get_builtin_fields();
268 if ( isset( $builtin_fields[ $field['field'] ]['label'] ) ) {
269 return $builtin_fields[ $field['field'] ]['label'];
270 }
271 }
272
273 return '';
274 }
275
276
277 /**
278 * @param string $field_name
279 *
280 * @return mixed
281 */
282 function wpmtst_get_field_by_name( $field_name = '' ) {
283 if ( $field_name ) {
284 $custom_fields = wpmtst_get_custom_fields();
285 if ( isset( $custom_fields[ $field_name ] ) ) {
286 return $custom_fields[ $field_name ];
287 }
288 }
289
290 return '';
291 }
292
293 /**
294 * Returns true if at least one extension is installed
295 */
296 function wpmtst_extensions_installed() {
297
298 if ( defined( 'WPMTST_CUSTOM_FIELDS_VERSION' ) ) {
299 return true;
300 }
301 if ( defined( 'WPMTST_ASSIGNMENT_VERSION' ) ) {
302 return true;
303 }
304 if ( defined( 'WPMTST_MULTIPLE_FORMS_VERSION' ) ) {
305 return true;
306 }
307 if ( defined( 'WPMTST_PROPERTIES_VERSION' ) ) {
308 return true;
309 }
310 if ( defined( 'WPMTST_COUNTRY_SELECTOR_VERSION' ) ) {
311 return true;
312 }
313 if ( defined( 'WPMTST_REVIEW_MARKUP_VERSION' ) ) {
314 return true;
315 }
316 if ( defined( 'WPMTST_ADVANCED_VIEWS_VERSION' ) ) {
317 return true;
318 }
319
320 return false;
321 }
322
323