Section break, html and default form in the back end

This topic contains 8 reply and 2 voices, and was last updated by cob-web 10 years, 8 months ago
Viewing 8 Posts - 1 through 8 (of 8 total)
Author Posts
July 29, 2013 at 3:04 am 6406
cob-web 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.
July 30, 2013 at 6:02 pm 6465
Tareq Hasan Tareq Hasan

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.

July 30, 2013 at 7:00 pm 6469
cob-web cob-web

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

July 30, 2013 at 8:10 pm 6473
Tareq Hasan Tareq Hasan

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

July 30, 2013 at 8:41 pm 6480
cob-web cob-web

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?

July 30, 2013 at 9:57 pm 6485
cob-web cob-web

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

August 2, 2013 at 2:17 pm 6594
cob-web cob-web

@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?

August 2, 2013 at 2:31 pm 6596
Tareq Hasan Tareq Hasan

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

August 9, 2013 at 3:03 pm 6776
cob-web cob-web

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 8 Posts - 1 through 8 (of 8 total)