| 1 |
<?php |
| 2 |
/** |
| 3 |
* Functions to improve compatibility. |
| 4 |
* |
| 5 |
* @package Charitable/Functions/Compatibility |
| 6 |
* @author David Bisset |
| 7 |
* @copyright Copyright (c) 2023, WP Charitable LLC |
| 8 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 |
* @since 1.5.0 |
| 10 |
* @version 1.6.48 |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Load plugin compatibility files on plugins_loaded hook. |
| 19 |
* |
| 20 |
* @since 1.5.0 |
| 21 |
* |
| 22 |
* @return void |
| 23 |
*/ |
| 24 |
function charitable_load_compat_functions() { |
| 25 |
$includes_path = charitable()->get_path( 'includes' ); |
| 26 |
|
| 27 |
/* WP Super Cache */ |
| 28 |
if ( function_exists( 'wpsupercache_activate' ) ) { |
| 29 |
require_once $includes_path . 'compat/charitable-wp-super-cache-compat-functions.php'; |
| 30 |
} |
| 31 |
|
| 32 |
/* W3TC */ |
| 33 |
if ( defined( 'W3TC' ) && W3TC ) { |
| 34 |
require_once $includes_path . 'compat/charitable-w3tc-compat-functions.php'; |
| 35 |
} |
| 36 |
|
| 37 |
/* WP Rocket */ |
| 38 |
if ( defined( 'WP_ROCKET_VERSION' ) ) { |
| 39 |
require_once $includes_path . 'compat/charitable-wp-rocket-compat-functions.php'; |
| 40 |
} |
| 41 |
|
| 42 |
/* WP Fastest Cache */ |
| 43 |
if ( class_exists( 'WpFastestCache' ) ) { |
| 44 |
require_once $includes_path . 'compat/charitable-wp-fastest-cache-compat-functions.php'; |
| 45 |
} |
| 46 |
|
| 47 |
/* Litespeed Cache */ |
| 48 |
if ( class_exists( 'LiteSpeed_Cache' ) ) { |
| 49 |
require_once $includes_path . 'compat/charitablespeed-cache-compat-functions.php'; |
| 50 |
} |
| 51 |
|
| 52 |
/* Twenty Seventeen */ |
| 53 |
if ( 'twentyseventeen' == wp_get_theme()->stylesheet ) { |
| 54 |
require_once $includes_path . 'compat/charitable-twentyseventeen-compat-functions.php'; |
| 55 |
} |
| 56 |
|
| 57 |
/* Ultimate Member */ |
| 58 |
if ( class_exists( 'UM' ) ) { |
| 59 |
require_once $includes_path . 'compat/charitable-ultimate-member-compat-functions.php'; |
| 60 |
} |
| 61 |
|
| 62 |
/* GDPR Cookie Compliance */ |
| 63 |
if ( function_exists( 'gdpr_cookie_is_accepted' ) ) { |
| 64 |
require_once $includes_path . 'compat/charitable-gdpr-cookie-compliance-compat-functions.php'; |
| 65 |
} |
| 66 |
|
| 67 |
/* WooCommerce */ |
| 68 |
if ( defined( 'WC_PLUGIN_FILE' ) ) { |
| 69 |
require_once $includes_path . 'compat/charitable-woocommerce-compat-functions.php'; |
| 70 |
} |
| 71 |
|
| 72 |
/* Polylang */ |
| 73 |
if ( defined( 'POLYLANG_VERSION' ) ) { |
| 74 |
new Charitable_Polylang_Compat(); |
| 75 |
} |
| 76 |
|
| 77 |
/* WPML */ |
| 78 |
if ( defined( 'ICL_SITEPRESS_VERSION' ) ) { |
| 79 |
new Charitable_WPML_Compat(); |
| 80 |
} |
| 81 |
|
| 82 |
/* Weglot */ |
| 83 |
if ( defined( 'WEGLOT_VERSION' ) ) { |
| 84 |
new Charitable_Weglot_Compat(); |
| 85 |
} |
| 86 |
|
| 87 |
/* TranslatePress */ |
| 88 |
if ( class_exists( 'TRP_Translate_Press' ) ) { |
| 89 |
new Charitable_Translatepress_Compat(); |
| 90 |
} |
| 91 |
|
| 92 |
/* Permalink Manager */ |
| 93 |
if ( defined( 'PERMALINK_MANAGER_PLUGIN_NAME' ) ) { |
| 94 |
require_once $includes_path . 'compat/charitable-permalink-manager-compat-functions.php'; |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
/** |
| 99 |
* Add custom styles for certain themes. |
| 100 |
* |
| 101 |
* @since 1.6.29 |
| 102 |
* |
| 103 |
* @return void |
| 104 |
*/ |
| 105 |
function charitable_compat_styles() { |
| 106 |
$styles = include 'styles/inline-styles.php'; |
| 107 |
|
| 108 |
foreach ( $styles as $stylesheet => $custom_styles ) { |
| 109 |
wp_add_inline_style( $stylesheet, $custom_styles ); |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
add_action( 'wp_enqueue_scripts', 'charitable_compat_styles', 20 ); |
| 114 |
|
| 115 |
/** |
| 116 |
* Change the default accent colour based on the current theme. |
| 117 |
* |
| 118 |
* @since 1.6.29 |
| 119 |
* |
| 120 |
* @param string $colour The default accent colour. |
| 121 |
* @return string |
| 122 |
*/ |
| 123 |
function charitable_compat_theme_highlight_colour( $colour ) { |
| 124 |
$colours = include 'styles/highlight-colours.php'; |
| 125 |
$stylesheet = strtolower( wp_get_theme()->stylesheet ); |
| 126 |
|
| 127 |
if ( 'twentytwenty' === $stylesheet && function_exists( 'twentytwenty_get_color_for_area' ) ) { |
| 128 |
return sanitize_hex_color( twentytwenty_get_color_for_area( 'content', 'accent' ) ); |
| 129 |
} |
| 130 |
|
| 131 |
if ( 'divi' === $stylesheet && function_exists( 'et_get_option' ) ) { |
| 132 |
$stylesheet = 'divi-' . et_get_option( 'color_schemes', 'none' ); |
| 133 |
} |
| 134 |
|
| 135 |
if ( array_key_exists( $stylesheet, $colours ) ) { |
| 136 |
return $colours[ $stylesheet ]; |
| 137 |
} |
| 138 |
|
| 139 |
/* Return default colour. */ |
| 140 |
return $colour; |
| 141 |
} |
| 142 |
|
| 143 |
add_filter( 'charitable_default_highlight_colour', 'charitable_compat_theme_highlight_colour' ); |
| 144 |
|
| 145 |
/** |
| 146 |
* Add button classes depending on the theme. |
| 147 |
* |
| 148 |
* @since 1.6.29 |
| 149 |
* |
| 150 |
* @param array $classes The classes to add to the button by default. |
| 151 |
* @param string $button The specific button we're showing. |
| 152 |
* @return array |
| 153 |
*/ |
| 154 |
function charitable_compat_button_classes( $classes, $button ) { |
| 155 |
switch ( strtolower( wp_get_theme()->template ) ) { |
| 156 |
case 'divi': |
| 157 |
$classes[] = 'et_pb_button'; |
| 158 |
break; |
| 159 |
} |
| 160 |
|
| 161 |
return $classes; |
| 162 |
} |
| 163 |
|
| 164 |
add_filter( 'charitable_button_class', 'charitable_compat_button_classes', 10, 2 ); |
| 165 |
|
| 166 |
/** |
| 167 |
* Enable locale functions in Charitable based on presence of other plugins. |
| 168 |
* |
| 169 |
* @since 1.6.43 |
| 170 |
* |
| 171 |
* @param boolean $locale_enabled Whether to enable locale functions. |
| 172 |
* @return boolean |
| 173 |
*/ |
| 174 |
function charitable_compat_load_locale_functions( $locale_enabled ) { |
| 175 |
/* We've already enabled locale functions. */ |
| 176 |
if ( $locale_enabled ) { |
| 177 |
return $locale_enabled; |
| 178 |
} |
| 179 |
|
| 180 |
/* Polylang */ |
| 181 |
if ( defined( 'POLYLANG_VERSION' ) ) { |
| 182 |
return true; |
| 183 |
} |
| 184 |
|
| 185 |
/* TranslatePress */ |
| 186 |
if ( class_exists( 'TRP_Translate_Press' ) ) { |
| 187 |
return true; |
| 188 |
} |
| 189 |
|
| 190 |
/* Weglot */ |
| 191 |
if ( defined( 'WEGLOT_VERSION' ) ) { |
| 192 |
return true; |
| 193 |
} |
| 194 |
|
| 195 |
return $locale_enabled; |
| 196 |
} |
| 197 |
|
| 198 |
add_filter( 'charitable_enable_locale_functions', 'charitable_compat_load_locale_functions' ); |
| 199 |
|