Passing parameters around in Plugin (20 posts)

  1. alexolder
    Posted 6 years ago #

    I'm working on a plugin, a very simple one for a client and I'm trying to work on an edit function by passing the id around ?id=1234

    However I'm getting permission denied when clicking the link I've created.

    What do I need to do, to allow this?

  2. s_ha_dum
    Posted 6 years ago #

    You are working in the backend, I assume? I'm also assuming you've made a management page of some sort? If so, look at the url on your management page. You'll see a string like admin.php?page=something. That 'something' should match a value defined when you instantiated the management page. You need to pass that string around with whatever other parameters you are sending. So ?id=1234 would be admin.php?page=something&id=1234. You can make POST forms work by putting that string in a hidden form field like <input type="hidden" name="page" value="something" />.

  3. alexolder
    Posted 6 years ago #

    Yeah working in the Backend. I've created a link where I'm creating the link: admin.php?page=something&id=1234 but when clicking on the link I get permission denied.

  4. s_ha_dum
    Posted 6 years ago #

    Ok. Then look at the function call that instantiates the page. The third or fourth parameter (Its different for top level and submenu pages) is the capability level that the user needs in order to access the page. Make sure your user has that capability. You might not want to use a values as generic as 'id' either. You can run into conflicts with internal stuff that way. Try something like 'alexpluginid' instead.

  5. alexolder
    Posted 6 years ago #

    I'm an admin currently.

    The parameter I'm passing is 'faqid' nothing generic. When I don't pass the parameter it works fine but I obviously need the ID for this part to work.

  6. Mark / t31os

    Posted 6 years ago #

    How are you registering the backend page, can we see the line that registers the page please?

  7. s_ha_dum
    Posted 6 years ago #

    I'm not sure what's wrong then. Maybe if you paste some code as t3los_ suggested.

  8. alexolder
    Posted 6 years ago #

    add_submenu_page(__FILE__, 'Edit Question', 'Edit Question', 1, __FILE__.'/edit.php', 'bluefly_faq_admin_edit');

    That registers the page, my guess is I'm missing something off the end?

  9. Mark / t31os

    Posted 6 years ago #

    Ok, well your links should be formed in the same format as the current page's url..

    So when viewing yourplugin/edit.php (as you've registered above), maybe something like..


    Been a long time since i've used the add_submenu_page function, but i'm pretty sure it's just how you're forming your URLs ...

  10. alexolder
    Posted 6 years ago #

    ok, and how do I make it so the parameter on the end can be any number?

  11. Mark / t31os

    Posted 6 years ago #

    Let's simplify a little, what is the url in your address bar when you're viewing your plugin page, and what is the url you're using with your links?

  12. alexolder
    Posted 6 years ago #



    Then linked are created that look like:


    The problem is passing ?faq=8 results in a permission denied message.

  13. Mark / t31os

    Posted 6 years ago #

    Does the edit page work on it's own?

  14. alexolder
    Posted 6 years ago #


  15. Mark / t31os

    Posted 6 years ago #

    Would you mind providing a copy of your plugin to test, i can't really see why that would happen, i can however run the code and test it if you like...

  16. alexolder
    Posted 6 years ago #

    [t31os edit]


    Replaced with pastebin version - http://wordpress.pastebin.ca/1816182

    Keeps thread trim .. :)

  17. alexolder
    Posted 6 years ago #

    I have changed the URLs at the bottom to be more human friendly and less .php etc but this should cause any problems.

  18. Mark / t31os

    Posted 6 years ago #

    Sorry for the delay... :)

    You should be forming your links like this..




    You can't use a question mark because there's already an existing query var in the URL, ?page=bluefly , all vars except the first must be preceded by a & ...

    Try this though..

    Should help you along a little... ;)

  19. alexolder
    Posted 6 years ago #

    Yeah just a little,

    Thank you very much!

  20. Mark / t31os

    Posted 6 years ago #

    I tried not to toy with it too much, i could see some areas were "in progress" so to speak...

    The point of moving the code into a class is that you avoid the need to do any..

    if( function_exists() )

    ...checks around your functions..

    Ideally you should have just one around the class name..

    if( class_exists() )

    Although neither is a requirement, it's always a good idea to check a function or class does not exist before declaring one, functions inside a class are less likely to cause naming conflicts though, because they are part of the class, and not regular named functions.

    Additionally class functions can be marked as private, this means that particular function can only be called inside the scope of the class (ie. only another function in the class can call the function). Small things like this can be really handy if you want to write a function that can only used inside the context of the code you're writing (ie. inside the class).

    If you get stuck on something else, post back, i don't mind helping if you need suggestions or guidance.

Topic Closed

This topic has been closed to new replies.

About this Topic