Last active
July 14, 2024 16:55
-
-
Save zzap/41440fce9e891e5cc431643be2305d69 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Get all users with `wpcli.loc` in their email address | |
* and export them to `users.csv` file. | |
* | |
* Execute this script with: | |
* wp eval-file get-users.php | |
*/ | |
$fields = [ | |
'user_login', | |
'user_email', | |
'display_name' | |
]; | |
$users = get_users( | |
[ | |
'fields' => $fields, | |
'search' => '*wpcli.loc', | |
'search_columns' => [ | |
'user_email' | |
], | |
] | |
); | |
$filename = 'users.csv'; | |
$file = fopen( $filename, 'w' ); | |
$items = []; | |
foreach ( $users as $user ) { | |
WP_CLI::log( sprintf( 'Reading user: %s.', $user->display_name ) ); | |
fputcsv( $file, (array) $user ); | |
$items[] = (array) $user; | |
} | |
fclose( $file ); | |
if ( ! file_exists( $filename ) ) { | |
WP_CLI::error( sprintf( 'Failed to create %s file.', $filename ) ); | |
} else { | |
WP_CLI::success( sprintf( 'Created %s file. Following users have been exported:', $filename ) ); | |
} | |
WP_CLI\Utils\format_items( 'table', $items, $fields ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Your code starts here. | |
if ( ! defined( 'ABSPATH' ) ) { | |
die(); | |
} | |
include_once __DIR__ . '/post-types/developers.php'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# WP-CLI for PHP developers article | |
# install WordPress | |
wp core download | |
wp config create --dbuser=<DB_USER> --dbpass=<DB_PASSWORD> --dbname=<DB_NAME> | |
wp core install --url=<URL> --title=<TITLE> --admin_user=<ADMIN_USERNAME> --admin_password=<ADMIN_PASSWORD> --admin_email=<ADMIN_EMAIL> | |
# bash script | |
#!/bin/bash | |
wp core download | |
read -p 'Database name: ' dbname | |
read -sp 'Database password: ' dbpass | |
wp config create --dbuser=milana --dbpass=$dbpass --dbname=$dbname --prompt --quiet | |
wp core install --url="${dbname}.loc" --title=$dbname --admin_user=admin --admin_password=admin --admin_email="admin@${dbname}.loc" | |
# make script executable | |
chmod +x wp-install | |
# move script to /bin/ | |
mv wp-install ~/bin/wp-install | |
# scaffold plugin | |
wp scaffold plugin --prompt | |
# scaffold CPT | |
wp scaffold post-type --prompt | |
# execute PHP file | |
wp eval-file get-users.php |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment