- Navigate to the ch3-hide-menu-item folder of the WordPress plugin directory of your development installation.
- Open the ch3-hide-menu-item.php file in a text editor.
- Create a new PHP code file called ch3-hide-menu-item-admin-functions.php in the same directory and open it in a text editor.
- Move the calls to the add_action function and the definition of the ch3hmi_hide_menu_item function to the new file, preceded by a standard PHP open tag and checking for the definition of a constant:
<?php
if ( !defined( 'ch3hmi' ) ) {
exit;
}
- Back in the main plugin code file (ch3-hide-menu-item.php), add code that will define a constant and check whether the current page being rendered is an administration page and proceed to load the administration functions if it is:
define( 'ch3hmi', 1 );
if ( is_admin() ) {
require plugin_dir_path( __FILE__ ) .
'ch3-hide-menu-item-admin-functions.php';
}
- Save and close the plugin file.
- While the plugin will continue to work as it did before, the action hook registration code will only be processed when an administration page is displayed.