• Resolved r_honey

    (@r_honey)


    Some of WordPress’ vocabulary is ambiguous, so I would try to be as precise as I can for my needs. For the lack of better term, I used the word “page” in subject, but I am NOT referring to page (as in a WP page of “page” post type).

    We all know WP ships with out of the box post types, e.g. blog and page post types. Both of these are oriented around displaying static content (well a blog post or About page is almost static once created).

    I am trying to write a plugin and what I am really wanting to do is to provide a non-post type (i.e. non content type) page from my plugin. Let’s take an example.

    Let’s say I want to expose a search form at this url in my WP site:
    http://example.com/ad-search

    The page would provide a few search criteria and upon submitting the form, I will execute a search for Active Directory users and list them as a html table on the page.
    You would see what I need is just the ability to define a relative url (ad-search) in the plugin, which when opened would invoke code from my plugin which would render the page’s content.

    I am expecting side-bars etc. to show up normally on this page, just the main page content is totally dictated in my plugin code.

    You would see this use-case is not suitable for defining a custom content type (aka custom post type) as there won’t be posts of this content type.

    I reckon one way of doing this might be to expose my search-form as a widget, then create a page and embed the widget as content on the page using many ways of embedding widgets in main content area of a page I found after googling.

    Although this is an option, I am trying to see if there’s a better and more “pure” way of doing it in WordPress (I am hoping there is one, most CMSes out there these days that have some traction do provide something).

    So in a nut-shell, I am trying to create a WP plugin that can create a totally custom form, expose it in WP using a relative url of choice and then be able to handle POST requests from such a form.

    I am open to ideas where you think WP has a better way of catering to this scenario than the one already listed (a widget inside a page).

Viewing 5 replies - 1 through 5 (of 5 total)
  • I think this is also what I am looking for as well. I have a php file coded but I don’t know how to integrate it into a wordpress and create a url for it from the plugin file.

    Moderator bcworkz

    (@bcworkz)

    As I answered in Cory’s thread, you could make your php search page a page (post type) template, then create the post type page based on this template, only the title needs to be assigned, no content required. This can all be done by code. The one thing that’s a bit rude is the template needs to be in the theme’s folder. This can be done, but it’s not really your plugin’s territory, you are sort of trespassing. I suppose this isn’t too bad as long as you remove the file to clean up after yourself if the user deletes your plugin from the control panel.

    Thread Starter r_honey

    (@r_honey)

    Thanks for replying bcworkz. The module is a bit more complex, e.g. each row would have a details button which would take you to a new page with additional details with further possibility of drill-down, and linking such pages would be a challenge.
    Although I can imagine approaches (e.g. creating such pages in code on module activation and storing page id’s in database somewhere and then linking them together), this is more messy work compared to writing plugins for other CMSes where plugin requires elaborate workflows.

    I know you might suggest that further details I have provided are more suitable for a custom post-type plus content of that type. But an important point to notice here is WP is not the content generator, rather its the consumer. The content itself is generated outside WP over which WP has no control.

    An easy option would have been to use iframes to embed custom php scripts in WP pages, but then I need information like current user/user roles etc., which won’t be availble in iframe’d code.

    I guess I would need to create pages in code and link them together.

    Moderator bcworkz

    (@bcworkz)

    You are free to develop your own stand alone pages, just require_once() the wp-load.php file (wp-admin/admin.php if login required) in order to have access to WP functions. You would then need to create the styling yourself, which would have been one of the advantages of the template. You may be able to simply include the theme header template to get a good part of this done, I haven’t included header files in my own work, so not sure of any side effects.

    The other advantage of the template approach lost is the permalink system, but you can implement this if desired with the Rewrite API.

    So such an approach is attainable, just a bit more work.

    Thread Starter r_honey

    (@r_honey)

    Yeah, thanks for those ideas, I would play with them and see what works better for my use-case.

    Thanks for your helpful replies!!!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Creating a custom page in plugin code’ is closed to new replies.