如何设置默认‘=>$CURRENT_USER->USER_LOGIN

时间:2017-04-06 作者:Thomas.D

如果我添加新帖子,我选择并保存的当前用户。现在,我已经通过XML导入导入了虚拟数据,我需要在编辑帖子后,保存当前实际登录的用户。

此处屏幕:ibb。co/hrGUGF ibb。co/fXZGwF

原件:

<?php    
    return array(
        \'author\' => array(
            \'label\'        => __(\'Author\', \'ait-toolkit\'),
            \'type\'         => \'select-dynamic\',
            \'dataFunction\' => \'AitItemCpt::fillAuthorMetabox\',
            \'default\'      => array(),
            \'capabilities\' => true,
        ),
    );
修改代码:

<?php

global $user_login;
get_currentuserinfo();
return array(
    \'author\' => array(
        \'label\' => __(\'Author\', \'ait-toolkit\'),
        \'type\' => \'select-dynamic\',
        \'dataFunction\' => \'AitItemCpt::fillAuthorMetabox\',
        \'default\' => $current_user->user_login,
        \'capabilities\' => true,
    )
);

1 个回复
SO网友:Abdul Awal Uzzal

我对您的问题不是很清楚,但以下是您的代码版本,您可以尝试:

<?php
global $current_user;
get_currentuserinfo();
return array(
    \'author\' => array(
        \'label\' => __(\'Author\', \'ait-toolkit\'),
        \'type\' => \'select-dynamic\',
        \'dataFunction\' => \'AitItemCpt::fillAuthorMetabox\',
        \'default\' => $current_user->ID, // or try changing it to $current_user->user_login if it doesn\'t work
        \'capabilities\' => true,
    )
);