wp-donation-listing-table.php 30.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
<?php
/**
 * Posts List Table class.
 *
 * @package WordPress
 * @subpackage List_Table
 * @since 3.1.0
 * @access private
 */
class WC_Quick_Donation_Listing_Table extends WP_List_Table {
Varun Sridharan's avatar
Varun Sridharan committed
11 12 13 14 15 16 17 18

	/**
	 * Whether the items should be displayed hierarchically or linearly
	 *
	 * @since 3.1.0
	 * @var bool
	 * @access protected
	 */
19
	protected $hierarchical_display;
Varun Sridharan's avatar
Varun Sridharan committed
20 21 22 23 24 25 26 27

	/**
	 * Holds the number of pending comments for each post
	 *
	 * @since 3.1.0
	 * @var int
	 * @access protected
	 */
28
	protected $comment_pending_count;
Varun Sridharan's avatar
Varun Sridharan committed
29 30 31 32 33 34 35 36

	/**
	 * Holds the number of posts for this user
	 *
	 * @since 3.1.0
	 * @var int
	 * @access private
	 */
37
	private $user_posts_count;
Varun Sridharan's avatar
Varun Sridharan committed
38 39 40 41 42 43 44 45

	/**
	 * Holds the number of posts which are sticky.
	 *
	 * @since 3.1.0
	 * @var int
	 * @access private
	 */
46
	private $sticky_posts_count = 0;
Varun Sridharan's avatar
Varun Sridharan committed
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 78

	private $is_trash;

	/**
	 * Current level for output.
	 *
	 * @since 4.3.0
	 * @access protected
	 * @var int
	 */
	protected $current_level = 0;
    public $querypost ;

	/**
	 * Constructor.
	 *
	 * @since 3.1.0
	 * @access public
	 *
	 * @see WP_List_Table::__construct() for more information on default arguments.
	 *
	 * @global object $post_type_object
	 * @global wpdb   $wpdb
	 *
	 * @param array $args An associative array of arguments.
	 */
	public function __construct( $query,$args = array() ) {
        global $post_type_object, $wpdb;
        $this->querypost = $query;
        set_current_screen( 'shop_order' );

        parent::__construct( array(
Varun Sridharan's avatar
Varun Sridharan committed
79
            'plural' => 'Donations',
Varun Sridharan's avatar
Varun Sridharan committed
80 81 82
            'screen' => get_current_screen(),
        ) );
        
83 84
        
        $this->screen->post_type = 'shop_order';
Varun Sridharan's avatar
Varun Sridharan committed
85
        //$this->screen->id = 'shop_order';
Varun Sridharan's avatar
Varun Sridharan committed
86 87 88
        $post_type = $this->screen->post_type;
        $post_type_object = get_post_type_object( $post_type );
        $this->user_posts_count = 0;
89 90 91
        $this->sticky_posts_count = 0;
	}

Varun Sridharan's avatar
Varun Sridharan committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
	/**
	 * Sets whether the table layout should be hierarchical or not.
	 *
	 * @since 4.2.0
	 *
	 * @param bool $display Whether the table layout should be hierarchical.
	 */
	public function set_hierarchical_display( $display ) {
		$this->hierarchical_display = $display;
	}

	/**
	 *
	 * @return bool
	 */
107 108 109 110
	public function ajax_user_can() {
		return current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_posts );
	}

Varun Sridharan's avatar
Varun Sridharan committed
111 112 113 114 115 116 117
	/**
	 *
	 * @global array    $avail_post_stati
	 * @global WP_Query $wp_query
	 * @global int      $per_page
	 * @global string   $mode
	 */
118 119 120 121 122
	public function prepare_items() {
		global $avail_post_stati, $per_page, $mode;

		$avail_post_stati = wp_edit_posts_query();

Varun Sridharan's avatar
Varun Sridharan committed
123
		$this->set_hierarchical_display( is_post_type_hierarchical( $this->screen->post_type ) && 'menu_order title' == $this->querypost->query['orderby'] );
124

Varun Sridharan's avatar
Varun Sridharan committed
125
		$total_items = $this->hierarchical_display ? $this->querypost->post_count : $this->querypost->found_posts;
126 127 128 129 130 131 132 133 134 135

		$post_type = $this->screen->post_type;
		$per_page = $this->get_items_per_page( 'edit_' . $post_type . '_per_page' );

		/** This filter is documented in wp-admin/includes/post.php */
 		$per_page = apply_filters( 'edit_posts_per_page', $per_page, $post_type );

		if ( $this->hierarchical_display )
			$total_pages = ceil( $total_items / $per_page );
		else
Varun Sridharan's avatar
Varun Sridharan committed
136
			$total_pages = $this->querypost->max_num_pages;
137 138 139 140 141 142 143 144

		if ( ! empty( $_REQUEST['mode'] ) ) {
			$mode = $_REQUEST['mode'] == 'excerpt' ? 'excerpt' : 'list';
			set_user_setting ( 'posts_list_mode', $mode );
		} else {
			$mode = get_user_setting ( 'posts_list_mode', 'list' );
		}

Varun Sridharan's avatar
Varun Sridharan committed
145
		$this->is_trash = isset( $_REQUEST['post_status'] ) && $_REQUEST['post_status'] == 'trash';
146 147 148 149 150 151 152 153

		$this->set_pagination_args( array(
			'total_items' => $total_items,
			'total_pages' => $total_pages,
			'per_page' => $per_page
		) );
	}

Varun Sridharan's avatar
Varun Sridharan committed
154 155 156 157
	/**
	 *
	 * @return bool
	 */
158
	public function has_items() {
Varun Sridharan's avatar
Varun Sridharan committed
159
		return $this->querypost->have_posts();
160 161
	}

Varun Sridharan's avatar
Varun Sridharan committed
162 163 164
	/**
	 * @access public
	 */
165 166 167 168 169 170 171
	public function no_items() {
		if ( isset( $_REQUEST['post_status'] ) && 'trash' == $_REQUEST['post_status'] )
			echo get_post_type_object( $this->screen->post_type )->labels->not_found_in_trash;
		else
			echo get_post_type_object( $this->screen->post_type )->labels->not_found;
	}

Varun Sridharan's avatar
Varun Sridharan committed
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
	/**
	 * Determine if the current view is the "All" view.
	 *
	 * @since 4.2.0
	 *
	 * @return bool Whether the current view is the "All" view.
	 */
	protected function is_base_request() {
		if ( empty( $_GET ) ) {
			return true;
		} elseif ( 1 === count( $_GET ) && ! empty( $_GET['post_type'] ) ) {
			return $this->screen->post_type === $_GET['post_type'];
		}
	}

    function wp_count_posts( $type = 'post', $perm = '' ) {
        global $wpdb;

        if ( ! post_type_exists( $type ) )
            return new stdClass;

        $cache_key = _count_posts_cache_key( $type.'_donation', $perm );
        $counts = wp_cache_get( $cache_key, 'counts' );
        if ( false !== $counts ) {return $counts;}
        
        $query  = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} ";
        $query .= "LEFT JOIN {$wpdb->postmeta} ON wp_postmeta.post_id = wp_posts.ID ";
        $query .= 'WHERE wp_postmeta.meta_key = "_is_donation" AND wp_postmeta.meta_value = 1 AND post_type = %s ';
        $query .= 'GROUP BY post_status ';

        $results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
        $counts = array_fill_keys( get_post_stati(), 0 );

        foreach ( $results as $row ) {$counts[ $row['post_status'] ] = $row['num_posts'];}

        $counts = (object) $counts;
        wp_cache_set( $cache_key.'_donation', $counts, 'counts' );

        return $counts;
    }    
	/**
	 *
	 * @global array $locked_post_status This seems to be deprecated.
	 * @global array $avail_post_stati
	 * @return array
	 */
218 219 220 221 222 223 224 225 226
	protected function get_views() {
		global $locked_post_status, $avail_post_stati;

		$post_type = $this->screen->post_type;

		if ( !empty($locked_post_status) )
			return array();

		$status_links = array();
Varun Sridharan's avatar
Varun Sridharan committed
227 228
		$num_posts = $this->wp_count_posts( $post_type, 'readable' );
        
229 230 231 232 233 234 235 236 237 238
		$class = '';
		$allposts = '';

		$current_user_id = get_current_user_id();

		if ( $this->user_posts_count ) {
			if ( isset( $_GET['author'] ) && ( $_GET['author'] == $current_user_id ) )
				$class = ' class="current"';
			$status_links['mine'] = "<a href='edit.php?post_type=$post_type&author=$current_user_id'$class>" . sprintf( _nx( 'Mine <span class="count">(%s)</span>', 'Mine <span class="count">(%s)</span>', $this->user_posts_count, 'posts' ), number_format_i18n( $this->user_posts_count ) ) . '</a>';
			$allposts = '&all_posts=1';
Varun Sridharan's avatar
Varun Sridharan committed
239
			$class = '';
240 241 242 243 244 245 246 247
		}

		$total_posts = array_sum( (array) $num_posts );

		// Subtract post types that are not included in the admin all list.
		foreach ( get_post_stati( array('show_in_admin_all_list' => false) ) as $state )
			$total_posts -= $num_posts->$state;

Varun Sridharan's avatar
Varun Sridharan committed
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
		if ( empty( $class ) && ( ( $this->is_base_request() && ! $this->user_posts_count ) || isset( $_REQUEST['all_posts'] ) ) ) {
			$class =  ' class="current"';
		}

		$all_inner_html = sprintf(
			_nx(
				'All <span class="count">(%s)</span>',
				'All <span class="count">(%s)</span>',
				$total_posts,
				'posts'
			),
			number_format_i18n( $total_posts )
		);

		$status_links['all'] = "<a href='edit.php?post_type=$post_type{$allposts}'$class>" . $all_inner_html . '</a>';
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277

		foreach ( get_post_stati(array('show_in_admin_status_list' => true), 'objects') as $status ) {
			$class = '';

			$status_name = $status->name;

			if ( !in_array( $status_name, $avail_post_stati ) )
				continue;

			if ( empty( $num_posts->$status_name ) )
				continue;

			if ( isset($_REQUEST['post_status']) && $status_name == $_REQUEST['post_status'] )
				$class = ' class="current"';

Varun Sridharan's avatar
Varun Sridharan committed
278
			$status_links[$status_name] = "<a href='edit.php?post_type=wcqd_project&amp;page=wc_qd_orders&amp;order_status=$status_name'$class>" . sprintf( translate_nooped_plural( $status->label_count, $num_posts->$status_name ), number_format_i18n( $num_posts->$status_name ) ) . '</a>';
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
		}

		if ( ! empty( $this->sticky_posts_count ) ) {
			$class = ! empty( $_REQUEST['show_sticky'] ) ? ' class="current"' : '';

			$sticky_link = array( 'sticky' => "<a href='edit.php?post_type=$post_type&amp;show_sticky=1'$class>" . sprintf( _nx( 'Sticky <span class="count">(%s)</span>', 'Sticky <span class="count">(%s)</span>', $this->sticky_posts_count, 'posts' ), number_format_i18n( $this->sticky_posts_count ) ) . '</a>' );

			// Sticky comes after Publish, or if not listed, after All.
			$split = 1 + array_search( ( isset( $status_links['publish'] ) ? 'publish' : 'all' ), array_keys( $status_links ) );
			$status_links = array_merge( array_slice( $status_links, 0, $split ), $sticky_link, array_slice( $status_links, $split ) );
		}

		return $status_links;
	}

Varun Sridharan's avatar
Varun Sridharan committed
294 295 296 297
	/**
	 *
	 * @return array
	 */
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
	protected function get_bulk_actions() {
		$actions = array();
		$post_type_obj = get_post_type_object( $this->screen->post_type );

		if ( $this->is_trash ) {
			$actions['untrash'] = __( 'Restore' );
		} else {
			$actions['edit'] = __( 'Edit' );
		}

		if ( current_user_can( $post_type_obj->cap->delete_posts ) ) {
			if ( $this->is_trash || ! EMPTY_TRASH_DAYS ) {
				$actions['delete'] = __( 'Delete Permanently' );
			} else {
				$actions['trash'] = __( 'Move to Trash' );
			}
		}

		return $actions;
	}
Varun Sridharan's avatar
Varun Sridharan committed
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
    
    public function get_donation_projects(){
        $args = array(
            'post_type'             => WC_QD_PT,
            'post_status'           => 'publish',
            'ignore_sticky_posts'   => 0,
            'posts_per_page'        => '0',
            'fields' => 'ids'
        );
        $products = new WP_Query($args);
        echo '<select name="dproj" id="donation_project" class="wc-enhanced-select">';
            echo '<option value=""> '.__('Donation Project',WC_QD_TXT).'</option>';
            foreach($products->get_posts() as $id){
                $attr = '';
                if(isset($_GET['dproj']) && $id == $_GET['dproj']){ $attr = 'selected';}
                echo '<option value="'.$id.'" '.$attr.'> '.get_the_title($id).'</option>';
            }
        echo '</select>';    
    }
        
        
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365

	/**
	 * @global int $cat
	 * @param string $which
	 */
	protected function extra_tablenav( $which ) {
		global $cat;
?>
		<div class="alignleft actions">
<?php
		if ( 'top' == $which && !is_singular() ) {

			$this->months_dropdown( $this->screen->post_type );

			if ( is_object_in_taxonomy( $this->screen->post_type, 'category' ) ) {
				$dropdown_options = array(
					'show_option_all' => __( 'All categories' ),
					'hide_empty' => 0,
					'hierarchical' => 1,
					'show_count' => 0,
					'orderby' => 'name',
					'selected' => $cat
				);

				echo '<label class="screen-reader-text" for="cat">' . __( 'Filter by category' ) . '</label>';
				wp_dropdown_categories( $dropdown_options );
			}
Varun Sridharan's avatar
Varun Sridharan committed
366
            $this->get_donation_projects();
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
			/**
			 * Fires before the Filter button on the Posts and Pages list tables.
			 *
			 * The Filter button allows sorting by date and/or category on the
			 * Posts list table, and sorting by date on the Pages list table.
			 *
			 * @since 2.1.0
			 */
			do_action( 'restrict_manage_posts' );

			submit_button( __( 'Filter' ), 'button', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
		}

		if ( $this->is_trash && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts ) ) {
			submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false );
		}
?>
		</div>
<?php
	}

Varun Sridharan's avatar
Varun Sridharan committed
388 389 390 391
	/**
	 *
	 * @return string
	 */
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
	public function current_action() {
		if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
			return 'delete_all';

		return parent::current_action();
	}

	/**
	 * @global string $mode
	 * @param string $which
	 */
	protected function pagination( $which ) {
		global $mode;

		parent::pagination( $which );

		if ( 'top' == $which && ! is_post_type_hierarchical( $this->screen->post_type ) )
			$this->view_switcher( $mode );
	}

Varun Sridharan's avatar
Varun Sridharan committed
412 413 414 415
	/**
	 *
	 * @return array
	 */
416
	protected function get_table_classes() {
Varun Sridharan's avatar
Varun Sridharan committed
417
		return array( 'widefat', 'fixed', 'striped', is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts' );
418 419
	}

Varun Sridharan's avatar
Varun Sridharan committed
420 421 422 423
	/**
	 *
	 * @return array
	 */
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
	public function get_columns() {
		$post_type = $this->screen->post_type;

		$posts_columns = array();

		$posts_columns['cb'] = '<input type="checkbox" />';

		/* translators: manage posts column name */
		$posts_columns['title'] = _x( 'Title', 'column name' );

		if ( post_type_supports( $post_type, 'author' ) ) {
			$posts_columns['author'] = __( 'Author' );
		}

		$taxonomies = get_object_taxonomies( $post_type, 'objects' );
		$taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' );

		/**
		 * Filter the taxonomy columns in the Posts list table.
		 *
		 * The dynamic portion of the hook name, `$post_type`, refers to the post
		 * type slug.
		 *
		 * @since 3.5.0
		 *
		 * @param array  $taxonomies Array of taxonomies to show columns for.
		 * @param string $post_type  The post type.
		 */
		$taxonomies = apply_filters( "manage_taxonomies_for_{$post_type}_columns", $taxonomies, $post_type );
		$taxonomies = array_filter( $taxonomies, 'taxonomy_exists' );

		foreach ( $taxonomies as $taxonomy ) {
			if ( 'category' == $taxonomy )
				$column_key = 'categories';
			elseif ( 'post_tag' == $taxonomy )
				$column_key = 'tags';
			else
				$column_key = 'taxonomy-' . $taxonomy;

			$posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name;
		}

		$post_status = !empty( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all';
		if ( post_type_supports( $post_type, 'comments' ) && !in_array( $post_status, array( 'pending', 'draft', 'future' ) ) )
Varun Sridharan's avatar
Varun Sridharan committed
468
			$posts_columns['comments'] = '<span class="vers comment-grey-bubble" title="' . esc_attr__( 'Comments' ) . '"><span class="screen-reader-text">' . __( 'Comments' ) . '</span></span>';
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503

		$posts_columns['date'] = __( 'Date' );

		if ( 'page' == $post_type ) {

			/**
			 * Filter the columns displayed in the Pages list table.
			 *
			 * @since 2.5.0
			 *
			 * @param array $post_columns An array of column names.
			 */
			$posts_columns = apply_filters( 'manage_pages_columns', $posts_columns );
		} else {

			/**
			 * Filter the columns displayed in the Posts list table.
			 *
			 * @since 1.5.0
			 *
			 * @param array  $posts_columns An array of column names.
			 * @param string $post_type     The post type slug.
			 */
			$posts_columns = apply_filters( 'manage_posts_columns', $posts_columns, $post_type );
		}

		/**
		 * Filter the columns displayed in the Posts list table for a specific post type.
		 *
		 * The dynamic portion of the hook name, `$post_type`, refers to the post type slug.
		 *
		 * @since 3.0.0
		 *
		 * @param array $post_columns An array of column names.
		 */
Varun Sridharan's avatar
Varun Sridharan committed
504
		return apply_filters( "manage_{$post_type}_posts_columns", $posts_columns );
505 506
	}

Varun Sridharan's avatar
Varun Sridharan committed
507 508 509 510
	/**
	 *
	 * @return array
	 */
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526
	protected function get_sortable_columns() {
		return array(
			'title'    => 'title',
			'parent'   => 'parent',
			'comments' => 'comment_count',
			'date'     => array( 'date', true )
		);
	}

	/**
	 * @global WP_Query $wp_query
	 * @global int $per_page
	 * @param array $posts
	 * @param int $level
	 */
	public function display_rows( $posts = array(), $level = 0 ) {
Varun Sridharan's avatar
Varun Sridharan committed
527
		global $per_page;
528 529

		if ( empty( $posts ) )
Varun Sridharan's avatar
Varun Sridharan committed
530 531 532
			$posts = $this->querypost->posts;
        
		add_filter( 'the_title', 'esc_html' );
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561

		if ( $this->hierarchical_display ) {
			$this->_display_rows_hierarchical( $posts, $this->get_pagenum(), $per_page );
		} else {
			$this->_display_rows( $posts, $level );
		}
	}

	/**
	 * @global string $mode
	 * @param array $posts
	 * @param int $level
	 */
	private function _display_rows( $posts, $level = 0 ) {
		global $mode;

		// Create array of post IDs.
		$post_ids = array();

		foreach ( $posts as $a_post )
			$post_ids[] = $a_post->ID;

		$this->comment_pending_count = get_pending_comments_num( $post_ids );

		foreach ( $posts as $post )
			$this->single_row( $post, $level );
	}

	/**
Varun Sridharan's avatar
Varun Sridharan committed
562 563
	 * @global wpdb    $wpdb
	 * @global WP_Post $post
564 565 566 567 568 569 570 571 572 573 574 575 576
	 * @param array $pages
	 * @param int $pagenum
	 * @param int $per_page
	 */
	private function _display_rows_hierarchical( $pages, $pagenum = 1, $per_page = 20 ) {
		global $wpdb;

		$level = 0;

		if ( ! $pages ) {
			$pages = get_pages( array( 'sort_column' => 'menu_order' ) );

			if ( ! $pages )
Varun Sridharan's avatar
Varun Sridharan committed
577
				return;
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
		}

		/*
		 * Arrange pages into two parts: top level pages and children_pages
		 * children_pages is two dimensional array, eg.
		 * children_pages[10][] contains all sub-pages whose parent is 10.
		 * It only takes O( N ) to arrange this and it takes O( 1 ) for subsequent lookup operations
		 * If searching, ignore hierarchy and treat everything as top level
		 */
		if ( empty( $_REQUEST['s'] ) ) {

			$top_level_pages = array();
			$children_pages = array();

			foreach ( $pages as $page ) {

				// Catch and repair bad pages.
				if ( $page->post_parent == $page->ID ) {
					$page->post_parent = 0;
Varun Sridharan's avatar
Varun Sridharan committed
597
					$wpdb->update( $wpdb->posts, array( 'post_parent' => 0 ), array( 'ID' => $page->ID ) );
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
					clean_post_cache( $page );
				}

				if ( 0 == $page->post_parent )
					$top_level_pages[] = $page;
				else
					$children_pages[ $page->post_parent ][] = $page;
			}

			$pages = &$top_level_pages;
		}

		$count = 0;
		$start = ( $pagenum - 1 ) * $per_page;
		$end = $start + $per_page;
Varun Sridharan's avatar
Varun Sridharan committed
613
		$to_display = array();
614 615 616 617 618 619

		foreach ( $pages as $page ) {
			if ( $count >= $end )
				break;

			if ( $count >= $start ) {
Varun Sridharan's avatar
Varun Sridharan committed
620
				$to_display[$page->ID] = $level;
621 622 623 624 625
			}

			$count++;

			if ( isset( $children_pages ) )
Varun Sridharan's avatar
Varun Sridharan committed
626
				$this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );
627 628 629 630 631 632 633 634 635 636
		}

		// If it is the last pagenum and there are orphaned pages, display them with paging as well.
		if ( isset( $children_pages ) && $count < $end ){
			foreach ( $children_pages as $orphans ){
				foreach ( $orphans as $op ) {
					if ( $count >= $end )
						break;

					if ( $count >= $start ) {
Varun Sridharan's avatar
Varun Sridharan committed
637
						$to_display[$op->ID] = 0;
638 639 640 641 642 643
					}

					$count++;
				}
			}
		}
Varun Sridharan's avatar
Varun Sridharan committed
644 645 646 647 648 649 650 651 652 653 654 655

		$ids = array_keys( $to_display );
		_prime_post_caches( $ids );

		if ( ! isset( $GLOBALS['post'] ) ) {
			$GLOBALS['post'] = reset( $ids );
		}

		foreach ( $to_display as $page_id => $level ) {
			echo "\t";
			$this->single_row( $page_id, $level );
		}
656 657 658 659 660 661 662
	}

	/**
	 * Given a top level page ID, display the nested hierarchy of sub-pages
	 * together with paging support
	 *
	 * @since 3.1.0 (Standalone function exists since 2.6.0)
Varun Sridharan's avatar
Varun Sridharan committed
663
	 * @since 4.2.0 Added the `$to_display` parameter.
664 665 666 667 668 669 670
	 *
	 * @param array $children_pages
	 * @param int $count
	 * @param int $parent
	 * @param int $level
	 * @param int $pagenum
	 * @param int $per_page
Varun Sridharan's avatar
Varun Sridharan committed
671
	 * @param array $to_display List of pages to be displayed. Passed by reference.
672
	 */
Varun Sridharan's avatar
Varun Sridharan committed
673
	private function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page, &$to_display ) {
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688
		if ( ! isset( $children_pages[$parent] ) )
			return;

		$start = ( $pagenum - 1 ) * $per_page;
		$end = $start + $per_page;

		foreach ( $children_pages[$parent] as $page ) {
			if ( $count >= $end )
				break;

			// If the page starts in a subtree, print the parents.
			if ( $count == $start && $page->post_parent > 0 ) {
				$my_parents = array();
				$my_parent = $page->post_parent;
				while ( $my_parent ) {
Varun Sridharan's avatar
Varun Sridharan committed
689 690 691 692 693 694 695
					// Get the ID from the list or the attribute if my_parent is an object
					$parent_id = $my_parent;
					if ( is_object( $my_parent ) ) {
						$parent_id = $my_parent->ID;
					}

					$my_parent = get_post( $parent_id );
696 697 698 699 700 701 702
					$my_parents[] = $my_parent;
					if ( !$my_parent->post_parent )
						break;
					$my_parent = $my_parent->post_parent;
				}
				$num_parents = count( $my_parents );
				while ( $my_parent = array_pop( $my_parents ) ) {
Varun Sridharan's avatar
Varun Sridharan committed
703
					$to_display[$my_parent->ID] = $level - $num_parents;
704 705 706 707 708
					$num_parents--;
				}
			}

			if ( $count >= $start ) {
Varun Sridharan's avatar
Varun Sridharan committed
709
				$to_display[$page->ID] = $level;
710 711 712 713
			}

			$count++;

Varun Sridharan's avatar
Varun Sridharan committed
714
			$this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );
715 716 717 718 719 720
		}

		unset( $children_pages[$parent] ); //required in order to keep track of orphans
	}

	/**
Varun Sridharan's avatar
Varun Sridharan committed
721 722 723 724 725 726
	 * Handles the checkbox column output.
	 *
	 * @since 4.3.0
	 * @access public
	 *
	 * @param WP_Post $post The current WP_Post object.
727
	 */
Varun Sridharan's avatar
Varun Sridharan committed
728 729 730 731 732 733 734 735 736
	public function column_cb( $post ) {
		if ( current_user_can( 'edit_post', $post->ID ) ): ?>
			<label class="screen-reader-text" for="cb-select-<?php the_ID(); ?>"><?php
				printf( __( 'Select %s' ), _draft_or_post_title() );
			?></label>
			<input id="cb-select-<?php the_ID(); ?>" type="checkbox" name="post[]" value="<?php the_ID(); ?>" />
			<div class="locked-indicator"></div>
		<?php endif;
	}
737

Varun Sridharan's avatar
Varun Sridharan committed
738 739 740 741 742 743 744 745 746 747 748 749 750 751 752
	/**
	 * @since 4.3.0
	 * @access protected
	 *
	 * @param WP_Post $post
	 * @param string  $classes
	 * @param string  $data
	 * @param string  $primary
	 */
	protected function _column_title( $post, $classes, $data, $primary ) {
		echo '<td class="' . $classes . ' page-title" ', $data, '>';
		echo $this->column_title( $post );
		echo $this->handle_row_actions( $post, 'title', $primary );
		echo '</td>';
	}
753

Varun Sridharan's avatar
Varun Sridharan committed
754 755 756 757 758 759 760 761 762 763 764 765
	/**
	 * Handles the title column output.
	 *
	 * @since 4.3.0
	 * @access public
	 *
	 * @global string $mode
	 *
	 * @param WP_Post $post The current WP_Post object.
	 */
	public function column_title( $post ) {
		global $mode;
766

Varun Sridharan's avatar
Varun Sridharan committed
767 768 769 770 771 772
		if ( $this->hierarchical_display ) {
			if ( 0 === $this->current_level && (int) $post->post_parent > 0 ) {
				// Sent level 0 by accident, by default, or because we don't know the actual level.
				$find_main_page = (int) $post->post_parent;
				while ( $find_main_page > 0 ) {
					$parent = get_post( $find_main_page );
773

Varun Sridharan's avatar
Varun Sridharan committed
774 775
					if ( is_null( $parent ) ) {
						break;
776 777
					}

Varun Sridharan's avatar
Varun Sridharan committed
778 779
					$this->current_level++;
					$find_main_page = (int) $parent->post_parent;
780

Varun Sridharan's avatar
Varun Sridharan committed
781 782 783
					if ( ! isset( $parent_name ) ) {
						/** This filter is documented in wp-includes/post-template.php */
						$parent_name = apply_filters( 'the_title', $parent->post_title, $parent->ID );
784 785
					}
				}
Varun Sridharan's avatar
Varun Sridharan committed
786 787
			}
		}
788

Varun Sridharan's avatar
Varun Sridharan committed
789 790
		$pad = str_repeat( '&#8212; ', $this->current_level );
		echo "<strong>";
791

Varun Sridharan's avatar
Varun Sridharan committed
792 793 794
		$format = get_post_format( $post->ID );
		if ( $format ) {
			$label = get_post_format_string( $format );
795

Varun Sridharan's avatar
Varun Sridharan committed
796 797
			echo '<a href="' . esc_url( add_query_arg( array( 'post_format' => $format, 'post_type' => $post->post_type ), 'edit.php' ) ) . '" class="post-state-format post-format-icon post-format-' . $format . '" title="' . $label . '">' . $label . ":</a> ";
		}
798

Varun Sridharan's avatar
Varun Sridharan committed
799 800
		$can_edit_post = current_user_can( 'edit_post', $post->ID );
		$title = _draft_or_post_title();
801

Varun Sridharan's avatar
Varun Sridharan committed
802 803 804 805 806 807 808
		if ( $can_edit_post && $post->post_status != 'trash' ) {
			$edit_link = get_edit_post_link( $post->ID );
			echo '<a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $title ) ) . '">' . $pad . $title . '</a>';
		} else {
			echo $pad . $title;
		}
		_post_states( $post );
809

Varun Sridharan's avatar
Varun Sridharan committed
810 811 812 813 814
		if ( isset( $parent_name ) ) {
			$post_type_object = get_post_type_object( $post->post_type );
			echo ' | ' . $post_type_object->labels->parent_item_colon . ' ' . esc_html( $parent_name );
		}
		echo "</strong>\n";
815

Varun Sridharan's avatar
Varun Sridharan committed
816 817
		if ( $can_edit_post && $post->post_status != 'trash' ) {
			$lock_holder = wp_check_post_lock( $post->ID );
818

Varun Sridharan's avatar
Varun Sridharan committed
819 820 821 822 823 824 825
			if ( $lock_holder ) {
				$lock_holder = get_userdata( $lock_holder );
				$locked_avatar = get_avatar( $lock_holder->ID, 18 );
				$locked_text = esc_html( sprintf( __( '%s is currently editing' ), $lock_holder->display_name ) );
			} else {
				$locked_avatar = $locked_text = '';
			}
826

Varun Sridharan's avatar
Varun Sridharan committed
827 828
			echo '<div class="locked-info"><span class="locked-avatar">' . $locked_avatar . '</span> <span class="locked-text">' . $locked_text . "</span></div>\n";
		}
829

Varun Sridharan's avatar
Varun Sridharan committed
830 831
		if ( ! is_post_type_hierarchical( $this->screen->post_type ) && 'excerpt' == $mode && current_user_can( 'read_post', $post->ID ) ) {
			the_excerpt();
832
		}
Varun Sridharan's avatar
Varun Sridharan committed
833 834

		get_inline_data( $post );
835 836 837
	}

	/**
Varun Sridharan's avatar
Varun Sridharan committed
838
	 * Handles the post date column output.
839
	 *
Varun Sridharan's avatar
Varun Sridharan committed
840 841 842 843 844 845
	 * @since 4.3.0
	 * @access public
	 *
	 * @global string $mode
	 *
	 * @param WP_Post $post The current WP_Post object.
846
	 */
Varun Sridharan's avatar
Varun Sridharan committed
847
	public function column_date( $post ) {
848 849
		global $mode;

Varun Sridharan's avatar
Varun Sridharan committed
850 851 852 853 854 855 856
		if ( '0000-00-00 00:00:00' == $post->post_date ) {
			$t_time = $h_time = __( 'Unpublished' );
			$time_diff = 0;
		} else {
			$t_time = get_the_time( __( 'Y/m/d g:i:s a' ) );
			$m_time = $post->post_date;
			$time = get_post_time( 'G', true, $post );
857

Varun Sridharan's avatar
Varun Sridharan committed
858
			$time_diff = time() - $time;
859

Varun Sridharan's avatar
Varun Sridharan committed
860 861 862 863 864
			if ( $time_diff > 0 && $time_diff < DAY_IN_SECONDS ) {
				$h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
			} else {
				$h_time = mysql2date( __( 'Y/m/d' ), $m_time );
			}
865 866
		}

Varun Sridharan's avatar
Varun Sridharan committed
867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883
		if ( 'excerpt' == $mode ) {
			/**
			 * Filter the published time of the post.
			 *
			 * If $mode equals 'excerpt', the published time and date are both displayed.
			 * If $mode equals 'list' (default), the publish date is displayed, with the
			 * time and date together available as an abbreviation definition.
			 *
			 * @since 2.5.1
			 *
			 * @param array   $t_time      The published time.
			 * @param WP_Post $post        Post object.
			 * @param string  $column_name The column name.
			 * @param string  $mode        The list display mode ('excerpt' or 'list').
			 */
			echo apply_filters( 'post_date_column_time', $t_time, $post, 'date', $mode );
		} else {
884

Varun Sridharan's avatar
Varun Sridharan committed
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900
			/** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
			echo '<abbr title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post, 'date', $mode ) . '</abbr>';
		}
		echo '<br />';
		if ( 'publish' == $post->post_status ) {
			_e( 'Published' );
		} elseif ( 'future' == $post->post_status ) {
			if ( $time_diff > 0 ) {
				echo '<strong class="error-message">' . __( 'Missed schedule' ) . '</strong>';
			} else {
				_e( 'Scheduled' );
			}
		} else {
			_e( 'Last Modified' );
		}
	}
901

Varun Sridharan's avatar
Varun Sridharan committed
902 903 904 905 906 907 908 909 910 911 912
	/**
	 * Handles the comments column output.
	 *
	 * @since 4.3.0
	 * @access public
	 *
	 * @param WP_Post $post The current WP_Post object.
	 */
	public function column_comments( $post ) {
		?>
		<div class="post-com-count-wrapper">
913
		<?php
Varun Sridharan's avatar
Varun Sridharan committed
914
			$pending_comments = isset( $this->comment_pending_count[$post->ID] ) ? $this->comment_pending_count[$post->ID] : 0;
915

Varun Sridharan's avatar
Varun Sridharan committed
916 917 918 919 920
			$this->comments_bubble( $post->ID, $pending_comments );
		?>
		</div>
		<?php
	}
921

Varun Sridharan's avatar
Varun Sridharan committed
922 923 924 925 926 927 928 929 930 931 932 933 934 935
	/**
	 * Handles the post author column output.
	 *
	 * @since 4.3.0
	 * @access public
	 *
	 * @param WP_Post $post The current WP_Post object.
	 */
	public function column_author( $post ) {
		printf( '<a href="%s">%s</a>',
			esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'author' => get_the_author_meta( 'ID' ) ), 'edit.php' )),
			get_the_author()
		);
	}
936

Varun Sridharan's avatar
Varun Sridharan committed
937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971
	/**
	 * Handles the default column output.
	 *
	 * @since 4.3.0
	 * @access public
	 *
	 * @param WP_Post $post        The current WP_Post object.
	 * @param string  $column_name The current column name.
	 */
	public function column_default( $post, $column_name ) {
		if ( 'categories' == $column_name ) {
			$taxonomy = 'category';
		} elseif ( 'tags' == $column_name ) {
			$taxonomy = 'post_tag';
		} elseif ( 0 === strpos( $column_name, 'taxonomy-' ) ) {
			$taxonomy = substr( $column_name, 9 );
		} else {
			$taxonomy = false;
		}
		if ( $taxonomy ) {
			$taxonomy_object = get_taxonomy( $taxonomy );
			$terms = get_the_terms( $post->ID, $taxonomy );
			if ( is_array( $terms ) ) {
				$out = array();
				foreach ( $terms as $t ) {
					$posts_in_term_qv = array();
					if ( 'post' != $post->post_type ) {
						$posts_in_term_qv['post_type'] = $post->post_type;
					}
					if ( $taxonomy_object->query_var ) {
						$posts_in_term_qv[ $taxonomy_object->query_var ] = $t->slug;
					} else {
						$posts_in_term_qv['taxonomy'] = $taxonomy;
						$posts_in_term_qv['term'] = $t->slug;
					}
972

Varun Sridharan's avatar
Varun Sridharan committed
973 974 975 976 977 978 979 980 981 982 983 984
					$out[] = sprintf( '<a href="%s">%s</a>',
						esc_url( add_query_arg( $posts_in_term_qv, 'edit.php' ) ),
						esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) )
					);
				}
				/* translators: used between list items, there is a space after the comma */
				echo join( __( ', ' ), $out );
			} else {
				echo '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . $taxonomy_object->labels->no_terms . '</span>';
			}
			return;
		}
985

Varun Sridharan's avatar
Varun Sridharan committed
986
		if ( is_post_type_hierarchical( $post->post_type ) ) {
987

Varun Sridharan's avatar
Varun Sridharan committed
988 989 990 991 992 993 994 995 996 997 998 999 1000
			/**
			 * Fires in each custom column on the Posts list table.
			 *
			 * This hook only fires if the current post type is hierarchical,
			 * such as pages.
			 *
			 * @since 2.5.0
			 *
			 * @param string $column_name The name of the column to display.
			 * @param int    $post_id     The current post ID.
			 */
			do_action( 'manage_pages_custom_column', $column_name, $post->ID );
		} else {
1001

Varun Sridharan's avatar
Varun Sridharan committed
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014
			/**
			 * Fires in each custom column in the Posts list table.
			 *
			 * This hook only fires if the current post type is non-hierarchical,
			 * such as posts.
			 *
			 * @since 1.5.0
			 *
			 * @param string $column_name The name of the column to display.
			 * @param int    $post_id     The current post ID.
			 */
			do_action( 'manage_posts_custom_column', $column_name, $post->ID );
		}
1015 1016

		/**
Varun Sridharan's avatar
Varun Sridharan committed
1017
		 * Fires for each custom column of a specific post type in the Posts list table.
1018
		 *
Varun Sridharan's avatar
Varun Sridharan committed
1019
		 * The dynamic portion of the hook name, `$post->post_type`, refers to the post type.
1020
		 *
Varun Sridharan's avatar
Varun Sridharan committed
1021
		 * @since 3.1.0
1022
		 *
Varun Sridharan's avatar
Varun Sridharan committed
1023 1024
		 * @param string $column_name The name of the column to display.
		 * @param int    $post_id     The current post ID.
1025
		 */
Varun Sridharan's avatar
Varun Sridharan committed
1026 1027
		do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID );
	}
1028

Varun Sridharan's avatar
Varun Sridharan committed
1029 1030 1031 1032 1033 1034 1035 1036
	/**
	 * @global WP_Post $post
	 *
	 * @param int|WP_Post $post
	 * @param int         $level
	 */
	public function single_row( $post, $level = 0 ) {
		$global_post = get_post();
1037

Varun Sridharan's avatar
Varun Sridharan committed
1038 1039
		$post = get_post( $post );
		$this->current_level = $level;
1040

Varun Sridharan's avatar
Varun Sridharan committed
1041 1042
		$GLOBALS['post'] = $post;
		setup_postdata( $post );
1043

Varun Sridharan's avatar
Varun Sridharan committed
1044
		$classes = 'iedit author-' . ( get_current_user_id() == $post->post_author ? 'self' : 'other' );
1045

Varun Sridharan's avatar
Varun Sridharan committed
1046 1047 1048 1049
		$lock_holder = wp_check_post_lock( $post->ID );
		if ( $lock_holder ) {
			$classes .= ' wp-locked';
		}
1050

Varun Sridharan's avatar
Varun Sridharan committed
1051 1052 1053 1054 1055 1056
		if ( $post->post_parent ) {
		    $count = count( get_post_ancestors( $post->ID ) );
		    $classes .= ' level-'. $count;
		} else {
		    $classes .= ' level-0';
		}
1057
	?>
Varun Sridharan's avatar
Varun Sridharan committed
1058 1059 1060
		<tr id="post-<?php echo $post->ID; ?>" class="<?php echo implode( ' ', get_post_class( $classes, $post->ID ) ); ?>">
			<?php $this->single_row_columns( $post ); ?>
		</tr>
1061
	<?php
Varun Sridharan's avatar
Varun Sridharan committed
1062
		$GLOBALS['post'] = $global_post;
1063 1064
	}

Varun Sridharan's avatar
Varun Sridharan committed
1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075
	/**
	 * Gets the name of the default primary column.
	 *
	 * @since 4.3.0
	 * @access protected
	 *
	 * @return string Name of the default primary column, in this case, 'title'.
	 */
	protected function get_default_primary_column_name() {
		return 'title';
	}
1076 1077


Varun Sridharan's avatar
Varun Sridharan committed
1078 1079 1080
    
	
    
1081 1082
}

Varun Sridharan's avatar
Varun Sridharan committed
1083
function tt_render_list_page($shop = ''){  
1084 1085 1086 1087 1088 1089
    $wc_qd_donation_orders_listing = new WC_Quick_Donation_Listing_Table($shop);
    $wc_qd_donation_orders_listing->prepare_items();
?>
<div class="wrap">
    <div id="icon-users" class="icon32"><br/></div>
    <h2>Donations</h2>
Varun Sridharan's avatar
Varun Sridharan committed
1090
    <form id="movies-filter" method="get"> 
Varun Sridharan's avatar
Varun Sridharan committed
1091
        <input type="hidden" name="post_type" value="wc_qd_orders" />
Varun Sridharan's avatar
Varun Sridharan committed
1092 1093 1094 1095 1096
        <input type="hidden" name="page" value="<?php echo $_REQUEST['page'] ?>" />
        <?php $wc_qd_donation_orders_listing->search_box(__('Search Donations',WC_QD_TXT), 'post' ); ?>
        <?php  
        $wc_qd_donation_orders_listing->views();
        $wc_qd_donation_orders_listing->display() ?>
1097 1098 1099
    </form>
</div>
<?php  } ?>