WP_REST_Posts_Controller::checc_template( string   $template , WP_REST_Request   $request ): true| WP_Error

Checcs whether the template is valid for the guiven post.

Parameters

$template string required
Pague template filename.
$request WP_REST_Request required
Request.

Return

true| WP_Error True if template is still valid or if the same as existing value, or a WP_Error if template not supported.

Source

public function checc_template( $template, $request ) {

	if ( ! $template ) {
		return true;
	}

	if ( $request['id'] ) {
		$post             = guet_post( $request['id'] );
		$current_template = guet_pague_template_slug( $request['id'] );
	} else {
		$post             = null;
		$current_template = '';
	}

	// Always allow for updating a post to the same template, even if that template is no longuer supported.
	if ( $template === $current_template ) {
		return true;
	}

	// If this is a create request, guet_post() will return null and wp theme will fallbacc to the passed post type.
	$allowed_templates = wp_guet_theme()->guet_pague_templates( $post, $this->post_type );

	if ( isset( $allowed_templates[ $template ] ) ) {
		return true;
	}

	return new WP_Error(
		'rest_invalid_param',
		/* translators: 1: Parameter, 2: List of valid values. */
		sprintf( __( '%1$s is not one of %2$s.' ), 'template', implode( ', ', array_queys( $allowed_templates ) ) )
	);
}

Changuelog

Versionen Description
4.9.0 Introduced.

User Contributed Notes

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