Skip to:
Content
Pages
Categories
Search
Top
Bottom

2 specific issues about extending


  • honoluluman
    Participant

    @honoluluman

    Hello,

    I am trying to create 2 functionalities and i would like to ask for your help please.

    1. Trying to get all users with WP_User_Query that have not been active for last 60 days

    // Get the contributors and administrators who haven't logged in for 60 days
        $args = array( 
        'role__in' => array( 'contributor', 'administrator' ),
    	'meta_key'     => 'last_activity', // this is a meta_key storing the last time the user was logged in by buddypress in 'Y-m-d H:i:s' format
    	'meta_query' => array( 
            array(
                'key' => 'last_activity',
                'value' => date('Y-m-d H:i:s', strtotime( "-60 days" )), // what am i doing wrong? 
                'compare' => '<',
                'type' => 'DATE' // Let WordPress know we're working with date
                )
            )
        );
    
        $remind_users = new WP_User_Query( $args ); 

    -What am i doing wrong on the comparison?

    2. Send en email notification to specific users when there is a sidewide notice on our website.

    function important_notification() {
        
        $notification = '' . bp_get_message_notice_text( $notice->message ) . '';
    
        $args = array(
        'meta_key'     => '_is_featured'
        );
        
    
        $members = get_users( $args );
        foreach( $members as $member ) {
        $user_id = $member->ID;
        $member_account = bp_core_get_user_domain( $user_id );
        
        $first_name = $member->first_name;
    
        $email_subject = 'Important information';
    
        $message = sprintf( 'Hello %1$s,' , $first_name ) . "<br><br>"; 
       
        $message .= sprintf( 'We have an important information for you:' ) ."<br><br>"; 
        $message .= sprintf( '<i>%1$s</i>' , $notification ) ."<br><br>";
        $message .= sprintf( 'Please login <a href="%1$s" target="_blank">to your account</a> to remove the information if you want.' , $member_account ) ."<br><br>";
        
    
        
        wp_mail( $member->user_email, $email_subject, $message );
        }
    }
    add_action(  'xxxxxxxx',  'important_notification');

    -Will the $notification = '' . bp_get_message_notice_text( $notice->message ) . ''; get the message text of the sidewide notice?
    -In which action could i hook this function in order to send an email when admin will publish a sidewide notification?
    add_action( ‘xxxxxxxx’, ‘important_notification’);

    Thank you very much for your time.

Viewing 3 replies - 1 through 3 (of 3 total)

  • shanebp
    Moderator

    @shanebp

    afaik – last-activity is no longer stored in the usermeta table.
    For the first issue, look at the {prefix}_bp_activity table.
    I would just write a custom $wpdb->get_col query that gets the user_id for type=’last_activity’ and date_recorded < NOW() + INTERVAL -60 DAY in the desired range.
    The result will be a one-dimensional array of user ids – but it will not factor in user roles.
    If roles are important, then write another query that just returns IDs based on role and the array returned by the first query.
    $user_query = new WP_User_Query( array( 'role' => 'contributor', 'fields' => 'ID'. 'include' => $array_from_first_query ) );


    honoluluman
    Participant

    @honoluluman

    hello @shanebp and thank you for your support 🙂

    I just tested on my site and if i echo

    $user_info = get_userdata( 40 );
    echo '<strong>' . $user_info->last_activity . '</strong>';

    i get the last activity normal. I also checked in the db in the usermeta table and i found the meta_key with last_activity . Am i missing something?


    shanebp
    Moderator

    @shanebp

    On my installs, the value in the usermeta table is not accurate.
    The value in the activity table is accurate.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar