Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*
*/
// This file must not accessed directly.
if (!defined('ABSPATH')) {
exit;
}
/**
* Miscellaneous plugin compatibility class.
*
* @since 5.24
*/
class CiviCRM_For_WordPress_Compat_Misc {
/**
* @var object
* Plugin object reference.
* @since 5.24
* @access public
*/
public $civi;
/**
* Instance constructor.
*
* @since 5.24
*/
public function __construct() {
// Store reference to CiviCRM plugin object.
$this->civi = civi_wp();
// Register plugin compatibility hooks.
$this->register_hooks();
}
/**
* Register plugin compatibility hooks.
*
* This is called via the constructor during the "plugins_loaded" action which
* is much earlier that CiviCRM's own internal hooks. The reason for this is
* that compability may need callbacks for events that fire well before "init"
* which is when CiviCRM begins to load.
*
* @since 5.24
*/
public function register_hooks() {
// Bail if CiviCRM not installed yet.
if (!CIVICRM_INSTALLED) {
return;
}
// Register Base Page callbacks.
add_action('civicrm_basepage_parsed', [$this, 'register_basepage_hooks']);
// Prevent AIOSEO from stomping on CiviCRM Shortcodes.
add_filter('aioseo_conflicting_shortcodes', [$this, 'aioseo_resolve_conflict']);
}
/**
* Register Base Page compatibility hooks.
*
* @since 5.66
*/
public function register_basepage_hooks() {
// Add compatibility with Yoast SEO plugin's Open Graph title.
add_filter('wpseo_opengraph_title', [$this, 'wpseo_page_title'], 100, 1);
// Don't let the Yoast SEO plugin parse the Base Page title.
if (class_exists('WPSEO_Frontend')) {
$frontend = WPSEO_Frontend::get_instance();
remove_filter('pre_get_document_title', [$frontend, 'title'], 15);
}
}
/**
* Get CiviCRM Base Page title for Open Graph elements.
*
* Callback method for 'wpseo_opengraph_title' hook, to provide compatibility
* with the WordPress SEO plugin.
*
* @since 4.6.4
*
* @param string $post_title The title of the WordPress page or post.
* @return string $basepage_title The title of the CiviCRM entity.
*/
public function wpseo_page_title($post_title) {
// Hand back our Base Page title.
return $this->civi->basepage->title_get();
}
/**
* Fixes AIOSEO's attempt to modify Shortcodes.
*
* @see https://civicrm.stackexchange.com/questions/40765/wp-all-in-one-seo-plugin-conflict
*
* @since 5.45
*
* @param array $conflicting_shortcodes The existing AIOSEO Conflicting Shortcodes array.
* @return array $conflicting_shortcodes The modified AIOSEO Conflicting Shortcodes array.
*/
public function aioseo_resolve_conflict($conflicting_shortcodes) {
$conflicting_shortcodes['CiviCRM'] = 'civicrm';
return $conflicting_shortcodes;
}
}