Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Occurrence of wp_insert_post followed by is_wp_error()->throw but default is not to return WP_Error so will never throw #213

Open
markheydon opened this issue Jun 14, 2020 · 0 comments

Comments

@markheydon
Copy link

Slightly long title but explains it pretty much. Example in Vehicle->WordPressRepository.php...

		// create
		$vehicle_id = wp_insert_post( array(
			'post_title'   => $vehicle->get_title(),
			'post_content' => $vehicle->get_description(),
			'post_excerpt' => $vehicle->get_short_description(),
			'post_author'  => $vehicle->get_author(),
			'post_type'    => PostType::VEHICLE,
			'post_status'  => $vehicle->get_status()
		) );

		if ( is_wp_error( $vehicle_id ) ) {
			throw new \Exception( 'Unable to insert post in WordPress database' );
		}

Default behaviour of wp_insert_post is NOT to return WP_Error therefore is_wp_error will always be false even on error.

Ref: https://developer.wordpress.org/reference/functions/wp_insert_post/

@markheydon markheydon changed the title Occurances of wp_insert_post followed by is_wp_error()->throw but default is not to return WP_Error so will never throw Occurrence of wp_insert_post followed by is_wp_error()->throw but default is not to return WP_Error so will never throw Jun 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant