• weweloo

    (@weweloo)


    I’m developing a WordPress theme settings page using React and there is a file upload function in this page. But the upload button cannot be displayed in the page, and there is no error reported by checking the console. But if I import this component into the Gutenberg editor, the component can be displayed normally.

    import { MediaUpload, MediaUploadCheck } from '@wordpress/block-editor';
    
    export const MyMediaUploader = () => {
        const onFileSelect = ( x ) => {
            console.log( x );
        };
        return (
            <>
                <div>upload</div>
                <MediaUploadCheck>
                    <MediaUpload
                        onSelect={ onFileSelect }
                        allowedTypes={ [ 'image' ] }
                        value={ 1 }
                        render={ ( { open } ) => {
                            return <button onClick={ open }>Choose image</button>;
                        } }
                    />
                </MediaUploadCheck>
            </>
        );
    };

    I use MediaPlaceholder component in this setting page, I am prompted that I do not have permission to upload files. But I’m logged in with my admin account. My theme setting page is implemented using the rest api.

Viewing 1 replies (of 1 total)
  • Mario Santos

    (@santosguillamot)

    According to this GitHub issue, it seems MediaUploadCheck component cannot be used outside the block editor. If I understood it correctly, I assume that’s the reason it works when you import the component into the Gutenberg editor but not on your settings page.

    Maybe you can try to replicate the solution suggested in the mentioned issue, and share your feedback there if it is helpful. If that doesn’t work, you can also reactivate the issue or try to follow another approach like this one.

Viewing 1 replies (of 1 total)
  • The topic ‘MediaUpload component is not displayed in the theme settings page’ is closed to new replies.