PluginProbe ʕ •ᴥ•ʔ
Strong Testimonials / 2.34
Strong Testimonials v2.34
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-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-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-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
298 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( wp_kses_post( $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
127 $options = get_option( 'wpmtst_options' );
128 if ( ! isset( $options['pending_indicator'] ) || ! $options['pending_indicator'] ) {
129 return $menu;
130 }
131
132 $types = array( 'wpm-testimonial' );
133 $status = 'pending';
134 foreach ( $types as $type ) {
135 $num_posts = wp_count_posts( $type, 'readable' );
136 $pending_count = 0;
137 if ( ! empty( $num_posts->$status ) ) {
138 $pending_count = $num_posts->$status;
139 }
140
141 if ( $type == 'post' ) {
142 $menu_str = 'edit.php';
143 } else {
144 $menu_str = 'edit.php?post_type=' . $type;
145 }
146
147 foreach ( $menu as $menu_key => $menu_data ) {
148 if ( $menu_str != $menu_data[2] ) {
149 continue;
150 }
151 $menu[ $menu_key ][0] .= " <span class='update-plugins count-$pending_count'><span class='plugin-count'>" . number_format_i18n( $pending_count ) . '</span></span>';
152 }
153 }
154
155 return $menu;
156 }
157 add_filter( 'add_menu_classes', 'wpmtst_pending_indicator' );
158
159 /**
160 * The [restore default] icon.
161 *
162 * @param $for
163 *
164 * @since 2.18.0
165 */
166 function wpmtst_restore_default_icon( $for ) {
167 if ( ! $for ) {
168 return;
169 }
170 ?>
171 <input type="button" class="button secondary restore-default" title="<?php esc_attr_e( 'restore default', 'strong-testimonials' ); ?>" value="&#xf171" data-for="<?php echo esc_attr( $for ); ?>"/>
172 <?php
173 }
174
175
176
177 /**
178 * Check for configuration issues when options are updated.
179 *
180 * @since 2.24.0
181 * @param $option
182 * @param $old_value
183 * @param $value
184 */
185 function wpmtst_updated_option( $option, $old_value, $value ) {
186 if ( 'wpmtst_' == substr( $option, 0, 7 ) ) {
187 do_action( 'wpmtst_check_config' );
188 }
189 }
190 add_action( 'updated_option', 'wpmtst_updated_option', 10, 3 );
191
192
193 /**
194 * Store configuration error.
195 *
196 * @since 2.24.0
197 * @param $key
198 */
199 function wpmtst_add_config_error( $key ) {
200 $errors = get_option( 'wpmtst_config_errors', array() );
201 $errors[] = $key;
202 update_option( 'wpmtst_config_errors', array_unique( $errors ) );
203
204 wpmtst_add_admin_notice( $key, true );
205 }
206
207
208 /**
209 * Delete configuration error.
210 *
211 * @since 2.24.0
212 * @param $key
213 */
214 function wpmtst_delete_config_error( $key ) {
215 $errors = get_option( 'wpmtst_config_errors', array() );
216 $errors = array_diff( $errors, array( $key ) );
217 update_option( 'wpmtst_config_errors', $errors );
218
219 wpmtst_delete_admin_notice( $key );
220 }
221
222
223 /**
224 * Save a View.
225 *
226 * @param $view
227 * @param string $action
228 * @usedby Strong_Testimonials_Update:update_views
229 *
230 * @return bool|false|int
231 */
232 function wpmtst_save_view( $view, $action = 'edit' ) {
233 global $wpdb;
234
235 if ( ! $view ) {
236 return false;
237 }
238
239 $table_name = $wpdb->prefix . 'strong_views';
240 $serialized = serialize( $view['data'] );
241
242 if ( 'add' == $action || 'duplicate' == $action ) {
243 $sql = "INSERT INTO {$table_name} (name, value) VALUES (%s, %s)";
244 $sql = $wpdb->prepare( $sql, $view['name'], $serialized );
245 $wpdb->query( $sql );
246 $view['id'] = $wpdb->insert_id;
247 $return = $view['id'];
248 } else {
249 $sql = "UPDATE {$table_name} SET name = %s, value = %s WHERE id = %d";
250 $sql = $wpdb->prepare( $sql, $view['name'], $serialized, intval( $view['id'] ) );
251 $wpdb->query( $sql );
252 $return = $wpdb->last_error ? 0 : 1;
253 }
254
255 do_action( 'wpmtst_view_saved', $view );
256
257 return $return;
258 }
259
260
261 /**
262 * @param $field
263 *
264 * @return mixed
265 */
266 function wpmtst_get_field_label( $field ) {
267 if ( isset( $field['field'] ) ) {
268 $custom_fields = wpmtst_get_custom_fields();
269 if ( isset( $custom_fields[ $field['field'] ]['label'] ) ) {
270 return $custom_fields[ $field['field'] ]['label'];
271 }
272 $builtin_fields = wpmtst_get_builtin_fields();
273 if ( isset( $builtin_fields[ $field['field'] ]['label'] ) ) {
274 return $builtin_fields[ $field['field'] ]['label'];
275 }
276 }
277
278 return '';
279 }
280
281
282 /**
283 * @param string $field_name
284 *
285 * @return mixed
286 */
287 function wpmtst_get_field_by_name( $field_name = '' ) {
288 if ( $field_name ) {
289 $custom_fields = wpmtst_get_custom_fields();
290 if ( isset( $custom_fields[ $field_name ] ) ) {
291 return $custom_fields[ $field_name ];
292 }
293 }
294
295 return '';
296 }
297
298