PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.6
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.6
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
wordpress-seo / src / helpers / permalink-helper.php

permalink-helper.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.6, at src/helpers/permalink-helper.php

47 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\Helpers;
4
5 use Yoast\WP\SEO\Models\Indexable;
6
7 /**
8 * A helper object for permalinks.
9 */
10 class Permalink_Helper {
11
12 /**
13 * Retrieves the permalink for an indexable.
14 *
15 * @param Indexable $indexable The indexable.
16 *
17 * @return string|null The permalink.
18 */
19 public function get_permalink_for_indexable( $indexable ) {
20 switch ( true ) {
21 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 );
26 case $indexable->object_type === 'home-page':
27 return \home_url( '/' );
28 case $indexable->object_type === 'term':
29 $term = \get_term( $indexable->object_id );
30
31 if ( $term === null || \is_wp_error( $term ) ) {
32 return null;
33 }
34
35 return \get_term_link( $term, $term->taxonomy );
36 case $indexable->object_type === 'system-page' && $indexable->object_sub_type === 'search-page':
37 return \get_search_link();
38 case $indexable->object_type === 'post-type-archive':
39 return \get_post_type_archive_link( $indexable->object_sub_type );
40 case $indexable->object_type === 'user':
41 return \get_author_posts_url( $indexable->object_id );
42 }
43
44 return null;
45 }
46 }
47