|All requests||>||I need a PHP class for saving file to...||>||Request new recommendation||>||Featured requests||>||No recommendations|
by Nermin Phelopis - 3 years ago (2019-10-16)
I am developing WordPress plugin. This plugin has a lot of addons it will enable and disable using the admininistration settings in WordPress.
I want to create a class to merge all PHP files which will be used by the enabled addons to be in one file with require it once time.
This file will be generated automatically with a generated id.
This file will be automatically removed and a new one is created when the settings are saved (enabled and disable addons).
This file will be made available in the uploads folder of WordPress.
Please advise on if this type of class exists or how can I develop it.
1. by adriano ghezzi - 3 years ago (2020-03-05) Reply
If I well understand requirements this can be a sample solution
-.plugins you have a variable number of plugins each plugin have at least one file associated with it but can have more
-configFile hold the status of plugin enabled/disabled
-srcDir all plugin's source file are in the srcDir directory
-merge merge enabled plugin files in new one file
-make config write a new configFile
-enable,disable plugin enable or disable a plugin
-load config load the configFile
for convention plugin source files are named plugin_1_file_1.<ext> plugn_1_file_2.<ext> plugin_2_file_1.<ext> ...and so on
configFile contains a php array configArray $configArray[<pluginNumber]=<status>(bool)
function makeConfig(srcDir,configFile) // generate a new configFile that contains the array $configArray=
browse dir pluginSrc for each file get the index if not exists in configArray add it configArray[<index>]=false endfor write to config file the array
function pluginEnableDisable(pluginNUmber,status,srcDir,configFile) ::makeConfig(srcDir,configFile) $configArray=require_once $configFile $configFile[pluginNumber]=status
function mergePlugin($destinationFile,$configFile,$srcDir) open $destination file for writing browse srcDir foreach file
get plugin number check if enabled in configArray if enabled open source file as text file cycle lines read line from source write line to destFile end cycle lines close source
end cycle files
ta add or remove plugins simply add or delete source files