bbp_update_anonymous_post_author( int $post_id, array $anonymous_data = array(), string $post_type = '' )

Update the relevant meta-data for an anonymous post author


Description Description


Parameters Parameters

$post_id

(Required)

$anonymous_data

(Optional)

Default value: array()

$post_type

(Optional)

Default value: ''


Top ↑

Source Source

File: includes/common/functions.php

function bbp_update_anonymous_post_author( $post_id = 0, $anonymous_data = array(), $post_type = '' ) {

	// Maybe look for anonymous
	if ( empty( $anonymous_data ) ) {
		$anonymous_data = bbp_filter_anonymous_post_data();
	}

	// Sanitize parameters
	$post_id   = (int) $post_id;
	$post_type = sanitize_key( $post_type );

	// Bail if missing required data
	if ( empty( $post_id ) || empty( $post_type ) || empty( $anonymous_data ) ) {
		return;
	}

	// Parse arguments against default values
	$r = bbp_parse_args( $anonymous_data, array(
		'bbp_anonymous_name'    => '',
		'bbp_anonymous_email'   => '',
		'bbp_anonymous_website' => '',
	), "update_{$post_type}" );

	// Update all anonymous metas
	foreach ( $r as $anon_key => $anon_value ) {

		// Update, or delete if empty
		! empty( $anon_value )
			? update_post_meta( $post_id, '_' . $anon_key, (string) $anon_value, false )
			: delete_post_meta( $post_id, '_' . $anon_key );
	}
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.6.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.