WordPress Admin Area Memory Allocation

A recent project required us to create a fairly large multipage competition entry form for a WordPress website. Because of some complex validation requirements we decided to implement the form in JavaScript using React and Redux.

The form allows the user to upload images and pdf files. These files are Base64 encoded and added to the Redux store. When the form is submitted the encoded files are transferred to the web server using Ajax, and they are then decoded and restored to their original format before being added to the WordPress media library.

This worked fine for small files, but we ran into PHP memory allocation errors when testing with large images - WordPress would attempt to allocate more memory than allowed in order to create thumbnails for the new images. This was expected and we increased the memory limits in php.ini accordingly, but to our surprise this had no effect whatsoever.

After some head-scratching we realised that we also needed to raise the WP_MAX_MEMORY_LIMIT setting in wp-config.php. Scripts running in WordPress' admin area are by default restricted to 256M memory. After adding a define( 'WP_MAX_MEMORY_LIMIT', '512M' ); to wp-config.php we no longer got memory allocation errors.

Why would a setting that affects the admin area of a WordPress site have any influence on form submission from the website's frontend? We are using Ajax calls to send the form contents to the server, and in WordPress Ajax is handled by the admin-ajax.php file located in the wp-admin folder. This is the same file that handles AJAX calls in the admin area, and so our code was subject to the default 256M memory limit.