| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Yoast\WP\SEO\Helpers; |
| 4 | 4 | |
| 5 | +use WP_Error; | |
| 5 | 6 | use Yoast\WP\SEO\Models\Indexable; |
| 6 | 7 | |
| 7 | 8 | /** |
| 8 | 9 | * A helper object for permalinks. |
| @@ -18,12 +19,9 @@ | ||
| 18 | 19 | */ |
| 19 | 20 | public function get_permalink_for_indexable( $indexable ) { |
| 20 | 21 | switch ( true ) { |
| 21 | 22 | case $indexable->object_type === 'post': |
| 22 | - if ( $indexable->object_sub_type === 'attachment' ) { | |
| 23 | - return \wp_get_attachment_url( $indexable->object_id ); | |
| 24 | - } | |
| 25 | - return \get_permalink( $indexable->object_id ); | |
| 23 | + return $this->get_permalink_for_post( $indexable->object_sub_type, $indexable->object_id ); | |
| 26 | 24 | case $indexable->object_type === 'home-page': |
| 27 | 25 | return \home_url( '/' ); |
| 28 | 26 | case $indexable->object_type === 'term': |
| 29 | 27 | $term = \get_term( $indexable->object_id ); |
| @@ -41,6 +39,22 @@ | ||
| 41 | 39 | return \get_author_posts_url( $indexable->object_id ); |
| 42 | 40 | } |
| 43 | 41 | |
| 44 | 42 | return null; |
| 43 | + } | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * Retrieves the permalink for a post with the given post type and ID. | |
| 47 | + * | |
| 48 | + * @param string $post_type The post type. | |
| 49 | + * @param int $post_id The post ID. | |
| 50 | + * | |
| 51 | + * @return WP_Error|string|false The permalink. | |
| 52 | + */ | |
| 53 | + public function get_permalink_for_post( $post_type, $post_id ) { | |
| 54 | + if ( $post_type !== 'attachment' ) { | |
| 55 | + return \get_permalink( $post_id ); | |
| 56 | + } | |
| 57 | + | |
| 58 | + return \wp_get_attachment_url( $post_id ); | |
| 45 | 59 | } |
| 46 | 60 | } |