Check if current user has created a location or not
-
Hi,
I’m currently using UsersWP and GeoDirectory and I want to achieve the following:
- Provide “My Shop Location” as a menu item in the UsersWP>Account page (DONE: https://paste.pics/9d861cfe4438b7bfcbf13ffee5bac379)
- Limit one location creation per user (DONE: https://paste.pics/708992d4ef3a997151b571f8d7b8a28a )
- Check with PHP if the currently_logged_in_user has created or not created a location. Here is my PHP code for all of this functionality so far:
if ( is_user_logged_in() ) { echo 'Welcome, registered user!'; global $current_user; get_currentuserinfo(); switch (true) { case ( user_can( $current_user, "barber") ): //blank break; //if user role is barber shop: case ( user_can( $current_user, "barber_shop") ): //create a new meny item add_filter('uwp_account_available_tabs', 'uwp_account_available_tabs_cb', 10, 1); function uwp_account_available_tabs_cb($tabs){ $tabs['barber-shop-tab'] = array( 'title' => __( 'Edit My Barber Shop', 'userswp' ), 'icon' => 'fas fa-store-alt', ); return $tabs; } //create a header title for the new menu item add_filter('uwp_account_page_title', 'uwp_account_page_title_cb', 10, 2); function uwp_account_page_title_cb($title, $type){ if ( $type == 'barber-shop-tab' ) { $title = __( 'Edit My Barber Shop', 'uwp-messaging' ); } return $title; } //create content of the new menu item add_filter('uwp_account_form_display', 'uwp_account_form_display_cb', 10, 1); function uwp_account_form_display_cb($type){ if ( $type == 'barber-shop-tab' ) { //check if user already has created a location: //if yes provide an Edit Location button //if not provide a Create New Location button echo do_shortcode('[gd_add_listing mapzoom="0" label_type="horizontal" show_login="1" mb="3"]'); } } break; case ( user_can( $current_user, "administrator") ): //blank break; } } else { echo 'Welcome, visitor!'; }
I have noticed that when using echo do_shortcode(‘[gd_add_listing mapzoom=”0″ label_type=”horizontal” show_login=”1″ mb=”3″]’); inside of UsersWP > Account, it brakes the MAP and it’s not loading. To avoid this I want to simply create two buttons inside UsersWP > Account > Edit My Barber Shop.
- Check if user has a post:
- – If yes:
- – Get post ID
- – Provide a link button (“Edit Location”) which will go on separate page to edit Location (Using this approach I would avoid the map breaking)
- – If not:
- – Provide a link button (“Create new location for my Barber Shop”) which will go on a separate page to enable users create a new Location (Will redirect to GD/Add-Listing default page.)
Thanks for your time, if you have any suggestions please let me know how to achieve this.
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Check if current user has created a location or not’ is closed to new replies.