Activity_Helper::delete( array $where )
Description #
Delete single and multiple activity from database.
Parameters #
- $wherearray (Required) Where clause for delete query.
- 'action'
(string) Activity action name. - 'q_id'
(integer) Question id. This is a required argument. - 'a_id'
(integer) Answer id. This is optional. - 'c_id'
(integer) Comment id. This is optional. - 'user_id'
(integer) Activity user id. This is optional. - 'date'
(string) Activity date. This is optional.
- 'action'
Source #
File: includes/class/class-activity-helper.php
public function delete( $where ) { global $wpdb; $where = wp_array_slice_assoc( $where, array( 'action', 'a_id', 'c_id', 'q_id', 'user_id', 'date' ) ); $types = array(); $cols = array(); foreach ( $where as $key => $value ) { if ( in_array( $key, array( 'action', 'date' ), true ) ) { $types[] = '%s'; } else { $types[] = '%d'; } $cols[ 'activity_' . $key ] = $value; } // Check if there are columns. if ( empty( $cols ) ) { return new WP_Error( 'no_cols', __( 'No columns found in where clue', 'anspress-question-answer' ) ); } $deleted = $wpdb->delete( $this->table, $cols, $types ); // phpcs:ignore WordPress.DB if ( false === $deleted ) { return new WP_Error( 'failed_to_delete', __( 'Failed to delete activity rows.', 'anspress-question-answer' ) ); } /** * Hook triggered right after an AnsPress activity is deleted from database. * * @param array $where Where clauses. * @since 4.1.2 */ do_action( 'ap_activity_deleted', $where ); return $deleted; }
Expand full source code Collapse full source code View on GitHub: includes/class/class-activity-helper.php:437
Add your comment