bp_nouveau_ajax_document_child_folder_save()
Description
Source
File: bp-templates/bp-nouveau/includes/document/ajax.php
function bp_nouveau_ajax_document_child_folder_save() { $response = array( 'feedback' => esc_html__( 'There was a problem performing this action. Please try again.', 'buddyboss' ), ); // Bail if not a POST action. if ( ! bp_is_post_request() ) { wp_send_json_error( $response ); } if ( empty( $_POST['_wpnonce'] ) ) { wp_send_json_error( $response ); } // Use default nonce. $nonce = filter_input( INPUT_POST, '_wpnonce', FILTER_SANITIZE_STRING ); $check = 'bp_nouveau_media'; // Nonce check! if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, $check ) ) { wp_send_json_error( $response ); } if ( empty( $_POST['title'] ) ) { $response['feedback'] = esc_html__( 'Please enter title of folder.', 'buddyboss' ); wp_send_json_error( $response ); } if ( ! is_user_logged_in() ) { $response['feedback'] = esc_html__( 'Please login to create a folder.', 'buddyboss' ); wp_send_json_error( $response ); } if ( strpbrk( $_POST['title'], "\\/?%*:|\"<>" ) !== false ) { $response['feedback'] = esc_html__( "Invalid folder name", 'buddyboss' ); wp_send_json_error( $response ); } // save folder. $id = 0; $group_id = ! empty( $_POST['group_id'] ) ? (int) $_POST['group_id'] : false; $title = wp_strip_all_tags( $_POST['title'] ); $folder_id = ! empty( $_POST['folder_id'] ) ? (int) filter_input( INPUT_POST, 'folder_id', FILTER_VALIDATE_INT ) : 0; $privacy = ''; if ( $folder_id > 0 ) { $parent_folder = BP_Document_Folder::get_folder_data( array( $folder_id ) ); $privacy = $parent_folder[0]->privacy; } if ( (int) $folder_id > 0 ) { $has_access = bp_folder_user_can_edit( $folder_id ); if ( ! $has_access ) { $response['feedback'] = esc_html__( 'You don\'t have permission to create folder inside this folder.', 'buddyboss' ); wp_send_json_error( $response ); } } $folder_id = bp_folder_add( array( 'id' => false, 'title' => $title, 'privacy' => $privacy, 'group_id' => $group_id, 'parent' => $folder_id, ) ); if ( ! $folder_id ) { $response['feedback'] = esc_html__( 'There was a problem when trying to create the folder.', 'buddyboss' ); wp_send_json_error( $response ); } $folder = new BP_Document_Folder( $folder_id ); if ( $group_id > 0 ) { $ul = bp_document_user_document_folder_tree_view_li_html( $folder->user_id, $group_id ); } else { $ul = bp_document_user_document_folder_tree_view_li_html( bp_loggedin_user_id() ); } $document = ''; if ( ! empty( $folder_id ) ) { ob_start(); if ( bp_has_folders( array( 'include' => $folder_id ) ) ) { while ( bp_folder() ) { bp_the_folder(); bp_get_template_part( 'document/document-entry' ); } } $document = ob_get_contents(); ob_end_clean(); } $response = array( 'document' => $document, 'tree_view' => $ul, 'folder_id' => $folder_id, ); wp_send_json_success( $response ); }
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.