obj = $that; add_action('wp_ajax_reacg_get_posts', [$this, 'get_posts'] ); } private function get_taxonomies( $post_type, $saved_data ) { // Organize saved data. $saved_taxonomies = []; foreach ( $saved_data as $data ) { $term = explode(":", $data); $term_taxonomy = isset($term[0]) ? $term[0] : ''; $term_id = isset($term[1]) ? $term[1] : 0; $saved_taxonomies[$term_taxonomy][] = $term_id; } // Get taxonomy and terms by post type. $taxonomies = get_object_taxonomies($post_type, 'objects'); $result = []; foreach ( $taxonomies as $taxonomy ) { $terms = get_terms([ 'taxonomy' => $taxonomy->name, 'hide_empty' => TRUE, ]); if ( !empty($terms) ) { $result[$taxonomy->name] = []; foreach ( $terms as $term ) { $result[$taxonomy->name][] = [ 'id' => $term->term_id, 'name' => $term->name, 'selected' => !empty($saved_taxonomies[$taxonomy->name]) && in_array($term->term_id, $saved_taxonomies[$taxonomy->name]), ]; } } } return $result; } public function get_posts() { if ( !REACGLibrary::verify_nonce() ) { wp_die(); } if ( !current_user_can('edit_posts') ) { wp_die(); } $select_type_defaults = ['manual', 'dynamic']; $select_type = ''; if ( !empty( $_POST['select_type'] ) ) { $select_type_input = sanitize_text_field( wp_unslash( $_POST['select_type'] ) ); if ( in_array( $select_type_input, $select_type_defaults ) ) { $select_type = $select_type_input; } } $type = 'post'; if ( !empty( $_POST['type'] ) ) { $type_input = sanitize_key( wp_unslash( $_POST['type'] ) ); if ( array_key_exists( $type_input, REACG_ALLOWED_POST_TYPES ) ) { $type = $type_input; } } $type_title = REACG_ALLOWED_POST_TYPES[$type]['title']; $gallery_id = !empty($_POST['gallery_id']) ? intval($_POST['gallery_id']) : 0; $additional_data = get_post_meta( $gallery_id, 'additional_data', TRUE ); if ( empty($select_type) ) { ob_end_clean(); ob_start(); ?>