-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
43 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,31 @@ | ||
<?php | ||
|
||
include_once plugin_dir_path( __FILE__ ) . 'core/user.php'; | ||
|
||
function get_presets_meta( $prefix , $field ) { | ||
$selected_presets_id = $_GET['wppresets-trigger']; | ||
|
||
return get_post_meta( $selected_presets_id, 'wppresets_' . $prefix . $field, true ); | ||
} | ||
|
||
function wppresets_admin_notice__success() { | ||
?> | ||
<div class="notice notice-success is-dismissible"> | ||
<p><?php _e( 'Done! ', 'wppresets' ); ?></p> | ||
</div> | ||
<?php | ||
} | ||
|
||
function apply_presets() { | ||
|
||
if ( isset( $_GET['wppresets-trigger'] ) && current_user_can( 'manage_options' ) ) { | ||
|
||
include_once plugin_dir_path( __FILE__ ) . 'core/user.php'; | ||
|
||
function wppresets_admin_notice__success() { | ||
?> | ||
<div class="notice notice-success is-dismissible"> | ||
<p><?php _e( 'Done! ', 'wppresets' ); ?></p> | ||
</div> | ||
<?php | ||
} | ||
wppresets_core_user_apply_meta(); | ||
|
||
add_action( 'admin_notices', 'wppresets_admin_notice__success' ); | ||
|
||
} | ||
|
||
} | ||
|
||
add_action( 'admin_footer', 'apply_presets' ); | ||
add_action( 'admin_head', 'apply_presets' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,30 @@ | ||
<?php | ||
|
||
function wppresets_core_user_apply_meta() { | ||
|
||
function get_presets_meta($field) { | ||
$selected_presets_id = $_GET['wppresets-trigger']; | ||
//$field_value = get_post_meta( $selected_presets_id, "wppresets_core_user_$field" )[0]; | ||
if ( isset( get_post_meta( $selected_presets_id, "wppresets_core_user_$field" )[0] ) ) { | ||
return get_post_meta( $selected_presets_id, "wppresets_core_user_$field" )[0]; | ||
} else { | ||
return 'Blank'; | ||
$prefix = 'core_user_'; | ||
|
||
$userdata = array( | ||
'ID' => get_current_user_id(), //(int) User ID. If supplied, the user will be updated. | ||
); | ||
|
||
$fields = [ | ||
'first_name', | ||
'last_name', | ||
'display_name', | ||
'description', | ||
'user_url', | ||
'user_email' | ||
]; | ||
|
||
foreach( $fields as $field ) { | ||
$meta = get_presets_meta( $prefix , $field ); | ||
if ( ! empty($meta) ) { | ||
$userdata[ $field ] = $meta; | ||
} | ||
} | ||
} | ||
|
||
|
||
$userdata = array( | ||
'ID' => get_current_user_id(), //(int) User ID. If supplied, the user will be updated. | ||
//'user_url' => get_presets_meta( 'user_url' ), //(string) The user URL. | ||
//'user_email' => get_presets_meta( 'user_email' ), //(string) The user email address. | ||
//'display_name' => get_presets_meta( 'display_name' ), //(string) The user's display name. Default is the user's username. | ||
'first_name' => get_presets_meta( 'first_name' ), //(string) The user's first name. For new users, will be used to build the first part of the user's display name if $display_name is not specified. | ||
'last_name' => get_presets_meta( 'last_name' ), //(string) The user's last name. For new users, will be used to build the second part of the user's display name if $display_name is not specified. | ||
//'description' => get_presets_meta( 'description' ), //(string) The user's biographical description. | ||
// 'admin_color' => '', //(string) Admin color scheme for the user. Default 'fresh'. | ||
// 'locale' => '', //(string) User's locale. Default empty. | ||
); | ||
wp_update_user( wp_slash( $userdata ) ); | ||
|
||
wp_update_user( wp_slash( $userdata ) ); | ||
} |