ap_new_edit_post_status( boolean|integer $user_id = false, string $post_type = 'question', boolean $edit = false )

Description #

Return post status based on AnsPress options.

Parameters #

  • $user_id
    boolean | integer (Optional) ID of user creating question. Default value: false
  • $post_type
    string (Optional) Post type, question or answer. Default value: 'question'
  • $edit
    boolean (Optional) Is editing post. Default value: false

Changelog #

VersionDescription
3.0.0Introduced.

Source #

File: includes/functions.php

function ap_new_edit_post_status( $user_id = false, $post_type = 'question', $edit = false ) {
	if ( false === $user_id ) {
		$user_id = get_current_user_id();
	}

	$new_edit   = $edit ? 'edit' : 'new';
	$option_key = $new_edit . '_' . $post_type . '_status';
	$status     = 'publish';

	// If super admin or user have no_moderation cap.
	if ( is_super_admin( $user_id ) || user_can( $user_id, 'ap_no_moderation' ) ) {
		return $status;
	}

	if ( ap_opt( $option_key ) === 'moderate' && ! ( user_can( $user_id, 'ap_moderator' ) || is_super_admin( $user_id ) ) ) {
		$status = 'moderate';
	}

	// If anonymous post status is set to moderate.
	if ( empty( $user_id ) && ap_opt( 'anonymous_post_status' ) === 'moderate' ) {
		$status = 'moderate';
	}

	return $status;
}

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