| 1 |
<?php |
| 2 |
/** |
| 3 |
* Fired during plugin activation. |
| 4 |
* |
| 5 |
* This class defines all code necessary to run during the plugin's activation. |
| 6 |
* |
| 7 |
* @since 1.0.0 |
| 8 |
* @author GeoDirectory Team <info@wpgeodirectory.com> |
| 9 |
*/ |
| 10 |
class UsersWP_Activator { |
| 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(); |
| 22 |
|
| 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 |
|
| 44 |
|
| 45 |
|
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Loads all dependencies during plugin activation. |
| 50 |
* |
| 51 |
* @since 1.0.0 |
| 52 |
* @package userswp |
| 53 |
* @return void |
| 54 |
*/ |
| 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 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Generates the default pages during plugin activation. |
| 64 |
* |
| 65 |
* @since 1.0.0 |
| 66 |
* @package userswp |
| 67 |
* @return void |
| 68 |
*/ |
| 69 |
public static function generate_pages() { |
| 70 |
uwp_generate_default_pages(); |
| 71 |
} |
| 72 |
|
| 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() { |
| 81 |
|
| 82 |
$settings = get_option( 'uwp_settings', array()); |
| 83 |
|
| 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'] = -1; |
| 92 |
} |
| 93 |
|
| 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'; |
| 111 |
} |
| 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 |
} else { |
| 119 |
$settings['enable_profile_tabs'] = array('more_info', 'posts', 'comments'); |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
//notifications |
| 124 |
|
| 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"); |
| 128 |
|
| 129 |
if (!isset($settings['registration_success_email_subject_admin'])) { |
| 130 |
$settings['registration_success_email_subject_admin'] = $registration_success_email_subject_admin; |
| 131 |
} |
| 132 |
if (!isset($settings['registration_success_email_content_admin'])) { |
| 133 |
$settings['registration_success_email_content_admin'] = $registration_success_email_content_admin; |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
// User |
| 138 |
|
| 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'); |
| 142 |
|
| 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 |
} |
| 149 |
|
| 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'); |
| 153 |
|
| 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 |
} |
| 160 |
|
| 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'); |
| 164 |
|
| 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 |
} |
| 171 |
|
| 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'); |
| 175 |
|
| 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 |
} |
| 182 |
|
| 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; |
| 189 |
} |
| 190 |
if (!isset($settings['reset_password_email_content'])) { |
| 191 |
$settings['reset_password_email_content'] = $reset_password_email_content; |
| 192 |
} |
| 193 |
|
| 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'); |
| 197 |
|
| 198 |
if (!isset($settings['account_update_email_subject'])) { |
| 199 |
$settings['account_update_email_subject'] = $account_update_email_subject; |
| 200 |
} |
| 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 |
} |
| 208 |
|
| 209 |
/** |
| 210 |
* Creates tables during plugin activation. |
| 211 |
* |
| 212 |
* @since 1.0.0 |
| 213 |
* @package userswp |
| 214 |
* @return void |
| 215 |
*/ |
| 216 |
public static function uwp_create_tables() |
| 217 |
{ |
| 218 |
uwp_create_tables(); |
| 219 |
} |
| 220 |
|
| 221 |
/** |
| 222 |
* Creates the new tables added in version 1.0.1 during plugin activation. |
| 223 |
* |
| 224 |
* @since 1.0.0 |
| 225 |
* @package userswp |
| 226 |
* @return void |
| 227 |
*/ |
| 228 |
public static function uwp101_create_tables() { |
| 229 |
uwp101_create_tables(); |
| 230 |
} |
| 231 |
|
| 232 |
/** |
| 233 |
* Syncs WP usermeta with UsersWP usermeta during plugin activation. |
| 234 |
* |
| 235 |
* @since 1.0.0 |
| 236 |
* @package userswp |
| 237 |
* @return void |
| 238 |
*/ |
| 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 )); |
| 246 |
|
| 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); |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
/** |
| 263 |
* Saves default custom fields in the database. |
| 264 |
* |
| 265 |
* @since 1.0.0 |
| 266 |
* @package userswp |
| 267 |
* @return void |
| 268 |
*/ |
| 269 |
public static function uwp_create_default_fields() |
| 270 |
{ |
| 271 |
$form_builder = new UsersWP_Form_Builder(); |
| 272 |
|
| 273 |
$fields = self::uwp_default_custom_fields(); |
| 274 |
|
| 275 |
$fields = apply_filters('uwp_before_default_custom_fields_saved', $fields); |
| 276 |
|
| 277 |
foreach ($fields as $field_index => $field) { |
| 278 |
$form_builder->uwp_admin_form_field_save($field); |
| 279 |
} |
| 280 |
} |
| 281 |
|
| 282 |
/** |
| 283 |
* Returns merged default custom fields. |
| 284 |
* |
| 285 |
* @since 1.0.0 |
| 286 |
* @package userswp |
| 287 |
* @return array Merged custom fields. |
| 288 |
*/ |
| 289 |
public static function uwp_default_custom_fields(){ |
| 290 |
|
| 291 |
$login = self::uwp_default_custom_fields_login(); |
| 292 |
$forgot = self::uwp_default_custom_fields_forgot(); |
| 293 |
$avatar = self::uwp_default_custom_fields_avatar(); |
| 294 |
$banner = self::uwp_default_custom_fields_banner(); |
| 295 |
$change = self::uwp_default_custom_fields_change(); |
| 296 |
$reset = self::uwp_default_custom_fields_reset(); |
| 297 |
$account = self::uwp_default_custom_fields_account(); |
| 298 |
|
| 299 |
$fields = array_merge($login, $forgot, $account, $avatar, $banner, $change, $reset); |
| 300 |
|
| 301 |
$fields = apply_filters('uwp_default_custom_fields', $fields); |
| 302 |
|
| 303 |
return $fields; |
| 304 |
|
| 305 |
} |
| 306 |
|
| 307 |
/** |
| 308 |
* Returns Login form default custom fields. |
| 309 |
* |
| 310 |
* @since 1.0.0 |
| 311 |
* @package userswp |
| 312 |
* @return array Login form default custom fields. |
| 313 |
*/ |
| 314 |
public static function uwp_default_custom_fields_login(){ |
| 315 |
|
| 316 |
$fields = array(); |
| 317 |
|
| 318 |
$fields[] = array( |
| 319 |
'form_type' => 'login', |
| 320 |
'field_type' => 'text', |
| 321 |
'data_type' => 'XVARCHAR', |
| 322 |
'site_title' => __('Username', 'userswp'), |
| 323 |
'htmlvar_name' => 'username', |
| 324 |
'default_value' => '', |
| 325 |
'option_values' => '', |
| 326 |
'is_default' => '1', |
| 327 |
'is_active' => '1', |
| 328 |
'is_required' => '1' |
| 329 |
); |
| 330 |
|
| 331 |
$fields[] = array( |
| 332 |
'form_type' => 'login', |
| 333 |
'field_type' => 'password', |
| 334 |
'data_type' => 'XVARCHAR', |
| 335 |
'site_title' => __('Password', 'userswp'), |
| 336 |
'htmlvar_name' => 'password', |
| 337 |
'default_value' => '', |
| 338 |
'option_values' => '', |
| 339 |
'is_default' => '1', |
| 340 |
'is_active' => '1', |
| 341 |
'is_required' => '1' |
| 342 |
); |
| 343 |
|
| 344 |
$fields = apply_filters('uwp_default_custom_fields_login', $fields); |
| 345 |
|
| 346 |
return $fields; |
| 347 |
} |
| 348 |
|
| 349 |
/** |
| 350 |
* Returns Forgot form default custom fields. |
| 351 |
* |
| 352 |
* @since 1.0.0 |
| 353 |
* @package userswp |
| 354 |
* @return array Forgot form default custom fields. |
| 355 |
*/ |
| 356 |
public static function uwp_default_custom_fields_forgot(){ |
| 357 |
|
| 358 |
$fields = array(); |
| 359 |
|
| 360 |
$fields[] = array( |
| 361 |
'form_type' => 'forgot', |
| 362 |
'field_type' => 'email', |
| 363 |
'data_type' => 'XVARCHAR', |
| 364 |
'site_title' => __('Email', 'userswp'), |
| 365 |
'htmlvar_name' => 'email', |
| 366 |
'default_value' => '', |
| 367 |
'option_values' => '', |
| 368 |
'is_default' => '1', |
| 369 |
'is_active' => '1', |
| 370 |
'is_required' => '1' |
| 371 |
); |
| 372 |
|
| 373 |
$fields = apply_filters('uwp_default_custom_fields_forgot', $fields); |
| 374 |
|
| 375 |
return $fields; |
| 376 |
} |
| 377 |
|
| 378 |
/** |
| 379 |
* Returns Avatar form default custom fields. |
| 380 |
* |
| 381 |
* @since 1.0.0 |
| 382 |
* @package userswp |
| 383 |
* @return array Avatar form default custom fields. |
| 384 |
*/ |
| 385 |
public static function uwp_default_custom_fields_avatar(){ |
| 386 |
|
| 387 |
$fields = array(); |
| 388 |
|
| 389 |
$fields[] = array( |
| 390 |
'form_type' => 'avatar', |
| 391 |
'field_type' => 'file', |
| 392 |
'data_type' => 'TEXT', |
| 393 |
'site_title' => __('Avatar', 'userswp'), |
| 394 |
'htmlvar_name' => 'file', |
| 395 |
'default_value' => '', |
| 396 |
'option_values' => '', |
| 397 |
'is_default' => '1', |
| 398 |
'is_active' => '1', |
| 399 |
'is_required' => '1', |
| 400 |
'extra_fields' => array( |
| 401 |
'uwp_file_types' => array( |
| 402 |
'jpg', |
| 403 |
'jpe', |
| 404 |
'jpeg', |
| 405 |
'gif', |
| 406 |
'png' |
| 407 |
), |
| 408 |
) |
| 409 |
); |
| 410 |
|
| 411 |
$fields = apply_filters('uwp_default_custom_fields_avatar', $fields); |
| 412 |
|
| 413 |
return $fields; |
| 414 |
} |
| 415 |
|
| 416 |
/** |
| 417 |
* Returns Banner form default custom fields. |
| 418 |
* |
| 419 |
* @since 1.0.0 |
| 420 |
* @package userswp |
| 421 |
* @return array Banner form default custom fields. |
| 422 |
*/ |
| 423 |
public static function uwp_default_custom_fields_banner(){ |
| 424 |
|
| 425 |
$fields = array(); |
| 426 |
|
| 427 |
$fields[] = array( |
| 428 |
'form_type' => 'banner', |
| 429 |
'field_type' => 'file', |
| 430 |
'data_type' => 'TEXT', |
| 431 |
'site_title' => __('Banner', 'userswp'), |
| 432 |
'htmlvar_name' => 'file', |
| 433 |
'default_value' => '', |
| 434 |
'option_values' => '', |
| 435 |
'is_default' => '1', |
| 436 |
'is_active' => '1', |
| 437 |
'is_required' => '1', |
| 438 |
'extra_fields' => array( |
| 439 |
'uwp_file_types' => array( |
| 440 |
'jpg', |
| 441 |
'jpe', |
| 442 |
'jpeg', |
| 443 |
'gif', |
| 444 |
'png' |
| 445 |
), |
| 446 |
) |
| 447 |
); |
| 448 |
|
| 449 |
$fields = apply_filters('uwp_default_custom_fields_banner', $fields); |
| 450 |
|
| 451 |
return $fields; |
| 452 |
} |
| 453 |
|
| 454 |
/** |
| 455 |
* Returns Change Password form default custom fields. |
| 456 |
* |
| 457 |
* @since 1.0.0 |
| 458 |
* @package userswp |
| 459 |
* @return array Change Password form default custom fields. |
| 460 |
*/ |
| 461 |
public static function uwp_default_custom_fields_change(){ |
| 462 |
|
| 463 |
$fields = array(); |
| 464 |
|
| 465 |
$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', |
| 471 |
'default_value' => '', |
| 472 |
'option_values' => '', |
| 473 |
'is_default' => '1', |
| 474 |
'is_active' => '1', |
| 475 |
'is_required' => '1' |
| 476 |
); |
| 477 |
|
| 478 |
$fields[] = array( |
| 479 |
'form_type' => 'change', |
| 480 |
'field_type' => 'password', |
| 481 |
'data_type' => 'XVARCHAR', |
| 482 |
'site_title' => __('New Password', 'userswp'), |
| 483 |
'htmlvar_name' => 'password', |
| 484 |
'default_value' => '', |
| 485 |
'option_values' => '', |
| 486 |
'is_default' => '1', |
| 487 |
'is_active' => '1', |
| 488 |
'is_required' => '1' |
| 489 |
); |
| 490 |
|
| 491 |
$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', |
| 497 |
'default_value' => '', |
| 498 |
'option_values' => '', |
| 499 |
'is_default' => '1', |
| 500 |
'is_active' => '1', |
| 501 |
'is_required' => '1' |
| 502 |
); |
| 503 |
|
| 504 |
$fields = apply_filters('uwp_default_custom_fields_change', $fields); |
| 505 |
|
| 506 |
return $fields; |
| 507 |
} |
| 508 |
|
| 509 |
/** |
| 510 |
* Returns Reset Password form default custom fields. |
| 511 |
* |
| 512 |
* @since 1.0.0 |
| 513 |
* @package userswp |
| 514 |
* @return array Reset Password form default custom fields. |
| 515 |
*/ |
| 516 |
public static function uwp_default_custom_fields_reset(){ |
| 517 |
|
| 518 |
$fields = array(); |
| 519 |
|
| 520 |
$fields[] = array( |
| 521 |
'form_type' => 'reset', |
| 522 |
'field_type' => 'password', |
| 523 |
'data_type' => 'XVARCHAR', |
| 524 |
'site_title' => __('Password', 'userswp'), |
| 525 |
'htmlvar_name' => 'password', |
| 526 |
'default_value' => '', |
| 527 |
'option_values' => '', |
| 528 |
'is_default' => '1', |
| 529 |
'is_active' => '1', |
| 530 |
'is_required' => '1' |
| 531 |
); |
| 532 |
|
| 533 |
$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', |
| 539 |
'default_value' => '', |
| 540 |
'option_values' => '', |
| 541 |
'is_default' => '1', |
| 542 |
'is_active' => '1', |
| 543 |
'is_required' => '1' |
| 544 |
); |
| 545 |
|
| 546 |
$fields = apply_filters('uwp_default_custom_fields_reset', $fields); |
| 547 |
|
| 548 |
return $fields; |
| 549 |
} |
| 550 |
|
| 551 |
/** |
| 552 |
* Returns Account form default custom fields. |
| 553 |
* |
| 554 |
* @since 1.0.0 |
| 555 |
* @package userswp |
| 556 |
* @return array Account form default custom fields. |
| 557 |
*/ |
| 558 |
public static function uwp_default_custom_fields_account(){ |
| 559 |
|
| 560 |
$fields = array(); |
| 561 |
|
| 562 |
$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', |
| 574 |
'is_register_field' => '1', |
| 575 |
'is_search_field' => '1', |
| 576 |
'css_class' => 'uwp-half uwp-half-left', |
| 577 |
); |
| 578 |
|
| 579 |
$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', |
| 591 |
'is_register_field' => '1', |
| 592 |
'is_search_field' => '1', |
| 593 |
'css_class' => 'uwp-half uwp-half-right', |
| 594 |
); |
| 595 |
|
| 596 |
$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', |
| 610 |
'is_register_only_field' => '1', |
| 611 |
); |
| 612 |
|
| 613 |
$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', |
| 625 |
'is_register_field' => '0', |
| 626 |
'is_search_field' => '1', |
| 627 |
); |
| 628 |
|
| 629 |
$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', |
| 640 |
'is_register_field' => '1', |
| 641 |
'is_search_field' => '1', |
| 642 |
); |
| 643 |
|
| 644 |
|
| 645 |
$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', |
| 657 |
'is_search_field' => '1', |
| 658 |
'show_in' => array('[profile_side]', '[users]') |
| 659 |
); |
| 660 |
|
| 661 |
$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', |
| 673 |
'is_register_only_field' => '1', |
| 674 |
'extra' => array( |
| 675 |
'confirm_password' => '1' |
| 676 |
) |
| 677 |
); |
| 678 |
|
| 679 |
|
| 680 |
$fields = apply_filters('uwp_default_custom_fields_account', $fields); |
| 681 |
|
| 682 |
return $fields; |
| 683 |
} |
| 684 |
|
| 685 |
/** |
| 686 |
* Flushes rewrite rules. |
| 687 |
* |
| 688 |
* @since 1.0.0 |
| 689 |
* @package userswp |
| 690 |
* @return void |
| 691 |
*/ |
| 692 |
public static function uwp_flush_rewrite_rules() { |
| 693 |
flush_rewrite_rules(); |
| 694 |
} |
| 695 |
|
| 696 |
/** |
| 697 |
* Inserts register form custom fields in form extras table. |
| 698 |
* |
| 699 |
* @since 1.0.0 |
| 700 |
* @package userswp |
| 701 |
* @return void |
| 702 |
*/ |
| 703 |
public static function uwp_insert_form_extras() { |
| 704 |
global $wpdb; |
| 705 |
$extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras'; |
| 706 |
|
| 707 |
$fields = array(); |
| 708 |
|
| 709 |
$fields[] = array( |
| 710 |
'form_type' => 'register', |
| 711 |
'field_type' => 'text', |
| 712 |
'is_default' => '1', |
| 713 |
'htmlvar_name' => 'uwp_account_first_name' |
| 714 |
); |
| 715 |
|
| 716 |
$fields[] = array( |
| 717 |
'form_type' => 'register', |
| 718 |
'field_type' => 'text', |
| 719 |
'is_default' => '1', |
| 720 |
'htmlvar_name' => 'uwp_account_last_name' |
| 721 |
); |
| 722 |
|
| 723 |
$fields[] = array( |
| 724 |
'form_type' => 'register', |
| 725 |
'field_type' => 'text', |
| 726 |
'is_default' => '1', |
| 727 |
'htmlvar_name' => 'uwp_account_username' |
| 728 |
); |
| 729 |
|
| 730 |
$fields[] = array( |
| 731 |
'form_type' => 'register', |
| 732 |
'field_type' => 'email', |
| 733 |
'is_default' => '1', |
| 734 |
'htmlvar_name' => 'uwp_account_email' |
| 735 |
); |
| 736 |
|
| 737 |
$fields[] = array( |
| 738 |
'form_type' => 'register', |
| 739 |
'field_type' => 'password', |
| 740 |
'is_default' => '1', |
| 741 |
'htmlvar_name' => 'uwp_account_password' |
| 742 |
); |
| 743 |
|
| 744 |
|
| 745 |
foreach ($fields as $field) { |
| 746 |
$last_order = $wpdb->get_var("SELECT MAX(sort_order) as last_order FROM " . $extras_table_name); |
| 747 |
$sort_order = (int)$last_order + 1; |
| 748 |
$wpdb->query( |
| 749 |
$wpdb->prepare( |
| 750 |
|
| 751 |
"insert into " . $extras_table_name . " set |
| 752 |
form_type = %s, |
| 753 |
field_type = %s, |
| 754 |
is_default = %s, |
| 755 |
site_htmlvar_name = %s, |
| 756 |
sort_order = %s", |
| 757 |
array( |
| 758 |
$field['form_type'], |
| 759 |
$field['field_type'], |
| 760 |
$field['is_default'], |
| 761 |
$field['htmlvar_name'], |
| 762 |
$sort_order |
| 763 |
) |
| 764 |
) |
| 765 |
); |
| 766 |
} |
| 767 |
} |
| 768 |
|
| 769 |
} |