Hey there ??
Quick one: app_old is the legacy version of the plugin, this folder will be removed in the next few weeks. If you use the new layout then this folder is not used (you can even delete app_old on your site)
The other part:
To use the M2 API module, you simply need to make sure that WordPress is fully loaded. You cannot include the plugins PHP files in a non-WordPress system to access memberships.
To do what you want I suggest to write a small custom plugin that listens to specific ajax requests, then your cron-job can send the user-details to the WordPress ajax handler, i.e. to “/wp-admin/admin-ajax.php”
I hope the following, simple and untested example helps you to get moving in the right direction ??
Thanks, Philipp
<?php
/**
* WP Plugin header...
*
* You can use this example by calling an URL like this:
* your-wp-url.com/wp-admin/admin-ajax?action=crm_sync&data={"do":"add","email":"[email protected]","membership":"Kennziffer"}
*/
// Listen to the Ajax action 'crm_sync'
add_action( 'wp_ajax_nopriv_crm_sync', 'crm_sync' );
// Callback for the ajax action, at this point WP is already loaded, so we can use M2 API.
function crm_sync() {
$data = json_decode( $_GET['data'] );
$api = ms_api();
if ( 'add' == $data['do'] ) {
// Find the user-ID from the email; if user does not exist create him.
$user = get_user_by( 'email', $data['email'] );
if ( $user ) {
$user_id = $user->ID;
} else {
$user_id = wp_create_user( $data['email'], 'password', $data['email'] );
}
// Get the M2 Member-object from the user-ID.
$member = $api->get_member( $user_id );
// Get the membership-ID from the membership name.
$membership_id = $api->get_membership_id( $data['membership'] );
// Assign the membership to the user.
$member->add_membership( $membership_id );
}
elseif ( 'del' == $data['do'] ) {
// ...
}
elseif ( 'update' == $data['do'] ) {
// ...
}
}