valendesigns / option-tree

Theme Options UI Builder for WordPress. A simple way to create & save Theme Options and Meta Boxes for free or premium themes.
GNU General Public License v2.0
597 stars 179 forks source link

WP CLI support #635

Open JMLX42 opened 7 years ago

JMLX42 commented 7 years ago

Hi there,

I'm using option tree from within the "Stratus" Wordpress theme. I'm setting up my Wordpress site using WP CLI (http://wp-cli.org) but it doesn't work because of the following error:

PHP Fatal error:  Call to undefined function ot_decode() in /srv/www/themes/stratus/option-tree/theme-options-defaults.php on line 16

The problem comes from this line: https://github.com/valendesigns/option-tree/blob/master/ot-loader.php#L361

Within WP CLI, is_admin will be false but some code loaded by the theme or Option Tree itself needs those admin functions. So I replaced:

if ( ! is_admin() )

with:

if ( ! is_admin() && !defined('WP_CLI') )

and it works.

Another solution is to call WP CLI with this theme disabled:

wp --skip-themes=stratus [...]

but I'm guessing this solution won't work if Option Tree is enabled as a plugin.

Should I create a pull request for this?

Regards,

valendesigns commented 5 years ago

Sorry for the late reply but feel free to create a PR.