[wp-trac] [WordPress Trac] #47071: Calling add_role() in a multi-site network causes a memory fatal error
WordPress Trac
noreply at wordpress.org
Tue Apr 30 14:19:43 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: critical | Resolution:
Keywords: | Focuses:
--------------------------+------------------------------
Comment (by wahabmirjan):
You are right. This was my bad in reporting the issue as well.
I omitted the **namespace** declaration (I did so on purpose to simplify
the written code, but apparently that was not the right decision). The
full code that generated the bug is as follows:
{{{#!php
<?php
namespace the_awesome_code
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__, 'the_awesome_code\add_role');
}}}
Note that the **namespace** keyword is added right now; however, running
the above code will generate the error that was reported earlier.
That said, I decided to test the code as per your suggestion. So when
changing the code where the **add_role()** function was renamed to
**add_my_awesome_role()**, things worked correctly.
Obviously adding the **namespace** keyword is resulting in a loop to
recursively call the **add_role()** function. I will update the code
correctly.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/47071#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list