Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm integrating a separate ecommerce CMS into a wordpress theme, using page templates for some pages such as the basket, search and checkout pages.

This is working out pretty well so far. However, there are a couple of dynamic pages that I'd normally make a single-posttype.php template for, but can't as in this case I can't because Wordpress doesn't 'know' about them, as the data is coming from the ecommerce CMS. For example, the product details page or a product category search page.

My solution was to create a template called product-details and make a page for it. In this template, the actual wordpress page data is ignored and the data is instead read from the ecommerce CMS.

My gut feeling is that this is not best practice however short of writing a full wordpress plugin integration of the ecommerce system, it's the best I could come up with.

TL;DR

The problem this leaves me is that if an admin were to delete that page, or unassign the template, the shop would break. So, I'd like to hide these pages to help prevent accidental deletion or editing (page content doesn't matter for them).

Is there a way to hide some pages from the 'All Pages' menu in wp-admin, unless a custom filter (e.g 'System Pages') is clicked?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

You can do this by using pre_get_posts() which will adjust the query before it's run. Therefore we can exclude pages from the query.

function wpse_hide_special_pages($query) {

    // Make sure we're in the admin and it's the main query
    if ( !is_admin() && !is_main_query() ) {
        return;
    }

    // Set the ID of your user so you can see see the pages
    $your_id = 1;

    // If it's you that is logged in then return
    if ($your_id == get_current_user_id()) {
        return;
    }

    global $typenow;

    // Only do this for pages
    if ( 'page' == $typenow) {

        // Don't show the special pages (get the IDs of the pages and replace these)
        $query->set( 'post__not_in', array('8', '15', '14', '22') );
        return;

    }

}
add_action('pre_get_posts', 'wpse_hide_special_pages');

Hope that helps.

share|improve this answer
    
this did the trick, I based my solution on this and then used another hook to add a filter link to the wp-admin page, with a GET param that I tested against. Thanks! –  jammypeach May 5 at 14:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.