sybrew / the-seo-framework

The SEO Framework WordPress plugin.
https://theseoframework.com/
GNU General Public License v3.0
416 stars 47 forks source link

wp-cli for The SEO Framework #441

Open ratzrattillo opened 5 years ago

ratzrattillo commented 5 years ago

Hey there dear SEO Framework guys!

i really like your framework a lot and i first want to give you props for the good and free (!!!) software that you create for all of us. As i am one of the persons who experiments a lot with wordpress and woocommerce, i also destroy a lot. Due to issues that can arise and destroy my environment, i decided to start scripting my pages with WP-CLI and it helps me a lot to get my sites up and running again. It would be a really great feature, if it was possible to change The SEO Framework settings using WP-CLI. However, i could not find a way to do so right now.

Would you like to implement this as a new great feature? (I think a lot of people might like it)

Keep up the good work and have a nice day/night :)

sybrew commented 5 years ago

Hello @ratzrattillo

I'm happy to see your enthusiasm!

We use the WordPress options API. https://developer.wordpress.org/cli/commands/option/

However, as we work with one single option storing a bulk of settings (EAV model), we had to implement an API on top of that; to streamline the process towards it.

Via the the_seo_framework() function, you can access most of the API. For example:

Deprecated: the_seo_framework()->get_default_site_options();    // Gets default site options.
Deprecated: the_seo_framework()->get_all_options();             // Gets all options you've set.
the_seo_framework()->get_option( $key );            // Gets a single option.
the_seo_framework()->update_option( $key, $value ); // Sets a single option.
Deprecated: the_seo_framework()->update_settings( $options );   // Sets an array of options, merges with current.

I hope this gets you started! Feel free to reach out if you require a little more help. :)

sybrew commented 5 years ago

We may want to add WP-CLI commands:

if ( defined( 'WP_CLI' ) && WP_CLI ) {
    WP_CLI::add_command( 'tsf', 'callback' );
    WP_CLI::add_command( 'tsf something', 'callback_to_something' );
}

I don't use WP-CLI myself; so, any feedback would be helpful.

ratzrattillo commented 5 years ago

Hello @sybrew

i just checked the options settings and this already seems to be a pretty good alternative for me to get things going. Thank you very much! The command to show the settings is: "wp option get autodescription-site-settings"

However, your suggestions of the CLI changes are of course prettier. E.g. something like: wp tsf general wp tsf meta wp tsf homepage

I will try to learn more about SEO with tsf and maybe we can find a really nice categorization, which makes up useful, structured commands!