Activity_Helper::delete( array $where )

Description #

Delete single and multiple activity from database.

Parameters #

  • $where
    array (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.

Changelog #

VersionDescription
4.1.2Introduced.

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 ); // DB call okay, DB cache okay.

		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;
	}

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