### Submit Button for Network Installation Source: https://developer.wordpress.org/reference/functions/network_step1 Renders a primary submit button with the text 'Install' to finalize the network setup process. ```php ``` -------------------------------- ### Get All Sites Source: https://developer.wordpress.org/reference/functions/get_sites Retrieves all sites from the WordPress installation. This is a basic usage example. ```php function get_sites( $args = array() ) { $query = new WP_Site_Query(); return $query->query( $args ); } ``` -------------------------------- ### Display WordPress Installer Setup Form Source: https://developer.wordpress.org/reference/functions/display_setup_form This function displays the main setup form for WordPress installation. It includes fields for site title, username, password, and administrator email. It also handles displaying any errors passed to it. ```php function display_setup_form( $error = null ) { global $wpdb; $user_table = ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $wpdb->users ) ) ) !== null ); // Ensure that sites appear in search engines by default. $blog_public = 1; if ( isset( $_POST['weblog_title'] ) ) { $blog_public = isset( $_POST['blog_public'] ) ? (int) $_POST['blog_public'] : $blog_public; } $weblog_title = isset( $_POST['weblog_title'] ) ? trim( wp_unslash( $_POST['weblog_title'] ) ) : ''; $user_name = isset( $_POST['user_name'] ) ? trim( wp_unslash( $_POST['user_name'] ) ) : ''; $admin_email = isset( $_POST['admin_email'] ) ? trim( wp_unslash( $_POST['admin_email'] ) ) : ''; if ( ! is_null( $error ) ) { ?>

``` -------------------------------- ### Example Output of get_plugins() Source: https://developer.wordpress.org/reference/functions/get_plugins This shows the typical array structure returned by the get_plugins() function, detailing each installed plugin's information. ```PHP Array ( [hello-dolly/hello.php] => Array ( [Name] => Hello Dolly [PluginURI] => https://wordpress.org/extend/plugins/hello-dolly/ [Version] => 1.6 [Description] => This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from Hello, Dolly in the upper right of your admin screen on every page. [Author] => Matt Mullenweg [AuthorURI] => http://ma.tt/ [TextDomain] => [DomainPath] => [Network] => [Title] => Hello Dolly [AuthorName] => Matt Mullenweg ) ) ``` -------------------------------- ### Subdomain and Subdirectory Installation Options Source: https://developer.wordpress.org/reference/functions/network_step1 This snippet displays the form table for choosing between subdomain and subdirectory installations. It shows example addresses for each option based on the provided hostname. Use this when configuring a new WordPress multisite network. ```html

``` -------------------------------- ### PHP Examples for get_blog_id_from_url Usage Source: https://developer.wordpress.org/reference/functions/get_blog_id_from_url Demonstrates how to use get_blog_id_from_url for both subdirectory and subdomain installations. Ensure the domain and path are correctly formatted. ```php // For subdirectory installs $blog_id = get_blog_id_from_url( "example.com", "/blog1/" ); // For subdomain installs $blog_id = get_blog_id_from_url( "blog1.example.com" ); ``` -------------------------------- ### install_blog() Source: https://developer.wordpress.org/reference/functions/install_blog Installs an empty blog, creating its associated database tables and options. It's recommended to use switch_to_blog() before calling this function directly. ```APIDOC ## install_blog() ### Description Creates the new blog tables and options. If calling this function directly, be sure to use switch_to_blog() first, so that $wpdb points to the new blog. ### Parameters * **$blog_id** (int) - Required - The value returned by wp_insert_site(). * **$blog_title** (string) - Optional - The title of the new site. Defaults to ''. ### Deprecated This function has been deprecated since 5.1.0. ### Source wp-includes/ms-deprecated.php ``` -------------------------------- ### Get User Blogs Example - WordPress PHP Source: https://developer.wordpress.org/reference/functions/get_blogs_of_user Demonstrates how to retrieve all sites (blogs) associated with a specific user ID in a WordPress multisite setup and display their details. It utilizes the `get_blogs_of_user` function. ```php $user_id = 1; // Replace with the actual user ID $sites = get_blogs_of_user( $user_id ); var_export( $sites ); ``` -------------------------------- ### wp_install() Source: https://developer.wordpress.org/reference/functions/wp_install Installs the site by running the required functions to set up and populate the database, including the primary admin user and initial options. ```APIDOC ## wp_install() ### Description Runs the required functions to set up and populate the database, including primary admin user and initial options. ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * None ### Method * None (This is a PHP function, not an HTTP endpoint) ### Endpoint * None (This is a PHP function, not an HTTP endpoint) ### Parameters `$blog_title` (string, required) - Site title. `$user_name` (string, required) - User’s username. `$user_email` (string, required) - User’s email. `$is_public` (bool, required) - Whether the site is public. `$deprecated` (string, optional) - Not used. Default: '' `$user_password` (string, optional) - User’s chosen password. Default empty (random password). Default: '' `$language` (string, optional) - Language chosen. Default: '' ### Return array - Data for the newly installed site. * `url` (string) - The URL of the site. * `user_id` (int) - The ID of the site owner. * `password` (string) - The password of the site owner, if their user account didn’t already exist. * `password_message` (string) - The explanatory message regarding the password. ### Source `wp-admin/includes/upgrade.php` ``` -------------------------------- ### Register a navigation menu location (extended example) Source: https://developer.wordpress.org/reference/functions/register_nav_menu This is an extended example demonstrating how to register a navigation menu. It's hooked into the 'after_setup_theme' action. ```php add_action( 'after_setup_theme', 'register_primary_menu' ); function register_primary_menu() { register_nav_menu( 'primary', __( 'Primary Menu', 'theme-text-domain' ) ); } ``` -------------------------------- ### Get Users by Search Term Source: https://developer.wordpress.org/reference/functions/get_users Searches for users by username, ID, or email. Wildcard characters (*) can be used for partial matches. For example, 'jo*' will find users whose names, IDs, or emails start with 'jo'. ```php 'john' ) ); // Array of WP_User objects. foreach ( $blogusers as $user ) { echo '' . esc_html( $user->user_email ) . ''; } // Example with wildcard $blogusers_wildcard = get_users( array( 'search' => 'jo*' ) ); foreach ( $blogusers_wildcard as $user ) { echo '' . esc_html( $user->user_email ) . ''; } ``` -------------------------------- ### Example: Get Ancestors for a Page Source: https://developer.wordpress.org/reference/functions/get_ancestors This example shows how to get the ancestor IDs for a given page ID. The function returns an array containing the parent page ID(s) in hierarchical order. ```php ``` -------------------------------- ### Initialize Filesystem and Copy Directory Example Source: https://developer.wordpress.org/reference/functions/copy_dir This example demonstrates how to initialize the WordPress filesystem and then use the copy_dir() function to copy a directory. It includes error handling for filesystem connection and ensures the target directory exists before copying. ```PHP // Connecting to the filesystem. if ( ! WP_Filesystem() ) { // Unable to connect to the filesystem, FTP credentials may be required or something. // You can request these with request_filesystem_credentials() exit; } // Don't forget that the target directory needs to exist. // If it doesn't already, you'll need to create it. global $wp_filesystem; $wp_filesystem->mkdir( $target_dir ); // Now copy all the files in the source directory to the target directory. copy_dir( $src_dir, $target_dir ); ``` -------------------------------- ### Get Post GUID Source: https://developer.wordpress.org/reference/functions/get_the_guid This function retrieves the GUID for a post. It handles cases where the post object might not be fully available and applies a filter to the GUID. ```php function get_the_guid( $post = 0 ) { $post = get_post( $post ); $post_guid = $post->guid ?? ''; $post_id = $post->ID ?? 0; /** * Filters the Global Unique Identifier (guid) of the post. * * @since 1.5.0 * * @param string $post_guid Global Unique Identifier (guid) of the post. * @param int $post_id The post ID. */ return apply_filters( 'get_the_guid', $post_guid, $post_id ); } ``` -------------------------------- ### Theme Setup with load_theme_textdomain() Source: https://developer.wordpress.org/reference/functions/load_theme_textdomain This example demonstrates the recommended way to load a theme's text domain using the 'after_setup_theme' action hook. It specifies the text domain and the path to the languages directory within the theme. ```php add_action('after_setup_theme', 'wpdocs_theme_setup'); /** * Load translations for wpdocs_theme */ function wpdocs_theme_setup(){ load_theme_textdomain('wpdocs_theme', get_template_directory() . '/languages'); } ``` -------------------------------- ### Basic Usage Example for wp_mkdir_p Source: https://developer.wordpress.org/reference/functions/wp_mkdir_p A simple example showing how to call wp_mkdir_p to create a deep directory structure and verify the result. ```php if ( wp_mkdir_p( '/a/really/deep/sub/directory' ) ) { echo __( 'It worked! Now look for a directory named "a".', 'textdomain' ); } ``` -------------------------------- ### Get Installed Translations Source: https://developer.wordpress.org/reference/functions/wp_update_plugins Retrieves installed translations for the WordPress site. Use this to check available language packs for localization. ```php wp_get_installed_translations() ``` -------------------------------- ### Install an Empty Blog using install_blog() Source: https://developer.wordpress.org/reference/functions/install_blog This function has been deprecated since 5.1.0. It creates the new blog tables and options. If calling this function directly, be sure to use switch_to_blog() first, so that $wpdb points to the new blog. ```php function install_blog( $blog_id, $blog_title = '' ) { global $wpdb, $wp_roles; _deprecated_function( __FUNCTION__, '5.1.0' ); // Cast for security. $blog_id = (int) $blog_id; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; $suppress = $wpdb->suppress_errors(); if ( $wpdb->get_results( "DESCRIBE {$wpdb->posts}" ) ) { die( '

' . __( 'Already Installed' ) . '

' . __( 'You appear to have already installed WordPress. To reinstall please clear your old database tables first.' ) . '

' ); } $wpdb->suppress_errors( $suppress ); $url = get_blogaddress_by_id( $blog_id ); // Set everything up. make_db_current_silent( 'blog' ); populate_options(); populate_roles(); // populate_roles() clears previous role definitions so we start over. $wp_roles = new WP_Roles(); $siteurl = $home = untrailingslashit( $url ); if ( ! is_subdomain_install() ) { if ( 'https' === parse_url( get_site_option( 'siteurl' ), PHP_URL_SCHEME ) ) { $siteurl = set_url_scheme( $siteurl, 'https' ); } if ( 'https' === parse_url( get_home_url( get_network()->site_id ), PHP_URL_SCHEME ) ) { $home = set_url_scheme( $home, 'https' ); } } update_option( 'siteurl', $siteurl ); update_option( 'home', $home ); if ( get_site_option( 'ms_files_rewriting' ) ) { update_option( 'upload_path', UPLOADBLOGSDIR . "/$blog_id/files" ); } else { update_option( 'upload_path', get_blog_option( get_network()->site_id, 'upload_path' ) ); } update_option( 'blogname', wp_unslash( $blog_title ) ); update_option( 'admin_email', '' ); // Remove all permissions. $table_prefix = $wpdb->get_blog_prefix(); delete_metadata( 'user', 0, $table_prefix . 'user_level', null, true ); // Delete all. delete_metadata( 'user', 0, $table_prefix . 'capabilities', null, true ); // Delete all. } ``` -------------------------------- ### PHP Example: Get RSS2 Feed Link for Author ID 2 Source: https://developer.wordpress.org/reference/functions/get_author_feed_link This example demonstrates how to get the default RSS2 feed link for a specific author ID (in this case, author ID 2). It directly calls the get_author_feed_link() function. ```php echo get_author_feed_link( '2', '' ); ``` -------------------------------- ### Basic oEmbed Provider Registration Example Source: https://developer.wordpress.org/reference/functions/wp_oembed_add_provider Demonstrates how to register a simple oEmbed provider using a wildcard URL format. This example shows how to associate a custom URL pattern with an oEmbed provider endpoint. ```php ``` -------------------------------- ### User Contributed Example: Displaying Image Dimensions Source: https://developer.wordpress.org/reference/functions/wp_getimagesize An example demonstrating how to get image dimensions from a URL and display them in an IMG tag. ```APIDOC ## Usage Example: Displaying Image Dimensions from URL ### Description This example shows how to obtain image dimensions from a given URL and use them to render an `` tag with width and height attributes. ### Method N/A (PHP Snippet) ### Endpoint N/A ### Parameters None ### Request Example ```php src="" /> ``` ### Response An HTML `` tag with `width` and `height` attributes dynamically generated from the image file. #### Example Output Structure ``` ``` #### Detailed Response Data (`$getimagesize` array) - `$getimagesize[0]` (integer): The width of the image. - `$getimagesize[1]` (integer): The height of the image. - `$getimagesize[2]` (integer): One of the IMAGETYPE_ constants indicating the type of the image. - `$getimagesize[3]` (string): A text string with the correct `height="yyy" width="xxx"` string that can be used directly in an IMG tag. - `$getimagesize['mime']` (string): The correspondent MIME type of the image. - `$getimagesize['channels']` (integer): 3 for RGB pictures and 4 for CMYK pictures. - `$getimagesize['bits']` (integer): The number of bits for each color. ``` -------------------------------- ### Object-Oriented Menu Setup with a Class Source: https://developer.wordpress.org/reference/functions/add_menu_page This example shows how to set up WordPress menus using an object-oriented approach with a class. It includes a static instance method and a method to add the menu page. ```php // For those who are object orientated. Add a class // function as the menu callback and setup the // menus automatically. // Exit if accessed directly if ( !defined( 'ABSPATH' ) ) exit; class MyMenuSetterUpper { private static $instance; /** * Main Instance * * @staticvar array $instance * @return The one true instance */ public static function instance() { if ( ! isset( self::$instance ) ) { self::$instance = new self; self::$instance->addMyAdminMenu(); } return self::$instance; } public function addMyAdminMenu() { add_menu_page( 'My Page Title', 'My Page', 'read', 'my-menu-page-slug', array( $this, 'myAdminPage' ), 'to/icon/file.svg', '2.1' ); } public function myAdminPage() { // Echo the html here... } } // Call the class and add the menus automatically. $MyMenuSetterUpper = MyMenuSetterUpper::instance(); ``` -------------------------------- ### Get the Site URL Source: https://developer.wordpress.org/reference/functions/site_url Retrieves the base URL for the WordPress installation. The output may or may not include '/wordpress/' depending on the installation directory. ```php $url = site_url(); echo $url; ``` -------------------------------- ### Load and Dump All Options Source: https://developer.wordpress.org/reference/functions/update_option This example demonstrates how to load all WordPress options using wp_load_alloptions() and then display them using var_dump(). ```php ``` -------------------------------- ### Basic Post Status Transition Example Source: https://developer.wordpress.org/reference/functions/wp_transition_post_status This example demonstrates how to manually transition a post's status to 'publish' and then trigger the associated WordPress hooks. It includes database update and cache cleaning. ```php global $wpdb; if ( ! $post = get_post( $post ) ) return; if ( 'publish' == $post->post_status ) return; $wpdb->update( $wpdb->posts, array( 'post_status' => 'publish' ), array( 'ID' => $post->ID ) ); clean_post_cache( $post->ID ); $old_status = $post->post_status; $post->post_status = 'publish'; wp_transition_post_status( 'publish', $old_status, $post ); ``` -------------------------------- ### Get Post Type Object Example Source: https://developer.wordpress.org/reference/functions/get_post_type_object This example demonstrates how to retrieve the post type object for 'post' and access its singular name label. ```APIDOC ## get_post_type_object() ### Description Retrieves the properties of a registered post type. ### Parameters #### Path Parameters - **post_type** (string) - Required - The slug of the post type to retrieve. ### Request Example ```php $obj = get_post_type_object( 'post' ); echo $obj->labels->singular_name; ``` ### Response #### Success Response Returns a `WP_Post_Type` object containing the properties of the specified post type. #### Response Example ```php stdClass Object ( [labels] => stdClass Object ( [name] => Posts [singular_name] => Post [add_new] => Add New [add_new_item] => Add New Post [edit_item] => Edit Post [new_item] => New Post [view_item] => View Post [search_items] => Search Posts [not_found] => No posts found [not_found_in_trash] => No posts found in Trash [parent_item_colon] => ) [description] => [publicly_queryable] => 1 [exclude_from_search] => [_builtin] => 1 [_edit_link] => post.php?post=%d [capability_type] => post [hierarchical] => [public] => 1 [rewrite] => [query_var] => [register_meta_box_cb] => [taxonomies] => Array ( ) [show_ui] => 1 [menu_position] => [menu_icon] => [permalink_epmask] => 1 [can_export] => 1 [show_in_nav_menus] => 1 [name] => post [cap] => stdClass Object ( [edit_post] => edit_post [edit_posts] => edit_posts [edit_others_posts] => edit_others_posts [publish_posts] => publish_posts [read_post] => read_post [read_private_posts] => read_private_posts [delete_post] => delete_post ) [label] => Posts ) ``` ``` -------------------------------- ### Get All Installed Plugins Source: https://developer.wordpress.org/reference/functions/get_plugins Retrieves an array of all installed plugins, including their metadata. This function scans the plugin directory and caches the results for performance. ```PHP function get_plugins( $plugin_folder = '' ) { $cache_plugins = wp_cache_get( 'plugins', 'plugins' ); if ( ! $cache_plugins ) { $cache_plugins = array(); } if ( isset( $cache_plugins[ $plugin_folder ] ) ) { return $cache_plugins[ $plugin_folder ]; } $wp_plugins = array(); $plugin_root = WP_PLUGIN_DIR; if ( ! empty( $plugin_folder ) ) { $plugin_root .= $plugin_folder; } // Files in wp-content/plugins directory. $plugins_dir = @opendir( $plugin_root ); $plugin_files = array(); if ( $plugins_dir ) { while ( ( $file = readdir( $plugins_dir ) ) !== false ) { if ( str_starts_with( $file, '.' ) ) { continue; } if ( is_dir( $plugin_root . '/' . $file ) ) { $plugins_subdir = @opendir( $plugin_root . '/' . $file ); if ( $plugins_subdir ) { while ( ( $subfile = readdir( $plugins_subdir ) ) !== false ) { if ( str_starts_with( $subfile, '.' ) ) { continue; } if ( str_ends_with( $subfile, '.php' ) ) { $plugin_files[] = "$file/$subfile"; } } closedir( $plugins_subdir ); } } elseif ( str_ends_with( $file, '.php' ) ) { $plugin_files[] = $file; } } closedir( $plugins_dir ); } if ( empty( $plugin_files ) ) { return $wp_plugins; } foreach ( $plugin_files as $plugin_file ) { if ( ! is_readable( "$plugin_root/$plugin_file" ) ) { continue; } // Do not apply markup/translate as it will be cached. $plugin_data = get_plugin_data( "$plugin_root/$plugin_file", false, false ); if ( empty( $plugin_data['Name'] ) ) { continue; } $wp_plugins[ plugin_basename( $plugin_file ) ] = $plugin_data; } uasort( $wp_plugins, '_sort_uname_callback' ); $cache_plugins[ $plugin_folder ] = $wp_plugins; wp_cache_set( 'plugins', $cache_plugins, 'plugins' ); return $wp_plugins; } ``` -------------------------------- ### Load Plugin Text Domain with 'init' Hook (Recommended) Source: https://developer.wordpress.org/reference/functions/load_plugin_textdomain This example demonstrates the recommended way to load a plugin's text domain using the 'init' hook. It ensures translations are available after all plugins are loaded and avoids early loading warnings. ```php function my_load_plugin_textdomain_function() { load_plugin_textdomain( 'my-plugin-textdomain', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); } add_action( 'init', 'my_load_plugin_textdomain_function', 0 ); ``` -------------------------------- ### get_weekstartend() Source: https://developer.wordpress.org/reference/functions/get_weekstartend Gets the week start and end from the datetime or date string from MySQL. It returns the week start and end dates as Unix timestamps. ```APIDOC ## get_weekstartend() ### Description Gets the week start and end from the datetime or date string from MySQL. ### Parameters #### Path Parameters * **mysqlstring** (string) - Required - Date or datetime field type from MySQL. * **start_of_week** (int|string) - Optional - Start of the week as an integer. Defaults to '' (uses the WordPress option 'start_of_week'). ### Return int[] Week start and end dates as Unix timestamps. - **start** (int) - The week start date as a Unix timestamp. - **end** (int) - The week end date as a Unix timestamp. ### Source `wp-includes/functions.php` ``` -------------------------------- ### setup_userdata() Source: https://developer.wordpress.org/reference/functions/get_userdata Sets up global user variables. ```APIDOC ## setup_userdata() ### Description Sets up global user vars. ### Method Not applicable (PHP function) ### Endpoint Not applicable (PHP function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response None #### Response Example None ``` -------------------------------- ### Get Installed Plugins Source: https://developer.wordpress.org/reference/functions/wp_update_plugins Checks the plugins directory and retrieves all plugin files along with their data. This function is essential for managing and displaying installed plugins. ```php get_plugins() ``` -------------------------------- ### WordPress wp_install Hook Source: https://developer.wordpress.org/reference/functions/wp_install Fires after a site is fully installed. This hook is useful for performing one-time setup tasks after a new WordPress installation is complete. ```php do_action( 'wp_install', WP_User $user ) ``` -------------------------------- ### Usage Example for move_dir() Source: https://developer.wordpress.org/reference/functions/move_dir Demonstrates how to initialize the WordPress Filesystem and call the move_dir() function to relocate a directory. ```php if ( ! WP_Filesystem() ) { exit; } global $wp_filesystem; $from = '/path/to/from_folder_name'; $to = '/path/to/to_folder_name'; $result = move_dir($from, $to); ``` -------------------------------- ### Example Usage of switch_to_blog() and restore_current_blog() Source: https://developer.wordpress.org/reference/functions/restore_current_blog This snippet demonstrates the typical usage pattern of switching to a different blog context and then restoring the original context. Ensure you have the correct blog ID before switching. ```php switch_to_blog( 5 ); /* Do stuff */ restore_current_blog(); ``` -------------------------------- ### Get Post by Slug Source: https://developer.wordpress.org/reference/functions/get_posts Retrieve a post by its slug using the 'name' parameter in the get_posts arguments. This example shows how to get the ID of the first matching post. ```php $the_slug, 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => 1 ); $my_posts = get_posts( $args ); if ( $my_posts ) { printf( __( 'ID on the first post found %s', 'textdomain' ), esc_html( $my_posts[0]->ID ) ); } ``` -------------------------------- ### Check if WordPress is Installed - PHP Source: https://developer.wordpress.org/reference/functions/wp_load_alloptions The `is_blog_installed()` function checks whether WordPress has already been installed on the current site. This is typically used during the initial setup process. ```PHP if ( is_blog_installed() ) { // WordPress is installed. } else { // WordPress is not installed. } ``` -------------------------------- ### Check Network Plugin Activation Source: https://developer.wordpress.org/reference/functions/is_plugin_active_for_network This example demonstrates how to safely include the necessary file and check if a specific plugin is network-activated. ```php // Makes sure the plugin is defined before trying to use it if ( ! function_exists( 'is_plugin_active_for_network' ) ) { require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); } if ( is_plugin_active_for_network( 'plugin-directory/plugin-file.php' ) ) { // Plugin is activated } ``` -------------------------------- ### Get All Bookmarks Source: https://developer.wordpress.org/reference/functions/get_bookmarks Retrieves all bookmarks with default settings. This is a basic usage example. ```php function get_bookmarks( $args = '' ) { global $wpdb; $defaults = array( 'orderby' => 'name', 'order' => 'ASC', 'limit' => -1, 'category' => '', 'category_name' => '', 'hide_invisible' => 1, 'show_updated' => 0, 'include' => '', 'exclude' => '', 'search' => '', ); $parsed_args = wp_parse_args( $args, $defaults ); $key = md5( serialize( $parsed_args ) ); $cache = wp_cache_get( 'get_bookmarks', 'bookmark' ); if ( 'rand' !== $parsed_args['orderby'] && $cache ) { if ( is_array( $cache ) && isset( $cache[ $key ] ) ) { $bookmarks = $cache[ $key ]; /** * Filters the returned list of bookmarks. * * The first time the hook is evaluated in this file, it returns the cached * bookmarks list. The second evaluation returns a cached bookmarks list if the * link category is passed but does not exist. The third evaluation returns * the full cached results. * * @since 2.1.0 * * @see get_bookmarks() * * @param array $bookmarks List of the cached bookmarks. * @param array $parsed_args An array of bookmark query arguments. */ return apply_filters( 'get_bookmarks', $bookmarks, $parsed_args ); } } if ( ! is_array( $cache ) ) { $cache = array(); } $inclusions = ''; if ( ! empty( $parsed_args['include'] ) ) { $parsed_args['exclude'] = ''; // Ignore exclude, category, and category_name params if using include. $parsed_args['category'] = ''; $parsed_args['category_name'] = ''; $inclinks = wp_parse_id_list( $parsed_args['include'] ); if ( count( $inclinks ) ) { foreach ( $inclinks as $inclink ) { if ( empty( $inclusions ) ) { $inclusions = ' AND ( link_id = ' . $inclink . ' '; } else { $inclusions .= ' OR link_id = ' . $inclink . ' '; } } } } if ( ! empty( $inclusions ) ) { $inclusions .= ')'; } $exclusions = ''; if ( ! empty( $parsed_args['exclude'] ) ) { $exlinks = wp_parse_id_list( $parsed_args['exclude'] ); if ( count( $exlinks ) ) { foreach ( $exlinks as $exlink ) { if ( empty( $exclusions ) ) { $exclusions = ' AND ( link_id <> ' . $exlink . ' '; } else { $exclusions .= ' AND link_id <> ' . $exlink . ' '; } } } } if ( ! empty( $exclusions ) ) { $exclusions .= ')'; } if ( ! empty( $parsed_args['category_name'] ) ) { $parsed_args['category'] = get_term_by( 'name', $parsed_args['category_name'], 'link_category' ); if ( $parsed_args['category'] ) { $parsed_args['category'] = $parsed_args['category']->term_id; } else { $cache[ $key ] = array(); wp_cache_set( 'get_bookmarks', $cache, 'bookmark' ); /** This filter is documented in wp-includes/bookmark.php */ return apply_filters( 'get_bookmarks', array(), $parsed_args ); } } $search = ''; if ( ! empty( $parsed_args['search'] ) ) { $like = '%' . $wpdb->esc_like( $parsed_args['search'] ) . '%'; $search = $wpdb->prepare( ' AND ( (link_url LIKE %s) OR (link_name LIKE %s) OR (link_description LIKE %s) ) ', $like, $like, $like ); } $category_query = ''; $join = ''; if ( ! empty( $parsed_args['category'] ) ) { $incategories = wp_parse_id_list( $parsed_args['category'] ); if ( count( $incategories ) ) { foreach ( $incategories as $incat ) { if ( empty( $category_query ) ) { $category_query = ' AND ( tt.term_id = ' . $incat . ' '; } else { $category_query .= ' OR tt.term_id = ' . $incat . ' '; } } } } if ( ! empty( $category_query ) ) { $category_query .= " AND taxonomy = 'link_category'"; $join = " INNER JOIN $wpdb->term_relationships AS tr ON ($wpdb->links.link_id = tr.object_id) INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_taxonomy_id = tr.term_taxonomy_id"; } if ( $parsed_args['show_updated'] ) { $recently_updated_test = ', IF (DATE_ADD(link_updated, INTERVAL 120 MINUTE) >= NOW(), 1,0) as recently_updated '; } else { $recently_updated_test = ''; } $get_updated = ( $parsed_args['show_updated'] ) ? ', UNIX_TIMESTAMP(link_updated) AS link_updated_f ' : ''; $orderby = strtolower( $parsed_args['orderby'] ); $length = ''; switch ( $orderby ) { case 'length': $length = ', CHAR_LENGTH(link_name) AS length'; break; case 'rand': $orderby = 'rand()'; break; case 'link_id': $orderby = "$wpdb->links.link_id"; break; default: $orderparams = array(); $keys = array( 'link_id', 'link_name', 'link_url', 'link_visible', 'link_rating', 'link_owner', 'link_updated', 'link_notes', 'link_description' ); foreach ( explode( ',', $orderby ) as $ordparam ) { $ordparam = trim( $ordparam ); ``` -------------------------------- ### PHP: Example usage of maybe_create_table() Source: https://developer.wordpress.org/reference/functions/maybe_create_table This example demonstrates how to use the `maybe_create_table()` function. It includes the necessary 'upgrade.php' file, defines a table name and SQL statement, and then calls the function. ```php require_once ABSPATH . 'wp-admin/includes/upgrade.php'; global $wpdb; $tablename = 'wpdocs_myTable'; $main_sql_create = 'CREATE TABLE ' . $tablename . ';'; maybe_create_table( $wpdb->prefix . $tablename, $main_sql_create ); ``` -------------------------------- ### POST /wp-admin/includes/upgrade.php/wp_install_defaults Source: https://developer.wordpress.org/reference/functions/wp_install_defaults Initializes a new WordPress site by creating default categories, posts, pages, and widgets associated with the specified user ID. ```APIDOC ## POST /wp_install_defaults ### Description Creates the initial content for a newly-installed site, including the default 'Uncategorized' category, the first post, the first page, and default widgets for the active theme. ### Method POST ### Endpoint wp_install_defaults( int $user_id ) ### Parameters #### Path Parameters - **user_id** (int) - Required - The ID of the user to whom the default content will be assigned. ### Request Example { "user_id": 1 } ### Response #### Success Response (200) - **void** - This function does not return a value; it performs database operations to populate site defaults. #### Response Example { "status": "success", "message": "Default content initialized." } ``` -------------------------------- ### Check WordPress Installation Mode - PHP Source: https://developer.wordpress.org/reference/functions/wp_load_alloptions The `wp_installing()` function checks or sets whether WordPress is currently in installation mode. This is a core function used internally by WordPress to manage the installation process and prevent certain operations during setup. ```PHP if ( wp_installing() ) { // WordPress is currently being installed. } else { // WordPress is not in installation mode. } ``` -------------------------------- ### Get Network Site URL with Path and Scheme Source: https://developer.wordpress.org/reference/functions/network_site_url This example demonstrates how to get a secure URL for a specific page within the current site using the 'https' scheme. ```php // Get a secure URL for a specific page within the current site $url = network_site_url('/contact-us/', 'https'); echo $url; ``` -------------------------------- ### Best Practice Minimal Example for Scheduling Source: https://developer.wordpress.org/reference/functions/wp_schedule_event A minimal, best-practice example for scheduling a daily event using init hook and ensuring the hook is cleared on deactivation. Includes a check to prevent rescheduling if an event is already scheduled. ```php function svd_deactivate() { wp_clear_scheduled_hook( 'svd_cron' ); } add_action('init', function() { add_action( 'svd_cron', 'svd_run_cron' ); register_deactivation_hook( __FILE__, 'svd_deactivate' ); if (! wp_next_scheduled ( 'svd_cron' )) { wp_schedule_event( time(), 'daily', 'svd_cron' ); } }); function svd_run_cron() { // do your stuff. } ``` -------------------------------- ### Example Usage of get_cat_ID() - PHP Source: https://developer.wordpress.org/reference/functions/get_cat_id Demonstrates how to get a category ID by its name and use it with another function. The second argument in the example is a placeholder and not a valid parameter for get_cat_ID(). ```php ``` ```php

The 'Category Name' description is:

``` -------------------------------- ### Basic Block Pattern Registration Example Source: https://developer.wordpress.org/reference/functions/register_block_pattern A fundamental example demonstrating how to register a new block pattern with a title, description, content, categories, keywords, and viewport width. This function should be hooked into the 'init' action. ```php function wpdocs_register_block_patterns() { register_block_pattern( 'wpdocs/my-example', array( 'title' => __( 'My First Block Pattern', 'textdomain' ), 'description' => _x( 'This is my first block pattern', 'Block pattern description', 'textdomain' ), 'content' => '

A single paragraph block style

', 'categories' => array( 'text' ), 'keywords' => array( 'cta', 'demo', 'example' ), 'viewportWidth' => 800, ) ); } add_action( 'init', 'wpdocs_register_block_patterns' ); ``` -------------------------------- ### Get Comment Author URL (User Contributed Note) Source: https://developer.wordpress.org/reference/functions/get_comment_author_url This example shows how to get the comment author's URL using the get_comment_author_url() function. Note that comment_author_url() is used to get the URL as plain text without an anchor tag. ```PHP $comment_author = get_comment_author_url(); ```