如何访问数组中的字符串值?

时间:2018-03-27 作者:M.S Shohan

目前,我正在开发一个使用Dokan多供应商插件的网站。我在注册表中添加了一个自定义字段

以下代码用于在注册表中添加自定义字段

<p class="form-row form-group form-row-wide">
    <label for="tskypeid"><?php _e( \'Skype ID\', \'dokan-lite\' ); ?> <span class="required">*</span></label>
    <input type="text" class="input-text form-control" name="tskypeid" id="tskype-id" value="<?php if ( ! empty( $postdata[\'tskypeid\'] ) ) echo esc_attr($postdata[\'tskypeid\']); ?>" required="required" />
</p>
这是用于保存字段数据的代码:

// save skype id after registration

function ms_dokan_on_create_seller( $user_id, $data ) {
    if ( $data[\'role\'] != \'seller\' ) {
        return;
    }

    $dokan_settings = array(
        \'tskypeid\'          => $_POST[\'tskypeid\'],
    );

    update_user_meta( $user_id, \'dokan_profile_settings\', $dokan_settings );
    update_user_meta( $user_id, \'dokan_store_name\', $dokan_settings[\'store_name\'] );

    do_action( \'dokan_new_seller_created\', $user_id, $dokan_settings );
}

add_action( \'woocommerce_created_customer\', \'ms_dokan_on_create_seller\', 10, 2);
尝试使用以下代码访问该值:

function wc_vendors_name_loop( $store_id ) {
    $user_id    = get_current_user_id();
    $dokan_profile_settings = get_user_meta( $user_id ) 
    [\'dokan_profile_settings\'];
    echo "<pre>";
    var_dump( $dokan_profile_settings );
    echo "</pre>";
}
add_action( \'wp_footer\', \'wc_vendors_name_loop\' );
此代码输出以下结果:

array(1) {
    [0]=>
    string(1183) 
    "a:17:{
        s:8:"tskypeid";
        s:7:"asdfasd";
        s:10:"store_name";
        s:17:"asdfas dfasdfasdf";
        s:9:"store_ppp";
        i:0;s:7:"address";
        a:6:{
            s:8:"street_1";
            s:19:"fasdf asdf asdf sad";
            s:8:"street_2";
            s:15:"sadf asdf asd f";
            s:4:"city";
            s:10:"asdf asd f";
            s:3:"zip";
            s:8:"sad fsad";
            s:7:"country";
            s:2:"AZ";
            s:5:"state";
            s:9:"asdfasdf ";
        }
        s:8:
        "location";
        s:0:"";
        s:12:"find_address";
        s:27:"dsfas sadf sadfsadfsadf asf";
        s:6:"banner";
        i:0;s:5:"phone";
        s:9:"345346456";
        s:10:"show_email";
        s:3:"yes";
        s:14:"show_more_ptab";
        s:3:"yes";
        s:8:"gravatar";
        i:0;s:10:"enable_tnc";
        s:2:"on";
        s:9:"store_tnc";
        s:27:"asdf asdf asdfa sdf sadfsdf";
        s:18:"profile_completion";
        a:6:{
            s:5:"phone";
            i:10;s:10:"store_name";
            i:10;s:7:"address";
            i:10;s:9:"next_todo";
            s:31:"Add Banner to gain 15% progress";
            s:8:"progress";
            i:30;s:13:"progress_vals";
            a:8:{
                s:10:"banner_val";
                i:15;s:19:"profile_picture_val";
                i:15;s:14:"store_name_val";
                i:10;s:10:"social_val";
                a:5:{
                    s:2:"fb";
                    i:2;s:5:"gplus";
                    i:2;s:7:"twitter";
                    i:2;s:7:"youtube";
                    i:2;s:8:"linkedin";
                    i:2;
                }
                s:18:"payment_method_val";
                i:15;s:9:"phone_val";
                i:10;s:11:"address_val";
                i:10;s:7:"map_val";
                i:15;
            }
        }
        s:23:"show_min_order_discount";
        s:2:"no";
        s:28:"setting_minimum_order_amount";
        s:0:"";
        s:24:"setting_order_percentage";
        s:0:"";
    }"
}
这里我想访问第5行中的“tskypeid”值,第6行中的值是“asdfasd”

请告诉我如何访问该值。

任何帮助都将不胜感激。

提前谢谢你。

2 个回复
SO网友:Welcher

如果您想知道如何通过WordPress获取这些元键,可以使用get_user_meta() - https://codex.wordpress.org/Function_Reference/get_user_meta

get_user_meta( $user_id, \'tskypeid\', true )

SO网友:M.S Shohan

呜呜!我用这个密码把它修好了。作用

wc_vendors_name_loop() { 
    $store_id = dokan_get_current_user_id(); 
    $existing_dokan_settings = get_user_meta( $store_id, \'dokan_profile_settings\', true ); 
    echo $existing_dokan_settings[\'tskypeid\']; 
} 
add_action( \'wp_footer\', \'wc_vendors_name_loop\' ); 
现在我可以在前端显示skype id了。

结束

相关推荐

Wp-login.php注册/丢失按钮的密码链接?

如何设置wp登录的样式。php注册/丢失密码链接到按钮,以简化移动UI?在哪里可以找到将ahref附加到提交的HTML?那个按钮的样式是哪个CSS文件?无需更改对操作的调用,只需将文本链接更改为按钮即可!任何帮助或指导都将不胜感激!