• We value your experience with Plesk during 2024
    Plesk strives to perform even better in 2025. To help us improve further, please answer a few questions about your experience with Plesk Obsidian 2024.
    Please take this short survey:

    https://pt-research.typeform.com/to/AmZvSXkx
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Wordpress toolkit: change default wp-config-settings?

Martin_Sauer

Regular Pleskian
Is there a way to change wordpress toolkit wp-config-settings for a new installation by default?

Also: how can I set Wordpress toolkit to configure sql-socket connection instead of TCP connections?

TIA
 
Thank you for interest but I would like to know your desired scenarios first. Could you describe in more details why do you need these customizations?
 
Thank you for interest but I would like to know your desired scenarios first. Could you describe in more details why do you need these customizations?

Hi Igor,

wow, cool to see you here - again. Always a pleasure.

-- scenario --
Wordpress hosting - customers/resellers build their own Wordpress environments on demand. In my case it is an extremely fast Wordpress environment, where soon the following adjustments are needed (and I didnt dive into how to apply which yet):
- socket instead of tcp database connection (plain for speed and in a second step to assign redis-MariaDB wrapper)
- install 4 plugins of my choosing on each default WP install, activate them and configure them (ideally I could mass-assign even changing of configuration to new and already installed WP sites)
- deactivate WP-cron, use CRON instead
- ...
-- /scenario --

Some of these changes are easily done by WP-CLI, yet that is imho already too late. I would prefer to apply these changes already right upon installation, before the site is first available.

Add2: Sorry but since I already got your attention :D - Can you point me somewhere, where I can start to modify Plesk GUI (eg add a radio button for nginx/Apache config? Remove some items from customer/reseller view and disable them for their use? Add a checkbox to apply a nginx/apache vhost template? Increase the values and add more options on php configuration_/limits per customer/reseller?)

TIA

Martin
 
Last edited:
Yes.
Took 2 years and no support from staff to get an answer to this. More than happy to necro the thread w/ all possible inherent disdain insinuated.
I'll hold my tongue... as best I can.


Tools & Settings -> Event Manager -> Add Event Handler -> Event = "Wordpress Installed".
Then after googling you can arrive to some documentation on the event we want.

So you can run your command right there. Or follow their guide on proper scripts.
In my case, I am hosted on windows, but you could probably use sed on linux to regex replace.
powershell -file C:\inetpub\AdminScripts\plesk\force_ssl_if_proxied.ps1 "<NEW_INSTALLATION_PATH>"

And a sample script utilizing the passed install path: force_ssl_if_proxied.ps1
Code:
param(
  [string]$Path
)

$CRLF = "`n";
$target = $Path+'\wp-config.php';

$find="Happy blogging. */"; # text present in all wp-config
$add_code="if (!empty(`$_SERVER['HTTP_X_FORWARDED_PROTO']) && `$_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
    `$_SERVER['HTTPS'] = 'on';
}";

$str = [System.IO.File]::ReadAllText($target);
$str = $str.Replace($find, $find + $CRLF + $CRLF + $add_code + $CRLF);
[System.IO.File]::WriteAllText($target, $str);

However sadly that fails, because apparently the wp toolkit event only passes the relative path, which excludes the full path, and also excludes parent folder if it's a subdomain. Not sure how that could ever be useful to anyone. Cool...

So we must switch to some proper php code to avoid messy shell scripts and give ourselves some better intel:
  • as per event handler class guide - drop the below php into a file in your install folder as they described
  • and as per some discovery code I wrote for potential events in wordpress toolkit which is ENTIRELY undocumented:
    • ext_wp-toolkit_uninstall
    • ext_wp-toolkit_install
  • And per lot's of online samples from github scripts for plesk, the following is born...
PHP:
<?php
use PleskExt\DomainConnect\DomainConnect;
class Modules_WordpressToolkit_EventListener implements EventListener {
    public function filterActions() {
        return [
            'ext_wp-toolkit_install',
        ];
    }

    public function handleEvent($objectType, $objectId, $action, $oldValues, $newValues) {
        if ($action == 'ext_wp-toolkit_install') {
            $domain = \pm_Domain::getByGuid($newValues["Domain GUID"]);//getByDomainId($objectId);
            if ($domain!=null && $domain->hasHosting()) {
                $doc_root = $domain->getDocumentRoot();
                $target = $doc_root."\\wp-config.php";
                
                $find = "Happy blogging. */";
                $add_code = "if (!empty(\$_SERVER['HTTP_X_FORWARDED_PROTO']) && \$_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {\r\n\t\$_SERVER['HTTPS'] = 'on';\r\n}";
                
                $wpc = file_get_contents($target);
                $wpc = str_replace($find, $find."\r\n".$add_code."\r\n", $wpc);
                file_put_contents($target, $wpc);
            }
        }
    }
}

return new Modules_WordpressToolkit_EventListener();
?>

However since the php EventListener code runs as [psaadm] , it does not have rights to write to the file, and fails again.
Since the file can be owned & granted to the domain/customer/subscription.
For me the solution was the decision to apply inherited permissions at the VHost folder level, which already had [psaadm] on it.
Just switched from "This Folder Only"to "This folder, subfolders, and files". and changed from Deny to Allow.
I'm sure that's a security risk for some reason (plesk , do you care to follow up on that question?).
But I see no alternative, other than maybe chaining executions of the above two scripts (either via php exec & runas, or plesk api to execute a custom event), to run the powershell script elevated.

And that folks is how you perform modifications to wordpress using the ever-lovely Wordpress Toolkit Extension.
Hope this helps someone save 3 hours of their life.

p.s. .. perhaps an alternative approach would be to simply modify plesk's temporary zip file of Wordpress which it downloads for future installs. And hope that plesk doesn't have an sha checksum running against it.
 
p.s. after discovering issues with permissions, do not change vhosts folder perms like i said above (via windows dialog).
Instead follow the guide for assigning folder permissions, using:
XML:
<?xml version="1.0" encoding="utf-8" ?>
<Entries>
    <Entry AccounType="1" Account="Psaadm" Path="[HTTPD_VHOSTS_D]" AceFlags="ThisFolderSubfoldersAndFiles" AccessMask="FullAccess" EntryFlags="0" />
</Entries>

Can confirm above php works fine with that. However the repair utility plesk repair fs, does not detect it unless you break the perms on disk. Little bit finicky to get it to reapply all the perms. And note that existing sites will not get the inherited perms of parent folder (windows issue/thing). Works for new subscriptions or root customers only. Then all subdomains etc work.

Anyway, i sorted the issue for myself, good day to he/she who reads.
P.s. Still not sure if granting psaadm full control on vhosts is wise. Need a plesk expert to answer that.
 
  1. Connection to database depends on how it is connected by Plesk; By default, it is connected via TCP. If you connect (in any way) through a socket - for WordPress it will be connected in the same way;
  2. Mass installation can be done through sets. But there is no default set;
  3. The ability to disable wp-cron was added in WPT 4.7.0 Users can enable a switch on each site, disabling wp-cron execution. This will also create a scheduled task in Plesk which you can modify to change the execution frequency.
 

Attachments

  • image.png
    image.png
    46 KB · Views: 9
  1. Connection to database depends on how it is connected by Plesk; By default, it is connected via TCP. If you connect (in any way) through a socket - for WordPress it will be connected in the same way;
  2. Mass installation can be done through sets. But there is no default set;
  3. The ability to disable wp-cron was added in WPT 4.7.0 Users can enable a switch on each site, disabling wp-cron execution. This will also create a scheduled task in Plesk which you can modify to change the execution frequency.
@IgorG Any chance to add custom Wordpress changes to wp-config.php ? Disable wp-cron already is a wp-config.php change.

Enabling custom wp-config changes would be the last tidbit of coolness :)
 
@IgorG Out of curiosity, would it be possible for you (or another) to grant me read-only source control access to the WordPress Toolkit repo source?
I'd be more than happy to sign a confidentiality agreement and any legal/contractual documents you require.
I do not wish for recognition, nor payment, or anything else - ala "pro bono".
I just want to improve this for myself and everyone.
Namely:
  • Additional powershell argument providing full disk path (since a generic script cannot know what domain/subdomain it's meant to operate on)
  • Ability to specify regex rules for string replacement within wp-config.php on install, and/or template files for the user to supply.
If that is possible (to grant me access), I'd be happy to get in touch more officially with my real identity, resume, everything.
Just want to fix this and provide you with a diff or pull request for your team to consider.
If viable, please let me know how best to pursue this further, thank you! I remain hopeful at this moment.
 
Back
Top