Skip to content

Commit

Permalink
Improve presets setup - Closes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
foosantos committed Mar 22, 2021
1 parent 8cc3b14 commit 44a0675
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 30 deletions.
30 changes: 20 additions & 10 deletions src/actions/apply-presets.php
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' );
43 changes: 23 additions & 20 deletions src/actions/core/user.php
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 ) );
}

0 comments on commit 44a0675

Please sign in to comment.