check_capabilities example

ob_start();
        $this->maybe_render();
        return trim( ob_get_clean() );
    }

    /** * Check capabilities and render the panel. * * @since 4.0.0 */
    final public function maybe_render() {
        if ( ! $this->check_capabilities() ) {
            return;
        }

        /** * Fires before rendering a Customizer panel. * * @since 4.0.0 * * @param WP_Customize_Panel $panel WP_Customize_Panel instance. */
        do_action( 'customize_render_panel', $this );

        

    final public function check_capabilities() {
        if ( ! empty( $this->capability ) && ! current_user_can( $this->capability ) ) {
            return false;
        }
        foreach ( $this->settings as $setting_id ) {
            $setting = $this->component->manager->get_setting( $setting_id );
            if ( ! $setting || ! $setting->check_capabilities() ) {
                return false;
            }
        }
        return true;
    }
}
'channel'           => $this->messenger_channel,
            'activePanels'      => array(),
            'activeSections'    => array(),
            'activeControls'    => array(),
            'settingValidities' => $exported_setting_validities,
            'nonce'             => current_user_can( 'customize' ) ? $this->get_nonces() : array(),
            'l10n'              => $l10n,
            '_dirty'            => array_keys( $post_values ),
        );

        foreach ( $this->panels as $panel_id => $panel ) {
            if ( $panel->check_capabilities() ) {
                $settings['activePanels'][ $panel_id ] = $panel->active();
                foreach ( $panel->sections as $section_id => $section ) {
                    if ( $section->check_capabilities() ) {
                        $settings['activeSections'][ $section_id ] = $section->active();
                    }
                }
            }
        }
        foreach ( $this->sections as $id => $section ) {
            if ( $section->check_capabilities() ) {
                $settings['activeSections'][ $id ] = $section->active();
            }


    /** * Exports data in preview after it has finished rendering so that partials can be added at runtime. * * @since 4.5.0 */
    public function export_preview_data() {
        $partials = array();

        foreach ( $this->partials() as $partial ) {
            if ( $partial->check_capabilities() ) {
                $partials[ $partial->id ] = $partial->json();
            }
        }

        $switched_locale = switch_to_user_locale( get_current_user_id() );
        $l10n            = array(
            'shiftClickToEdit' => __( 'Shift-click to edit this element.' ),
            'clickEditMenu'    => __( 'Click to edit this menu.' ),
            'clickEditWidget'  => __( 'Click to edit this widget.' ),
            'clickEditTitle'   => __( 'Click to edit the site title.' ),
            'clickEditMisc'    => __( 'Click to edit this element.' ),
            

    final public function check_capabilities() {
        if ( ! empty( $this->capability ) && ! current_user_can( $this->capability ) ) {
            return false;
        }

        foreach ( $this->settings as $setting ) {
            if ( ! $setting || ! $setting->check_capabilities() ) {
                return false;
            }
        }

        $section = $this->manager->get_section( $this->section );
        if ( isset( $section ) && ! $section->check_capabilities() ) {
            return false;
        }

        return true;
    }

    

    final public function save() {
        $value = $this->post_value();

        if ( ! $this->check_capabilities() || ! isset( $value ) ) {
            return false;
        }

        $id_base = $this->id_data['base'];

        /** * Fires when the WP_Customize_Setting::save() method is called. * * The dynamic portion of the hook name, `$id_base` refers to * the base slug of the setting name. * * @since 3.4.0 * * @param WP_Customize_Setting $setting WP_Customize_Setting instance. */
ob_start();
        $this->maybe_render();
        return trim( ob_get_clean() );
    }

    /** * Check capabilities and render the section. * * @since 3.4.0 */
    final public function maybe_render() {
        if ( ! $this->check_capabilities() ) {
            return;
        }

        /** * Fires before rendering a Customizer section. * * @since 3.4.0 * * @param WP_Customize_Section $section WP_Customize_Section instance. */
        do_action( 'customize_render_section', $this );
        
Home | Imprint | This part of the site doesn't use cookies.