首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >自定义用户注册时间

自定义用户注册时间
EN

WordPress Development用户
提问于 2020-06-26 11:57:41
回答 1查看 637关注 0票数 0

我们使用的学习LMS,并希望让用户每天早上6点获得访问与注册为基础的访问。为此,LMS将每个用户的注册时间存储在UNIX中的db usermeta表中。因此,我的问题是:如何将此值更改为用户注册的相同日期,只要时间是上午8点,但日期保持不变?如何在用户注册后不久运行此功能?

Thx

EN

回答 1

WordPress Development用户

发布于 2020-06-26 15:11:03

勒恩达什用过滤器给我写信:

代码语言:javascript
复制
/**
* LearnDash Lesson Access From
*
* This filter is called when using the learndash lesson drip feed options. This filter allows override timestamp value.
*
* @since 2.4
*
* @param int $gmt_timestamps This is a GMT timestamp value like 1489062972
* @param int $lesson_id The Lesson post ID.
* @param int $user_id The User ID. This is the user_id value passed to the calling function. It may not be the current user
*
* @return int adjusted value for $gmt_timestamp
*/
add_filter( 'ld_lesson_access_from__visible_after', function ( $gmt_timestamp = 0, $lesson_id = 0, $user_id = 0 ) {

// Check to ensure our timestamp is not empty
if ( !empty( $gmt_timestamp ) ) {

// Example 1: In this example we want to remove hh:mm:ss: values from the timestamp so the user gets access at midnight.
// Let's assume for the purpose of this example you have a lesson using the 'Make lesson visible X days after sign-up' option with a value
// if '1'. A student started the course on 2017-02-18 02:34pm. This would mean with the '1' value they will get access to the lesson one
// day (24 hours) later on 2017-02-19 02:34pm.
// But assume you don't want the user to have to wait 24 hours. You want the user do get access at the start of the next day 2017-02-19 (midnight)

// The logic below is how this can be done.

// Then convert to YMD format.
$gmt_ymd = date('Y-m-d H:i:s', $gmt_timestamp );

// At this point $gmt_ymd is still GMT so we need to adjust it to our local timezone. To do
// we use the WP utility function get_date_from_gmt(). But instead of converting the
// hour/minute/seconds to local we want to set these to 00:00:00 so the time is midnight
$gmt_local_midnight = get_date_from_gmt( $gmt_ymd, 'Y-m-d 00:00:00' );


// so noy we have a nice human readable value in $gmt_local_midnight
// that will be something like '2017-02-15 00:00:00'.


// We now need to return a timestamp (not YMD) back to LD. So we need to convert the YMD
// date back into a timestamp
$gmt_timestamp = learndash_get_timestamp_from_date_string( $gmt_local_midnight, true );
}


// Always return the $gmt_timestamp.
return $gmt_timestamp;


}, 10, 3);
票数 0
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/369830

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档