### Get Plugin Install Screen Views Source: https://developer.wordpress.org/reference/classes/wp_plugin_install_list_table Generates the navigation links for the different plugin installation tabs. It excludes the 'upload' tab as it's no longer a primary view. ```php protected function get_views() { global $tabs, $tab; $display_tabs = array(); foreach ( (array) $tabs as $action => $text ) { $display_tabs[ 'plugin-install-' . $action ] = array( 'url' => self_admin_url( 'plugin-install.php?tab=' . $action ), 'label' => $text, 'current' => $action === $tab, ); } // No longer a real tab. unset( $display_tabs['plugin-install-upload'] ); return $this->get_views_links( $display_tabs ); } ``` -------------------------------- ### Get User Blogs (Non-Multisite) Source: https://developer.wordpress.org/reference/classes/wp_xmlrpc_server Retrieves a list of blogs owned by the user. This is primarily for non-multisite installations. It returns an array containing blog details. ```php $is_admin = current_user_can( 'manage_options' ); $struct = array( 'isAdmin' => $is_admin, 'url' => get_option( 'home' ) . '/', 'blogid' => '1', 'blogName' => get_option( 'blogname' ), 'xmlrpc' => site_url( 'xmlrpc.php', 'rpc' ), ); return array( $struct ); ``` -------------------------------- ### Get User Blogs (Multisite) Source: https://developer.wordpress.org/reference/classes/wp_xmlrpc_server Handles retrieving user blogs in a multisite WordPress setup. It uses a private helper method for multisite-specific logic. ```php $current_blog = get_site(); $domain = $current_blog->domain; $path = $current_blog->path . 'xmlrpc.php'; ``` -------------------------------- ### Demo API Methods Source: https://developer.wordpress.org/reference/classes/wp_xmlrpc_server Example methods for testing XML-RPC connectivity and functionality. ```APIDOC ## demo.sayHello ### Description Tests the XML-RPC connection by returning a simple greeting. ### Method POST ### Endpoint / ### Parameters #### Query Parameters - **method** (string) - Required - The name of the method to call, e.g., "demo.sayHello". - **params** (array) - Required - An empty array for this method. ### Request Example ```json { "method": "demo.sayHello", "params": [], "id": "xmlrpc_id" } ``` ### Response #### Success Response (200) - **result** (string) - The string "Hello!" is returned. #### Response Example ```json { "result": "Hello!", "id": "xmlrpc_id" } ``` ``` ```APIDOC ## demo.addTwoNumbers ### Description Adds two integer numbers together. ### Method POST ### Endpoint / ### Parameters #### Query Parameters - **method** (string) - Required - The name of the method to call, e.g., "demo.addTwoNumbers". - **params** (array) - Required - An array containing two integers. - **0** (integer) - Required - The first number. - **1** (integer) - Required - The second number. ### Request Example ```json { "method": "demo.addTwoNumbers", "params": [5, 3], "id": "xmlrpc_id" } ``` ### Response #### Success Response (200) - **result** (integer) - The sum of the two input numbers. #### Response Example ```json { "result": 8, "id": "xmlrpc_id" } ``` ``` -------------------------------- ### Example of replacing a row with specific data types Source: https://developer.wordpress.org/reference/classes/wpdb This example demonstrates using `replace()` with an array of format specifiers to ensure correct data types are used for insertion or replacement. ```php $wpdb->replace( 'table', array( 'ID' => 456, 'column1' => 'foo', 'column2' => 1337, ), array( '%d', '%s', '%d', ) ); ``` -------------------------------- ### Get Installed Plugin Slugs Source: https://developer.wordpress.org/reference/classes/wp_plugin_install_list_table/get_installed_plugin_slugs Retrieves an array of slugs for all installed plugins. This method is part of the `WP_Plugin_Install_List_Table` class. ```php protected function get_installed_plugin_slugs() { return array_keys( $this->get_installed_plugins() ); } ``` -------------------------------- ### Initialize WordPress Environment Setup Source: https://developer.wordpress.org/reference/classes/wp Sets up the WordPress environment by initializing core components, parsing the request, querying posts, handling 404s, registering global variables, and sending headers. It also fires the 'wp' action hook. ```php public function main( $query_args = '' ) { $this->init(); $parsed = $this->parse_request( $query_args ); if ( $parsed ) { $this->query_posts(); $this->handle_404(); $this->register_globals(); } $this->send_headers(); /** * Fires once the WordPress environment has been set up. * * @since 2.1.0 * * @param WP $wp Current WordPress environment instance (passed by reference). */ do_action_ref_array( 'wp', array( &$this ) ); } ``` -------------------------------- ### Example of replacing a row with default data types Source: https://developer.wordpress.org/reference/classes/wpdb This example shows a basic usage of the `replace()` method where data types are inferred from the input or default to strings if not specified. ```php $wpdb->replace( 'table', array( 'ID' => 123, 'column1' => 'foo', 'column2' => 'bar', ) ); ``` -------------------------------- ### Get Theme Status in WordPress Source: https://developer.wordpress.org/reference/classes/wp_theme_install_list_table This PHP function determines the installation status of a theme by comparing its version with the installed version. It returns 'install', 'latest_installed', 'newer_installed', or 'update_available'. ```php private function _get_theme_status( $theme ) { $status = 'install'; $installed_theme = wp_get_theme( $theme->slug ); if ( $installed_theme->exists() ) { if ( version_compare( $installed_theme->get( 'Version' ), $theme->version, '=' ) ) { $status = 'latest_installed'; } elseif ( version_compare( $installed_theme->get( 'Version' ), $theme->version, '>' ) ) { $status = 'newer_installed'; } else { $status = 'update_available'; } } return $status; } ``` -------------------------------- ### Initialize Theme Installer Skin - PHP Source: https://developer.wordpress.org/reference/classes/theme_installer_skin Sets up the theme installer skin with default arguments for type, URL, theme, nonce, title, and overwrite. ```php class Theme_Installer_Skin extends WP_Upgrader_Skin { public $api; public $type; public $url; public $overwrite; private $is_downgrading = false; /** * Constructor. * * Sets up the theme installer skin. * * @since 2.8.0 * * @param array $args */ public function __construct( $args = array() ) { $defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '', 'overwrite' => '', ); $args = wp_parse_args( $args, $defaults ); $this->type = $args['type']; $this->url = $args['url']; $this->api = $args['api'] ?? array(); $this->overwrite = $args['overwrite']; parent::__construct( $args ); } /** * Performs an action before installing a theme. * * @since 2.8.0 */ public function before() { if ( ! empty( $this->api ) ) { $this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version ); } } /** * Hides the `process_failed` error when updating a theme by uploading a zip file. * * @since 5.5.0 * * @param WP_Error $wp_error WP_Error object. * @return bool True if the error should be hidden, false otherwise. */ public function hide_process_failed( $wp_error ) { if ( 'upload' === $this->type && '' === $this->overwrite && $wp_error->get_error_code() === 'folder_exists' ) { return true; } return false; } /** * Performs an action following a single theme install. * * @since 2.8.0 */ public function after() { if ( $this->do_overwrite() ) { return; } if ( empty( $this->upgrader->result['destination_name'] ) ) { return; } $theme_info = $this->upgrader->theme_info(); if ( empty( $theme_info ) ) { return; } $name = $theme_info->display( 'Name' ); $stylesheet = $this->upgrader->result['destination_name']; $template = $theme_info->get_template(); $activate_link = add_query_arg( array( 'action' => 'activate', 'template' => urlencode( $template ), 'stylesheet' => urlencode( $stylesheet ), ), admin_url( 'themes.php' ) ); $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet ); $install_actions = array(); if ( current_user_can( 'edit_theme_options' ) && ( $theme_info->is_block_theme() || current_user_can( 'customize' ) ) ) { if ( $theme_info->is_block_theme() ) { $customize_url = add_query_arg( array( 'wp_theme_preview' => urlencode( $stylesheet ), 'return' => urlencode( admin_url( 'web' === $this->type ? 'theme-install.php' : 'themes.php' ) ), ), admin_url( 'site-editor.php' ) ); } else { $customize_url = add_query_arg( array( 'theme' => urlencode( $stylesheet ), 'return' => urlencode( admin_url( 'web' === $this->type ? 'theme-install.php' : 'themes.php' ) ), ), admin_url( 'customize.php' ) ); } $install_actions['preview'] = sprintf( ' %s', esc_url( $customize_url ), __( 'Live Preview' ), /* translators: Hidden accessibility text. %s: Theme name. */ sprintf( __( 'Live Preview “%s”' ), $name ) ); } $install_actions['activate'] = sprintf( ' %s', esc_url( $activate_link ), _x( 'Activate', 'theme' ), /* translators: Hidden accessibility text. %s: Theme name. */ sprintf( _x( 'Activate “%s”', 'theme' ), $name ) ); if ( is_network_admin() && current_user_can( 'manage_network_themes' ) ) { $install_actions['network_enable'] = sprintf( '%s', esc_url( wp_nonce_url( 'themes.php?action=enable&theme=' . urlencode( $stylesheet ), 'enable-theme_' . $stylesheet ) ), __( 'Network Enable' ) ); } if ( 'web' === $this->type ) { $install_actions['themes_page'] = sprintf( '%s', self_admin_url( 'theme-install.php' ), __( 'Go to Theme Installer' ) ); } elseif ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) ) { $install_actions['themes_page'] = sprintf( '%s', self_admin_url( 'themes.php' ), __( 'Go to Themes page' ) ); } if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() || ! current_user_can( 'switch_themes' ) ) { unset( $install_actions['activate'], $install_actions['preview'] ); } elseif ( get_option( 'template' ) === $stylesheet ) { unset( $install_actions['activate'] ); } /** ``` -------------------------------- ### Retrieve and Display User Count Source: https://developer.wordpress.org/reference/classes/wpdb Example of using wpdb::get_var to retrieve the total number of users from the database and display it. ```php get_var( "SELECT COUNT(*) FROM $wpdb->users" ); echo "

User count is {$user_count}

"; ?> ``` -------------------------------- ### Get Installed Plugins Data Source: https://developer.wordpress.org/reference/classes/wp_plugin_dependencies/get_plugins Retrieves an array of data for all installed WordPress plugins. This method caches the results after the first call. ```php protected static function get_plugins() { if ( is_array( self::$plugins ) ) { return self::$plugins; } require_once ABSPATH . 'wp-admin/includes/plugin.php'; self::$plugins = get_plugins(); return self::$plugins; } ``` -------------------------------- ### Initialize Theme Installation Strings Source: https://developer.wordpress.org/reference/classes/theme_upgrader/install_strings Sets up default strings for theme installation messages. This method should be called before initiating a theme installation. ```php public function install_strings() { $this->strings['no_package'] = __( 'Installation package not available.' ); /* translators: %s: Package URL. */ $this->strings['downloading_package'] = sprintf( __( 'Downloading installation package from %s…' ), '%s' ); $this->strings['unpack_package'] = __( 'Unpacking the package…' ); $this->strings['installing_package'] = __( 'Installing the theme…' ); $this->strings['remove_old'] = __( 'Removing the old version of the theme…' ); $this->strings['remove_old_failed'] = __( 'Could not remove the old theme.' ); $this->strings['no_files'] = __( 'The theme contains no files.' ); $this->strings['process_failed'] = __( 'Theme installation failed.' ); $this->strings['process_success'] = __( 'Theme installed successfully.' ); /* translators: 1: Theme name, 2: Theme version. */ $this->strings['process_success_specific'] = __( 'Successfully installed the theme %1$s %2$s.' ); $this->strings['parent_theme_search'] = __( 'This theme requires a parent theme. Checking if it is installed…' ); /* translators: 1: Theme name, 2: Theme version. */ $this->strings['parent_theme_prepare_install'] = __( 'Preparing to install %1$s %2$s…' ); /* translators: 1: Theme name, 2: Theme version. */ $this->strings['parent_theme_currently_installed'] = __( 'The parent theme, %1$s %2$s, is currently installed.' ); /* translators: 1: Theme name, 2: Theme version. */ $this->strings['parent_theme_install_success'] = __( 'Successfully installed the parent theme, %1$s %2$s.' ); /* translators: %s: Theme name. */ $this->strings['parent_theme_not_found'] = sprintf( __( 'The parent theme could not be found. You will need to install the parent theme, %s, before you can use this child theme.' ), '%s' ); /* translators: %s: Theme error. */ $this->strings['current_theme_has_errors'] = __( 'The active theme has the following error: "%s".' ); if ( ! empty( $this->skin->overwrite ) ) { if ( 'update-theme' === $this->skin->overwrite ) { $this->strings['installing_package'] = __( 'Updating the theme…' ); $this->strings['process_failed'] = __( 'Theme update failed.' ); $this->strings['process_success'] = __( 'Theme updated successfully.' ); } if ( 'downgrade-theme' === $this->skin->overwrite ) { $this->strings['installing_package'] = __( 'Downgrading the theme…' ); $this->strings['process_failed'] = __( 'Theme downgrade failed.' ); $this->strings['process_success'] = __( 'Theme downgraded successfully.' ); } } } ``` -------------------------------- ### Setting up Help Text and Sidebar Source: https://developer.wordpress.org/reference/classes/custom_image_header This snippet shows how to set up contextual help text and a sidebar with links to documentation and support forums for the custom header screen. ```php get_current_screen()->set_help_sidebar( '

' . __( 'For more information:' ) . '

' . '

' . __( 'Documentation on Custom Header' ) . '

' . '

' . __( 'Support forums' ) . '

' ); ``` -------------------------------- ### WP_REST_Site_Health_Controller::get_directory_sizes Source: https://developer.wordpress.org/reference/classes/wp_error/__construct Gets the current directory sizes for this install. ```APIDOC ## WP_REST_Site_Health_Controller::get_directory_sizes ### Description Gets the current directory sizes for this install. ### Method (Not specified in source) ### Endpoint (Not specified in source) ### Parameters (Not specified in source) ### Request Example (Not specified in source) ### Response #### Success Response (200) (Not specified in source) #### Response Example (Not specified in source) ``` -------------------------------- ### Get Blog Options Source: https://developer.wordpress.org/reference/classes/wp_xmlrpc_server Retrieves specified blog options or all options if none are specified. Requires 'manage_options' capability for certain options. ```php public function wp_getOptions( $args ) { $this->escape( $args ); $username = $args[1]; $password = $args[2]; $options = isset( $args[3] ) ? (array) $args[3] : array(); $user = $this->login( $username, $password ); if ( ! $user ) { return $this->error; } // If no specific options where asked for, return all of them. if ( count( $options ) === 0 ) { $options = array_keys( $this->blog_options ); } return $this->_getOptions( $options ); } ``` -------------------------------- ### Get Dependency Filepaths Source: https://developer.wordpress.org/reference/classes/wp_plugin_dependencies/get_dependency_filepaths Retrieves an array of installed dependency filepaths. If a dependency is not installed, its filepath is set to false. This method should be used when you need to check the installation status and location of multiple plugin dependencies. ```PHP protected static function get_dependency_filepaths() { if ( is_array( self::$dependency_filepaths ) ) { return self::$dependency_filepaths; } if ( null === self::$dependency_slugs ) { return array(); } self::$dependency_filepaths = array(); $plugin_dirnames = self::get_plugin_dirnames(); foreach ( self::$dependency_slugs as $slug ) { if ( isset( $plugin_dirnames[ $slug ] ) ) { self::$dependency_filepaths[ $slug ] = $plugin_dirnames[ $slug ]; continue; } self::$dependency_filepaths[ $slug ] = false; } return self::$dependency_filepaths; } ``` -------------------------------- ### Example of add_setting() Usage Source: https://developer.wordpress.org/reference/classes/wp_customize_manager/add_setting This example demonstrates how to use the add_setting() method with various common parameters like type, capability, default, transport, and sanitization callbacks. ```php $wp_customize->add_setting( 'wpdocs_setting_id', array( 'type' => 'theme_mod', // or 'option' 'capability' => 'edit_theme_options', 'theme_supports' => '', // Rarely needed. 'default' => '', 'transport' => 'refresh', // or postMessage 'sanitize_callback' => '', 'sanitize_js_callback' => '', // Basically to_json. ) ); ``` -------------------------------- ### Theme_Installer_Skin::__construct() Source: https://developer.wordpress.org/reference/classes/theme_installer_skin/__construct Initializes the Theme_Installer_Skin class, setting up the theme installer interface with provided arguments. ```APIDOC ## Theme_Installer_Skin::__construct( array $args = array() ) ### Description Sets up the theme installer skin. ### Parameters #### Parameters - **$args** (array) - Optional - Default: `array()` - An array of arguments to configure the theme installer skin. The defaults include 'type', 'url', 'theme', 'nonce', 'title', and 'overwrite'. ``` -------------------------------- ### Get Plugin Install Table Columns Source: https://developer.wordpress.org/reference/classes/wp_plugin_install_list_table/get_columns Returns an empty array, indicating no custom columns are defined by default for the plugin install list table. ```php public function get_columns() { return array(); } ``` -------------------------------- ### Add Themes Panel and Sections Source: https://developer.wordpress.org/reference/classes/wp_customize_manager/register_controls Registers the 'themes' panel and its associated sections for managing installed and WordPress.org themes. This setup is conditional for multisite installations. ```php public function register_controls() { /* Themes (controls are loaded via ajax) */ $this->add_panel( new WP_Customize_Themes_Panel( $this, 'themes', array( 'title' => $this->theme()->display( 'Name' ), 'description' => ( '

' . __( 'Looking for a theme? You can search or browse the WordPress.org theme directory, install and preview themes, then activate them right here.' ) . '

' . '

' . __( 'While previewing a new theme, you can continue to tailor things like widgets and menus, and explore theme-specific options.' ) . '

' ), 'capability' => 'switch_themes', 'priority' => 0, ) ) ); $this->add_section( new WP_Customize_Themes_Section( $this, 'installed_themes', array( 'title' => __( 'Installed themes' ), 'action' => 'installed', 'capability' => 'switch_themes', 'panel' => 'themes', 'priority' => 0, ) ) ); if ( ! is_multisite() ) { $this->add_section( new WP_Customize_Themes_Section( $this, 'wporg_themes', array( 'title' => __( 'WordPress.org themes' ), 'action' => 'wporg', 'filter_type' => 'remote', 'capability' => 'install_themes', 'panel' => 'themes', 'priority' => 5, ) ) ); } // Themes Setting (unused - the theme is considerably more fundamental to the Customizer experience). $this->add_setting( new WP_Customize_Filter_Setting( $this, 'active_theme', array( 'capability' => 'switch_themes', ) ) ); ``` -------------------------------- ### Plugin_Installer_Skin::__construct() Source: https://developer.wordpress.org/reference/classes/plugin_installer_skin/__construct Initializes the plugin installer skin with provided arguments, setting up default values for type, URL, plugin information, nonce, title, and overwrite options. ```APIDOC ## Plugin_Installer_Skin::__construct( array $args = array() ) ### Description Sets up the plugin installer skin. ### Parameters #### `$args` - `array` optional - Default: `array()` - `type` (string) - The type of installation, defaults to 'web'. - `url` (string) - The URL for the plugin source. - `plugin` (string) - The plugin slug or identifier. - `nonce` (string) - A security nonce for the request. - `title` (string) - The title displayed for the installation. - `overwrite` (string) - Indicates if an existing plugin should be overwritten. ### Source `wp-admin/includes/class-plugin-installer-skin.php` ```php public function __construct( $args = array() ) { $defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '', 'overwrite' => '', ); $args = wp_parse_args( $args, $defaults ); $this->type = $args['type']; $this->url = $args['url']; $this->api = $args['api'] ?? array(); $this->overwrite = $args['overwrite']; parent::__construct( $args ); } ``` ``` -------------------------------- ### Get Blog Table Prefix Source: https://developer.wordpress.org/reference/classes/wpdb Retrieves the table prefix for a given blog ID. Returns the base prefix for single sites or multisite installations with blog ID 0 or 1. Otherwise, appends the blog ID to the base prefix. ```php public function get_blog_prefix( $blog_id = null ) { if ( is_multisite() ) { if ( null === $blog_id ) { $blog_id = $this->blogid; } $blog_id = (int) $blog_id; if ( defined( 'MULTISITE' ) && ( 0 === $blog_id || 1 === $blog_id ) ) { return $this->base_prefix; } else { return $this->base_prefix . $blog_id . '_'; } } else { return $this->base_prefix; } } ``` -------------------------------- ### Initialize Plugin Installation Strings Source: https://developer.wordpress.org/reference/classes/plugin_upgrader/install_strings This method sets default strings for plugin installation steps. It also handles conditional string changes for plugin updates and downgrades based on the `overwrite` property of the skin. ```php public function install_strings() { $this->strings['no_package'] = __( 'Installation package not available.' ); /* translators: %s: Package URL. */ $this->strings['downloading_package'] = sprintf( __( 'Downloading installation package from %s…' ), '%s' ); $this->strings['unpack_package'] = __( 'Unpacking the package…' ); $this->strings['installing_package'] = __( 'Installing the plugin…' ); $this->strings['remove_old'] = __( 'Removing the current plugin…' ); $this->strings['remove_old_failed'] = __( 'Could not remove the current plugin.' ); $this->strings['no_files'] = __( 'The plugin contains no files.' ); $this->strings['process_failed'] = __( 'Plugin installation failed.' ); $this->strings['process_success'] = __( 'Plugin installed successfully.' ); /* translators: 1: Plugin name, 2: Plugin version. */ $this->strings['process_success_specific'] = __( 'Successfully installed the plugin %1$s %2$s.' ); if ( ! empty( $this->skin->overwrite ) ) { if ( 'update-plugin' === $this->skin->overwrite ) { $this->strings['installing_package'] = __( 'Updating the plugin…' ); $this->strings['process_failed'] = __( 'Plugin update failed.' ); $this->strings['process_success'] = __( 'Plugin updated successfully.' ); } if ( 'downgrade-plugin' === $this->skin->overwrite ) { $this->strings['installing_package'] = __( 'Downgrading the plugin…' ); $this->strings['process_failed'] = __( 'Plugin downgrade failed.' ); $this->strings['process_success'] = __( 'Plugin downgraded successfully.' ); } } } ``` -------------------------------- ### Get Installed Plugins List Source: https://developer.wordpress.org/reference/classes/wp_plugin_install_list_table/get_installed_plugins Retrieves a list of installed plugins, including those without updates and those with available updates, from the site's transient data. This method is useful for populating plugin installation tables or lists. ```php protected function get_installed_plugins() { $plugins = array(); $plugin_info = get_site_transient( 'update_plugins' ); if ( isset( $plugin_info->no_update ) ) { foreach ( $plugin_info->no_update as $plugin ) { if ( isset( $plugin->slug ) ) { $plugin->upgrade = false; $plugins[ $plugin->slug ] = $plugin; } } } if ( isset( $plugin_info->response ) ) { foreach ( $plugin_info->response as $plugin ) { if ( isset( $plugin->slug ) ) { $plugin->upgrade = true; $plugins[ $plugin->slug ] = $plugin; } } } return $plugins; } ``` -------------------------------- ### Get All Draft Post Information by User Source: https://developer.wordpress.org/reference/classes/wpdb Retrieves all information for draft posts authored by a specific user and displays their permalinks and titles. ```php get_results( "\nSELECT *\nFROM $wpdb->posts\nWHERE post_status = 'draft'\nAND post_author = 5\n" ); if ( $fivesdrafts ) { foreach ( $fivesdrafts as $post ) { setup_postdata( $post ); ?>

Not Found

``` -------------------------------- ### Basic wpdb::prepare() Usage Source: https://developer.wordpress.org/reference/classes/wpdb/prepare Demonstrates the fundamental usage of wpdb::prepare() with a simple placeholder. ```php public function prepare( $query, ...$args ) { if ( is_null( $query ) ) { return; } /* * This is not meant to be foolproof -- but it will catch obviously incorrect usage. * * Note: str_contains() is not used here, as this file can be included * directly outside of WordPress core, e.g. by HyperDB, in which case * the polyfills from wp-includes/compat.php are not loaded. */ if ( false === strpos( $query, '%' ) ) { wp_load_translations_early(); _doing_it_wrong( 'wpdb::prepare', sprintf( /* translators: %s: wpdb::prepare() */ __( 'The query argument of %s must have a placeholder.' ), 'wpdb::prepare()' ), '3.9.0' ); } /* * Specify the formatting allowed in a placeholder. The following are allowed: * * - Sign specifier, e.g. $+d * - Numbered placeholders, e.g. %1$s * - Padding specifier, including custom padding characters, e.g. %05s, %'#5s * - Alignment specifier, e.g. %05-s * - Precision specifier, e.g. %.2f */ $allowed_format = '(?:[1-9][0-9]*[$])?[-+0-9]*(?: |0|'.)?[-+0-9]*(?:.[0-9]+)?'; /* * If a %s placeholder already has quotes around it, removing the existing quotes * and re-inserting them ensures the quotes are consistent. * * For backward compatibility, this is only applied to %s, and not to placeholders like %1$s, * which are frequently used in the middle of longer strings, or as table name placeholders. */ $query = str_replace( "'%s'", '%s', $query ); // Strip any existing single quotes. $query = str_replace( '"%s"', '%s', $query ); // Strip any existing double quotes. // Escape any unescaped percents (i.e. anything unrecognised). $query = preg_replace( "%(?:%|$|(?!($allowed_format)?[sdfFi]))", '%%\\1', $query ); // Extract placeholders from the query. $split_query = preg_split( "/(^|[^%]|(?:%%)+)(%(?:$allowed_format)?[sdfFi])/, $query, -1, PREG_SPLIT_DELIM_CAPTURE ); $split_query_count = count( $split_query ); /* * Split always returns with 1 value before the first placeholder (even with $query = "%s"), * then 3 additional values per placeholder. */ $placeholder_count = ( ( $split_query_count - 1 ) / 3 ); // If args were passed as an array, as in vsprintf(), move them up. $passed_as_array = ( isset( $args[0] ) && is_array( $args[0] ) && 1 === count( $args ) ); if ( $passed_as_array ) { $args = $args[0]; } $new_query = ''; $key = 2; // Keys 0 and 1 in $split_query contain values before the first placeholder. $arg_id = 0; $arg_identifiers = array(); $arg_strings = array(); while ( $key < $split_query_count ) { $placeholder = $split_query[ $key ]; $format = substr( $placeholder, 1, -1 ); $type = substr( $placeholder, -1 ); if ( 'f' === $type && true === $this->allow_unsafe_unquoted_parameters /* * Note: str_ends_with() is not used here, as this file can be included * directly outside of WordPress core, e.g. by HyperDB, in which case * the polyfills from wp-includes/compat.php are not loaded. */ && '%' === substr( $split_query[ $key - 1 ], -1, 1 ) ) { /* * Before WP 6.2 the "force floats to be locale-unaware" RegEx didn't * convert "%%%f" to "%%%F" (note the uppercase F). * This was because it didn't check to see if the leading "%" was escaped. * And because the "Escape any unescaped percents" RegEx used "[sdF]" in its * negative lookahead assertion, when there was an odd number of "%", it added * an extra "%", to give the fully escaped "%%%%f" (not a placeholder). */ $s = $split_query[ $key - 2 ] . $split_query[ $key - 1 ]; $k = 1; $l = strlen( $s ); while ( $k <= $l && '%' === $s[ $l - $k ] ) { ++$k; } $placeholder = '%' . ( $k % 2 ? '%' : '' ) . $format . $type; --$placeholder_count; } else { // Force floats to be locale-unaware. if ( 'f' === $type ) { $type = 'F'; $placeholder = '%' . $format . $type; } if ( 'i' === $type ) { $placeholder = '`%' . $format . 's`'; // Using a simple strpos() due to previous checking (e.g. $allowed_format). $argnum_pos = strpos( $format, '$' ); if ( false !== $argnum_pos ) { // sprintf() argnum starts at 1, $arg_id from 0. $arg_identifiers[] = ( ( (int) substr( $format, 0, $argnum_pos ) ) - 1 ); } else { $arg_identifiers[] = $arg_id; } } elseif ( 'd' !== $type && 'F' !== $type ) { /* * i.e. ( 's' === $type ), where 'd' and 'F' keeps $placeholder unchanged, * and we ensure string escaping is used as a safe default (e.g. even if 'x'). */ $argnum_pos = strpos( $format, '$' ); if ( false !== $argnum_pos ) { $arg_strings[] = ( ( (int) substr( $format, 0, $argnum_pos ) ) - 1 ); } else { $arg_strings[] = $arg_id; } /* * Unquoted strings for backward compatibility (dangerous). ``` -------------------------------- ### Get Plugin Links Source: https://developer.wordpress.org/reference/classes/wp_rest_block_directory_controller Generates links for a plugin, including installation and direct API endpoints. It checks if the plugin is installed to add the direct API link. ```php 'https://api.w.org/install-plugin' => array( 'href' => add_query_arg( 'slug', urlencode( $plugin['slug'] ), rest_url( 'wp/v2/plugins' ) ), ), ); $plugin_file = $this->find_plugin_for_slug( $plugin['slug'] ); if ( $plugin_file ) { $links['https://api.w.org/plugin'] = array( 'href' => rest_url( 'wp/v2/plugins/' . substr( $plugin_file, 0, - 4 ) ), 'embeddable' => true, ); } return $links; } ``` -------------------------------- ### WP::main() Source: https://developer.wordpress.org/reference/classes/wp/main Sets up all of the variables required by the WordPress environment. It initializes the WordPress object, parses the request, queries posts, handles 404s, registers globals, sends headers, and fires the 'wp' action hook. ```APIDOC ## WP::main( string|array $query_args = '' ) ### Description Sets up all of the variables required by the WordPress environment. The action ‘wp’ has one parameter that references the WP object. It allows for accessing the properties and methods to further manipulate the object. ### Parameters #### Optional Parameters - **$query_args** (string|array) - Passed to parse_request(). Defaults to '' ### Source `wp-includes/class-wp.php` ### Hooks - **do_action_ref_array( ‘wp’, WP $wp )**: Fires once the WordPress environment has been set up. ### Related - **WP::init()**: Set up the current user. - **WP::query_posts()**: Set up the Loop based on the query variables. - **WP::handle_404()**: Set the Headers for 404, if nothing is found for requested URL. - **WP::register_globals()**: Set up the WordPress Globals. - **WP::parse_request()**: Parses the request to find the correct WordPress query. - **WP::send_headers()**: Sends additional HTTP headers for caching, content type, etc. - **do_action_ref_array()**: Calls the callback functions that have been added to an action hook, specifying arguments in an array. ``` -------------------------------- ### Get All Taxonomies Source: https://developer.wordpress.org/reference/classes/wp_xmlrpc_server Retrieves a list of all taxonomies, optionally filtered by arguments. Requires authentication. ```php public function wp_getTaxonomies( $args ) { if ( ! $this->minimum_args( $args, 3 ) ) { return $this->error; } $this->escape( $args ); $username = $args[1]; $password = $args[2]; $filter = $args[3] ?? array( 'public' => true ); if ( isset( $args[4] ) ) { $fields = $args[4]; } else { /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ $fields = apply_filters( 'xmlrpc_default_taxonomy_fields', array( 'labels', 'cap', 'object_type' ), 'wp.getTaxonomies' ); } $user = $this->login( $username, $password ); if ( ! $user ) { return $this->error; } /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ do_action( 'xmlrpc_call', 'wp.getTaxonomies', $args, $this ); $taxonomies = get_taxonomies( $filter, 'objects' ); // Holds all the taxonomy data. $struct = array(); foreach ( $taxonomies as $taxonomy ) { // Capability check for post types. if ( ! current_user_can( $taxonomy->cap->assign_terms ) ) { continue; } $struct[] = $this->_prepare_taxonomy( $taxonomy, $fields ); } return $struct; } ``` -------------------------------- ### Get User Blogs Source: https://developer.wordpress.org/reference/classes/wp_xmlrpc_server Retrieves a list of blogs associated with a user. It checks if the current host and path match the expected values and returns the blogs accordingly. ```php $blogs = $this->wp_getUsersBlogs( $args ); if ( $blogs instanceof IXR_Error ) { return $blogs; } if ( $_SERVER['HTTP_HOST'] === $domain && $_SERVER['REQUEST_URI'] === $path ) { return $blogs; } else { foreach ( (array) $blogs as $blog ) { if ( str_contains( $blog['url'], $_SERVER['HTTP_HOST'] ) ) { return array( $blog ); } } return array(); } ``` -------------------------------- ### wpdb::__construct() Source: https://developer.wordpress.org/reference/classes/wpdb/__construct Connects to the database server and selects a database. This method sets up the class properties and establishes the database connection. ```APIDOC ## wpdb::__construct() ### Description Connects to the database server and selects a database. Does the actual setting up of the class properties and connection to the database. ### Method __construct ### Parameters #### Path Parameters - **dbuser** (string) - Required - Database user. - **dbpassword** (string) - Required - Database password. - **dbname** (string) - Required - Database name. - **dbhost** (string) - Required - Database host. ### Source `wp-includes/class-wpdb.php` ```