Monday, March 4, 2013

[Wordpress][Tutorial] Installing wordpress mu must use plugins with image and example

Mu-plugins, are plugins located at wp-content/mu-plugin folder, and it’s also known as “Must Use plugin”. At usual, it was used for the wordpress multisite version.
About the reason why using mu-plugins is cos it can be automatically enabled on all sites in the installation and the Must-use plugins do not show in the default list of plugins on the Plugins page of wp-admin.

The steps to install Must-use plugin is really easy, you just need to move the source code to the plugin is already okay.

Now I would use my localhost be an example:

Step 1)
Create a folder named “mu-plugins” in your “wp-content” directory:
The wp-content Path :Your_wordpress_root\wp-content For my case my path wp-content is
C:\wamp\www\test\wp-content

Open a folder there.


Step 2)
Create a blank file name your_plugin._name.php. For an example, I use logo.php


Step 3)
Copy the example plugin code to test your plugin file you have just added :

<?php/** * @package fnq *//*Plugin Name: fnqPlugin URI: http://akismet.com/?return=trueDescription: Custom Wordpress plugin, F&QVersion: 0.0.1Author: TestingAuthor URI: fnqLicense: GPLv2 or later*/?><?php
add_action( 'init', 'create_icon_post' );add_filter('manage_edit-gallery_columns', 'add_new_gallery_columns');  function create_icon_post() {    register_post_type( 'logo',//url        array(            'labels' => array(                'name' => 'Logo',                'singular_name' => 'Company Logo',                'add_new' => 'Add New',                'add_new_item' => 'Add New Comapny Logo', //title                'edit' => 'Edit',                'edit_item' => 'Edit Company Logo',                'new_item' => 'New Company Logo',                'view' => 'View',                'view_item' => 'View Company Logo',                'search_items' => 'Search Company Logo',                'not_found' => 'No Company Logo found',                'not_found_in_trash' => 'No Company Logo found in Trash',                'parent' => 'Parent Company Logo'            ),             'public' => true,            'menu_position' => 15,            'supports' => array( 'title', 'editor', 'comments', 'thumbnail', 'custom-fields' ),            'taxonomies' => array( '' ),            'menu_icon' => plugins_url( 'icon_logo.png', __FILE__ ),            'has_archive' => true        )    );}?>
This is the icon to be copy, named "icon_logo.png"
 

Step 4)
Move to your admin panel and refresh the page, you will find the plugin will automatic applied.

 

And you will find it’s will not appear in the installed plugin list.


Making compare:

If you move the plugin file to plugins folder
The plugins folder path :Your_wordpress_root\wp-content For my case my plugins folder path is
C:\wamp\www\test\wp-content


You will find the plugin would be appear in to installed list and need to be activated by the wordpress users, can’t be enabled automatically.



Remarks:
1.          You cannot be disabled except by removing the plugin file from the must-use directory, which is found in wp-content/mu-plugins by default, if you want disable the Must-use plugin, remove it from the folder or delete it.
2.          The must-use plugin cannot run in sub-folder, to know the detail and the solution, please read this article: Autoload Must Use Plugins In Sub Folders In WordPress

Reference

No comments :

Post a Comment