WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Front-end Editor] Only show Front End editor for posts belonging to a particular category? (34 posts)

  1. jascanio
    Member
    Posted 4 years ago #

    Is there any possible way to only enable the Front End editor for posts that belong to a particular category? It seems that the default handles ALL posts, and the "Loading only on certain pages" instructions do not address this particular issue.

    Any help would be GREATLY appreciated!

    http://wordpress.org/extend/plugins/front-end-editor/

  2. scribu
    Member
    Posted 4 years ago #

    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.

  3. jascanio
    Member
    Posted 4 years ago #

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

  4. scribu
    Member
    Posted 4 years ago #

    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.

  5. subito_g
    Member
    Posted 4 years ago #

    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.

  6. scribu
    Member
    Posted 4 years ago #

    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'
    	));
    }
  7. subito_g
    Member
    Posted 4 years ago #

    Works perfect! Thank you for providing it.

  8. nzde
    Member
    Posted 4 years ago #

    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

  9. scribu
    Member
    Posted 4 years ago #

    Here's a direct link.

  10. nzde
    Member
    Posted 4 years ago #

    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

  11. nzde
    Member
    Posted 4 years ago #

    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?

  12. nzde
    Member
    Posted 4 years ago #

    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.)

  13. scribu
    Member
    Posted 4 years ago #

    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?

  14. scribu
    Member
    Posted 4 years ago #

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

  15. nzde
    Member
    Posted 4 years ago #

    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?

  16. scribu
    Member
    Posted 4 years ago #

    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.

  17. nzde
    Member
    Posted 4 years ago #

    Hi Scribu

    Thanks so much for doing this. Sadly, however, now when I click on the restricted category, the whirring loading symbol comes up but keeps spinning; no front page edit screen appears.

    I thought this might have been an issue with my local install of WP using MAMP, so I tried it on a live WordPress install (behind passowrd protection). This time I receive these fatal error messages:

    "Fatal error: Call to private method frontEd_field::allow() from context 'frontEditor' in /home/lexpress/public_html/wp-content/plugins/front-end-editor/core.php on line 135"

    Do you why this might be happening please?

    Best regards
    Richard

  18. scribu
    Member
    Posted 4 years ago #

    That's why it's in alpha. :)

    The latest version (1.4a4) should work.

  19. nzde
    Member
    Posted 4 years ago #

    Hi again Scribu. Thanks so much for doing this, and doing it so quickly. It works perfectly now. Brilliant! I've just made a Paypal donation to you to say thanks.

    By the way, and just out of interest, would it be possible to create similar code which works for subpages of a given parent page AND for that code to work at the same time as the category code? I ask, really out of interest, because previously I tried the category and page code together and it made my site go blank (upon which I rapidly removed it of course).

    In any event, thanks again for the new version. Great stuff.

    Best regards
    Richard

  20. scribu
    Member
    Posted 4 years ago #

    I thought someone might need that. Here's the other part of the code:

    add_filter('front_ed_allow_post', 'restrict_to_parent_page', 10, 2);
    function restrict_to_parent_page($allow, $post_id) {
    	// Only apply this check to pages
    	if ( 'page' != get_post_field('post_type', $post_id) )
    		return $allow;
    
    	$ancestors = get_post_ancestors($post_id);
    	$parent_page = 123;
    
    	return $allow && in_array($parent_page, $ancestors);
    }
  21. xanderashwell
    Member
    Posted 4 years ago #

    Hi Scribu,

    Firstly, many thanks for taking the time to create and improve on your front-end editor plugin. I'm integrating it into a website, and I've run across a small stumbling block...

    The example code you gave for restricting the front-end editor to a single category works fantastically, I added it, changed the category fields, and it worked. However, one of the side effects of this filter is that it seems to remove the original text from the input field of the editor when editing. Prior to adding the filter to the functions.php, the input field in the editor was populated with the original content, and upon removing the filter, it is re-instated. I don't suppose you know what might be causing this minor bug, and how to rectify it?

    I've checked this out in Firefox 3.5.5 & Safari 4.0.3 in Mac OS 10.6.1 and I don't have the rich text editor enabled.

    Kind Regards,

    Xander

  22. scribu
    Member
    Posted 4 years ago #

    First of all, I hope you're using this code, not the old version:

    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);
    }

    Secondly, what version of WP are you using?

    Install Firebug and follow the AJAX requests in the console.

  23. xanderashwell
    Member
    Posted 4 years ago #

    I'm using the up-to-date version of the code, with WordPress 2.8.6. I've disabled all other plugins to see if there is any conflict, but that's thrown back a dud. I've followed the AJAX requests in the Firebug console, but it doesn't throw any errors back at me apart from "compactMenu not defined" (onload(load) in the growfield.js file).

    When I double-click the text field to edit, it doesn't seem to populate the field with any text, and if I click "Save", it doesn't seem to save the edition, and returns a blank post. If I remove the code to enable the plugin to edit across all posts, the full functionality is restored.

    I hope it's not something blindingly obvious I'm missing...

  24. scribu
    Member
    Posted 4 years ago #

    xanderashwell, I can't reproduce your problem. Therefore, I can't fix it. Sorry.

  25. xanderashwell
    Member
    Posted 4 years ago #

    Hi Scribu,

    My apologies for being an eternal idiot. I tried to recreate this issue in a different theme, and got the same error. I realised the full extent of my idiocy when I understood that the `add_filter('front_ed_allow_post', 'restrict_to_category', 10, 2);
    ` snippet of code didn't refer to the category id numbers, and was to be left alone. I had changed the "10,2" to correspond to my category id's.

    Fool.

    My apologies again for wasting your time, and congratulations on your ace ace plugin.

    Xander

  26. scribu
    Member
    Posted 4 years ago #

    Glad to hear you figured it out. Should have asked you to post the exact code you were using at the beginning.

  27. nzde
    Member
    Posted 4 years ago #

    Hi Scribu

    Thanks again for this super plugin.

    Could you let me know please whether it's possible to use the code below to make front-page editing possible for a number of selected categories, rather than only one category?

    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);
    }

    Many thanks
    Richard

  28. scribu
    Member
    Posted 4 years ago #

    add_filter('front_ed_allow_post', 'restrict_to_category', 10, 2);
    function restrict_to_category($allow, $post_id) {
    	$allowed_cats = array('First Category', 'Another one', 'Etc...');
    	return $allow && in_category($allowed_cats, $post_id);
    }
  29. nzde
    Member
    Posted 4 years ago #

    Brilliant. Thanks Scribu. Much appreciated.

  30. nzde
    Member
    Posted 4 years ago #

    Hi again Scribu

    Can I just check please if the code above, which allows one to limit the FEE to selected categories, is still working in the latest release of FEE? I ask because I'm using it but without success.

    The code I'm using is this:

    <?php
    
    add_filter('front_ed_allow_post', 'restrict_to_category', 10, 2);
    function restrict_to_category($allow, $post_id) {
    	$allowed_cats = array('Templates', 'Website terms of use');
    	return $allow && in_category($allowed_cats, $post_id);
    }
    
    ?>

    The theme I'm using is quite complex and has a functions.php file which pulls in a number of functions files from a functions library. The calling code I'm using in the main functions.php file, which follows the same model as for other functions it's pulling in, is as follows:

    // Load Front End Editor functions
    require_once(WEBTREATS_FUNCTIONS . '/front-page-editor-functions.php');

    Do you have any idea please why the code you've provided might not be working?

    Any help much appreciated.

    Richard

Topic Closed

This topic has been closed to new replies.

About this Topic