Advanced WordPress Integration

Once Open Food Source has been integrated with WordPress, there are a few additional tweaks that can make the system more seamless and easy to use.

Set up wordpress menu entries that link to OFS pages.

In general, there is an OFS landing page (panel) for the major auth_types: member, producer, route_admin, member_admin, producer_admin, cashier, and site_admin. There is also a shopping panel, and you might be interested in providing links for logout and shopping baskets as well as other possible pages.

On the OFS side, menu items are selectively shown only to members who have permission to see a particular page. In order to achieve this behavior on the WordPress side, you will need to create a dummy WordPress page for each OFS page you desire to have linked in the site navigation. For each of those pages, the trick is to use dummy WordPress pages with group access permissions that will be redirected to the corresponding OFS page.

As an example, let’s consider adding three links for: member panel, shopping panel, and producer panel.

  1. Create three bogus WordPress pages, giving them a distinct permalink pattern such as: ofs_panel_member_ofs, ofs_panel_shopping_ofs, and ofs_panel_producer_ofs.
  2. Give each of the pages respective access permissions of: member, member, and producer.
  3. Add the pages to the WordPress menu under the desired hierarchy. Because of the pages’ access permissions, WordPress will hide those menu items when a member without those permissions is logged in. This matches the behavior on the OFS side of the site.
  4. Set up an Apache redirect that will send pages over to OFS. Assuming there are no other WordPress permalinks beginning with “ofs_” we will redirect all files with a pattern like ofs_[pattern] to /food/[pattern].php
  5. The result is that a member clicking on the WordPress “Member Panel” menu item (ofs_panel_member) will be redirected to /food/panel_member.php on the OFS side of the site instead.
  6. An .htaccess redirect for the above rule could look like this:
    RewriteRule ^ofs_(.*)_ofs.*/$ /food/$1.php [R=301,L]
  7. Pages besides the basic “panel” pages can also be also be linked in the same way.

Set up a skin on the Open Food Source portion of the site that closely resembles the WordPress theme. This is a tricky task and will require some coding expertise.

Before beginning this process, it is advisable to completely set up the WordPress site as much as possible with all desired theme and style changes, and particularly menu entries.

  1. Login to the OFS/Wordpress site with highest asministrative permissions.
  2. Find a relatively simple WordPress page on your site and view the page source. Save this file for comparison.
  3. Open an OFS page on your site and view the page source. Save this file for comparison also.
  4. Open the OFS template_header.php and template_footer.php files for editing.

Direct WordPress activities to OFS: The OFS-Wordpress integration allows a single OFS login to also log users into WordPress, but those users can also log into WordPress independently. It might be desirable to restrict this behavior and direct all logins through the OFS side of the system. Using mod_redirect on Apache web servers, we will:

  1. send WordPress login attempts to the OFS login screen.
  2. send WordPress admin login attempts to the OFS login screen.
  3. send WordPress member editing to the OFS system.

Turn off the WordPress admin bar for consistency across pages. This can be done by adding the following lines to the functions.php file in your chosen WordPress theme directory:

/* Disable WordPress Admin Bar for all users but admins. */

A useful resource for creating WordPress child themes can be found on the Elegant Themes Blog.

Add a menu entry to the OFS navigation that provides administrative users a direct link to the WordPress dashboard.

Leave a Reply