Action hook on edit

This topic contains 3 reply and 2 voices, and was last updated by Dimitri 10 years ago
Viewing 3 Posts - 1 through 3 (of 3 total)
Author Posts
April 14, 2014 at 8:52 pm 18763
Dimitri Hi, I’ve used this code in order to: 1) generate a password 2) saving into a custom field 3) add password to the URL
function add_custom_field_automatically( $post_id ) {
    
	$passord_progetto = wp_generate_password(6, false, false); 
	
	if ( isset( $passord_progetto) ) {
        update_post_meta( $post_id, 'password_ordine', $passord_progetto );
    }
}
  
add_action( 'wpuf_add_post_after_insert', 'add_custom_field_automatically' );
add_action( 'wpuf_edit_post_after_update', 'update_my_brand_new_hook' );

// ADD QUERY VAR PASSWORD ORDINE
add_filter( 'post_type_link', 'wpchef_ordine_url', 10, 2 );
function wpchef_ordine_url( $url, $post ) {
	
	if ( 'project' !== $post->post_type )
        return $url;
	
	$password = get_post_meta( $post->ID, 'password_ordine', true );
	
    return add_query_arg( 'psw', $password, $url );
	
}
When I create a new post (project) all works well. The problem is when I EDIT the post the password is deleted. Could you give me some hints? Thank you. D.
April 15, 2014 at 1:41 am 18777
Tareq Hasan Tareq Hasan

Just remove this line? add_action( 'wpuf_edit_post_after_update', 'update_my_brand_new_hook' );.

April 15, 2014 at 3:21 pm 18802
Dimitri Dimitri

Strangely it doesn’t work even if I remove that line.. and I don’t understand why..

April 15, 2014 at 3:36 pm 18806
Dimitri Dimitri

This is the custom Edit url that I use

<?php 
						
						if ( current_user_can( 'delete_others_posts' ) || $post->post_author == get_current_user_id() ) {
							  $edit_page = (int) wpuf_get_option( 'edit_page_id', 'wpuf_general' );
							  $url = add_query_arg( array('pid' => $post->ID), get_permalink( $edit_page ) );
						  
							  printf( '<a href="%s" class="bottone_new_project">%s</a>', wp_nonce_url( $url, 'wpuf_edit' ), __( 'Edit this project', 'wpuf' ) );
}
						
						?>
Viewing 3 Posts - 1 through 3 (of 3 total)