| @@ -8,256 +8,293 @@ | ||
| 8 | 8 | * @author GeoDirectory Team <info@wpgeodirectory.com> |
| 9 | 9 | */ |
| 10 | 10 | class UsersWP_Activator { |
| 11 | 11 | |
| 12 | - /** | |
| 13 | - * This method gets fired during plugin activation. | |
| 14 | - * | |
| 15 | - * @since 1.0.0 | |
| 16 | - * @package userswp | |
| 17 | - * @return void | |
| 18 | - */ | |
| 19 | - public static function activate() { | |
| 20 | - | |
| 21 | - self::load_dependencies(); | |
| 12 | + /** @var array DB updates and callbacks that need to be run per version */ | |
| 13 | + private static $db_updates = array( | |
| 14 | + '1.2.0.0' => array( | |
| 15 | + 'uwp_upgrade_1200', | |
| 16 | + ), | |
| 17 | + '1.2.0.13' => array( | |
| 18 | + 'uwp_upgrade_12013', | |
| 19 | + ), | |
| 20 | + '1.2.2.5' => array( | |
| 21 | + 'uwp_upgrade_1225', | |
| 22 | + ), | |
| 23 | + '1.2.3' => array( | |
| 24 | + 'uwp_upgrade_1230', | |
| 25 | + ), | |
| 26 | + ); | |
| 22 | 27 | |
| 23 | - if (!get_option('uwp_default_data_installed')) { | |
| 24 | - // This is a fresh install | |
| 25 | - self::generate_pages(); | |
| 26 | - self::add_default_options(); | |
| 27 | - self::uwp_create_tables(); | |
| 28 | - self::uwp101_create_tables(); | |
| 29 | - self::uwp_insert_usermeta(); | |
| 30 | - self::uwp_create_default_fields(); | |
| 31 | - self::uwp_insert_form_extras(); | |
| 32 | - self::uwp_flush_rewrite_rules(); | |
| 33 | - update_option('uwp_activation_redirect', 1); | |
| 34 | - update_option('uwp_flush_rewrite', 1); | |
| 35 | - update_option('uwp_db_version', USERSWP_VERSION); | |
| 36 | - update_option('uwp_default_data_installed', 1); | |
| 37 | - } else { | |
| 38 | - // already installed | |
| 39 | - self::uwp_create_tables(); | |
| 40 | - self::uwp101_create_tables(); | |
| 41 | - update_option('uwp_db_version', USERSWP_VERSION); | |
| 42 | - } | |
| 43 | 28 | |
| 44 | - | |
| 45 | - | |
| 46 | - } | |
| 47 | - | |
| 48 | 29 | /** |
| 49 | - * Loads all dependencies during plugin activation. | |
| 30 | + * Background update class. | |
| 50 | 31 | * |
| 51 | - * @since 1.0.0 | |
| 52 | - * @package userswp | |
| 53 | - * @return void | |
| 32 | + * @var object | |
| 54 | 33 | */ |
| 55 | - public static function load_dependencies() { | |
| 56 | - require_once dirname( __FILE__ ) . '/class-tables.php'; | |
| 57 | - require_once dirname( __FILE__ ) . '/class-meta.php'; | |
| 58 | - require_once dirname( __FILE__ ) . '/class-pages.php'; | |
| 59 | - require_once dirname(dirname( __FILE__ )) . '/admin/settings/class-formbuilder.php'; | |
| 60 | - } | |
| 34 | + private static $background_updater; | |
| 61 | 35 | |
| 62 | 36 | /** |
| 63 | - * Generates the default pages during plugin activation. | |
| 37 | + * This method gets fired during plugin activation. | |
| 64 | 38 | * |
| 65 | 39 | * @since 1.0.0 |
| 66 | 40 | * @package userswp |
| 67 | 41 | * @return void |
| 68 | 42 | */ |
| 69 | - public static function generate_pages() { | |
| 70 | - uwp_generate_default_pages(); | |
| 71 | - } | |
| 43 | + public static function activate( $network_wide = false ) { | |
| 72 | 44 | |
| 73 | - /** | |
| 74 | - * Adds default settings during plugin activation. | |
| 75 | - * | |
| 76 | - * @since 1.0.0 | |
| 77 | - * @package userswp | |
| 78 | - * @return void | |
| 79 | - */ | |
| 80 | - public static function add_default_options() { | |
| 45 | + if ( is_multisite() ) { | |
| 46 | + $main_site = get_network()->site_id; | |
| 47 | + if ( $network_wide ) { | |
| 81 | 48 | |
| 82 | - $settings = get_option( 'uwp_settings', array()); | |
| 49 | + update_network_option( '', 'uwp_is_network_active', 1 ); | |
| 50 | + switch_to_blog( $main_site ); | |
| 51 | + restore_current_blog(); | |
| 83 | 52 | |
| 84 | - //general | |
| 85 | - if (!isset($settings['profile_no_of_items'])) { | |
| 86 | - $settings['profile_no_of_items'] = '10'; | |
| 87 | - } | |
| 88 | - | |
| 89 | - //login | |
| 90 | - if (!isset($settings['login_redirect_to'])) { | |
| 91 | - $settings['login_redirect_to'] = ''; | |
| 92 | - } | |
| 53 | + if ( defined( 'UWP_ROOT_PAGES' ) ) { | |
| 54 | + if ( UWP_ROOT_PAGES == 'all' ) { | |
| 55 | + $blog_ids = self::get_blog_ids(); | |
| 93 | 56 | |
| 94 | - //profile | |
| 95 | - if (!isset($settings['enable_profile_header'])) { | |
| 96 | - $settings['enable_profile_header'] = '1'; | |
| 97 | - } | |
| 98 | - if (!isset($settings['enable_profile_body'])) { | |
| 99 | - $settings['enable_profile_body'] = '1'; | |
| 100 | - } | |
| 101 | - if (!isset($settings['enable_profile_posts_tab'])) { | |
| 102 | - $settings['enable_profile_posts_tab'] = '1'; | |
| 103 | - } | |
| 104 | - if (!isset($settings['enable_profile_comments_tab'])) { | |
| 105 | - $settings['enable_profile_comments_tab'] = '1'; | |
| 106 | - } | |
| 107 | - | |
| 108 | - if (isset($settings['enable_profile_tabs']) && is_array($settings['enable_profile_tabs'])) { | |
| 109 | - if (!isset($settings['enable_profile_tabs']['more_info'])) { | |
| 110 | - $settings['enable_profile_tabs'][] = 'more_info'; | |
| 57 | + foreach ( $blog_ids as $blog_id ) { | |
| 58 | + switch_to_blog( $blog_id ); | |
| 59 | + self::install(); | |
| 60 | + } | |
| 61 | + restore_current_blog(); | |
| 62 | + } else { | |
| 63 | + $blog_id = UWP_ROOT_PAGES; | |
| 64 | + switch_to_blog( $blog_id ); | |
| 65 | + self::install(); | |
| 66 | + restore_current_blog(); | |
| 67 | + } | |
| 68 | + } else { | |
| 69 | + switch_to_blog( $main_site ); | |
| 70 | + self::install(); | |
| 71 | + restore_current_blog(); | |
| 72 | + } | |
| 73 | +} else { | |
| 74 | + self::install(); | |
| 111 | 75 | } |
| 112 | - if (!isset($settings['enable_profile_tabs']['posts'])) { | |
| 113 | - $settings['enable_profile_tabs'][] = 'posts'; | |
| 114 | - } | |
| 115 | - if (!isset($settings['enable_profile_tabs']['comments'])) { | |
| 116 | - $settings['enable_profile_tabs'][] = 'comments'; | |
| 117 | - } | |
| 118 | 76 | } else { |
| 119 | - $settings['enable_profile_tabs'] = array('more_info', 'posts', 'comments'); | |
| 77 | + self::install(); | |
| 120 | 78 | } |
| 79 | + } | |
| 121 | 80 | |
| 81 | + public static function install() { | |
| 122 | 82 | |
| 123 | - //notifications | |
| 83 | + uwp_generate_default_pages(); | |
| 84 | + self::add_default_options(); | |
| 85 | + uwp_create_tables(); | |
| 124 | 86 | |
| 125 | - // admin | |
| 126 | - $registration_success_email_subject_admin = __( 'New account registration', 'userswp' ); | |
| 127 | - $registration_success_email_content_admin = __("A user has been registered recently on your website. [#extras#]", "userswp"); | |
| 87 | + // run update functions if needed | |
| 88 | + if ( self::needs_db_update() ) { | |
| 89 | + self::update(); | |
| 90 | + } | |
| 128 | 91 | |
| 129 | - if (!isset($settings['registration_success_email_subject_admin'])) { | |
| 130 | - $settings['registration_success_email_subject_admin'] = $registration_success_email_subject_admin; | |
| 92 | + if ( ! get_option( 'uwp_default_data_installed' ) ) { | |
| 93 | + // new install | |
| 94 | + self::create_default_fields(); | |
| 95 | + self::insert_form_extras(); | |
| 96 | + update_option( 'uwp_default_data_installed', 1 ); | |
| 97 | + update_option( 'uwp_activation_redirect', 1 ); | |
| 98 | + } else { | |
| 99 | + // upgrade | |
| 100 | + // if updating from < 1.2.0 then add the try bootstrap notice | |
| 101 | + if ( version_compare( get_option( 'uwp_db_version', null ), '1.2.0', '<' ) ) { | |
| 102 | + update_option( 'uwp_notice_try_bootstrap', true ); | |
| 103 | + uwp_update_option( 'design_style', '' ); | |
| 104 | + } | |
| 131 | 105 | } |
| 132 | - if (!isset($settings['registration_success_email_content_admin'])) { | |
| 133 | - $settings['registration_success_email_content_admin'] = $registration_success_email_content_admin; | |
| 134 | - } | |
| 135 | 106 | |
| 107 | + self::flush_rewrite_rules(); | |
| 108 | + update_option( 'uwp_flush_rewrite', 1 ); | |
| 136 | 109 | |
| 137 | - // User | |
| 110 | + // update the version | |
| 111 | + update_option( 'uwp_db_version', USERSWP_VERSION ); | |
| 138 | 112 | |
| 139 | - // Register | |
| 140 | - $registration_success_email_subject = __('Your Log In Details', 'userswp'); | |
| 141 | - $registration_success_email_content = __("<p>Dear [#user_name#],</p><p>You can log in with the following information:</p>[#login_details#]<p>You can login here: [#login_url#]</p><p>Thank you,<br /><br />[#site_name_url#].</p>" ,'userswp'); | |
| 113 | + $installed = get_option( 'uwp_installed_on' ); | |
| 142 | 114 | |
| 143 | - if (!isset($settings['registration_success_email_subject'])) { | |
| 144 | - $settings['registration_success_email_subject'] = $registration_success_email_subject; | |
| 145 | - } | |
| 146 | - if (!isset($settings['registration_success_email_content'])) { | |
| 147 | - $settings['registration_success_email_content'] = $registration_success_email_content; | |
| 148 | - } | |
| 115 | + if ( empty( $installed ) ) { | |
| 116 | + update_option( 'uwp_installed_on', time() ); | |
| 117 | + } | |
| 118 | + } | |
| 149 | 119 | |
| 150 | - // Activate | |
| 151 | - $registration_activate_email_subject = __('Please activate your account', 'userswp'); | |
| 152 | - $registration_activate_email_content = __("<p>Dear [#user_name#],</p><p>Thank you for signing up with [#site_name#]</p>[#login_details#]<p>Thank you,<br /><br />[#site_name_url#].</p>" ,'userswp'); | |
| 120 | + /** | |
| 121 | + * Get all IDs of blogs that are not activated, not spam, and not deleted | |
| 122 | + * | |
| 123 | + * @global object $wpdb | |
| 124 | + * @return array|false Array of IDs or false if none are found | |
| 125 | + */ | |
| 126 | + public static function get_blog_ids() { | |
| 127 | + global $wpdb; | |
| 153 | 128 | |
| 154 | - if (!isset($settings['registration_activate_email_subject'])) { | |
| 155 | - $settings['registration_activate_email_subject'] = $registration_activate_email_subject; | |
| 156 | - } | |
| 157 | - if (!isset($settings['registration_activate_email_content'])) { | |
| 158 | - $settings['registration_activate_email_content'] = $registration_activate_email_content; | |
| 159 | - } | |
| 129 | + // Get an array of IDs | |
| 130 | + $sql = "SELECT blog_id FROM $wpdb->blogs | |
| 131 | + WHERE archived = '0' AND spam = '0' | |
| 132 | + AND deleted = '0'"; | |
| 160 | 133 | |
| 161 | - // Forgot | |
| 162 | - $forgot_password_email_subject = __('[#site_name#] - Your new password', 'userswp'); | |
| 163 | - $forgot_password_email_content = __("<p>Dear [#user_name#],</p>[#login_details#]<p>You can login here: [#login_url#]</p><p>Thank you,<br /><br />[#site_name_url#].</p>" ,'userswp'); | |
| 134 | + return $wpdb->get_col( $sql ); | |
| 135 | + } | |
| 164 | 136 | |
| 165 | - if (!isset($settings['forgot_password_email_subject'])) { | |
| 166 | - $settings['forgot_password_email_subject'] = $forgot_password_email_subject; | |
| 167 | - } | |
| 168 | - if (!isset($settings['forgot_password_email_content'])) { | |
| 169 | - $settings['forgot_password_email_content'] = $forgot_password_email_content; | |
| 170 | - } | |
| 137 | + /** | |
| 138 | + * Adds default settings during plugin activation. | |
| 139 | + * | |
| 140 | + * @since 1.0.0 | |
| 141 | + * @package userswp | |
| 142 | + * @return void | |
| 143 | + */ | |
| 144 | + public static function add_default_options() { | |
| 171 | 145 | |
| 172 | - // Change | |
| 173 | - $change_password_email_subject = __('[#site_name#] - Password has been changed', 'userswp'); | |
| 174 | - $change_password_email_content = __("<p>Dear [#user_name#],</p><p>Your password has been changed successfully.</p><p>You can login here: [#login_url#]</p><p>Thank you,<br /><br />[#site_name_url#].</p>" ,'userswp'); | |
| 146 | + $settings = get_option( 'uwp_settings', array() ); | |
| 175 | 147 | |
| 176 | - if (!isset($settings['change_password_email_subject'])) { | |
| 177 | - $settings['change_password_email_subject'] = $change_password_email_subject; | |
| 178 | - } | |
| 179 | - if (!isset($settings['change_password_email_content'])) { | |
| 180 | - $settings['change_password_email_content'] = $change_password_email_content; | |
| 181 | - } | |
| 148 | + $options = array( | |
| 149 | + 'register_modal' => 1, | |
| 150 | + 'uwp_registration_action' => 'auto_approve', | |
| 151 | + 'wp_register_redirect' => 1, | |
| 152 | + 'login_modal' => 1, | |
| 153 | + 'login_redirect_to' => -1, | |
| 154 | + 'block_wp_login' => 0, | |
| 155 | + 'disable_wp_2fa' => 0, | |
| 156 | + 'forgot_modal' => 1, | |
| 157 | + 'change_enable_old_password' => 1, | |
| 158 | + 'change_disable_password_nag' => 0, | |
| 159 | + 'enable_profile_header' => 1, | |
| 160 | + 'enable_profile_body' => 1, | |
| 161 | + 'profile_avatar_size' => '', | |
| 162 | + 'profile_banner_size' => '', | |
| 163 | + 'profile_banner_width' => 1000, | |
| 164 | + 'profile_no_of_items' => 10, | |
| 165 | + 'users_no_of_items' => 10, | |
| 166 | + 'uwp_disable_author_link' => 0, | |
| 167 | + 'users_default_layout' => '3col', | |
| 168 | + 'author_box_enable_disable' => 1, | |
| 169 | + 'author_box_display_content' => 'below_content', | |
| 170 | + 'author_box_display_post_types' => array( 'post' ), | |
| 171 | + 'author_box_content' => '', | |
| 172 | + 'author_box_bio_limit' => 200, | |
| 173 | + 'registration_success_email_admin' => 1, | |
| 174 | + 'registration_success_email_subject_admin' => UsersWP_Defaults::registration_success_email_subject_admin(), | |
| 175 | + 'registration_success_email_content_admin' => UsersWP_Defaults::registration_success_email_content_admin(), | |
| 176 | + 'registration_activate_email' => 1, | |
| 177 | + 'registration_activate_email_subject' => UsersWP_Defaults::registration_activate_email_subject(), | |
| 178 | + 'registration_activate_email_content' => UsersWP_Defaults::registration_activate_email_content(), | |
| 179 | + 'registration_success_email' => 1, | |
| 180 | + 'registration_success_email_subject' => UsersWP_Defaults::registration_success_email_subject(), | |
| 181 | + 'registration_success_email_content' => UsersWP_Defaults::registration_success_email_content(), | |
| 182 | + 'forgot_password_email' => 1, | |
| 183 | + 'forgot_password_email_subject' => UsersWP_Defaults::forgot_password_email_subject(), | |
| 184 | + 'forgot_password_email_content' => UsersWP_Defaults::forgot_password_email_content(), | |
| 185 | + 'change_password_email' => 1, | |
| 186 | + 'change_password_email_subject' => UsersWP_Defaults::change_password_email_subject(), | |
| 187 | + 'change_password_email_content' => UsersWP_Defaults::change_password_email_content(), | |
| 188 | + 'reset_password_email' => 1, | |
| 189 | + 'reset_password_email_subject' => UsersWP_Defaults::reset_password_email_subject(), | |
| 190 | + 'reset_password_email_content' => UsersWP_Defaults::reset_password_email_content(), | |
| 191 | + 'account_update_email' => 1, | |
| 192 | + 'account_update_email_subject' => UsersWP_Defaults::account_update_email_subject(), | |
| 193 | + 'account_update_email_content' => UsersWP_Defaults::account_update_email_content(), | |
| 194 | + 'account_delete_email' => 1, | |
| 195 | + 'account_delete_email_subject' => UsersWP_Defaults::account_delete_email_subject(), | |
| 196 | + 'account_delete_email_content' => UsersWP_Defaults::account_delete_email_content(), | |
| 197 | + 'account_delete_email_admin' => 1, | |
| 198 | + 'account_delete_email_subject_admin' => UsersWP_Defaults::account_delete_email_subject_admin(), | |
| 199 | + 'account_delete_email_content_admin' => UsersWP_Defaults::account_delete_email_content_admin(), | |
| 200 | + 'wp_new_user_notification_email' => 1, | |
| 201 | + 'wp_new_user_notification_email_subject' => UsersWP_Defaults::wp_new_user_notification_email_subject(), | |
| 202 | + 'wp_new_user_notification_email_content' => UsersWP_Defaults::wp_new_user_notification_email_content(), | |
| 203 | + 'account_new_email_activation_email' => 1, | |
| 204 | + 'account_new_email_activation_email_subject' => UsersWP_Defaults::account_new_email_activation_email_subject(), | |
| 205 | + 'account_new_email_activation_email_content' => UsersWP_Defaults::account_new_email_activation_email_content(), | |
| 206 | + 'wp_new_user_notification_email_admin' => 1, | |
| 207 | + 'wp_new_user_notification_email_subject_admin' => UsersWP_Defaults::wp_new_user_notification_email_subject_admin(), | |
| 208 | + 'wp_new_user_notification_email_content_admin' => UsersWP_Defaults::wp_new_user_notification_email_content_admin(), | |
| 209 | + 'user_post_counts_cpts' => array( 'post' ), | |
| 210 | + 'login_user_post_counts_cpts' => array( 'post' ), | |
| 211 | + 'multiple_registration_forms' => uwp_get_default_form_data(), | |
| 212 | + 'profile_seo_meta_description_length' => 150, | |
| 213 | + ); | |
| 182 | 214 | |
| 183 | - // Reset | |
| 184 | - $reset_password_email_subject = __('[#site_name#] - Password has been reset', 'userswp'); | |
| 185 | - $reset_password_email_content = __("<p>Dear [#user_name#],</p><p>Your password has been reset</p><p>You can login here: [#login_url#]</p><p>Thank you,<br /><br />[#site_name_url#].</p>" ,'userswp'); | |
| 186 | - | |
| 187 | - if (!isset($settings['reset_password_email_subject'])) { | |
| 188 | - $settings['reset_password_email_subject'] = $reset_password_email_subject; | |
| 215 | + foreach ( $options as $option => $value ) { | |
| 216 | + if ( ! isset( $settings[ $option ] ) ) { | |
| 217 | + $settings[ $option ] = $value; | |
| 218 | + } | |
| 189 | 219 | } |
| 190 | - if (!isset($settings['reset_password_email_content'])) { | |
| 191 | - $settings['reset_password_email_content'] = $reset_password_email_content; | |
| 192 | - } | |
| 193 | 220 | |
| 194 | - // Update | |
| 195 | - $account_update_email_subject = __('[#site_name#] - Account has been updated', 'userswp'); | |
| 196 | - $account_update_email_content = __("<p>Dear [#user_name#],</p><p>Your account has been updated successfully</p><p>Thank you,<br /><br />[#site_name_url#].</p>" ,'userswp'); | |
| 221 | + update_option( 'uwp_settings', $settings ); | |
| 222 | + } | |
| 197 | 223 | |
| 198 | - if (!isset($settings['account_update_email_subject'])) { | |
| 199 | - $settings['account_update_email_subject'] = $account_update_email_subject; | |
| 224 | + public static function init_background_updater() { | |
| 225 | + if ( empty( self::$background_updater ) ) { | |
| 226 | + include_once __DIR__ . '/class-uwp-background-updater.php'; | |
| 227 | + self::$background_updater = new UsersWP_Background_Updater(); | |
| 200 | 228 | } |
| 201 | - if (!isset($settings['account_update_email_content'])) { | |
| 202 | - $settings['account_update_email_content'] = $account_update_email_content; | |
| 203 | - } | |
| 204 | - | |
| 205 | - update_option( 'uwp_settings', $settings ); | |
| 206 | - | |
| 207 | 229 | } |
| 208 | 230 | |
| 209 | 231 | /** |
| 210 | - * Creates tables during plugin activation. | |
| 232 | + * Syncs WP usermeta with UsersWP usermeta during plugin activation. | |
| 211 | 233 | * |
| 212 | 234 | * @since 1.0.0 |
| 213 | 235 | * @package userswp |
| 214 | 236 | * @return void |
| 215 | 237 | */ |
| 216 | - public static function uwp_create_tables() | |
| 217 | - { | |
| 218 | - uwp_create_tables(); | |
| 238 | + public static function uwp_update_usermeta( $dispatch = false ) { | |
| 239 | + $update_callback = 'uwp_insert_usermeta'; | |
| 240 | + self::init_background_updater(); | |
| 241 | + | |
| 242 | + uwp_error_log( sprintf( 'Queuing %s - %s', USERSWP_VERSION, $update_callback ) ); | |
| 243 | + self::$background_updater->push_to_queue( $update_callback ); | |
| 244 | + if ( $dispatch ) { | |
| 245 | + self::$background_updater->save()->dispatch(); | |
| 246 | + } | |
| 219 | 247 | } |
| 220 | 248 | |
| 221 | 249 | /** |
| 222 | - * Creates the new tables added in version 1.0.1 during plugin activation. | |
| 250 | + * Get list of DB update callbacks. | |
| 223 | 251 | * |
| 224 | - * @since 1.0.0 | |
| 225 | - * @package userswp | |
| 226 | - * @return void | |
| 252 | + * @since 3.0.0 | |
| 253 | + * @return array | |
| 227 | 254 | */ |
| 228 | - public static function uwp101_create_tables() { | |
| 229 | - uwp101_create_tables(); | |
| 255 | + public static function get_db_update_callbacks() { | |
| 256 | + return self::$db_updates; | |
| 230 | 257 | } |
| 231 | 258 | |
| 232 | 259 | /** |
| 233 | - * Syncs WP usermeta with UsersWP usermeta during plugin activation. | |
| 260 | + * Is a DB update needed? | |
| 234 | 261 | * |
| 235 | - * @since 1.0.0 | |
| 236 | - * @package userswp | |
| 237 | - * @return void | |
| 262 | + * @since 2.0.0 | |
| 263 | + * @return boolean | |
| 238 | 264 | */ |
| 239 | - public static function uwp_insert_usermeta() | |
| 240 | - { | |
| 241 | - global $wpdb; | |
| 242 | - $sort= "user_registered"; | |
| 243 | - $all_users_id = $wpdb->get_col( $wpdb->prepare( | |
| 244 | - "SELECT $wpdb->users.ID FROM $wpdb->users ORDER BY %s ASC" | |
| 245 | - , $sort )); | |
| 265 | + private static function needs_db_update() { | |
| 266 | + $current_db_version = get_option( 'uwp_db_version', null ); | |
| 267 | + $updates = self::get_db_update_callbacks(); | |
| 246 | 268 | |
| 247 | - //we got all the IDs, now loop through them to get individual IDs | |
| 248 | - foreach ( $all_users_id as $user_id ) { | |
| 249 | - // get user info by calling get_userdata() on each id | |
| 250 | - $user_data = get_userdata($user_id); | |
| 251 | - $first_name = get_user_meta( $user_id, 'first_name', true ); | |
| 252 | - $last_name = get_user_meta( $user_id, 'last_name', true ); | |
| 253 | - $bio = get_user_meta( $user_id, 'description', true ); | |
| 254 | - uwp_update_usermeta($user_id, 'uwp_account_username', $user_data->user_login); | |
| 255 | - uwp_update_usermeta($user_id, 'uwp_account_email', $user_data->user_email); | |
| 256 | - uwp_update_usermeta($user_id, 'uwp_account_first_name', $first_name); | |
| 257 | - uwp_update_usermeta($user_id, 'uwp_account_last_name', $last_name); | |
| 258 | - uwp_update_usermeta($user_id, 'uwp_account_bio', $bio); | |
| 269 | + return ! is_null( $current_db_version ) && ! empty( $updates ) && version_compare( $current_db_version, max( array_keys( $updates ) ), '<' ); | |
| 270 | + } | |
| 271 | + | |
| 272 | + /** | |
| 273 | + * Push all needed DB updates to the queue for processing. | |
| 274 | + * | |
| 275 | + * @since 2.0.0 | |
| 276 | + */ | |
| 277 | + private static function update() { | |
| 278 | + $current_db_version = get_option( 'uwp_db_version' ); | |
| 279 | + $update_queued = false; | |
| 280 | + self::init_background_updater(); | |
| 281 | + foreach ( self::get_db_update_callbacks() as $version => $update_callbacks ) { | |
| 282 | + if ( version_compare( $current_db_version, $version, '<' ) ) { | |
| 283 | + foreach ( $update_callbacks as $update_callback ) { | |
| 284 | + uwp_error_log( sprintf( 'Queuing %s - %s', $version, $update_callback ) ); | |
| 285 | + self::$background_updater->push_to_queue( $update_callback ); | |
| 286 | + $update_queued = true; | |
| 287 | + } | |
| 288 | + } | |
| 259 | 289 | } |
| 290 | + | |
| 291 | + if ( $update_queued ) { | |
| 292 | + self::uwp_update_usermeta();// make sure to sync user meta | |
| 293 | + self::$background_updater->save()->dispatch(); | |
| 294 | + } else { | |
| 295 | + self::uwp_update_usermeta( true );// make sure to sync user meta | |
| 296 | + } | |
| 260 | 297 | } |
| 261 | 298 | |
| 262 | 299 | /** |
| 263 | 300 | * Saves default custom fields in the database. |
| @@ -265,18 +302,17 @@ | ||
| 265 | 302 | * @since 1.0.0 |
| 266 | 303 | * @package userswp |
| 267 | 304 | * @return void |
| 268 | 305 | */ |
| 269 | - public static function uwp_create_default_fields() | |
| 270 | - { | |
| 306 | + public static function create_default_fields() { | |
| 271 | 307 | $form_builder = new UsersWP_Form_Builder(); |
| 272 | 308 | |
| 273 | 309 | $fields = self::uwp_default_custom_fields(); |
| 274 | 310 | |
| 275 | - $fields = apply_filters('uwp_before_default_custom_fields_saved', $fields); | |
| 311 | + $fields = apply_filters( 'uwp_before_default_custom_fields_saved', $fields ); | |
| 276 | 312 | |
| 277 | - foreach ($fields as $field_index => $field) { | |
| 278 | - $form_builder->uwp_admin_form_field_save($field); | |
| 313 | + foreach ( $fields as $field_index => $field ) { | |
| 314 | + $form_builder->admin_form_field_save( $field ); | |
| 279 | 315 | } |
| 280 | 316 | } |
| 281 | 317 | |
| 282 | 318 | /** |
| @@ -285,9 +321,9 @@ | ||
| 285 | 321 | * @since 1.0.0 |
| 286 | 322 | * @package userswp |
| 287 | 323 | * @return array Merged custom fields. |
| 288 | 324 | */ |
| 289 | - public static function uwp_default_custom_fields(){ | |
| 325 | + public static function uwp_default_custom_fields() { | |
| 290 | 326 | |
| 291 | 327 | $login = self::uwp_default_custom_fields_login(); |
| 292 | 328 | $forgot = self::uwp_default_custom_fields_forgot(); |
| 293 | 329 | $avatar = self::uwp_default_custom_fields_avatar(); |
| @@ -295,14 +331,13 @@ | ||
| 295 | 331 | $change = self::uwp_default_custom_fields_change(); |
| 296 | 332 | $reset = self::uwp_default_custom_fields_reset(); |
| 297 | 333 | $account = self::uwp_default_custom_fields_account(); |
| 298 | 334 | |
| 299 | - $fields = array_merge($login, $forgot, $account, $avatar, $banner, $change, $reset); | |
| 335 | + $fields = array_merge( $login, $forgot, $account, $avatar, $banner, $change, $reset ); | |
| 300 | 336 | |
| 301 | - $fields = apply_filters('uwp_default_custom_fields', $fields); | |
| 337 | + $fields = apply_filters( 'uwp_default_custom_fields', $fields ); | |
| 302 | 338 | |
| 303 | 339 | return $fields; |
| 304 | - | |
| 305 | 340 | } |
| 306 | 341 | |
| 307 | 342 | /** |
| 308 | 343 | * Returns Login form default custom fields. |
| @@ -310,39 +345,39 @@ | ||
| 310 | 345 | * @since 1.0.0 |
| 311 | 346 | * @package userswp |
| 312 | 347 | * @return array Login form default custom fields. |
| 313 | 348 | */ |
| 314 | - public static function uwp_default_custom_fields_login(){ | |
| 349 | + public static function uwp_default_custom_fields_login() { | |
| 315 | 350 | |
| 316 | 351 | $fields = array(); |
| 317 | 352 | |
| 318 | 353 | $fields[] = array( |
| 319 | - 'form_type' => 'login', | |
| 320 | - 'field_type' => 'text', | |
| 321 | - 'data_type' => 'XVARCHAR', | |
| 322 | - 'site_title' => __('Username', 'userswp'), | |
| 323 | - 'htmlvar_name' => 'username', | |
| 354 | + 'form_type' => 'login', | |
| 355 | + 'field_type' => 'text', | |
| 356 | + 'data_type' => 'XVARCHAR', | |
| 357 | + 'site_title' => __( 'Username', 'userswp' ), | |
| 358 | + 'htmlvar_name' => 'username', | |
| 324 | 359 | 'default_value' => '', |
| 325 | 360 | 'option_values' => '', |
| 326 | - 'is_default' => '1', | |
| 327 | - 'is_active' => '1', | |
| 328 | - 'is_required' => '1' | |
| 361 | + 'is_default' => '1', | |
| 362 | + 'is_active' => '1', | |
| 363 | + 'is_required' => '1', | |
| 329 | 364 | ); |
| 330 | 365 | |
| 331 | 366 | $fields[] = array( |
| 332 | - 'form_type' => 'login', | |
| 333 | - 'field_type' => 'password', | |
| 334 | - 'data_type' => 'XVARCHAR', | |
| 335 | - 'site_title' => __('Password', 'userswp'), | |
| 336 | - 'htmlvar_name' => 'password', | |
| 367 | + 'form_type' => 'login', | |
| 368 | + 'field_type' => 'password', | |
| 369 | + 'data_type' => 'XVARCHAR', | |
| 370 | + 'site_title' => __( 'Password', 'userswp' ), | |
| 371 | + 'htmlvar_name' => 'password', | |
| 337 | 372 | 'default_value' => '', |
| 338 | 373 | 'option_values' => '', |
| 339 | - 'is_default' => '1', | |
| 340 | - 'is_active' => '1', | |
| 341 | - 'is_required' => '1' | |
| 374 | + 'is_default' => '1', | |
| 375 | + 'is_active' => '1', | |
| 376 | + 'is_required' => '1', | |
| 342 | 377 | ); |
| 343 | 378 | |
| 344 | - $fields = apply_filters('uwp_default_custom_fields_login', $fields); | |
| 379 | + $fields = apply_filters( 'uwp_default_custom_fields_login', $fields ); | |
| 345 | 380 | |
| 346 | 381 | return $fields; |
| 347 | 382 | } |
| 348 | 383 | |
| @@ -352,26 +387,26 @@ | ||
| 352 | 387 | * @since 1.0.0 |
| 353 | 388 | * @package userswp |
| 354 | 389 | * @return array Forgot form default custom fields. |
| 355 | 390 | */ |
| 356 | - public static function uwp_default_custom_fields_forgot(){ | |
| 391 | + public static function uwp_default_custom_fields_forgot() { | |
| 357 | 392 | |
| 358 | 393 | $fields = array(); |
| 359 | 394 | |
| 360 | 395 | $fields[] = array( |
| 361 | - 'form_type' => 'forgot', | |
| 362 | - 'field_type' => 'email', | |
| 363 | - 'data_type' => 'XVARCHAR', | |
| 364 | - 'site_title' => __('Email', 'userswp'), | |
| 365 | - 'htmlvar_name' => 'email', | |
| 396 | + 'form_type' => 'forgot', | |
| 397 | + 'field_type' => 'email', | |
| 398 | + 'data_type' => 'XVARCHAR', | |
| 399 | + 'site_title' => __( 'Email', 'userswp' ), | |
| 400 | + 'htmlvar_name' => 'email', | |
| 366 | 401 | 'default_value' => '', |
| 367 | 402 | 'option_values' => '', |
| 368 | - 'is_default' => '1', | |
| 369 | - 'is_active' => '1', | |
| 370 | - 'is_required' => '1' | |
| 403 | + 'is_default' => '1', | |
| 404 | + 'is_active' => '1', | |
| 405 | + 'is_required' => '1', | |
| 371 | 406 | ); |
| 372 | 407 | |
| 373 | - $fields = apply_filters('uwp_default_custom_fields_forgot', $fields); | |
| 408 | + $fields = apply_filters( 'uwp_default_custom_fields_forgot', $fields ); | |
| 374 | 409 | |
| 375 | 410 | return $fields; |
| 376 | 411 | } |
| 377 | 412 | |
| @@ -381,35 +416,35 @@ | ||
| 381 | 416 | * @since 1.0.0 |
| 382 | 417 | * @package userswp |
| 383 | 418 | * @return array Avatar form default custom fields. |
| 384 | 419 | */ |
| 385 | - public static function uwp_default_custom_fields_avatar(){ | |
| 420 | + public static function uwp_default_custom_fields_avatar() { | |
| 386 | 421 | |
| 387 | 422 | $fields = array(); |
| 388 | 423 | |
| 389 | 424 | $fields[] = array( |
| 390 | - 'form_type' => 'avatar', | |
| 391 | - 'field_type' => 'file', | |
| 392 | - 'data_type' => 'TEXT', | |
| 393 | - 'site_title' => __('Avatar', 'userswp'), | |
| 394 | - 'htmlvar_name' => 'file', | |
| 425 | + 'form_type' => 'avatar', | |
| 426 | + 'field_type' => 'file', | |
| 427 | + 'data_type' => 'TEXT', | |
| 428 | + 'site_title' => __( 'Avatar', 'userswp' ), | |
| 429 | + 'htmlvar_name' => 'avatar', | |
| 395 | 430 | 'default_value' => '', |
| 396 | 431 | 'option_values' => '', |
| 397 | - 'is_default' => '1', | |
| 398 | - 'is_active' => '1', | |
| 399 | - 'is_required' => '1', | |
| 400 | - 'extra_fields' => array( | |
| 401 | - 'uwp_file_types' => array( | |
| 432 | + 'is_default' => '1', | |
| 433 | + 'is_active' => '1', | |
| 434 | + 'is_required' => '1', | |
| 435 | + 'extra_fields' => array( | |
| 436 | + 'uwp_file_types' => array( | |
| 402 | 437 | 'jpg', |
| 403 | 438 | 'jpe', |
| 404 | 439 | 'jpeg', |
| 405 | 440 | 'gif', |
| 406 | - 'png' | |
| 441 | + 'png', | |
| 407 | 442 | ), |
| 408 | - ) | |
| 443 | + ), | |
| 409 | 444 | ); |
| 410 | 445 | |
| 411 | - $fields = apply_filters('uwp_default_custom_fields_avatar', $fields); | |
| 446 | + $fields = apply_filters( 'uwp_default_custom_fields_avatar', $fields ); | |
| 412 | 447 | |
| 413 | 448 | return $fields; |
| 414 | 449 | } |
| 415 | 450 | |
| @@ -419,35 +454,35 @@ | ||
| 419 | 454 | * @since 1.0.0 |
| 420 | 455 | * @package userswp |
| 421 | 456 | * @return array Banner form default custom fields. |
| 422 | 457 | */ |
| 423 | - public static function uwp_default_custom_fields_banner(){ | |
| 458 | + public static function uwp_default_custom_fields_banner() { | |
| 424 | 459 | |
| 425 | 460 | $fields = array(); |
| 426 | 461 | |
| 427 | 462 | $fields[] = array( |
| 428 | - 'form_type' => 'banner', | |
| 429 | - 'field_type' => 'file', | |
| 430 | - 'data_type' => 'TEXT', | |
| 431 | - 'site_title' => __('Banner', 'userswp'), | |
| 432 | - 'htmlvar_name' => 'file', | |
| 463 | + 'form_type' => 'banner', | |
| 464 | + 'field_type' => 'file', | |
| 465 | + 'data_type' => 'TEXT', | |
| 466 | + 'site_title' => __( 'Banner', 'userswp' ), | |
| 467 | + 'htmlvar_name' => 'banner', | |
| 433 | 468 | 'default_value' => '', |
| 434 | 469 | 'option_values' => '', |
| 435 | - 'is_default' => '1', | |
| 436 | - 'is_active' => '1', | |
| 437 | - 'is_required' => '1', | |
| 438 | - 'extra_fields' => array( | |
| 439 | - 'uwp_file_types' => array( | |
| 470 | + 'is_default' => '1', | |
| 471 | + 'is_active' => '1', | |
| 472 | + 'is_required' => '1', | |
| 473 | + 'extra_fields' => array( | |
| 474 | + 'uwp_file_types' => array( | |
| 440 | 475 | 'jpg', |
| 441 | 476 | 'jpe', |
| 442 | 477 | 'jpeg', |
| 443 | 478 | 'gif', |
| 444 | - 'png' | |
| 479 | + 'png', | |
| 445 | 480 | ), |
| 446 | - ) | |
| 481 | + ), | |
| 447 | 482 | ); |
| 448 | 483 | |
| 449 | - $fields = apply_filters('uwp_default_custom_fields_banner', $fields); | |
| 484 | + $fields = apply_filters( 'uwp_default_custom_fields_banner', $fields ); | |
| 450 | 485 | |
| 451 | 486 | return $fields; |
| 452 | 487 | } |
| 453 | 488 | |
| @@ -457,52 +492,52 @@ | ||
| 457 | 492 | * @since 1.0.0 |
| 458 | 493 | * @package userswp |
| 459 | 494 | * @return array Change Password form default custom fields. |
| 460 | 495 | */ |
| 461 | - public static function uwp_default_custom_fields_change(){ | |
| 496 | + public static function uwp_default_custom_fields_change() { | |
| 462 | 497 | |
| 463 | 498 | $fields = array(); |
| 464 | 499 | |
| 465 | 500 | $fields[] = array( |
| 466 | - 'form_type' => 'change', | |
| 467 | - 'field_type' => 'password', | |
| 468 | - 'data_type' => 'XVARCHAR', | |
| 469 | - 'site_title' => __('Old Password', 'userswp'), | |
| 470 | - 'htmlvar_name' => 'old_password', | |
| 501 | + 'form_type' => 'change', | |
| 502 | + 'field_type' => 'password', | |
| 503 | + 'data_type' => 'XVARCHAR', | |
| 504 | + 'site_title' => __( 'Old Password', 'userswp' ), | |
| 505 | + 'htmlvar_name' => 'old_password', | |
| 471 | 506 | 'default_value' => '', |
| 472 | 507 | 'option_values' => '', |
| 473 | - 'is_default' => '1', | |
| 474 | - 'is_active' => '1', | |
| 475 | - 'is_required' => '1' | |
| 508 | + 'is_default' => '1', | |
| 509 | + 'is_active' => '1', | |
| 510 | + 'is_required' => '1', | |
| 476 | 511 | ); |
| 477 | 512 | |
| 478 | 513 | $fields[] = array( |
| 479 | - 'form_type' => 'change', | |
| 480 | - 'field_type' => 'password', | |
| 481 | - 'data_type' => 'XVARCHAR', | |
| 482 | - 'site_title' => __('New Password', 'userswp'), | |
| 483 | - 'htmlvar_name' => 'password', | |
| 514 | + 'form_type' => 'change', | |
| 515 | + 'field_type' => 'password', | |
| 516 | + 'data_type' => 'XVARCHAR', | |
| 517 | + 'site_title' => __( 'New Password', 'userswp' ), | |
| 518 | + 'htmlvar_name' => 'password', | |
| 484 | 519 | 'default_value' => '', |
| 485 | 520 | 'option_values' => '', |
| 486 | - 'is_default' => '1', | |
| 487 | - 'is_active' => '1', | |
| 488 | - 'is_required' => '1' | |
| 521 | + 'is_default' => '1', | |
| 522 | + 'is_active' => '1', | |
| 523 | + 'is_required' => '1', | |
| 489 | 524 | ); |
| 490 | 525 | |
| 491 | 526 | $fields[] = array( |
| 492 | - 'form_type' => 'change', | |
| 493 | - 'field_type' => 'password', | |
| 494 | - 'data_type' => 'XVARCHAR', | |
| 495 | - 'site_title' => __('Confirm Password', 'userswp'), | |
| 496 | - 'htmlvar_name' => 'confirm_password', | |
| 527 | + 'form_type' => 'change', | |
| 528 | + 'field_type' => 'password', | |
| 529 | + 'data_type' => 'XVARCHAR', | |
| 530 | + 'site_title' => __( 'Confirm Password', 'userswp' ), | |
| 531 | + 'htmlvar_name' => 'confirm_password', | |
| 497 | 532 | 'default_value' => '', |
| 498 | 533 | 'option_values' => '', |
| 499 | - 'is_default' => '1', | |
| 500 | - 'is_active' => '1', | |
| 501 | - 'is_required' => '1' | |
| 534 | + 'is_default' => '1', | |
| 535 | + 'is_active' => '1', | |
| 536 | + 'is_required' => '1', | |
| 502 | 537 | ); |
| 503 | 538 | |
| 504 | - $fields = apply_filters('uwp_default_custom_fields_change', $fields); | |
| 539 | + $fields = apply_filters( 'uwp_default_custom_fields_change', $fields ); | |
| 505 | 540 | |
| 506 | 541 | return $fields; |
| 507 | 542 | } |
| 508 | 543 | |
| @@ -512,39 +547,39 @@ | ||
| 512 | 547 | * @since 1.0.0 |
| 513 | 548 | * @package userswp |
| 514 | 549 | * @return array Reset Password form default custom fields. |
| 515 | 550 | */ |
| 516 | - public static function uwp_default_custom_fields_reset(){ | |
| 551 | + public static function uwp_default_custom_fields_reset() { | |
| 517 | 552 | |
| 518 | 553 | $fields = array(); |
| 519 | 554 | |
| 520 | 555 | $fields[] = array( |
| 521 | - 'form_type' => 'reset', | |
| 522 | - 'field_type' => 'password', | |
| 523 | - 'data_type' => 'XVARCHAR', | |
| 524 | - 'site_title' => __('Password', 'userswp'), | |
| 525 | - 'htmlvar_name' => 'password', | |
| 556 | + 'form_type' => 'reset', | |
| 557 | + 'field_type' => 'password', | |
| 558 | + 'data_type' => 'XVARCHAR', | |
| 559 | + 'site_title' => __( 'Password', 'userswp' ), | |
| 560 | + 'htmlvar_name' => 'password', | |
| 526 | 561 | 'default_value' => '', |
| 527 | 562 | 'option_values' => '', |
| 528 | - 'is_default' => '1', | |
| 529 | - 'is_active' => '1', | |
| 530 | - 'is_required' => '1' | |
| 563 | + 'is_default' => '1', | |
| 564 | + 'is_active' => '1', | |
| 565 | + 'is_required' => '1', | |
| 531 | 566 | ); |
| 532 | 567 | |
| 533 | 568 | $fields[] = array( |
| 534 | - 'form_type' => 'reset', | |
| 535 | - 'field_type' => 'password', | |
| 536 | - 'data_type' => 'XVARCHAR', | |
| 537 | - 'site_title' => __('Confirm Password', 'userswp'), | |
| 538 | - 'htmlvar_name' => 'confirm_password', | |
| 569 | + 'form_type' => 'reset', | |
| 570 | + 'field_type' => 'password', | |
| 571 | + 'data_type' => 'XVARCHAR', | |
| 572 | + 'site_title' => __( 'Confirm Password', 'userswp' ), | |
| 573 | + 'htmlvar_name' => 'confirm_password', | |
| 539 | 574 | 'default_value' => '', |
| 540 | 575 | 'option_values' => '', |
| 541 | - 'is_default' => '1', | |
| 542 | - 'is_active' => '1', | |
| 543 | - 'is_required' => '1' | |
| 576 | + 'is_default' => '1', | |
| 577 | + 'is_active' => '1', | |
| 578 | + 'is_required' => '1', | |
| 544 | 579 | ); |
| 545 | 580 | |
| 546 | - $fields = apply_filters('uwp_default_custom_fields_reset', $fields); | |
| 581 | + $fields = apply_filters( 'uwp_default_custom_fields_reset', $fields ); | |
| 547 | 582 | |
| 548 | 583 | return $fields; |
| 549 | 584 | } |
| 550 | 585 | |
| @@ -554,131 +589,127 @@ | ||
| 554 | 589 | * @since 1.0.0 |
| 555 | 590 | * @package userswp |
| 556 | 591 | * @return array Account form default custom fields. |
| 557 | 592 | */ |
| 558 | - public static function uwp_default_custom_fields_account(){ | |
| 593 | + public static function uwp_default_custom_fields_account() { | |
| 559 | 594 | |
| 560 | 595 | $fields = array(); |
| 561 | 596 | |
| 562 | 597 | $fields[] = array( |
| 563 | - 'form_type' => 'account', | |
| 564 | - 'field_type' => 'text', | |
| 565 | - 'data_type' => 'XVARCHAR', | |
| 566 | - 'site_title' => __('First Name', 'userswp'), | |
| 567 | - 'htmlvar_name' => 'first_name', | |
| 568 | - 'default_value' => '', | |
| 569 | - 'option_values' => '', | |
| 570 | - 'is_default' => '1', | |
| 571 | - 'is_public' => '1', | |
| 572 | - 'is_active' => '1', | |
| 573 | - 'is_required' => '1', | |
| 598 | + 'form_type' => 'account', | |
| 599 | + 'field_type' => 'text', | |
| 600 | + 'data_type' => 'XVARCHAR', | |
| 601 | + 'site_title' => __( 'First Name', 'userswp' ), | |
| 602 | + 'htmlvar_name' => 'first_name', | |
| 603 | + 'default_value' => '', | |
| 604 | + 'option_values' => '', | |
| 605 | + 'is_default' => '1', | |
| 606 | + 'is_public' => '1', | |
| 607 | + 'is_active' => '1', | |
| 608 | + 'is_required' => '1', | |
| 574 | 609 | 'is_register_field' => '1', |
| 575 | - 'is_search_field' => '1', | |
| 576 | - 'css_class' => 'uwp-half uwp-half-left', | |
| 610 | + 'is_search_field' => '1', | |
| 577 | 611 | ); |
| 578 | 612 | |
| 579 | 613 | $fields[] = array( |
| 580 | - 'form_type' => 'account', | |
| 581 | - 'field_type' => 'text', | |
| 582 | - 'data_type' => 'XVARCHAR', | |
| 583 | - 'site_title' => __('Last Name', 'userswp'), | |
| 584 | - 'htmlvar_name' => 'last_name', | |
| 585 | - 'default_value' => '', | |
| 586 | - 'option_values' => '', | |
| 587 | - 'is_default' => '1', | |
| 588 | - 'is_public' => '1', | |
| 589 | - 'is_active' => '1', | |
| 590 | - 'is_required' => '1', | |
| 614 | + 'form_type' => 'account', | |
| 615 | + 'field_type' => 'text', | |
| 616 | + 'data_type' => 'XVARCHAR', | |
| 617 | + 'site_title' => __( 'Last Name', 'userswp' ), | |
| 618 | + 'htmlvar_name' => 'last_name', | |
| 619 | + 'default_value' => '', | |
| 620 | + 'option_values' => '', | |
| 621 | + 'is_default' => '1', | |
| 622 | + 'is_public' => '1', | |
| 623 | + 'is_active' => '1', | |
| 624 | + 'is_required' => '1', | |
| 591 | 625 | 'is_register_field' => '1', |
| 592 | - 'is_search_field' => '1', | |
| 593 | - 'css_class' => 'uwp-half uwp-half-right', | |
| 626 | + 'is_search_field' => '1', | |
| 594 | 627 | ); |
| 595 | 628 | |
| 596 | 629 | $fields[] = array( |
| 597 | - 'form_type' => 'account', | |
| 598 | - 'field_type' => 'text', | |
| 599 | - 'data_type' => 'XVARCHAR', | |
| 600 | - 'site_title' => __('Username', 'userswp'), | |
| 601 | - 'htmlvar_name' => 'username', | |
| 602 | - 'default_value' => '', | |
| 603 | - 'option_values' => '', | |
| 604 | - 'is_default' => '1', | |
| 605 | - 'is_public' => '1', | |
| 606 | - 'is_active' => '1', | |
| 607 | - 'is_required' => '1', | |
| 608 | - 'is_register_field' => '1', | |
| 609 | - 'is_search_field' => '1', | |
| 630 | + 'form_type' => 'account', | |
| 631 | + 'field_type' => 'text', | |
| 632 | + 'data_type' => 'XVARCHAR', | |
| 633 | + 'site_title' => __( 'Username', 'userswp' ), | |
| 634 | + 'htmlvar_name' => 'username', | |
| 635 | + 'default_value' => '', | |
| 636 | + 'option_values' => '', | |
| 637 | + 'is_default' => '1', | |
| 638 | + 'is_public' => '1', | |
| 639 | + 'is_active' => '1', | |
| 640 | + 'is_required' => '1', | |
| 641 | + 'is_register_field' => '1', | |
| 642 | + 'is_search_field' => '1', | |
| 610 | 643 | 'is_register_only_field' => '1', |
| 611 | 644 | ); |
| 612 | 645 | |
| 613 | 646 | $fields[] = array( |
| 614 | - 'form_type' => 'account', | |
| 615 | - 'field_type' => 'text', | |
| 616 | - 'data_type' => 'XVARCHAR', | |
| 617 | - 'site_title' => __('Display Name', 'userswp'), | |
| 618 | - 'htmlvar_name' => 'display_name', | |
| 619 | - 'default_value' => '', | |
| 620 | - 'option_values' => '', | |
| 621 | - 'is_default' => '1', | |
| 622 | - 'is_public' => '1', | |
| 623 | - 'is_active' => '1', | |
| 624 | - 'is_required' => '0', | |
| 647 | + 'form_type' => 'account', | |
| 648 | + 'field_type' => 'text', | |
| 649 | + 'data_type' => 'XVARCHAR', | |
| 650 | + 'site_title' => __( 'Display Name', 'userswp' ), | |
| 651 | + 'htmlvar_name' => 'display_name', | |
| 652 | + 'default_value' => '', | |
| 653 | + 'option_values' => '', | |
| 654 | + 'is_default' => '1', | |
| 655 | + 'is_public' => '1', | |
| 656 | + 'is_active' => '1', | |
| 657 | + 'is_required' => '0', | |
| 625 | 658 | 'is_register_field' => '0', |
| 626 | - 'is_search_field' => '1', | |
| 659 | + 'is_search_field' => '1', | |
| 627 | 660 | ); |
| 628 | 661 | |
| 629 | 662 | $fields[] = array( |
| 630 | - 'form_type' => 'account', | |
| 631 | - 'field_type' => 'email', | |
| 632 | - 'data_type' => 'XVARCHAR', | |
| 633 | - 'site_title' => __('Email', 'userswp'), | |
| 634 | - 'htmlvar_name' => 'email', | |
| 635 | - 'default_value' => '', | |
| 636 | - 'option_values' => '', | |
| 637 | - 'is_default' => '1', | |
| 638 | - 'is_active' => '1', | |
| 639 | - 'is_required' => '1', | |
| 663 | + 'form_type' => 'account', | |
| 664 | + 'field_type' => 'email', | |
| 665 | + 'data_type' => 'XVARCHAR', | |
| 666 | + 'site_title' => __( 'Email', 'userswp' ), | |
| 667 | + 'htmlvar_name' => 'email', | |
| 668 | + 'default_value' => '', | |
| 669 | + 'option_values' => '', | |
| 670 | + 'is_default' => '1', | |
| 671 | + 'is_active' => '1', | |
| 672 | + 'is_required' => '1', | |
| 640 | 673 | 'is_register_field' => '1', |
| 641 | - 'is_search_field' => '1', | |
| 674 | + 'is_search_field' => '1', | |
| 642 | 675 | ); |
| 643 | 676 | |
| 644 | - | |
| 645 | 677 | $fields[] = array( |
| 646 | - 'form_type' => 'account', | |
| 647 | - 'field_type' => 'textarea', | |
| 648 | - 'data_type' => 'TEXT', | |
| 649 | - 'site_title' => __('Bio', 'userswp'), | |
| 650 | - 'htmlvar_name' => 'bio', | |
| 651 | - 'default_value' => '', | |
| 652 | - 'option_values' => '', | |
| 653 | - 'is_default' => '1', | |
| 654 | - 'is_active' => '1', | |
| 655 | - 'is_public' => '1', | |
| 656 | - 'is_required' => '1', | |
| 678 | + 'form_type' => 'account', | |
| 679 | + 'field_type' => 'textarea', | |
| 680 | + 'data_type' => 'TEXT', | |
| 681 | + 'site_title' => __( 'Bio', 'userswp' ), | |
| 682 | + 'htmlvar_name' => 'bio', | |
| 683 | + 'default_value' => '', | |
| 684 | + 'option_values' => '', | |
| 685 | + 'is_default' => '0', | |
| 686 | + 'is_active' => '1', | |
| 687 | + 'is_public' => '1', | |
| 688 | + 'is_required' => '1', | |
| 657 | 689 | 'is_search_field' => '1', |
| 658 | - 'show_in' => array('[profile_side]', '[users]') | |
| 690 | + 'show_in' => array( '[users]' ), | |
| 659 | 691 | ); |
| 660 | 692 | |
| 661 | 693 | $fields[] = array( |
| 662 | - 'form_type' => 'account', | |
| 663 | - 'field_type' => 'password', | |
| 664 | - 'data_type' => 'XVARCHAR', | |
| 665 | - 'site_title' => __('Password', 'userswp'), | |
| 666 | - 'htmlvar_name' => 'password', | |
| 667 | - 'default_value' => '', | |
| 668 | - 'option_values' => '', | |
| 669 | - 'is_default' => '1', | |
| 670 | - 'is_active' => '1', | |
| 671 | - 'is_required' => '1', | |
| 672 | - 'is_register_field' => '1', | |
| 694 | + 'form_type' => 'account', | |
| 695 | + 'field_type' => 'password', | |
| 696 | + 'data_type' => 'XVARCHAR', | |
| 697 | + 'site_title' => __( 'Password', 'userswp' ), | |
| 698 | + 'htmlvar_name' => 'password', | |
| 699 | + 'default_value' => '', | |
| 700 | + 'option_values' => '', | |
| 701 | + 'is_default' => '1', | |
| 702 | + 'is_active' => '1', | |
| 703 | + 'is_required' => '1', | |
| 704 | + 'is_register_field' => '1', | |
| 673 | 705 | 'is_register_only_field' => '1', |
| 674 | - 'extra' => array( | |
| 675 | - 'confirm_password' => '1' | |
| 676 | - ) | |
| 706 | + 'extra' => array( | |
| 707 | + 'confirm_password' => '1', | |
| 708 | + ), | |
| 677 | 709 | ); |
| 678 | - | |
| 679 | 710 | |
| 680 | - $fields = apply_filters('uwp_default_custom_fields_account', $fields); | |
| 711 | + $fields = apply_filters( 'uwp_default_custom_fields_account', $fields ); | |
| 681 | 712 | |
| 682 | 713 | return $fields; |
| 683 | 714 | } |
| 684 | 715 | |
| @@ -688,9 +719,9 @@ | ||
| 688 | 719 | * @since 1.0.0 |
| 689 | 720 | * @package userswp |
| 690 | 721 | * @return void |
| 691 | 722 | */ |
| 692 | - public static function uwp_flush_rewrite_rules() { | |
| 723 | + public static function flush_rewrite_rules() { | |
| 693 | 724 | flush_rewrite_rules(); |
| 694 | 725 | } |
| 695 | 726 | |
| 696 | 727 | /** |
| @@ -699,9 +730,9 @@ | ||
| 699 | 730 | * @since 1.0.0 |
| 700 | 731 | * @package userswp |
| 701 | 732 | * @return void |
| 702 | 733 | */ |
| 703 | - public static function uwp_insert_form_extras() { | |
| 734 | + public static function insert_form_extras( $form_id = 1 ) { | |
| 704 | 735 | global $wpdb; |
| 705 | 736 | $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras'; |
| 706 | 737 | |
| 707 | 738 | $fields = array(); |
| @@ -706,61 +737,61 @@ | ||
| 706 | 737 | |
| 707 | 738 | $fields = array(); |
| 708 | 739 | |
| 709 | 740 | $fields[] = array( |
| 710 | - 'form_type' => 'register', | |
| 711 | - 'field_type' => 'text', | |
| 712 | - 'is_default' => '1', | |
| 713 | - 'htmlvar_name' => 'uwp_account_first_name' | |
| 741 | + 'form_type' => 'register', | |
| 742 | + 'field_type' => 'text', | |
| 743 | + 'is_default' => '0', | |
| 744 | + 'htmlvar_name' => 'first_name', | |
| 714 | 745 | ); |
| 715 | 746 | |
| 716 | 747 | $fields[] = array( |
| 717 | - 'form_type' => 'register', | |
| 718 | - 'field_type' => 'text', | |
| 719 | - 'is_default' => '1', | |
| 720 | - 'htmlvar_name' => 'uwp_account_last_name' | |
| 748 | + 'form_type' => 'register', | |
| 749 | + 'field_type' => 'text', | |
| 750 | + 'is_default' => '0', | |
| 751 | + 'htmlvar_name' => 'last_name', | |
| 721 | 752 | ); |
| 722 | 753 | |
| 723 | 754 | $fields[] = array( |
| 724 | - 'form_type' => 'register', | |
| 725 | - 'field_type' => 'text', | |
| 726 | - 'is_default' => '1', | |
| 727 | - 'htmlvar_name' => 'uwp_account_username' | |
| 755 | + 'form_type' => 'register', | |
| 756 | + 'field_type' => 'text', | |
| 757 | + 'is_default' => '1', | |
| 758 | + 'htmlvar_name' => 'username', | |
| 728 | 759 | ); |
| 729 | 760 | |
| 730 | 761 | $fields[] = array( |
| 731 | - 'form_type' => 'register', | |
| 732 | - 'field_type' => 'email', | |
| 733 | - 'is_default' => '1', | |
| 734 | - 'htmlvar_name' => 'uwp_account_email' | |
| 762 | + 'form_type' => 'register', | |
| 763 | + 'field_type' => 'email', | |
| 764 | + 'is_default' => '1', | |
| 765 | + 'htmlvar_name' => 'email', | |
| 735 | 766 | ); |
| 736 | 767 | |
| 737 | 768 | $fields[] = array( |
| 738 | - 'form_type' => 'register', | |
| 739 | - 'field_type' => 'password', | |
| 740 | - 'is_default' => '1', | |
| 741 | - 'htmlvar_name' => 'uwp_account_password' | |
| 769 | + 'form_type' => 'register', | |
| 770 | + 'field_type' => 'password', | |
| 771 | + 'is_default' => '0', | |
| 772 | + 'htmlvar_name' => 'password', | |
| 742 | 773 | ); |
| 743 | 774 | |
| 744 | - | |
| 745 | - foreach ($fields as $field) { | |
| 746 | - $last_order = $wpdb->get_var("SELECT MAX(sort_order) as last_order FROM " . $extras_table_name); | |
| 775 | + foreach ( $fields as $field ) { | |
| 776 | + $last_order = $wpdb->get_var( 'SELECT MAX(sort_order) as last_order FROM ' . $extras_table_name . ' where form_id = ' . $form_id ); | |
| 747 | 777 | $sort_order = (int)$last_order + 1; |
| 748 | 778 | $wpdb->query( |
| 749 | 779 | $wpdb->prepare( |
| 750 | - | |
| 751 | - "insert into " . $extras_table_name . " set | |
| 780 | + 'insert into ' . $extras_table_name . ' set | |
| 752 | 781 | form_type = %s, |
| 753 | 782 | field_type = %s, |
| 754 | 783 | is_default = %s, |
| 755 | 784 | site_htmlvar_name = %s, |
| 756 | - sort_order = %s", | |
| 785 | + sort_order = %s, | |
| 786 | + form_id = %s', | |
| 757 | 787 | array( |
| 758 | 788 | $field['form_type'], |
| 759 | 789 | $field['field_type'], |
| 760 | 790 | $field['is_default'], |
| 761 | 791 | $field['htmlvar_name'], |
| 762 | - $sort_order | |
| 792 | + $sort_order, | |
| 793 | + $form_id, | |
| 763 | 794 | ) |
| 764 | 795 | ) |
| 765 | 796 | ); |
| 766 | 797 | } |
| @@ -765,5 +796,66 @@ | ||
| 765 | 796 | ); |
| 766 | 797 | } |
| 767 | 798 | } |
| 768 | 799 | |
| 769 | -} | |
| 800 | + /** | |
| 801 | + * Performs automatic upgrade | |
| 802 | + * | |
| 803 | + * @since 2.0.0 | |
| 804 | + * @package userswp | |
| 805 | + * @return void | |
| 806 | + */ | |
| 807 | + public static function automatic_upgrade() { | |
| 808 | + $uwp_db_version = get_option( 'uwp_db_version' ); | |
| 809 | + | |
| 810 | + if ( $uwp_db_version != USERSWP_VERSION ) { | |
| 811 | + self::activate( is_plugin_active_for_network( 'userswp/userswp.php' ) ); | |
| 812 | + $settings = get_option( 'uwp_settings', array() ); | |
| 813 | + $needs_update = false; | |
| 814 | + if ( isset( $settings['design_style'] ) && 'bootstrap' == $settings['design_style'] ) { | |
| 815 | + $settings['users_default_layout'] = '3col'; | |
| 816 | + $needs_update = true; | |
| 817 | + } | |
| 818 | + | |
| 819 | + if ( isset( $settings['uwp_registration_action'] ) && $settings['uwp_registration_action'] == 'force_redirect' ) { | |
| 820 | + $settings['uwp_registration_action'] = 'auto_approve_login'; | |
| 821 | + $needs_update = true; | |
| 822 | + } | |
| 823 | + | |
| 824 | + $get_register_form = isset( $settings['multiple_registration_forms'] ) ? $settings['multiple_registration_forms'] : false; | |
| 825 | + | |
| 826 | + if ( ! empty( $get_register_form ) && is_array( $get_register_form ) ) { | |
| 827 | + | |
| 828 | + foreach ( $get_register_form as $key => $register_form ) { | |
| 829 | + | |
| 830 | + if ( ! empty( $register_form['id'] ) ) { | |
| 831 | + | |
| 832 | + $reg_action = isset( $register_form['reg_action'] ) ? $register_form['reg_action'] : ''; | |
| 833 | + | |
| 834 | + if ( isset( $reg_action ) && $reg_action == 'force_redirect' ) { | |
| 835 | + $settings['multiple_registration_forms'][ $key ]['reg_action'] = 'auto_approve_login'; | |
| 836 | + $needs_update = true; | |
| 837 | + } | |
| 838 | + | |
| 839 | + $reg_title = isset( $register_form['title'] ) ? $register_form['title'] : ''; | |
| 840 | + | |
| 841 | + if ( isset( $reg_title ) && ! empty( $reg_title ) ) { | |
| 842 | + $clean_title = sanitize_text_field( $reg_title ); | |
| 843 | + if ( $clean_title !== $reg_title ) { | |
| 844 | + $settings['multiple_registration_forms'][ $key ]['title'] = $clean_title; | |
| 845 | + $needs_update = true; | |
| 846 | + } | |
| 847 | + } | |
| 848 | + } | |
| 849 | + } | |
| 850 | + } | |
| 851 | + | |
| 852 | + if ( $needs_update ) { | |
| 853 | + update_option( 'uwp_settings', $settings ); | |
| 854 | + } | |
| 855 | + | |
| 856 | + // Run this function once. | |
| 857 | + update_option( 'uwp_db_version', USERSWP_VERSION ); | |
| 858 | + | |
| 859 | + } | |
| 860 | + } | |
| 861 | +} | |