03Mar

WordPress, show admin notices, required plugins for a theme

When you create a bespoke theme, you usually need some specific plugins who needs to be activated for a normal use of your theme.
Here is a way to create notice message on your admin area.

Here is just an example, please adapt it to your needs:


add_action('admin_notices', 'showAdminMessages');

function showAdminMessages()
{
    $plugin_messages = array();
    $aRequired_plugins = array();

    include_once( ABSPATH . 'wp-admin/includes/plugin.php' );

    $aRequired_plugins = array(
                                array('name'=>'Advanced Custom Fields', 'download'=>'http://wordpress.org/plugins/advanced-custom-fields/', 'path'=>'advanced-custom-fields/acf.php'),
                                array('name'=>'Custom Taxonomy Order NE', 'download'=>'http://wordpress.org/plugins/custom-taxonomy-order-ne/', 'path'=>'custom-taxonomy-order-ne/customtaxorder.php'),
                                array('name'=>'Relative URL', 'download'=>'http://sparanoid.com/work/relative-url/', 'path'=>'relative-url/relative-url.php' ),
                                array('name'=>'Relevanssi', 'download'=>'https://downloads.wordpress.org/plugin/relevanssi.3.3.8.zip', 'path'=>'relevanssi/relevanssi.php'),
                                array('name'=>'User Role Editor', 'download'=>'https://role-editor.storage.googleapis.com/downloads/user-role-editor-4.18.3.zip', 'path'=>'user-role-editor/user-role-editor.php'),
                                array('name'=>'Yet Another Related Posts Plugin', 'download'=>'https://downloads.wordpress.org/plugin/yet-another-related-posts-plugin.4.2.4.zip', 'path'=>'yet-another-related-posts-plugin/yarpp.php')
    );

    
    foreach($aRequired_plugins as $aPlugin){
        // Check if plugin exists
        if(!is_plugin_active( $aPlugin['path'] ))
        {
            $plugin_messages[] = 'This theme requires you to install the '.$aPlugin['name'].' plugin, download it from here.';
        }
    }

    if(count($plugin_messages) > 0)
    {
        echo '
'; foreach($plugin_messages as $message) { echo '

'.$message.'

'; } echo '
'; } }
Subscribe
Notify of

0 Comments
Inline Feedbacks
View all comments