PluginProbe ʕ •ᴥ•ʔ
Strong Testimonials / 2.33
Strong Testimonials v2.33
3.3.3 3.3.2 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 8 years ago js 7 years ago menu 8 years ago partials 7 years ago scss 7 years ago settings 7 years ago admin-notices.php 8 years ago admin.php 7 years ago class-strong-testimonials-admin-category-list.php 8 years ago class-strong-testimonials-admin-list.php 7 years ago class-strong-testimonials-admin-scripts.php 8 years ago class-strong-testimonials-defaults.php 7 years ago class-strong-testimonials-help.php 8 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-views-list-table.php 8 years ago class-walker-strong-category-checklist.php 7 years ago class-walker-strong-form-category-checklist.php 7 years ago compat.php 8 years ago custom-fields-ajax.php 8 years ago custom-fields.php 7 years ago form-preview.php 8 years ago view-list-order.php 8 years ago views-ajax.php 7 years ago views-validate.php 7 years ago views.php 7 years ago
admin.php
330 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 * Add plugin links.
173 *
174 * @param $plugin_meta
175 * @param $plugin_file
176 * @param array $plugin_data
177 * @param string $status
178 *
179 * @return array
180 */
181 function wpmtst_plugin_row_meta( $plugin_meta, $plugin_file, $plugin_data = array(), $status = '' ) {
182
183 if ( $plugin_file == WPMTST_PLUGIN ) {
184
185 $plugin_meta[] = sprintf(
186 '<a class="strong-plugin-link" href="%s" target="_blank" title="%s">%s</a>',
187 'https://strongplugins.com/documents/',
188 __( 'For guides and tutorials', 'strong-testimonials' ),
189 __( 'Documentation', 'strong-testimonials' ) );
190
191 $plugin_meta[] = sprintf(
192 '<a class="strong-plugin-link" href="%s" target="_blank" title="%s">%s</a>',
193 'https://support.strongplugins.com/',
194 __( 'For direct support requests', 'strong-testimonials' ),
195 __( 'Support', 'strong-testimonials' ) );
196
197 $plugin_meta[] = sprintf(
198 '<a class="strong-plugin-link" href="%s" target="_blank" title="%s">%s</a>',
199 'https://strongplugins.com/',
200 __( 'Get more features with premium add-ons', 'strong-testimonials' ),
201 __( 'Add-ons', 'strong-testimonials' ) );
202
203 }
204
205 return $plugin_meta;
206 }
207 //add_filter( 'plugin_row_meta', 'wpmtst_plugin_row_meta' , 10, 4 );
208
209
210 /**
211 * Check for configuration issues when options are updated.
212 *
213 * @since 2.24.0
214 * @param $option
215 * @param $old_value
216 * @param $value
217 */
218 function wpmtst_updated_option( $option, $old_value, $value ) {
219 if ( 'wpmtst_' == substr( $option, 0, 7 ) ) {
220 do_action( 'wpmtst_check_config' );
221 }
222 }
223 add_action( 'updated_option', 'wpmtst_updated_option', 10, 3 );
224
225
226 /**
227 * Store configuration error.
228 *
229 * @since 2.24.0
230 * @param $key
231 */
232 function wpmtst_add_config_error( $key ) {
233 $errors = get_option( 'wpmtst_config_errors', array() );
234 $errors[] = $key;
235 update_option( 'wpmtst_config_errors', array_unique( $errors ) );
236
237 wpmtst_add_admin_notice( $key, true );
238 }
239
240
241 /**
242 * Delete configuration error.
243 *
244 * @since 2.24.0
245 * @param $key
246 */
247 function wpmtst_delete_config_error( $key ) {
248 $errors = get_option( 'wpmtst_config_errors', array() );
249 $errors = array_diff( $errors, array ( $key ) );
250 update_option( 'wpmtst_config_errors', $errors );
251
252 wpmtst_delete_admin_notice( $key );
253 }
254
255
256 /**
257 * Save a View.
258 *
259 * @param $view
260 * @param string $action
261 * @usedby Strong_Testimonials_Update:update_views
262 *
263 * @return bool|false|int
264 */
265 function wpmtst_save_view( $view, $action = 'edit' ) {
266 global $wpdb;
267
268 if ( ! $view ) return false;
269
270 $table_name = $wpdb->prefix . 'strong_views';
271 $serialized = serialize( $view['data'] );
272
273 if ( 'add' == $action || 'duplicate' == $action ) {
274 $sql = "INSERT INTO {$table_name} (name, value) VALUES (%s, %s)";
275 $sql = $wpdb->prepare( $sql, $view['name'], $serialized );
276 $wpdb->query( $sql );
277 $view['id'] = $wpdb->insert_id;
278 $return = $view['id'];
279 }
280 else {
281 $sql = "UPDATE {$table_name} SET name = %s, value = %s WHERE id = %d";
282 $sql = $wpdb->prepare( $sql, $view['name'], $serialized, intval( $view['id'] ) );
283 $wpdb->query( $sql );
284 $return = $wpdb->last_error ? 0 : 1;
285 }
286
287 do_action( 'wpmtst_view_saved', $view );
288
289 return $return;
290 }
291
292
293 /**
294 * @param $field
295 *
296 * @return mixed
297 */
298 function wpmtst_get_field_label( $field ) {
299 if ( isset( $field['field'] ) ) {
300 $custom_fields = wpmtst_get_custom_fields();
301 if ( isset( $custom_fields[ $field['field'] ]['label'] ) ) {
302 return $custom_fields[ $field['field'] ]['label'];
303 }
304 $builtin_fields = wpmtst_get_builtin_fields();
305 if ( isset( $builtin_fields[ $field['field'] ]['label'] ) ) {
306 return $builtin_fields[ $field['field'] ]['label'];
307 }
308 }
309
310 return '';
311 }
312
313
314 /**
315 * @param string $field_name
316 *
317 * @return mixed
318 */
319 function wpmtst_get_field_by_name( $field_name = '' ) {
320 if ( $field_name ) {
321 $custom_fields = wpmtst_get_custom_fields();
322 if ( isset( $custom_fields[ $field_name ] ) ) {
323 return $custom_fields[ $field_name ];
324 }
325 }
326
327 return '';
328 }
329
330