PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.5
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
← All changes | src/helpers/permalink-helper.php +18 -4 18.228.5 View file →
@@ -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 }