> */ private static array $blocks = array(); /** * Add a block to a profile-screen hook. All blocks added this way are * drawn together, one after another, in `$order` -- so the plugin's * blocks always sit in one place on the screen, whichever plugin or * module registered first. * * @param string $hook 'show_user_profile', 'edit_user_profile' or 'user_new_form'. * @param callable $render The block's renderer (receives the hook's argument). * @param string $owner 'free', 'pro', 'woo' or 'tools'. * @param int $order Position in the group (lower first). * @return void */ public static function add( string $hook, callable $render, string $owner = 'free', int $order = 50 ): void { if ( ! isset( self::$blocks[ $hook ] ) ) { self::$blocks[ $hook ] = array(); add_action( $hook, static function ( $arg = null ) use ( $hook ): void { $blocks = self::$blocks[ $hook ]; usort( $blocks, static fn( array $a, array $b ): int => array( $a[0], $a[1] ) <=> array( $b[0], $b[1] ) ); foreach ( $blocks as $block ) { ( $block[2] )( $arg ); } } ); } self::$blocks[ $hook ][] = array( $order, count( self::$blocks[ $hook ] ), self::wrap( $render, $owner ) ); } /** * Whether the stylesheet hook is in place. * * @var bool */ private static bool $hooked = false; /** * A profile-screen callback that draws $render's output as a section. * * @param callable $render Original callback (receives the hook's arguments). * @param string $owner 'free', 'pro', 'woo' or 'tools'. * @return \Closure */ public static function wrap( callable $render, string $owner = 'free' ): \Closure { self::enqueue_styles(); return static function ( ...$args ) use ( $render, $owner ): void { ob_start(); $render( ...$args ); $html = (string) ob_get_clean(); if ( '' === trim( $html ) ) { return; } // The owner's badge goes on the block's first heading. if ( 'free' !== $owner ) { ob_start(); SettingsPage::render_owner_badge( $owner ); $badge = (string) ob_get_clean(); $html = (string) preg_replace( '##', $badge . '', $html, 1 ); } printf( '
%2$s
', esc_attr( $owner ), $html // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- the feature's own, already-escaped markup. ); }; } /** * A short line under a block's heading naming the setting that added * it, with a link to that setting's section, for admins who can change it. * * @param string $setting The setting's name, e.g. "Multiple User Roles". * @param string $tab Settings tab id. * @param string $section Section id on that tab. * @return void */ public static function source_note( string $setting, string $tab, string $section ): void { if ( ! current_user_can( 'manage_options' ) ) { return; } $url = admin_url( 'admin.php?page=' . Menu::SLUG . '-settings&tab=' . rawurlencode( $tab ) ) . '#aiou-section-' . rawurlencode( $section ); ?>

' . esc_html__( 'All-In-One Utilities settings', 'all-in-one-utilities' ) . '' ); ?>