• Resolved ottobonn28

    (@ottobonn28)


    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.

Viewing 6 replies - 1 through 6 (of 6 total)
  • 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" />.

    Thread Starter ottobonn28

    (@ottobonn28)

    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.

    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.

    Thread Starter ottobonn28

    (@ottobonn28)

    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.

    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;

    Thread Starter ottobonn28

    (@ottobonn28)

    Alright, thanks.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘GET variables on custom admin pages’ is closed to new replies.