0

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

1
  • This seem your first question in this site. Wellcome. To help with your issue it is appreciated that you show us the effort you have done to do it yourself: code, research, etc. Also, you would narrow down the exact problem you have to achieve it.
    – cybmeta
    Commented Jan 23, 2015 at 16:31

3 Answers 3

0

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)

0

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

1
  • Yes, paul. I put this block as function and added the action save_post. function my_project_updated_send_email( $post_id ) { (the entire block) } add_action( 'save_post', 'my_project_updated_send_email' );
    – martin
    Commented Jan 27, 2015 at 16:26
0

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' )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.