Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何向URL添加更多用户数据_Php_Wordpress - Fatal编程技术网

Php 如何向URL添加更多用户数据

Php 如何向URL添加更多用户数据,php,wordpress,Php,Wordpress,我需要向URL添加更多用户数据。目前,我正在尝试将$last_name字符串添加到我的函数中,但似乎无法正确执行。 将来,我们可能会根据注册用户的不同向URL中添加更多信息 请检查以下代码: 另外,我在Stackoverflow上找到了函数的基础,但不确定是哪个链接。我已对功能进行了更改以满足我的需要 它成功地拔出了第一个名字 function add_userid_page_url(){ $user_info = get_userdata(get_current_user_i

我需要向URL添加更多用户数据。目前,我正在尝试将$last_name字符串添加到我的函数中,但似乎无法正确执行。 将来,我们可能会根据注册用户的不同向URL中添加更多信息

请检查以下代码:

另外,我在Stackoverflow上找到了函数的基础,但不确定是哪个链接。我已对功能进行了更改以满足我的需要

它成功地拔出了第一个名字

function add_userid_page_url(){
    
    $user_info = get_userdata(get_current_user_id());
    $first_name = $user_info->first_name;
    $last_name = $user_info->last_name;
    
    if( is_user_logged_in() && is_page('my-account') && !isset( $_GET['fname'] ) ) : //Check User Logged In and Account Page and User Info not set in URL
        wp_safe_redirect( add_query_arg('fname', $first_name, get_permalink() ) );
    endif; //Endif
}
add_action('template_redirect', 'add_userid_page_url');
只是更新一下

我找到了一种将用户信息添加到URL结构中的方法

以备将来有人需要

    <?php
      function add_userid_page_url(){
      $user_id = get_current_user_id();
      $user_info = get_userdata($user_id);
        $logged_in = array (
          $first_name = $user_info->user_firstname,
          $last_name = $user_info->user_lastname,
          $email_address = $user_info->user_email,
        );
      if( is_user_logged_in() && is_page('my-account') && !isset( $_GET['user_details'] ) ) : //Check User Logged In and Page and User Id not set in URL
         wp_safe_redirect( add_query_arg( 'user_details', $logged_in, get_permalink() ) );
      endif; //Endif
        }
      add_action('template_redirect', 'add_userid_page_url');
    ?>


到目前为止,您做了哪些尝试和调试工作?您是否验证了在您希望的上下文中调用函数?您是否检查了
if
语句的所有单个条件是否都为true?我已尝试以各种方式向字符串中添加另一个$\u GET(,$\u GET&&$\u GET“”&&$\u GET),但没有任何结果。但是,我可以在URL中调用lname,但不能调用$last_name。不确定你在if语句中真正的意思是什么