bp_nouveau_ajax_document_move()

Ajax document move.

Description

Source

File: bp-templates/bp-nouveau/includes/document/ajax.php

799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
function bp_nouveau_ajax_document_move() {
 
    $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 );
    }
 
    // Move document.
    $folder_id   = ! empty( $_POST['folder_id'] ) ? (int) $_POST['folder_id'] : 0;
    $document_id = ! empty( $_POST['document_id'] ) ? (int) $_POST['document_id'] : 0;
    $group_id    = ! empty( $_POST['group_id'] ) ? (int) $_POST['group_id'] : 0;
 
    if ( 0 === $document_id ) {
        wp_send_json_error( $response );
    }
 
    if ( (int) $document_id > 0 ) {
        $has_access = bp_document_user_can_edit( $document_id );
        if ( ! $has_access ) {
            $response['feedback'] = esc_html__( 'You don\'t have permission to move this document.', 'buddyboss' );
            wp_send_json_error( $response );
        }
    }
 
    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 move this document.', 'buddyboss' );
            wp_send_json_error( $response );
        }
    }
 
    $document = bp_document_move_document_to_folder( $document_id, $folder_id, $group_id );
 
    if ( $document > 0 ) {
 
        $content = '';
        ob_start();
 
        if ( bp_has_document( bp_ajax_querystring( 'document' ) ) ) :
 
            if ( empty( $_POST['page'] ) || 1 === (int) filter_input( INPUT_POST, 'page', FILTER_SANITIZE_STRING ) ) :
                ?>
 
                <div class="document-data-table-head">
                    <span class="data-head-sort-label"><?php esc_html_e( 'Sort By:', 'buddyboss' ); ?></span>
                    <div class="data-head data-head-name">
                <span>
                    <?php esc_html_e( 'Name', 'buddyboss' ); ?>
                    <i class="bb-icon-triangle-fill"></i>
                </span>
 
                    </div>
                    <div class="data-head data-head-modified">
                <span>
                    <?php esc_html_e( 'Modified', 'buddyboss' ); ?>
                    <i class="bb-icon-triangle-fill"></i>
                </span>
 
                    </div>
                    <div class="data-head data-head-visibility">
                <span>
                    <?php esc_html_e( 'Visibility', 'buddyboss' ); ?>
                    <i class="bb-icon-triangle-fill"></i>
                </span>
                    </div>
                </div><!-- .document-data-table-head -->
 
                <div id="media-folder-document-data-table">
                <?php
                bp_get_template_part( 'document/activity-document-move' );
                bp_get_template_part( 'document/activity-document-folder-move' );
 
            endif;
 
            while ( bp_document() ) :
                bp_the_document();
 
                bp_get_template_part( 'document/document-entry' );
 
            endwhile;
 
            if ( bp_document_has_more_items() ) :
                ?>
                <div class="pager">
                    <div class="dt-more-container load-more">
                        <a class="button outline full" href="<?php bp_document_load_more_link(); ?>"><?php esc_html_e( 'Load More', 'buddyboss' ); ?></a>
                    </div>
                </div>
                <?php
            endif;
 
            if ( empty( $_POST['page'] ) || 1 === (int) filter_input( INPUT_POST, 'page', FILTER_SANITIZE_STRING ) ) :
                ?>
                </div> <!-- #media-folder-document-data-table -->
                <?php
            endif;
 
        else :
 
            bp_nouveau_user_feedback( 'media-loop-document-none' );
 
        endif;
 
        $content .= ob_get_clean();
 
        wp_send_json_success(
            array(
                'message' => 'success',
                'html'    => $content,
            )
        );
 
    } else {
        wp_send_json_error( $response );
    }
 
}

Changelog

Changelog
Version Description
BuddyBoss 1.4.0 Introduced.

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.