ap_get_all_reputation_events( array $args = array() )

Description #

Delete a reputation event by slug.

Parameters #

  • $args
    array (Optional) Arguments. Default value: array()

Changelog #

VersionDescription
4.3.0Introduced.

Source #

File: includes/reputation.php

function ap_get_all_reputation_events( $args = array() ) {
	global $wpdb;

	$args = wp_parse_args(
		$args,
		array(
			'order_by' => 'rep_events_id',
			'order'    => 'ASC',
			'per_page' => 20,
			'offset'   => 0,
		)
	);

	extract( $args ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract

	$columns = array( 'rep_events_id', 'slug', 'label', 'points', 'parent' );

	$order    = 'ASC' === $args['order'] ? 'ASC' : 'DESC';
	$order_by = sanitize_key( $order_by );
	$order_by = in_array( $order_by, $columns, true ) ? $order_by : 'rep_events_id';
	$per_page = (int) $per_page;
	$offset   = $offset < 0 ? 0 : absint( $offset );

	$order_st = $wpdb->prepare( "ORDER BY %s {$order}", $order_by ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
	$limit_st = $per_page < 0 ? '' : "LIMIT $offset,$per_page";

	$query = "SELECT * FROM $wpdb->ap_reputation_events WHERE 1=1 $order_st $limit_st";

	$results = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB

	return $results;
}

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