예제 #1
0
/**
 * RPC endpoint for rendering a list of posts in jstree format
 */
function bu_navigation_ajax_get_navtree()
{
    if (defined('DOING_AJAX') && DOING_AJAX) {
        $child_of = isset($_POST['child_of']) ? $_POST['child_of'] : 0;
        $post_types = isset($_POST['post_types']) ? $_POST['post_types'] : 'page';
        $post_statuses = isset($_POST['post_statuses']) ? $_POST['post_statuses'] : 'publish';
        $instance = isset($_POST['instance']) ? $_POST['instance'] : 'default';
        $prefix = isset($_POST['prefix']) ? $_POST['prefix'] : 'p';
        $include_links = isset($_POST['include_links']) ? (bool) $_POST['include_links'] : true;
        $tree_view = new BU_Navigation_Tree_View($instance, array('childOf' => $child_of, 'postTypes' => $post_types, 'postStatuses' => $post_statuses, 'nodePrefix' => $prefix, 'includeLinks' => $include_links));
        // WP >= 3.5
        if (function_exists('wp_send_json')) {
            wp_send_json($tree_view->render());
        } else {
            @header('Content-Type: application/json; charset=' . get_option('blog_charset'));
            echo json_encode($tree_view->render());
            die;
        }
    }
}