But Employee's can have an associated WordPress account so somewhere that must be stored next to an Employee ID otherwise how would it know which WordPress user is associated to it?
We want the correct calendar to display on the users profile without our admin or the user having to manually add the correct shortcode or even see the shortcode for that matter. It's a user experience need to make the the displaying of an employees calendar automatic and just one bit of code that dynamically displays the correct one their profile.
We're trying to get Amelia to work and appear seamlessly with BuddyPress (well actually BuddyBoss) as currently we feel Amelia is the most comprehensive and user friendly booking system out there but it's too separated from WordPress user accounts. There is also no booking plugin for BuddyPress/Boss which is a huge gap in the market in my opinion.
I want to be careful here to not make it look like I'm asking for some custom code and digging beyond the realms of your support. I can see in the table amelia_users we have a 'provider' and there is a column externalID which is the WordPress user ID it's linked to.
Amelia's Employees have their own ID's, as you know. If they are linked with a WordPress user, that user ID is stored in wp_amelia_users, under "externalId" column.
Amelia can see its own employee IDs, but it cannot find it based on WordPress user and/or ID, so you would need to use Amelia Employee's IDs.
If you are able to use Amelia's employee IDs, you could achieve this with the help of some plugin that has the possibility to use PHP Snippets, and add shortcodes on the page in that way. For example:
1. There's the page (where you want the booking form to be), and when you're creating links that lead to that page, in URL you need to place the ID for the employee (http://somesite/booking?employee=17)
2. On that page (where you want the booking form to be), instead of our shortcode, you'd need to add the shortcode of that plugin which uses PHP Snippet which will generate our shortcode (https://wordpress.org/plugins/insert-php-code-snippet/).
Linking the user's WordPress ID would have to be done as a custom solution, and unfortunately, we don't have any examples that would help you achieve this.
I found that I also needed a way to match employees to users, as the only way I could see to add meta information to providers, with tools that are currently available, is to add the custom meta to the `WP_User`, and then find the user by the provider ID.
For my integration, I ended up using a database query to obtain the necessary information:
$user_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT externalId FROM {$wpdb->prefix}amelia_users WHERE id = %s", $provider_id ) );
Of course, for Dan's original query, you could just as easily reverse the column names in the SQL statement, in order to find the employee from the user:
$provider_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$wpdb->prefix}amelia_users WHERE externalId = %s", $user_id ) );
I feel that some form of constructor, factory, or internal API, such as how we can use `get_user_by()` to get the `WP_User` object, would be beneficial. My suggestion would be for a new class to be created with a number of static functions for finding providers, or maybe an Employee class which can be used to read user meta. This way, if the table names or columns change in future, it won't immediately break legacy installations.
namespace AmeliaBooking;
class ProviderAPI {
const USERS_TABLE = 'amelia_users';
public static function get_id_from_user( $user_id ) {
global $wpdb;
$users_table = static::USERS_TABLE;
return (int) $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$wpdb->prefix}{$users_table} WHERE externalId = %s", $user_id ) );
}
}
$provider_id = \AmeliaBooking\ProviderAPI::get_id_from_user( $user_id );
Please us me know your thoughts, if you have any further suggestions or if you are able to provide documentation for features like this if they already exist.
I need to implent this great solution on my WP website... (Exactly the same issue) (I am a noob on WP!) In what file I have to add "class ProviderAPI" ? Using Snippet ? in functions.php ? ... How do I call this function on my user page ? with a shortcode ? Thanks a lot for your reply Emmanuel
The ProviderAPI class is only really necessary if you want to organise your functions into classes, otherwise you can easily just use the second snippet I gave in your author.php template for the same result. You just need to make sure that you call "global $wpdb;" before it.
If you still want to use the ProviderAPI class, then it should go into a new file in your theme, for example you could use the filename; /wp-content/themes/YOUR_THEME/includes/ameliabooking/providerapi.php
You would then move the last line from that snippet into your author.php template where you need to access $provider_id, and then on the line above it, you can include the providerapi.php file.
require_once( get_theme_file_path( 'includes/ameliabooking/providerapi.php' ) );
$provider_id = \AmeliaBooking\ProviderAPI::get_id_from_user( $user_id );
// Do stuff with $provider_id.
Amelia updates are why we need an API as part of the plug-in, to account for breaking changes such as this. I won't be able to confirm what the issue is, so best to wait for someone from Amelia to answer.
From what we can see, you're fetching Amelia's ameliaUser Id with WP User ID with SQL query that looks good. We haven't changed the code, so can you please share the page with us and we'll gladly take a look?
I used [WPUserBooking] before the update but after update ... it was not working any more:
add_shortcode("WPUserBooking","Booking4wpID");
function Booking4wpID(){
// Test si User loggé $user = wp_get_current_user();
$aa = $user->exists();
// récupère ID UM
$user_id = um_profile_id();
$provider_id = \AmeliaBooking\ProviderAPI::get_id_from_user( $user_id );
if ($aa == 1) {
$value = "[ameliabooking employee=$provider_id]";
} else {
$value = "<H3> Connectez-vous pour prendre RdV</H3>";
}
return $value;
}
So I used SQL to find my info :
add_shortcode("WPUserID","Booking4wpIDsql");
function Booking4wpIDsql(){
//On établit la connexion $servername = "localhost"; $username = "xxxxxxx"; $password = "xxxxxxx"; $db = "MMP1"; $mysqli = new mysqli($servername, $username, $password, $db);
// ID du User de la page $user_id = um_profile_id(); $requete = "SELECT * FROM wp_amelia_users WHERE externalId=".$user_id; $resultat = $mysqli->query($requete); while ($ligne = $resultat->fetch_assoc()) { $value="[ameliabooking employee=".$ligne['id']."]"; } $mysqli->close(); return $value; }
1 - Could you tell me what is the best practice/what du you recon and what is the more reliable.
2 - I could you tell me what is wrong in API call in [WPUserBooking]
Sorry to keep you waiting, but you still haven't sent us the page where this is being used, so our developers can't take a look at the front-end and see the behavior.
Hello,
We would like to write a shortcode that displays an employees booking calendar on their BuddyPress profile page (the profile of an Amelia Employee).
1. We know that to display the correct calendar we need this shortcode: [ameliabooking employee=1] where 1 is the employee ID.
2. We know how to get the WordPress User ID of the profile page you are on: bp_displayed_user_id()
Are you able to provide any advice on how to get the Employer ID from a WordPress User ID please?
Many thanks!
Hi, Dan,
Thank you for choosing Amelia.
To be honest, I doubt that Employee IDs can be linked to the WP User IDs.
Could you please explain why using the Employee ID won't work for this solution?
Looking forward to hearing from you.
But Employee's can have an associated WordPress account so somewhere that must be stored next to an Employee ID otherwise how would it know which WordPress user is associated to it?
We want the correct calendar to display on the users profile without our admin or the user having to manually add the correct shortcode or even see the shortcode for that matter. It's a user experience need to make the the displaying of an employees calendar automatic and just one bit of code that dynamically displays the correct one their profile.
We're trying to get Amelia to work and appear seamlessly with BuddyPress (well actually BuddyBoss) as currently we feel Amelia is the most comprehensive and user friendly booking system out there but it's too separated from WordPress user accounts. There is also no booking plugin for BuddyPress/Boss which is a huge gap in the market in my opinion.
I want to be careful here to not make it look like I'm asking for some custom code and digging beyond the realms of your support. I can see in the table amelia_users we have a 'provider' and there is a column externalID which is the WordPress user ID it's linked to.
Is there an advised way to get this data?
Dan,
Thank you for the clarification.
Since Amelia Employee and WP User are linked through the email address, I'm not sure it can work this way.
However, I'm not a developer, so I will forward your question to our Level 2 Support, probably they will be able to help with that.
We will get back to you at the earliest possible time.
Hello Dan
Sorry for the late response.
Amelia's Employees have their own ID's, as you know. If they are linked with a WordPress user, that user ID is stored in wp_amelia_users, under "externalId" column.
Amelia can see its own employee IDs, but it cannot find it based on WordPress user and/or ID, so you would need to use Amelia Employee's IDs.
If you are able to use Amelia's employee IDs, you could achieve this with the help of some plugin that has the possibility to use PHP Snippets, and add shortcodes on the page in that way. For example:
1. There's the page (where you want the booking form to be), and when you're creating links that lead to that page, in URL you need to place the ID for the employee (http://somesite/booking?employee=17)
2. On that page (where you want the booking form to be), instead of our shortcode, you'd need to add the shortcode of that plugin which uses PHP Snippet which will generate our shortcode (https://wordpress.org/plugins/insert-php-code-snippet/).
3. The snippet would look something like this:
Linking the user's WordPress ID would have to be done as a custom solution, and unfortunately, we don't have any examples that would help you achieve this.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Hi Team,
I found that I also needed a way to match employees to users, as the only way I could see to add meta information to providers, with tools that are currently available, is to add the custom meta to the `WP_User`, and then find the user by the provider ID.
For my integration, I ended up using a database query to obtain the necessary information:
Of course, for Dan's original query, you could just as easily reverse the column names in the SQL statement, in order to find the employee from the user:
I feel that some form of constructor, factory, or internal API, such as how we can use `get_user_by()` to get the `WP_User` object, would be beneficial. My suggestion would be for a new class to be created with a number of static functions for finding providers, or maybe an Employee class which can be used to read user meta. This way, if the table names or columns change in future, it won't immediately break legacy installations.
Please us me know your thoughts, if you have any further suggestions or if you are able to provide documentation for features like this if they already exist.
Hey Shaun
Thank you for this! I forwarded the ticket to one of our developers, and as soon as I hear back from him I will let you know.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Just got a confirmation, Shaun, that this should work nicely. There's no additional tweak that you'd need to add for it to work.
So this method will use the WP user ID and match it with Amelia's Employee ID and change it dynamically on the page.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Thank you all so much, I'll pass this onto our developer!
You're welcome, Dan
If you have any further questions or issues, please feel free to open a new ticket, and we'll gladly help.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Bonjour,
I need to implent this great solution on my WP website... (Exactly the same issue) (I am a noob on WP!)
In what file I have to add "class ProviderAPI" ? Using Snippet ? in functions.php ? ...
How do I call this function on my user page ? with a shortcode ?
Thanks a lot for your reply
Emmanuel
Hi Emmanuel,
The ProviderAPI class is only really necessary if you want to organise your functions into classes, otherwise you can easily just use the second snippet I gave in your author.php template for the same result. You just need to make sure that you call "global $wpdb;" before it.
If you still want to use the ProviderAPI class, then it should go into a new file in your theme, for example you could use the filename; /wp-content/themes/YOUR_THEME/includes/ameliabooking/providerapi.php
You would then move the last line from that snippet into your author.php template where you need to access $provider_id, and then on the line above it, you can include the providerapi.php file.
Thanks a lot Shaun !!!
it works good !!!
Great to see the community helping each other! Thanks again Shaun.
Emmanuel, if you need some further assistance from us, please feel free to open a new ticket.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Bonjour,
After updating with 4.5.1, the shortcode doesn't work anymore... Does it a relative issue?
Thanks,
Emmanuel
/**
* Amelia booking for the current displayed Wordpress User
*/
add_shortcode("WPUserBooking","Booking4wpID");
function Booking4wpID(){
// Test si User loggé
$user = wp_get_current_user();
$aa = $user->exists();
// récupère ID UM
$user_id = um_profile_id();
// This is correct ????:
$provider_id = \AmeliaBooking\ProviderAPI::get_id_from_user( $user_id );
if ($aa == 1) {
$value = "[ameliabooking employee=$provider_id]";
} else {$value = "<H3> Connectez-vous pour prendre RdV</H3>";
}
return $value;
}
Amelia updates are why we need an API as part of the plug-in, to account for breaking changes such as this. I won't be able to confirm what the issue is, so best to wait for someone from Amelia to answer.
Hello all.
From what we can see, you're fetching Amelia's ameliaUser Id with WP User ID with SQL query that looks good. We haven't changed the code, so can you please share the page with us and we'll gladly take a look?
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Bonjour,
I used [WPUserBooking] before the update but after update ... it was not working any more:
So I used SQL to find my info :
1 - Could you tell me what is the best practice/what du you recon and what is the more reliable.
2 - I could you tell me what is wrong in API call in [WPUserBooking]
With best regards,
Emmanuel
Thank you Emmanuel, but can you also please share the page with us?
I did return this ticket to our developers, so if there's anything they can advise based on this, I'll get back to you in the meantime.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Hello again Emmanuel
Sorry to keep you waiting, but you still haven't sent us the page where this is being used, so our developers can't take a look at the front-end and see the behavior.
Can you send me the front-end page?
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Bonjour Aleksandar,
I worked around with a sql request instead of an API call...
Do you think it is a good practice?
Thanks again.
Emmanuel
Hi again Emmanuel
Sure, if it works, I don't see why not. I'll check with our developers, but I believe this is fine.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Hi again Emmanuel.
Our developers advised using a prepared statement, but otherwise, it looks OK.
This is the code that we use in one of our functions, adjusted for your variables:
Also could be in a try-catch block. The code you used before looks fine and should work. The only thing that's a little weird is this:
Not sure if PHP will recognize it correctly. Maybe try this:
or
Do you see any errors when you test that function? Does it print out the message Connectez-vous pour prendre RdV?
Kind regards!
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables