| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
class WPCargo_User{ |
| 6 |
function __construct(){ |
| 7 |
add_action( 'show_user_profile', array( $this, 'extra_profile_fields' ) ); |
| 8 |
add_action( 'edit_user_profile', array( $this, 'extra_profile_fields' ) ); |
| 9 |
add_action( 'personal_options_update', array( $this, 'save_extra_profile_fields' ) ); |
| 10 |
add_action( 'edit_user_profile_update', array( $this, 'save_extra_profile_fields' ) ); |
| 11 |
} |
| 12 |
function extra_profile_fields( $user ) { |
| 13 |
$current_offset = get_option('gmt_offset'); |
| 14 |
$tzstring = get_option('timezone_string'); |
| 15 |
$check_zone_info = true; |
| 16 |
// Remove old Etc mappings. Fallback to gmt_offset. |
| 17 |
if ( false !== strpos($tzstring,'Etc/GMT') ) |
| 18 |
$tzstring = ''; |
| 19 |
if ( empty($tzstring) ) { // Create a UTC+- zone if no timezone string exists |
| 20 |
$check_zone_info = false; |
| 21 |
if ( 0 == $current_offset ) |
| 22 |
$tzstring = 'UTC+0'; |
| 23 |
elseif ($current_offset < 0) |
| 24 |
$tzstring = 'UTC' . $current_offset; |
| 25 |
else |
| 26 |
$tzstring = 'UTC+' . $current_offset; |
| 27 |
} |
| 28 |
$user_timezone = get_user_meta( $user->ID, 'wpc_user_timezone', true ); |
| 29 |
$tzstring = $user_timezone ? $user_timezone : $tzstring ; |
| 30 |
require_once( WPCARGO_PLUGIN_PATH.'admin/templates/user-profile.tpl.php'); |
| 31 |
} |
| 32 |
|
| 33 |
function save_extra_profile_fields( $user_id ) { |
| 34 |
if ( !current_user_can( 'edit_user', $user_id ) ){ |
| 35 |
return false; |
| 36 |
} |
| 37 |
if( isset( $_POST['wpc_user_timezone'] ) ){ |
| 38 |
update_user_meta( $user_id, 'wpc_user_timezone', sanitize_text_field( $_POST['wpc_user_timezone'] ) ); |
| 39 |
} |
| 40 |
if( isset( $_POST['business_reg'] ) ){ |
| 41 |
update_user_meta( $user_id, 'business_reg', sanitize_text_field( $_POST['business_reg'] ) ); |
| 42 |
} |
| 43 |
|
| 44 |
if( isset( $_POST['gst_account'] ) ){ |
| 45 |
update_user_meta( $user_id, 'gst_account', sanitize_text_field( $_POST['gst_account'] ) ); |
| 46 |
} |
| 47 |
|
| 48 |
if( isset( $_POST['min_notification'] ) ){ |
| 49 |
update_user_meta( $user_id, 'min_notification', sanitize_text_field( $_POST['min_notification'] ) ); |
| 50 |
} |
| 51 |
|
| 52 |
if( isset( $_POST['wpcargo_phone'] ) ){ |
| 53 |
update_user_meta( $user_id, 'wpcargo_phone', sanitize_text_field( $_POST['wpcargo_phone'] ) ); |
| 54 |
} |
| 55 |
if( isset( $_POST['company_logo'] ) ){ |
| 56 |
update_user_meta( $user_id, 'company_logo', sanitize_text_field( $_POST['company_logo'] ) ); |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
new WPCargo_User; |