Filters

From Softaculous Wiki
Jump to: navigation, search

Overview

Filters enable the admin to modify/hook into certain aspects of the task being done. There are several Filters in Softaculous that you can take advantage of.

Note : Filters have been added since Softaculous version 4.7.9

The following guide will show you how the Server Admin can configure Filter Functions to customize the installation, upgrade, email and several other events.

  • SSH to your server and go to the following path:
/path/to/softaculous/enduser/hooks/
  • You can see the file filter.txt.
  • Rename the file to make it a PHP file as filter.php.
  • Uncomment the function that matches your requirement, add the code inside the function as per your requirements and save the file.
  • That's it you have configured your filter.


insert_filter

  • We make use of insert_filter function to trigger a specific filter.
insert_filter(string $tag, string $function_to_add, int $priority, int $accepted_args);

Parameters

Param Type Description
$tag string/Required Action name that triggers the specific function.
$function_to_add string/Required Name of the function to be triggered.
$priority int/optional Priority in which you want the filter to be triggered. (Default is 10)
$accepted_args int/optional Number of arguments accepted by the filter function. (Default is 1)

Example
Following is the example describing how a filter is triggered by an action:

If you would like to make some changes whenever an error is triggered in Softaculous, you will have to rename the file filter.txt to filter.php and uncomment the following part and add the code in my_error_handle() function.

insert_filter('error_handle', 'my_error_handle', 1, 1);

function my_error_handle($error){
     // Add your custom code here
}

insert_filter adds the data added by you to Softaculous and when the appropriate event is triggered your respective function is called. For eg., in the above example, whenever the event error_handle occurs, function my_error_handle is called and the code inside the same is executed.


pre_install

Description
The pre_install filter will trigger your function before the installation process for any script is started.

Usage
Uncomment the following part inside filter.php and add your code inside the function my_pre_install:

insert_filter('pre_install', 'my_pre_install', 1);

function my_pre_install(){
	global $soft, $software, $globals;
	
	// Do stuff here e.g. is as follows
	if($soft == 26){ 
		//Do things only if its WordPress 
	}
	
}


post_install

Description
The post_install filter will trigger your function after a script is installed.

Parameters

Key Value Description
$installation array/Required Contains details of the installation.
 Array
 (
       [insid] => installation id
       [sid] => script id
       [ver] => installed version of script
       [itime] => installation time
       [softpath] => path to installation
       [softurl] => installation URL
       [softdb] => database name of installation
       [softdbuser] => database user of installation
       [softdbhost] => database host of installation
       [softdbpass] => database password of installation
 )

Usage
Uncomment the following part inside filter.php and add your code inside the function my_post_install:

insert_filter('post_install', 'my_post_install', 1, 1);

// @param	array $installation Details of the new installation
function my_post_install($installation){
	global $soft, $software, $globals;
	
	// Do stuff here e.g. is as follows
	if($soft == 26){ 
		//Do things only if its WordPress 
	}
	
}


pre_mail

Description

  • The pre_mail filter will trigger your function whenever any mail is sent via Softaculous (e.g installing scripts, removing installation, etc).
  • The main usage of this filter is if you want to send out a CUSTOM Email or want to perform any action before an email is sent. e.g. if an Admin does not want to send an EMAIL of the installation of a script or any other process, then the Admin can Disable Email forcefully using this filter.

Parameters

Key Value Description
$array array/Required Contains details of an Email which is being sent.
 Array
 (
   [0] => Array
        (
            [to] => Email of USER
            [subject] => Email SUBJECT
            [message] => Email BODY
         )
 )

Usage
Uncomment the following part inside filter.php and add your code inside the function my_pre_mail:

insert_filter('pre_mail', 'my_pre_mail', 1, 1);

// @param	array $array Details of the email to be sent.
function my_pre_mail($array){
	global $globals;
	
	//////////////////////////////////////////////////////////////////////////////////
	// $array	 - Will contain the Email Content which is being sent           //
	//////////////////////////////////////////////////////////////////////////////////

	global $globals;
	foreach($array as $k => $v){
            
                if($v['to'] == USER_EMAIL){

                     // Do the STUFF

                }

                // Update the Email subject
                $array[$k]['subject'] = 'My Custom Subject';
        }

        return $array;
}


pre_import

Description
The pre_import filter will trigger your function right before an installation is being imported.

Usage
Uncomment the following part inside filter.php and add your code inside the function my_pre_import:

insert_filter('pre_import', 'my_pre_import', 1);

function my_pre_import(){
	global $soft, $software, $globals;
	
	// Do stuff here e.g. is as follows
	if($soft == 26){ 
		//Do things only if its WordPress 
	}
	
}


post_import

Description
The post_import filter will trigger your function after an installation is imported.

Parameters

Key Value Description
$installation array/Required Contains details of the installation.
 Array
 (
       [insid] => installation id
       [sid] => script id
       [ver] => installed version of script
       [itime] => installation time
       [softpath] => path to installation
       [softurl] => installation URL
       [softdb] => database name of installation
       [softdbuser] => database user of installation
       [softdbhost] => database host of installation
       [softdbpass] => database password of installation
 )

Usage
Uncomment the following part and add your code inside the function my_post_import:

insert_filter('post_import', 'my_post_import', 1, 1);

// @param	array $installation Details of the installation imported
function my_post_import($installation){
	global $soft, $software, $globals;
	
	// Do stuff here e.g. is as follows
	if($soft == 26){ 
		//Do things only if its WordPress 
	}
}


pre_upgrade

Description
The pre_upgrade filter will trigger your function right before an installation is upgraded.

Parameters

Key Value Description
$installation array/Required Contains details of the installation.
 Array
 (
       [insid] => installation id
       [sid] => script id
       [ver] => installed version of script
       [itime] => installation time
       [softpath] => path to installation
       [softurl] => installation URL
       [softdb] => database name of installation
       [softdbuser] => database user of installation
       [softdbhost] => database host of installation
       [softdbpass] => database password of installation
 )

Usage
Uncomment the following part and add your code inside the function my_pre_upgrade:

insert_filter('pre_upgrade', 'my_pre_upgrade', 1, 1);

// @param	array $installation Details of the installation being upgraded
function my_pre_upgrade($installation){
	global $soft, $software, $globals;
	
	// Do stuff here e.g. is as follows
	if($soft == 26){ 
		//Do things only if its WordPress 
	}
	
}


post_upgrade

Description
The post_upgrade filter will trigger your function after an installation is upgraded.

Parameters

Key Value Description
$installation array/Required Contains details of the installation.
 Array
 (
       [insid] => installation id
       [sid] => script id
       [ver] => installed version of script
       [itime] => installation time
       [softpath] => path to installation
       [softurl] => installation URL
       [softdb] => database name of installation
       [softdbuser] => database user of installation
       [softdbhost] => database host of installation
       [softdbpass] => database password of installation
 )

Usage
Uncomment the following part and add your code inside the function my_post_upgrade:

insert_filter('post_upgrade', 'my_post_upgrade', 1, 1);

// @param	array $installation Details of the installation upgraded
function my_post_upgrade($installation){
	global $soft, $software, $globals;
	
	// Do stuff here e.g. is as follows
	if($soft == 26){
		//Do things only if its WordPress
	}
	
}


pre_remove

Description
The pre_remove filter will trigger your function right before an installation is removed.

Parameters

Key Value Description
$installation array/Required Contains details of the installation.
 Array
 (
       [insid] => installation id
       [sid] => script id
       [ver] => installed version of script
       [itime] => installation time
       [softpath] => path to installation
       [softurl] => installation URL
       [softdb] => database name of installation
       [softdbuser] => database user of installation
       [softdbhost] => database host of installation
       [softdbpass] => database password of installation
 )

Usage
Uncomment the following part and add your code inside the function my_pre_remove:

insert_filter('pre_remove', 'my_pre_remove', 1, 1);

// @param	array $installation Details of the installation being removed
function my_pre_remove($installation){
	global $soft, $software, $globals;
	
	// Do stuff here e.g. is as follows
	if($soft == 26){ 
		//Do things only if its WordPress 
	}
	
}


post_remove

Description
The post_remove filter will trigger your function after an installation is removed.

Parameters

Key Value Description
$installation array/Required Contains details of the installation.
 Array
 (
       [insid] => installation id
       [sid] => script id
       [ver] => installed version of script
       [itime] => installation time
       [softpath] => path to installation
       [softurl] => installation URL
       [softdb] => database name of installation
       [softdbuser] => database user of installation
       [softdbhost] => database host of installation
       [softdbpass] => database password of installation
 )

Usage
Uncomment the following part and add your code inside the function my_post_remove:

insert_filter('post_remove', 'my_post_remove', 1, 1);

// @param	array $installation Details of the installation removed
function my_post_remove($installation){
	global $soft, $software, $globals;
	
	// Do stuff here e.g. is as follows
	if($soft == 26){
		//Do things only if its WordPress
	}
	
}


pre_clone

Description
The pre_clone filter will trigger your function before the clone process is started.

Usage
Uncomment the following part and add your code inside the function my_pre_clone:

insert_filter('pre_clone', 'my_pre_clone', 1);

function my_pre_clone(){
	global $soft, $software, $globals;
	
	// Do stuff here e.g. is as follows
	if($soft == 26){
		//Do things only if its WordPress
	}
	
}


post_clone

Description
The post_clone filter will trigger your function after an installation is cloned.

Parameters

Key Value Description
$installation array/Required Contains details of the installation.
 Array
 (
       [insid] => installation id
       [sid] => script id
       [ver] => installed version of script
       [itime] => installation time
       [softpath] => path to installation
       [softurl] => installation URL
       [softdb] => database name of installation
       [softdbuser] => database user of installation
       [softdbhost] => database host of installation
       [softdbpass] => database password of installation
 )

Usage
Uncomment the following part and add your code inside the function my_post_clone:

insert_filter('post_clone', 'my_post_clone', 1, 1);

// @param	array $installation Details of the installation cloned
function my_post_clone($installation){
	global $soft, $software, $globals;
	
	// Do stuff here e.g. is as follows
	if($soft == 26){
		//Do things only if its WordPress	
	}
	
}


error_handle

Description
The error_handle filter will trigger your function when an error is triggered in Softaculous and return the custom errors defined within.

Parameters

Key Value Description
$error array/Required Contains the list of Softaculous error(s) occurred.
 Array
 (
       [ERROR_NAME] => ERROR_DESC
 )

Usage
Uncomment the following part and add your code inside the function my_error_handle:

insert_filter('error_handle', 'my_error_handle', 1, 1);

function my_error_handle($error){
     // Add your custom code here

     $error['my_cust_err'] = 'My Custom Error';

     return $error;
}


post_load_settings

Description
The post_load_settings filter will trigger your function after Install Form Settings are loaded and before the form is displayed in Softaculous.

Usage
Uncomment the following part and add your code inside the function my_post_load_settings:

insert_filter('post_load_settings', 'my_post_load_settings', 1, 1);

// @param	array $settings Contains Install Form Fields
function my_post_load_settings($settings){
	// Add your custom code here
}


pre_softaculous_upgrade

Description
The pre_softaculous_upgrade filter will trigger your function before Softaculous Core Upgrade function is called.

Usage
Uncomment the following part and add your code inside the function my_pre_softaculous_upgrade:

insert_filter('pre_softaculous_upgrade', 'my_pre_softaculous_upgrade', 1);

function my_pre_softaculous_upgrade(){
	// Add your custom code here
}


post_softaculous_upgrade

Description
The post_softaculous_upgrade filter will trigger your function after Softaculous Core Upgrade function is called.

Usage
Uncomment the following part and add your code inside the function my_post_softaculous_upgrade:

insert_filter('post_softaculous_upgrade', 'my_post_softaculous_upgrade', 1);

function my_post_softaculous_upgrade(){
	// Add your custom code here
}


post_unzip

Description
The post_unzip filter will trigger your function after the script package is unzipped when installing the script or upgrading, cloning, etc.

Usage
Uncomment the following part and add your code inside the function my_post_unzip:

insert_filter('post_unzip', 'my_post_unzip', 1);

function my_post_unzip(){
	// Add your custom code here
}


navbar_links

Description
The navbar_links filter will trigger your function before displaying the links in Navbar in Softaculous Enduser Panel (top right hand corner). Use this filter to Add/Remove the navbar links.

Parameters

Key Value Description
$navbar array/Required Contains details of the installation.
 Array
 (
       ['goto_control_panel'] => Array(
                                         ['fullscreen'] => HTML content for the link
                                         ['responsive'] => HTML content for the link
                                      )
       ['add_domain'] => Array(
                                 ['fullscreen'] => HTML content for the link
                                 ['responsive'] => HTML content for the link
                              )
       ['goto_demo'] => Array(
                                 ['fullscreen'] => HTML content for the link
                                 ['responsive'] => HTML content for the link
                             )
       ['goto_rating'] => Array(
                                  ['fullscreen'] => HTML content for the link
                                  ['responsive'] => HTML content for the link
                               )
       ['goto_installations'] => Array(
                                         ['fullscreen'] => HTML content for the link
                                         ['responsive'] => HTML content for the link
                                      )
       ['goto_tasklist'] => Array(
                                    ['fullscreen'] => HTML content for the link
                                    ['responsive'] => HTML content for the link
                                 )
       ['goto_settings'] => Array(
                                    ['fullscreen'] => HTML content for the link
                                    ['responsive'] => HTML content for the link
                                 )
       ['goto_backups'] => Array(
                                    ['fullscreen'] => HTML content for the link
                                    ['responsive'] => HTML content for the link
                                )
       ['goto_email_settings'] => Array(
                                         ['fullscreen'] => HTML content for the link
                                         ['responsive'] => HTML content for the link
                                       )
       ['goto_premium_themes'] => Array(
                                         ['fullscreen'] => HTML content for the link
                                         ['responsive'] => HTML content for the link
                                       )
       ['goto_sync'] => Array(
                                 ['fullscreen'] => HTML content for the link
                                 ['responsive'] => HTML content for the link
                             )
       ['goto_help'] => Array(
                                 ['fullscreen'] => HTML content for the link
                                 ['responsive'] => HTML content for the link
                             )
       ['goto_logout'] => Array(
                                   ['fullscreen'] => HTML content for the link
                                   ['responsive'] => HTML content for the link
                               )
 )

Usage
Uncomment the following part and add your code inside the function my_navbar_links:

insert_filter('navbar_links', 'my_navbar_links', 1, 1);

// @param	array $navbar contains the navbar links
function my_navbar_links($navbar){
	// Add your custom code here
	
	// unset($navbar['goto_email_settings']); // Example to disable email settings link
	// unset($navbar['goto_backups']); // Example to disable backups link
	
	return $navbar;
}


eu_php_bin

Description
The eu_php_bin filter is used to define a php binary path if you are using custom PHP binary and want to define the same in Softaculous.

Parameters

Key Value Description
$php_bin string/Required Contains path of the php binary.

Usage
Uncomment the following part and add your code inside the function my_eu_php_bin:

insert_filter('eu_php_bin', 'my_eu_php_bin', 1, 1);

// @param	string $php_bin Path of php binary
function my_eu_php_bin($php_bin){
	// Add your custom code here
	
	$php_bin = '/PATH/TO/PHPBIN';
	
	return $php_bin;
}


post_load_dbdetails

Description
The post_load_dbdetails filter is used to set database details to be pre-filled on install form.

Parameters

Key Value Description
$dbdetails array/Required Contains prefilled DB details for the installation.
 Array
 (
       ['dbname'] => db_name,
       ['dbusername'] => db_username,
       ['dbuserpass'] => db_userpass,
       ['dbhost'] => db_host
 )

Usage
Uncomment the following part and add your code inside the function my_post_load_dbdetails:

insert_filter('post_load_dbdetails', 'my_post_load_dbdetails', 1, 1);

// @param	array $dbdetails Prefilled DB details for the installation
function my_post_load_dbdetails($dbdetails){
	// Add your custom code here	
	
	//$dbdetails['dbname'] = '';
	//$dbdetails['dbusername'] = ''; // This can be used only in Softaculous Remote
	//$dbdetails['dbuserpass'] = ''; // This can be used only in Softaculous Remote
	//$dbdetails['dbhost'] = ''; // This can be used only in Softaculous Remote
	
	return $dbdetails;
}


pre_update_email

Description

  • The pre_update_email filter will trigger your function whenever an UPDATE becomes available for an installation AND before an email is sent to the user informing him about the update.
  • The main usage of this filter is if you want to send out a CUSTOM Email when a script update is available. e.g. if a new version of WordPress is available, Softaculous will load all the list of users who have WordPress installations and will email them of the same. But if you want to send them an email yourself, you can use this filter.

Usage
Uncomment the following part and add your code inside the function my_pre_update_email:

insert_filter('pre_update_email', 'my_pre_update_email', 1);

function my_pre_update_email(){
	global $globals, $ins_list, $updated_scripts, $scripts;
	
	// $ins_list		 	 - Will contain the details of the OUTDATED installations of all users immediately
							when an update becomes available
	// $updated_scripts	 - The scripts which just got updated
	// $scripts			 - Detailed information about all the scripts.
	
	foreach($ins_list as $username => $scriptwise){
		// Do what needs to be done !
		
		// $scriptwise will now contain the list of installations in the format of array(SCRIPTID => array());
		foreach($scriptwise as $_sid => $_ins){
			
			// Loop through the installations
			foreach($_ins as $kk => $vv){
							
			}
			
		}
		
	}
}


post_adddomain

Description
The post_adddomain filter will trigger your function after a Domain is added.
Note : This filter is only available in Softaculous Remote.

Parameters

Key Value Description
$did string/Required Domain ID of the domain added.

Usage
Uncomment the following part and add your code inside the function my_post_adddomain:

insert_filter('post_adddomain', 'my_post_adddomain', 1, 1);

// @param	string $did Domain ID of the domain added
function my_post_adddomain($did){
	global $softpanel, $globals;
	
	// Do stuff here
	// e.g. is for if you want to perform action only for apache
	
}


post_editdomain

Description
This filter will trigger your function after a Domain is edited.
Note : This filter is only available in Softaculous Remote.

Parameters

Key Value Description
$did string/Required Domain ID of the domain edited.

Usage
Uncomment the following part and add your code inside the function my_post_editdomain:

insert_filter('post_editdomain', 'my_post_editdomain', 1, 1);

// @param	string $did Domain ID of the domain edited
function my_post_editdomain($did){
	
	global $softpanel, $globals;
	
	// Do stuff here
	// e.g. is for if you want to perform action only for apache
	
}


remote_exec_url

Description
This filter can be used if you want to use custom URLs for Softaculous Remote calls to perform tasks such as install, etc.
Note : This filter is available since Softaculous version 4.8.0 and is only available on Softaculous Remote.

Parameters

Key Value Description
$url string/Required Custom URL

Usage
Uncomment the following part and add your code inside the function my_remote_exec_url:

insert_filter('remote_exec_url', 'my_remote_exec_url', 1, 1);

// @param	array $url URL where the script is to be installed
function my_remote_exec_url($url){
	
	// Add your custom code here
	//echo $url; //http://example.com/sreq.php
	$parse = parse_url($url);
	$custom_url = 'domain.com';//This url should point to the location where the current domain being installed is pointing
	$url = str_replace($parse['host'], $custom_url, $url);
	//echo $url; //http://domain.com/sreq.php
	return $url;
}


post_load_soft

Description
This filter can be used to modify the id of the script to be installed.
Note : This filter is available since Softaculous version 4.8.0.

Parameters

Key Value Description
$soft int/Required Script ID to be installed.

Usage
Uncomment the following part and add your code inside the function my_post_load_soft:

insert_filter('post_load_soft', 'my_post_load_soft', 1, 1);

// @param	array $soft Contains softid
function my_post_load_soft($soft){
	// Add your custom code here
	
	return $soft;
}


pre_addcron

Description
The pre_addcron filter will trigger your function right before the cron job is added for an installation while installing the script. You can make changes to the cron execution time as well as the cron command.
Note : This filter is available since Softaculous version 4.8.9.

Usage
Uncomment the following part inside filter.php and add your code inside the function my_pre_addcron:

insert_filter('pre_addcron', 'my_pre_addcron', 1, 1);

function my_pre_addcron($cron){
	global $soft, $software, $globals;
	
	//Add your custom cron command in $cron array.
	$cron['cron_min'] = '';
	$cron['cron_hour'] = ''; 
	$cron['cron_day'] = '';
	$cron['cron_month'] = '';
	$cron['cron_weekday'] = '';
	$cron['cron_command'] = '';
	
	return $cron;
}


post_addcron

Description
The post_addcron filter will trigger your function right after the cron job is added during an installation.
Note : This filter is available since Softaculous version 4.8.9.

Usage
Uncomment the following part inside filter.php and add your code inside the function my_post_addcron:

insert_filter('post_addcron', 'my_post_addcron', 1, 1);

function my_post_addcron($cron){
	global $soft, $software, $globals;
	
	//Add your custom code here.
}


soft_php_bin

Description
Use this filter to pass the path to PHP binary which should be used to perform operations like Clone, Remote Import, etc.
Note : This filter is available since Softaculous version 4.9.2.

Usage
Uncomment the following part inside filter.php and add your code inside the function my_soft_php_bin:

insert_filter('soft_php_bin', 'my_soft_php_bin', 1, 1);

function my_soft_php_bin($phpbin){
	
	// Note : The PHP binary should be a CLI PHP binary
	$phpbin = '/PATH/TO/PHPBIN'; //Define your php binary here
	
	return $phpbin;
}


pre_softaculous_upgrade_check

Description
The pre_softaculous_upgrade_check filter will trigger your function before the Softaculous Core Upgrade check is performed.
Note : This filter is available since Softaculous version 4.9.0
Note : This filter is for Softaculous core upgrade and not script updates.

Usage
Uncomment the following part inside filter.php and add your code inside the function my_pre_softaculous_upgrade_check:

insert_filter('pre_softaculous_upgrade_check', 'my_pre_softaculous_upgrade_check', 1);

function my_pre_softaculous_upgrade_check(){
	// Add your custom code here
}


upgrade_softaculous_to_version

Description
The upgrade_softaculous_to_version filter will trigger your function and define the version of Softaculous you want to upgrade to. Make sure you pass correct version of Softaculous you want to upgrade to, otherwise you will be upgraded to the latest version.

  • If you enter the version as less than the Softaculous version you are currently at, Softaculous will be upgraded to the latest version.
  • If you pass the version greater than or equal to the Softaculous version you are currently at but less than or equal to the latest Softaculous version, Softaculous will be upgraded to that particular version. But if the passed version is greater than the latest Softaculous version, your Softaculous will be upgraded to the latest version only.

Note : This filter is available since Softaculous version 4.9.0.

Usage
Uncomment the following part inside filter.php and add your code inside the function my_upgrade_softaculous_to_version:

insert_filter('upgrade_softaculous_to_version', 'my_upgrade_softaculous_to_version', 1);
function my_upgrade_softaculous_to_version(){
	//return '4.9.0'; // this example will upgrade Softaculous to 4.9.0
}


check_files_exist

Description
The check_files_exist filter will trigger your function when Softaculous checks for files already exists while installing a script, use this filter to add or remove the list of files existing in the path where you are installing a script. The list returned after applying this filter is the list for which the user will be reported of files already exists (with an option to overwrite the files).
Note : This filter is available since Softaculous version 4.9.0

Usage
Uncomment the following part inside filter.php and add your code inside the function my_check_files_exist:

insert_filter('check_files_exist', 'my_check_files_exist', 1, 1);

function my_check_files_exist($exists){
	
	//e.g if you want to unset .htaccess 
	
	if(in_array('.htaccess', $exists)){
		$htaccess_key = array_search('.htaccess', $exists);
		unset($exists[$htaccess_key]);
	}
	
	return $exists;
}


Define PHP Version

You can also define the PHP version in the Pre Install Filter if you are using multiple PHP versions on your server.

  • Uncomment the part defining pre_install filter as explained above.
  • Add your code to Identify the PHP version in the function my_pre_install()

insert_filter('pre_install', 'my_pre_install', 1);

function my_pre_install(){	
	global $soft, $software, $globals;
	// Your Code to Identify the PHP version
	// E.g
	$version = phpversion();
	define('php_version', $version);
}
  • If the PHP version is defined here then Softaculous will skip its process to detect the PHP version while installing a Script.
  • The above example is for pre_install filter. You can similarly configure the pre_upgrade and pre_clone filter to skip the php version check during the upgrade and clone process respectively.


Define PERL Version

You can also define the PERL version in the Pre Install Filter.

  • Uncomment the part defining pre_install filter as explained above.
  • Define the PERL version in the function you used while adding the pre install filter (my_pre_install() in this case)

insert_filter('pre_install', 'my_pre_install', 1);

function my_pre_install(){	
	global $soft, $software, $globals;
	// Your Code to Identify the PERL version
	// E.g
	define('perl_version', '5.8.8');
}
  • If the PERL version is defined here then Softaculous will skip its process to detect the PERL version while installing a Script.
  • The above example is for pre_install filter. You can similarly configure the pre_upgrade and pre_clone filter to skip the PERL version check during the upgrade and clone process respectively.


Define MySQL Version

You can also define the MySQL version in the Pre Install Filter.

  • Uncomment the part defining pre_install filter as explained above.
  • Define the MySQL version in the function my_pre_install()

insert_filter('pre_install', 'my_pre_install', 1);

function my_pre_install(){	
	global $soft, $software, $globals;
	// Your Code to Identify the MySQL version
	// E.g
	define('mysql_version', '5.1.65');
}
  • If the MySQL version is defined here then Softaculous will skip its process to detect the MySQL version while installing a Script.
  • The above example is for pre_install filter. You can similarly configure the pre_upgrade and pre_clone filter to skip the MySQL version check during the upgrade and clone process respectively.


Define Loaded Extensions

You can also define the list of enabled PHP extensions in the Pre Install Filter.

  • Uncomment the part defining pre_install filter as explained above.
  • Define the list of enabled PHP extensions in the function my_pre_install()

insert_filter('pre_install', 'my_pre_install', 1);

function my_pre_install(){	
	global $soft, $software, $globals, $__hooks;
	// E.g
	$__hooks['loaded_extension'] = array('mysqli', 'curl', 'gd');

        //If $__hooks['loaded_extension'] is the only extension loaded list and you do not want Softaculous to detect the extensions, then you can define the following constant.
        define('PHP_EXT_EXHAUSTIVE', 1);

}
  • If the extension is defined as enabled here then Softaculous will skip its process to detect the PHP extension enabled while installing a Script.
  • The above example is for pre_install filter. You can similarly configure the pre_upgrade and pre_clone filter to skip the PHP extensions check during the upgrade and clone process respectively.


Define Functions Enabled

You can also define the list of enabled PHP functions in the Pre Install Filter.

  • Uncomment the part defining pre_install filter as explained above.
  • Define the list of enabled PHP functions in the function my_pre_install()

insert_filter('pre_install', 'my_pre_install', 1);

function my_pre_install(){	
	global $soft, $software, $globals, $__hooks;
	// E.g
	$__hooks['function_exists'] = array('phpinfo', 'exec', 'shell_exec');
}
  • If the function is defined as enabled here then Softaculous will skip its process to detect the PHP function enabled while installing a Script.
  • The above example is for pre_install filter. You can similarly configure the pre_upgrade and pre_clone filter to skip the PHP function exists check during the upgrade and clone process respectively.


Change PHP Version using .htaccess

.htaccess is used by many web hosts to change PHP version for their users. You can do this using Softaculous for the scripts that require PHP 5.3+
Note : This example assumes that you run PHP 5.2 as default for the user and this filter will switch the version to PHP 5.3.

  • Add the following code in the file /path/to/softaculous/enduser/hooks/filter.php

insert_filter('pre_install', 'my_pre_install', 1);

function my_pre_install(){

global $soft, $software, $globals, $scripts;
	// Do stuff here e.g. is as follows	

	if($scripts[$soft]['php_min'] >= '5.3'){
		$version = '5.3.24';
		define('php_version', $version);	
	}
}
  • This pre install filter will skip the PHP version check by Softaculous.
  • Now you have to create the .htaccess file with the content to switch PHP version to 5.3
  • Add the following code to my_post_install() function in the file /path/to/softaculous/enduser/hooks/filter.php

insert_filter('post_install', 'my_post_install', 1, 1);

// @param	array $installation Details of the new installation
function my_post_install($installation){
global $soft, $software, $globals, $scripts;
	// Do stuff here e.g. is as follows
	
	if($scripts[$soft]['php_min'] >= '5.3'){
	
		$data = "AddHandler application/x-httpd-php53 .php\n";
		
		if(sfile_exists($installation[0]['softpath'].'/.htaccess')){
			$tmp_data = sfile($installation[0]['softpath'].'/.htaccess');
			if(!preg_match('/AddHandler(\s*?)application/is', $tmp_data)){
				$data .= $tmp_data;
			}
		}
		
		swrite($installation[0]['softpath'].'/.htaccess', $data, 1);	
	}
}
  • This will create the .htaccess file with the required content and if the script has a .htaccess then it will write the content to the existing file.
  • Now we also need to define the PHP version during the Upgrade process.
  • Add the following code to my_pre_upgrade() function in the file /path/to/softaculous/enduser/hooks/filter.php
insert_filter('pre_upgrade', 'my_pre_upgrade', 1, 1);

// @param	array $installation Details of the installation being upgraded
function my_pre_upgrade($installation){
global $soft, $software, $globals, $scripts;
	// Do stuff here e.g. is as follows	

	if($scripts[$soft]['php_min'] >= '5.3'){
		$version = '5.3.24';
		define('php_version', $version);	
	}
}
  • This pre upgrade filter will skip the PHP version check by Softaculous.
  • Now you have to create the .htaccess file with the content to switch PHP version to 5.3
  • Add the following code to my_post_upgrade() function in the file /path/to/softaculous/enduser/hooks/filter.php
insert_filter('post_upgrade', 'my_post_upgrade', 1, 1);

// @param	array $installation Details of the installation upgraded
function my_post_upgrade($installation){
global $soft, $software, $globals, $scripts;
	// Do stuff here e.g. is as follows
	
	if($scripts[$soft]['php_min'] >= '5.3'){
	
		$data = "AddHandler application/x-httpd-php53 .php\n";
		
		if(sfile_exists($installation[0]['softpath'].'/.htaccess')){
			$tmp_data = sfile($installation[0]['softpath'].'/.htaccess');
			if(!preg_match('/AddHandler(\s*?)application/is', $tmp_data)){
				$data .= $tmp_data;
			}
		}
		
		swrite($installation[0]['softpath'].'/.htaccess', $data, 1);	
	}
}
  • This will create the .htaccess file with the required content if the content does not exist.
  • Thats it you have the filter configured to switch PHP version.