- hookdocs;
This commit is contained in:
Mykyta Synelnikov
2024-03-07 14:56:55 +02:00
parent 7c2b305266
commit 7aaf47dc2d
7 changed files with 70 additions and 102 deletions
+64 -60
View File
@@ -7,64 +7,56 @@ if ( ! defined( 'ABSPATH' ) ) {
if ( ! class_exists( 'um\core\Options' ) ) {
/**
* Class Options
* @package um\core
*/
class Options {
/**
* @var array
*/
var $options = array();
private $options = array();
/**
* Options constructor.
*/
function __construct() {
public function __construct() {
$this->init_variables();
}
/**
* Set variables
*/
function init_variables() {
private function init_variables() {
$this->options = get_option( 'um_options', array() );
}
/**
* Get UM option value
* Get UM option value.
*
* @param $option_id
* @return mixed|string|void
* @param string $option_id
*
* @return mixed
*/
function get( $option_id ) {
public function get( $option_id ) {
if ( isset( $this->options[ $option_id ] ) ) {
/**
* UM hook
* Filters the plugin option.
*
* @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;
* @param {mixed} $value Option value.
*
* @return {mixed} Option value.
*
* @since 1.3.67
* @hook um_get_option_filter__{$option_id}
*
* @example <caption>Change `option_1` value.</caption>
* function my_custom_option_1( $value ) {
* $value = 'option_1_custom_value';
* return $value;
* }
* ?>
* add_filter( 'um_get_option_filter__option_1', 'my_custom_option_1' );
*/
return apply_filters( "um_get_option_filter__{$option_id}", $this->options[ $option_id ] );
}
@@ -72,35 +64,30 @@ if ( ! class_exists( 'um\core\Options' ) ) {
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 ) {
public function update( $option_id, $value ) {
$this->options[ $option_id ] = $value;
update_option( 'um_options', $this->options );
}
/**
* Delete UM option
*
* @param $option_id
*/
function remove( $option_id ) {
public function remove( $option_id ) {
if ( ! empty( $this->options[ $option_id ] ) ) {
unset( $this->options[ $option_id ] );
}
@@ -108,16 +95,15 @@ if ( ! class_exists( 'um\core\Options' ) ) {
update_option( 'um_options', $this->options );
}
/**
* Get UM option default value
*
* @use UM()->config()
*
* @param $option_id
* @param string $option_id
* @return mixed
*/
function get_default( $option_id ) {
public function get_default( $option_id ) {
$settings_defaults = UM()->config()->settings_defaults;
if ( ! isset( $settings_defaults[ $option_id ] ) ) {
return false;
@@ -136,40 +122,58 @@ if ( ! class_exists( 'um\core\Options' ) ) {
* @return string
*/
public function get_predefined_page_option_key( $slug ) {
/**
* Filters the predefined page option key.
*
* @param {string} $option_key Predefined page option key.
*
* @return {string} Predefined page option key.
*
* @since 2.8.3
* @hook um_predefined_page_option_key
*
* @example <caption>Change option key for login predefined page.</caption>
* function my_um_predefined_page_option_key( $option_key ) {
* if ( 'core_login' === $option_key ) {
* $option_key = 'core_login_custom';
* }
* return $option_key;
* }
* add_filter( 'um_predefined_page_option_key', 'my_um_predefined_page_option_key' );
*/
return apply_filters( 'um_predefined_page_option_key', "core_{$slug}" );
}
/**
* Get core page ID
*
* @todo Deprecate soon
*
* @param string $key
*
* @return mixed|void
* @return string
*/
function get_core_page_id( $key ) {
public function get_core_page_id( $key ) {
/**
* UM hook
* Filters the predefined page option key.
*
* @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;
* @param {string} $page_key Predefined page option key.
*
* @return {string} Predefined page option key.
*
* @since 1.3.x
* @hook um_core_page_id_filter
*
* @example <caption>Change option key for login predefined page.</caption>
* function my_um_core_page_id_filter( $page_key ) {
* if ( 'core_login' === $page_key ) {
* $page_key = 'core_login_custom';
* }
* return $page_key;
* }
* ?>
* add_filter( 'um_core_page_id_filter', 'my_um_core_page_id_filter' );
*/
return apply_filters( 'um_core_page_id_filter', 'core_' . $key );
return apply_filters( 'um_core_page_id_filter', $this->get_predefined_page_option_key( $key ) );
}
}
}