This plugin hooks into “add_attachment” filter and only writes a thumbanil_id. It doesn’t touch attachment itself. You don’t show the code for how a media uploader is created on front-end, so it’s all I can guess.
Thank you.
Thanks for your respons. I think its not the plugin issue. This plugin is simple great. But just let me describe what I need. I use the wp_editor() functions, and create the the front-end-editor to submit post ( template page) in exp: mydomain.com/submitpage. The args functions of wp_editor this template like this.
<?php
wp_enqueue_media();
$args = array(
'textarea_rows' => 15,
'quicktags' => false,
'media_buttons' => true,
'drag_drop_upload' => true,
);
wp_editor( '','content', $args );
?>
<div id="content"></div>
In front-end, after upload file, the plugin create PDF attachment ID and image thumbnail ID but PDF file status unattached. So now I still fix this issue and make the attached PDF file become auto draft before submit post, the same way how the wp backend do. Thanks for your support.
Yeah, it does not relate to the plugin.
I guess, When you upload an attachment on front end, there is no post ID. So, it needs a little tricky way.
At first, set a particular post to an upload button.
wp_enqueue_media( array( 'post' => $post->ID )); // upload file to submitpage
And, write these functions in your functions.php.
<?php
function tempo_id_for_frontend( $attachment_id ){ // run after an attachment is added to the DB
global $post;
$user_id = get_current_user_id();
$submit_id = get_page_by_path( 'submitpage' )->ID;
$attachment = get_post( $attachment_id );
if ( $attachment->post_parent == $submit_id && $user_id ){
$tempo_ids = get_post_meta( $submit_id, 'id_for_frontend', true); // set attachment ID in the customfield of "submitpage"
if( !$tempo_ids ) $tempo_ids = array();
$tempo_ids = $tempo_ids += array( $attachment_id => $user_id );
update_post_meta( $submit_id, 'id_for_frontend', $tempo_ids );
}
return $attachment_id;
}
add_filter( 'add_attachment', 'tempo_id_for_frontend', 99, 2 );
function save_post_for_frontend ( $post_id ) {
if ( !is_admin() ){
$user_id = wp_get_current_user()->ID;
$submit_id = get_page_by_path( 'submitpage' )->ID;
if( get_post_type( $post_id ) === 'your_custom_post_type_here' && $user_id ){ // set "post", "page", or your custom posttype
$tempo_ids = get_post_meta( $submit_id, 'id_for_frontend', true);
if( $tempo_ids ) : foreach ($tempo_ids as $key => $val ) : // pick attachment IDs from the customfield
if ( $val == $user_id ){
$at_post = array();
$at_post['ID'] = $key;
$at_post['post_parent'] = $post_id; // set post_parent
wp_update_post( $at_post );
}
unset( $tempo_ids[$key] );
endforeach; endif;
if( $tempo_ids ) update_post_meta( $submit_id, 'id_for_frontend', $tempo_ids );
else delete_post_meta( $submit_id, 'id_for_frontend' );
}
}
}
add_action( 'save_post', 'save_post_for_frontend' );
?>
nah… thanks a lot Ogino, you save my time to fix my issue. Awaiting for another feature release from yours. Regards.