admin
8 years ago
api
8 years ago
deprecated
8 years ago
donors
8 years ago
emails
8 years ago
forms
8 years ago
gateways
8 years ago
libraries
8 years ago
payments
8 years ago
actions.php
8 years ago
ajax-functions.php
8 years ago
class-give-async-process.php
8 years ago
class-give-background-updater.php
8 years ago
class-give-cache.php
8 years ago
class-give-cli-commands.php
8 years ago
class-give-cron.php
8 years ago
class-give-db-donor-meta.php
8 years ago
class-give-db-donors.php
8 years ago
class-give-db-form-meta.php
8 years ago
class-give-db-logs-meta.php
8 years ago
class-give-db-logs.php
8 years ago
class-give-db-meta.php
8 years ago
class-give-db-payment-meta.php
8 years ago
class-give-db-sequential-ordering.php
8 years ago
class-give-db.php
8 years ago
class-give-donate-form.php
8 years ago
class-give-donor.php
8 years ago
class-give-email-access.php
8 years ago
class-give-gravatars.php
8 years ago
class-give-html-elements.php
8 years ago
class-give-license-handler.php
8 years ago
class-give-logging.php
8 years ago
class-give-readme-parser.php
8 years ago
class-give-roles.php
8 years ago
class-give-scripts.php
8 years ago
class-give-session.php
8 years ago
class-give-stats.php
8 years ago
class-give-template-loader.php
8 years ago
class-give-tooltips.php
8 years ago
class-give-translation.php
8 years ago
class-notices.php
8 years ago
country-functions.php
8 years ago
currency-functions.php
8 years ago
error-tracking.php
8 years ago
filters.php
8 years ago
formatting.php
8 years ago
import-functions.php
8 years ago
install.php
8 years ago
login-register.php
8 years ago
misc-functions.php
8 years ago
plugin-compatibility.php
8 years ago
post-types.php
8 years ago
price-functions.php
8 years ago
process-donation.php
8 years ago
shortcodes.php
8 years ago
template-functions.php
8 years ago
user-functions.php
8 years ago
filters.php
261 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Front-end Filters |
| 4 | * |
| 5 | * @package Give |
| 6 | * @subpackage Functions |
| 7 | * @copyright Copyright (c) 2016, WordImpress |
| 8 | * @license https://opensource.org/licenses/gpl-license GNU Public License |
| 9 | * @since 1.0 |
| 10 | */ |
| 11 | |
| 12 | // Exit if accessed directly. |
| 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | exit; |
| 15 | } |
| 16 | |
| 17 | |
| 18 | /** |
| 19 | * Add backward compatibility for settings who has disable_ as name prefix. |
| 20 | * TODO: Remove this backward compatibility when do not need. |
| 21 | * |
| 22 | * @since 1.8 |
| 23 | * |
| 24 | * @param array $old_settings Array of settings. |
| 25 | * @param array $settings Array of settings. |
| 26 | * |
| 27 | * @return void |
| 28 | */ |
| 29 | function give_set_settings_with_disable_prefix( $old_settings, $settings ) { |
| 30 | // Bailout. |
| 31 | if ( ! function_exists( 'give_v18_renamed_core_settings' ) ) { |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | // Get old setting names. |
| 36 | $old_settings = array_flip( give_v18_renamed_core_settings() ); |
| 37 | $update_setting = false; |
| 38 | |
| 39 | foreach ( $settings as $key => $value ) { |
| 40 | |
| 41 | // Check 1. Check if new option is really updated or not. |
| 42 | // Check 2. Continue if key is not renamed. |
| 43 | if ( ! isset( $old_settings[ $key ] ) ) { |
| 44 | continue; |
| 45 | } |
| 46 | |
| 47 | // Set old setting. |
| 48 | $settings[ $old_settings[ $key ] ] = 'on'; |
| 49 | |
| 50 | // Do not need to set old setting if new setting is not set. |
| 51 | if ( |
| 52 | ( give_is_setting_enabled( $value ) && ( false !== strpos( $old_settings[ $key ], 'disable_' ) ) ) |
| 53 | || ( ! give_is_setting_enabled( $value ) && ( false !== strpos( $old_settings[ $key ], 'enable_' ) ) ) |
| 54 | |
| 55 | ) { |
| 56 | unset( $settings[ $old_settings[ $key ] ] ); |
| 57 | } |
| 58 | |
| 59 | // Tell bot to update setting. |
| 60 | $update_setting = true; |
| 61 | } |
| 62 | |
| 63 | // Update setting if any old setting set. |
| 64 | if ( $update_setting ) { |
| 65 | update_option( 'give_settings', $settings ); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | add_action( 'update_option_give_settings', 'give_set_settings_with_disable_prefix', 10, 2 ); |
| 70 | |
| 71 | /** |
| 72 | * Check spam through Akismet. |
| 73 | * |
| 74 | * It will build Akismet query string and call Akismet API. |
| 75 | * Akismet response return 'true' for spam donation. |
| 76 | * |
| 77 | * @since 1.8.14 |
| 78 | * |
| 79 | * @param $spam |
| 80 | * |
| 81 | * @return bool|mixed |
| 82 | */ |
| 83 | function give_akismet( $spam ) { |
| 84 | |
| 85 | // Bail out, If spam. |
| 86 | if ( $spam ) { |
| 87 | return $spam; |
| 88 | } |
| 89 | |
| 90 | // Bail out, if Akismet key not exist. |
| 91 | if ( ! give_check_akismet_key() ) { |
| 92 | return false; |
| 93 | } |
| 94 | |
| 95 | // Build args array. |
| 96 | $args = array(); |
| 97 | |
| 98 | $args['comment_author'] = isset( $_POST['give_first'] ) ? strip_tags( trim( $_POST['give_first'] ) ) : ''; |
| 99 | $args['comment_author_email'] = isset( $_POST['give_email'] ) ? $_POST['give_email'] : false; |
| 100 | $args['blog'] = get_option( 'home' ); |
| 101 | $args['blog_lang'] = get_locale(); |
| 102 | $args['blog_charset'] = get_option( 'blog_charset' ); |
| 103 | $args['user_ip'] = $_SERVER['REMOTE_ADDR']; |
| 104 | $args['user_agent'] = $_SERVER['HTTP_USER_AGENT']; |
| 105 | $args['referrer'] = $_SERVER['HTTP_REFERER']; |
| 106 | $args['comment_type'] = 'contact-form'; |
| 107 | |
| 108 | $ignore = array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW' ); |
| 109 | |
| 110 | foreach ( $_SERVER as $key => $value ) { |
| 111 | if ( ! in_array( $key, (array) $ignore ) ) { |
| 112 | $args["$key"] = $value; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | // It will return Akismet spam detect API response. |
| 117 | return give_akismet_spam_check( $args ); |
| 118 | |
| 119 | } |
| 120 | |
| 121 | add_filter( 'give_spam', 'give_akismet' ); |
| 122 | |
| 123 | /** |
| 124 | * Check Akismet API Key. |
| 125 | * |
| 126 | * @since 1.8.14 |
| 127 | * |
| 128 | * @return bool |
| 129 | */ |
| 130 | function give_check_akismet_key() { |
| 131 | if ( is_callable( array( 'Akismet', 'get_api_key' ) ) ) { // Akismet v3.0+ |
| 132 | return (bool) Akismet::get_api_key(); |
| 133 | } |
| 134 | |
| 135 | if ( function_exists( 'akismet_get_key' ) ) { |
| 136 | return (bool) akismet_get_key(); |
| 137 | } |
| 138 | |
| 139 | return false; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Detect spam through Akismet Comment API. |
| 144 | * |
| 145 | * @since 1.8.14 |
| 146 | * |
| 147 | * @param array $args |
| 148 | * |
| 149 | * @return bool|mixed |
| 150 | */ |
| 151 | function give_akismet_spam_check( $args ) { |
| 152 | global $akismet_api_host, $akismet_api_port; |
| 153 | |
| 154 | $spam = false; |
| 155 | $query_string = http_build_query( $args ); |
| 156 | |
| 157 | if ( is_callable( array( 'Akismet', 'http_post' ) ) ) { // Akismet v3.0+ |
| 158 | $response = Akismet::http_post( $query_string, 'comment-check' ); |
| 159 | } else { |
| 160 | $response = akismet_http_post( $query_string, $akismet_api_host, |
| 161 | '/1.1/comment-check', $akismet_api_port ); |
| 162 | } |
| 163 | |
| 164 | // It's spam if response status is true. |
| 165 | if ( 'true' === $response[1] ) { |
| 166 | $spam = true; |
| 167 | } |
| 168 | |
| 169 | // Allow developer to modified Akismet spam detection response. |
| 170 | return apply_filters( 'give_akismet_spam_check', $spam, $args ); |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * Add support of RIAL code for backward compatibility. |
| 175 | * Note: for internal use only |
| 176 | * |
| 177 | * @since 1.8.17 |
| 178 | * |
| 179 | * @param array $currencies |
| 180 | * |
| 181 | * @return array |
| 182 | */ |
| 183 | function give_bc_v1817_iranian_currency_code( $currencies ) { |
| 184 | if ( ! give_has_upgrade_completed( 'v1817_update_donation_iranian_currency_code' ) ) { |
| 185 | $currencies['RIAL'] = $currencies['IRR']; |
| 186 | } |
| 187 | |
| 188 | return $currencies; |
| 189 | } |
| 190 | |
| 191 | add_filter( 'give_currencies', 'give_bc_v1817_iranian_currency_code', 0 ); |
| 192 | |
| 193 | |
| 194 | /** |
| 195 | * Format right to left supported currency amount. |
| 196 | * |
| 197 | * @since 1.8.17 |
| 198 | * |
| 199 | * @param $formatted_amount |
| 200 | * @param $currency_args |
| 201 | * @param $price |
| 202 | * |
| 203 | * @return string |
| 204 | */ |
| 205 | function give_format_price_for_right_to_left_supported_currency( $formatted_amount, $currency_args, $price ) { |
| 206 | if ( ! give_is_right_to_left_supported_currency( $currency_args['currency_code'] ) ) { |
| 207 | return $formatted_amount; |
| 208 | } |
| 209 | |
| 210 | $formatted_amount = ( |
| 211 | 'before' === (string) $currency_args['position'] ? |
| 212 | '‫' . $price . $currency_args['symbol'] . '‬' : |
| 213 | '‪' . $price . $currency_args['symbol'] . '‬' |
| 214 | ); |
| 215 | |
| 216 | $formatted_amount = $currency_args['decode_currency'] ? |
| 217 | html_entity_decode( $formatted_amount, ENT_COMPAT, 'UTF-8' ) : |
| 218 | $formatted_amount; |
| 219 | |
| 220 | return $formatted_amount; |
| 221 | } |
| 222 | |
| 223 | add_filter( 'give_currency_filter', 'give_format_price_for_right_to_left_supported_currency', 10, 3 ); |
| 224 | |
| 225 | /** |
| 226 | * Validate active gateway value before returning result. |
| 227 | * |
| 228 | * @since 2.1.0 |
| 229 | * |
| 230 | * @param $value |
| 231 | * |
| 232 | * @return array |
| 233 | */ |
| 234 | function __give_validate_active_gateways( $value ) { |
| 235 | $gateways = array_keys( give_get_payment_gateways() ); |
| 236 | $active_gateways = is_array( $value ) ? array_keys( $value ) : array(); |
| 237 | |
| 238 | // Remove deactivated payment gateways. |
| 239 | if( ! empty( $active_gateways ) ) { |
| 240 | foreach ( $active_gateways as $index => $gateway_id ) { |
| 241 | if( ! in_array( $gateway_id, $gateways ) ) { |
| 242 | unset( $value[$gateway_id] ); |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | if ( empty( $value ) ) { |
| 248 | /** |
| 249 | * Filter the default active gateway |
| 250 | * |
| 251 | * @since 2.1.0 |
| 252 | */ |
| 253 | $value = apply_filters( 'give_default_active_gateways', array( |
| 254 | 'manual' => 1, |
| 255 | ) ); |
| 256 | } |
| 257 | |
| 258 | return $value; |
| 259 | } |
| 260 | |
| 261 | add_filter( 'give_get_option_gateways', '__give_validate_active_gateways', 10, 1 ); |