{"id":5720,"date":"2026-02-12T20:45:13","date_gmt":"2026-02-13T01:45:13","guid":{"rendered":"https:\/\/chubes.net\/?documentation=wordpress-plugin-functions"},"modified":"2026-03-13T03:28:51","modified_gmt":"2026-03-13T07:28:51","slug":"wordpress-plugin-functions","status":"publish","type":"documentation","link":"https:\/\/chubes.net\/docs\/wordpress-core\/plugins\/wordpress-plugin-functions\/","title":{"rendered":"WordPress Plugin Functions"},"content":{"rendered":"<p>Core functions for plugin management, URLs, lifecycle hooks, and utilities.<\/p><h2 class=\"wp-block-heading\">Plugin Path &amp; URL Functions<\/h2><h3 class=\"wp-block-heading\"><code>plugin_basename( $file )<\/code><\/h3><p>Extracts the plugin&#8217;s relative path from its absolute file path.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ In your-plugin\/your-plugin.php\n$basename = plugin_basename( __FILE__ );\n\/\/ Returns: &#039;your-plugin\/your-plugin.php&#039;\n\n\/\/ Single-file plugin in plugins root\n$basename = plugin_basename( &#039;\/var\/www\/html\/wp-content\/plugins\/hello.php&#039; );\n\/\/ Returns: &#039;hello.php&#039;<\/code><\/pre><\/div><p><strong>Parameters:<\/strong><\/p><ul class=\"wp-block-list\"><li><code>$file<\/code> (string) &#8211; Absolute path to plugin file<\/li><\/ul><p><strong>Returns:<\/strong> (string) &#8211; Plugin path relative to plugins directory<\/p><p><strong>Source:<\/strong> <code>wp-includes\/plugin.php<\/code><\/p><hr class=\"wp-block-separator\"\/><h3 class=\"wp-block-heading\"><code>plugin_dir_path( $file )<\/code><\/h3><p>Gets the filesystem directory path for a plugin file.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ In your-plugin\/your-plugin.php\n$path = plugin_dir_path( __FILE__ );\n\/\/ Returns: &#039;\/var\/www\/html\/wp-content\/plugins\/your-plugin\/&#039;\n\n\/\/ Use for includes\nrequire_once plugin_dir_path( __FILE__ ) . &#039;includes\/class-loader.php&#039;;<\/code><\/pre><\/div><p><strong>Parameters:<\/strong><\/p><ul class=\"wp-block-list\"><li><code>$file<\/code> (string) &#8211; Plugin&#8217;s <code>__FILE__<\/code> constant<\/li><\/ul><p><strong>Returns:<\/strong> (string) &#8211; Directory path with trailing slash<\/p><p><strong>Source:<\/strong> <code>wp-includes\/plugin.php<\/code><\/p><hr class=\"wp-block-separator\"\/><h3 class=\"wp-block-heading\"><code>plugin_dir_url( $file )<\/code><\/h3><p>Gets the URL directory path for a plugin file.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ In your-plugin\/your-plugin.php\n$url = plugin_dir_url( __FILE__ );\n\/\/ Returns: &#039;https:\/\/example.com\/wp-content\/plugins\/your-plugin\/&#039;\n\n\/\/ Use for assets\nwp_enqueue_script( &#039;my-script&#039;, plugin_dir_url( __FILE__ ) . &#039;js\/script.js&#039; );<\/code><\/pre><\/div><p><strong>Parameters:<\/strong><\/p><ul class=\"wp-block-list\"><li><code>$file<\/code> (string) &#8211; Plugin&#8217;s <code>__FILE__<\/code> constant<\/li><\/ul><p><strong>Returns:<\/strong> (string) &#8211; URL path with trailing slash<\/p><p><strong>Source:<\/strong> <code>wp-includes\/plugin.php<\/code><\/p><hr class=\"wp-block-separator\"\/><h3 class=\"wp-block-heading\"><code>plugins_url( $path, $plugin )<\/code><\/h3><p>Retrieves a URL within the plugins or mu-plugins directory.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Get plugins directory URL\n$url = plugins_url();\n\/\/ Returns: &#039;https:\/\/example.com\/wp-content\/plugins&#039;\n\n\/\/ Get URL to specific file\n$url = plugins_url( &#039;js\/script.js&#039;, __FILE__ );\n\/\/ Returns: &#039;https:\/\/example.com\/wp-content\/plugins\/your-plugin\/js\/script.js&#039;\n\n\/\/ Mu-plugin detection\n\/\/ If $plugin is in WPMU_PLUGIN_DIR, returns WPMU_PLUGIN_URL<\/code><\/pre><\/div><p><strong>Parameters:<\/strong><\/p><ul class=\"wp-block-list\"><li><code>$path<\/code> (string) &#8211; Optional. Relative path within plugin directory. Default empty.<\/li><li><code>$plugin<\/code> (string) &#8211; Optional. Plugin file path. Default empty.<\/li><\/ul><p><strong>Returns:<\/strong> (string) &#8211; Plugins URL with optional path appended<\/p><p><strong>Filter:<\/strong> <code>plugins_url<\/code> &#8211; Modify the returned URL<\/p><p><strong>Source:<\/strong> <code>wp-includes\/link-template.php<\/code><\/p><hr class=\"wp-block-separator\"\/><h3 class=\"wp-block-heading\"><code>wp_register_plugin_realpath( $file )<\/code><\/h3><p>Registers a plugin&#8217;s real path for symlink resolution.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Useful for symlinked plugin development\nwp_register_plugin_realpath( __FILE__ );<\/code><\/pre><\/div><p><strong>Parameters:<\/strong><\/p><ul class=\"wp-block-list\"><li><code>$file<\/code> (string) &#8211; Known path to the file<\/li><\/ul><p><strong>Returns:<\/strong> (bool) &#8211; Whether the path was registered<\/p><p><strong>Source:<\/strong> <code>wp-includes\/plugin.php<\/code><\/p><hr class=\"wp-block-separator\"\/><h2 class=\"wp-block-heading\">Lifecycle Hook Registration<\/h2><h3 class=\"wp-block-heading\"><code>register_activation_hook( $file, $callback )<\/code><\/h3><p>Sets the activation hook for a plugin.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Function callback\nregister_activation_hook( __FILE__, &#039;my_plugin_activate&#039; );\n\nfunction my_plugin_activate() {\n    \/\/ Create database tables\n    \/\/ Set default options\n    \/\/ Flush rewrite rules\n    flush_rewrite_rules();\n}\n\n\/\/ Class method callback\nregister_activation_hook( __FILE__, array( &#039;My_Plugin&#039;, &#039;activate&#039; ) );\n\n\/\/ Object method\nregister_activation_hook( __FILE__, array( $this, &#039;activate&#039; ) );<\/code><\/pre><\/div><p><strong>Parameters:<\/strong><\/p><ul class=\"wp-block-list\"><li><code>$file<\/code> (string) &#8211; Plugin main file path<\/li><li><code>$callback<\/code> (callable) &#8211; Function to run on activation<\/li><\/ul><p><strong>Action fired:<\/strong> <code>activate_{$plugin}<\/code> where <code>$plugin<\/code> is the plugin basename<\/p><p><strong>Source:<\/strong> <code>wp-includes\/plugin.php<\/code><\/p><hr class=\"wp-block-separator\"\/><h3 class=\"wp-block-heading\"><code>register_deactivation_hook( $file, $callback )<\/code><\/h3><p>Sets the deactivation hook for a plugin.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">register_deactivation_hook( __FILE__, &#039;my_plugin_deactivate&#039; );\n\nfunction my_plugin_deactivate() {\n    \/\/ Clear scheduled events\n    wp_clear_scheduled_hook( &#039;my_plugin_cron&#039; );\n    \n    \/\/ Flush rewrite rules\n    flush_rewrite_rules();\n    \n    \/\/ Note: Don&#039;t delete options here - that&#039;s for uninstall\n}<\/code><\/pre><\/div><p><strong>Parameters:<\/strong><\/p><ul class=\"wp-block-list\"><li><code>$file<\/code> (string) &#8211; Plugin main file path<\/li><li><code>$callback<\/code> (callable) &#8211; Function to run on deactivation<\/li><\/ul><p><strong>Action fired:<\/strong> <code>deactivate_{$plugin}<\/code> where <code>$plugin<\/code> is the plugin basename<\/p><p><strong>Source:<\/strong> <code>wp-includes\/plugin.php<\/code><\/p><hr class=\"wp-block-separator\"\/><h3 class=\"wp-block-heading\"><code>register_uninstall_hook( $file, $callback )<\/code><\/h3><p>Sets the uninstallation hook for a plugin.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Must be static method or function\nregister_uninstall_hook( __FILE__, &#039;my_plugin_uninstall&#039; );\n\nfunction my_plugin_uninstall() {\n    \/\/ Delete options\n    delete_option( &#039;my_plugin_settings&#039; );\n    \n    \/\/ Delete custom tables\n    global $wpdb;\n    $wpdb-&gt;query( &quot;DROP TABLE IF EXISTS {$wpdb-&gt;prefix}my_plugin_data&quot; );\n    \n    \/\/ Delete user meta\n    delete_metadata( &#039;user&#039;, 0, &#039;my_plugin_user_data&#039;, &#039;&#039;, true );\n}\n\n\/\/ Class static method\nregister_uninstall_hook( __FILE__, array( &#039;My_Plugin&#039;, &#039;uninstall&#039; ) );<\/code><\/pre><\/div><p><strong>Parameters:<\/strong><\/p><ul class=\"wp-block-list\"><li><code>$file<\/code> (string) &#8211; Plugin file path<\/li><li><code>$callback<\/code> (callable) &#8211; <strong>Must be static method or function<\/strong><\/li><\/ul><p><strong>Note:<\/strong> Alternative is <code>uninstall.php<\/code> file in plugin root.<\/p><p><strong>Source:<\/strong> <code>wp-includes\/plugin.php<\/code><\/p><hr class=\"wp-block-separator\"\/><h2 class=\"wp-block-heading\">Plugin State Functions<\/h2><h3 class=\"wp-block-heading\"><code>is_plugin_active( $plugin )<\/code><\/h3><p>Determines whether a plugin is active.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Check by plugin basename\nif ( is_plugin_active( &#039;woocommerce\/woocommerce.php&#039; ) ) {\n    \/\/ WooCommerce is active\n}\n\n\/\/ Note: Only checks plugins\/ directory, not mu-plugins\/\n\/\/ For mu-plugins, check if class\/function exists instead<\/code><\/pre><\/div><p><strong>Parameters:<\/strong><\/p><ul class=\"wp-block-list\"><li><code>$plugin<\/code> (string) &#8211; Plugin path relative to plugins directory<\/li><\/ul><p><strong>Returns:<\/strong> (bool) &#8211; True if active (site or network), false otherwise<\/p><p><strong>Note:<\/strong> Only available after <code>plugins_loaded<\/code>. Include <code>wp-admin\/includes\/plugin.php<\/code> for frontend use.<\/p><p><strong>Source:<\/strong> <code>wp-admin\/includes\/plugin.php<\/code><\/p><hr class=\"wp-block-separator\"\/><h3 class=\"wp-block-heading\"><code>is_plugin_inactive( $plugin )<\/code><\/h3><p>Determines whether a plugin is inactive. Reverse of <code>is_plugin_active()<\/code>.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">if ( is_plugin_inactive( &#039;old-plugin\/old-plugin.php&#039; ) ) {\n    \/\/ Plugin is not active\n}<\/code><\/pre><\/div><p><strong>Source:<\/strong> <code>wp-admin\/includes\/plugin.php<\/code><\/p><hr class=\"wp-block-separator\"\/><h3 class=\"wp-block-heading\"><code>is_plugin_active_for_network( $plugin )<\/code><\/h3><p>Determines whether a plugin is network-activated (Multisite only).<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">if ( is_plugin_active_for_network( &#039;my-plugin\/my-plugin.php&#039; ) ) {\n    \/\/ Plugin is network-activated\n}<\/code><\/pre><\/div><p><strong>Returns:<\/strong> (bool) &#8211; True if network-activated, false if single-site active or inactive<\/p><p><strong>Source:<\/strong> <code>wp-admin\/includes\/plugin.php<\/code><\/p><hr class=\"wp-block-separator\"\/><h3 class=\"wp-block-heading\"><code>is_network_only_plugin( $plugin )<\/code><\/h3><p>Checks for &quot;Network: true&quot; in the plugin header.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">if ( is_network_only_plugin( &#039;multisite-only\/multisite-only.php&#039; ) ) {\n    \/\/ Plugin requires network activation\n}<\/code><\/pre><\/div><p><strong>Source:<\/strong> <code>wp-admin\/includes\/plugin.php<\/code><\/p><hr class=\"wp-block-separator\"\/><h2 class=\"wp-block-heading\">Plugin Management Functions<\/h2><h3 class=\"wp-block-heading\"><code>activate_plugin( $plugin, $redirect, $network_wide, $silent )<\/code><\/h3><p>Attempts to activate a plugin.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Basic activation\n$result = activate_plugin( &#039;my-plugin\/my-plugin.php&#039; );\n\nif ( is_wp_error( $result ) ) {\n    echo $result-&gt;get_error_message();\n}\n\n\/\/ Network-wide activation\nactivate_plugin( &#039;my-plugin\/my-plugin.php&#039;, &#039;&#039;, true );\n\n\/\/ Silent activation (skip hooks)\nactivate_plugin( &#039;my-plugin\/my-plugin.php&#039;, &#039;&#039;, false, true );<\/code><\/pre><\/div><p><strong>Parameters:<\/strong><\/p><ul class=\"wp-block-list\"><li><code>$plugin<\/code> (string) &#8211; Plugin path relative to plugins directory<\/li><li><code>$redirect<\/code> (string) &#8211; Optional. URL to redirect on success. Default empty.<\/li><li><code>$network_wide<\/code> (bool) &#8211; Optional. Network activation (Multisite). Default false.<\/li><li><code>$silent<\/code> (bool) &#8211; Optional. Skip activation hooks. Default false.<\/li><\/ul><p><strong>Returns:<\/strong> <code>null|WP_Error<\/code> &#8211; Null on success, WP_Error on failure<\/p><p><strong>Source:<\/strong> <code>wp-admin\/includes\/plugin.php<\/code><\/p><hr class=\"wp-block-separator\"\/><h3 class=\"wp-block-heading\"><code>deactivate_plugins( $plugins, $silent, $network_wide )<\/code><\/h3><p>Deactivates one or more plugins.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Single plugin\ndeactivate_plugins( &#039;my-plugin\/my-plugin.php&#039; );\n\n\/\/ Multiple plugins\ndeactivate_plugins( array(\n    &#039;plugin-one\/plugin-one.php&#039;,\n    &#039;plugin-two\/plugin-two.php&#039;\n) );\n\n\/\/ Silent deactivation (skip hooks)\ndeactivate_plugins( &#039;my-plugin\/my-plugin.php&#039;, true );\n\n\/\/ Network-wide deactivation\ndeactivate_plugins( &#039;my-plugin\/my-plugin.php&#039;, false, true );<\/code><\/pre><\/div><p><strong>Parameters:<\/strong><\/p><ul class=\"wp-block-list\"><li><code>$plugins<\/code> (string|string[]) &#8211; Single plugin or array of plugins<\/li><li><code>$silent<\/code> (bool) &#8211; Optional. Skip deactivation hooks. Default false.<\/li><li><code>$network_wide<\/code> (bool|null) &#8211; Optional. Network deactivation. Default null (both).<\/li><\/ul><p><strong>Source:<\/strong> <code>wp-admin\/includes\/plugin.php<\/code><\/p><hr class=\"wp-block-separator\"\/><h3 class=\"wp-block-heading\"><code>activate_plugins( $plugins, $redirect, $network_wide, $silent )<\/code><\/h3><p>Activates multiple plugins.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">$result = activate_plugins( array(\n    &#039;plugin-one\/plugin-one.php&#039;,\n    &#039;plugin-two\/plugin-two.php&#039;\n) );\n\nif ( is_wp_error( $result ) ) {\n    \/\/ Contains array of individual plugin errors\n    $errors = $result-&gt;get_error_data();\n}<\/code><\/pre><\/div><p><strong>Returns:<\/strong> <code>true|WP_Error<\/code> &#8211; True on success, WP_Error with plugin errors on failure<\/p><p><strong>Source:<\/strong> <code>wp-admin\/includes\/plugin.php<\/code><\/p><hr class=\"wp-block-separator\"\/><h3 class=\"wp-block-heading\"><code>delete_plugins( $plugins )<\/code><\/h3><p>Removes plugin files and directories.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">$result = delete_plugins( array( &#039;old-plugin\/old-plugin.php&#039; ) );\n\nif ( is_wp_error( $result ) ) {\n    echo $result-&gt;get_error_message();\n}<\/code><\/pre><\/div><p><strong>Parameters:<\/strong><\/p><ul class=\"wp-block-list\"><li><code>$plugins<\/code> (string[]) &#8211; Array of plugin paths to delete<\/li><\/ul><p><strong>Returns:<\/strong> <code>bool|null|WP_Error<\/code> &#8211; True on success, false if empty, WP_Error on failure, null if credentials needed<\/p><p><strong>Source:<\/strong> <code>wp-admin\/includes\/plugin.php<\/code><\/p><hr class=\"wp-block-separator\"\/><h2 class=\"wp-block-heading\">Plugin Data Functions<\/h2><h3 class=\"wp-block-heading\"><code>get_plugin_data( $plugin_file, $markup, $translate )<\/code><\/h3><p>Parses plugin file to retrieve metadata.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">$data = get_plugin_data( WP_PLUGIN_DIR . &#039;\/my-plugin\/my-plugin.php&#039; );\n\n\/*\nReturns:\narray(\n    &#039;Name&#039;            =&gt; &#039;My Plugin&#039;,\n    &#039;PluginURI&#039;       =&gt; &#039;https:\/\/example.com\/my-plugin&#039;,\n    &#039;Version&#039;         =&gt; &#039;1.0.0&#039;,\n    &#039;Description&#039;     =&gt; &#039;Plugin description.&#039;,\n    &#039;Author&#039;          =&gt; &#039;Author Name&#039;,\n    &#039;AuthorURI&#039;       =&gt; &#039;https:\/\/example.com&#039;,\n    &#039;TextDomain&#039;      =&gt; &#039;my-plugin&#039;,\n    &#039;DomainPath&#039;      =&gt; &#039;\/languages&#039;,\n    &#039;Network&#039;         =&gt; false,\n    &#039;RequiresWP&#039;      =&gt; &#039;6.0&#039;,\n    &#039;RequiresPHP&#039;     =&gt; &#039;7.4&#039;,\n    &#039;UpdateURI&#039;       =&gt; &#039;&#039;,\n    &#039;RequiresPlugins&#039; =&gt; &#039;woocommerce&#039;,\n    &#039;Title&#039;           =&gt; &#039;My Plugin&#039;,\n    &#039;AuthorName&#039;      =&gt; &#039;Author Name&#039;,\n)\n*\/\n\n\/\/ Without markup (links)\n$data = get_plugin_data( $file, false );\n\n\/\/ Without translation\n$data = get_plugin_data( $file, true, false );<\/code><\/pre><\/div><p><strong>Parameters:<\/strong><\/p><ul class=\"wp-block-list\"><li><code>$plugin_file<\/code> (string) &#8211; Absolute path to main plugin file<\/li><li><code>$markup<\/code> (bool) &#8211; Optional. Apply HTML markup. Default true.<\/li><li><code>$translate<\/code> (bool) &#8211; Optional. Translate strings. Default true.<\/li><\/ul><p><strong>Returns:<\/strong> (array) &#8211; Plugin data array<\/p><p><strong>Source:<\/strong> <code>wp-admin\/includes\/plugin.php<\/code><\/p><hr class=\"wp-block-separator\"\/><h3 class=\"wp-block-heading\"><code>get_plugins( $plugin_folder )<\/code><\/h3><p>Gets all installed plugins with their data.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">$all_plugins = get_plugins();\n\nforeach ( $all_plugins as $plugin_path =&gt; $plugin_data ) {\n    echo $plugin_data[&#039;Name&#039;] . &#039;: &#039; . $plugin_data[&#039;Version&#039;];\n}\n\n\/\/ Get plugins from specific folder\n$subfolder_plugins = get_plugins( &#039;\/my-folder&#039; );<\/code><\/pre><\/div><p><strong>Parameters:<\/strong><\/p><ul class=\"wp-block-list\"><li><code>$plugin_folder<\/code> (string) &#8211; Optional. Relative path to subfolder. Default empty.<\/li><\/ul><p><strong>Returns:<\/strong> (array[]) &#8211; Array of plugin data arrays, keyed by plugin file<\/p><p><strong>Source:<\/strong> <code>wp-admin\/includes\/plugin.php<\/code><\/p><hr class=\"wp-block-separator\"\/><h3 class=\"wp-block-heading\"><code>get_mu_plugins()<\/code><\/h3><p>Gets all must-use plugins.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">$mu_plugins = get_mu_plugins();\n\nforeach ( $mu_plugins as $file =&gt; $data ) {\n    echo $data[&#039;Name&#039;];\n}<\/code><\/pre><\/div><p><strong>Returns:<\/strong> (array[]) &#8211; Array of mu-plugin data arrays, keyed by filename<\/p><p><strong>Source:<\/strong> <code>wp-admin\/includes\/plugin.php<\/code><\/p><hr class=\"wp-block-separator\"\/><h3 class=\"wp-block-heading\"><code>get_dropins()<\/code><\/h3><p>Gets all drop-in plugins.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">$dropins = get_dropins();\n\n\/\/ Check if object cache is in use\nif ( isset( $dropins[&#039;object-cache.php&#039;] ) ) {\n    echo &#039;Object cache plugin active&#039;;\n}<\/code><\/pre><\/div><p><strong>Returns:<\/strong> (array[]) &#8211; Array of drop-in data arrays, keyed by filename<\/p><p><strong>Source:<\/strong> <code>wp-admin\/includes\/plugin.php<\/code><\/p><hr class=\"wp-block-separator\"\/><h3 class=\"wp-block-heading\"><code>get_plugin_files( $plugin )<\/code><\/h3><p>Gets list of files belonging to a plugin.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">$files = get_plugin_files( &#039;my-plugin\/my-plugin.php&#039; );\n\n\/*\nReturns array of relative paths:\narray(\n    &#039;my-plugin\/my-plugin.php&#039;,\n    &#039;my-plugin\/includes\/class-main.php&#039;,\n    &#039;my-plugin\/assets\/style.css&#039;,\n    ...\n)\n*\/<\/code><\/pre><\/div><p><strong>Parameters:<\/strong><\/p><ul class=\"wp-block-list\"><li><code>$plugin<\/code> (string) &#8211; Plugin path relative to plugins directory<\/li><\/ul><p><strong>Returns:<\/strong> (string[]) &#8211; Array of file paths relative to plugin root<\/p><p><strong>Filter:<\/strong> <code>plugin_files_exclusions<\/code> &#8211; Directories\/files to exclude from scan<\/p><p><strong>Source:<\/strong> <code>wp-admin\/includes\/plugin.php<\/code><\/p><hr class=\"wp-block-separator\"\/><h2 class=\"wp-block-heading\">Validation Functions<\/h2><h3 class=\"wp-block-heading\"><code>validate_plugin( $plugin )<\/code><\/h3><p>Validates plugin path and header.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">$result = validate_plugin( &#039;my-plugin\/my-plugin.php&#039; );\n\nif ( is_wp_error( $result ) ) {\n    switch ( $result-&gt;get_error_code() ) {\n        case &#039;plugin_invalid&#039;:\n            \/\/ Invalid path\n            break;\n        case &#039;plugin_not_found&#039;:\n            \/\/ File doesn&#039;t exist\n            break;\n        case &#039;no_plugin_header&#039;:\n            \/\/ No valid plugin header\n            break;\n    }\n}<\/code><\/pre><\/div><p><strong>Returns:<\/strong> <code>int|WP_Error<\/code> &#8211; 0 on success, WP_Error on failure<\/p><p><strong>Source:<\/strong> <code>wp-admin\/includes\/plugin.php<\/code><\/p><hr class=\"wp-block-separator\"\/><h3 class=\"wp-block-heading\"><code>validate_plugin_requirements( $plugin )<\/code><\/h3><p>Validates WordPress and PHP version requirements.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">$result = validate_plugin_requirements( &#039;my-plugin\/my-plugin.php&#039; );\n\nif ( is_wp_error( $result ) ) {\n    \/\/ Requirements not met\n    echo $result-&gt;get_error_message();\n}<\/code><\/pre><\/div><p><strong>Returns:<\/strong> <code>true|WP_Error<\/code> &#8211; True if requirements met, WP_Error otherwise<\/p><p><strong>Error codes:<\/strong><\/p><ul class=\"wp-block-list\"><li><code>plugin_wp_php_incompatible<\/code> &#8211; Both WP and PHP requirements failed<\/li><li><code>plugin_php_incompatible<\/code> &#8211; PHP version too low<\/li><li><code>plugin_wp_incompatible<\/code> &#8211; WordPress version too low<\/li><\/ul><p><strong>Source:<\/strong> <code>wp-admin\/includes\/plugin.php<\/code><\/p><hr class=\"wp-block-separator\"\/><h3 class=\"wp-block-heading\"><code>validate_active_plugins()<\/code><\/h3><p>Validates all active plugins, deactivating invalid ones.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">$invalid = validate_active_plugins();\n\nforeach ( $invalid as $plugin =&gt; $error ) {\n    echo $plugin . &#039;: &#039; . $error-&gt;get_error_message();\n}<\/code><\/pre><\/div><p><strong>Returns:<\/strong> (WP_Error[]) &#8211; Array of errors keyed by plugin file<\/p><p><strong>Source:<\/strong> <code>wp-admin\/includes\/plugin.php<\/code><\/p><hr class=\"wp-block-separator\"\/><h2 class=\"wp-block-heading\">Admin Menu Functions<\/h2><h3 class=\"wp-block-heading\"><code>get_plugin_page_hook( $plugin_page, $parent_page )<\/code><\/h3><p>Gets the hook name for a plugin admin page.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">$hook = get_plugin_page_hook( &#039;my-settings&#039;, &#039;options-general.php&#039; );\n\/\/ Returns: &#039;settings_page_my-settings&#039;<\/code><\/pre><\/div><p><strong>Source:<\/strong> <code>wp-admin\/includes\/plugin.php<\/code><\/p><hr class=\"wp-block-separator\"\/><h3 class=\"wp-block-heading\"><code>get_plugin_page_hookname( $plugin_page, $parent_page )<\/code><\/h3><p>Gets the hookname for plugin page output.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">$hookname = get_plugin_page_hookname( &#039;my-settings&#039;, &#039;options-general.php&#039; );<\/code><\/pre><\/div><p><strong>Source:<\/strong> <code>wp-admin\/includes\/plugin.php<\/code><\/p><hr class=\"wp-block-separator\"\/><h2 class=\"wp-block-heading\">Utility Functions<\/h2><h3 class=\"wp-block-heading\"><code>plugin_sandbox_scrape( $plugin )<\/code><\/h3><p>Loads a plugin in a sandbox for testing fatal errors.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Used internally during activation\nplugin_sandbox_scrape( &#039;my-plugin\/my-plugin.php&#039; );<\/code><\/pre><\/div><p><strong>Source:<\/strong> <code>wp-admin\/includes\/plugin.php<\/code><\/p><hr class=\"wp-block-separator\"\/><h3 class=\"wp-block-heading\"><code>is_uninstallable_plugin( $plugin )<\/code><\/h3><p>Checks if plugin has registered an uninstall hook or has uninstall.php.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">if ( is_uninstallable_plugin( &#039;my-plugin\/my-plugin.php&#039; ) ) {\n    \/\/ Will run cleanup on deletion\n}<\/code><\/pre><\/div><p><strong>Source:<\/strong> <code>wp-admin\/includes\/plugin.php<\/code><\/p><hr class=\"wp-block-separator\"\/><h3 class=\"wp-block-heading\"><code>uninstall_plugin( $plugin )<\/code><\/h3><p>Runs the plugin&#8217;s uninstall routine.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Called automatically during delete_plugins()\nuninstall_plugin( &#039;my-plugin\/my-plugin.php&#039; );<\/code><\/pre><\/div><p><strong>Source:<\/strong> <code>wp-admin\/includes\/plugin.php<\/code><\/p>","protected":false},"excerpt":{"rendered":"<p>Core functions for plugin management, URLs, lifecycle hooks, and utilities. Plugin Path &amp; URL Functions plugin_basename( $file ) Extracts the plugin&#8217;s relative path from its absolute file path. \/\/ In&#8230;<\/p>\n","protected":false},"featured_media":0,"template":"","meta":{"footnotes":""},"tags":[],"project":[646],"project_type":[749],"class_list":["post-5720","documentation","type-documentation","status-publish","hentry","project-plugins","project_type-wordpress-reference"],"project_info":{"id":589,"name":"WordPress Core","slug":"wordpress-core"},"project_type_info":{"id":749,"name":"WordPress Reference","slug":"wordpress-reference"},"_links":{"self":[{"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/documentation\/5720","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/documentation"}],"about":[{"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/types\/documentation"}],"version-history":[{"count":3,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/documentation\/5720\/revisions"}],"predecessor-version":[{"id":8823,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/documentation\/5720\/revisions\/8823"}],"wp:attachment":[{"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/media?parent=5720"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/tags?post=5720"},{"taxonomy":"project","embeddable":true,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/project?post=5720"},{"taxonomy":"project_type","embeddable":true,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/project_type?post=5720"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}