Forums

[resolved] GET variables on custom admin pages (7 posts)

  1. ottobonn28
    Member
    Posted 3 months ago #

    Hi,

    I am developing a plugin that needs to send GET variables to its admin pages for editing database values. The plugin page edits "events" that users have entered into a database. I need to send the "event id" through the URL, so the page knows what event to load for editing.

    The problem is this. When a plugin creates a custom admin page, wordpress loads that page through a GET variable, like admin.php?page=mypage. The problem is that, when I try to send a variable through a URL, I lose the existing GET variables in the URL, so I end up with something like admin.php?event_id=2. Wordpress doesn't understand this, and so doesn't load my admin page.

    Is there an easy way I can add on custom GET variables, without interrupting wordpress's needs? I want to end up with something like admin.php?page=mypage&event_id=2.

  2. apljdi
    Member
    Posted 3 months ago #

    If you are using anchor tags just write out your url just the way you did. That's a valid get string. No problem.

    If you are using a form include a hidden field with the page value in it-- <input type="hidden" name="page" value="mypage" />.

  3. ottobonn28
    Member
    Posted 3 months ago #

    I just wasn't sure if the "page" variable would always be predictable across installs and versions, since it's a wordpress thing. Ideally my code would be independent of wordpress's variables; i.e. I could add a GET variable to the end of the URL as it was and leave the other variables alone.

  4. apljdi
    Member
    Posted 3 months ago #

    Well... its been stable for awhile. Parsing the URL won't give you any better long term stability. A variable name change or position in the string would throw that off. You could use information in $_SERVER to build your string. That might be a little better. Still not foolproof though, and a bit messy. My sentiment is, though, that trusting the 'page' variable isn't any more problematic than trusting that admin stuff is in <blogroot>/wp-admin and that plugins are in <blogroot>/wp-content/plugins.

  5. ottobonn28
    Member
    Posted 3 months ago #

    Is this kind of URL building standard practice for plugins that need to communicate across their own pages, or is there some other wordpress facility for this? It feels a little hackish to me.

  6. apljdi
    Member
    Posted 3 months ago #

    Well, if you look at the Akismet plugin built by Matt Mullenweg you'll see URLs cooked up in much the same manner. Same with Thomas Schneider's Role Manager-- this line for example: $this->manage_roles_uri = get_option('siteurl') . '/wp-admin/'.$path_file.'?page=' . $this->file_basename;

  7. ottobonn28
    Member
    Posted 3 months ago #

    Alright, thanks.

Reply

You must log in to post.

About this Topic