|
30 | 30 | add_action( 'the_content', array( 'PTR\Display', 'filter_the_content' ) ); |
31 | 31 | add_action( 'rest_api_init', array( 'PTR\RestAPI', 'register_routes' ) ); |
32 | 32 |
|
| 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 | + |
33 | 73 | /** |
34 | 74 | * Get a rendered template part |
35 | 75 | * |
|
0 commit comments