• I know I’m probubly beating a dead horse here but is it possible to dynamicly add a Menu item to the top Admin Menu?

    Admin Menu Example

    I hardcoded the ‘Galleries’ link on the menu. But I’d like for it to appear when I ‘Activate’ the plugin and dissappear when the plugin is ‘Disactivated’.

    Can this be done with 1.2? If so, how? If not, can it be done with 1.5? If so, how?

    Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Spaminator and Spamkarma do this in 1.5 . check their code ?

    This is a copy of a plugin that adds backup/restore to options in 1.5. I can’t get in to work with 1.2.2 though:
    <?php
    /*
    Plugin Name: Backup/Restore
    Plugin URI:
    Description: Enables Backup/Restore from the Admin menu
    Version: 1.0
    Author:
    Author URI:
    */
    $menu[46] = array('Backup/Restore', 10, 'backupRestore.php');
    ?>

    This is also done in the Dashboard for 1.2.x, i.e. the Dashboard option is added to the admin menu.
    see here:
    https://dan.hersam.com/archives/2004/12/13/wordpress-12x-dashboard

    I think you “only” need to edit wp-admin/menu.php and add the file needed. See Dashboard’s code for information. ??

    Thread Starter zephyrsky

    (@zephyrsky)

    Looks like this functionality is not in 1.2. The functions alphaoide linked to aren’t available in 1.2 so they probubly only work in 1.5.

    And it appears that doing:

    $menu[46] = array(‘Backup/Restore’, 10, ‘backupRestore.php’)

    doesn’t work either. So as a cheap hack I put this in menu.php under where the $menu array is created:

    // Add gallery to the Admin Menu
    include(‘../wp-content/plugins/galleries/galleries_functions.php’);
    $add_menu = new galleries();
    $menu = $add_menu->gallery_add_menu($menu);

    The gallery_functions.php file will check to see if the plugin is loaded and if so it will insert the ‘Galleries’ Item in the admin menu. Below is galleries_functions.php in case anyone is interested:

    <?php

    class galleries
    {

    //
    // This check to see if Galleries is installed. If so it will add it to the menu
    //
    function gallery_add_menu($menu) {
    $newset_menu = $menu;
    $installed = galleries::check_installed();
    $array_counter = 0;
    if ($installed) {
    foreach ($menu as $menu2)
    {
    if ($array_counter == 2)
    {
    $menu3[$array_counter] = array(‘Galleries’, 3, ‘galleries.php’, ‘Galleries’);
    ++$array_counter;
    $menu3[$array_counter] = $menu2;
    } else {
    $menu3[$array_counter] = $menu2;
    }
    ++$array_counter;
    }
    return $menu3;
    } else {
    // not installed
    return $menu;
    }
    }

    //
    // Adapted from wp-plugin-list.php from Matt Read
    //
    function check_installed() {

    $installed = false;

    // Files in wp-content/plugins directory
    $plugins_dir = @ dir(ABSPATH . ‘wp-content/plugins’);
    if ($plugins_dir) {
    while(($file = $plugins_dir->read()) !== false) {
    if ( !preg_match(‘|^\.+$|’, $file) && preg_match(‘|\.php$|’, $file) )
    $plugin_files[] = $file;
    }
    }

    if (” != trim(get_settings(‘active_plugins’))) {
    $current_plugins = explode(“\n”, (get_settings(‘active_plugins’)));
    }

    if (!$plugins_dir || !$plugin_files) {
    _e(“Error”); // TODO: make more helpful
    break;
    } else {

    sort($plugin_files); // Alphabetize by filename. Better way?
    $style = ”;
    foreach($plugin_files as $plugin_file) {
    $plugin_data = implode(”, file(ABSPATH . ‘/wp-content/plugins/’ . $plugin_file));
    preg_match(“|Plugin Name:(.*)|i”, $plugin_data, $plugin_name);
    preg_match(“|Plugin URI:(.*)|i”, $plugin_data, $plugin_uri);
    preg_match(“|Description:(.*)|i”, $plugin_data, $description);
    preg_match(“|Author:(.*)|i”, $plugin_data, $author_name);
    preg_match(“|Author URI:(.*)|i”, $plugin_data, $author_uri);
    if ( preg_match(“|Version:(.*)|i”, $plugin_data, $version) ) {
    $version = $version[1];
    } else {
    $version =”;
    }

    $description = wptexturize($description[1]);

    if (!empty($current_plugins) && in_array($plugin_file, $current_plugins)) {
    // If Galleries is found return true
    if (trim($plugin_name[1]) == ‘Galleries’) {
    $installed = true;
    return $installed;
    }
    }

    }
    // echo $plugs;
    return $installed;
    }
    }
    }
    ?>

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Admin Menu’ is closed to new replies.