Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action('wpcf7_before_send_mail', function( $wpcf7 ){
- if( WPCF7_Submission::get_instance() ){
- $mail = $wpcf7->prop('mail');
- $fields = $wpcf7->scan_form_tags( array( 'type' => array('mfile', 'mfile*') ) );
- $folder = '';
- // For dropbox
- $dropbox = get_option('drag_n_drop_storage_api_dropbox');
- $access_tokens = ( isset( $dropbox['dropbox']['tokens']['access_token'] ) ? $dropbox['dropbox']['tokens']['access_token'] : '' );
- if( $uploader = wp_list_pluck( $fields, 'name' ) ){
- foreach( $uploader as $upload ){
- if( isset( $_POST[ $upload ] ) ){
- $folder = dirname( $_POST[ $upload ][0] );
- break;
- }
- }
- }
- if( $folder ){
- $data = array(
- 'path' => $folder,
- 'settings' => ['requested_visibility' => 'public']
- );
- $response = wp_remote_post( 'https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings', array(
- 'headers' => array( 'Authorization' => 'Bearer '.$access_tokens, 'Content-Type' => 'application/json' ),
- 'body' => json_encode( $data ),
- 'timeout' => 20
- ));
- if( ! is_wp_error( $response ) ){
- $json_response = json_decode( wp_remote_retrieve_body( $response ), true);
- if( isset( $json_response['url'] ) ){
- $mail['body'] = str_replace('[your-name__folder]', $json_response['url'], $mail['body'] );
- }
- }
- }
- $wpcf7->set_properties( array("mail" => $mail) );
- }
- return $wpcf7;
- }, 10, 1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement