PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.2.3
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.2.3
1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.23 All 172 releases
userswp / admin / class-admin.php

class-admin.php in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP 1.2.2.3, at admin/class-admin.php

371 lines 13.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The admin-specific functionality of the plugin.
4 *
5 * @link http://wpgeodirectory.com
6 * @since 1.0.0
7 *
8 * @package userswp
9 * @subpackage userswp/admin
10 */
11
12 /**
13 * The admin-specific functionality of the plugin.
14 *
15 * Defines the plugin name, version, and two examples hooks for how to
16 * enqueue the admin-specific stylesheet and JavaScript.
17 *
18 * @package userswp
19 * @subpackage userswp/admin
20 * @author GeoDirectory Team <info@wpgeodirectory.com>
21 */
22 class UsersWP_Admin {
23
24 /**
25 * Register all of the hooks related to the admin area functionality
26 * of the plugin.
27 *
28 * @since 1.0.0
29 */
30 public function __construct() {
31 add_action( 'admin_init', array( $this, 'preview_emails' ) );
32 add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) );
33 }
34
35 /**
36 * Maybe show the AyeCode Connect Notice.
37 */
38 public function init_ayecode_connect_helper(){
39 // AyeCode Connect notice
40 if ( is_admin() ){
41 // set the strings so they can be translated
42 $strings = array(
43 'connect_title' => __("UsersWP - an AyeCode product!","userswp"),
44 'connect_external' => __( "Please confirm you wish to connect your site?","userswp" ),
45 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","userswp" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
46 'connect_button' => __("Connect Site","userswp"),
47 'connecting_button' => __("Connecting...","userswp"),
48 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","userswp" ),
49 'error' => __( "Something went wrong, please refresh and try again.","userswp" ),
50 );
51 new AyeCode_Connect_Helper($strings,array('uwp-addons'));
52 }
53 }
54
55
56 /**
57 * Register the stylesheets for the admin area.
58 *
59 * @since 1.0.0
60 * @param $hook_suffix
61 */
62 public function enqueue_styles( $hook_suffix ) {
63
64 if ( $hook_suffix == 'profile.php' || $hook_suffix == 'user-edit.php' ) {
65 wp_register_style( 'jquery-ui', USERSWP_PLUGIN_URL . 'assets/css/jquery-ui.css' );
66 wp_enqueue_style( 'jquery-ui' );
67 wp_enqueue_style( 'jcrop' );
68 wp_enqueue_style( "userswp", USERSWP_PLUGIN_URL . 'assets/css/users-wp.css', array(), USERSWP_VERSION, 'all' );
69 wp_enqueue_style( "uwp_timepicker_css", USERSWP_PLUGIN_URL . 'assets/css/jquery.ui.timepicker.css', array(), USERSWP_VERSION, 'all' );
70 }
71 if ( $hook_suffix == 'userswp_page_uwp_tools' ) {
72 wp_enqueue_style( "userswp", USERSWP_PLUGIN_URL . 'assets/css/users-wp.css', array(), USERSWP_VERSION, 'all' );
73 }
74 wp_enqueue_style( "userswp_admin_css", USERSWP_PLUGIN_URL . 'admin/assets/css/users-wp-admin.css', array(), USERSWP_VERSION, 'all' );
75
76 if ( $hook_suffix == 'toplevel_page_userswp' ) {
77 wp_enqueue_style( 'wp-color-picker' );
78 }
79
80 }
81
82 /**
83 * Register the JavaScript for the admin area.
84 *
85 * @since 1.0.0
86 * @param $hook_suffix
87 */
88 public function enqueue_scripts($hook_suffix) {
89
90 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
91
92 if ( $hook_suffix == 'profile.php' || $hook_suffix == 'user-edit.php' ) {
93
94 wp_enqueue_script( 'jquery-ui-datepicker', array( 'jquery' ) );
95 wp_enqueue_script( "uwp_timepicker", USERSWP_PLUGIN_URL . 'assets/js/jquery.ui.timepicker.min.js', array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-core' ), USERSWP_VERSION );
96 wp_enqueue_script( "userswp", USERSWP_PLUGIN_URL . 'assets/js/users-wp' . $suffix . '.js', array( 'jquery' ), USERSWP_VERSION, false );
97 $uwp_localize_data = uwp_get_localize_data();
98 wp_localize_script('userswp', 'uwp_localize_data', $uwp_localize_data );
99 wp_enqueue_script( 'jquery-ui-progressbar', array( 'jquery' ) );
100 wp_enqueue_script( 'jcrop', array( 'jquery' ) );
101 wp_enqueue_script( "country-select", USERSWP_PLUGIN_URL . 'assets/js/countrySelect' . $suffix . '.js', array( 'jquery' ), USERSWP_VERSION );
102
103
104 }
105 if ( $hook_suffix == 'userswp_page_uwp_status' ) {
106 wp_enqueue_script( 'jquery-ui-progressbar', array( 'jquery' ) );
107 wp_enqueue_script( "uwp_status", USERSWP_PLUGIN_URL . 'admin/assets/js/system-status.js', array( 'jquery' ), USERSWP_VERSION, true );
108 }
109
110 wp_enqueue_script( 'jquery-ui-sortable' );
111 wp_enqueue_script( 'uwp-nestable-script', USERSWP_PLUGIN_URL . 'admin/assets/js/jquery.nestable' . $suffix . '.js', array('jquery-ui-sortable'), USERSWP_VERSION );
112
113 wp_enqueue_script( "userswp_admin", USERSWP_PLUGIN_URL . 'admin/assets/js/users-wp-admin' . $suffix . '.js', array( 'jquery' ), USERSWP_VERSION, false );
114
115 wp_enqueue_script( "jquery-ui-tooltip" );
116 wp_enqueue_script( 'wp-color-picker' );
117
118 $ajax_cons_data = array(
119 'url' => admin_url( 'admin-ajax.php' ),
120 'custom_field_not_blank_var' => __( 'Field key must not be blank', 'userswp' ),
121 'custom_field_options_not_blank_var' => __( 'Option Values must not be blank', 'userswp' ),
122 'custom_field_not_special_char' => __( 'Please do not use special character and spaces in field key.', 'userswp' ),
123 'custom_field_unique_name' => __( 'Field key should be a unique name.', 'userswp' ),
124 'custom_field_delete' => __( 'Are you sure you wish to delete this field?', 'userswp' ),
125 'custom_field_id_required' => __( 'This field is required.', 'userswp' ),
126 'img_spacer' => admin_url( 'images/media-button-image.gif' ),
127 'txt_choose_image' => __( 'Choose an image', 'userswp' ),
128 'txt_use_image' => __( 'Use image', 'userswp' ),
129 );
130 wp_localize_script( "userswp_admin", 'uwp_admin_ajax', $ajax_cons_data );
131
132 $country_data = uwp_get_country_data();
133 wp_localize_script( USERSWP_NAME, 'uwp_country_data', $country_data );
134
135 }
136
137 /**
138 * Adds UsersWP css to admin area
139 *
140 * @since 1.0.0
141 * @package userswp
142 *
143 * @return void
144 */
145 public function admin_only_css() {
146 ?>
147 <style type="text/css">
148 .uwp_page .uwp-bs-modal input[type="submit"].button,
149 .uwp_page .uwp-bs-modal button.button {
150 padding: 0 10px 1px;
151 }
152 </style>
153 <?php
154 }
155
156 /**
157 * Adds UsersWP JS to admin area.
158 *
159 * @since 1.0.0
160 * @package userswp
161 *
162 * @return void
163 */
164 public function admin_only_script() {
165
166 // check page is userswp or not.
167 if( !empty( $_GET['page'] ) && 'userswp' == $_GET['page'] ) {
168
169 // check tab is general or not.
170 if( !empty( $_GET['tab'] ) && 'general' == $_GET['tab'] ) {
171
172 // check for login section.
173 if( !empty( $_GET['section'] ) && 'login' == $_GET['section'] ) {
174 ?>
175 <script type="text/javascript">
176 jQuery( document ).ready(function() {
177 var login_redirect_to = jQuery('#login_redirect_to');
178 login_redirect_to.on( 'change', function() {
179 var value = jQuery( this ).val();
180 var login_redirect_custom_obj = jQuery('#login_redirect_custom_url');
181
182 if( '-2' === value ) {
183 login_redirect_custom_obj.parent().parent().show();
184 } else{
185 login_redirect_custom_obj.parent().parent().hide();
186 }
187 } ).change();
188 });
189 </script>
190 <?php
191 }
192
193 // check for registration section.
194 if( !empty( $_GET['section'] ) && 'register' == $_GET['section'] ) {
195 ?>
196 <script type="text/javascript">
197 jQuery( document ).ready(function() {
198 var register_redirect_to = jQuery('#register_redirect_to');
199 register_redirect_to.on( 'change', function() {
200 var value = jQuery( this ).val();
201 var register_redirect_custom_obj = jQuery('#register_redirect_custom_url');
202
203 if( '-2' === value ) {
204 register_redirect_custom_obj.parent().parent().show();
205 } else{
206 register_redirect_custom_obj.parent().parent().hide();
207 }
208 } ).change();
209 });
210 </script>
211 <?php
212 }
213 }
214
215 }
216
217 }
218
219 /**
220 * Filters the user profile picture description displayed under the Gravatar.
221 *
222 * @since 1.0.0
223 * @package userswp
224 *
225 * @param string $description Profile picture description.
226 *
227 * @return string Modified description.
228 */
229 public function user_profile_picture_description($description) {
230 if (is_admin() && IS_PROFILE_PAGE) {
231 $user_id = get_current_user_id();
232 $avatar = uwp_get_usermeta($user_id, 'avatar_thumb', '');
233
234 if (!empty($avatar)) {
235 $description = sprintf( __( 'You can change your profile picture on your <a href="%s">Profile Page</a>.', 'userswp' ),
236 uwp_build_profile_tab_url( $user_id ));
237 }
238
239 }
240 return $description;
241 }
242
243 /**
244 * Adds avatar and banner fields in admin side.
245 *
246 * @since 1.0.0
247 * @package userswp
248 *
249 * @param object $user User object.
250 *
251 * @return void
252 */
253 public function edit_profile_banner_fields($user) {
254 global $wpdb;
255
256 $file_obj = new UsersWP_Files();
257
258 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
259 $fields = $wpdb->get_results("SELECT * FROM " . $table_name . " WHERE (form_type = 'avatar' OR form_type = 'banner') ORDER BY sort_order ASC");
260 if ($fields) {
261 ?>
262 <div class="uwp-profile-extra uwp_page">
263 <?php do_action('uwp_admin_profile_edit', $user ); ?>
264 <table class="uwp-profile-extra-table form-table">
265 <?php
266 foreach ($fields as $field) {
267
268 // Icon
269 $icon = uwp_get_field_icon( $field->field_icon );
270
271 if ($field->field_type == 'fieldset') {
272 ?>
273 <tr style="margin: 0; padding: 0">
274 <th class="uwp-profile-extra-key" style="margin: 0; padding: 0"><h3 style="margin: 10px 0;">
275 <?php echo $icon.$field->site_title; ?></h3></th>
276 <td></td>
277 </tr>
278 <?php
279 } else { ?>
280 <tr>
281 <th class="uwp-profile-extra-key"><?php echo $icon.$field->site_title; ?></th>
282 <td class="uwp-profile-extra-value">
283 <?php
284 if ( $field->htmlvar_name == "avatar" ) {
285 $value = uwp_get_usermeta( $user->ID, "avatar_thumb", "" );
286 } elseif ( $field->htmlvar_name == "banner" ) {
287 $value = uwp_get_usermeta( $user->ID, "banner_thumb", "" );
288 } else {
289 $value = "";
290 }
291
292 echo $file_obj->file_upload_preview( $field, $value );
293
294 if ( $field->htmlvar_name == "avatar" ) {
295 if ( ! empty( $value ) ) {
296 $label = __( "Change Avatar", "userswp" );
297 } else {
298 $label = __( "Upload Avatar", "userswp" );
299 }
300 ?>
301 <a onclick="uwp_profile_image_change('avatar');return false;" href="#"
302 class="uwp-banner-change-icon-admin">
303 <?php echo $label; ?>
304 </a>
305 <?php
306 } elseif ( $field->htmlvar_name == "banner" ) {
307 if ( ! empty( $value ) ) {
308 $label = __( "Change Banner", "userswp" );
309 } else {
310 $label = __( "Upload Banner", "userswp" );
311 } ?>
312 <a onclick="uwp_profile_image_change('banner');return false;" href="#"
313 class="uwp-banner-change-icon-admin">
314 <?php echo $label; ?>
315 </a>
316 <?php
317 }
318 ?>
319 </td>
320 </tr>
321 <?php
322 }
323 }
324 ?>
325 </table>
326 </div>
327 <?php
328 }
329 }
330
331 public function admin_body_class($classes) {
332 $screen = get_current_screen();
333 if ( 'profile' == $screen->base || 'user-edit' == $screen->base )
334 $classes .= 'uwp_page';
335 return $classes;
336 }
337
338 /**
339 * Preview email template for UWP emails.
340 */
341 public function preview_emails() {
342 if ( isset( $_GET['uwp_preview_mail'] ) ) {
343 if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'uwp-preview-mail' ) ) {
344 die( 'Security check failed.' );
345 }
346
347 $email_name = 'preview_mail';
348 $email_vars = array();
349 $plain_text = UsersWP_Mails::get_email_type() != 'html' ? true : false;
350
351 // Get the preview email content.
352 ob_start();
353 include( 'views/html-email-template-preview.php' );
354 $message = ob_get_clean();
355
356 $message = UsersWP_Mails::email_wrap_message( $message, $email_name, $email_vars, '', $plain_text );
357 $message = UsersWP_Mails::style_body( $message, $email_name, $email_vars );
358 $message = apply_filters( 'uwp_mail_content', $message, $email_name, $email_vars );
359
360 // Print the preview email content.
361 if ( $plain_text ) {
362 echo '<div style="white-space:pre-wrap;font-family:sans-serif">';
363 }
364 echo $message;
365 if ( $plain_text ) {
366 echo '</div>';
367 }
368 exit;
369 }
370 }
371 }