diff --git a/changelog.txt b/changelog.txt
index d2f06595..9082e135 100755
--- a/changelog.txt
+++ b/changelog.txt
@@ -1,3 +1,6 @@
+= 1.3.6 - 2020-02-29 =
+* Fixes - User register form & User roles
+
= 1.3.5 - 2020-02-28 =
* Added - Time format setting
* Added - Hide unset amenities settings
diff --git a/inc/admin/class-user.php b/inc/admin/class-user.php
index 6f4a567b..5c44bdf9 100755
--- a/inc/admin/class-user.php
+++ b/inc/admin/class-user.php
@@ -1,4 +1,4 @@
-
+
+
+
+
+
-
-
-
-
- $prefix . 'edit',
'title' => esc_html__( 'Metabox', 'opalestate-pro' ),
- 'object_types' => array( 'user' ),
+ 'object_types' => [ 'user' ],
'show_names' => true,
- );
+ ];
$cmb = new_cmb2_box( $box_options );
// Setting tabs
- $tabs_setting = array(
+ $tabs_setting = [
'config' => $box_options,
'layout' => 'vertical', // Default : horizontal
- 'tabs' => array()
- );
+ 'tabs' => [],
+ ];
-
- $tabs_setting['tabs'][] = array(
+ $tabs_setting['tabs'][] = [
'id' => 'p-general',
- 'icon' => 'dashicons-admin-home',
+ 'icon' => 'dashicons-admin-home',
'title' => esc_html__( 'General', 'opalestate-pro' ),
- 'fields' => $this->get_base_fields()
- );
+ 'fields' => $this->get_base_fields(),
+ ];
- $tabs_setting['tabs'][] = array(
+ $tabs_setting['tabs'][] = [
'id' => 'p-socials',
- 'icon' => 'dashicons-share',
+ 'icon' => 'dashicons-share',
'title' => esc_html__( 'Socials', 'opalestate-pro' ),
'fields' => $metabox->get_social_fields( $prefix ),
- );
+ ];
+
-
// Set tabs
- $cmb->add_field( array(
+ $cmb->add_field( [
'id' => '__tabs',
'type' => 'tabs',
- 'tabs' => $tabs_setting
- ) );
+ 'tabs' => $tabs_setting,
+ ] );
/**
* Metabox for the user profile screen
*/
- $cmb_user = new_cmb2_box( array(
+ $cmb_user = new_cmb2_box( [
'id' => $prefix . 'edit',
'title' => esc_html__( 'User Profile Metabox', 'cmb2' ), // Doesn't output for user boxes
- 'object_types' => array( 'user' ), // Tells CMB2 to use user_meta vs post_meta
+ 'object_types' => [ 'user' ], // Tells CMB2 to use user_meta vs post_meta
'show_names' => true,
'new_user_section' => 'add-new-user', // where form will show on new user page. 'add-existing-user' is only other valid option.
- ) );
-
+ ] );
+
$fields = $this->extra_info_fields();
- foreach( $fields as $field ){
- $cmb_user->add_field( $field );
- }
+ foreach ( $fields as $field ) {
+ $cmb_user->add_field( $field );
+ }
}
}
- public function get_base_fields(){
+ public function get_base_fields() {
$prefix = OPALESTATE_USER_PROFILE_PREFIX;
- $metabox = new Opalestate_User_MetaBox();
- $fields = array_merge_recursive(
+ $metabox = new Opalestate_User_MetaBox();
+ $fields = array_merge_recursive(
$metabox->get_base_fields( $prefix ),
- $metabox->get_job_fields( $prefix ) ,
+ $metabox->get_job_fields( $prefix ),
$metabox->get_address_fields( $prefix )
);
return $fields;
}
+
/**
*
*/
- public function extra_info_fields(){
+ public function extra_info_fields() {
+
-
$prefix = OPALESTATE_USER_PROFILE_PREFIX;
- $management = array();
-
+ $management = [];
- $admin_fields = array();
- $admin_fields[] = array(
- 'id' => "{$prefix}block_submission",
- 'name' => esc_html__( 'Block Submssion', 'opalestate-pro' ),
- 'type' => 'checkbox',
- 'description' => esc_html__( 'Disable Submssion Functions to not allow submit property', 'opalestate-pro' ),
- 'before_row' => '
'
-
- );
- $admin_fields[] = array(
- 'id' => "{$prefix}block_submission_msg",
- 'name' => esc_html__( 'Block Submssion Message', 'opalestate-pro' ),
- 'type' => 'textarea',
- 'description' => esc_html__( 'Show message for disabled user', 'opalestate-pro' ),
- );
- $management = array_merge_recursive( $admin_fields, $management );
-
- return $management;
- }
+ $admin_fields = [];
+ $admin_fields[] = [
+ 'id' => "{$prefix}block_submission",
+ 'name' => esc_html__( 'Block Submssion', 'opalestate-pro' ),
+ 'type' => 'checkbox',
+ 'description' => esc_html__( 'Disable Submssion Functions to not allow submit property', 'opalestate-pro' ),
+ 'before_row' => '
',
+
+ ];
+ $admin_fields[] = [
+ 'id' => "{$prefix}block_submission_msg",
+ 'name' => esc_html__( 'Block Submssion Message', 'opalestate-pro' ),
+ 'type' => 'textarea',
+ 'description' => esc_html__( 'Show message for disabled user', 'opalestate-pro' ),
+ ];
+ $management = array_merge_recursive( $admin_fields, $management );
+
+
+ return $management;
+ }
}
new OpalEstate_Admin_User();
diff --git a/inc/classes/class-opalestate-metabox-user.php b/inc/classes/class-opalestate-metabox-user.php
index 19391934..3631b5d2 100755
--- a/inc/classes/class-opalestate-metabox-user.php
+++ b/inc/classes/class-opalestate-metabox-user.php
@@ -34,7 +34,6 @@ class Opalestate_User_MetaBox {
'type' => 'uploader',
'single' => 1,
'limit' => 1,
-
],
[
'id' => 'first_name',
@@ -65,7 +64,7 @@ class Opalestate_User_MetaBox {
}
public function get_avatar_fields( $prefix ) {
- return [
+ return apply_filters( 'opalestate_get_user_matabox_avatar_fields', [
[
'name' => esc_html__( 'Avatar Picture', 'opalestate-pro' ),
'desc' => esc_html__( 'This image will display in user detail and profile box information', 'opalestate-pro' ),
@@ -74,7 +73,7 @@ class Opalestate_User_MetaBox {
'avatar' => true,
],
- ];
+ ] );
}
public function get_address_fields( $prefix ) {
diff --git a/inc/user/class-opalestate-user-search.php b/inc/user/class-opalestate-user-search.php
index 828d603c..bc373a41 100755
--- a/inc/user/class-opalestate-user-search.php
+++ b/inc/user/class-opalestate-user-search.php
@@ -188,7 +188,7 @@ class OpalEstate_User_Search {
*
*/
public function dashboard_menu( $menu ) {
- if ( 'on' === opalestate_get_option( 'enable_dashboard_savedsearch', 'on' ) ) {
+ if ( opalestate_current_user_can_access_dashboard_page( 'savedsearch' ) && 'on' === opalestate_get_option( 'enable_dashboard_savedsearch', 'on' ) ) {
$menu['savedsearch'] = [
'icon' => 'fa fa-search',
'link' => 'saved_search',
diff --git a/inc/user/class-opalestate-user.php b/inc/user/class-opalestate-user.php
index a448f079..9da41f25 100755
--- a/inc/user/class-opalestate-user.php
+++ b/inc/user/class-opalestate-user.php
@@ -63,7 +63,6 @@ class OpalEstate_User {
}
$this->enable_extra_profile = opalestate_options( 'enable_extra_profile', 'on' );
-
add_action( 'init', [ $this, 'process_frontend_submit' ], 99999 );
add_action( 'cmb2_render_text_password', [ $this, 'cmb2_render_text_password' ], 10, 5 );
@@ -160,9 +159,9 @@ class OpalEstate_User {
public function disable() {
if ( ! current_user_can( 'manage_options' ) ) {
- add_action( 'wp_before_admin_bar_render', [ $this, 'disable_profile_page' ] );
- add_action( 'admin_init', [ $this, 'disable_profile_page' ] );
- add_filter( 'show_admin_bar', '__return_false' );
+ // add_action( 'wp_before_admin_bar_render', [ $this, 'disable_profile_page' ] );
+ // add_action( 'admin_init', [ $this, 'disable_profile_page' ] );
+ add_filter( 'show_admin_bar', [ $this, 'disable_admin_bar' ] );
}
}
@@ -170,6 +169,19 @@ class OpalEstate_User {
add_action( 'opalestate_user_content_profile_page', [ $this, 'user_profile' ] );
}
+ public function disable_admin_bar( $show_admin_bar ) {
+ if ( is_user_logged_in() ) {
+ $current_user = wp_get_current_user();
+ $roles = $current_user->roles;
+
+ if ( in_array( 'opalestate_agent', $roles ) || in_array( 'opalestate_agency', $roles ) ) {
+ return false;
+ }
+ }
+
+ return $show_admin_bar;
+ }
+
/**
*
*/
@@ -303,7 +315,7 @@ class OpalEstate_User {
public static function get_user_types() {
return apply_filters( 'opalestate_usertypes', [
- 'none' => esc_html__( 'Subscriber', 'opalestate-pro' ),
+ 'subscriber' => esc_html__( 'Subscriber', 'opalestate-pro' ),
'opalestate_agent' => esc_html__( 'Agent', 'opalestate-pro' ),
'opalestate_agency' => esc_html__( 'Agency', 'opalestate-pro' ),
] );
diff --git a/inc/user/functions.php b/inc/user/functions.php
index 76ab8aa3..3a0f20ea 100755
--- a/inc/user/functions.php
+++ b/inc/user/functions.php
@@ -69,7 +69,14 @@ function opalestate_get_user_tab_uri( $tab ) {
function opalestate_management_show_content_page_tab() {
- $tab = isset( $_GET['tab'] ) && $_GET['tab'] ? sanitize_text_field( $_GET['tab'] ) : 'dashboard';
+ $tab = isset( $_GET['tab'] ) && $_GET['tab'] ? sanitize_text_field( $_GET['tab'] ) : 'dashboard';
+
+ if ( ! opalestate_current_user_can_access_dashboard_page( $tab ) ) {
+ echo opalestate_load_template_path( 'user/error' );
+
+ return;
+ }
+
$tab_hook = $tab;
$tab_hook = apply_filters( 'opalestate_user_content_tab_hook', $tab_hook, $tab );
$fnc = 'opalestate_user_content_' . $tab_hook . '_page';
@@ -122,9 +129,8 @@ function opalestate_my_account_page( $id = false, $args = [] ) {
}
function opalestate_submssion_page( $id = false, $args = [] ) {
-
-
$page = get_permalink( opalestate_get_option( 'submission_page', '/' ) );
+
if ( $id ) {
$edit_page_id = opalestate_get_option( 'submission_edit_page' );
$page = $edit_page_id ? get_permalink( $edit_page_id ) : $page;
@@ -177,12 +183,12 @@ function opalestate_get_user_dashboard_menus() {
$menu['dashboard'] = [
'icon' => 'fas fa-chart-line',
- 'link' => 'dashboard',
+ 'link' => opalestate_current_user_can_access_dashboard_page( 'dashboard' ) ? 'dashboard' : get_dashboard_url(),
'title' => esc_html__( 'Dashboard', 'opalestate-pro' ),
'id' => isset( $opalestate_options['profile_page'] ) ? $opalestate_options['profile_page'] : 0,
];
- if ( 'on' === opalestate_get_option( 'enable_dashboard_profile', 'on' ) ) {
+ if ( opalestate_current_user_can_access_dashboard_page( 'profile' ) && 'on' === opalestate_get_option( 'enable_dashboard_profile', 'on' ) ) {
$menu['profile'] = [
'icon' => 'far fa-user',
'link' => 'profile',
@@ -191,7 +197,7 @@ function opalestate_get_user_dashboard_menus() {
];
}
- if ( 'on' === opalestate_get_option( 'enable_dashboard_favorite', 'on' ) ) {
+ if ( opalestate_current_user_can_access_dashboard_page( 'favorite' ) && 'on' === opalestate_get_option( 'enable_dashboard_favorite', 'on' ) ) {
$menu['favorite'] = [
'icon' => 'far fa-heart',
'link' => 'favorite',
@@ -200,7 +206,7 @@ function opalestate_get_user_dashboard_menus() {
];
}
- if ( 'on' === opalestate_get_option( 'enable_dashboard_reviews', 'on' ) ) {
+ if ( opalestate_current_user_can_access_dashboard_page( 'reviews' ) && 'on' === opalestate_get_option( 'enable_dashboard_reviews', 'on' ) ) {
$menu['reviews'] = [
'icon' => 'far fa-star',
'link' => 'reviews',
@@ -209,7 +215,7 @@ function opalestate_get_user_dashboard_menus() {
];
}
- if ( 'on' === opalestate_get_option( 'message_log', 'on' ) ) {
+ if ( opalestate_current_user_can_access_dashboard_page( 'messages' ) && 'on' === opalestate_get_option( 'message_log', 'on' ) ) {
$menu['messages'] = [
'icon' => 'fa fa-envelope',
'link' => 'messages',
@@ -218,7 +224,7 @@ function opalestate_get_user_dashboard_menus() {
];
}
- if ( 'on' === opalestate_get_option( 'enable_dashboard_submission', 'on' ) ) {
+ if ( opalestate_current_user_can_access_dashboard_page( 'submission' ) && 'on' === opalestate_get_option( 'enable_dashboard_submission', 'on' ) ) {
$menu['submission'] = [
'icon' => 'fa fa-upload',
'link' => 'submission',
@@ -227,7 +233,7 @@ function opalestate_get_user_dashboard_menus() {
];
}
- if ( 'on' === opalestate_get_option( 'enable_dashboard_properties', 'on' ) ) {
+ if ( opalestate_current_user_can_access_dashboard_page( 'myproperties' ) && 'on' === opalestate_get_option( 'enable_dashboard_properties', 'on' ) ) {
$statistics = new OpalEstate_User_Statistics();
$menu['myproperties'] = [
@@ -308,3 +314,59 @@ if ( ! function_exists( 'opalestate_create_user' ) ) {
function opalestate_get_user_meta( $user_id, $key, $single = true ) {
return get_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . $key, $single );
}
+
+/**
+ * Current user can access dashboard page?
+ *
+ * @param $page
+ * @return bool
+ */
+function opalestate_current_user_can_access_dashboard_page( $page = '' ) {
+ if ( ! is_user_logged_in() ) {
+ return false;
+ }
+
+ $current_user = wp_get_current_user();
+ $roles = $current_user->roles;
+ $allowd_roles = opalestate_get_allowed_roles();
+
+ foreach ( $roles as $role ) {
+ if ( in_array( $role, $allowd_roles ) ) {
+ return apply_filters( 'opalestate_opalestate_user_can_access', true, $role, $page );
+ }
+ }
+
+ return false;
+}
+
+/**
+ * User has estate roles?
+ *
+ * @param $user_id
+ * @return bool
+ */
+function opalestate_user_has_estate_roles( $user_id ) {
+ $user_meta = get_userdata( $user_id );
+ $roles = $user_meta->roles;
+ $allowd_roles = opalestate_get_allowed_roles();
+
+ foreach ( $roles as $role ) {
+ if ( in_array( $role, $allowd_roles ) ) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+/**
+ * Get allowed roles for dashboard page.
+ */
+function opalestate_get_allowed_roles() {
+ return apply_filters( 'opalestate_get_allowed_roles', [
+ 'opalestate_agent',
+ 'opalestate_agency',
+ 'opalestate_manager',
+ 'administrator',
+ ] );
+}
diff --git a/inc/vendors/opalmembership/membership.php b/inc/vendors/opalmembership/membership.php
index e9645085..57c025b0 100755
--- a/inc/vendors/opalmembership/membership.php
+++ b/inc/vendors/opalmembership/membership.php
@@ -290,26 +290,33 @@ class OpalEstate_Membership {
public static function membership_menu( $menu ) {
if ( function_exists( "opalmembership_get_dashdoard_page_uri" ) ) {
global $opalmembership_options;
- $menu['membership'] = [
- 'icon' => 'fa fa-user',
- 'link' => opalmembership_get_dashdoard_page_uri(),
- 'title' => esc_html__( 'My Membership', 'opalestate-pro' ),
- 'id' => isset( $opalmembership_options['dashboard_page'] ) ? $opalmembership_options['dashboard_page'] : 0,
- ];
- $menu['membership_history'] = [
- 'icon' => 'fa fa-user',
- 'link' => opalmembership_get_payment_history_page_uri(),
- 'title' => esc_html__( 'My Invoices', 'opalestate-pro' ),
- 'id' => isset( $opalmembership_options['dashboard_page'] ) ? $opalmembership_options['dashboard_page'] : 0,
- ];
+ if ( opalestate_current_user_can_access_dashboard_page( 'membership' ) ) {
+ $menu['membership'] = [
+ 'icon' => 'fa fa-user',
+ 'link' => opalmembership_get_dashdoard_page_uri(),
+ 'title' => esc_html__( 'My Membership', 'opalestate-pro' ),
+ 'id' => isset( $opalmembership_options['dashboard_page'] ) ? $opalmembership_options['dashboard_page'] : 0,
+ ];
+ }
- $menu['packages'] = [
- 'icon' => 'fa fa-certificate',
- 'link' => opalmembership_get_membership_page_uri(),
- 'title' => esc_html__( 'Renew membership', 'opalestate-pro' ),
- 'id' => isset( $opalmembership_options['dashboard_page'] ) ? $opalmembership_options['dashboard_page'] : 0,
- ];
+ if ( opalestate_current_user_can_access_dashboard_page( 'membership_history' ) ) {
+ $menu['membership_history'] = [
+ 'icon' => 'fa fa-user',
+ 'link' => opalmembership_get_payment_history_page_uri(),
+ 'title' => esc_html__( 'My Invoices', 'opalestate-pro' ),
+ 'id' => isset( $opalmembership_options['dashboard_page'] ) ? $opalmembership_options['dashboard_page'] : 0,
+ ];
+ }
+
+ if ( opalestate_current_user_can_access_dashboard_page( 'packages' ) ) {
+ $menu['packages'] = [
+ 'icon' => 'fa fa-certificate',
+ 'link' => opalmembership_get_membership_page_uri(),
+ 'title' => esc_html__( 'Renew membership', 'opalestate-pro' ),
+ 'id' => isset( $opalmembership_options['dashboard_page'] ) ? $opalmembership_options['dashboard_page'] : 0,
+ ];
+ }
}
return $menu;
diff --git a/opal-estate-pro.php b/opal-estate-pro.php
index 5d0b782e..b562f1fd 100755
--- a/opal-estate-pro.php
+++ b/opal-estate-pro.php
@@ -3,7 +3,7 @@
* Plugin Name: Opal Estate Pro
* Plugin URI: https://wpdocs.gitbook.io/opal-estate/
* Description: Opal Real Estate Plugin is an ideal solution and brilliant choice for you to set up a professional estate website.
- * Version: 1.3.5
+ * Version: 1.3.6
* Author: WPOPAL
* Author URI: http://www.wpopal.com
* Requires at least: 4.9
@@ -150,7 +150,7 @@ if ( ! class_exists( 'OpalEstate' ) ) {
*/
public function __clone() {
// Cloning instances of the class is forbidden
- _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'opalestate-pro' ), '1.3.5' );
+ _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'opalestate-pro' ), '1.3.6' );
}
/**
@@ -159,7 +159,7 @@ if ( ! class_exists( 'OpalEstate' ) ) {
public function setup_constants() {
// Plugin version
if ( ! defined( 'OPALESTATE_VERSION' ) ) {
- define( 'OPALESTATE_VERSION', '1.3.5' );
+ define( 'OPALESTATE_VERSION', '1.3.6' );
}
// Plugin Folder Path
diff --git a/readme.txt b/readme.txt
index d1950c23..3b561339 100755
--- a/readme.txt
+++ b/readme.txt
@@ -4,7 +4,7 @@ Donate link: https://wpdocs.gitbook.io/opal-estate/
Tags: estate, property, opalestate, house for rent, agency for lease, estate submission, agents estate property, property marketplace
Requires at least: 4.9
Tested up to: 5.3.2
-Stable tag: 1.3.5
+Stable tag: 1.3.6
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl-3.0.html
@@ -156,6 +156,9 @@ This section describes how to install the plugin and get it working.
* System tickets support 24/7 available : [free support](https://wpopal.ticksy.com/ "Visit the Plugin support Page")
== Changelog ==
+= 1.3.6 - 2020-02-29 =
+* Fixes - User register form & User roles
+
= 1.3.5 - 2020-02-28 =
* Added - Time format setting
* Added - Hide unset amenities settings
diff --git a/templates/user/error.php b/templates/user/error.php
new file mode 100644
index 00000000..f2d1a3f2
--- /dev/null
+++ b/templates/user/error.php
@@ -0,0 +1,4 @@
+
diff --git a/templates/user/register-form.php b/templates/user/register-form.php
index 686b42ae..11ea0c9c 100755
--- a/templates/user/register-form.php
+++ b/templates/user/register-form.php
@@ -25,6 +25,7 @@ if ( is_user_logged_in() ) {
}
$types = OpalEstate_User::get_user_types();
+$type_default = apply_filters( 'opalestate_register_form_default_type', 'subscriber' );
?>
@@ -69,7 +70,7 @@ $types = OpalEstate_User::get_user_types();