Activity::__construct( array $args = array() )

Description #

Initialize the activity class.

By default if no arguments are passed then all activities of site will be shown.

Parameters #

  • $args
    array (Optional) Arguments.
    • 'q_id'
      (integer) Question id, to fetch activities only related to a specific question.
    • 'a_id'
      (integer) Answer id, to fetch activities only related to a specific answer.
    • 'number'
      (integer) Activities to show per page.
    • 'orderby'
      (integer) name of column to order activities. Valid values are: activity_date, activity_q_id, activity_a_id, activity_user_id.
    • 'order'
      (integer) Activity order. DESC is default order.
    Default value: array()

Changelog #

VersionDescription
4.1.2Introduced.

Source #

File: includes/class/class-activity.php

77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
public function __construct( $args = array() ) {
    $this->paged  = isset( $args['paged'] ) ? (int) $args['paged'] : 1;
    $this->offset = $this->per_page * ( $this->paged - 1 );
 
    $this->args = wp_parse_args(
        $args,
        array(
            'number'        => $this->per_page,
            'offset'        => $this->offset,
            'orderby'       => 'activity_date',
            'order'         => 'DESC',
            'exclude_roles' => array( 'administrator' ),
        )
    );
 
    // Check if valid orderby argument.
    $valid_orderby = array( 'activity_q_id', 'activity_a_id', 'activity_c_id', 'activity_date' );
    if ( ! in_array( $this->args['orderby'], $valid_orderby, true ) ) {
        $this->args['orderby'] = 'activity_date';
    }
 
    $this->per_page = $this->args['number'];
    $this->query();
}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment