| 1 |
<?php |
| 2 |
/** |
| 3 |
* Charitable Security Hooks. |
| 4 |
* |
| 5 |
* Action/filter hooks used for Charitable Security Settings API. |
| 6 |
* |
| 7 |
* @package Charitable/Functions/Admin |
| 8 |
* @author David Bisset |
| 9 |
* @copyright Copyright (c) 2023, WP Charitable LLC |
| 10 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 11 |
* @since 1.8.9 |
| 12 |
* @version 1.8.9 |
| 13 |
*/ |
| 14 |
|
| 15 |
// Exit if accessed directly. |
| 16 |
if ( ! defined( 'ABSPATH' ) ) { |
| 17 |
exit; |
| 18 |
} |
| 19 |
|
| 20 |
// Load the security settings class. |
| 21 |
// Use a direct path since charitable() may not be available yet during load_dependencies(). |
| 22 |
$charitable_security_settings_path = dirname( __FILE__ ) . '/class-charitable-security-settings.php'; |
| 23 |
if ( file_exists( $charitable_security_settings_path ) ) { |
| 24 |
require_once $charitable_security_settings_path; |
| 25 |
} |
| 26 |
|
| 27 |
// Always instantiate the security settings class (needed for frontend CAPTCHA functionality). |
| 28 |
// Defer instantiation until after plugins_loaded to ensure charitable() is available. |
| 29 |
add_action( 'plugins_loaded', function() { |
| 30 |
if ( function_exists( 'charitable' ) ) { |
| 31 |
Charitable_Security_Settings::get_instance(); |
| 32 |
} |
| 33 |
}, 5 ); |
| 34 |
|
| 35 |
// Only register admin settings hooks in admin area. |
| 36 |
if ( is_admin() ) { |
| 37 |
/** |
| 38 |
* Add the security settings group. |
| 39 |
* |
| 40 |
* @see Charitable_Security_Settings::add_security_settings_group() |
| 41 |
*/ |
| 42 |
add_filter( 'charitable_security_admin_settings_groups', function( $groups ) { |
| 43 |
if ( function_exists( 'charitable' ) ) { |
| 44 |
return Charitable_Security_Settings::get_instance()->add_security_settings_group( $groups ); |
| 45 |
} |
| 46 |
return $groups; |
| 47 |
} ); |
| 48 |
|
| 49 |
/** |
| 50 |
* Add the security settings. |
| 51 |
* |
| 52 |
* @see Charitable_Security_Settings::add_settings() |
| 53 |
*/ |
| 54 |
add_filter( 'charitable_settings_tab_fields_security', function( $settings ) { |
| 55 |
if ( function_exists( 'charitable' ) ) { |
| 56 |
return Charitable_Security_Settings::get_instance()->add_settings( $settings ); |
| 57 |
} |
| 58 |
return $settings; |
| 59 |
} ); |
| 60 |
|
| 61 |
/** |
| 62 |
* Hook into settings save to reset security notice dismissal if needed. |
| 63 |
* |
| 64 |
* @see Charitable_Security_Settings::maybe_reset_security_notice_dismissal() |
| 65 |
*/ |
| 66 |
add_filter( 'charitable_save_settings', function( $values, $new_values ) { |
| 67 |
if ( function_exists( 'charitable' ) ) { |
| 68 |
return Charitable_Security_Settings::get_instance()->maybe_reset_security_notice_dismissal( $values, $new_values ); |
| 69 |
} |
| 70 |
return $values; |
| 71 |
}, 10, 2 ); |
| 72 |
} |
| 73 |
|
| 74 |
|