| 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 |
class PH_Rank_Math { |
| 17 |
|
| 18 |
/** @var PH_Rank_Math The single instance of the class */ |
| 19 |
protected static $_instance = null; |
| 20 |
|
| 21 |
/** |
| 22 |
* Hook in methods |
| 23 |
*/ |
| 24 |
public static function init() { |
| 25 |
add_filter( 'rank_math/excluded_taxonomies', array( __CLASS__, 'sitemap_exclude_taxonomy' ), 10, 2 ); |
| 26 |
add_filter( 'manage_edit-property_columns', array( __CLASS__, 'remove_columns' ) ); |
| 27 |
add_filter( 'rank_math/sitemap/posts_to_exclude', array( __CLASS__, 'sitemap_exclude_off_market' ) ); |
| 28 |
add_filter( 'rank_math/opengraph/facebook/image', array( __CLASS__, 'custom_og_image_url' ) ); |
| 29 |
} |
| 30 |
|
| 31 |
public static function custom_og_image_url( $url ) |
| 32 |
{ |
| 33 |
if ( !is_single() ) |
| 34 |
{ |
| 35 |
return $url; |
| 36 |
} |
| 37 |
|
| 38 |
if ( get_option('propertyhive_images_stored_as', '') != 'urls' ) |
| 39 |
{ |
| 40 |
return $url; |
| 41 |
} |
| 42 |
|
| 43 |
global $post; |
| 44 |
|
| 45 |
$photos = get_post_meta( $post->ID, '_photo_urls', true ); |
| 46 |
|
| 47 |
if ( empty( $photos ) ) |
| 48 |
{ |
| 49 |
return $url; |
| 50 |
} |
| 51 |
|
| 52 |
$url = esc_url( $photos[0]['url'] ); |
| 53 |
|
| 54 |
return $url; |
| 55 |
} |
| 56 |
|
| 57 |
public static function sitemap_exclude_taxonomy( $taxonomies ) { |
| 58 |
$taxonomy_objects = get_object_taxonomies( array('property', 'key_date'), 'objects' ); |
| 59 |
|
| 60 |
if ( !empty($taxonomy_objects) ) |
| 61 |
{ |
| 62 |
foreach ( $taxonomy_objects as $taxonomy_name => $object ) |
| 63 |
{ |
| 64 |
if ( isset($taxonomies[$taxonomy_name]) ) |
| 65 |
{ |
| 66 |
unset($taxonomies[$taxonomy_name]); |
| 67 |
} |
| 68 |
} |
| 69 |
} |
| 70 |
return $taxonomies; |
| 71 |
} |
| 72 |
|
| 73 |
public static function remove_columns( $columns ) { |
| 74 |
unset( $columns['rank_math_seo_details'] ); |
| 75 |
unset( $columns['rank_math_title'] ); |
| 76 |
unset( $columns['rank_math_description'] ); |
| 77 |
return $columns; |
| 78 |
} |
| 79 |
|
| 80 |
public static function sitemap_exclude_off_market( $post_ids_to_exclude ) { |
| 81 |
$properties_to_exclude = get_posts(array( |
| 82 |
'fields' => 'ids', |
| 83 |
'posts_per_page' => -1, |
| 84 |
'post_type' => 'property', |
| 85 |
'meta_query' => array( |
| 86 |
array( |
| 87 |
'key' => '_on_market', |
| 88 |
'value' => '', |
| 89 |
) |
| 90 |
) |
| 91 |
)); |
| 92 |
return array_merge($post_ids_to_exclude, $properties_to_exclude); |
| 93 |
} |
| 94 |
|
| 95 |
} |
| 96 |
|
| 97 |
PH_Rank_Math::init(); |