WP-CLI - Das Kommandozeilen Interface für Wordpress

45
WP-CLI - Ein Kommandozeilen Interface für WordPress 23.10.2013 Frank Staude <[email protected]>

description

Wordpress mit der Kommandozeile steuern. Mit dem Tool WP-CLI kann man Wordpress per Kommandozeile steuern.

Transcript of WP-CLI - Das Kommandozeilen Interface für Wordpress

Page 1: WP-CLI - Das Kommandozeilen Interface für Wordpress

WP-CLI - Ein Kommandozeilen Interface für WordPress

23.10.2013 Frank Staude <[email protected]>

Page 2: WP-CLI - Das Kommandozeilen Interface für Wordpress

WP-CLI ?WP-CLI ( WordPress - Command Line Interface) ist ein Programm, mit dem man Wordpress per Kommandozeile bedienen kann. !Warum braucht man das? - Admins sind gewohnt mit der Tastatur zu arbeiten - Mit der Tastatur ist man in der Regel schneller als in einem Webinterface - Mit Kommandos kann man Aufgaben automatisieren

Page 3: WP-CLI - Das Kommandozeilen Interface für Wordpress

VoraussetzungenUm WP-CLI zu installieren braucht es ein paar Dinge !- Unix shell. ( OS X, Linux, Windows mit Cygwin) - PHP 5.3 oder neuer - php-cli im PHP aktiviert (php -v / phpinfo zum prüfen) - Git - Wordpress 3.4 oder neuer !

Page 4: WP-CLI - Das Kommandozeilen Interface für Wordpress

InstallationEin Installationsscript kann direkt von GitHub geladen und ausgeführt werden. !curl https://raw.github.com/wp-cli/wp-cli.github.com/master/installer.sh | bash !Das installiert WP-CLI im Verzeichnis .wp-cli im Benutzerverzeichnis. Damit es von überall gefunden wird, sollte man danach noch das bin Verzeichnis von wp-cli mit im Pfad seiner Shell aufnehmen. Eine Entsprechende Meldung gibt der Installer aus. !MySQL muss im Pfad liegen, sonst scheitert wp core config !Alternative Installationsmethoden: https://github.com/wp-cli/wp-cli/wiki/Alternative-Install-Methods

Page 5: WP-CLI - Das Kommandozeilen Interface für Wordpress

Erster StartNun kann WP-CLI durch die Eingabe von wp aufgerufen werden. !

Page 6: WP-CLI - Das Kommandozeilen Interface für Wordpress

Mehr KomfortWP-CLI bietet auch s.g. Tab completion, also die Funktionalität bei drücken der Tabulator Taste das Kommando zu vervollständigen oder (wenn nicht eindeutig) die Liste der Kommandos auszugeben. !Dazu muss man seine .profile Datei ergänzen um !source $HOME/.wp-cli/vendor/wp-cli/wp-cli/utils/wp-completion.bash !!

Page 7: WP-CLI - Das Kommandozeilen Interface für Wordpress

wp

Page 8: WP-CLI - Das Kommandozeilen Interface für Wordpress

wp cache

Page 9: WP-CLI - Das Kommandozeilen Interface für Wordpress

wp cap

Page 10: WP-CLI - Das Kommandozeilen Interface für Wordpress

wp cli

Page 11: WP-CLI - Das Kommandozeilen Interface für Wordpress

wp comment

Page 12: WP-CLI - Das Kommandozeilen Interface für Wordpress

wp core

Page 13: WP-CLI - Das Kommandozeilen Interface für Wordpress

wp db

Page 14: WP-CLI - Das Kommandozeilen Interface für Wordpress

wp eval

Page 15: WP-CLI - Das Kommandozeilen Interface für Wordpress

wp eval-file

Page 16: WP-CLI - Das Kommandozeilen Interface für Wordpress

wp export

Page 17: WP-CLI - Das Kommandozeilen Interface für Wordpress

wp help

Page 18: WP-CLI - Das Kommandozeilen Interface für Wordpress

wp import

Page 19: WP-CLI - Das Kommandozeilen Interface für Wordpress

wp media

Page 20: WP-CLI - Das Kommandozeilen Interface für Wordpress

wp network-meta

Page 21: WP-CLI - Das Kommandozeilen Interface für Wordpress

wp option

Page 22: WP-CLI - Das Kommandozeilen Interface für Wordpress

wp plugin

Page 23: WP-CLI - Das Kommandozeilen Interface für Wordpress

wp post

Page 24: WP-CLI - Das Kommandozeilen Interface für Wordpress

wp post-meta

Page 25: WP-CLI - Das Kommandozeilen Interface für Wordpress

wp rewrite

Page 26: WP-CLI - Das Kommandozeilen Interface für Wordpress

wp role

Page 27: WP-CLI - Das Kommandozeilen Interface für Wordpress

wp scaffold

Page 28: WP-CLI - Das Kommandozeilen Interface für Wordpress

wp search-replace

Page 29: WP-CLI - Das Kommandozeilen Interface für Wordpress

wp site

Page 30: WP-CLI - Das Kommandozeilen Interface für Wordpress

wp term

Page 31: WP-CLI - Das Kommandozeilen Interface für Wordpress

wp theme

Page 32: WP-CLI - Das Kommandozeilen Interface für Wordpress

wp transient

Page 33: WP-CLI - Das Kommandozeilen Interface für Wordpress

wp user

Page 34: WP-CLI - Das Kommandozeilen Interface für Wordpress

wp user-meta

Page 35: WP-CLI - Das Kommandozeilen Interface für Wordpress

Beispiele: WP VersionEntweder man wechselt in das Verzeichnis der jeweiligen Wordpress Installation !staude$ cd Wordpress\ Dev/!staude$ wp core version!3.6.1!!oder man übergibt den Pfad mittels --path=‘pfad/zur/WP/Installation‘ !staude$ wp core version --path='/Users/staude/Projekte/Wordpress Dev'!3.6.1!

Page 36: WP-CLI - Das Kommandozeilen Interface für Wordpress

Beispiele: Plugins auflistenstaude$ wp plugin list!+-----------------------------------+----------+--------+---------+!| name | status | update | version |!+-----------------------------------+----------+--------+---------+!| akismet | inactive | none | 2.5.9 |!| backend-startpage-customizer | inactive | none | 0.2 |!| blog-description-randomizer | inactive | none | 0.1 |!| codestyling-localization | active | none | 1.99.30 |!| disable-author-pages | active | none | 0.2 |!| disable-title | active | none | 0.5 |!| downloads-per-page | active | none | 0.1 |!| google-analytics-dashboard-for-wp | active | none | 4.2.1 |!| mime-types-extended | active | none | 0.7 |!| my-own-plugins | inactive | none | 0.1 |!| post-author-filter | active | none | 0.1 |!| random-blog-description | inactive | none | 1.0 |!| scheduled-posts-dashboard-widget | active | none | 0.1 |!| scheduled-jobs-dashboard-widget | inactive | none | 0.2.2 |!| scheduled-unsticky | inactive | none | 0.2.2 |!| widget-or-sidebar-per-shortcode | inactive | none | 0.4 |!+-----------------------------------+----------+--------+---------+!

Page 37: WP-CLI - Das Kommandozeilen Interface für Wordpress

Beispiele: Plugins suchen

staude$ wp plugin search hello-dolly!Success: Showing 10 of 20 plugins.!+-------------------------------+-------------------------------+--------+!| name | slug | rating |!+-------------------------------+-------------------------------+--------+!| Hello Dolly | hello-dolly | 67.4 |!| Hello Dolly For Your Song | hello-dolly-for-your-song | 0 |!| Hello Simpsons Chalkboard Gag | hello-simpsons-chalkboard-gag | 100 |!| Hello Kurt | hello-kurt | 0 |!| Fancy Dolly | fancy-plugin | 91.4 |!| Hello Darth | hello-darth | 100 |!| Hello Hollywood | hello-hollywood | 100 |!| Hello Ziggy | hello-ziggy | 0 |!| Hello HAL | hello-hal | 100 |!| Unwanted Plugins Remover | unwanted-plugins-remover | 100 |!+-------------------------------+-------------------------------+--------+!

Page 38: WP-CLI - Das Kommandozeilen Interface für Wordpress

Beispiele: Plugin installieren

staude$ wp plugin install hello-dolly!Installing Hello Dolly (1.6)!Runterladen des Installationspakets von http://downloads.wordpress.org/plugin/hello-dolly.1.6.zip...!Entpacken des Pakets...!Das Plugin wird installiert...!Das Plugin wurde erfolgreich installiert.!

Page 39: WP-CLI - Das Kommandozeilen Interface für Wordpress

Beispiele: Plugin aktivieren

staude$ wp plugin activate hello-dolly!Success: Plugin 'hello-dolly' activated.!!!staude$ wp plugin deactivate hello-dolly!Success: Plugin 'hello-dolly' deactivated.!

Page 40: WP-CLI - Das Kommandozeilen Interface für Wordpress

Beispiele: WP installieren

In ein neues, leeres Verzeichnis gehen (oder --path überall angeben)!!staude$ wp core download!Downloading latest WordPress (en_US)...!Success: WordPress downloaded.!!staude$ wp core config --dbname=Datenbank --dbuser=Benutzer --dbpass=Kennwort!Success: Generated wp-config.php file.!!staude$ wp core install --url=test.de --title=title --admin_user=adminBenutzer --admin_password=adminKennwort [email protected]!Success: WordPress installed successfully.!

Page 41: WP-CLI - Das Kommandozeilen Interface für Wordpress

Plugin + WP-CLIPlugins können ebenfalls das WP-CLI Interface implementieren und können dann ebenfalls perKomandozeile bedient werden. Zum Beispiel das Plugin Developer ( http://wordpress.org/plugins/developer ). !staude$ wp plugin install developer!Installing Developer (1.2.5)!Runterladen des Installationspakets von http://downloads.wordpress.org/plugin/developer.1.2.5.zip...!Entpacken des Pakets...!Das Plugin wird installiert...!Das Plugin wurde erfolgreich installiert.!!staude$ wp plugin activate developer!Success: Plugin 'developer' activated.!!!staude$ wp developer!usage: wp developer install-plugins --type=<type> [--activate]!!See 'wp help developer <subcommand>' for more information on a specific subcommand.!

Page 42: WP-CLI - Das Kommandozeilen Interface für Wordpress

Eigenes Plugin + WP-CLIAm Beispiel meines Plugins scheduled-unsticky ( http://wordpress.org/plugins/scheduled-unsticky/ ) demonstriere ich die Arbeiten um ein Plugin per WP-CLI steuerbar zu machen. !Abfragen des WP-CLI defines im Constructor und ggf laden einer Klasse die das CLI Interface implementiert. !if ( defined ( 'WP_CLI' ) && WP_CLI ) {! require_once( __DIR__ . '/class-wp-cli-commands.php' );!}

Page 43: WP-CLI - Das Kommandozeilen Interface für Wordpress

Eigenes Plugin + WP-CLIUnd die Implementierung!!<?php!class Scheduled_Unsticky_WP_CLI_Command extends WP_CLI_Command {! /**! * @subcommand info! */ ! function info( $args, $assoc_args ) {! $cron = get_option('scheduled_unsticky_cron');! $days = get_option( 'scheduled_unsticky_days' );! if ($cron != 0) {! $schedules = wp_get_schedules();! $cron = $schedules[$cron];! }! WP_CLI::line('interval: '. $cron );! WP_CLI::line('days : '. $days);! }! /**! * @subcommand days ! * @synopsis <days>! */! function days( $args ) {! $days = $args[0];! update_option( 'scheduled_unsticky_days', $days );! WP_CLI::success('days: '. $days);! }!}!!WP_CLI::add_command( 'scheduled-unsticky', 'Scheduled_Unsticky_WP_CLI_Command' );!!

Page 44: WP-CLI - Das Kommandozeilen Interface für Wordpress

Eigenes Plugin + WP-CLI

staude$ wp scheduled-unsticky!usage: wp scheduled-unsticky days <days>! or: wp scheduled-unsticky info!!See 'wp help scheduled-unsticky <subcommand>' for more information on a specific subcommand.!!!staude$ wp scheduled-unsticky info!interval: twicedaily!days : 2!!!staude$ wp scheduled-unsticky days 3!Success: days: 3!!!staude$ wp scheduled-unsticky info!interval: twicedaily!days : 3!!!

Page 45: WP-CLI - Das Kommandozeilen Interface für Wordpress

Links

WP-CLI !http://wp-cli.org/!!WP-CLI Wiki!https://github.com/wp-cli/wp-cli/wiki!!WP-CLI Installation!http://wp-cli.org/!!Alternative Installationsmöglichkeiten!https://github.com/wp-cli/wp-cli/wiki/Alternative-Install-Methods!!Command Cookbook - für Implementierung eigener Erweiterungen!https://github.com/wp-cli/wp-cli/wiki/Commands-Cookbook!!Scheduled Unsticky Plugin!http://wordpress.org/plugins/scheduled-unsticky/!