ap_insert_reputation_event( string $slug, string $label, string $description, int $points, int $activity, string $parent_type = '', string $icon = '' )

Description #

Insert a reputation event to database.

Parameters #

  • $slug
    string (Required) Reputation event unique slug.
  • $label
    string (Required) Reputation event label, must be less than 100 letters.
  • $description
    string (Required) Reputation event description.
  • $points
    int (Required) Signed point value.
  • $activity
    int (Required) Activity label.
  • $parent_type
    string (Optional) Parent type. Default value: ''
  • $icon
    string (Optional) Reputation event icon. Default value: ''

Changelog #

VersionDescription
4.4.0Added new argument $icon for setting the respective reputation event icon.
4.3.0Introduced.

Source #

File: includes/reputation.php

function ap_insert_reputation_event( $slug, $label, $description, $points, $activity, $parent_type = '', $icon = '' ) {
	global $wpdb;

	$slug     = sanitize_key( $slug );
	$existing = ap_get_reputation_event_by_slug( $slug );

	if ( $existing ) {
		return new WP_Error( 'already_exits' );
	}

	$inserted = $wpdb->insert( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
		$wpdb->ap_reputation_events,
		array(
			'slug'        => $slug,
			'label'       => $label,
			'description' => $description,
			'points'      => $points,
			'activity'    => $activity,
			'parent'      => $parent_type,
			'icon'        => $icon,
		),
		array(
			'%s',
			'%s',
			'%s',
			'%d',
			'%s',
			'%s',
			'%s',
		)
	);

	if ( $inserted ) {
		$inserted_id = $wpdb->insert_id;

		// Delete cache.
		wp_cache_delete( 'all', 'ap_get_all_reputation_events' );

		/**
		 * Hook called right after inserting a reputation event.
		 *
		 * @param object $event Reputation event id.
		 * @since 4.3.0
		 */
		do_action( 'ap_inserted_reputation_event', $inserted_id );

		return $inserted_id;
	}

	return new WP_Error( 'failed_to_insert_rep_event' );
}

2 Comments

  1. Hello, I use this for the avada theme, but the simple question page alaways cant correct show the header and footer, any solutions

    Reply
  2. Congrats on the 4.4.0 release! The reputation and moderation improvements look solid. We run a Q&A section for users of GenPix (an AI image tool) and moderation workflow is exactly the pain point this solves. Upgrade path looks smooth – testing it this weekend.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

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

Add your comment