### WP-CLI Plugin Management Example Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-cli-handbook.md This example demonstrates how to use WP-CLI to install and activate a WordPress plugin. It shows the command-line interface output for each operation, indicating the success of the actions. WP-CLI provides a programmatic alternative to the WordPress admin interface for managing plugins. ```bash $ wp plugin install akismet Installing Akismet (3.1.8) Downloading install package from https://downloads.wordpress.org/plugin/akismet.3.1.8.zip... Unpacking the package... Installing the plugin... Plugin installed successfully. ``` ```bash $ wp plugin activate akismet Success: Plugin 'akismet' activated. ``` -------------------------------- ### WordPress Directory Structure Example Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-adv-admin-handbook.md Illustrates the typical file and directory layout of a WordPress installation. This structure is important for understanding where specific permissions need to be applied. ```text | |- index.php |- wp-admin | |- wp-admin.css |- wp-blog-header.php |- wp-comments-post.php |- wp-commentsrss2.php |- wp-config.php |- wp-content | |- cache | |- plugins | |- themes | |- uploads |- wp-cron.php |- wp-includes |- xmlrpc.php ``` -------------------------------- ### Start WordPress Development Web Server Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-cli-handbook.md Launches PHP's built-in web server for a specific WordPress installation. Allows specifying host and port, defaults to localhost:8080. Useful for local development. ```bash wp server [--host=] [--port=] ``` ```bash $ wp server PHP 7.2.24-0ubuntu0.18.04.4 Development Server started at Thu Jun 4 17:40:13 2020 Listening on http://localhost:8080 Document root is ../wpdemo.test Press Ctrl-C to quit. ``` -------------------------------- ### Install WordPress Core Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-cli-handbook.md Installs WordPress core files and sets up the site with provided URL, title, and admin credentials. Requires database to be created and wp-config.php to be set up. ```bash wp core install --url= --title= --admin_user=<user> --admin_password=<password> --admin_email=<email> ``` ```bash $ wp core install --url=wpclidemo.dev --title="WP-CLI" --admin_user=wpcli --admin_password=wpcli --admin_email=info@wp-cli.org Success: WordPress installed successfully. ``` -------------------------------- ### Download and Install WordPress with WP-CLI Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-cli-handbook.md This snippet demonstrates the steps to download WordPress, create a wp-config.php file, set up the database, and finally install WordPress using WP-CLI commands. ```bash $ wp core download --path=wpclidemo.dev Creating directory '/srv/www/wpclidemo.dev/'. Downloading WordPress 4.6.1 (en_US)... Using cached file '/home/vagrant/.wp-cli/cache/core/wordpress-4.6.1-en_US.tar.gz'... Success: WordPress downloaded. ``` ```bash $ cd wpclidemo.dev $ wp config create --dbname=wpclidemo --dbuser=root --prompt=dbpass 1/10 [--dbpass=<dbpass>]: Success: Generated 'wp-config.php' file. ``` ```bash $ wp db create Success: Database created. ``` ```bash $ wp core install --url=wpclidemo.dev --title="WP-CLI" --admin_user=wpcli --admin_password=wpcli --admin_email=info@wp-cli.org Success: WordPress installed successfully. ``` -------------------------------- ### Example: Plugin Activation with Custom Post Type and Permalinks Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-plugin-handbook.md Demonstrates a common use case for activation hooks: registering a custom post type and flushing rewrite rules to prevent 404 errors. It includes a separate function for setup and the activation hook registration. ```php /** * Register the "book" custom post type */ function pluginprefix_setup_post_type() { register_post_type( 'book', ['public' => true ] ); } add_action( 'init', 'pluginprefix_setup_post_type' ); /** * Activate the plugin. */ function pluginprefix_activate() { // Trigger our function that registers the custom post type plugin. pluginprefix_setup_post_type(); // Clear the permalinks after the post type has been registered. flush_rewrite_rules(); } register_activation_hook( __FILE__, 'pluginprefix_activate' ); ``` -------------------------------- ### Install and Configure WordPress with WP-CLI Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-cli-handbook.md A bash function to automate the WordPress installation and configuration process using WP-CLI. It downloads WordPress core, sets up the database configuration, creates the database, and prompts for core installation details. This function should be added to your ~/.bashrc file. ```bash wp_install () { wp core download --path=$1; cd $1; read -p 'name the database:' dbname; wp config create --dbname=$dbname --dbuser=root --dbpass=awoods --dbhost=localhost; wp db create; wp core install --prompt } ``` -------------------------------- ### Navigate WordPress Installations with a Menu Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-cli-handbook.md This bash script finds all WordPress installations under a specified path, displays a progress bar while fetching blog names, and then presents a menu to select an installation. It requires 'wp-cli/find-command' and 'whiptail'. The output is a 'cd' command to enter the selected directory. ```bash #!/bin/bash WP_TOP_PATH="/home/" MENU_TEXT="Choose an installation" GAUGE_TEXT="Searching for WordPress" declare -a MENU WPS="$(wp --allow-root find "$WP_TOP_PATH" --field=version_path)" WP_TOTAL="$(wc -l <<< "$WPS")" WP_COUNT="0" while read -r WP; do WP_LOCAL="${WP%wp-includes/version.php}" NAME="$(cd "$WP_LOCAL"; sudo -u "$(stat . -c %U)" -- wp --no-debug --quiet option get blogname)" if [ -z "$NAME" ]; then NAME="(unknown)" fi MENU+=( "$WP_LOCAL" "$NAME" ) echo "$((++WP_COUNT * 100 / WP_TOTAL))". done <<< "$WPS" > >(whiptail --gauge "$GAUGE_TEXT" 7 74 0) WP_LOCAL="$(whiptail --title "WordPress" --menu "$MENU_TEXT" $((${#MENU[*]} / 2 + 7)) 74 10 "${MENU[@]}" 3>&1 1>&2 2>&3)" if [ $? -ne 0 ] || [ ! -d "$WP_LOCAL" ]; then echo "Cannot find '${WP_LOCAL}'" 1>&2 exit 100 fi echo "cd ${WP_LOCAL}" ``` -------------------------------- ### WordPress Multisite .htaccess Rewrites (3.5+ Subdomain) Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-adv-admin-handbook.md This .htaccess configuration is for WordPress Multisite installations starting from version 3.5 that use a subdomain setup. It includes rules for index.php, /wp-admin, and rewrites for core WordPress files and PHP scripts. ```apache # BEGIN WordPress RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] # add a trailing slash to /wp-admin RewriteRule ^wp-admin$ wp-admin/ [R=301,L] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^(wp-(content|admin|includes).*) $1 [L] RewriteRule ^(.*\.php)$ wp/$1 [L] RewriteRule . index.php [L] # END WordPress ``` -------------------------------- ### WordPress Multisite .htaccess Rewrites (3.5+ Subdirectory) Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-adv-admin-handbook.md This .htaccess configuration is for WordPress Multisite installations starting from version 3.5 that use a subdirectory setup. It includes rules for handling index.php, /wp-admin, uploaded files, and general WordPress core files. ```apache # BEGIN WordPress RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] # add a trailing slash to /wp-admin RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L] RewriteRule . index.php [L] # END WordPress ``` -------------------------------- ### Initialize WordPress Test Environment Locally Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-cli-handbook.md This script sets up a local WordPress testing environment by downloading WordPress, installing the testing tools, and creating a dedicated database. It requires wget and bash to be installed. The parameters define the database name, user, password, host, and WordPress version. ```bash bash bin/install-wp-tests.sh wordpress_test root '' localhost latest ``` -------------------------------- ### GET Request Example Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-plugin-handbook.md Illustrates a typical GET request to a WordPress REST API endpoint, specifically targeting a books collection. ```APIDOC ## GET Request to Books Endpoint ### Description This example shows how a GET request to a registered 'books' endpoint would be structured and its expected outcome. ### Method GET ### Endpoint `https://ourawesomesite.com/wp-json/my-namespace/v1/books` ### Parameters #### Query Parameters None specified in this example. ### Request Example ```http GET /wp-json/my-namespace/v1/books HTTP/1.1 Host: ourawesomesite.com ``` ### Response #### Success Response (200) - **body** (array) - A JSON array representing the collection of books. #### Response Example ```json [ { "id": 1, "title": "The Great Gatsby", "author": "F. Scott Fitzgerald" }, { "id": 2, "title": "To Kill a Mockingbird", "author": "Harper Lee" } ] ``` ``` -------------------------------- ### Verify WP-CLI Installation Locally Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-cli-handbook.md This command verifies that WP-CLI has been installed correctly within a specific package's development environment. It displays information about the WP-CLI version and its configuration. This is a crucial step after installing dependencies to ensure the setup is functional. ```bash vendor/bin/wp --info ``` -------------------------------- ### Example: WordPress Settings Initialization and Callback Functions Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-plugin-handbook.md Demonstrates a complete example of initializing WordPress settings, including registering a setting, adding a section, and adding a field. It also includes callback functions for rendering the section introduction and the input field itself. This showcases the integration of register_setting, add_settings_section, and add_settings_field. ```php function wporg_settings_init() { // register a new setting for "reading" page register_setting('reading', 'wporg_setting_name'); // register a new section in the "reading" page add_settings_section( 'wporg_settings_section', 'WPOrg Settings Section', 'wporg_settings_section_callback', 'reading' ); // register a new field in the "wporg_settings_section" section, inside the "reading" page add_settings_field( 'wporg_settings_field', 'WPOrg Setting', 'wporg_settings_field_callback', 'reading', 'wporg_settings_section' ); } /** * register wporg_settings_init to the admin_init action hook */ add_action('admin_init', 'wporg_settings_init'); /** * callback functions */ // section content cb function wporg_settings_section_callback() { echo '<p>WPOrg Section Introduction.</p>'; } // field content cb function wporg_settings_field_callback() { // get the value of the setting we've registered with register_setting() $setting = get_option('wporg_setting_name'); // output the field ?> <input type="text" name="wporg_setting_name" value="<?php echo isset( $setting ) ? esc_attr( $setting ) : ''; ?>"> <?php } ``` -------------------------------- ### Set Up WP-CLI Development Environment Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-cli-handbook.md Installs the WP-CLI development environment, including cloning all necessary repositories and preparing automated tests. Requires Composer and a local MySQL or MariaDB server. ```bash git clone https://github.com/wp-cli/wp-cli-dev wp-cli-dev cd wp-cli-dev composer install composer prepare-tests ``` -------------------------------- ### Complete Example: Set, Get, and Use Transients with WP_Query in PHP Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-apis-handbook.md This example demonstrates a common pattern: checking if a transient exists, and if not, regenerating the data (using WP_Query in this case) and saving it as a transient with a specified expiration time. The retrieved data is then used as usual. ```php <?php // Get any existing copy of our transient data if ( false === ( $special_query_results = get_transient( 'special_query_results' ) ) ) { // It wasn't there, so regenerate the data and save the transient $special_query_results = new WP_Query( 'cat=5&order=random&tag=tech&post_meta_key=thumbnail' ); set_transient( 'special_query_results', $special_query_results, 12 * HOUR_IN_SECONDS ); } // Use the data like you would have normally... ?> ``` -------------------------------- ### Secure VirtualHost Example for Apache Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-adv-admin-handbook.md This is an example configuration stanza for a secure virtual host (port 443) in Apache. It includes SSL engine setup, certificate file paths, and rewrite rules to redirect non-wp-admin/wp-includes traffic to the secure site. Note compatibility issues with WordPress 2.8+. ```apache <VirtualHost nnn.nnn.nnn.nnn:443> ServerName www.example.com SSLEngine On SSLCertificateFile /etc/apache2/ssl/thissite.crt SSLCertificateKeyFile /etc/apache2/ssl/thissite.pem SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown DocumentRoot /var/www/mysite <IfModule mod_rewrite.c> RewriteEngine On RewriteRule !^/wp-(admin|includes)/(.*) - [C] RewriteRule ^/(.*) https://www.example.com/$1 [QSA,L] </IfModule> </VirtualHost> ``` -------------------------------- ### Initialize New WordPress Plugin Repository with SVN Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-plugin-handbook.md Guides users through creating a local directory, checking out the SVN repository, and adding initial plugin files to the trunk directory. Ensures the main plugin file is not in a subfolder of trunk. ```bash mkdir my-local-dir svn co https://plugins.svn.wordpress.org/your-plugin-name my-local-dir cd my-local-dir # Add your plugin files to the trunk/ directory svn add trunk/* svn ci -m 'Adding first version of my plugin' ``` -------------------------------- ### Example WP-CLI Command Usage Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-cli-handbook.md Illustrates basic WP-CLI command structure for activating a theme and creating a user. These commands are fundamental for administrative tasks in WordPress via the command line. ```bash wp theme activate wp user create ``` -------------------------------- ### Install WP-CLI Development Environment Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-cli-handbook.md This code snippet demonstrates how to clone the `wp-cli-dev` repository, navigate into the directory, and install the necessary dependencies using Composer. This sets up the local environment for contributing to WP-CLI. ```shell git clone https://github.com/wp-cli/wp-cli-dev cd wp-cli-dev composer install ``` -------------------------------- ### Configuring WP-CLI for shared packages (environment variable) Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-cli-handbook.md This example shows how to configure WP-CLI to use a shared directory for installed packages by setting the `WP_CLI_PACKAGES_DIR` environment variable in `/etc/environment`. This approach allows multiple users on a server to access the same set of WP-CLI packages without individual installations. It overrides the default user-specific package directory (`~/.wp-cli/packages/`). ```bash vim /etc/environment export WP_CLI_PACKAGES_DIR=/usr/local/lib/wp-cli-packages ``` -------------------------------- ### WordPress Multisite URL Functions Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-plugin-handbook.md Provides specific functions for multisite installations to get URLs for the admin, home, and site directories across different sites and the network. These are vital for managing multisite environments. ```php get_admin_url(); get_home_url(); get_site_url(); network_admin_url(); network_site_url(); network_home_url(); ``` -------------------------------- ### Sanitize Integer Input with filter_input Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-plugin-handbook.md This example shows how to sanitize input specifically for an integer using PHP's `filter_input` function with the `FILTER_SANITIZE_NUMBER_INT` filter. This ensures that only numeric characters are retained from the GET parameter 'post_id'. ```php $post_id = filter_input(INPUT_GET, 'post_id', FILTER_SANITIZE_NUMBER_INT); ``` -------------------------------- ### Install WP-CLI using curl and make executable (Shell) Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-cli-handbook.md This code snippet shows the recommended way to install WP-CLI by downloading the Phar build using `curl`, marking it as executable with `chmod`, and moving it to the system's PATH using `mv`. This allows running WP-CLI commands using the `wp` alias. ```bash curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar chmod +x wp-cli.phar sudo mv wp-cli.phar /usr/local/bin/wp ``` -------------------------------- ### Configure WordPress Database Settings (PHP) Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-adv-admin-handbook.md This snippet shows how to define the database connection parameters for a WordPress installation. It includes settings for the database name, username, password, and host. Ensure these match your local database setup. ```php // ** MySQL settings ** // define('DB_NAME', 'wordpress'); // The name of the new database you made define('DB_USER', 'root'); // keep this as is define('DB_PASSWORD', ''); // keep this empty define('DB_HOST', 'localhost'); // 99% chance you won't need to change this ``` -------------------------------- ### Nginx Config: WordPress Multisite Subdomain Setup (<3.4) Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-adv-admin-handbook.md This Nginx configuration is designed for WordPress multisite installations using the subdomain approach for versions 3.4 and below. It handles domain mapping and file serving specific to subdomain configurations. ```nginx # WordPress multisite subdomain config file for WP 3.4 and below. map $http_host $blogid { default -999; #Ref: https://wordpress.org/extend/plugins/nginx-helper/ #include /var/www/wordpress/wp-content/plugins/nginx-helper/map.conf ; } server { server_name example.com *.example.com ; root /var/www/example.com/htdocs; index index.php; location / { try_files $uri $uri/ /index.php?$args ; } location ~ \.php$ { try_files $uri =404; include fastcgi_params; fastcgi_pass php; } #WPMU Files location ~ ^/files/(.*)$ { try_files /wp-content/blogs.dir/$blogid/$uri /wp-includes/ms-files.php?file=$1 ; access_log off; log_not_found off; expires max; } #WPMU x-sendfile to avoid php readfile() location ^~ /blogs.dir { internal; alias /var/www/example.com/htdocs/wp-content/blogs.dir; access_log off; log_not_found off; expires max; } #add some rules for static content expiry-headers here } ``` -------------------------------- ### Retrieve Specific Header using wp_remote_retrieve_header() in PHP Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-apis-handbook.md This example illustrates how to retrieve a specific HTTP header from a remote response using `wp_remote_retrieve_header()` in PHP. It requires the response object and the name of the header to fetch. An alternative is `wp_remote_retrieve_headers()` to get all headers. ```php $last_modified = wp_remote_retrieve_header( $response, 'last-modified' ); ``` -------------------------------- ### WordPress Plugin Readme.txt Header Example Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-plugin-handbook.md This is an example of the standard header information found in a WordPress plugin's readme.txt file. It includes essential metadata about the plugin, such as its name, contributors, requirements, and licensing. ```adoc === Plugin Name === Contributors: (this should be a list of wordpress.org userid's) Donate link: https://example.com/ Tags: tag1, tag2 Requires at least: 4.7 Tested up to: 5.4 Stable tag: 4.3 Requires PHP: 7.0 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html Here is a short description of the plugin. This should be no more than 150 characters. No markup here. ``` -------------------------------- ### Update All Plugins to Latest Version with WP-CLI Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-cli-handbook.md This example shows how to update all installed plugins on a WordPress site to their latest available versions using the `wp plugin update --all` command. It includes output indicating the update process and a summary table. ```bash $ wp plugin update --all Enabling Maintenance mode... Downloading update from https://downloads.wordpress.org/plugin/akismet.3.1.11.zip... Unpacking the update... Installing the latest version... Removing the old version of the plugin... Plugin updated successfully. Downloading update from https://downloads.wordpress.org/plugin/nginx-champuru.3.2.0.zip... Unpacking the update... Installing the latest version... Removing the old version of the plugin... Plugin updated successfully. Disabling Maintenance mode... Success: Updated 2/2 plugins. +------------------------+-------------+-------------+---------+ | name | old_version | new_version | status | +------------------------+-------------+-------------+---------+ | akismet | 3.1.3 | 3.1.11 | Updated | | nginx-cache-controller | 3.1.1 | 3.2.0 | Updated | +------------------------+-------------+-------------+---------+ ``` -------------------------------- ### Generate Starter Code for a WordPress Plugin Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-cli-handbook.md Illustrates the usage of the WP-CLI scaffold command to generate starter code for a new WordPress plugin. This command streamlines the initial setup process for plugin development. ```bash wp scaffold plugin <plugin-name> ``` -------------------------------- ### Complete WordPress Plugin Header Example Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-plugin-handbook.md This example demonstrates a comprehensive WordPress plugin header comment, including all available fields. It provides essential metadata for the plugin, such as version, author, and compatibility information. ```php /* * Plugin Name: My Basics Plugin * Plugin URI: https://example.com/plugins/the-basics/ * Description: Handle the basics with this plugin. * Version: 1.10.3 * Requires at least: 5.2 * Requires PHP: 7.2 * Author: John Smith * Author URI: https://author.example.com/ * License: GPL v2 or later * License URI: https://www.gnu.org/licenses/gpl-2.0.html * Update URI: https://example.com/my-plugin/ * Text Domain: my-basics-plugin * Domain Path: /languages * Requires Plugins: my-plugin, yet-another-plugin */ ``` -------------------------------- ### WordPress Multisite .htaccess Rewrites (3.0-3.4+ Subdomain) Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-adv-admin-handbook.md This .htaccess configuration is for WordPress Multisite installations from version 3.0 through 3.4 that use a subdomain setup. It includes rules for handling index.php and uploaded files, redirecting them to the appropriate WordPress core files. ```apache # BEGIN WordPress RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] # uploaded files RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule . index.php [L] # END WordPress ``` -------------------------------- ### Nginx Config: WordPress Multisite Subdirectory Setup (<3.4) Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-adv-admin-handbook.md This Nginx configuration is for WordPress multisite installations using the subdirectory approach for versions 3.4 and below. It includes map directives for routing files and handling requests, ensuring proper functioning of multisite features. ```nginx map $uri $blogname{ ~^(?P<blogpath>/[^/]+/)files/(.*) $blogpath ; } map $blogname $blogid{ default -999; #Ref: https://wordpress.org/extend/plugins/nginx-helper/ #include /var/www/wordpress/wp-content/plugins/nginx-helper/map.conf ; } server { server_name example.com ; root /var/www/example.com/htdocs; index index.php; location ~ ^(/[^/]+/)?files/(.+) { try_files /wp-content/blogs.dir/$blogid/files/$2 /wp-includes/ms-files.php?file=$2 ; access_log off; log_not_found off; expires max; } #avoid php readfile() location ^~ /blogs.dir { internal; alias /var/www/example.com/htdocs/wp-content/blogs.dir ; access_log off; log_not_found off; expires max; } if (!-e $request_filename) { rewrite /wp-admin$ $scheme://$host$request_uri/ permanent; rewrite ^(/[^/]+)?(/wp-.*) $2 last; rewrite ^(/[^/]+)?(/.*\.php) $2 last; } location / { try_files $uri $uri/ /index.php?$args ; } location ~ \.php$ { try_files $uri =404; include fastcgi_params; fastcgi_pass php; } #add some rules for static content expiry-headers here } ``` -------------------------------- ### Define Cookie Paths (wp-config.php) Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-apis-handbook.md Sets custom paths for WordPress cookies, which can be useful for complex domain setups or multisite installations. It uses WordPress functions to dynamically determine paths. These constants affect how cookies are managed across different parts of the site. ```php define( 'COOKIEPATH', preg_replace( '|https?://[^/]+|i', '', get_option( 'home' ) . '/' ) ); define( 'SITECOOKIEPATH', preg_replace( '|https?://[^/]+|i', '', get_option( 'siteurl' ) . '/' ) ); define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . 'wp-admin' ); define( 'PLUGINS_COOKIE_PATH', preg_replace( '|https?://[^/]+|i', '', WP_PLUGIN_URL ) ); define( 'TEMPLATEPATH', get_template_directory() ); define( 'STYLESHEETPATH', get_stylesheet_directory() ); ``` -------------------------------- ### Local SVN Operations for Trunk Update and Tag Creation Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-plugin-handbook.md This example illustrates the process of updating the trunk directory and creating a new tag from it locally before committing to SVN. This approach simplifies the workflow for developers managing their repositories offline. ```bash svn checkout [repository_root] cd [repository_root] # Update files in /trunk svn copy /trunk /tags/1.2.3 svn commit -m "Update trunk and create tag 1.2.3" ``` -------------------------------- ### WP-CLI Command Synopsis Example Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-cli-handbook.md Illustrates the typical synopsis format for a WP-CLI command, showcasing positional arguments (e.g., `<plugin|zip|url>...`) and optional associative arguments (e.g., `[--version=<version>]`). This defines how users interact with the command. ```bash $ wp plugin install <plugin|zip|url>... [--version=<version>] [--force] [--activate] [--activate-network] ``` -------------------------------- ### Change WordPress Database Table Prefix (PHP) Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-adv-admin-handbook.md This code example demonstrates how to change the default database table prefix 'wp_' in WordPress to a custom prefix. This is often done for security reasons or when installing multiple WordPress instances in the same database. The new prefix should only contain numbers, letters, and underscores. ```php $table_prefix = 'example123_'; // Only numbers, letters, and underscores please! ``` -------------------------------- ### Complete WordPress Table Installation Function Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-plugin-handbook.md This comprehensive PHP function combines table creation (using dbDelta), initial data insertion (using wpdb->insert), and setting a version option. It utilizes global WordPress variables and functions for database operations and file inclusion. ```php <?php global $jal_db_version; $jal_db_version = '1.0'; function jal_install() { global $wpdb; global $jal_db_version; $table_name = $wpdb->prefix . 'liveshoutbox'; $charset_collate = $wpdb->get_charset_collate(); $sql = "CREATE TABLE $table_name ( id mediumint(9) NOT NULL AUTO_INCREMENT, time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, name tinytext NOT NULL, text text NOT NULL, url varchar(55) DEFAULT '' NOT NULL, PRIMARY KEY (id) ) $charset_collate;"; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta( $sql ); add_option( 'jal_db_version', $jal_db_version ); } function jal_install_data() { global $wpdb; $welcome_name = 'Mr. WordPress'; $welcome_text = 'Congratulations, you just completed the installation!'; $table_name = $wpdb->prefix . 'liveshoutbox'; $wpdb->insert( $table_name, array( 'time' => current_time( 'mysql' ), 'name' => $welcome_name, 'text' => $welcome_text, ) ); } ``` -------------------------------- ### Install WP-CLI using Homebrew Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-cli-handbook.md Installs WP-CLI on macOS or Linux systems that have Homebrew package manager installed. This is a straightforward command-line installation. ```bash brew install wp-cli ``` -------------------------------- ### Example POT File Entry Source: https://github.com/kasparsd/wp-docs-md/blob/main/docs/wp-apis-handbook.md A sample entry within a POT (Portable Object Template) file, which serves as a template for translations. It includes metadata like the file and line number where the string originates, the original string (msgid), and an empty string (msgstr) for translation. ```text #: plugin-name.php:123 msgid "Page Title" msgstr "" ```