wp_get_theme_file_editable_extensions example

if ( ! $theme->exists() ) {
    wp_die( __( 'The requested theme does not exist.' ) );
}

if ( $theme->errors() && 'theme_no_stylesheet' === $theme->errors()->get_error_code() ) {
    wp_die( __( 'The requested theme does not exist.' ) . ' ' . $theme->errors()->get_error_message() );
}

$allowed_files = array();
$style_files   = array();

$file_types = wp_get_theme_file_editable_extensions( $theme );

foreach ( $file_types as $type ) {
    switch ( $type ) {
        case 'php':
            $allowed_files += $theme->get_files( 'php', -1 );
            break;
        case 'css':
            $style_files                = $theme->get_files( 'css', -1 );
            $allowed_files['style.css'] = $style_files['style.css'];
            $allowed_files             += $style_files;
            break;
        
if ( ! wp_verify_nonce( $args['nonce'], 'edit-theme_' . $stylesheet . '_' . $file ) ) {
            return new WP_Error( 'nonce_failure' );
        }

        if ( $theme->errors() && 'theme_no_stylesheet' === $theme->errors()->get_error_code() ) {
            return new WP_Error(
                'theme_no_stylesheet',
                __( 'The requested theme does not exist.' ) . ' ' . $theme->errors()->get_error_message()
            );
        }

        $editable_extensions = wp_get_theme_file_editable_extensions( $theme );

        $allowed_files = array();
        foreach ( $editable_extensions as $type ) {
            switch ( $type ) {
                case 'php':
                    $allowed_files = array_merge( $allowed_files$theme->get_files( 'php', -1 ) );
                    break;
                case 'css':
                    $style_files                = $theme->get_files( 'css', -1 );
                    $allowed_files['style.css'] = $style_files['style.css'];
                    $allowed_files              = array_merge( $allowed_files$style_files );
                    
Home | Imprint | This part of the site doesn't use cookies.