| 1 |
<?php |
| 2 |
/** |
| 3 |
* EazyDocs compatibility. |
| 4 |
* |
| 5 |
* EazyDocs' user_has_cap filter calls is_super_admin( $user->ID ). On a single |
| 6 |
* site that calls $user->has_cap( 'delete_users' ), which re-enters the same |
| 7 |
* filter and recurses until PHP runs out of memory. |
| 8 |
* |
| 9 |
* Forumax topic pages trigger this because they resolve the topic author's |
| 10 |
* role and capabilities. The current viewer can be an administrator and still |
| 11 |
* fatal — the loop is on the author's user object, not the logged-in staff. |
| 12 |
* |
| 13 |
* @package Forumax |
| 14 |
*/ |
| 15 |
|
| 16 |
defined( 'ABSPATH' ) || exit; |
| 17 |
|
| 18 |
/** |
| 19 |
* Replace the EazyDocs cap filter with a re-entry-safe wrapper. |
| 20 |
* |
| 21 |
* @return void |
| 22 |
*/ |
| 23 |
function forumax_patch_eazydocs_user_has_cap() { |
| 24 |
if ( ! function_exists( 'ezd_filter_user_has_cap' ) ) { |
| 25 |
return; |
| 26 |
} |
| 27 |
|
| 28 |
remove_filter( 'user_has_cap', 'ezd_filter_user_has_cap', 10 ); |
| 29 |
add_filter( 'user_has_cap', 'forumax_safe_ezd_user_has_cap', 10, 4 ); |
| 30 |
} |
| 31 |
add_action( 'plugins_loaded', 'forumax_patch_eazydocs_user_has_cap', 99 ); |
| 32 |
|
| 33 |
/** |
| 34 |
* Run EazyDocs' cap grants without letting is_super_admin() recurse. |
| 35 |
* |
| 36 |
* @param array $allcaps All capabilities for the user. |
| 37 |
* @param array $caps Required capabilities being checked. |
| 38 |
* @param array $args Additional arguments passed to the check. |
| 39 |
* @param \WP_User $user The user object. |
| 40 |
* @return array |
| 41 |
*/ |
| 42 |
function forumax_safe_ezd_user_has_cap( $allcaps, $caps, $args, $user ) { |
| 43 |
static $guard = array(); |
| 44 |
|
| 45 |
$uid = ( isset( $user->ID ) ) ? (int) $user->ID : 0; |
| 46 |
if ( $uid && isset( $guard[ $uid ] ) ) { |
| 47 |
return $allcaps; |
| 48 |
} |
| 49 |
|
| 50 |
if ( $uid ) { |
| 51 |
$guard[ $uid ] = true; |
| 52 |
} |
| 53 |
|
| 54 |
$allcaps = ezd_filter_user_has_cap( $allcaps, $caps, $args, $user ); |
| 55 |
|
| 56 |
if ( $uid ) { |
| 57 |
unset( $guard[ $uid ] ); |
| 58 |
} |
| 59 |
|
| 60 |
return $allcaps; |
| 61 |
} |
| 62 |
|