Understanding Clean Options

What options does the Clean Options plugin catch? To understand what the Clean Options plugin does, an explanation of how it gathers WordPress options may be helpful.

The plugin searches the blog folders for PHP files. It searches these files for occurrences of get_option and get_settings using the regular expression
"#get_(?:option|settings)[ ]?\([ ]?[\'\"]([-\w]+)[\'\"][ ]?\)#"
This will match common variations in syntax, such as
get_option('option-name-here') //no spaces next to parens – single quotes
get_option ('Option-Name-Here') //space outside paren – single quotes
get_option( 'option_name_here' ) //spaces inside parens – single quotes
get_option ( 'Option_Name_Here' ) //spaces both sides of parens – single quotes
get_option("option-name-here") //no spaces next to parens – double quotes
get_option ("Option-Name-Here") //space outside paren – double quotes
get_option( "option_name_here" ) //spaces inside parens – double quotes
get_option ( "Option_Name_Here" ) //spaces both sides of parens – double quotes

Will the regular expression match all the possible variations in syntax? As Leonid Mamchenkov posted on the WordPress Bits blog , the plugin will not find occurrences of options where the option name is a constant or a variable such as
get_option(OPTION) //constant
get_option($option) //variable
How does this affect the plugin? Understand that these matches are put into an array of options that either are, or potentially could be, needed. The plugin does not determine whether or not the option is being used, only that the blog folders contain a file that "gets" the option. This array is combined with an array of core options.

The Clean Options plugin uses the WordPress get_alloptions function to find all options where autoload = yes in the options table. The Clean Options plugin also uses a database query to find all options where autoload is not equal to yes.

The plugin then lists options that were found in the options table, but were not found in the PHP files.

Because it can not be guarantied that all listed options are orphaned, it is important that their contents be studied before they are removed to ensure that they are in fact orphaned.

Technorati Tags: , ,