Files
ultimatemember/includes/core/class-options.php
T

176 lines
3.4 KiB
PHP
Raw Normal View History

2017-12-11 09:53:38 +02:00
<?php
namespace um\core;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
2017-12-11 09:53:38 +02:00
2018-03-26 01:27:46 +03:00
if ( ! class_exists( 'um\core\Options' ) ) {
2018-03-20 13:24:38 +02:00
/**
* Class Options
* @package um\core
*/
2017-12-11 09:53:38 +02:00
class Options {
2018-03-20 13:24:38 +02:00
/**
* @var array
*/
2017-12-12 11:13:02 +02:00
var $options = array();
2017-12-11 09:53:38 +02:00
2018-03-20 13:24:38 +02:00
2017-12-11 09:53:38 +02:00
/**
2018-03-20 13:24:38 +02:00
* Options constructor.
2017-12-11 09:53:38 +02:00
*/
function __construct() {
$this->init_variables();
}
/**
* Set variables
*/
function init_variables() {
2022-06-06 15:56:53 +03:00
$this->options = get_option( 'um_options', array() );
2017-12-11 09:53:38 +02:00
}
/**
* Get UM option value
*
* @param $option_id
* @return mixed|string|void
*/
function get( $option_id ) {
2018-03-02 09:55:49 +02:00
if ( isset( $this->options[ $option_id ] ) ) {
/**
* UM hook
*
* @type filter
* @title um_get_option_filter__{$option_id}
* @description Change UM option on get by $option_id
* @input_vars
* [{"var":"$option","type":"array","desc":"Option Value"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_get_option_filter__{$option_id}', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_get_option_filter__{$option_id}', 'my_get_option_filter', 10, 1 );
* function my_get_option_filter( $option ) {
* // your code here
* return $option;
* }
* ?>
*/
2017-12-11 09:53:38 +02:00
return apply_filters( "um_get_option_filter__{$option_id}", $this->options[ $option_id ] );
2018-03-02 09:55:49 +02:00
}
2017-12-11 09:53:38 +02:00
switch ( $option_id ) {
case 'site_name':
return get_bloginfo( 'name' );
break;
case 'admin_email':
return get_bloginfo( 'admin_email' );
break;
default:
return '';
break;
}
}
/**
* Update UM option value
*
* @param $option_id
* @param $value
*/
function update( $option_id, $value ) {
$this->options[ $option_id ] = $value;
update_option( 'um_options', $this->options );
}
/**
* Delete UM option
*
* @param $option_id
*/
2017-12-12 11:13:02 +02:00
function remove( $option_id ) {
if ( ! empty( $this->options[ $option_id ] ) ) {
2017-12-11 09:53:38 +02:00
unset( $this->options[ $option_id ] );
}
2017-12-11 09:53:38 +02:00
update_option( 'um_options', $this->options );
}
/**
* Get UM option default value
*
* @use UM()->config()
*
* @param $option_id
2023-07-06 01:56:59 +03:00
* @return mixed
2017-12-11 09:53:38 +02:00
*/
function get_default( $option_id ) {
$settings_defaults = UM()->config()->settings_defaults;
2023-07-06 01:56:59 +03:00
if ( ! isset( $settings_defaults[ $option_id ] ) ) {
2017-12-11 09:53:38 +02:00
return false;
2023-07-06 01:56:59 +03:00
}
2017-12-11 09:53:38 +02:00
return $settings_defaults[ $option_id ];
}
/**
* Get predefined page option key
*
* @since 2.8.3
*
* @param string $slug
*
* @return string
*/
public function get_predefined_page_option_key( $slug ) {
return apply_filters( 'um_predefined_page_option_key', "core_{$slug}" );
}
2018-03-02 09:55:49 +02:00
/**
* Get core page ID
*
* @param string $key
*
* @return mixed|void
*/
function get_core_page_id( $key ) {
/**
* UM hook
*
* @type filter
* @title um_core_page_id_filter
* @description Change UM page slug
* @input_vars
* [{"var":"$slug","type":"array","desc":"UM page slug"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_core_page_id_filter', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_core_page_id_filter', 'my_core_page_id', 10, 1 );
* function my_core_page_id( $slug ) {
* // your code here
* return $slug;
* }
* ?>
*/
return apply_filters( 'um_core_page_id_filter', 'core_' . $key );
}
2017-12-11 09:53:38 +02:00
}
}