Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author scribu

    (@scribu)

    Thread Starter mardev

    (@mardev)

    Thank you for your quick reply but I still can’t get things working so please help me once more.

    My functions.php looks like this:

    register_post_type('poi', $args); // 'poi' custom post type definition 
    
    function fee_restrict_post_types( $allow, $data ) {
        $allowed_post_types = array( 'poi', 'post', 'page');
        $current_post_type = get_post_type( $data['post_id'] );
        return $allow && in_array( $current_post_type, $allowed_post_types );
    }
    add_filter('front_end_editor_allow_post', 'fee_restrict_post_types', 10, 2 );

    Do I need to let FEE know anywhere else about the new post type ‘poi’?

    Thanks!

    Plugin Author scribu

    (@scribu)

    You shouldn’t call register_post_type() directly in functions.php. Instead, wrap it in a callback, hooked to ‘init’.

    function register_my_post_types() {
      register_post_type('poi', $args); // 'poi' custom post type definition
    }
    add_action('init', 'register_my_post_types');

    Other than that, it looks ok.

    You said that you wanted to enable editing for the ‘poi’ post type.

    Note that, by default, all post types are editable. If that’s not the case for you, it means there’s something else going on.

    Thread Starter mardev

    (@mardev)

    Scribu,

    thanks again for your help. Method register_post_type was already wrapped in ‘init’ action callback but I didn’t want to paste large amount of other unrelated code. Anyway you pointed me in the right direction and I found error somewhere else. I was using get_posts and previous posts sorted that out http://wordpress.org/support/topic/plugin-front-end-editor-making-fields-retrieved-with-get_post-editable?replies=13.

    I have just one last question for you! Hope you don’t mind!

    I want to achieve initializing FEE editor for the posts that has been returned from AJAX call so without reloading the whole page.

    What I’m doing is:
    I insert new post on front-end side with AJAX callback function which returns inserted post ID after which I can format content like:

    <div data-post_id='{POSTID}' class='fee-field fee-clearfix' data-filter='the_content' data-type='rich' > {POST_CONTENT} </div>

    In this stage I don’t use FEE but my own ajax call as I know you don’t support inserting new posts but what I want to achieve now is to call your internal mechanism(on PHP&JS side) to initialize this new post on frontend to enable FEE editing.

    Your help is greatly appreciated! I really want to make this plugin work for my project, it has unbelievable UX.

    Plugin Author scribu

    (@scribu)

    what I want to achieve now is to call your internal mechanism(on PHP&JS side) to initialize this new post on frontend to enable FEE editing.

    There currently is no easy way to do this, but I’ve started working on fixing that.

    With the latest Development Version (2.1.2-alpha2), you should be able to do something like this:

    jQuery('some selector').each(FrontEndEditor.make_editable);

    I insert new post on front-end side with AJAX callback function which returns inserted post ID after which I can format content like:

    I would recommend making the ajax request return the final HTML, using the_content() etc. That way, you don’t have to insert the FEE attributes by hand.

    Thread Starter mardev

    (@mardev)

    Great, that feature should really increase functionality a lot.

    I tried to implement what I explained above but 2 problems occurred that you should know about it.

    1. In Ajax callback function defined in my functions.php the_content() method doesn’t apply FEE actions. This is my own ajax call for inserting new post.

    add_action('wp_ajax_poi_insert', 'poi_insert');
    function poi_insert()
    {
     // here are unrelated wp_insert_post logic
    
    // test FEE editing for newly created post, this same code works great in index.php
       query_posts('posts_per_page=2');
       while ( have_posts() ) : the_post(); ?>
       <?php the_title(); ?>
       <?php the_content(); ?>
     <?php
     endwhile;
     wp_reset_query();
     }

    Above code returns 2 posts title and content that are not wrapped in FEE editing elements/attributes.

    2. FEE Ajax call for a new post returns nothing

    Ignoring the first problem above, I return ID of newly inserted post instead of final FEE html and do FEE attributes wrapping by hand on the client side after which I reinitialize FEE editor. That works and I get nice ‘Edit’ flag on mouseover event over new post content. But the second problem occur when I click edit new post content, FEE sends proper AJAX call on server but script returns nothing. It seems like that is happening because I wrapped FEE attributes by hand, I assume the_content() method and FEE sets something on server.

    Plugin Author scribu

    (@scribu)

    If you re-download the development version, this code should work:

    add_action('wp_ajax_poi_insert', 'poi_insert');
    function poi_insert() {
    	FEE_Core::add_filters();
    
    	query_posts('posts_per_page=1');
    	while ( have_posts() ) : the_post();
    ?>
       <?php the_title(); ?>
       <?php the_content(); ?>
    <?php
    	endwhile;
    	wp_reset_query();
    
    	die;
    }

    Note the first and last lines of the callback.

    Thread Starter mardev

    (@mardev)

    Awesome! I’ll try it soon. Thank you very much for your efforts and quick fixes.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Can't find filter 'front_end_editor_allow_post'’ is closed to new replies.