| 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 SEOPress plugin. |
| 15 |
* |
| 16 |
* See https://wordpress.org/plugins/wp-seopress/. |
| 17 |
*/ |
| 18 |
if ( ! class_exists( 'WpssoIntegSeoSeopress' ) ) { |
| 19 |
|
| 20 |
class WpssoIntegSeoSeopress { |
| 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 |
'primary_term_id' => 4, |
| 35 |
'primary_terms' => 3, |
| 36 |
'title_seed' => 5, |
| 37 |
'description_seed' => 4, |
| 38 |
'post_url' => 2, |
| 39 |
'term_url' => 2, |
| 40 |
'get_md_options' => 2, |
| 41 |
), 100 ); |
| 42 |
|
| 43 |
if ( is_admin() ) { |
| 44 |
|
| 45 |
add_filter( 'seopress_metabox_seo_tabs', array( $this, 'cleanup_seopress_tabs' ), 1000, 1 ); |
| 46 |
|
| 47 |
} else { |
| 48 |
|
| 49 |
add_filter( 'seopress_titles_author', '__return_empty_string', 1000, 0 ); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
public function filter_primary_term_id( $primary_term_id, $mod, $tax_slug, $is_custom ) { |
| 54 |
|
| 55 |
if ( $this->p->debug->enabled ) { |
| 56 |
|
| 57 |
$this->p->debug->mark(); |
| 58 |
} |
| 59 |
|
| 60 |
if ( $is_custom ) { |
| 61 |
|
| 62 |
if ( $this->p->debug->enabled ) { |
| 63 |
|
| 64 |
$this->p->debug->log( 'exiting early: $is_custom is true' ); |
| 65 |
} |
| 66 |
|
| 67 |
return $primary_term_id; |
| 68 |
|
| 69 |
} elseif ( empty( $mod[ 'is_post' ] ) || empty( $mod[ 'id' ] ) ) { |
| 70 |
|
| 71 |
if ( $this->p->debug->enabled ) { |
| 72 |
|
| 73 |
$this->p->debug->log( 'exiting early: not post object or no post ID' ); |
| 74 |
} |
| 75 |
|
| 76 |
return $primary_term_id; |
| 77 |
|
| 78 |
} elseif ( empty( $tax_slug ) ) { |
| 79 |
|
| 80 |
if ( $this->p->debug->enabled ) { |
| 81 |
|
| 82 |
$this->p->debug->log( 'exiting early: $tax_slug is empty' ); |
| 83 |
} |
| 84 |
|
| 85 |
return $primary_term_id; |
| 86 |
|
| 87 |
} else { |
| 88 |
|
| 89 |
$meta_key = '_seopress_robots_primary_cat'; |
| 90 |
|
| 91 |
if ( $this->p->debug->enabled ) { |
| 92 |
|
| 93 |
$this->p->debug->log( 'calling get_metadata() for ' . $meta_key ); |
| 94 |
} |
| 95 |
|
| 96 |
if ( $ret = get_metadata( 'post', $mod[ 'id' ], $meta_key, $single = true ) ) { |
| 97 |
|
| 98 |
return $ret; |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
return $primary_term_id; |
| 103 |
} |
| 104 |
|
| 105 |
public function filter_primary_terms( $primary_terms, $mod, $tax_slug ) { |
| 106 |
|
| 107 |
if ( $this->p->debug->enabled ) { |
| 108 |
|
| 109 |
$this->p->debug->mark(); |
| 110 |
} |
| 111 |
|
| 112 |
if ( $primary_term_id = $this->filter_primary_term_id( false, $mod, $tax_slug, $is_custom = false ) ) { |
| 113 |
|
| 114 |
if ( empty( $primary_terms[ $primary_term_id ] ) ) { |
| 115 |
|
| 116 |
$term_obj = get_term( $primary_term_id ); |
| 117 |
|
| 118 |
if ( isset( $term_obj->term_id ) ) { // Just in case. |
| 119 |
|
| 120 |
$primary_terms[ $term_obj->term_id ] = $term_obj->name; |
| 121 |
} |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
return $primary_terms; |
| 126 |
} |
| 127 |
|
| 128 |
public function filter_title_seed( $title_text, $mod, $num_hashtags, $md_key, $title_sep ) { |
| 129 |
|
| 130 |
if ( $this->p->debug->enabled ) { |
| 131 |
|
| 132 |
$this->p->debug->mark(); |
| 133 |
} |
| 134 |
|
| 135 |
return WpssoAbstractWpMeta::get_mod_meta( $mod, $meta_key = '_seopress_titles_title', $single = true ); |
| 136 |
} |
| 137 |
|
| 138 |
public function filter_description_seed( $desc_text, $mod, $num_hashtags, $md_key ) { |
| 139 |
|
| 140 |
if ( $this->p->debug->enabled ) { |
| 141 |
|
| 142 |
$this->p->debug->mark(); |
| 143 |
} |
| 144 |
|
| 145 |
return WpssoAbstractWpMeta::get_mod_meta( $mod, $meta_key = '_seopress_titles_desc', $single = true ); |
| 146 |
} |
| 147 |
|
| 148 |
public function filter_post_url( $url, $mod ) { |
| 149 |
|
| 150 |
if ( $this->p->debug->enabled ) { |
| 151 |
|
| 152 |
$this->p->debug->mark(); |
| 153 |
} |
| 154 |
|
| 155 |
$canonical = ''; |
| 156 |
|
| 157 |
if ( $mod[ 'id' ] ) { |
| 158 |
|
| 159 |
$canonical = get_metadata( 'post', $mod[ 'id' ], $meta_key = '_seopress_robots_canonical', $single = true ); |
| 160 |
} |
| 161 |
|
| 162 |
if ( ! empty( $canonical ) ) { |
| 163 |
|
| 164 |
return $canonical; |
| 165 |
} |
| 166 |
|
| 167 |
return $url; |
| 168 |
} |
| 169 |
|
| 170 |
public function filter_term_url( $url, $mod ) { |
| 171 |
|
| 172 |
if ( $this->p->debug->enabled ) { |
| 173 |
|
| 174 |
$this->p->debug->mark(); |
| 175 |
} |
| 176 |
|
| 177 |
$canonical = ''; |
| 178 |
|
| 179 |
if ( $mod[ 'id' ] ) { |
| 180 |
|
| 181 |
$canonical = get_metadata( 'term', $mod[ 'id' ], $meta_key = '_seopress_robots_canonical', $single = true ); |
| 182 |
} |
| 183 |
|
| 184 |
if ( ! empty( $canonical ) ) { |
| 185 |
|
| 186 |
return $canonical; |
| 187 |
} |
| 188 |
|
| 189 |
return $url; |
| 190 |
} |
| 191 |
|
| 192 |
public function filter_get_md_options( array $md_opts, array $mod ) { |
| 193 |
|
| 194 |
if ( $this->p->debug->enabled ) { |
| 195 |
|
| 196 |
$this->p->debug->mark(); |
| 197 |
} |
| 198 |
|
| 199 |
$md_meta_names = array( |
| 200 |
'og_title' => '_seopress_social_fb_title', |
| 201 |
'og_desc' => '_seopress_social_fb_desc', |
| 202 |
'og_img_url' => '_seopress_social_fb_img', |
| 203 |
'schema_title' => '_seopress_titles_title', |
| 204 |
'schema_desc' => '_seopress_titles_desc', |
| 205 |
'tc_title' => '_seopress_social_twitter_title', |
| 206 |
'tc_desc' => '_seopress_social_twitter_desc', |
| 207 |
'tc_sum_img_url' => '_seopress_social_twitter_img', |
| 208 |
'tc_lrg_img_url' => '_seopress_social_twitter_img', |
| 209 |
); |
| 210 |
|
| 211 |
foreach( $md_meta_names as $opt_key => $meta_key ) { |
| 212 |
|
| 213 |
/* |
| 214 |
* Skip plugin options that already have a custom value. |
| 215 |
*/ |
| 216 |
if ( ! empty( $md_opts[ $opt_key ] ) ) { // Not 0, false, or empty string. |
| 217 |
|
| 218 |
continue; |
| 219 |
} |
| 220 |
|
| 221 |
$md_opts[ $opt_key ] = WpssoAbstractWpMeta::get_mod_meta( $mod, $meta_key, $single = true ); |
| 222 |
} |
| 223 |
|
| 224 |
return $md_opts; |
| 225 |
} |
| 226 |
|
| 227 |
public function cleanup_seopress_tabs( $tabs ) { |
| 228 |
|
| 229 |
unset( $tabs[ 'social-tab' ] ); |
| 230 |
|
| 231 |
return $tabs; |
| 232 |
} |
| 233 |
} |
| 234 |
} |
| 235 |
|