admin管理员组文章数量:1304632
I have a plugin that gets a value on user register and stores it in its own automatic made table.
I need to set that same value into a usermeta custom meta_value, so the user will be able to see it from user settings. (this will also make that I will be able to see it in the users admin panel etc..)
See final screenshot (self explanatory for all the post) I was going to paste another here but I prefer this post to be lighter.
I already have the code to set a usermeta custom value and let the user modify it from settings panel (already working). (user won't be able to modify it, this will be blocked, just here for testing purposes)
I share the code and a screenshot below, notice the usermeta custom value is empty now.. (I simply added this as a plugin in wordpress)
<?php
/*
Plugin Name: #Addy Plugin
Plugin URI: #
Description: #
Version: 0.1
Author: #
Author URI: #
License: GPLv2 or later
Text Domain: #
*/
//$wpdb->show_errors(); $wpdb->print_error();
add_action( 'personal_options_update', 'save_extra_user_profile_fields_uny' );
add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields_uny' );
function save_extra_user_profile_fields_uny( $user_id ) {
if(!current_user_can( 'edit_user', $user_id ) ) {
return false;
}
update_user_meta($user_id, 'ethaddyadd', $_POST["ethaddyadd"]);
}
add_action( 'show_user_profile', 'extra_user_profile_fields_uny' );
add_action( 'edit_user_profile', 'extra_user_profile_fields_uny' );
function extra_user_profile_fields_uny( $user ) {
$user_id = $user->ID;
?>
<script type="text/javascript" src=".4.0.js"></script>
<h3>Extra profile information</h3>
<table class="form-table">
<tr>
<td>Ethaddyadd</td>
<td><input type="text" name="ethaddyadd">
</td>
</tr>
</table>
<script type="text/javascript">
$('input').addClass('regular-text');
$('input[name=ethaddyadd]').val('<?php echo get_the_author_meta('ethaddyadd', $user->ID); ?>');
</script>
<?php
}
function new_modify_user_table_uny( $column ) {
$column['ethaddyadd'] = 'Ethaddyadd';
return $column;
}
add_filter( 'manage_users_columns', 'new_modify_user_table_uny' );
function new_modify_user_table_row_uny( $val, $column_name, $user_id ) {
$meta = get_user_meta($user_id);
switch ($column_name) {
case 'ethaddyadd' :
$ethaddyadd = $meta['ethaddyadd'][0];
return $ethaddyadd;
default:
}
return $val;
}
add_filter( 'manage_users_custom_column', 'new_modify_user_table_row_uny', 10, 3 );
I also have a code that shows the data from the mysql column that I need if I set a root test.php file and test it.
<?php
require_once('wp-load.php');
$get = $wpdb->get_results("
SELECT
addresses.name
FROM
".$wpdb->prefix."addresses as addresses
");
/*
echo "<pre>";print_r($get);echo "</pre>";
*/
foreach ( $get as $print ) { ?>
<pre> <?php echo $print->name; ?> </pre>
<?php
}
?>
¿ How can I then tell the database/wordpress input the other table value into the user's usermeta custom value ?
Final screenshot.
Thank you for all your knowledge sharing ;)
本文标签:
版权声明:本文标题:database - How to replicate a user plugin made table value, to this user's custom meta table value? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741788524a2397525.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论