Make Appointments+ Plugin viewable to non admin Roles

Hi

I'd like the appointments+ plugin to be viewable in the back end to non admin roles. Ie the editor role. I can them have some key users who can make changes for me but I can restrict their access to other plugins

Is this possible please

Kind Regards
Kieran

    Adam Czajczyk

    Hello Kieran,

    I hope you're well today and thank you for your question!

    It is possible to make Appointments+ backend available (entire or parts of it) to selected user-roles. It's a "per user role" setting.

    In order to make use of it please first go to "Appointments -> Settings -> Add-ons" page and activate "Administrative Permissions" add-on. Once it's activated, you'll find access settings on "Appointments -> Settings [page] -> General -> Advanced [tab]" where you can decide which user role can do what.

    I hope that helps!

    Best regards,
    Adam

    Kieran

    Hi Adam

    That seems to have worked great. thank you.

    Would it be possible to take it one step further and only show appointments which are filtered by certain service providers. So for instance service providers could only see their own appointments. The main reason is although at the minute service providers can book in their own appointments they can't edit them and it's a really key feature for me

    Kind Regards
    Kieran

    Adam Czajczyk

    Hello Kieran!

    The suggested add-on doesn't work on "per-user" and/or "per service provider" base so it wouldn't work that way. However, a workaround would be to use User Role Editor plugin in addition:

    - duplicate one of the default WP user roles using User Role Editor, giving it a new name
    - assign this role to all the WP accounts that are service providers
    - use Appointments+ "Administrative Permissions" settings to grant editing capability to that new role

    This should do the trick. Let me know please if it worked for you!

    Best regards,
    Adam

    Kieran

    Hi Adam

    All my service providers are set to "Editors" I can set a new WP user role but I'm not really seeing the point of doing so see as they are all "Editors" anyway.

    I can't see from your instructions how each of my service providers would only see their own appointments? I have it working so they only see the Appointments page and can create new appointments but they can all see each others at the minute which is not what I want

    Cheers
    Kieran

    Milan

    Hello Kieran

    Hope you are well today and won't mind me chiming here.

    Unfortunately there isn't any option for displaying only service provider's appointment. But I've flagged our SLS guys for this. If there is any possible solution for this one, they will surely provide you here.

    Please also note that responses of our SLS guys are bit slower than usual support staff here. We appreciate your patience here.

    Kind Regards,
    Milan

    Milan

    Kieran

    Thanks for sharing your views on this.

    Hopefully this will have solution and our SLS staff provide you one. Please note also that its not guaranteed that solution will be there for your this requirement. But our SLS ( Second Line Support ) guys will take a look at your setup and provide you one if its possible anyhow.

    Please wait for our reply here.
    Kind Regards,
    Milan

    Panos

    Hi Kieran ,

    As Milan has already mentioned the plugin doesn't support this functionality.

    The easiest way would be to use the following workaround:

    First, I would recommend to follow Adam's suggestion and use the Administrative Permissions where you can set the editors ( since your service providers are editors ) to have access to Appointments so they can see the list.

    Then add the following snippet in your child theme's functions.php file (or in a custom plugin or even a MU plugin):
    '
    function wpmudev_set_workerlist_page() {

    if( !is_admin() ) return;

    $user_id = get_current_user_id();

    if( !appointments_is_worker( $user_id ) || current_user_can( 'manage_options' ) ) return;

    if( isset( $_GET['page'] ) && $_GET['page'] == 'appointments' && ( !isset( $_GET['app_provider_id'] ) || $_GET['app_provider_id'] != $user_id ) ){
    $full_url = wpmudev_full_url( $_SERVER );
    wp_redirect( $full_url . '&app_provider_id=' . $user_id );
    }

    return;

    }

    add_action( 'wp_loaded', 'wpmudev_set_workerlist_page' );

    function wpmudev_url_origin( $s, $use_forwarded_host = false )
    {
    $ssl = ( ! empty( $s['HTTPS'] ) && $s['HTTPS'] == 'on' );
    $sp = strtolower( $s['SERVER_PROTOCOL'] );
    $protocol = substr( $sp, 0, strpos( $sp, '/' ) ) . ( ( $ssl ) ? 's' : '' );
    $port = $s['SERVER_PORT'];
    $port = ( ( ! $ssl && $port=='80' ) || ( $ssl && $port=='443' ) ) ? '' : ':'.$port;
    $host = ( $use_forwarded_host && isset( $s['HTTP_X_FORWARDED_HOST'] ) ) ? $s['HTTP_X_FORWARDED_HOST'] : ( isset( $s['HTTP_HOST'] ) ? $s['HTTP_HOST'] : null );
    $host = isset( $host ) ? $host : $s['SERVER_NAME'] . $port;
    return $protocol . '://' . $host;
    }

    function wpmudev_full_url( $s, $use_forwarded_host = false )
    {
    return wpmudev_url_origin( $s, $use_forwarded_host ) . $s['REQUEST_URI'];
    }
    `

    The above snippet makes sure that when a user is a Service Provider he will only have access to his own appointments.

    I hope you find this helpful

    Thanks!
    Panos

    Kieran

    Hi Panos

    Thanks for the help here it's much appreciate. I'd REALLY like to get this working.

    Unfortunately when I create an MU PLugin for the above. I get the follwing error

    ' function wpmudev_set_workerlist_page() { if( !is_admin() ) return; $user_id = get_current_user_id(); if( !appointments_is_worker( $user_id ) || current_user_can( 'manage_options' ) ) return; if( isset( $_GET['page'] ) && $_GET['page'] == 'appointments' && ( !isset( $_GET['app_provider_id'] ) || $_GET['app_provider_id'] != $user_id ) ){ $full_url = wpmudev_full_url( $_SERVER ); wp_redirect( $full_url . '&app_provider_id=' . $user_id ); } return; } add_action( 'wp_loaded', 'wpmudev_set_workerlist_page' ); function wpmudev_url_origin( $s, $use_forwarded_host = false ) { $ssl = ( ! empty( $s['HTTPS'] ) && $s['HTTPS'] == 'on' ); $sp = strtolower( $s['SERVER_PROTOCOL'] ); $protocol = substr( $sp, 0, strpos( $sp, '/' ) ) . ( ( $ssl ) ? 's' : '' ); $port = $s['SERVER_PORT']; $port = ( ( ! $ssl && $port=='80' ) || ( $ssl && $port=='443' ) ) ? '' : ':'.$port; $host = ( $use_forwarded_host && isset( $s['HTTP_X_FORWARDED_HOST'] ) ) ? $s['HTTP_X_FORWARDED_HOST'] : ( isset( $s['HTTP_HOST'] ) ? $s['HTTP_HOST'] : null ); $host = isset( $host ) ? $host : $s['SERVER_NAME'] . $port; return $protocol . '://' . $host; } function wpmudev_full_url( $s, $use_forwarded_host = false ) { return wpmudev_url_origin( $s, $use_forwarded_host ) . $s['REQUEST_URI']; }
    Warning: Cannot modify header information - headers already sent by (output started at /var/sites/t/treatmeathome.com/public_html/wp-content/mu-plugins/service_provider_security_settings.php:37) in /var/sites/t/treatmeathome.com/public_html/wp-includes/pluggable.php on line 117`

    Adam Czajczyk

    Hello Kieran!

    I see that the code Panos provided you with somehow got scrambled in a post. I checked that and here's a fixed version, already ready to be used as a "MU plugin":

    <?php 
    
    function wpmudev_set_workerlist_page() {
    
    	if( !is_admin() ) return;
    
    	$user_id = get_current_user_id();
    
    	if( !appointments_is_worker( $user_id ) || current_user_can( 'manage_options' ) ) return;
    
    	if( isset( $_GET['page'] ) && $_GET['page'] == 'appointments' && ( !isset( $_GET['app_provider_id'] ) || $_GET['app_provider_id'] != $user_id ) ){
    		$full_url = wpmudev_full_url( $_SERVER );
    		wp_redirect( $full_url . '&app_provider_id=' . $user_id );
    	}
    
    	return;
    
    }
    
    add_action( 'wp_loaded', 'wpmudev_set_workerlist_page' );
    
    function wpmudev_url_origin( $s, $use_forwarded_host = false ) {
    	$ssl = ( ! empty( $s['HTTPS'] ) && $s['HTTPS'] == 'on' );
    	$sp = strtolower( $s['SERVER_PROTOCOL'] );
    	$protocol = substr( $sp, 0, strpos( $sp, '/' ) ) . ( ( $ssl ) ? 's' : '' );
    	$port = $s['SERVER_PORT'];
    	$port = ( ( ! $ssl && $port=='80' ) || ( $ssl && $port=='443' ) ) ? '' : ':'.$port;
    	$host = ( $use_forwarded_host && isset( $s['HTTP_X_FORWARDED_HOST'] ) ) ? $s['HTTP_X_FORWARDED_HOST'] : ( isset( $s['HTTP_HOST'] ) ? $s['HTTP_HOST'] : null );
    	$host = isset( $host ) ? $host : $s['SERVER_NAME'] . $port;
    	return $protocol . '://' . $host;
    }
    
    function wpmudev_full_url( $s, $use_forwarded_host = false ) {
    	return wpmudev_url_origin( $s, $use_forwarded_host ) . $s['REQUEST_URI'];
    }

    To use it as a "MU plugin" simply copy and paste the code into an empty file with a ".php" extension and upload it to the "/wp-content/mu-plugins" folder on your server. Don't forget to remove that previous code that's causing errors first, please

    I hope that helps!
    Best regards,
    Adam

    Kieran

    Hi Adam

    Thanks for the updated code. Superb it's now filtering correctly.

    Just one final point on the page If i direct my service provider to
    http://mysite.com.com/wp-admin/profile.php

    This shows them their user name, details, working hours etc. Everything looks fine except when you get to the "Appointments +: My Appointments as Provider"

    I would expect this to just show the service providers appointments but it's showing them all. I dont think this is related to the code above but feels like a bug? Welcome your thoughts

    I'd like this bit to filter correctly so my Service Providers can also set their own working hours unless I can somehow get it working another way.

    Happy to raise a seperate thread if required.

    Kind Regards
    Kieran

    Panos

    Hi Kieran ,

    It seems like a bug you spotted there

    Good job

    I have attached file
    wp-content/plugins/appointments/includes/shortcodes/class-app-shortcode-my-appointments.php
    for you to replace which should fix this issue. Please download the file and decompress/unzip it before you upload it. Also keep a backup of the previous file before replacing.

    I have reported this to developer so it should be taken care of in next update!

    I am also sending some points your way to show our appreciation to your feedback

    Thanks!
    Panos

    Kieran

    Hi Panos,

    Thanks for the Class-app-shortcode. I can confirm when installing it now works great! I can see it's only 1 line of code alteration. I can edit myself going forward but be nice to get this fix in for future versions if possible? It obviously never made it to version 1.91

    Thank you so much for the code though its a massive improvement for me. Only downside is the code you provided for an MU plugin doesn't work with the latest version of Appointments+ 1.91. It errors on line 9 which is

    'if( !appointments_is_worker( $user_id ) || current_user_can( 'manage_options' ) ) return;'

    Working fine on 1.90 so would appreciate any code update you might be able to provide

    Thanks
    Kieran

    Panos

    Hi Kieran ,

    Just checked in my installation and don't get any error, also checked for this specific function and still exists in plugin.

    Do you have debug enabled? Please add the following at your wp-config.php file :

    define('WP_DEBUG', true);
    define( 'WP_DEBUG_LOG', true );
    define( 'WP_DEBUG_DISPLAY', false );

    if you have
    define('WP_DEBUG', false);
    you can replace it with the above.

    Please make sure you paste these lines before the one that contains the following sentence:
    /* That's all, stop editing! Happy blogging. */

    Once you have enabled debugging repeat once and then open file wp-content/debug.log and let us know about the error message regarding that specific line!

    Thanks!
    Panos

    Panos

    Hi Kieran ,

    whilst logged in as a service provider if only exports the relevant service provider appointments?

    Could you please try adding the following snipped in your functions.php or a mu-plugin:

    add_filter( 'app-export-appointment', 'wpmudev_app_export_appointment', 10, 2 );
    
    function wpmudev_app_export_appointment($app , $raw){
    
    	if( !is_admin() ) return;
    
    	if( current_user_can( 'manage_options' ) ) return $app;
    
    	$user_data = get_userdata( get_current_user_id() );
    
    	if( $app->worker != $user_data->display_name ) return;
    
    	return $app;
    
    }

    Thanks!
    Panos

    Kieran

    Hi Panos,

    I can confirm it's all working now on my test and main site. I did get the same error message again as mentioned above but once I'd copied over my usual code changes it started working again. So maybe there is a slight conflict with some of the default plugin code I'm not so sure. It seems ok so far and will post again if I have any other issues.

    So many thanks for all your efforts. Fingers crossed it stays working on each plugin upgrade. I'll mark this as resolved now

    The only thing left would be to get this code working in the main plugin if possible as I think most users would like it

    Kind Regards
    Kieran

    Panos

    Hi Kieran ,

    There have been some changes in Appointments plugin so the code provide previously is not working any more.

    I have prepared a custom plugin which you can download from here:
    https://gist.github.com/panoslyrakis/825e2d6c6c191b9c5427a4b9462868a8

    It should provide a new admin menu for Service Providers which contains a list of their appointments categorized by status, with an option to change the status.

    Hope this helps

    Cheers!