Home Forums Plugin Support WP User Frontend Pro Section break, html and default form in the back end

This topic is: resolved

This topic contains 8 replies, has 2 voices, and was last updated by  cob-web 5 years, 6 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #6406

    cob-web
    Participant
    Post count: 14

    Hi,
    I have two questions today:

    1. is it possible to display the section breaks and HTML on the back end?

    2. in the back end in the post edit you can choose the existing forms under “WPUF Form”. Is it possible, to set one form as a default?

    Thanks.

    #6465

    Tareq Hasan
    Keymaster
    Post count: 2831

    1. No. In the backend it's not a customized form like in the frontend. It shows just the custom fields thats being used.
    2. That would be a good idea, but currently you can't set a default form.

    #6469

    cob-web
    Participant
    Post count: 14

    Thanks Tareq,
    regarding 2. – isn't there any hook to set it? It would be a huge improvement for the work flow…

    #6473

    Tareq Hasan
    Keymaster
    Post count: 2831

    No, there isn't any hook. It's just a custom field _wpuf_form that is saved for each post for Form assignment. You can run a loop and update all existing posts to a form id. Check here

    #6480

    cob-web
    Participant
    Post count: 14

    This sounds like exactly what I need! ๐Ÿ™‚

    function wpufe_auto_set_formid( $post_id, $post ) {
        $form_id = 143;
         
        if ( $post->post_type == 'post' ) {
            update_post_meta( $post_id, '_wpuf_form_id', $form_id );
        }
    }
     
    add_action( 'wp_insert_post', 'wpufe_auto_set_formid', 10, 2 );

    But won't it clash, when the user will create a new post at the front end with another form?

    #6485

    cob-web
    Participant
    Post count: 14

    To explain: for different reasons I use another form in the back end than in the front end… So when I create a new post in the back end, it should use the “default form”, when a user creates a new post, he should be able to use the “frond end from”.

    #6594

    cob-web
    Participant
    Post count: 14

    @tareq
    I was playing with the function as you suggested.
    Unfortunately it won't allow me to change the form once a new post is created! Every time I save or update a post, the function sets the form ID back to the “default form”.
    I changed the $priority number of the action to 1 and to 15 but it doesn't seem to change this behavior.
    Actually the function should run just once when I create a new post.
    Do you have any hint on this?

    #6596

    Tareq Hasan
    Keymaster
    Post count: 2831

    Use this two hooks wpuf_add_post_after_insert and wpuf_edit_post_after_update. Check the other hooks as well.

    #6776

    cob-web
    Participant
    Post count: 14

    I found a very simple solution ๐Ÿ™‚
    If the _wpuf_form_id is empty, the form ID will get set to the default ID, otherwise nothing gets changed…

    function wpufe_auto_set_formid( $post_id, $post ) {
     	$form_id = get_post_meta( $post_id, '_wpuf_form_id', true );
           if ( $post->post_type == 'my_post_type' ) {
       	if ($form_id == "") 
       {
       	$form_id = 201;
            update_post_meta( $post_id, '_wpuf_form_id', $form_id );
       	} else{   }
    }
    }
    add_action( 'wp_insert_post', 'wpufe_auto_set_formid', 10, 2 );
Viewing 9 posts - 1 through 9 (of 9 total)

The topic ‘Section break, html and default form in the back end’ is closed to new replies.