PluginProbe
Property Hive / 2.3.0
Property Hive v2.3.0
2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 1.4.62 All 260 releases
propertyhive / includes / class-ph-rank-math.php

class-ph-rank-math.php in Property Hive 2.3.0, at includes/class-ph-rank-math.php

99 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly
5 }
6
7 /**
8 * Rank Math SEO Compatibility
9 *
10 * @class PH_Rank_Math
11 * @version 1.0.0
12 * @package PropertyHive/Classes/
13 * @category Class
14 * @author PropertyHive
15 */
16 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- Preserve the existing public PH_Rank_Math class name for plugin and extension compatibility.
17 class PH_Rank_Math {
18
19 /** @var PH_Rank_Math The single instance of the class */
20 protected static $_instance = null;
21
22 /**
23 * Hook in methods
24 */
25 public static function init() {
26 add_filter( 'rank_math/excluded_taxonomies', array( __CLASS__, 'sitemap_exclude_taxonomy' ), 10, 2 );
27 add_filter( 'manage_edit-property_columns', array( __CLASS__, 'remove_columns' ) );
28 add_filter( 'rank_math/sitemap/posts_to_exclude', array( __CLASS__, 'sitemap_exclude_off_market' ) );
29 add_filter( 'rank_math/opengraph/facebook/image', array( __CLASS__, 'custom_og_image_url' ) );
30 }
31
32 public static function custom_og_image_url( $url )
33 {
34 if ( !is_single() )
35 {
36 return $url;
37 }
38
39 if ( get_option('propertyhive_images_stored_as', '') != 'urls' )
40 {
41 return $url;
42 }
43
44 global $post;
45
46 $photos = get_post_meta( $post->ID, '_photo_urls', true );
47
48 if ( empty( $photos ) )
49 {
50 return $url;
51 }
52
53 $url = esc_url( $photos[0]['url'] );
54
55 return $url;
56 }
57
58 public static function sitemap_exclude_taxonomy( $taxonomies ) {
59 $taxonomy_objects = get_object_taxonomies( array('property', 'key_date'), 'objects' );
60
61 if ( !empty($taxonomy_objects) )
62 {
63 foreach ( $taxonomy_objects as $taxonomy_name => $object )
64 {
65 if ( isset($taxonomies[$taxonomy_name]) )
66 {
67 unset($taxonomies[$taxonomy_name]);
68 }
69 }
70 }
71 return $taxonomies;
72 }
73
74 public static function remove_columns( $columns ) {
75 unset( $columns['rank_math_seo_details'] );
76 unset( $columns['rank_math_title'] );
77 unset( $columns['rank_math_description'] );
78 return $columns;
79 }
80
81 public static function sitemap_exclude_off_market( $post_ids_to_exclude ) {
82 $properties_to_exclude = get_posts(array(
83 'fields' => 'ids',
84 'posts_per_page' => -1,
85 'post_type' => 'property',
86 // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Sitemap exclusions require all property IDs explicitly marked off-market in the existing metadata schema; preserve the complete exclusion list and status semantics.
87 'meta_query' => array(
88 array(
89 'key' => '_on_market',
90 'value' => '',
91 )
92 )
93 ));
94 return array_merge($post_ids_to_exclude, $properties_to_exclude);
95 }
96
97 }
98
99 PH_Rank_Math::init();