### 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( '', 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 ); ?>