class-media-library-organizer-tree-view-ajax.php
1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* Tree View AJAX class.
*
* @package Media_Library_Organizer
* @author WP Media Library
*/
/**
* AJAX class
*
* @version 1.1.1
*/
class Media_Library_Organizer_Tree_View_AJAX {
/**
* Holds the base class object.
*
* @since 1.1.1
*
* @var object
*/
public $base;
/**
* Constructor
*
* @since 1.1.1
*
* @param object $base Base Plugin Class.
*/
public function __construct( $base ) {
// Store base class.
$this->base = $base;
add_action( 'wp_ajax_media_library_organizer_tree_view_get_tree_view', array( $this, 'get_tree_view' ) );
}
/**
* Returns the Tree View HTML in a JSON payload
*
* @since 1.1.1
*/
public function get_tree_view() {
// Check nonce.
check_ajax_referer( 'media_library_organizer_tree_view_get_tree_view', 'nonce' );
// Get inputs.
$taxonomy_name = sanitize_text_field( $_REQUEST['taxonomy_name'] );
$current_term = ( isset( $_REQUEST['current_term'] ) ? sanitize_text_field( $_REQUEST['current_term'] ) : false );
$current_term_id = false;
// Get Term ID.
if ( $current_term !== false ) {
if ( is_numeric( $current_term ) ) {
$current_term_id = absint( $current_term );
} else {
// Get Term ID from Slug.
$term = get_term_by( 'slug', $current_term, $taxonomy_name );
if ( $term ) {
$current_term_id = $term->term_id;
}
}
}
// Get Output.
$output = $this->base->get_class( 'media' )->get_tree_view( $taxonomy_name, $current_term_id );
// Done.
wp_send_json_success( $output );
}
}