请任何人帮忙,
当我从word word admin部分更新用户时,用户电子邮件字段在成功更新后显示为空白。
我不明白为什么会这样。请建议我应该检查什么。我使用默认的user-edit.php
和functions.php是:
<?php
function register_my_menus() {
register_nav_menus(
array(
'top-right' => __('Top Right'),
'footer-menu' => __('Footer Menu'),
'profile_drive_nav' => __('Profile Drive Page')
)
);
}
//Top menu Remove Classes
add_action('init', 'register_my_menus');
add_filter('wp_nav_menu_args', 'prefix_nav_menu_args');
function prefix_nav_menu_args($args = '') {
$args['container'] = false;
return $args;
}
$menuParameters = array(
'container' => false,
'echo' => false,
'items_wrap' => '%3$s',
'depth' => 0,
);
//echo strip_tags(wp_nav_menu( $menuParameters ), '<a>' );
//Logout Function in Menu perticullar menu--Top Right Menu
/* add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
function add_login_logout_link($items, $args) {
ob_start();
wp_loginout('index.php');
$loginoutlink = ob_get_contents();
ob_end_clean();
if( $args->theme_location == 'top-right' ){
$items .= '<li class="login_link">'. $loginoutlink .'</li>';
}
return $items;
} */
//Bloginfo
function pk_bloginfo_shortcode($atts) {
extract(shortcode_atts(array(
'key' => '',
), $atts));
return get_bloginfo($key);
}
add_filter('widget_text', 'do_shortcode');
add_shortcode('bloginfo', 'pk_bloginfo_shortcode');
//Page Slug Body Classes
function add_body_class($pk_classes) {
global $post;
if (isset($post)) {
$pk_classes[] = /* $post->post_type . '-' . */ $post->post_name;
}
return $pk_classes;
}
add_filter('body_class', 'add_body_class');
/* Remove Checkout Fields */
/* Remove Woocommerce User Fields */
add_filter('woocommerce_checkout_fields', 'custom_override_checkout_fields');
add_filter('woocommerce_billing_fields', 'custom_override_billing_fields');
add_filter('woocommerce_shipping_fields', 'custom_override_shipping_fields');
function custom_override_checkout_fields($fields) {
unset($fields['billing']['billing_state']);
unset($fields['billing']['billing_country']);
//unset($fields['billing']['billing_last_name']);
unset($fields['billing']['billing_phone']);
unset($fields['billing']['billing_company']);
unset($fields['billing']['billing_address_1']);
unset($fields['billing']['billing_address_2']);
unset($fields['billing']['billing_postcode']);
unset($fields['billing']['billing_city']);
unset($fields['shipping']['shipping_state']);
unset($fields['shipping']['shipping_country']);
unset($fields['shipping']['shipping_company']);
unset($fields['shipping']['shipping_address_1']);
unset($fields['shipping']['shipping_address_2']);
unset($fields['shipping']['shipping_postcode']);
unset($fields['shipping']['shipping_city']);
unset($fields['order']['order_comments']);
return $fields;
}
function custom_override_billing_fields($fields) {
unset($fields['billing_state']);
unset($fields['billing_country']);
unset($fields['billing_company']);
unset($fields['billing_address_1']);
unset($fields['billing_address_2']);
unset($fields['billing_postcode']);
unset($fields['billing_city']);
unset($fields['account_password']);
return $fields;
}
function custom_override_shipping_fields($fields) {
unset($fields['shipping_first_name']);
unset($fields['shipping_last_name']);
unset($fields['shipping_state']);
unset($fields['shipping_country']);
unset($fields['shipping_company']);
unset($fields['shipping_address_1']);
unset($fields['shipping_address_2']);
unset($fields['shipping_postcode']);
unset($fields['shipping_city']);
unset($fields['order']['order_comments']);
return $fields;
}
add_filter('woocommerce_default_address_fields', 'override_address_fields32');
function override_address_fields32($fields) {
//$address_fields['account_password']['placeholder'] = '';
$address_fields['first_name']['label'] = 'Name';
$address_fields['first_name']['placeholder'] = '';
return $address_fields;
}
add_filter( 'woocommerce_billing_fields', 'custom_woocommerce_billing_fields' );
function custom_woocommerce_billing_fields( $fields ) {
$fields['billing_email'] = array(
'label' => __('Email', 'woothemes'),
'required' => true
);
return $fields;
}
/*
add_filter('woocommerce_default_address_fields', 'override_address_fields32');
function override_address_fields32( $fields ) {
//$address_fields['account_password']['placeholder'] = '';
$address_fields['billing_first_name']['label'] ='Name';
$address_fields['billing_first_name']['required'] =true;
$address_fields['billing_email']['label'] ='Email';
$address_fields['billing_email']['required'] =true;
$address_fields['address_2']['placeholder'] = '';
$address_fields['city']['placeholder'] = '';
$address_fields['state']['placeholder'] = '';
$address_fields['postcode']['placeholder'] = '';
return $address_fields;
}
/* End - Remove Woocommerce User Fields */
add_filter('gettext', 'translate_text');
add_filter('ngettext', 'translate_text');
function translate_text($translated) {
$translated = str_ireplace('Billing Details', 'Sign Up', $translated);
return $translated;
}
add_filter('gettext', 'translate_text2');
add_filter('ngettext', 'translate_text2');
function translate_text2($translated2) {
$translated2 = str_ireplace('Additional Information', '', $translated2);
return $translated2;
}
add_filter('gettext', 'translate_text3');
add_filter('ngettext', 'translate_text3');
function translate_text3($translated3) {
$translated3 = str_ireplace('First Name', 'Name', $translated3);
return $translated3;
}
add_filter('gettext', 'translate_text4');
add_filter('ngettext', 'translate_text4');
function translate_text4($translated4) {
$translated4 = str_ireplace('Create an account by entering the information below. If you are a returning customer please login at the top of the page.', '<hr style="clear:both;" />', $translated4);
return $translated4;
}
add_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_single_excerpt', 5);
/** woocommerce: change position of add-to-cart on single product * */
//Removed featured image
remove_action('woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20);
//For pricing hook
remove_action('woocommerce_product_summary', 'woocommerce_template_price', 10);
add_action('woocommerce_product_summary', 'woocommerce_template_price', 25);
add_action('woocommerce_single_product_summary', 'woocommerce_template_single_title', 5);
add_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10);
add_action('woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20);
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30);
add_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 7);
//Remove return customer
remove_action('woocommerce_before_checkout_form', 'woocommerce_checkout_login_form', 10);
// place the following code in your theme's functions.php file
// Add a second password field to the checkout page.
add_action('woocommerce_checkout_init', 'wc_add_confirm_password_checkout', 10, 1);
function wc_add_confirm_password_checkout($checkout) {
if (get_option('woocommerce_registration_generate_password') == 'no') {
$checkout->checkout_fields['account']['account_password2'] = array(
'type' => 'password',
'label' => __('Confirm password', 'woocommerce'),
'placeholder' => __('Confirm password', 'woocommerce'),
'required' => true
);
}
}
// Check the password and confirm password fields match before allow checkout to proceed.
add_action('woocommerce_after_checkout_validation', 'wc_check_confirm_password_matches_checkout', 10, 2);
function wc_check_confirm_password_matches_checkout($posted) {
$checkout = WC()->checkout;
if (!is_user_logged_in() && ( $checkout->must_create_account || !empty($posted['createaccount']) )) {
if (strcmp($posted['account_password'], $posted['account_password2']) !== 0) {
wc_add_notice(__('Passwords do not match.', 'woocommerce'), 'error');
}
}
}
/* Changes the redirect URL for the Return To Shop button in the cart. */
add_filter( 'woocommerce_checkout_fields' , 'wp_set_timezone' );
// Our hooked in function - $fields is passed via the filter!
function wp_set_timezone( $fields ) {
$fields['billing']['billing_timezone'] = array(
'label' => __('Timezone', 'woocommerce'),
'placeholder' => _x('Timezone', 'placeholder', 'woocommerce'),
'required' => false,
'class' => array('form-row-wide'),
'clear' => true,
'type' => 'radio',
'options' => array('UK'=>'UK','NON-UK'=>'NON-UK'
)//end of options
);
return $fields;
}
function wc_empty_cart_redirect_url() {
return bloginfo('url') . '/?page_id=14';
}
add_filter('woocommerce_return_to_shop_redirect', 'wc_empty_cart_redirect_url');
add_action('woocommerce_checkout_update_order_meta', 'woo_save_timezone');
function woo_save_timezone($order_id) {
if ($_POST['timezone'])
update_post_meta($order_id, 'timezone', esc_attr($_POST['timezone']));
}
/**
* Store terms and conditions value within the database
* */
add_action('woocommerce_checkout_update_order_meta', 'woo_save_terms_and_conditions_status');
/* function woo_save_terms_and_conditions_status( $order_id ) {
if ($_POST['terms']) update_post_meta( $order_id, '_terms', esc_attr($_POST['terms']));
}
add_action( 'woocommerce_admin_order_data_after_billing_address', 'woo_display_terms_and_conditions_status', 10, 1 );
*/
function woo_display_terms_and_conditions_status($order) {
$terms = get_post_meta($order->id, '_terms', true);
$terms_status = ( $terms == 'on' ? __('accepted') : __('undefined') );
echo '<p><strong>' . __('Terms & conditions') . ':</strong> ' . $terms_status . '</p>';
}
//Remove sidebar from product page
remove_action('woocommerce_sidebar', 'woocommerce_get_sidebar', 10);
//Thank You Title Messages change here
/* function bk_title_order_received( $title, $id ) {
if ( is_order_received_page() && get_the_ID() === $id ) {
$title = "Thank you for your order!";
}
return $title;
}
add_filter( 'the_title', 'bk_title_order_received', 10, 2 );
*/
//Remove Related Products
remove_action('woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);
//Remove Tabs
add_filter('woocommerce_product_tabs', 'woo_remove_product_tabs', 98);
function woo_remove_product_tabs($tabs) {
//unset( $tabs['description'] );
unset($tabs['reviews']);
return $tabs;
}
function wc_remove_all_quantity_fields($return, $product) {
return true;
}
show_admin_bar(false);
/* Adding Image Upload Fields */
function get_image_url($user) {
if (esc_url(get_the_author_meta('user_meta_image', $user->ID))) {
return esc_url(get_the_author_meta('user_meta_image', $user->ID));
} else {
return esc_url(bloginfo('template_url') . "/images/user-img.jpg");
}
}
//////////////////////////////////////////////////////////////////////////////
add_editor_style('editor-style.css');
function deleteDirectoryFile($checkDirectoryExist) {
foreach (glob($checkDirectoryExist . "/*.*") as $filename) {
if (is_file($filename)) {
@unlink($filename);
}
}
@rmdir($dir);
}
/////////////////////////////////////////////////////////////////
add_editor_style('css/custom-editor-style.css');
add_action('media_buttons', 'add_my_media_button');
function add_my_media_button() {
if (!current_user_can('subscriber')){
echo '<a href="#" id="insert-my-media" class="button">Add my media</a>';
}
}
function add_media_upload_scripts() {
if (is_admin()) {
return;
}
wp_enqueue_media();
}
add_action('wp_enqueue_scripts', 'add_media_upload_scripts');
/////////////////////////////////////////////////////////////////////
add_filter('tiny_mce_before_init', 'restrict_font_choices');
function restrict_font_choices($initArray) {
$initArray['theme_advanced_fonts'] = 'Andale Mono=andale mono,times;' .
'Arial=arial,helvetica,sans-serif;' .
'Arial Black=arial black,avant garde;' .
'Book Antiqua=book antiqua,palatino;' .
'Comic Sans MS=comic sans ms,sans-serif;' .
'Courier New=courier new,courier;' .
'Georgia=georgia,palatino;' .
'Helvetica=helvetica;' .
'Impact=impact,chicago;' .
'Symbol=symbol;' .
'Tahoma=tahoma,arial,helvetica,sans-serif;' .
'Terminal=terminal,monaco;' .
'Times New Roman=times new roman,times;' .
'Trebuchet MS=trebuchet ms,geneva;' .
'Verdana=verdana,geneva;' .
'Webdings=webdings;' .
'Calibri=Calibri' .
'Formula436B=Formula436B' .
'Lucida Calligraphy=Lucida Calligraphy';
return $initArray;
}
$current_user = wp_get_current_user();
if (current_user_can('customer') && !current_user_can('upload_files'))
add_action('admin_init', 'allow_customer_uploads');
function allow_customer_uploads() {
$contributor = get_role('customer');
$contributor->add_cap('upload_files');
}
function add_theme_caps() {
// gets the subscriber role
$role = get_role( 'subscriber' );
// would allow the subscriber role to upload photos for the current theme
$role->add_cap( 'upload_files' );
}
add_action( 'admin_init', 'add_theme_caps');
///////////////////////////overwrite user login///////////////////////////////////////
function wcs_filter_username_email($args) {
$args['user_login'] = $args['user_email'];
return $args;
}
add_filter('woocommerce_new_customer_data', 'wcs_filter_username_email');
////////////////////////////////Code for free user//////////////////////////////////////////////////////////
require('class-wev-email-verification.php');
$wev = new WEV_Email_Verification();
//////////////////////////////////////////////////////////////////////////////////////////
add_action('woocommerce_checkout_update_order_meta', 'woo_save_terms_and_conditions_status');
function woo_save_terms_and_conditions_status($order_id) {
if ($_POST['terms'])
update_post_meta($order_id, '_terms', esc_attr($_POST['terms']));
}
function add_user_to_laravel($order_id) {
$order = new WC_Order($order_id);
$postId = $order->post->ID;
$wpUserId = get_post_meta($postId, '_customer_user', true);
$wpUser = get_userdata($wpUserId);
/* Add user into laravel */
$currentDateTime = date('Y-m-d H:i:s', time());
$wpdbNew = new wpdb(DMS_DB_USER, DMS_DB_PASSWORD, DMS_DB_NAME, DMS_DB_HOST);
$qry = "SELECT email,id FROM users WHERE email = '$wpUser->user_email'";
$userExist = $wpdbNew->get_results( $qry );
if( empty($userExist) ){
$wpdbNew->insert("users", array(
'group_id' => '2',
'parent_id' => '0',
'username' => $wpUser->user_email,
'email' => $wpUser->user_email,
'password' => '',
'status' => get_user_meta($wpUserId, 'is_activated', true),
'network' => '0',
'token' => '',
'remember_token' => '',
'wp_user_id' => $wpUserId,
'created_at' => $currentDateTime,
'updated_at' => $currentDateTime,
'timezone'=>get_user_meta($wpUserId, 'billing_timezone', true),
));
$userId = $wpdbNew->insert_id;
$wpdbNew->insert("user_profile", array(
'user_id' => $userId,
'first_name' => $wpUser->display_name,
'last_name' => '',
'email' => $wpUser->user_email,
'company' => '',
'position' => '',
'website' => '',
'mobile' => '',
'image' => '',
));
$constArr = array(DMS_FIRST_DEFAULT_NETWORK_ORDER => array(
DMS_FIRST_DEFAULT_NETWORK, DMS_FIRST_DEFAULT_NETWORK_COLOR)
);
foreach ($constArr as $k => $v) {
$wpdbNew->insert("user_networks", array(
'id' => NULL,
'user_id' => $userId,
'name' => $v[0],
'color' => $v[1],
'can_delete' => 0,
'created_on' => $currentDateTime,
'order_by' => $k
));
}
// update user notification settings.
$wpdbNew->insert("user_settings", array(
'user_id' => $userId,
'notifyon_share_folder' => 1,
'notifyon_document_change' => 1,
'notifyon_shared_document_deleted' => 1
));
/* End */
}else{
$userId = $userExist[0]->id;
//$query = "UPDATE users SET wp_user_id= $wpUserId WHERE id = $userId";
$wpdbNew->update(
"users",
array(
'wp_user_id' => $wpUserId
),
array(
'id' => $userId
),
$format = null,
$where_format = null
);
// $wpdbNew->get_results( $query );
}
$items = $order->get_items();
foreach ( $items as $item ) {
$product_id = $item['product_id'];
$package_name = $item['name'];
$amount = $item['line_total'];
$start_date = $item['subscription_start_date'];
$end_date = $item['subscription_end_date'];
$status = $item['subscription_status'];
}
$wpdbNew->insert("user_subscriptions", array(
'user_id' => $userId,
'package_name' => $package_name,
'total_amount' => $amount,
'start_date' => $start_date,
'end_date' => $end_date,
'status' => get_user_meta($wpUserId, 'is_activated', true),
'cancelled_on' => '',
'disk_space' => get_post_meta($product_id, 'disk_space', true)
));
}
add_action('woocommerce_order_status_completed', 'add_user_to_laravel');
add_filter ('woocommerce_payment_complete_order_status', 'my_change_status_function');
function my_change_status_function ($order_id) {
$order = new WC_Order($order_id);
//Do whatever additional logic you like before….
return 'completed';
}
function my_custom_login() {
echo '<link rel="stylesheet" type="text/css" href="' . get_bloginfo('stylesheet_directory') . '/css/custom-login-styles.css" >';
}
add_action('login_head', 'my_custom_login');
function update_text() {
return $thank_you_message = sprintf(__(''));
}
add_filter('woocommerce_subscriptions_thank_you_message', 'update_text');
function previewEmail() {
if (is_admin()) {
$default_path = WC()->plugin_path() . '/templates/';
$files = scandir($default_path . 'emails');
$exclude = array('.', '..', 'email-header.php', 'email-footer.php', 'plain');
$list = array_diff($files, $exclude);
?><form method="get" action="<?php echo site_url(); ?>/wp-admin/admin-ajax.php">
<input type="hidden" name="order" value="942">
<input type="hidden" name="action" value="previewemail">
<select name="file">
<?php foreach ($list as $item) { ?>
<option value="<?php echo $item; ?>"><?php echo str_replace('.php', '', $item); ?></option>
<?php } ?>
</select><input type="submit" value="Go"></form><?php
global $order;
$order = new WC_Order($_GET['order']);
echo'<pre>';
print_r($order);
echo'<pre>';
//die($order->billing_email);
wc_get_template('emails/email-header.php', array('order' => $order));
wc_get_template('emails/' . $_GET['file'], array('order' => $order));
wc_get_template('emails/email-footer.php', array('order' => $order));
}
return null;
}
add_action('wp_ajax_previewemail', 'previewEmail');
/* add media frontend bof */
/* add media frontend eof */
/* hook update user bof */
/* send email template when admin update user details */
/*function admin_update_user($user_id, $old_user_data) {
//die('22222');
$userDtl = get_userdata($user_id);
$pass1 = filter_input(INPUT_POST, 'pass1');
$pass2 = filter_input(INPUT_POST, 'pass2');
if (!empty($pass1) && $pass1 === $pass2 && sanitize_text_field($pass1) === $pass1):
$userPassword = sanitize_text_field($pass1);
else:
$userPassword = 'Your chosen password';
endif;
if (current_user_can('edit_user', $user_id)) {
ob_start();
include_once('woocommerce/emails/email-header.php');
include_once('woocommerce/emails/user-account-updated.php');
include_once('woocommerce/emails/email-footer.php');
$message = ob_get_contents();
ob_end_clean();
$headers = array('Content-Type: text/html; charset=UTF-8');
wp_mail($userDtl->user_email, 'Your K-Docs account is activated', $message, $headers);
}
}*/
function wpse_user_update($user_id) {
if (current_user_can('manage_options')) {
//die('$user_id-'.$user_id);
$user_info = get_userdata($user_id);
//echo'<pre>';
//print_r($userDtl);
$pass1 = filter_input(INPUT_POST, 'pass1');
$pass2 = filter_input(INPUT_POST, 'pass2');
$uemail2 = strlen($user_info->user_email)>0?$user_info->user_email:$user_info->user_login;
if (!empty($pass1) && $pass1 === $pass2 && sanitize_text_field($pass1) === $pass1):
$userPassword = sanitize_text_field($pass1);
else:
$userPassword = 'Your chosen password';
endif;
if (current_user_can('edit_user', $user_id)) {
ob_start();
include_once('woocommerce/emails/email-header.php');
include_once('woocommerce/emails/user-account-updated.php');
include_once('woocommerce/emails/email-footer.php');
$message = ob_get_contents();
ob_end_clean();
$headers = array('Content-Type: text/html; charset=UTF-8');
wp_mail($uemail2, 'Your K-Docs account is updaed', $message, $headers);
}
}
}
add_action('edit_user_profile_update', 'wpse_user_update');
add_action('personal_options_update', 'wpse_user_update');
/* hook update user eof */
?>