| 1 |
<?php |
| 2 |
/* |
| 3 |
* License: GPLv3 |
| 4 |
* License URI: https://www.gnu.org/licenses/gpl.txt |
| 5 |
* Copyright 2012-2026 Jean-Sebastien Morisset (https://wpsso.com/) |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
|
| 10 |
die( 'These aren\'t the droids you\'re looking for.' ); |
| 11 |
} |
| 12 |
|
| 13 |
/* |
| 14 |
* Integration module for the Rate my Post plugin. |
| 15 |
* |
| 16 |
* https://wordpress.org/plugins/rate-my-post/ |
| 17 |
*/ |
| 18 |
if ( ! class_exists( 'WpssoIntegRatingRateMyPost' ) ) { |
| 19 |
|
| 20 |
class WpssoIntegRatingRateMyPost { |
| 21 |
|
| 22 |
private $p; // Wpsso class object. |
| 23 |
|
| 24 |
public function __construct( &$plugin ) { |
| 25 |
|
| 26 |
$this->p =& $plugin; |
| 27 |
|
| 28 |
if ( $this->p->debug->enabled ) { |
| 29 |
|
| 30 |
$this->p->debug->mark(); |
| 31 |
} |
| 32 |
|
| 33 |
$this->p->util->add_plugin_filters( $this, array( |
| 34 |
'og' => 2, |
| 35 |
), $prio = 2000 ); // Run after the WPSSO RAR add-on. |
| 36 |
|
| 37 |
add_action( 'rmp_after_vote', array( $this, 'refresh_post_cache' ), 10, 4 ); |
| 38 |
|
| 39 |
if ( is_admin() ) { |
| 40 |
|
| 41 |
$this->conflict_check(); |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
private function conflict_check() { |
| 46 |
|
| 47 |
if ( $this->p->debug->enabled ) { |
| 48 |
|
| 49 |
$this->p->debug->mark(); |
| 50 |
} |
| 51 |
|
| 52 |
$opts = get_option( 'rmp_options' ); |
| 53 |
|
| 54 |
$structured = isset( $opts[ 'structuredDataType' ] ) ? $opts[ 'structuredDataType' ] : false; |
| 55 |
|
| 56 |
if ( ! empty( $structured ) && 'none' !== $structured ) { |
| 57 |
|
| 58 |
$log_pre = 'plugin conflict detected - '; |
| 59 |
|
| 60 |
$notice_pre = __( 'Plugin conflict detected:', 'wpsso' ) . ' '; |
| 61 |
|
| 62 |
// translators: Please ignore - translation uses a different text domain. |
| 63 |
$label_transl = '<strong>' . __( 'Type of structured data for rich snippets', 'rate-my-post' ) . '</strong>'; |
| 64 |
|
| 65 |
$settings_url = get_admin_url( $blog_id = null, 'admin.php?page=rate-my-post' ); |
| 66 |
|
| 67 |
$settings_link = '<a href="' . $settings_url . '">' . |
| 68 |
// translators: Please ignore - translation uses a different text domain. |
| 69 |
__( 'Rate my Post', 'rate-my-post' ) . ' > ' . |
| 70 |
// translators: Please ignore - translation uses a different text domain. |
| 71 |
__( 'Settings', 'rate-my-post' ) . ' > ' . |
| 72 |
// translators: Please ignore - translation uses a different text domain. |
| 73 |
__( 'Rating Widget Settings', 'rate-my-post' ) . '</a>'; |
| 74 |
|
| 75 |
if ( $this->p->debug->enabled ) { |
| 76 |
|
| 77 |
$this->p->debug->log( $log_pre . 'rate-my-post structuredDataType option is enabled' ); |
| 78 |
} |
| 79 |
|
| 80 |
$this->p->notice->err( $notice_pre . sprintf( __( 'Please disable the %1$s option in the %2$s settings page.', 'wpsso' ), |
| 81 |
$label_transl, $settings_link ) ); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
public function filter_og( array $mt_og, array $mod ) { |
| 86 |
|
| 87 |
if ( $this->p->debug->enabled ) { |
| 88 |
|
| 89 |
$this->p->debug->mark(); |
| 90 |
} |
| 91 |
|
| 92 |
if ( $mod[ 'is_post' ] && $mod[ 'id' ] ) { |
| 93 |
|
| 94 |
$average_rating = (float) Rate_My_Post_Common::get_average_rating( $mod[ 'id' ] ); |
| 95 |
$rating_count = (int) Rate_My_Post_Common::get_vote_count( $mod[ 'id' ] ); |
| 96 |
$worst_rating = 1; |
| 97 |
$best_rating = (int) Rate_My_Post_Common::max_rating(); |
| 98 |
|
| 99 |
/* |
| 100 |
* An average rating value must be greater than 0. |
| 101 |
*/ |
| 102 |
if ( $average_rating > 0 ) { |
| 103 |
|
| 104 |
/* |
| 105 |
* At least one rating is required. |
| 106 |
*/ |
| 107 |
if ( $rating_count > 0 ) { |
| 108 |
|
| 109 |
if ( $this->p->debug->enabled ) { |
| 110 |
|
| 111 |
$this->p->debug->log( 'adding rating meta tags for ' . $mod[ 'name' ] . ' id ' . $mod[ 'id' ] ); |
| 112 |
} |
| 113 |
|
| 114 |
$og_type = $mt_og[ 'og:type' ]; |
| 115 |
|
| 116 |
$mt_og[ $og_type . ':rating:average' ] = $average_rating; |
| 117 |
$mt_og[ $og_type . ':rating:count' ] = $rating_count; |
| 118 |
$mt_og[ $og_type . ':rating:worst' ] = $worst_rating; |
| 119 |
$mt_og[ $og_type . ':rating:best' ] = $best_rating; |
| 120 |
|
| 121 |
} elseif ( $this->p->debug->enabled ) { |
| 122 |
|
| 123 |
$this->p->debug->log( 'rating count is invalid (must be greater than 0)' ); |
| 124 |
} |
| 125 |
|
| 126 |
} elseif ( $this->p->debug->enabled ) { |
| 127 |
|
| 128 |
$this->p->debug->log( 'average rating is invalid (must be greater than 0)' ); |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
return $mt_og; |
| 133 |
} |
| 134 |
|
| 135 |
public function refresh_post_cache( $post_id, $avg_rating, $new_vote_count, $submitted_rating ) { |
| 136 |
|
| 137 |
$this->p->post->refresh_cache( $post_id ); // Refresh the cache for a single post ID. |
| 138 |
} |
| 139 |
} |
| 140 |
} |
| 141 |
|