From 7aaf47dc2d0f90facd536a4d5ce89534bb0489ac Mon Sep 17 00:00:00 2001 From: Mykyta Synelnikov Date: Thu, 7 Mar 2024 14:56:55 +0200 Subject: [PATCH] - WPCS; - hookdocs; --- includes/admin/class-site-health.php | 2 +- includes/admin/core/class-admin-columns.php | 2 +- includes/admin/core/class-admin-settings.php | 36 ------ includes/class-config.php | 4 +- includes/core/class-options.php | 124 ++++++++++--------- includes/core/class-setup.php | 2 +- includes/core/um-actions-register.php | 2 +- 7 files changed, 70 insertions(+), 102 deletions(-) diff --git a/includes/admin/class-site-health.php b/includes/admin/class-site-health.php index 7f15dea0..30406f7c 100644 --- a/includes/admin/class-site-health.php +++ b/includes/admin/class-site-health.php @@ -165,7 +165,7 @@ class Site_Health { $pages = array(); $predefined_pages = UM()->config()->core_pages; foreach ( $predefined_pages as $page_s => $page ) { - $page_id = UM()->options()->get_core_page_id( $page_s ); + $page_id = UM()->options()->get_predefined_page_option_key( $page_s ); $page_title = ! empty( $page['title'] ) ? $page['title'] : ''; if ( empty( $page_title ) ) { continue; diff --git a/includes/admin/core/class-admin-columns.php b/includes/admin/core/class-admin-columns.php index 212edfac..9baa4527 100644 --- a/includes/admin/core/class-admin-columns.php +++ b/includes/admin/core/class-admin-columns.php @@ -244,7 +244,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Columns' ) ) { public function add_display_post_states( $post_states, $post ) { foreach ( UM()->config()->core_pages as $page_key => $page_value ) { - $page_id = UM()->options()->get( UM()->options()->get_core_page_id( $page_key ) ); + $page_id = UM()->options()->get( UM()->options()->get_predefined_page_option_key( $page_key ) ); if ( $page_id == $post->ID ) { $post_states[ 'um_core_page_' . $page_key ] = sprintf( 'UM %s', $page_value['title'] ); diff --git a/includes/admin/core/class-admin-settings.php b/includes/admin/core/class-admin-settings.php index b1bc777a..74af0edc 100644 --- a/includes/admin/core/class-admin-settings.php +++ b/includes/admin/core/class-admin-settings.php @@ -249,42 +249,6 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) { ), ); -// $core_pages = UM()->config()->core_pages; -// -// foreach ( $core_pages as $page_s => $page ) { -// $have_pages = UM()->query()->wp_pages(); -// $page_id = UM()->options()->get_core_page_id( $page_s ); -// -// $page_title = ! empty( $page['title'] ) ? $page['title'] : ''; -// -// if ( 'reached_maximum_limit' === $have_pages ) { -// $general_pages_fields[] = array( -// 'id' => $page_id, -// 'type' => 'text', -// // translators: %s: Page title -// 'label' => sprintf( __( '%s page', 'ultimate-member' ), $page_title ), -// 'placeholder' => __( 'Add page ID', 'ultimate-member' ), -// 'compiler' => true, -// 'size' => 'small', -// ); -// } else { -// $general_pages_fields[] = array( -// 'id' => $page_id, -// 'type' => 'select', -// // translators: %s: Page title -// 'label' => sprintf( __( '%s page', 'ultimate-member' ), $page_title ), -// 'options' => UM()->query()->wp_pages(), -// 'placeholder' => __( 'Choose a page...', 'ultimate-member' ), -// 'compiler' => true, -// 'size' => 'small', -// ); -// } -// -// $settings_map[ $page_id ] = array( -// 'sanitize' => 'absint', -// ); -// } - foreach ( UM()->config()->get( 'predefined_pages' ) as $slug => $page ) { $page_id = UM()->options()->get_predefined_page_option_key( $slug ); $page_title = ! empty( $page['title'] ) ? $page['title'] : ''; diff --git a/includes/class-config.php b/includes/class-config.php index de0cda8a..3d3039a5 100644 --- a/includes/class-config.php +++ b/includes/class-config.php @@ -627,7 +627,7 @@ if ( ! class_exists( 'um\Config' ) ) { } foreach ( $this->core_pages as $page_s => $page ) { - $page_id = UM()->options()->get_core_page_id( $page_s ); + $page_id = UM()->options()->get_predefined_page_option_key( $page_s ); $this->settings_defaults[ $page_id ] = ''; } @@ -781,7 +781,7 @@ if ( ! class_exists( 'um\Config' ) ) { } foreach ( $core_pages as $page_key ) { - $page_option_key = UM()->options()->get_core_page_id( $page_key ); + $page_option_key = UM()->options()->get_predefined_page_option_key( $page_key ); $permalink[ $page_key ] = UM()->options()->get( $page_option_key ); } diff --git a/includes/core/class-options.php b/includes/core/class-options.php index 66a0ca97..daf801e3 100644 --- a/includes/core/class-options.php +++ b/includes/core/class-options.php @@ -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 - * - * @example - * Change `option_1` value. + * 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 Change option key for login predefined page. + * 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 - * - * @example - * Change option key for login predefined page. + * 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 ) ); } - } } diff --git a/includes/core/class-setup.php b/includes/core/class-setup.php index 305397b1..ae67f0ac 100644 --- a/includes/core/class-setup.php +++ b/includes/core/class-setup.php @@ -213,7 +213,7 @@ KEY meta_value_indx (um_value(191)) $options = get_option( 'um_options', array() ); foreach ( $core_pages as $slug => $page_id ) { - $key = UM()->options()->get_core_page_id( $slug ); + $key = UM()->options()->get_predefined_page_option_key( $slug ); $options[ $key ] = $page_id; } diff --git a/includes/core/um-actions-register.php b/includes/core/um-actions-register.php index 5d4bf6ac..d79718c4 100644 --- a/includes/core/um-actions-register.php +++ b/includes/core/um-actions-register.php @@ -766,7 +766,7 @@ add_action( 'um_registration_set_extra_data', 'um_registration_set_profile_full_ * Redirect from default registration to UM registration page */ function um_form_register_redirect() { - $page_id = UM()->options()->get( UM()->options()->get_core_page_id( 'register' ) ); + $page_id = UM()->options()->get( UM()->options()->get_predefined_page_option_key( 'register' ) ); // Do not redirect if the registration page is not published. if ( ! empty( $page_id ) && 'publish' === get_post_status( $page_id ) ) { // Not `um_safe_redirect()` because predefined register page is situated on the same host.