ole1986 / wp-ispconfig3

Wordpress ISPConfig plugin with Gutenberg support
https://wordpress.org/plugins/wp-ispconfig3/
28 stars 13 forks source link

Make use of Gutenberg blocks #20

Closed ole1986 closed 5 years ago

ole1986 commented 5 years ago

While I have already started in branch wp-blocks to include gutenberg blocks I am actually struggling with the concept on how to deal with all the possible fields available in ISPConfig3

Would be good to have you involved @MachineITSvcs. So, that I know in which situation you have used your implemented method Ispconfig->UpdClient([...])

MachineITSvcs commented 5 years ago

The UpdClient function is used in the example cancelled method, and can also be used for switching master templates, updating passwords, limits, etc. Maybe utilize it on a form (for logged in users) that either creates or updates the ISPConfig user account by the same name as the WordPress username, depending on whether or not the user already exists. I would recommend providing this function only when a username is gathered automatically to avoid an existing user from being updated by someone else. I assume you’re turning this into some kind of form builder? I’m unable to look at the code presently, but if that is correct, then I recommend only utilizing that function when the username field does not exist in the form. I will look at the branch later today.

ole1986 commented 5 years ago

To update (or manage) ISPconfig users based on their wordpress login I was more thinking of a small plugin, the developer can create for each action individually

Currently wp-blocks branch supports the following actions (but this may change):

Below would be a working example plugin

<?php
/*
Plugin Name: Ispconfig client2user
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: Always overwrite the ISPConfig client id to its logged in wp_user.
Version: 1.0
Author: ole1986
License: GPL2
*/

add_filter('ispconfig_block_action_update_client', function($fields) {

    $user = wp_get_current_user();

    array_walk($fields, function(&$item) use($user) {
        if($item['id'] == 'client_username') $item['value'] = $user->user_login;
    });

    return $fields;
});

This will overwrite the "action" known as "Update client" (may change in future) to always use the logged in account.

There will be other actions available of course (E.g. "Update bank details") which can easily be included through the add_filter callback.

And even more, it could overwrite the default values (being set by the gutenberg block) from different sources.

ole1986 commented 5 years ago

@MachineITSvcs I have updated the wp-blocks branch so, that I could actually get rid of the shortcodes (including the "canceled" one).

It would be really helpful you can test it and let me know what you think about it. Please note that this is still not release and errors/problems may occur.

Thank you in advanced

MachineITSvcs commented 5 years ago

After re-reading your previous message, I noticed you said you may change the Client Update function in the future to always use the logged in user. How I currently use this function is to detect on web hosting (subscription checkout) if the client already exists and update it if necessary. This also runs on every recurring payment, and the canceled method is used when a payment is failed or subscription canceled. So using the logged in user would not be a good idea, as the username needs to be able to get passed into the function on a backend recurring payment for example.

ole1986 commented 5 years ago

Well, the action/filter hook can actually be used to overwrite the username and other fields dependent on the action being used.

The only difficulty I see now from your last comment, is that you are using such Shortcodes to immediately call an ISPconfig soap action instead of waiting for a user input. Is this correct?!

Can you explain how you trigger the shortcode in recurring payments

MachineITSvcs commented 5 years ago

That is correct. This is how I’ve always done it, but I also have another custom method besides canceled for this purpose. Would you like me to include both here as examples? They are fairly basic.

MachineITSvcs commented 5 years ago

I would prefer to email you the code actually

MachineITSvcs commented 5 years ago

They have been sent.

ole1986 commented 5 years ago

I have improved the use of custom shortcode classes, allowing you to put the files outside of the wp-ispconfig3 plugin.

Check out this wiki page on how to upgrade and implement for version 1.4.0

ole1986 commented 5 years ago

@MachineITSvcs I am planning to release this version soon. Does the changes fit to your needs?