| @@ -20,217 +20,1009 @@ | ||
| 20 | 20 | * @author GeoDirectory Team <info@wpgeodirectory.com> |
| 21 | 21 | */ |
| 22 | 22 | class UsersWP_Admin { |
| 23 | 23 | |
| 24 | - protected $admin_settings; | |
| 25 | - /** | |
| 26 | - * Register all of the hooks related to the admin area functionality | |
| 27 | - * of the plugin. | |
| 28 | - * | |
| 29 | - * @since 1.0.0 | |
| 30 | - */ | |
| 31 | - public function __construct($admin_settings) { | |
| 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, 'activation_redirect' ) ); | |
| 32 | + add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); | |
| 33 | + add_action( 'admin_init', array( $this, 'prevent_admin_access' ) ); | |
| 34 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) ); | |
| 35 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); | |
| 36 | + add_action( 'admin_notices', array( $this, 'show_update_messages' ) ); | |
| 37 | + add_action( 'admin_footer', array( $this, 'admin_only_script' ) ); | |
| 38 | + add_action( 'user_profile_picture_description', array( $this, 'user_profile_picture_description' ) ); | |
| 39 | + add_action( 'admin_body_class', array( $this, 'admin_body_class' ) ); | |
| 40 | + add_action( 'admin_init', array( $this, 'preview_emails' ) ); | |
| 32 | 41 | |
| 33 | - $this->admin_settings = $admin_settings; | |
| 34 | - } | |
| 42 | + add_filter( 'views_users', array( $this, 'request_views_users' ) ); | |
| 43 | + add_filter( 'pre_user_query', array( $this, 'request_users_filter' ) ); | |
| 44 | + add_action( 'edit_user_profile', array( $this, 'get_profile_extra_edit' ), 10, 1 ); | |
| 45 | + add_action( 'show_user_profile', array( $this, 'get_profile_extra_edit' ), 10, 1 ); | |
| 46 | + add_filter( 'user_row_actions', array( $this, 'user_row_actions' ), 10, 2 ); | |
| 47 | + add_action( 'bulk_actions-users', array( $this, 'users_bulk_actions' ) ); | |
| 48 | + add_action( 'handle_bulk_actions-users', array( $this, 'handle_users_bulk_actions' ), 10, 3 ); | |
| 49 | + add_filter( 'init', array( $this, 'process_user_actions' ) ); | |
| 50 | + add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 ); | |
| 51 | + add_filter( 'aui_screen_ids', array( $this, 'add_aui_screens' ), 20, 1 ); | |
| 35 | 52 | |
| 53 | + add_action( 'wp_ajax_uwp_ajax_create_register', array( $this, 'process_create_register_form' ) ); | |
| 54 | + add_action( 'wp_ajax_uwp_ajax_update_register', array( $this, 'process_update_register_form' ) ); | |
| 55 | + add_action( 'wp_ajax_uwp_ajax_remove_register', array( $this, 'process_remove_register_form' ) ); | |
| 36 | 56 | |
| 37 | - /** | |
| 38 | - * Register the stylesheets for the admin area. | |
| 39 | - * | |
| 40 | - * @since 1.0.0 | |
| 41 | - * @param $hook_suffix | |
| 42 | - */ | |
| 43 | - public function enqueue_styles($hook_suffix) { | |
| 57 | + // Register with the deactivation survey class. | |
| 58 | + if(class_exists('AyeCode_Deactivation_Survey')){ | |
| 59 | + AyeCode_Deactivation_Survey::instance(array( | |
| 60 | + 'slug' => 'userswp', | |
| 61 | + 'version' => USERSWP_VERSION, | |
| 62 | + 'support_url'=> 'https://userswp.io/support/', | |
| 63 | + 'documentation_url'=> 'https://docs.userswp.io/', | |
| 64 | + 'activated' => get_option('uwp_installed_on', 0) | |
| 65 | + )); | |
| 66 | + } | |
| 67 | + } | |
| 44 | 68 | |
| 45 | - /** | |
| 46 | - * An instance of this class should be passed to the run() function | |
| 47 | - * defined in UsersWP_Loader as all of the hooks are defined | |
| 48 | - * in that particular class. | |
| 49 | - * | |
| 50 | - * The UsersWP_Loader will then create the relationship | |
| 51 | - * between the defined hooks and the functions defined in this | |
| 52 | - * class. | |
| 53 | - */ | |
| 54 | - if ($hook_suffix == 'profile.php' || $hook_suffix == 'user-edit.php') { | |
| 55 | - wp_register_style('jquery-ui', plugin_dir_url(dirname(__FILE__)) . 'public/assets/css/jquery-ui.css'); | |
| 56 | - wp_enqueue_style( 'jquery-ui' ); | |
| 57 | - wp_enqueue_style( 'jcrop' ); | |
| 58 | - wp_enqueue_style( "userswp", plugin_dir_url(dirname(__FILE__)) . 'public/assets/css/users-wp.css', array(), null, 'all' ); | |
| 59 | - wp_enqueue_style( "uwp_timepicker_css", plugin_dir_url( dirname(__FILE__) ) . 'public/assets/css/jquery.ui.timepicker.css', array(), null, 'all' ); | |
| 60 | - } | |
| 61 | - if ($hook_suffix == 'userswp_page_uwp_tools') { | |
| 62 | - wp_enqueue_style( "userswp", plugin_dir_url(dirname(__FILE__)) . 'public/assets/css/users-wp.css', array(), null, 'all' ); | |
| 63 | - } | |
| 64 | - wp_enqueue_style( "userswp_admin_css", plugin_dir_url( __FILE__ ) . 'assets/css/users-wp-admin.css', array(), USERSWP_VERSION, 'all' ); | |
| 65 | - wp_enqueue_style( "uwp_chosen_css", plugin_dir_url(dirname(__FILE__)) . 'public/assets/css/chosen.css', array(), USERSWP_VERSION, 'all' ); | |
| 69 | + /** | |
| 70 | + * Redirects to UsersWP info page after plugin activation. | |
| 71 | + * | |
| 72 | + * @return void | |
| 73 | + * @package userswp | |
| 74 | + * @since 1.0.0 | |
| 75 | + */ | |
| 76 | + public function activation_redirect() { | |
| 66 | 77 | |
| 67 | - } | |
| 78 | + if ( get_option( 'uwp_activation_redirect', false ) ) { | |
| 79 | + delete_option( 'uwp_activation_redirect' ); | |
| 80 | + update_option( "uwp_setup_wizard_notice", 1 ); | |
| 81 | + wp_redirect( admin_url( 'index.php?page=uwp-setup' ) ); | |
| 82 | + exit; | |
| 83 | + } | |
| 68 | 84 | |
| 69 | - /** | |
| 70 | - * Register the JavaScript for the admin area. | |
| 71 | - * | |
| 72 | - * @since 1.0.0 | |
| 73 | - * @param $hook_suffix | |
| 74 | - */ | |
| 75 | - public function enqueue_scripts($hook_suffix) { | |
| 85 | + if ( ! empty( $_GET['force_sync_data'] ) ) { | |
| 86 | + $blog_id = get_current_blog_id(); | |
| 87 | + do_action( 'wp_' . $blog_id . '_uwp_updater_cron' ); | |
| 88 | + wp_safe_redirect( admin_url( 'admin.php?page=userswp' ) ); | |
| 89 | + exit; | |
| 90 | + } | |
| 76 | 91 | |
| 77 | - /** | |
| 78 | - * An instance of this class should be passed to the run() function | |
| 79 | - * defined in UsersWP_Loader as all of the hooks are defined | |
| 80 | - * in that particular class. | |
| 81 | - * | |
| 82 | - * The UsersWP_Loader will then create the relationship | |
| 83 | - * between the defined hooks and the functions defined in this | |
| 84 | - * class. | |
| 85 | - */ | |
| 92 | + } | |
| 86 | 93 | |
| 87 | - if ($hook_suffix == 'profile.php' || $hook_suffix == 'user-edit.php') { | |
| 94 | + /** | |
| 95 | + * Maybe show the AyeCode Connect Notice. | |
| 96 | + */ | |
| 97 | + public function init_ayecode_connect_helper() { | |
| 98 | + // AyeCode Connect notice | |
| 99 | + if ( is_admin() ) { | |
| 100 | + // set the strings so they can be translated | |
| 101 | + $strings = array( | |
| 102 | + 'connect_title' => __( "UsersWP - an AyeCode product!", "userswp" ), | |
| 103 | + 'connect_external' => __( "Please confirm you wish to connect your site?", "userswp" ), | |
| 104 | + '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>" ), | |
| 105 | + 'connect_button' => __( "Connect Site", "userswp" ), | |
| 106 | + 'connecting_button' => __( "Connecting...", "userswp" ), | |
| 107 | + 'error_localhost' => __( "This service will only work with a live domain, not a localhost.", "userswp" ), | |
| 108 | + 'error' => __( "Something went wrong, please refresh and try again.", "userswp" ), | |
| 109 | + ); | |
| 110 | + new AyeCode_Connect_Helper( $strings, array( 'uwp-addons' ) ); | |
| 111 | + } | |
| 112 | + } | |
| 88 | 113 | |
| 89 | - wp_enqueue_script( 'jquery-ui-datepicker', array( 'jquery' ) ); | |
| 90 | - wp_enqueue_script( "uwp_timepicker", plugin_dir_url( dirname(__FILE__) ) . 'public/assets/js/jquery.ui.timepicker.min.js', array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-core' ), null, false ); | |
| 91 | - wp_enqueue_script( "userswp", plugin_dir_url(dirname(__FILE__)) . 'public/assets/js/users-wp.min.js', array( 'jquery' ), null, false ); | |
| 92 | - $uwp_localize_data = uwp_get_localize_data(); | |
| 93 | - wp_localize_script('userswp', 'uwp_localize_data', $uwp_localize_data); | |
| 94 | - wp_enqueue_script( 'jquery-ui-progressbar', array( 'jquery' ) ); | |
| 95 | - wp_enqueue_script( 'jcrop', array( 'jquery' ) ); | |
| 96 | - wp_enqueue_script( "country-select", plugin_dir_url(dirname(__FILE__)) . 'public/assets/js/countrySelect.min.js', array( 'jquery' ), null, false ); | |
| 114 | + /** | |
| 115 | + * Restrict the wp-admin area from specific user roles if set to do so. | |
| 116 | + */ | |
| 117 | + public function prevent_admin_access() { | |
| 118 | + $restricted_roles = (array) uwp_get_option( 'admin_blocked_roles', array() ); | |
| 97 | 119 | |
| 120 | + // Checking action in request to allow ajax request go through | |
| 121 | + if ( ! empty ( $restricted_roles ) && is_user_logged_in() && ! wp_doing_ajax() && ! wp_doing_cron() ) { | |
| 122 | + $roles = wp_get_current_user()->roles; | |
| 98 | 123 | |
| 99 | - } | |
| 100 | - if ($hook_suffix == 'userswp_page_uwp_tools') { | |
| 101 | - wp_enqueue_script( 'jquery-ui-progressbar', array( 'jquery' ) ); | |
| 102 | - } | |
| 103 | - wp_enqueue_script('jquery-ui-sortable'); | |
| 104 | - wp_enqueue_script( "userswp_admin", plugin_dir_url( __FILE__ ) . 'assets/js/users-wp-admin.min.js', array( 'jquery' ), null, false ); | |
| 105 | - wp_enqueue_script( "uwp_chosen", plugin_dir_url(dirname(__FILE__)) . 'public/assets/js/chosen.jquery.js', array( 'jquery' ), USERSWP_VERSION, false ); | |
| 106 | - wp_enqueue_script( "uwp_chosen_order", plugin_dir_url( __FILE__ ) . 'assets/js/chosen.order.jquery.min.js', array( 'jquery' ), USERSWP_VERSION, false ); | |
| 124 | + $prevent = false; | |
| 107 | 125 | |
| 108 | - if ($hook_suffix == 'userswp_page_uwp_status') { | |
| 109 | - wp_enqueue_script( "uwp_status", USERSWP_PLUGIN_URL . '/admin/assets/js/system-status.js', array( 'jquery' ), USERSWP_VERSION, true ); | |
| 110 | - } | |
| 126 | + // Always allow administrator role. | |
| 127 | + if ( ! ( ! empty( $roles ) && in_array( 'administrator', $roles ) ) ) { | |
| 128 | + foreach( $restricted_roles as $role ) { | |
| 129 | + if ( in_array( $role, $roles ) ) { | |
| 130 | + $prevent = true; | |
| 131 | + break; | |
| 132 | + } | |
| 133 | + } | |
| 134 | + } | |
| 111 | 135 | |
| 112 | - $ajax_cons_data = array( | |
| 113 | - 'url' => admin_url('admin-ajax.php'), | |
| 114 | - 'custom_field_not_blank_var' => __('HTML Variable Name must not be blank', 'userswp'), | |
| 115 | - 'custom_field_options_not_blank_var' => __('Option Values must not be blank', 'userswp'), | |
| 116 | - 'custom_field_not_special_char' => __('Please do not use special character and spaces in HTML Variable Name.', 'userswp'), | |
| 117 | - 'custom_field_unique_name' => __('HTML Variable Name should be a unique name.', 'userswp'), | |
| 118 | - 'custom_field_delete' => __('Are you sure you wish to delete this field?', 'userswp'), | |
| 119 | - 'custom_field_id_required' => __('This field is required.', 'userswp'), | |
| 120 | - ); | |
| 121 | - wp_localize_script("userswp_admin", 'uwp_admin_ajax', $ajax_cons_data); | |
| 136 | + /* | |
| 137 | + * Check and prevent admin access based on user role. | |
| 138 | + * | |
| 139 | + * @param bool $prevent True to prevent admin access. | |
| 140 | + */ | |
| 141 | + $prevent = apply_filters( 'uwp_prevent_wp_admin_access', $prevent ); | |
| 122 | 142 | |
| 123 | - $country_data = uwp_get_country_data(); | |
| 124 | - wp_localize_script(USERSWP_NAME, 'uwp_country_data', $country_data); | |
| 143 | + if ( $prevent ) { | |
| 144 | + wp_safe_redirect( home_url() ); | |
| 145 | + exit; | |
| 146 | + } | |
| 147 | + } | |
| 148 | + } | |
| 125 | 149 | |
| 126 | - } | |
| 150 | + /** | |
| 151 | + * Register the stylesheets for the admin area. | |
| 152 | + * | |
| 153 | + * @param $hook_suffix | |
| 154 | + * | |
| 155 | + * @since 1.0.0 | |
| 156 | + */ | |
| 157 | + public function enqueue_styles( $hook_suffix ) { | |
| 158 | + $screen = get_current_screen(); | |
| 159 | + $screen_id = $screen ? $screen->id : ''; | |
| 127 | 160 | |
| 128 | - public function setup_admin_menus() { | |
| 161 | + if ( $hook_suffix == 'profile.php' || $hook_suffix == 'user-edit.php' ) { | |
| 162 | + wp_register_style( 'jquery-ui', USERSWP_PLUGIN_URL . 'assets/css/jquery-ui.css' ); | |
| 163 | + wp_enqueue_style( 'jquery-ui' ); | |
| 164 | + wp_enqueue_style( 'jcrop' ); | |
| 165 | + wp_enqueue_style( "uwp-country-select", USERSWP_PLUGIN_URL . 'assets/css/countryselect.css', array(), USERSWP_VERSION, 'all' ); | |
| 166 | + wp_enqueue_style( "userswp", USERSWP_PLUGIN_URL . 'assets/css/users-wp.css', array(), USERSWP_VERSION, 'all' ); | |
| 167 | + wp_enqueue_style( "uwp_timepicker_css", USERSWP_PLUGIN_URL . 'assets/css/jquery.ui.timepicker.css', array(), USERSWP_VERSION, 'all' ); | |
| 168 | + } | |
| 129 | 169 | |
| 130 | - $install_type = uwp_get_installation_type(); | |
| 170 | + if ( false !== strpos($hook_suffix, 'page_uwp_tools' )) { | |
| 171 | + wp_enqueue_style( "userswp", USERSWP_PLUGIN_URL . 'assets/css/users-wp.css', array(), USERSWP_VERSION, 'all' ); | |
| 172 | + } | |
| 131 | 173 | |
| 132 | - // Proceed if main site or pages on all sites or specific blog id | |
| 133 | - $proceed = false; | |
| 134 | - $show_builder = false; | |
| 135 | - switch ($install_type) { | |
| 136 | - case "single": | |
| 137 | - $proceed = true; | |
| 138 | - $show_builder = true; | |
| 139 | - break; | |
| 140 | - case "multi_na_all": | |
| 141 | - $proceed = true; | |
| 142 | - $show_builder = true; | |
| 143 | - break; | |
| 144 | - case "multi_na_site_id": | |
| 145 | - if (defined('UWP_ROOT_PAGES')) { | |
| 146 | - $blog_id = UWP_ROOT_PAGES; | |
| 147 | - } else { | |
| 148 | - $blog_id = null; | |
| 174 | + if ( false !== strpos($hook_suffix, 'page_uwp_form_builder' )) { | |
| 175 | + wp_enqueue_style( "uwp_form_builder", USERSWP_PLUGIN_URL . 'admin/assets/css/uwp-form-builder.css', array(), USERSWP_VERSION, 'all' ); | |
| 176 | + } | |
| 177 | + | |
| 178 | + if ( $hook_suffix == 'toplevel_page_userswp' ) { | |
| 179 | + wp_enqueue_style( 'wp-color-picker' ); | |
| 180 | + } | |
| 181 | + | |
| 182 | + if ( in_array( $screen_id, uwp_get_screen_ids() ) ) { | |
| 183 | + wp_enqueue_style( "userswp_admin_css", USERSWP_PLUGIN_URL . 'admin/assets/css/users-wp-admin.css', array(), USERSWP_VERSION, 'all' ); | |
| 184 | + } | |
| 185 | + | |
| 186 | + } | |
| 187 | + | |
| 188 | + /** | |
| 189 | + * Register the JavaScript for the admin area. | |
| 190 | + * | |
| 191 | + * @param $hook_suffix | |
| 192 | + * | |
| 193 | + * @since 1.0.0 | |
| 194 | + */ | |
| 195 | + public function enqueue_scripts( $hook_suffix ) { | |
| 196 | + | |
| 197 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; | |
| 198 | + $screen = get_current_screen(); | |
| 199 | + $screen_id = $screen ? $screen->id : ''; | |
| 200 | + | |
| 201 | + if ( $hook_suffix == 'profile.php' || $hook_suffix == 'user-edit.php' ) { | |
| 202 | + | |
| 203 | + wp_enqueue_script( 'jquery-ui-datepicker', array( 'jquery' ) ); | |
| 204 | + wp_enqueue_script( "uwp_timepicker", USERSWP_PLUGIN_URL . 'assets/js/jquery.ui.timepicker.min.js', array( | |
| 205 | + 'jquery', | |
| 206 | + 'jquery-ui-datepicker', | |
| 207 | + 'jquery-ui-core' | |
| 208 | + ), USERSWP_VERSION ); | |
| 209 | + wp_enqueue_script( "userswp", USERSWP_PLUGIN_URL . 'assets/js/users-wp' . $suffix . '.js', array( 'jquery' ), USERSWP_VERSION, false ); | |
| 210 | + $uwp_localize_data = uwp_get_localize_data(); | |
| 211 | + wp_localize_script( 'userswp', 'uwp_localize_data', $uwp_localize_data ); | |
| 212 | + wp_enqueue_script( 'jquery-ui-progressbar', array( 'jquery' ) ); | |
| 213 | + wp_enqueue_script( 'jcrop', array( 'jquery' ) ); | |
| 214 | + wp_enqueue_script( "country-select", USERSWP_PLUGIN_URL . 'assets/js/countrySelect' . $suffix . '.js', array( 'jquery' ), USERSWP_VERSION ); | |
| 215 | + | |
| 216 | + $country_data = uwp_get_country_data(); | |
| 217 | + wp_localize_script( USERSWP_NAME, 'uwp_country_data', $country_data ); | |
| 218 | + } | |
| 219 | + | |
| 220 | + if ( false !== strpos($hook_suffix, 'page_uwp_tools' )) { | |
| 221 | + wp_enqueue_script( 'jquery-ui-progressbar', array( 'jquery' ) ); | |
| 222 | + } | |
| 223 | + | |
| 224 | + if ( false !== strpos($hook_suffix, 'page_uwp_status' )) { | |
| 225 | + wp_enqueue_script( "uwp_status", USERSWP_PLUGIN_URL . 'admin/assets/js/system-status.js', array( 'jquery' ), USERSWP_VERSION, true ); | |
| 226 | + } | |
| 227 | + | |
| 228 | + if ( false !== strpos($hook_suffix, 'page_uwp_form_builder' )) { | |
| 229 | + wp_enqueue_script( 'jquery-ui-sortable' ); | |
| 230 | + wp_enqueue_script( 'uwp-nestable-script', USERSWP_PLUGIN_URL . 'admin/assets/js/jquery.nestable' . $suffix . '.js', array( 'jquery-ui-sortable' ), USERSWP_VERSION ); | |
| 231 | + wp_enqueue_script( "uwp_form_builder", USERSWP_PLUGIN_URL . 'admin/assets/js/uwp-form-builder' . $suffix . '.js', array(), USERSWP_VERSION, 'all' ); | |
| 232 | + } | |
| 233 | + | |
| 234 | + if ( in_array( $screen_id, uwp_get_screen_ids() ) ) { | |
| 235 | + wp_enqueue_script( "userswp_admin", USERSWP_PLUGIN_URL . 'admin/assets/js/users-wp-admin' . $suffix . '.js', array( 'jquery' ), USERSWP_VERSION, false ); | |
| 236 | + | |
| 237 | + wp_enqueue_script( "jquery-ui-tooltip" ); | |
| 238 | + wp_enqueue_script( 'wp-color-picker' ); | |
| 239 | + | |
| 240 | + $ajax_cons_data = array( | |
| 241 | + 'url' => admin_url( 'admin-ajax.php' ), | |
| 242 | + 'custom_field_not_blank_var' => __( 'Field key must not be blank', 'userswp' ), | |
| 243 | + 'custom_field_options_not_blank_var' => __( 'Option Values must not be blank', 'userswp' ), | |
| 244 | + 'custom_field_not_special_char' => __( 'Please do not use special character and spaces in field key.', 'userswp' ), | |
| 245 | + 'custom_field_unique_name' => __( 'Field key should be a unique name.', 'userswp' ), | |
| 246 | + 'custom_field_delete' => __( 'Are you sure you wish to delete this field?', 'userswp' ), | |
| 247 | + 'custom_field_id_required' => __( 'This field is required.', 'userswp' ), | |
| 248 | + 'img_spacer' => admin_url( 'images/media-button-image.gif' ), | |
| 249 | + 'txt_choose_image' => __( 'Choose an image', 'userswp' ), | |
| 250 | + 'txt_use_image' => __( 'Use image', 'userswp' ), | |
| 251 | + 'delete_register_form' => __( 'Are you sure you wish to delete this form?', 'userswp' ), | |
| 252 | + 'ask_register_form_title' => __( 'Enter register form title', 'userswp' ), | |
| 253 | + 'form_updated_msg' => __( 'Updated! Reloading page...', 'userswp' ) | |
| 254 | + ); | |
| 255 | + wp_localize_script( "userswp_admin", 'uwp_admin_ajax', $ajax_cons_data ); | |
| 256 | + } | |
| 257 | + | |
| 258 | + } | |
| 259 | + | |
| 260 | + public function get_screen_ids(){ | |
| 261 | + return uwp_get_screen_ids(); | |
| 262 | + } | |
| 263 | + | |
| 264 | + /** | |
| 265 | + * Displays update messages | |
| 266 | + */ | |
| 267 | + public function show_update_messages() { | |
| 268 | + if ( ! isset( $_REQUEST['update'] ) ) { | |
| 269 | + return; | |
| 270 | + } | |
| 271 | + | |
| 272 | + $update = sanitize_text_field( $_REQUEST['update'] ); | |
| 273 | + $messages = array(); | |
| 274 | + | |
| 275 | + switch ( $update ) { | |
| 276 | + case 'uwp_resend': | |
| 277 | + $messages['msg'] = __( 'Activation email has been sent!', 'userswp' ); | |
| 278 | + break; | |
| 279 | + case 'err_uwp_resend': | |
| 280 | + $messages['err_msg'] = __( 'Error while sending activation email. Please try again.', 'userswp' ); | |
| 281 | + break; | |
| 282 | + case 'uwp_activate_user': | |
| 283 | + $messages['msg'] = __( 'User(s) has been activated!', 'userswp' ); | |
| 284 | + break; | |
| 285 | + } | |
| 286 | + | |
| 287 | + if ( ! empty( $messages ) ) { | |
| 288 | + if ( isset( $messages['err_msg'] ) ) { | |
| 289 | + echo '<div class="notice notice-error"><p>' . esc_html( $messages['err_msg'] ) . '</p></div>'; | |
| 290 | + } else { | |
| 291 | + echo '<div class="notice notice-success is-dismissible"><p>' . esc_html( $messages['msg'] ) . '</p></div>'; | |
| 292 | + } | |
| 293 | + } | |
| 294 | + } | |
| 295 | + | |
| 296 | + /** | |
| 297 | + * Adds UsersWP JS to admin area. | |
| 298 | + * | |
| 299 | + * @return void | |
| 300 | + * @package userswp | |
| 301 | + * | |
| 302 | + * @since 1.0.0 | |
| 303 | + */ | |
| 304 | + public function admin_only_script() { | |
| 305 | + | |
| 306 | + // check page is userswp or not. | |
| 307 | + if ( ! empty( $_GET['page'] ) && 'userswp' == $_GET['page']) { | |
| 308 | + | |
| 309 | + // check tab is general or not. | |
| 310 | + if ( ! empty( $_GET['tab'] ) && 'general' == $_GET['tab']) { | |
| 311 | + | |
| 312 | + // check for login section. | |
| 313 | + if ( ! empty( $_GET['section'] ) && 'login' == $_GET['section'] ) { | |
| 314 | + ?> | |
| 315 | + <script type="text/javascript"> | |
| 316 | + jQuery(document).ready(function () { | |
| 317 | + var login_redirect_to = jQuery('#login_redirect_to'); | |
| 318 | + login_redirect_to.on('change', function () { | |
| 319 | + var value = jQuery(this).val(); | |
| 320 | + var login_redirect_custom_obj = jQuery('#login_redirect_custom_url'); | |
| 321 | + | |
| 322 | + if ('-2' === value) { | |
| 323 | + login_redirect_custom_obj.parent().parent().show(); | |
| 324 | + } else { | |
| 325 | + login_redirect_custom_obj.parent().parent().hide(); | |
| 326 | + } | |
| 327 | + }).change(); | |
| 328 | + }); | |
| 329 | + </script> | |
| 330 | + <?php | |
| 331 | + } | |
| 332 | + } | |
| 333 | + | |
| 334 | + } | |
| 335 | + | |
| 336 | + if(! empty( $_GET['page'] ) && 'uwp_form_builder' == $_GET['page']) { | |
| 337 | + ?> | |
| 338 | + <script type="text/javascript"> | |
| 339 | + jQuery(document).ready(function () { | |
| 340 | + var uwp_registration_action = jQuery('#uwp_registration_action'); | |
| 341 | + uwp_registration_action.on('change', function () { | |
| 342 | + var value = jQuery(this).val(); | |
| 343 | + var register_redirect_obj = jQuery('#register_redirect_to'); | |
| 344 | + | |
| 345 | + if ('auto_approve_login' === value) { | |
| 346 | + register_redirect_obj.parent().parent().show(); | |
| 347 | + } else { | |
| 348 | + register_redirect_obj.parent().parent().hide(); | |
| 349 | + } | |
| 350 | + }).change(); | |
| 351 | + | |
| 352 | + var register_redirect_to = jQuery('#register_redirect_to'); | |
| 353 | + register_redirect_to.on('change', function () { | |
| 354 | + var value = jQuery(this).val(); | |
| 355 | + var register_redirect_custom_obj = jQuery('#register_redirect_custom_url'); | |
| 356 | + | |
| 357 | + if ('-2' === value) { | |
| 358 | + register_redirect_custom_obj.parent().show(); | |
| 359 | + register_redirect_custom_obj.parent().prev().show(); | |
| 360 | + } else { | |
| 361 | + register_redirect_custom_obj.parent().hide(); | |
| 362 | + register_redirect_custom_obj.parent().prev().hide(); | |
| 363 | + } | |
| 364 | + }).change(); | |
| 365 | + }); | |
| 366 | + </script> | |
| 367 | + <?php | |
| 368 | + } | |
| 369 | + | |
| 370 | + } | |
| 371 | + | |
| 372 | + /** | |
| 373 | + * Filters the user profile picture description displayed under the Gravatar. | |
| 374 | + * | |
| 375 | + * @param string $description Profile picture description. | |
| 376 | + * | |
| 377 | + * @return string Modified description. | |
| 378 | + * @since 1.0.0 | |
| 379 | + * @package userswp | |
| 380 | + * | |
| 381 | + */ | |
| 382 | + public function user_profile_picture_description( $description ) { | |
| 383 | + if ( is_admin() && IS_PROFILE_PAGE ) { | |
| 384 | + $user_id = get_current_user_id(); | |
| 385 | + $avatar = uwp_get_usermeta( $user_id, 'avatar_thumb', '' ); | |
| 386 | + | |
| 387 | + if ( ! empty( $avatar ) ) { | |
| 388 | + $description = sprintf( __( 'You can change your profile picture on your <a href="%s">Profile Page</a>.', 'userswp' ), | |
| 389 | + uwp_build_profile_tab_url( $user_id ) ); | |
| 390 | + } | |
| 391 | + | |
| 392 | + } | |
| 393 | + | |
| 394 | + return $description; | |
| 395 | + } | |
| 396 | + | |
| 397 | + public function admin_body_class( $classes ) { | |
| 398 | + $screen = get_current_screen(); | |
| 399 | + if ( 'profile' == $screen->base || 'user-edit' == $screen->base ) { | |
| 400 | + $classes .= ' uwp_page'; | |
| 401 | + } | |
| 402 | + | |
| 403 | + // Add original UsersWP page class when UsersWP screen is translated. | |
| 404 | + if ( ! empty( $_GET['page'] ) && in_array( $_GET['page'], array( 'uwp_form_builder', 'uwp_tools', 'uwp_status', 'uwp-addons' ) ) ) { | |
| 405 | + $uwp_screen_id = sanitize_title( __( 'UsersWP', 'userswp' ) ); | |
| 406 | + | |
| 407 | + if ( $uwp_screen_id != 'userswp' ) { | |
| 408 | + $classes .= ' userswp_page_' . esc_attr( sanitize_text_field( $_GET['page'] ) ); | |
| 409 | + } | |
| 410 | + } | |
| 411 | + | |
| 412 | + // Add body class for admin pages. | |
| 413 | + $screen = get_current_screen(); | |
| 414 | + $screen_id = $screen ? $screen->id : ''; | |
| 415 | + | |
| 416 | + if ( $screen_id && in_array( $screen_id, uwp_get_screen_ids() ) ) { | |
| 417 | + $classes .= ' uwp-admin-page uwp-admin-page-' . sanitize_key( $screen_id ); | |
| 418 | + } | |
| 419 | + | |
| 420 | + return $classes; | |
| 421 | + } | |
| 422 | + | |
| 423 | + /** | |
| 424 | + * Preview email template for UWP emails. | |
| 425 | + */ | |
| 426 | + public function preview_emails() { | |
| 427 | + if ( isset( $_GET['uwp_preview_mail'] ) ) { | |
| 428 | + if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'uwp-preview-mail' ) ) { | |
| 429 | + die( 'Security check failed.' ); | |
| 430 | + } | |
| 431 | + | |
| 432 | + $email_name = 'preview_mail'; | |
| 433 | + $email_vars = array(); | |
| 434 | + $plain_text = UsersWP_Mails::get_email_type() != 'html' ? true : false; | |
| 435 | + | |
| 436 | + // Get the preview email content. | |
| 437 | + ob_start(); | |
| 438 | + include( 'views/html-email-template-preview.php' ); | |
| 439 | + $message = ob_get_clean(); | |
| 440 | + | |
| 441 | + $message = UsersWP_Mails::email_wrap_message( $message, $email_name, $email_vars, '', $plain_text ); | |
| 442 | + $message = UsersWP_Mails::style_body( $message, $email_name, $email_vars ); | |
| 443 | + $message = apply_filters( 'uwp_mail_content', $message, $email_name, $email_vars ); | |
| 444 | + | |
| 445 | + // Print the preview email content. | |
| 446 | + if ( $plain_text ) { | |
| 447 | + echo '<div style="white-space:pre-wrap;font-family:sans-serif">'; | |
| 448 | + } | |
| 449 | + echo $message; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 450 | + if ( $plain_text ) { | |
| 451 | + echo '</div>'; | |
| 452 | + } | |
| 453 | + exit; | |
| 454 | + } | |
| 455 | + } | |
| 456 | + | |
| 457 | + /** | |
| 458 | + * Returns user views filter | |
| 459 | + * | |
| 460 | + * @return array User views. | |
| 461 | + */ | |
| 462 | + public function request_views_users( $views ) { | |
| 463 | + | |
| 464 | + $current = ''; | |
| 465 | + | |
| 466 | + if ( isset( $_REQUEST['uwp_status'] ) && $_REQUEST['uwp_status'] == 'pending-email-activate' ) { | |
| 467 | + $views['all'] = str_replace( 'current', '', $views['all'] ); | |
| 468 | + $current = 'current'; | |
| 469 | + } | |
| 470 | + | |
| 471 | + $views['pending-email-activate'] = '<a href="' . admin_url( 'users.php' ) . '?uwp_status=pending-email-activate" class="' . $current . '">' . __( 'Pending Email Activation', 'userswp' ) . ' <span class="count">(' . $this->uwp_pending_email_count() . ')</span></a>'; | |
| 472 | + | |
| 473 | + return $views; | |
| 474 | + } | |
| 475 | + | |
| 476 | + /** | |
| 477 | + * Returns pending email activation user counts | |
| 478 | + * | |
| 479 | + * @return int User count | |
| 480 | + */ | |
| 481 | + public function uwp_pending_email_count() { | |
| 482 | + | |
| 483 | + $args = array( | |
| 484 | + 'fields' => 'ID', | |
| 485 | + 'number' => 0, | |
| 486 | + 'meta_query' => array( | |
| 487 | + array( | |
| 488 | + 'key' => 'uwp_mod', | |
| 489 | + 'value' => 'email_unconfirmed', | |
| 490 | + 'compare' => '=' | |
| 491 | + ) | |
| 492 | + ) | |
| 493 | + ); | |
| 494 | + $users = new WP_User_Query( $args ); | |
| 495 | + | |
| 496 | + return isset( $users->results ) ? (int) count( $users->results ) : 0; | |
| 497 | + } | |
| 498 | + | |
| 499 | + /** | |
| 500 | + * Filter to modify the user query | |
| 501 | + * | |
| 502 | + * @return object User query. | |
| 503 | + */ | |
| 504 | + public function request_users_filter( $query ) { | |
| 505 | + | |
| 506 | + global $wpdb, $pagenow; | |
| 507 | + | |
| 508 | + if ( is_admin() && $pagenow == 'users.php' && isset( $_GET['uwp_status'] ) && $_GET['uwp_status'] != '' ) { | |
| 509 | + | |
| 510 | + do_action('uwp_users_show_pending_email_activation', $query); | |
| 511 | + | |
| 512 | + $status = sanitize_text_field( urldecode( $_GET['uwp_status'] ) ); | |
| 513 | + | |
| 514 | + if ( $status == 'pending-email-activate' ) { | |
| 515 | + $query->query_where = str_replace( 'WHERE 1=1', | |
| 516 | + "WHERE 1=1 AND {$wpdb->users}.ID IN ( | |
| 517 | + SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta | |
| 518 | + WHERE {$wpdb->usermeta}.meta_key = 'uwp_mod' | |
| 519 | + AND {$wpdb->usermeta}.meta_value = 'email_unconfirmed')", | |
| 520 | + $query->query_where | |
| 521 | + ); | |
| 522 | + } | |
| 523 | + } | |
| 524 | + | |
| 525 | + return $query; | |
| 526 | + } | |
| 527 | + | |
| 528 | + /** | |
| 529 | + * Gets UsersWP fields in WP-Admin Users Edit page. | |
| 530 | + * | |
| 531 | + * @param object $user User Object. | |
| 532 | + * | |
| 533 | + * @package userswp | |
| 534 | + * @since 1.0.0 | |
| 535 | + */ | |
| 536 | + public function get_profile_extra_edit( $user ) { | |
| 537 | + global $wpdb; | |
| 538 | + $table_name = uwp_get_table_prefix() . 'uwp_form_fields'; | |
| 539 | + $form_id = uwp_get_register_form_id( $user->ID ); | |
| 540 | + $excluded_fields = apply_filters( 'uwp_exclude_edit_profile_fields', array('bio', 'register_gdpr', 'register_tos', 'uwp_language', 'multisite_site_title', 'multisite_site_address') ); | |
| 541 | + $query = $wpdb->prepare("SELECT * FROM " . $table_name . " WHERE form_type = 'account' AND is_default = '0' AND form_id = %d", $form_id); | |
| 542 | + if ( is_array( $excluded_fields ) && count( $excluded_fields ) > 0 ) { | |
| 543 | + $query .= " AND htmlvar_name NOT IN ('" . implode( "','", $excluded_fields ) . "')"; | |
| 544 | + } | |
| 545 | + $query .= ' ORDER BY sort_order ASC'; | |
| 546 | + $fields = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 547 | + | |
| 548 | + $this->edit_profile_banner_fields( $user ); // Displays avatar and banner fields | |
| 549 | + | |
| 550 | + if ( $fields ) { | |
| 551 | + ?> | |
| 552 | + <div class="uwp-profile-extra"> | |
| 553 | + <table class="uwp-profile-extra-table form-table bsui"> | |
| 554 | + <?php | |
| 555 | + foreach ( $fields as $field ) { | |
| 556 | + | |
| 557 | + if(isset($field->css_class) && !empty($field->css_class)){ | |
| 558 | + $field->css_class = $field->css_class.' w-50'; | |
| 559 | + } else { | |
| 560 | + $field->css_class = 'w-50'; | |
| 561 | + } | |
| 562 | + | |
| 563 | + if ( $field->field_type == 'fieldset' ) { | |
| 564 | + ?> | |
| 565 | + <tr style="margin: 0; padding: 0"> | |
| 566 | + <th class="uwp-profile-extra-key" style="margin: 0; padding: 0"><h3 | |
| 567 | + style="margin: 10px 0;"><?php echo esc_html( $field->site_title ); ?></h3></th> | |
| 568 | + <td></td> | |
| 569 | + </tr> | |
| 570 | + <?php | |
| 571 | + } else { ?> | |
| 572 | + <tr> | |
| 573 | + <th class="uwp-profile-extra-key"><?php echo esc_html( $field->site_title ); ?></th> | |
| 574 | + <td class="uwp-profile-extra-value"> | |
| 575 | + <?php | |
| 576 | + $templates_obj = new UsersWP_Templates(); | |
| 577 | + $templates_obj->template_fields_html( $field, 'account', $user->ID ); ?> | |
| 578 | + </td> | |
| 579 | + </tr> | |
| 580 | + <?php | |
| 581 | + } | |
| 582 | + } | |
| 583 | + ?> | |
| 584 | + </table> | |
| 585 | + </div> | |
| 586 | + <?php | |
| 587 | + } | |
| 588 | + } | |
| 589 | + | |
| 590 | + /** | |
| 591 | + * Adds avatar and banner fields in admin side. | |
| 592 | + * | |
| 593 | + * @param object $user User object. | |
| 594 | + * | |
| 595 | + * @return void | |
| 596 | + * @since 1.0.0 | |
| 597 | + * @package userswp | |
| 598 | + * | |
| 599 | + */ | |
| 600 | + public function edit_profile_banner_fields( $user ) { | |
| 601 | + global $wpdb; | |
| 602 | + | |
| 603 | + $file_obj = new UsersWP_Files(); | |
| 604 | + | |
| 605 | + $table_name = uwp_get_table_prefix() . 'uwp_form_fields'; | |
| 606 | + $fields = $wpdb->get_results( "SELECT * FROM " . $table_name . " WHERE (form_type = 'avatar' OR form_type = 'banner') ORDER BY sort_order ASC" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 607 | + if ( $fields ) { | |
| 608 | + ?> | |
| 609 | + <div class="uwp-profile-extra uwp_page"> | |
| 610 | + <?php do_action( 'uwp_admin_profile_edit', $user ); ?> | |
| 611 | + <h2><?php esc_html_e('UsersWP Account Details', 'userswp'); ?></h2> | |
| 612 | + <table class="uwp-profile-extra-table form-table"> | |
| 613 | + <?php | |
| 614 | + foreach ( $fields as $field ) { | |
| 615 | + | |
| 616 | + if ( $field->field_type == 'fieldset' ) { | |
| 617 | + ?> | |
| 618 | + <tr style="margin: 0; padding: 0"> | |
| 619 | + <th class="uwp-profile-extra-key" style="margin: 0; padding: 0"><h3 | |
| 620 | + style="margin: 10px 0;"> | |
| 621 | + <?php echo esc_html( $field->site_title ); ?></h3></th> | |
| 622 | + <td></td> | |
| 623 | + </tr> | |
| 624 | + <?php | |
| 625 | + } else { ?> | |
| 626 | + <tr> | |
| 627 | + <th class="uwp-profile-extra-key"><?php echo esc_html( $field->site_title ); ?></th> | |
| 628 | + <td class="uwp-profile-extra-value"> | |
| 629 | + <?php | |
| 630 | + if ( $field->htmlvar_name == "avatar" ) { | |
| 631 | + $value = uwp_get_usermeta( $user->ID, "avatar_thumb", "" ); | |
| 632 | + } elseif ( $field->htmlvar_name == "banner" ) { | |
| 633 | + $value = uwp_get_usermeta( $user->ID, "banner_thumb", "" ); | |
| 634 | + } else { | |
| 635 | + $value = ""; | |
| 636 | + } | |
| 637 | + | |
| 638 | + echo $file_obj->file_upload_preview( $field, $value ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 639 | + | |
| 640 | + if ( $field->htmlvar_name == "avatar" ) { | |
| 641 | + if ( ! empty( $value ) ) { | |
| 642 | + $label = __( "Change Avatar", "userswp" ); | |
| 643 | + } else { | |
| 644 | + $label = __( "Upload Avatar", "userswp" ); | |
| 645 | + } | |
| 646 | + ?> | |
| 647 | + <a onclick="uwp_profile_image_change('avatar');return false;" href="#" | |
| 648 | + class="uwp-banner-change-icon-admin"> | |
| 649 | + <?php echo esc_html( $label ); ?> | |
| 650 | + </a> | |
| 651 | + <?php | |
| 652 | + } elseif ( $field->htmlvar_name == "banner" ) { | |
| 653 | + if ( ! empty( $value ) ) { | |
| 654 | + $label = __( "Change Banner", "userswp" ); | |
| 655 | + } else { | |
| 656 | + $label = __( "Upload Banner", "userswp" ); | |
| 657 | + } ?> | |
| 658 | + <a onclick="uwp_profile_image_change('banner');return false;" href="#" | |
| 659 | + class="uwp-banner-change-icon-admin"> | |
| 660 | + <?php echo esc_html( $label ); ?> | |
| 661 | + </a> | |
| 662 | + <?php | |
| 663 | + } | |
| 664 | + ?> | |
| 665 | + </td> | |
| 666 | + </tr> | |
| 667 | + <?php | |
| 668 | + } | |
| 669 | + } | |
| 670 | + ?> | |
| 671 | + </table> | |
| 672 | + </div> | |
| 673 | + <?php | |
| 674 | + } | |
| 675 | + } | |
| 676 | + | |
| 677 | + /** | |
| 678 | + * Returns user row actions | |
| 679 | + * | |
| 680 | + * @param array $actions Date string. | |
| 681 | + * @param object $user_object The User ID. | |
| 682 | + * | |
| 683 | + * @return array Row actions. | |
| 684 | + * @package userswp | |
| 685 | + * | |
| 686 | + */ | |
| 687 | + public function user_row_actions( $actions, $user_object ) { | |
| 688 | + $user_id = $user_object->ID; | |
| 689 | + $mod_value = get_user_meta( $user_id, 'uwp_mod', true ); | |
| 690 | + $resend_link = add_query_arg( | |
| 691 | + array( | |
| 692 | + 'user_id' => $user_id, | |
| 693 | + 'action' => 'uwp_resend', | |
| 694 | + '_nonce' => wp_create_nonce( 'uwp_resend' ), | |
| 695 | + 'uwp_is_admin' => 1, | |
| 696 | + ), | |
| 697 | + admin_url( 'users.php' ) | |
| 698 | + ); | |
| 699 | + | |
| 700 | + $activate_link = add_query_arg( | |
| 701 | + array( | |
| 702 | + 'user_id' => $user_id, | |
| 703 | + 'action' => 'uwp_activate_user', | |
| 704 | + '_nonce' => wp_create_nonce( 'uwp_activate_user' ), | |
| 705 | + 'uwp_is_admin' => 1, | |
| 706 | + ), | |
| 707 | + admin_url( 'users.php' ) | |
| 708 | + ); | |
| 709 | + | |
| 710 | + if ( $mod_value == 'email_unconfirmed' ) { | |
| 711 | + $actions['uwp_resend_activation'] = "<a class='' href='" . $resend_link . "'>" . __( 'Resend Activation', 'userswp' ) . "</a>"; | |
| 712 | + $actions['uwp_auto_activate'] = "<a class='' href='" . $activate_link . "'>" . __( 'Activate User', 'userswp' ) . "</a>"; | |
| 713 | + } | |
| 714 | + | |
| 715 | + return $actions; | |
| 716 | + } | |
| 717 | + | |
| 718 | + /** | |
| 719 | + * Returns users bulk actions | |
| 720 | + * | |
| 721 | + * @param array $bulk_actions Bulk actions. | |
| 722 | + * | |
| 723 | + * @return array Bulk actions. | |
| 724 | + * @package userswp | |
| 725 | + * | |
| 726 | + */ | |
| 727 | + public function users_bulk_actions( $bulk_actions ) { | |
| 728 | + $bulk_actions['uwp_resend'] = __( 'Resend Activation', 'userswp' ); | |
| 729 | + $bulk_actions['uwp_activate_user'] = __( 'Activate Users', 'userswp' ); | |
| 730 | + | |
| 731 | + return $bulk_actions; | |
| 732 | + } | |
| 733 | + | |
| 734 | + /** | |
| 735 | + * Handles users bulk actions | |
| 736 | + * | |
| 737 | + * @param string $redirect_to Bulk actions. | |
| 738 | + * @param string $doaction Current action. | |
| 739 | + * @param array $user_ids User IDs to process. | |
| 740 | + * | |
| 741 | + * @return string Redirect URL. | |
| 742 | + * @package userswp | |
| 743 | + * | |
| 744 | + */ | |
| 745 | + public function handle_users_bulk_actions( $redirect_to, $doaction, $user_ids ) { | |
| 746 | + if ( 'uwp_resend' == $doaction ) { | |
| 747 | + foreach ( $user_ids as $user_id ) { | |
| 748 | + uwp_resend_activation_mail( $user_id ); | |
| 749 | + } | |
| 750 | + | |
| 751 | + $redirect_to = add_query_arg( 'update', 'uwp_resend', $redirect_to ); | |
| 752 | + } elseif ( 'uwp_activate_user' == $doaction ) { | |
| 753 | + foreach ( $user_ids as $user_id ) { | |
| 754 | + $this->activate_user( $user_id ); | |
| 755 | + } | |
| 756 | + $redirect_to = add_query_arg( 'update', 'uwp_activate_user', $redirect_to ); | |
| 757 | + } | |
| 758 | + | |
| 759 | + return $redirect_to; | |
| 760 | + } | |
| 761 | + | |
| 762 | + /** | |
| 763 | + * Activates user | |
| 764 | + * | |
| 765 | + * @param int $user_id User ID | |
| 766 | + * | |
| 767 | + * @return bool | |
| 768 | + */ | |
| 769 | + public function activate_user( $user_id = 0 ) { | |
| 770 | + if ( ! $user_id ) { | |
| 771 | + return false; | |
| 772 | + } | |
| 773 | + | |
| 774 | + $uwp_mode = get_user_meta( $user_id, 'uwp_mod', true ); | |
| 775 | + if ( 'email_unconfirmed' == $uwp_mode ) { | |
| 776 | + delete_user_meta( $user_id, 'uwp_mod' ); | |
| 777 | + do_action( 'uwp_email_activation_success', $user_id ); | |
| 778 | + } | |
| 779 | + | |
| 780 | + return true; | |
| 781 | + } | |
| 782 | + | |
| 783 | + /** | |
| 784 | + * Processes user action | |
| 785 | + * | |
| 786 | + * @return mixed | |
| 787 | + * @package userswp | |
| 788 | + * | |
| 789 | + */ | |
| 790 | + public function process_user_actions() { | |
| 791 | + $user_id = isset( $_REQUEST['user_id'] ) ? (int) $_REQUEST['user_id'] : 0; | |
| 792 | + $action = isset( $_REQUEST['action'] ) ? sanitize_text_field($_REQUEST['action']) : false; | |
| 793 | + $nonce = isset( $_REQUEST['_nonce'] ) ? sanitize_text_field($_REQUEST['_nonce']) : false; | |
| 794 | + $is_admin = isset( $_REQUEST['uwp_is_admin'] ) ? sanitize_text_field($_REQUEST['uwp_is_admin']) : false; | |
| 795 | + | |
| 796 | + if ( $user_id && 'uwp_resend' == $action && !empty($nonce) && wp_verify_nonce( $nonce, 'uwp_resend' ) ) { | |
| 797 | + uwp_resend_activation_mail( $user_id ); | |
| 798 | + if ( isset($is_admin) && $is_admin ) { | |
| 799 | + wp_redirect( add_query_arg( 'update', 'uwp_resend', admin_url( 'users.php' ) ) ); | |
| 800 | + exit(); | |
| 801 | + } else { | |
| 802 | + global $uwp_notices; | |
| 803 | + $message = __( 'Activation email has been sent!', 'userswp' ); | |
| 804 | + $uwp_notices[] = aui()->alert( array( | |
| 805 | + 'type' => 'success', | |
| 806 | + 'content' => $message | |
| 807 | + ) ); | |
| 808 | + } | |
| 809 | + } elseif ( $user_id && 'uwp_activate_user' == $action && wp_verify_nonce( $nonce, 'uwp_activate_user' ) ) { | |
| 810 | + if ( isset($is_admin) && $is_admin && current_user_can( 'edit_users' ) ) { | |
| 811 | + $this->activate_user( $user_id ); | |
| 812 | + wp_redirect( add_query_arg( 'update', 'uwp_activate_user', admin_url( 'users.php' ) ) ); | |
| 813 | + } | |
| 814 | + } | |
| 815 | + } | |
| 816 | + | |
| 817 | + /** | |
| 818 | + * Show row meta on the plugin screen. | |
| 819 | + * | |
| 820 | + * @param mixed $links Plugin Row Meta | |
| 821 | + * @param mixed $file Plugin Base file | |
| 822 | + * @return array | |
| 823 | + */ | |
| 824 | + public static function plugin_row_meta( $links, $file ) { | |
| 825 | + if ( USERSWP_PLUGIN_BASENAME == $file ) { | |
| 826 | + $row_meta = array( | |
| 827 | + 'docs' => '<a href="' . esc_url( 'https://docs.userswp.io/' ) . '" aria-label="' . esc_attr__( 'View UsersWP Documentation', 'userswp' ) . '">' . esc_html__( 'Docs', 'userswp' ) . '</a>', | |
| 828 | + 'support' => '<a href="' . esc_url( 'https://userswp.io/support/' ) . '" aria-label="' . esc_attr__( 'Visit UsersWP support', 'userswp' ) . '">' . esc_html__( 'Support', 'userswp' ) . '</a>', | |
| 829 | + 'translation' => '<a href="' . esc_url( 'https://userswp.io/translate/projects' ) . '" aria-label="' . esc_attr__( 'View translations', 'userswp' ) . '">' . esc_html__( 'Translations', 'userswp' ) . '</a>', | |
| 830 | + ); | |
| 831 | + | |
| 832 | + return array_merge( $links, $row_meta ); | |
| 833 | + } | |
| 834 | + | |
| 835 | + return (array) $links; | |
| 836 | + } | |
| 837 | + | |
| 838 | + public function process_create_register_form() { | |
| 839 | + | |
| 840 | + if ( ! current_user_can( 'manage_options' ) ) { | |
| 841 | + wp_die( -1 ); | |
| 842 | + } | |
| 843 | + | |
| 844 | + $type = ! empty( $_POST['type'] ) ? sanitize_text_field($_POST['type']) : ''; | |
| 845 | + $form_title = ! empty( $_POST['form_title'] ) ? sanitize_title_with_dashes($_POST['form_title']) : ''; | |
| 846 | + $nonce = ! empty( $_POST['nonce'] ) ? sanitize_text_field($_POST['nonce']) : ''; | |
| 847 | + | |
| 848 | + $status = false; | |
| 849 | + $message = __( 'Something went wrong. Please try again.', 'userswp' ); | |
| 850 | + $redirect = ''; | |
| 851 | + if ( ! empty( $type ) && $type == 'create' && ! empty( $nonce ) && wp_verify_nonce( $nonce, 'uwp-create-register-form-nonce' ) ) { | |
| 852 | + | |
| 853 | + $get_register_forms = uwp_get_option( 'multiple_registration_forms' ); | |
| 854 | + $new_form_id = uwp_get_next_register_form_id(); | |
| 855 | + | |
| 856 | + if ( ! empty( $new_form_id ) ) { | |
| 857 | + | |
| 858 | + $get_register_forms[] = array( | |
| 859 | + 'id' => $new_form_id, | |
| 860 | + 'title' => ! empty( $form_title ) ? sanitize_text_field( $form_title ) : sprintf( __( 'Form %d', 'userswp' ), $new_form_id ), | |
| 861 | + ); | |
| 862 | + | |
| 863 | + uwp_update_option( 'multiple_registration_forms', $get_register_forms ); | |
| 864 | + | |
| 865 | + $fields = UsersWP_Activator::uwp_default_custom_fields_account(); | |
| 866 | + $form_builder = new UsersWP_Form_Builder(); | |
| 867 | + | |
| 868 | + if(isset($fields) && count($fields) > 0){ | |
| 869 | + foreach ($fields as $field_index => $field) { | |
| 870 | + $field['form_id'] = $new_form_id; | |
| 871 | + $form_builder->admin_form_field_save($field); | |
| 872 | + } | |
| 149 | 873 | } |
| 150 | - $current_blog_id = get_current_blog_id(); | |
| 151 | - if (!is_int($blog_id)) { | |
| 152 | - $proceed = false; | |
| 153 | - } else { | |
| 154 | - if ($blog_id == $current_blog_id) { | |
| 155 | - $proceed = true; | |
| 156 | - $show_builder = true; | |
| 157 | - } else { | |
| 158 | - $proceed = false; | |
| 159 | - } | |
| 160 | - } | |
| 161 | - break; | |
| 162 | - case "multi_na_default": | |
| 163 | - $is_main_site = is_main_site(); | |
| 164 | - if ($is_main_site) { | |
| 165 | - $proceed = true; | |
| 166 | - $show_builder = true; | |
| 167 | - } | |
| 168 | - break; | |
| 169 | - case "multi_not_na": | |
| 170 | - $proceed = true; | |
| 171 | - $show_builder = true; | |
| 172 | - break; | |
| 173 | - default: | |
| 174 | - $proceed = false; | |
| 175 | 874 | |
| 176 | - } | |
| 875 | + UsersWP_Activator::insert_form_extras($new_form_id); | |
| 177 | 876 | |
| 178 | - if (!$proceed) { | |
| 179 | - return; | |
| 180 | - } | |
| 877 | + do_action('uwp_create_register_form', $new_form_id); | |
| 181 | 878 | |
| 879 | + $status = true; | |
| 880 | + $redirect = admin_url( 'admin.php?page=uwp_form_builder&tab=account&form=' . $new_form_id ); | |
| 881 | + } | |
| 882 | + } | |
| 182 | 883 | |
| 183 | - add_menu_page( | |
| 184 | - __( 'UsersWP Settings', 'userswp' ), | |
| 185 | - __( 'UsersWP', 'userswp' ), | |
| 186 | - 'manage_options', | |
| 187 | - 'userswp', | |
| 188 | - array( $this->admin_settings, 'uwp_settings_page' ), | |
| 189 | - 'dashicons-groups', | |
| 190 | - 70 | |
| 191 | - ); | |
| 884 | + $response = array( | |
| 885 | + 'status' => $status, | |
| 886 | + 'message' => $message, | |
| 887 | + 'redirect' => $redirect, | |
| 888 | + ); | |
| 192 | 889 | |
| 193 | - if ($show_builder) { | |
| 194 | - add_submenu_page( | |
| 195 | - "userswp", | |
| 196 | - __( 'Form Builder', 'userswp' ), | |
| 197 | - __( 'Form Builder', 'userswp' ), | |
| 198 | - 'manage_options', | |
| 199 | - 'uwp_form_builder', | |
| 200 | - array($this->admin_settings, 'uwp_settings_page') | |
| 201 | - ); | |
| 890 | + echo json_encode( $response ); | |
| 891 | + wp_die(); | |
| 892 | + } | |
| 202 | 893 | |
| 203 | - add_submenu_page( | |
| 204 | - "userswp", | |
| 205 | - __( 'Notifications', 'userswp' ), | |
| 206 | - __( 'Notifications', 'userswp' ), | |
| 207 | - 'manage_options', | |
| 208 | - 'uwp_notifications', | |
| 209 | - array($this->admin_settings, 'uwp_settings_page') | |
| 210 | - ); | |
| 894 | + public function process_update_register_form() { | |
| 211 | 895 | |
| 212 | - $settings_page = array($this->admin_settings, 'uwp_settings_page'); | |
| 213 | - do_action('uwp_admin_sub_menus', $settings_page, $this->admin_settings); | |
| 214 | - } | |
| 215 | - } | |
| 896 | + check_ajax_referer( 'uwp-update-register-form-nonce', 'uwp_update_register_form_nonce' ); | |
| 216 | 897 | |
| 217 | - /** | |
| 218 | - * Adds UsersWP css to admin area | |
| 219 | - * | |
| 220 | - * @since 1.0.0 | |
| 221 | - * @package userswp | |
| 222 | - * | |
| 223 | - * @return void | |
| 224 | - */ | |
| 225 | - function uwp_admin_only_css() { | |
| 226 | - ?> | |
| 227 | - <style type="text/css"> | |
| 228 | - .uwp_page .uwp-bs-modal input[type="submit"].button, | |
| 229 | - .uwp_page .uwp-bs-modal button.button { | |
| 230 | - padding: 0 10px 1px; | |
| 231 | - } | |
| 232 | - </style> | |
| 233 | - <?php | |
| 234 | - } | |
| 898 | + if ( ! current_user_can( 'manage_options' ) ) { | |
| 899 | + wp_die( -1 ); | |
| 900 | + } | |
| 235 | 901 | |
| 902 | + $type = ! empty( $_POST['type'] ) ? sanitize_text_field($_POST['type']) : ''; | |
| 903 | + $form_id = ! empty( $_POST['manage_field_form_id'] ) ? (int)$_POST['manage_field_form_id'] : ''; | |
| 904 | + $form_title = ! empty( $_POST['form_title'] ) ? sanitize_text_field($_POST['form_title']) : __( 'Form', 'userswp' ); | |
| 905 | + $user_role = ! empty( $_POST['user_role'] ) ? sanitize_text_field($_POST['user_role']) : ''; | |
| 906 | + $action = ! empty( $_POST['reg_action'] ) ? sanitize_text_field($_POST['reg_action']) : uwp_get_option( 'uwp_registration_action', 'auto_approve' ); | |
| 907 | + $redirect_to = (int) $_POST['redirect_to']; | |
| 908 | + $custom_url = ! empty( $_POST['custom_url'] ) ? sanitize_text_field($_POST['custom_url']) : ''; | |
| 909 | + $gdpr_page = ! empty( $_POST['gdpr_page'] ) ? (int)$_POST['gdpr_page'] : (int)uwp_get_option('register_gdpr_page', false); | |
| 910 | + $tos_page = ! empty( $_POST['tos_page'] ) ? (int)$_POST['tos_page'] : (int)uwp_get_option('register_terms_page', false); | |
| 911 | + | |
| 912 | + $status = false; | |
| 913 | + $message = __( 'Something went wrong. Please try again.', 'userswp' ); | |
| 914 | + if ( ! empty( $type ) && ! empty( $form_id ) && $type === 'update' ) { | |
| 915 | + | |
| 916 | + $register_forms = uwp_get_option( 'multiple_registration_forms' ); | |
| 917 | + | |
| 918 | + if ( ! empty( $register_forms ) && is_array( $register_forms ) ) { | |
| 919 | + | |
| 920 | + foreach ( $register_forms as $key => $register_form ) { | |
| 921 | + | |
| 922 | + if ( ! empty( $register_form['id'] ) && $register_form['id'] == $form_id ) { | |
| 923 | + $status = true; | |
| 924 | + $register_forms[ $key ]['title'] = $form_title; | |
| 925 | + $register_forms[ $key ]['user_role'] = $user_role; | |
| 926 | + $register_forms[ $key ]['reg_action'] = $action; | |
| 927 | + $register_forms[ $key ]['redirect_to'] = $redirect_to; | |
| 928 | + $register_forms[ $key ]['custom_url'] = $custom_url; | |
| 929 | + $register_forms[ $key ]['gdpr_page'] = $gdpr_page; | |
| 930 | + $register_forms[ $key ]['tos_page'] = $tos_page; | |
| 931 | + } | |
| 932 | + } | |
| 933 | + } | |
| 934 | + | |
| 935 | + $register_forms = array_values( $register_forms ); | |
| 936 | + $register_forms = apply_filters('uwp_multiple_registration_forms_update', $register_forms); | |
| 937 | + uwp_update_option( 'multiple_registration_forms', $register_forms ); | |
| 938 | + } | |
| 939 | + | |
| 940 | + $response = array( | |
| 941 | + 'status' => $status, | |
| 942 | + 'message' => $message, | |
| 943 | + ); | |
| 944 | + | |
| 945 | + echo json_encode( $response ); | |
| 946 | + wp_die(); | |
| 947 | + } | |
| 948 | + | |
| 949 | + public function process_remove_register_form() { | |
| 950 | + | |
| 951 | + check_ajax_referer( 'uwp-delete-register-form-nonce', 'nonce' ); | |
| 952 | + | |
| 953 | + if ( ! current_user_can( 'manage_options' ) ) { | |
| 954 | + wp_die( -1 ); | |
| 955 | + } | |
| 956 | + | |
| 957 | + global $wpdb; | |
| 958 | + $table_name = uwp_get_table_prefix() . 'uwp_form_fields'; | |
| 959 | + | |
| 960 | + $type = ! empty( $_POST['type'] ) ? sanitize_text_field($_POST['type']) : ''; | |
| 961 | + $form_id = ! empty( $_POST['form_id'] ) ? (int)$_POST['form_id'] : ''; | |
| 962 | + | |
| 963 | + $status = false; | |
| 964 | + $message = __( 'Security nonce failed. Please try again.', 'userswp' ); | |
| 965 | + $redirect = ''; | |
| 966 | + if ( ! empty( $type ) && ! empty( $form_id ) && $type === 'remove' ) { | |
| 967 | + | |
| 968 | + $register_forms = uwp_get_option( 'multiple_registration_forms' ); | |
| 969 | + $form_builder = new UsersWP_Form_Builder(); | |
| 970 | + | |
| 971 | + if ( ! empty( $register_forms ) && is_array( $register_forms ) ) { | |
| 972 | + | |
| 973 | + foreach ( $register_forms as $key => $register_form ) { | |
| 974 | + | |
| 975 | + if ( ! empty( $register_form['id'] ) && $register_form['id'] == $form_id ) { | |
| 976 | + $status = true; | |
| 977 | + unset( $register_forms[ $key ] ); | |
| 978 | + $fields = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 979 | + $wpdb->prepare( | |
| 980 | + "select id from " . $table_name . " where form_type = %s AND form_id = %d order by sort_order asc", | |
| 981 | + array('account', $form_id) | |
| 982 | + ) | |
| 983 | + ); | |
| 984 | + | |
| 985 | + if (!empty($fields)) { | |
| 986 | + foreach ($fields as $field) { | |
| 987 | + $form_builder->admin_form_field_delete($field->id, false, $form_id); | |
| 988 | + } | |
| 989 | + } | |
| 990 | + } | |
| 991 | + } | |
| 992 | + } | |
| 993 | + | |
| 994 | + $register_forms = array_values( $register_forms ); | |
| 995 | + uwp_update_option( 'multiple_registration_forms', $register_forms ); | |
| 996 | + $redirect = admin_url( 'admin.php?page=uwp_form_builder&tab=account' ); | |
| 997 | + } | |
| 998 | + | |
| 999 | + $response = array( | |
| 1000 | + 'status' => $status, | |
| 1001 | + 'message' => $message, | |
| 1002 | + 'redirect' => $redirect, | |
| 1003 | + ); | |
| 1004 | + | |
| 1005 | + echo json_encode( $response ); | |
| 1006 | + wp_die(); | |
| 1007 | + } | |
| 1008 | + | |
| 1009 | + /** | |
| 1010 | + * Tell AyeCode UI to load on certain admin pages. | |
| 1011 | + * | |
| 1012 | + * @since 1.2.3.22 | |
| 1013 | + * | |
| 1014 | + * @param array $screen_ids Screen IDs. | |
| 1015 | + * @return array Screen IDs. | |
| 1016 | + */ | |
| 1017 | + public function add_aui_screens( $screen_ids ) { | |
| 1018 | + // Load on these pages if set | |
| 1019 | + if ( is_admin() && ! wp_doing_ajax() ) { | |
| 1020 | + $screen_ids = array_merge( $screen_ids, uwp_get_screen_ids() ); | |
| 1021 | + } | |
| 1022 | + | |
| 1023 | + // AUI is also needed for setup wizard. | |
| 1024 | + $screen_ids[] = 'uwp-setup'; | |
| 1025 | + | |
| 1026 | + return $screen_ids; | |
| 1027 | + } | |
| 236 | 1028 | } |