[wp-trac] [WordPress Trac] #47071: Calling add_role() in a multi-site network causes a memory fatal error

WordPress Trac noreply at wordpress.org
Mon Apr 29 16:59:26 UTC 2019


#47071: Calling add_role() in a multi-site network causes a memory fatal error
--------------------------+-----------------------------
 Reporter:  wahabmirjan   |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  5.1.1
 Severity:  blocker       |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Hello,

 I am developing a plugin, in which I have to add a new role while
 activating it. Once I do that I get a fatal error. Here are the details.



 {{{#!php
 <?php
 function add_role () {

     // Create chart_user role if it does not exist
     $chart_user_role = get_role('no-access-role');
     if ($chart_user_role == null) {
         add_role('no-access-role', 'No-Access Role', array (
             'read' => false,
             'edit_posts' => false,
             'delete_posts' => false,
         ));
     }
 }

 register_activation_hook(__FILE__, 'add_role');

 }}}


 Once I activate the plugin, I get the following errors in the admin
 section



 {{{
 Plugin could not be activated because it triggered a fatal error.

 Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to
 allocate 262144 bytes) in C:\dev\wordpress\server\wp-content\plugins\test-
 plugin\backend\inc\activate.php on line 179

 Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to
 allocate 262144 bytes) in Unknown on line 0
 }}}




 I tried all possible solutions as suggested in many sites, including (and
 not limited to) the following:

 https://www.wpbeginner.com/wp-tutorials/fix-wordpress-memory-exhausted-
 error-increase-php-memory/

 https://stackoverflow.com/questions/21680244/fatal-error-allowed-memory-
 size-of-268435456-bytes-exhausted-tried-to-allocate


 Once I remove the call to add the new role, things work OK. So the
 **add_role()** call is definitely the culprit.


 **Please note that I have a multi-site network setup using sub-domains.**

 Thanks.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/47071>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list