如何删除在 WordPress 中更改“站点图标”的功能?

Alb*_*o93 2 php wordpress

我正在尝试删除在 Wordpress 站点中更改“站点图标”的功能,除非用户是“超级管理员”。

删除红框中的内容

我的第一个想法是尝试修改位于 **/wp-includes/class-wp-customize-manager.php 中的这段代码片段

        $this->add_setting( 'site_icon', array(
        'type'       => 'option',
        'capability' => 'manage_options',
        'transport'  => 'postMessage', // Previewed with JS in the Customizer controls window.
    ) );

    $this->add_control( new WP_Customize_Site_Icon_Control( $this, 'site_icon', array(
        'label'       => __( 'Site Icon' ),
        'description' => sprintf(
            /* translators: %s: site icon size in pixels */
            __( 'The Site Icon is used as a browser and app icon for your site. Icons must be square, and at least %s pixels wide and tall.' ),
            '<strong>512</strong>'
        ),
        'section'     => 'title_tagline',
        'priority'    => 60,
        'height'      => 512,
        'width'       => 512,
    ) ) );
Run Code Online (Sandbox Code Playgroud)

但我不想更改任何核心/交付的文件。有没有其他方法可以做到这一点?也许在主题的functions.php 文件中?

另外,我目前正在使用 WordPress 4.5.2 和 2012 主题。

小智 5

function remove_styles_sections($wp_customize) {
    $wp_customize->remove_control('site_icon');
}
add_action( 'customize_register', 'remove_styles_sections', 20, 1 );  
Run Code Online (Sandbox Code Playgroud)