Forked from wpmudev-sls/wpmudev-hustle-fix-memory-size-error.php
Created
June 4, 2022 15:04
-
-
Save glaubersilva/91a9f1612dd592303f7236ed787a9c88 to your computer and use it in GitHub Desktop.
[Hustle] Fix Memory Size Error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Plugin Name: [Hustle] Fix Memory Size Error | |
| * Plugin URI: https://wpmudev.com/ | |
| * Description: When the site has a huge number of posts (or any other CPT as product for example) the queries used to get the items to be used on the wp_localize_script( 'optin_admin_scripts', 'optinVars', $optin_vars ) method generates a fatal error related to memory size. This plugin fix this temporally while a final solutions isn't implemented on the core of the Hustle plugin. | |
| * Author: Glauber Silva @ WPMUDEV | |
| * Author URI: https://wpmudev.com/ | |
| * Task: SLS-3394 and SLS-3326 | |
| * License: GPLv2 or later | |
| * | |
| * @package Hustle_Fix_Memory_Size_Error | |
| */ | |
| defined( 'ABSPATH' ) || exit; | |
| function wpmudev_intercept_queries_in_hustle_pages( $query ) { | |
| $pages_to_check = array( | |
| 'hustle_popup_listing', | |
| 'hustle_popup', | |
| 'hustle_slidein_listing', | |
| 'hustle_slidein', | |
| 'hustle_embedded_listing', | |
| 'hustle_embedded', | |
| 'hustle_sshare_listing', | |
| 'hustle_sshare', | |
| ); | |
| $post_types_to_intercept = array( | |
| 'post', | |
| 'product', | |
| ); | |
| if ( is_admin() && | |
| in_array( $_REQUEST['page'], $pages_to_check ) && | |
| in_array( $query->query_vars['post_type'], $post_types_to_intercept ) && | |
| -1 === $query->query_vars['numberposts'] ) { | |
| $query->set( 'posts_per_page', 0 ); | |
| } | |
| } | |
| add_action( 'pre_get_posts', 'wpmudev_intercept_queries_in_hustle_pages' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment