![Page 2: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/2.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/3.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/4.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/5.jpg)
Erster StartNun kann WP-CLI durch die Eingabe von wp aufgerufen werden. !
![Page 6: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/6.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/7.jpg)
wp
![Page 8: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/8.jpg)
wp cache
![Page 9: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/9.jpg)
wp cap
![Page 10: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/10.jpg)
wp cli
![Page 11: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/11.jpg)
wp comment
![Page 12: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/12.jpg)
wp core
![Page 13: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/13.jpg)
wp db
![Page 14: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/14.jpg)
wp eval
![Page 15: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/15.jpg)
wp eval-file
![Page 16: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/16.jpg)
wp export
![Page 17: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/17.jpg)
wp help
![Page 18: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/18.jpg)
wp import
![Page 19: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/19.jpg)
wp media
![Page 20: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/20.jpg)
wp network-meta
![Page 21: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/21.jpg)
wp option
![Page 22: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/22.jpg)
wp plugin
![Page 23: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/23.jpg)
wp post
![Page 24: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/24.jpg)
wp post-meta
![Page 25: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/25.jpg)
wp rewrite
![Page 26: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/26.jpg)
wp role
![Page 27: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/27.jpg)
wp scaffold
![Page 28: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/28.jpg)
wp search-replace
![Page 29: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/29.jpg)
wp site
![Page 30: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/30.jpg)
wp term
![Page 31: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/31.jpg)
wp theme
![Page 32: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/32.jpg)
wp transient
![Page 33: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/33.jpg)
wp user
![Page 34: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/34.jpg)
wp user-meta
![Page 35: WP-CLI - Das Kommandozeilen Interface für Wordpress](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/35.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/36.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/37.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/38.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/39.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/40.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/41.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/42.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/43.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/44.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022020110/554f50ffb4c905b9508b4d9c/html5/thumbnails/45.jpg)
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/!