| 1 |
<?php |
| 2 |
/** |
| 3 |
* Gets UsersWP setting value using key. |
| 4 |
* |
| 5 |
* @since 1.0.0 |
| 6 |
* @package userswp |
| 7 |
* |
| 8 |
* @param string $key Setting Key. |
| 9 |
* @param bool|string $default Default value. |
| 10 |
* @param bool $cache Use cache to retrieve the value?. |
| 11 |
* |
| 12 |
* @return string Setting Value. |
| 13 |
*/ |
| 14 |
function uwp_get_option( $key = '', $default = false, $cache = true ) { |
| 15 |
|
| 16 |
if ($cache) { |
| 17 |
global $uwp_options; |
| 18 |
} else { |
| 19 |
$uwp_options = get_option( 'uwp_settings' ); |
| 20 |
} |
| 21 |
|
| 22 |
$value = isset( $uwp_options[ $key ] ) ? $uwp_options[ $key ] : $default; |
| 23 |
$value = apply_filters( 'uwp_get_option', $value, $key, $default ); |
| 24 |
return apply_filters( 'uwp_get_option_' . $key, $value, $key, $default ); |
| 25 |
|
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Updates UsersWP setting value using key. |
| 30 |
* |
| 31 |
* @since 1.0.0 |
| 32 |
* @package userswp |
| 33 |
* |
| 34 |
* @param string|bool $key Setting Key. |
| 35 |
* @param string $value Setting Value. |
| 36 |
* |
| 37 |
* @return bool Update success or not?. |
| 38 |
*/ |
| 39 |
function uwp_update_option( $key = false, $value = '') { |
| 40 |
|
| 41 |
if (!$key ) { |
| 42 |
return false; |
| 43 |
} |
| 44 |
|
| 45 |
$settings = get_option( 'uwp_settings', array()); |
| 46 |
|
| 47 |
if( !is_array( $settings ) ) { |
| 48 |
$settings = array(); |
| 49 |
} |
| 50 |
|
| 51 |
$settings[ $key ] = $value; |
| 52 |
|
| 53 |
$settings = apply_filters( 'uwp_update_option', $settings, $key, $value ); |
| 54 |
$settings = apply_filters( 'uwp_update_option_' . $key, $settings, $key, $value ); |
| 55 |
|
| 56 |
$updated = update_option( 'uwp_settings', $settings ); |
| 57 |
|
| 58 |
if ( $updated ) { |
| 59 |
global $uwp_options; |
| 60 |
$uwp_options[ $key ] = $value; |
| 61 |
} |
| 62 |
|
| 63 |
return $updated; |
| 64 |
|
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* Deletes UsersWP setting value using key. |
| 69 |
* |
| 70 |
* @package userswp |
| 71 |
* |
| 72 |
* @param string|bool $key Setting Key. |
| 73 |
* |
| 74 |
* @return bool delete success or not?. |
| 75 |
*/ |
| 76 |
function uwp_delete_option( $key = '' ) { |
| 77 |
|
| 78 |
if ( empty( $key ) ) { |
| 79 |
return false; |
| 80 |
} |
| 81 |
|
| 82 |
$options = get_option( 'uwp_settings' ); |
| 83 |
if ( empty( $options ) ) { |
| 84 |
$options = array(); |
| 85 |
} |
| 86 |
|
| 87 |
if ( isset( $options[ $key ] ) ) { |
| 88 |
unset( $options[ $key ] ); |
| 89 |
} |
| 90 |
|
| 91 |
$updated = update_option( 'uwp_settings', $options ); |
| 92 |
|
| 93 |
if ( $updated ) { |
| 94 |
global $uwp_options; |
| 95 |
$uwp_options = $options; |
| 96 |
} |
| 97 |
|
| 98 |
return $updated; |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* Get UWP Settings. |
| 103 |
* |
| 104 |
* Retrieves all plugin settings. |
| 105 |
* |
| 106 |
* @return array UWP settings |
| 107 |
*/ |
| 108 |
function uwp_get_settings() { |
| 109 |
$settings = get_option( 'uwp_settings' ); |
| 110 |
|
| 111 |
if ( empty( $settings ) ) { |
| 112 |
// Update old settings with new single option. |
| 113 |
$settings = array(); |
| 114 |
|
| 115 |
update_option( 'uwp_settings', $settings ); |
| 116 |
} |
| 117 |
|
| 118 |
return apply_filters( 'uwp_get_settings', $settings ); |
| 119 |
} |
| 120 |
|
| 121 |
function uwp_get_register_only_fields(){ |
| 122 |
$reg_only_fields = array('username', 'register_gdpr', 'register_tos', 'subscribe'); |
| 123 |
return apply_filters('uwp_register_mandatory_fields', $reg_only_fields); |
| 124 |
} |