WordPress,检索当前正在编辑的用户个人资料页面的ID

时间:2018-05-29 18:29:40

标签: php wordpress advanced-custom-fields

我正在开发一个WordPress插件。编辑用户的个人资料页面时,我需要能够检索该用户的ID(不是当前登录的用户)。

我正在使用高级自定义字段插件,并使用负载过滤器来处理相关功能。

add_filter( 'acf/load_field/name=funbotic_parents', 'funbotic_load_parents' );

function funbotic_load_parents( $field ) {

    $args = array(
        'role'      => 'customer',
        'orderby'   => 'display_name',
        'order'     => 'ASC',
    );

    $parent_data_array = get_users( $args );

    // Clear choices array in case it was previously set.
    $field['choices'] = array();

    foreach ( $parent_data_array as $parent ) {
        $parent_ID = $parent->ID;
        $parent_display_name = $parent->display_name;
        $field['choices'][$parent_ID] = $parent_display_name;
    }

    $current_user = (int) $_GET['user_id'];

    $previously_associated_parents = get_user_meta( $current_user_id, 'funbotic_parents' );

    if ( empty( $previously_associated_parents ) || is_null( $previously_associated_parents ) ) {
        update_user_meta( $current_user_id, 'funbotic_previously_associated_parents', $previously_associated_parents );
    } else {
        $new_meta = funbotic_clean_array( $previously_associated_parents );
        update_user_meta( $current_user_id, 'funbotic_previously_associated_parents', $new_meta );
    }

    return $field;

}

$current_user = (int) $_GET['user_id'];行正在返回null。有没有办法从URL中提取'user_id'?这不是一个理想的解决方案,但在这一点上我开始变得绝望。 URL如下所示:

http://dev-funbotic.local/wp-admin/user-edit.php?user_id=115&wp_http_referer=%2Fwp-admin%2Fusers.php%3Fs%3Dtest%26action%3D-1%26new_role%26course_id%26group_id%26paged%3D1%26action2%3D-1%26new_role2

1 个答案:

答案 0 :(得分:0)

您可以尝试获取当前网址并将其分解以查询这样的参数:

$params['user_id'][0]


然后您可以通过 import itertools list_Abecedario= ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"] for i in range(1, len(list_Abecedario)+1): for x in list(itertools.permutations(list_Abecedario, i)): aux = ''.join(x) print(aux)

访问user_id
相关问题