From 1f5bf3dafc7b64d953a4b7e0554a1fac6873bea4 Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Wed, 30 Aug 2017 16:01:43 +0300 Subject: [PATCH] - fixed get_meta_value function for options with "0" value; - fixed upgrade to 2.0 for transferring menu restriction; --- includes/admin/core/packages/2.0.php | 30 ++++++++++++++++++- .../admin/templates/form/login_customize.php | 10 +++++-- .../templates/form/profile_customize.php | 12 +++++--- .../templates/form/register_customize.php | 10 +++++-- includes/core/class-query.php | 18 +++++++---- 5 files changed, 63 insertions(+), 17 deletions(-) diff --git a/includes/admin/core/packages/2.0.php b/includes/admin/core/packages/2.0.php index d805fdc8..2dd1bf6b 100644 --- a/includes/admin/core/packages/2.0.php +++ b/includes/admin/core/packages/2.0.php @@ -1166,4 +1166,32 @@ foreach ( $emails as $email_key => $value ) { } } } -} \ No newline at end of file +} + + +/** + * Transferring menu restriction data + */ +$menus = get_posts( array( + 'post_type' => 'nav_menu_item', + 'meta_query' => array( + array( + 'key' => 'menu-item-um_nav_roles', + 'compare' => 'EXISTS', + ) + ) +) ); + +foreach ( $menus as $menu ) { + $menu_roles = get_post_meta( $menu->ID, 'menu-item-um_nav_roles', true ); + + $menu_roles = array_map( function( $item ) { + if ( strpos( $item, 'um_' ) === 0 ) + return $item; + + return 'um_' . $item; + }, $menu_roles ); + + update_post_meta( $menu->ID, 'menu-item-um_nav_roles', $menu_roles ); +} + diff --git a/includes/admin/templates/form/login_customize.php b/includes/admin/templates/form/login_customize.php index 7a78ac77..75c3bee6 100644 --- a/includes/admin/templates/form/login_customize.php +++ b/includes/admin/templates/form/login_customize.php @@ -53,10 +53,14 @@ ), array( 'id' => '_um_login_secondary_btn', - 'type' => 'checkbox', + 'type' => 'select', 'label' => __( 'Show Secondary Button', 'ultimate-member' ), - 'value' => UM()->query()->get_meta_value( '_um_login_secondary_btn', null, 1 ), - 'conditional' => array( '_um_login_use_custom_settings', '=', 1 ) + 'value' => UM()->query()->get_meta_value( '_um_login_secondary_btn', null, um_get_option( 'login_secondary_btn' ) ), + 'conditional' => array( '_um_login_use_custom_settings', '=', 1 ), + 'options' => array( + 0 => __( 'No', 'ultimate-member' ), + 1 => __( 'Yes', 'ultimate-member' ), + ), ), array( 'id' => '_um_login_secondary_btn_word', diff --git a/includes/admin/templates/form/profile_customize.php b/includes/admin/templates/form/profile_customize.php index fd13ffc1..f445a28f 100644 --- a/includes/admin/templates/form/profile_customize.php +++ b/includes/admin/templates/form/profile_customize.php @@ -77,12 +77,16 @@ ), array( 'id' => '_um_profile_secondary_btn', - 'type' => 'checkbox', + 'type' => 'select', 'label' => __( 'Show Secondary Button', 'ultimate-member' ), - 'value' => UM()->query()->get_meta_value( '_um_profile_secondary_btn', null, 1 ), - 'conditional' => array( '_um_profile_use_custom_settings', '=', 1 ) + 'value' => UM()->query()->get_meta_value( '_um_profile_secondary_btn', null, um_get_option( 'profile_secondary_btn' ) ), + 'conditional' => array( '_um_profile_use_custom_settings', '=', 1 ), + 'options' => array( + 0 => __( 'No', 'ultimate-member' ), + 1 => __( 'Yes', 'ultimate-member' ), + ), ), - array( + array( 'id' => '_um_profile_secondary_btn_word', 'type' => 'text', 'label' => __( 'Primary Button Text', 'ultimate-member' ), diff --git a/includes/admin/templates/form/register_customize.php b/includes/admin/templates/form/register_customize.php index d319556e..408a8e43 100644 --- a/includes/admin/templates/form/register_customize.php +++ b/includes/admin/templates/form/register_customize.php @@ -68,10 +68,14 @@ ), array( 'id' => '_um_register_secondary_btn', - 'type' => 'checkbox', + 'type' => 'select', 'label' => __( 'Show Secondary Button', 'ultimate-member' ), - 'value' => UM()->query()->get_meta_value( '_um_register_secondary_btn', null, 1 ), - 'conditional' => array( '_um_register_use_custom_settings', '=', 1 ) + 'value' => UM()->query()->get_meta_value( '_um_register_secondary_btn', null, um_get_option( 'register_secondary_btn' ) ), + 'conditional' => array( '_um_register_use_custom_settings', '=', 1 ), + 'options' => array( + 0 => __( 'No', 'ultimate-member' ), + 1 => __( 'Yes', 'ultimate-member' ), + ), ), array( 'id' => '_um_register_secondary_btn_word', diff --git a/includes/core/class-query.php b/includes/core/class-query.php index a1c1e291..9a3d9f1d 100644 --- a/includes/core/class-query.php +++ b/includes/core/class-query.php @@ -258,15 +258,21 @@ if ( ! class_exists( 'Query' ) ) { return $array; } - /*** - *** @Capture selected value - ***/ + /** + * Capture selected value + * + * @param $key + * @param null $array_key + * @param null $fallback + * @return int|mixed|null|string + */ function get_meta_value( $key, $array_key = null, $fallback = null ) { global $post; $post_id = get_the_ID(); $try = get_post_meta( $post_id, $key, true ); - if ( ! empty( $try ) ) + //old version if ( ! empty( $try ) ) + if ( false !== $try ) if ( is_array( $try ) && in_array( $array_key, $try ) ) { return $array_key; } else if ( is_array( $try ) ) { @@ -275,13 +281,13 @@ if ( ! class_exists( 'Query' ) ) { return $try; } - if ($fallback == 'na') { + if ( $fallback == 'na' ) { $fallback = 0; $none = ''; } else { $none = 0; } - return (!empty($fallback)) ? $fallback : $none; + return ! empty( $fallback ) ? $fallback : $none; } /***