all_post_types = (bool) $all_post_types; $this->post_types = array_values( array_filter( array_map( 'strval', $post_types ) ) ); } /** * Whether comments are disabled for a post type. * * @param string $post_type Post type slug. * @return bool */ public function is_disabled_for( $post_type ) { if ( '' === (string) $post_type ) { return false; } if ( $this->all_post_types ) { return true; } return in_array( $post_type, $this->post_types, true ); } /** * Whether comments are disabled for the post type of a given post. * * @param int|\WP_Post|null $post Post id or object. * @return bool */ public function is_disabled_for_post( $post ) { $post_type = get_post_type( $post ); if ( ! $post_type ) { return false; } return $this->is_disabled_for( $post_type ); } /** * Whether every post type is covered. * * @return bool */ public function covers_everything() { return $this->all_post_types; } /** * The post types this guard covers, resolved against what is registered. * * @return string[] */ public function covered_post_types() { if ( $this->all_post_types ) { return get_post_types( array(), 'names' ); } return $this->post_types; } }