Viewing 15 replies - 1 through 15 (of 33 total)
  • Well, you could do something like this (not tested):

    class frontEd_check_cat extends frontEd_basic {
      function check($post_id) {
        return frontEd_basic::check($post_id)
        && in_category('YOUR-CATEGORY-SLUG');
      }
    }
    
    add_action('front_ed_fields', 'front_ed_overwrite');
    function front_ed_overwrite() {
      register_fronted_field('the_content',  array(
        'class' => 'frontEd_check_cat'
      ));
    }

    Just add it to functions.php in your theme directory.

    Thread Starter jascanio

    (@jascanio)

    Thanks for the reply and suggestion, but unfortunately it didn’t do the trick.

    I figured out why it wasn’t working. You need to download the development version (1.4a2) and add this code to functions.php:

    add_action('front_ed_fields', 'front_ed_overwrite');
    function front_ed_overwrite() {
    
    	class frontEd_check_cat extends frontEd_basic {
    		function check($post_id) {
    			return parent::check($post_id)
    			&& in_category('YOUR-CATEGORY-SLUG');
    		}
    	}
    
    	register_fronted_field('the_content', array(
    		'class' => 'frontEd_check_cat'
    	));
    }

    If you have ‘Edit paragraphs’ enabled, you should replace frontEd_basic with frontEd_chunks in the code above.

    scribu,
    Could you provide a modification of the above code that would work for pages with a specific page parent? There is only a group of child pages I would like this to work for. Thank you.

    Here you go:

    add_action('front_ed_fields', 'front_ed_overwrite');
    function front_ed_overwrite() {
    	class frontEd_check_cat extends frontEd_basic {
    		function check($post_id) {
    			$page_parent = 123;
    			$parents = get_post_ancestors($post_id);
    
    			return parent::check($post_id)
    			&& in_array($page_parent, $parents);
    		}
    	}
    
    	register_fronted_field('the_content', array(
    		'class' => 'frontEd_check_cat'
    	));
    }

    Works perfect! Thank you for providing it.

    Hi Scribu

    Is the dev version still available? I tried to download at the link above but could only access 1.3.3 under the Developer Version link. If that’s right, would that explain why, when I tried the code you provided above for limiting the functionality to a certain category, it didn’t work?

    Any help much appreciated.

    Thanks again for the plugin. It’s superb.

    Richard

    Here’s a direct link.

    Hi again Scribu

    I’ve installed the version of the plugin you linked to, added the category-related code above to the theme’s functions.php file and replaced ‘YOUR-CATEGORY-SLUG’ with the name of the relevant category, i.e., ‘wikified’.

    What happens now is that only posts in the ‘wikified’ category are editable by double-clicking them on the front end of the site (which is good). However, when you double-click, instead of bringing up the text of the post in the edit box, it brings up an empty edit box (not so good).

    Any ideas on what is happening here please?

    Many thanks in advance for your help. It’s much appreciated.

    Richard

    Hmm. I just tried the “child of page” code instead of the “category” code. The “child of page” works perfectly.

    Is it possible that I’m doing something wrong with the category code?

    P.S. I’ve swapped out themes to see if that’s the problem. It’s not. (I note, by the way, that this testing revealed that the plugin doesn’t seem to work at all with the Thematic theme.)

    I note, by the way, that this testing revealed that the plugin doesn’t seem to work at all with the Thematic theme.

    You mean it doesn’t work, regardless if you use the above code or not? None of the fields?

    nzde: On second thought, if you’re having problems specific to a certain theme, please open a new topic.

    Sure, will do. I may have put too many comments above for you to have spotted the main one, which was this:

    “Hi again Scribu

    I’ve installed the version of the plugin you linked to, added the category-related code above to the theme’s functions.php file and replaced ‘YOUR-CATEGORY-SLUG’ with the name of the relevant category, i.e., ‘wikified’.

    What happens now is that only posts in the ‘wikified’ category are editable by double-clicking them on the front end of the site (which is good). However, when you double-click, instead of bringing up the text of the post in the edit box, it brings up an empty edit box (not so good).

    Any ideas on what is happening here please?”

    Do you have any views on that one please?

    nzde:

    No ideea why that’s happening. However, seeing how several people need to restrict which posts to edit, I’ve made it easier to do that.

    Download the latest version (1.4a3) and replace the code above with this:

    add_filter('front_ed_allow_post', 'restrict_to_category', 10, 2);
    function restrict_to_category($allow, $post_id) {
    	return $allow && in_category('Your Category', $post_id);
    }

    The main advantage of this code is that it restricts access for all post fields, not just the post content.

    Hope it fixes your problem.

Viewing 15 replies - 1 through 15 (of 33 total)
  • The topic ‘[Plugin: Front-end Editor] Only show Front End editor for posts belonging to a particular category?’ is closed to new replies.