AnsPress_Hooks::wp_insert_post_data( array $data, array $args )

Description #

Filter post so that anonymous author should not be replaced by current user approving post.

Parameters #

  • $data
    array (Required) post data.
  • $args
    array (Required) Post arguments.

Changelog #

VersionDescription
4.1.0Fixed: post_author get replaced if anonymous_name is empty.
2.2Introduced.

Source #

File: includes/hooks.php

	public static function wp_insert_post_data( $data, $args ) {
		global $post;

		if ( in_array( $args['post_type'], [ 'question', 'answer' ], true ) ) {
			$fields = ap_get_post_field( 'fields', $args['ID'] );

			if ( ( is_object( $post ) && '0' === $post->post_author ) || ( !empty( $fields ) && !empty( $fields['anonymous_name'] ) ) ) {
				$data['post_author'] = '0';
			}
		}

		return $data;
	}

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