Skip to content

Add theme screenshot uploading#185

Merged
jffng merged 7 commits intotrunkfrom
add/screenshot-upload
Jan 27, 2023
Merged

Add theme screenshot uploading#185
jffng merged 7 commits intotrunkfrom
add/screenshot-upload

Conversation

@jffng
Copy link
Contributor

@jffng jffng commented Jan 25, 2023

Fixes #74

To test, try out adding a screenshot and generating a theme with the Create child, Clone, and Blank theme options.

@jffng jffng marked this pull request as ready for review January 25, 2023 07:03
Copy link
Member

@mikachan mikachan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fab!

I've left a couple of comments. I also wanted to check if we should be validating the image files server-side as well as the HTML form validation. Things such as the file size, and if there's a way to check if the file is actually an image, maybe by checking the mimetype as well as the type.

// Add screenshot.png.
// Add screenshot.
$screenshot_path = __DIR__ . '/../screenshot.png';
if ( is_uploaded_file( $screenshot['tmp_name'] ) && $screenshot['type'] === 'image/png' ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're checking the type of the file here is an image/png, but on the upload form, we say it can be a .png, .jpg, or .jpeg. I'm guessing we should probably test if the image is png or jpg/jpeg?

<?php _e('Screenshot:', 'create-block-theme'); ?><br />
<small><?php _e('Upload a new theme screenshot (2mb max | .png,.jpg,.jpeg allowed | 1200x900 recommended)', 'create-block-theme'); ?></small><br />
<input type="hidden" name="MAX_FILE_SIZE" value="20000000" />
<input type="file" accept=".png" name="screenshot" id="screenshot" class="upload"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're only accepting .png here too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modified this to only accept png, since that seems to be the standard for screenshots. What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think that makes sense, .png definitely seems to be the standard for screenshots.

@jffng
Copy link
Contributor Author

jffng commented Jan 26, 2023

I refactored this and I think it's ready for another review.

One thing is that it fails silently if the screenshot is not valid or too big, maybe we should add in some error handling as a follow up?

Copy link
Member

@mikachan mikachan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I really like the is_valid_screenshot function! This is testing well for me.

One thing is that it fails silently if the screenshot is not valid or too big, maybe we should add in some error handling as a follow up?

Yep, this sounds like a good thing to follow up on separately.

@jffng jffng merged commit 4baa52a into trunk Jan 27, 2023
@jffng jffng deleted the add/screenshot-upload branch January 27, 2023 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Theme Screenshot Upload to Export Form

2 participants