PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.5.0
Forumax – AI Powered Advanced Community Forum Plugin v2.5.0
2.5.0 2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 trunk 1.0.8 1.1.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 2.0.0 All 30 releases
bbp-core / includes / eazydocs-compatibility.php

eazydocs-compatibility.php in Forumax – AI Powered Advanced Community Forum Plugin 2.5.0, at includes/eazydocs-compatibility.php

62 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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