Skip to content

Commit fce2fe7

Browse files
authored
Merge pull request #101 from WordPress/fix/100
2 parents 5377958 + e320786 commit fce2fe7

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

phpunit-test-reporter.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,46 @@
3030
add_action( 'the_content', array( 'PTR\Display', 'filter_the_content' ) );
3131
add_action( 'rest_api_init', array( 'PTR\RestAPI', 'register_routes' ) );
3232

33+
add_action( 'load-edit.php', 'ptr_load_edit_php' );
34+
35+
/**
36+
* Override the post type list table.
37+
*
38+
* The Results post type Quick Edit 'Page Parent' dropdown is tens of thousands of items long,
39+
* and causes PHP OOM errors.
40+
* This replaces it with a variant that doesn't support inline editing.. through a very non-conventional method.
41+
*/
42+
function ptr_load_edit_php() {
43+
if ( ! isset( $_GET['post_type'] ) || 'result' != $_GET['post_type'] ) {
44+
return;
45+
}
46+
47+
require_once ABSPATH . 'wp-admin/includes/class-wp-posts-list-table.php';
48+
require_once __DIR__ . '/src/class-posts-list-table.php';
49+
50+
add_action( 'parse_request', 'ptr_override_results_list_table' );
51+
}
52+
53+
/**
54+
* Override the edit.php?post_type=results WP_Post_List_Table.
55+
*
56+
* This is the most ridiculous hack I've hacked, but this totally works.
57+
*/
58+
function ptr_override_results_list_table() {
59+
global $wp_list_table;
60+
61+
if (
62+
isset( $wp_list_table ) &&
63+
'WP_Posts_List_Table' == get_class( $wp_list_table )
64+
) {
65+
remove_action( 'parse_request', __FUNCTION__ );
66+
67+
$wp_list_table = new PTR\Posts_List_Table();
68+
// We were within WP_Posts_List_Table::prepare_items() when we overrode it, so we have to query again.
69+
$wp_list_table->prepare_items();
70+
}
71+
}
72+
3373
/**
3474
* Get a rendered template part
3575
*

src/class-posts-list-table.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
namespace PTR;
3+
4+
use WP_Posts_List_Table;
5+
6+
class Posts_List_Table extends WP_Posts_List_Table {
7+
8+
function __construct( $args = array() ) {
9+
parent::__construct( $args );
10+
11+
add_filter( 'page_row_actions', [ $this, 'remove_quick_edit_link' ] );
12+
}
13+
14+
function inline_edit() {
15+
// silence is golden, no more OOM.
16+
}
17+
18+
function remove_quick_edit_link( $links ) {
19+
unset( $links['inline hide-if-no-js'] );
20+
return $links;
21+
}
22+
23+
}

0 commit comments

Comments
 (0)