2019-09-20 09:37:55 +02:00
|
|
|
<?php
|
2019-09-10 06:27:33 +02:00
|
|
|
|
|
|
|
function opalestate_submssion_list_page( $args = [] ) {
|
2019-09-20 09:37:55 +02:00
|
|
|
return opalestate_get_user_management_page_uri( [ 'tab' => 'submission_list' ] );
|
2019-09-10 06:27:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function opalestate_get_user_management_page_uri( $args = [] ) {
|
|
|
|
|
|
|
|
global $opalestate_options;
|
|
|
|
|
|
|
|
$uri = isset( $opalestate_options['user_management_page'] ) ? get_permalink( absint( $opalestate_options['user_management_page'] ) ) : get_bloginfo( 'url' );
|
|
|
|
|
|
|
|
if ( ! empty( $args ) ) {
|
|
|
|
// Check for backward compatibility
|
|
|
|
if ( is_string( $args ) ) {
|
|
|
|
$args = str_replace( '?', '', $args );
|
|
|
|
}
|
|
|
|
$args = wp_parse_args( $args );
|
|
|
|
$uri = add_query_arg( $args, $uri );
|
|
|
|
}
|
|
|
|
|
|
|
|
return apply_filters( 'opalestate_user_management_page_uri', $uri );
|
|
|
|
}
|
|
|
|
|
|
|
|
function opalestate_get_current_url( $args = [] ) {
|
|
|
|
global $wp;
|
2019-09-20 09:37:55 +02:00
|
|
|
if ( isset( $_GET['tab'] ) && $_GET['tab'] ) {
|
|
|
|
$args['tab'] = $_GET['tab'];
|
|
|
|
}
|
2019-09-10 06:27:33 +02:00
|
|
|
$current_url = home_url( add_query_arg( $args, $wp->request ) );
|
2019-09-20 09:37:55 +02:00
|
|
|
|
2019-09-10 06:27:33 +02:00
|
|
|
return $current_url;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function opalestate_get_user_tab_uri( $tab ) {
|
2019-09-20 09:37:55 +02:00
|
|
|
$args['tab'] = $tab;
|
|
|
|
|
2019-09-10 06:27:33 +02:00
|
|
|
return opalestate_get_current_url( $args );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function opalestate_management_show_content_page_tab() {
|
|
|
|
|
2019-09-20 09:37:55 +02:00
|
|
|
$tab = isset( $_GET['tab'] ) && $_GET['tab'] ? sanitize_text_field( $_GET['tab'] ) : 'dashboard';
|
|
|
|
|
|
|
|
$fnc = 'opalestate_user_content_' . $tab . '_page';
|
2019-09-10 06:27:33 +02:00
|
|
|
|
|
|
|
$content = apply_filters( $fnc, '' );
|
|
|
|
|
2019-09-20 09:37:55 +02:00
|
|
|
if ( $content ) {
|
2019-09-10 06:27:33 +02:00
|
|
|
echo $content;
|
|
|
|
} else {
|
2019-09-20 09:37:55 +02:00
|
|
|
if ( function_exists( $fnc ) ) {
|
2019-09-10 06:27:33 +02:00
|
|
|
$fnc();
|
|
|
|
} else {
|
|
|
|
opalestate_user_content_dashboard_page();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function opalestate_user_savedsearch_page( $args = [] ) {
|
|
|
|
|
|
|
|
$uri = get_permalink( opalestate_get_option( 'saved_link_page', '/' ) );
|
|
|
|
|
|
|
|
if ( ! empty( $args ) ) {
|
|
|
|
// Check for backward compatibility
|
|
|
|
if ( is_string( $args ) ) {
|
|
|
|
$args = str_replace( '?', '', $args );
|
|
|
|
}
|
|
|
|
$args = wp_parse_args( $args );
|
|
|
|
$uri = add_query_arg( $args, $uri );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $uri;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-20 09:37:55 +02:00
|
|
|
function opalestate_my_account_page( $id = false, $args = [] ) {
|
|
|
|
|
2019-09-10 06:27:33 +02:00
|
|
|
$page = get_permalink( opalestate_get_option( 'user_myaccount_page', '/' ) );
|
|
|
|
if ( $id ) {
|
|
|
|
$edit_page_id = opalestate_get_option( 'user_myaccount_page' );
|
|
|
|
$page = $edit_page_id ? get_permalink( $edit_page_id ) : $page;
|
|
|
|
$page = add_query_arg( 'id', $id, $page );
|
|
|
|
}
|
2019-09-20 09:37:55 +02:00
|
|
|
if ( $args ) {
|
|
|
|
foreach ( $args as $key => $value ) {
|
|
|
|
$page = add_query_arg( $key, $value, $page );
|
2019-09-10 06:27:33 +02:00
|
|
|
}
|
|
|
|
}
|
2019-09-20 09:37:55 +02:00
|
|
|
|
2019-09-10 06:27:33 +02:00
|
|
|
return $page;
|
|
|
|
}
|
|
|
|
|
2019-09-20 09:37:55 +02:00
|
|
|
function opalestate_submssion_page( $id = false, $args = [] ) {
|
|
|
|
|
2019-09-10 06:27:33 +02:00
|
|
|
|
|
|
|
$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;
|
|
|
|
$page = add_query_arg( 'id', $id, $page );
|
|
|
|
}
|
2019-09-20 09:37:55 +02:00
|
|
|
if ( $args ) {
|
|
|
|
foreach ( $args as $key => $value ) {
|
|
|
|
$page = add_query_arg( $key, $value, $page );
|
2019-09-10 06:27:33 +02:00
|
|
|
}
|
|
|
|
}
|
2019-09-20 09:37:55 +02:00
|
|
|
|
2019-09-10 06:27:33 +02:00
|
|
|
return $page;
|
|
|
|
}
|
|
|
|
|
2019-09-20 09:37:55 +02:00
|
|
|
function opalestate_management_user_menu() {
|
2019-09-10 06:27:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function opalestate_management_user_menu_tabs() {
|
2019-09-20 09:37:55 +02:00
|
|
|
|
2019-09-10 06:27:33 +02:00
|
|
|
global $opalestate_options;
|
|
|
|
$menu = [];
|
|
|
|
|
|
|
|
$menu['dashboard'] = [
|
|
|
|
'icon' => 'fa fa-user',
|
|
|
|
'link' => 'dashboard',
|
|
|
|
'title' => esc_html__( 'Dashboard', 'opalestate-pro' ),
|
|
|
|
'id' => isset( $opalestate_options['profile_page'] ) ? $opalestate_options['profile_page'] : 0,
|
|
|
|
];
|
|
|
|
|
|
|
|
$menu['profile'] = [
|
|
|
|
'icon' => 'fa fa-user',
|
|
|
|
'link' => 'profile',
|
|
|
|
'title' => esc_html__( 'Personal Information', 'opalestate-pro' ),
|
|
|
|
'id' => isset( $opalestate_options['profile_page'] ) ? $opalestate_options['profile_page'] : 0,
|
|
|
|
];
|
|
|
|
|
|
|
|
$menu['favorite'] = [
|
|
|
|
'icon' => 'fa fa-heart',
|
2019-09-20 09:37:55 +02:00
|
|
|
'link' => 'favorite',
|
2019-09-10 06:27:33 +02:00
|
|
|
'title' => esc_html__( 'Favorite', 'opalestate-pro' ),
|
|
|
|
'id' => isset( $opalestate_options['favorite_page'] ) ? $opalestate_options['favorite_page'] : 0,
|
|
|
|
];
|
|
|
|
|
|
|
|
$menu['reviews'] = [
|
|
|
|
'icon' => 'fa fa-star',
|
2019-09-20 09:37:55 +02:00
|
|
|
'link' => 'reviews',
|
2019-09-10 06:27:33 +02:00
|
|
|
'title' => esc_html__( 'Reviews', 'opalestate-pro' ),
|
|
|
|
'id' => isset( $opalestate_options['reviews_page'] ) ? $opalestate_options['reviews_page'] : 0,
|
|
|
|
];
|
|
|
|
|
2019-09-20 09:37:55 +02:00
|
|
|
if ( opalestate_get_option( 'message_log' ) ) {
|
2019-09-10 06:27:33 +02:00
|
|
|
$menu['messages'] = [
|
|
|
|
'icon' => 'fa fa-envelope',
|
2019-09-20 09:37:55 +02:00
|
|
|
'link' => 'messages',
|
2019-09-10 06:27:33 +02:00
|
|
|
'title' => esc_html__( 'Messages', 'opalestate-pro' ),
|
|
|
|
'id' => isset( $opalestate_options['reviews_page'] ) ? $opalestate_options['reviews_page'] : 0,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
$menu['submission'] = [
|
|
|
|
'icon' => 'fa fa-upload',
|
|
|
|
'link' => 'submission',
|
|
|
|
'title' => esc_html__( 'Submit Property', 'opalestate-pro' ),
|
|
|
|
'id' => isset( $opalestate_options['submission_page'] ) ? $opalestate_options['submission_page'] : 0,
|
|
|
|
];
|
|
|
|
|
|
|
|
$menu['myproperties'] = [
|
|
|
|
'icon' => 'fa fa-building',
|
|
|
|
'link' => 'submission_list',
|
|
|
|
'title' => esc_html__( 'My Properties', 'opalestate-pro' ),
|
|
|
|
'id' => isset( $opalestate_options['submission_list_page'] ) ? $opalestate_options['submission_list_page'] : 0,
|
|
|
|
];
|
|
|
|
|
|
|
|
$menu = apply_filters( 'opalestate_management_user_menu', $menu );
|
|
|
|
|
|
|
|
$output = '<ul class="account-links nav-pills nav-stacked">';
|
|
|
|
|
|
|
|
global $post;
|
|
|
|
|
2019-09-18 08:21:58 +02:00
|
|
|
$uri = opalestate_get_user_management_page_uri();
|
|
|
|
|
|
|
|
$current_tab = isset( $_GET['tab'] ) && $_GET['tab'] ? sanitize_text_field( $_GET['tab'] ) : 'dashboard';
|
2019-09-10 06:27:33 +02:00
|
|
|
|
|
|
|
foreach ( $menu as $key => $item ) {
|
2019-09-20 09:37:55 +02:00
|
|
|
if ( preg_match( "#http#", $item['link'] ) ) {
|
|
|
|
$link = $item['link'];
|
2019-09-10 06:27:33 +02:00
|
|
|
} else {
|
2019-09-20 09:37:55 +02:00
|
|
|
$link = $uri . '?tab=' . $item['link'];
|
2019-09-10 06:27:33 +02:00
|
|
|
}
|
2019-09-18 08:21:58 +02:00
|
|
|
|
|
|
|
$output .= '<li class="account-links-item' . ( $current_tab == $item['link'] ? ' active' : '' ) . '"><a href="' . $link . '"><i class="' . $item['icon'] . '"></i> ' . $item['title'] . '</a></li>';
|
2019-09-10 06:27:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$output .= '<li><a href="' . wp_logout_url( home_url( '/' ) ) . '"> <i class="fa fa-unlock"></i> ' . esc_html__( 'Log out', 'opalestate-pro' ) . '</a></li>';
|
|
|
|
|
|
|
|
$output .= '</ul>';
|
|
|
|
|
|
|
|
echo $output;
|
|
|
|
}
|
|
|
|
|
2019-09-20 09:37:55 +02:00
|
|
|
function opalestate_user_content_dashboard_page() {
|
2019-09-10 06:27:33 +02:00
|
|
|
echo opalestate_load_template_path( 'user/dashboard' );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! function_exists( 'opalestate_create_user' ) ) {
|
|
|
|
/**
|
|
|
|
* create new wp user
|
|
|
|
*/
|
|
|
|
function opalestate_create_user( $credentials = [] ) {
|
|
|
|
$cred = wp_parse_args( $credentials, [
|
|
|
|
'user_login' => '',
|
|
|
|
'user_email' => '',
|
|
|
|
'user_pass' => '',
|
|
|
|
'first_name' => '',
|
|
|
|
'last_name' => '',
|
|
|
|
] );
|
|
|
|
|
|
|
|
/* sanitize user email */
|
|
|
|
$user_email = sanitize_email( $cred['user_email'] );
|
|
|
|
if ( email_exists( $user_email ) ) {
|
|
|
|
return new WP_Error( 'email-exists', esc_html__( 'An account is already registered with your email address. Please login.', 'opalestate-pro' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
$username = sanitize_user( $cred['user_login'] );
|
|
|
|
if ( ! $username || ! validate_username( $username ) ) {
|
|
|
|
return new WP_Error( 'username-invalid', esc_html__( 'Please enter a valid account username.', 'opalestate-pro' ) );
|
|
|
|
}
|
|
|
|
/* if username exists */
|
|
|
|
if ( username_exists( $username ) ) {
|
|
|
|
return new WP_Error( 'username-exists', esc_html__( 'Username is already exists.', 'opalestate-pro' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* password empty */
|
|
|
|
if ( ! $cred['user_pass'] ) {
|
|
|
|
return new WP_Error( 'password-empty', esc_html__( 'Password is requried.', 'opalestate-pro' ) );
|
|
|
|
} else {
|
|
|
|
$password = $cred['user_pass'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$user_data = apply_filters( 'opalestate_create_user_data', [
|
|
|
|
'user_login' => $username,
|
|
|
|
'user_pass' => $password,
|
|
|
|
'user_email' => $user_email,
|
|
|
|
] );
|
|
|
|
|
|
|
|
/* insert new wp user */
|
|
|
|
$user_id = wp_insert_user( $user_data );
|
|
|
|
if ( is_wp_error( $user_id ) ) {
|
|
|
|
return new WP_Error( 'user-create-failed', $user_id->get_error_message() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* allow hook like insert user meta. create new post type agent in opalmembership */
|
|
|
|
do_action( 'opalmembership_create_new_user_successfully', $user_id, $user_data, $cred );
|
|
|
|
|
|
|
|
return $user_id;
|
|
|
|
}
|
|
|
|
}
|
2019-09-20 09:37:55 +02:00
|
|
|
|
2019-09-18 08:21:58 +02:00
|
|
|
?>
|