Alex Howes
Forum Replies Created
-
AuthorPosts
-
Sorry. My site is primarily a farm job site. There are two CPTs, jobs and farms, which are linked. Users with the role “employer” can claim farm listings, list farms, and post jobs.
Currently employers can post jobs whether or not they have a farm because the “Link Farm” option at the top of the add job form is optional.
However, I want to force all employers to link posted jobs to one of their farms, and not be able to post jobs if they don’t have a farm. I.e. there should be no jobs appearing that aren’t linked to a farm. Is it possible to do this?
I tested it with a listing that did have a featured image, and it’s working fine. Sorry for the trouble.
Ah, ok, thanks 🙂
Sorry, I didn’t realise that. The listing has a default image- can that not be used?
Alex
This reply has been marked as private.Thanks Kor, that’s perfect! I’ll apply it in the same way to my other pages 🙂
Thanks Kor, I didn’t realise custom CSS could be used to do that 🙂
An example page is this: https://www.barn-door.co.uk/farms/coybal-farm/ where the category link is “Dairy Cows” at the top of the page.
Sorry for the last question, I’ve got it working now 🙂 In case anyone else is interested in doing this I’ve posted my code below. Thanks for your help! 🙂
The post type (CPT) I’m blocking is “gd_cv”, which I’m only allowing the logged in listing owner to view.
function cv_detail_redirect() { $current_user = wp_get_current_user(); $current_user_roles = $current_user->roles; global $post; if ($post) { $author_id = $post->post_author; if( geodir_is_page('detail') && ! is_user_logged_in() && geodir_get_current_posttype() == 'gd_cv') { wp_redirect( home_url( '/login/' ) ); die; } elseif( geodir_is_page('detail') && is_user_logged_in() && geodir_get_current_posttype() == 'gd_cv') { if ( ! ( current_user_can('manage_options') || ( !empty( $author_id ) && get_current_user_id() == $author_id ) ) ) { wp_redirect( home_url( '' ) ); die; } } } } add_action( 'template_redirect', 'cv_detail_redirect' );
Thanks! I’ve almost got it working. Is there a GD function to get the id of the listing owner?
Yes I understand that bit but is there a way to check if the current page is a geodirectory listing detail page without specifying the url?
Thanks for the suggestion but I’m not sure that would work since I can’t specify a specific url to redirect from. I rather want it to redirect on every listing detail page and since I have lots of them (and they’re created by users) I can’t specify each one.
Thanks Alex
I’m using the following code (found here https://userswp.io/support/topic/restrict-users-from-seeing-each-others-profiles/) to restrict access to only allow users to view their own profile.
function _uwp_custom_profile_access( $access, $user ) { if ( ! ( current_user_can('manage_options') || ( !empty( $user ) && get_current_user_id() == $user->ID ) ) ) { $access = false; } return $access; } add_filter( 'uwp_profile_access', '_uwp_custom_profile_access', 10, 2 ); function _uwp_custom_profile_access_denied( $user ) { ?> <div><p><?php echo __( 'You are not allowed to view this profile!' ); ?></p></div> <?php } add_action( 'uwp_profile_access_denied', '_uwp_custom_profile_access_denied', 10, 1 );
I was wondering if there are hooks equivalent to _uwp_profile_access and _uwp_profile_access_denied that I can use to restrict listing pages in a similar way?
Hi Kiran, I’ve just got it to work using this:
add_action('geodir_after_save_listing', 'change_user_role_when_submit_cv'); function change_user_role_when_submit_cv( $last_post_id, $request_info ) { if (geodir_get_current_posttype() == 'gd_cv') { $current_user = wp_get_current_user(); $current_user_roles = $current_user->roles; if (in_array('um_worker', $current_user_roles)){ $current_user->set_role( 'worker_has_cv' ); } } }
Thanks for your help with this 🙂
Hi Dirk, yes, the post_type is ‘gd_cv’. You can see it in the JSON file here under “type” http://www.barn-door.co.uk/wp-json/geodir/v1/cvs.
Thanks Dirk, I’ve changed it to that and it’s still not working. If I remove the if statement completely it works, so it must be a problem with getting the post type.
-
AuthorPosts