WordPress.org

Ready to get started?Download WordPress

Forums

wrapping output of plugin function in admin interface (2 posts)

  1. billrdio
    Member
    Posted 8 years ago #

    DESCRIPTION:
    I am trying to write a plugin that adds a submenu to the Manage top-level menu. I want to put hyperlinks on my submenu page that link back to my plugin PHP file, which then grabs the query string I include in the URL and executes the appropriate function in my plugin PHP file.

    PROBLEM:
    This all works, but the output produced by the function I execute is NOT wrapped in the admin interface.

    EXAMPLE:
    here is a very barebones example of my code - basically, I run through some processing logic if my PHP receives a certain query string, otherwise, I add an action that results in my sub-menu being displayed.


    if (isset($_GET['up_action'])) {
    switch ($_GET['up_action']) {
    case "checkout":
    up_checkOut($up_filename);
    break;
    default:
    die("Invalid action");
    break;
    }
    } else {
    add_action('admin_menu', 'uploadplus_add_admin_menu_pages');
    }

    function uploadplus_add_admin_menu_pages() {
    add_management_page('UploadPlus', 'UploadPlus', 8, __FILE__, 'up_showForm');
    }

    function up_checkOut($filename) {
    // THIS OUTPUTS HTML THAT DOESN'T INCLUDE THE ADMIN
    // HEADER AND FOOTER - I WANT IT TO
    print('<div class="wrap">'."n");
    print('<a href="/wp-test/wp-content/files/'.$filename.'">Download file</a>');
    print('</div>');
    }

    In my submenu page (code not shown), there is a hyperlink that I want to link back to this PHP page with a query string that will cause a the up_checkOut() function to run, which I want to do some stuff and then display the results. Here is an example of the link:


    $queryStr='up_action=checkout&amp;up_id='.$row['id'].
    '&amp;up_filename='.$row['filename'];
    $url='/wordpress/wp-content/plugins/uploadplus/uploadplus.php?'.$queryStr;

    print('<a href="'.$url.'">Checkout &amp; edit</a>');

    The problem is, the up_checkOut() function displays the results correctly, but the HTML is not wrapped in the admin interface - i.e., the admin header and footer aren't there.

    I also tried using
    /wp-admin/edit.php?page=uploadplus/uploadplus.php
    as the page to link to with my additional query parameters
    and it did include the admin header and footer, but gave me a bunch of error messages:

    HOW DO I DO SOMETHING LIKE THIS? WHAT'S THE SUGGESTED WAY TO DO SOMETHING LIKE THIS? ARE THERE ANY EXAMPLES I CAN REFER TO?

    Any help would be greatly appreciated!

  2. MichaelH
    Member
    Posted 8 years ago #

    If you haven't seen Writing a Plugin, check it out. Here's a good list of other Plugin related articles:
    http://codex.wordpress.org/Category:Plugins

    Welcome to WordPress!

    Please help make the Forums more successful by reading:
    http://wordpress.org/support/topic/39501

    And, thank you, for letting us know if this information proves useful (or not)!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.