My plugin needs to introduce a number of interfaces to WordPress for the public traffic. What is the best way of introducing new interfaces?
Leave a Reply
You must be logged in to post a comment.
My plugin needs to introduce a number of interfaces to WordPress for the public traffic. What is the best way of introducing new interfaces?
You must be logged in to post a comment.
Believe it or not the WordPress official documentation has a great page covering this topic called Administration Menus. It also provides example code on how to use WordPress hooks in your plugin code to add custom setting pages and other pages like that.
The page can be found here. Fire up the kettle and make yourself a coffee or tea before reading, because it is quite a large page. It even covers things like adding in forms and saving settings for your plugin that you can access.
** Update **
After further understanding what you were asking, it’s apparent you want to create a WordPress page from within your plugin, not an admin screen. Depending on whether or not you want to create it upon activation or when a user does a particular thing I’ll assume you want to create it upon activation and remove it upon deactivation.
I did not add in code for deleting pages, you should be able to work that part out though. The following should add in a page upon activation of your plugin.
If you have any questions or issues using the sample code post up what you’re trying to accomplish and someone will sort you out. Good luck.
I’m not sure that Dwayne’s answer on how to create a WordPress “Page” is what the poster is looking for. Here are some disadvantages of creating a WordPress Page.
Based on the poster’s desire for “interfaces to WordPress”, I’m going to assume Am01 wants to create a “page” (lower-case), not a WordPress “Page”–ie, just some arbitrary PHP creating arbitrary HTML.
I had the same this problem. I needed a callback URL for an OAuth login sequence. Also, I wanted to create a self-contained test-bed page for my Plugin. Here is how I did it:
foo.php
in my plugin directory.At the top, put
Wrote my code below. The code can make all normal calls to WordPress and the Plugin.
plugins_url('foo.php', __FILE__)
.This is unofficial! One reason it is a hack is it hard-codes the location of
wp-load.php
. If the plugin directory were in a non-default location, it might not work. Also, the URL to the page is pretty ugly (/wp-content/...
).But I couldn’t find an official or cleaner way to do this. If someone has one, I’d be grateful for it!