I need create a file (any type: json, php, csv, txt) when I create or update a post from WPadmin. The format structure would be:
ID, "operation to execute" (new post, update post, delete post), title, field2, field3
Thanks! martin
I need create a file (any type: json, php, csv, txt) when I create or update a post from WPadmin. The format structure would be:
ID, "operation to execute" (new post, update post, delete post), title, field2, field3
Thanks! martin
There are a number of action hooks for Post Status Transitions. They each receive the $post
object as an argument. You could use these to trigger a function that writes your file to disk using fopen
.
Edit: if you're writing CSV, PHP has a function specifically for that: fputcsv
(fopen
still required)
You should use the save_post action to perform an action when creating or updating a post
http://codex.wordpress.org/Plugin_API/Action_Reference/save_post
Thanks paul/karpstrucking for your responses!
I tried with this codex example.. for sending fields to my mailbox, but this isnt running... i need little sample for testing when i publish..
i put this block on theme's functions.php.. that is ok?
function my_project_updated_send_email( $post_id ) {
// If this is just a revision, don't send the email.
if ( wp_is_post_revision( $post_id ) )
return;
$post_title = get_the_title( $post_id );
$post_url = get_permalink( $post_id );
$subject = 'A post has been updated';
$message = "A post has been updated on your website:\n\n";
$message .= $post_title . ": " . $post_url;
// Send email to admin.
wp_mail( '[email protected]', $subject, $message );
} add_action( 'save_post', 'my_project_updated_send_email' )