Last active
April 14, 2021 03:24
-
-
Save strangerstudios/5b0f732d5c654e084fa1 to your computer and use it in GitHub Desktop.
Increase memory and execution time for WP admins only.
This file contains 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
/* | |
Increase memory and execution time for WP admins | |
You can add code to your php.ini, .htaccess, or wp-config.php | |
to increase execution times and memory limits to get WordPress | |
and PMPro to work when it needs more memory, time, or both. | |
However, sometimes you only need the extra memory and time | |
when doing something an admin would be doing... like exporting | |
a members list or orders table. | |
If this is the case, you can use this code to selectively | |
increase the execution time and memory for admins only. | |
This will make sure that normal visitors don't end up | |
using more memory or apache/etc services than they need to, | |
which should make your site run smoother. | |
*/ | |
function my_init_memory() | |
{ | |
if(current_user_can("manage_options") || current_user_can("pmpro_memberslistcsv") || current_user_can("pmpro_orderscsv")) | |
{ | |
ini_set('max_execution_time', 300); //300 seconds = 5 minutes | |
ini_set('memory_limit', '256M'); | |
} | |
} | |
add_action('init', 'my_init_memory', 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This recipe is included in the blog post on "Resolving Memory Issues When Exporting the Members List or Orders to CSV" at Paid Memberships Pro here: https://www.paidmembershipspro.com/resolving-memory-issues-when-exporting-the-members-list-or-orders-to-csv/