Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare 1.0.1 #210

Merged
merged 34 commits into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
dee982a
Merge pull request #186 from xwp/1.0
derekherman Jul 21, 2020
8bf247f
Add block directory support.
spacedmonkey Jul 22, 2020
4a3698e
Convert comment in php.
spacedmonkey Jul 23, 2020
70b744b
Remove unneed tests.
spacedmonkey Jul 23, 2020
91fc313
Feedback
spacedmonkey Jul 23, 2020
ed55b6a
Move inside php check.
spacedmonkey Jul 23, 2020
5243018
Fix test.
spacedmonkey Jul 23, 2020
3dce76b
Fix test again.
spacedmonkey Jul 23, 2020
3852281
Ignore function.
spacedmonkey Jul 24, 2020
29d9783
Fix image import parent post attach issue
ravichdev Jul 29, 2020
146a5ab
Fix MediaUpload override issue
ravichdev Jul 29, 2020
4f6965f
Fix directory separator issue in Windows
ravichdev Jul 29, 2020
eded8c1
Merge pull request #192 from xwp/fix/block-tweaks-1
spacedmonkey Aug 3, 2020
4c3c842
Merge pull request #197 from xwp/fix/hooks
spacedmonkey Aug 3, 2020
151534c
Merge branch 'develop' into fix/198-jetpack
ravichdev Aug 3, 2020
9116437
Move hook to init method from docblock
ravichdev Aug 3, 2020
fb72abf
Fix cropping in WordPress 5.5.
spacedmonkey Aug 3, 2020
545d25b
Merge branch 'develop' into fix/193-import
ravichdev Aug 3, 2020
4af2ad3
Invert logic.
spacedmonkey Aug 3, 2020
28d1b46
Add import endpoint params
ravichdev Aug 3, 2020
fb371d1
CR feedback
ravichdev Aug 3, 2020
c2a977f
Add a better check
spacedmonkey Aug 3, 2020
95bddf3
Remove logic.
spacedmonkey Aug 3, 2020
7b8eebf
Merge pull request #199 from xwp/fix/193-import
spacedmonkey Aug 3, 2020
b946d14
Merge pull request #200 from xwp/fix/198-jetpack
spacedmonkey Aug 3, 2020
4eb4cab
Merge pull request #201 from xwp/fix/194-separator
spacedmonkey Aug 3, 2020
55d9034
Merge branch 'develop' into fix/cropped-image
spacedmonkey Aug 3, 2020
da776ce
Merge pull request #202 from xwp/fix/cropped-image
ravichdev Aug 3, 2020
fe07cd6
Change version number to 1.0.1
spacedmonkey Aug 3, 2020
7bf793d
Merge pull request #203 from xwp/release/1.0.1
spacedmonkey Aug 3, 2020
7cb29e8
Name sure site name isn't empty.
spacedmonkey Aug 6, 2020
0a78564
Add a test.
spacedmonkey Aug 7, 2020
9e6d777
Check to see host exists.
spacedmonkey Aug 7, 2020
7a26345
Merge pull request #208 from xwp/fix/empty-name
spacedmonkey Aug 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions assets/src/block-editor/blocks/image/block.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "unsplash/image",
"title": "Unsplash",
"category": "common",
"supports": {
"lightBlockWrapper": true,
Expand Down
2 changes: 1 addition & 1 deletion assets/src/media-selector/featured-image-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ addFilter(
'editor.MediaUpload',
'unsplash/extend-featured-image',
() => UnsplashMediaUpload,
20
10
);
1 change: 1 addition & 0 deletions assets/src/media-selector/helpers/import-images.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const importImage = image => {
title,
description,
caption,
parent: getConfig( 'postId' ),
};

return wp
Expand Down
15 changes: 7 additions & 8 deletions php/class-block-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,18 @@ public function __construct( $plugin ) {
* Initiate the class.
*/
public function init() {
$this->plugin->add_doc_hooks( $this );
add_action( 'init', [ $this, 'register_blocks' ] );
add_action( 'enqueue_block_editor_assets', [ $this, 'register_block_editor_assets' ] );
}

/**
* Register our custom blocks.
*
* @action init
*/
public function register_blocks() {
if ( ! function_exists( 'register_block_type' ) ) {
return;
}

$blocks_dir = $this->plugin->dir_path . '/assets/js/blocks/';
$block_folders = [
'image',
Expand All @@ -64,16 +67,12 @@ public function register_blocks() {
$metadata['render_callback'] = [ $this, $callback ];
}

if ( function_exists( '\register_block_type' ) ) {
\register_block_type( $metadata['name'], $metadata );
}
register_block_type( $metadata['name'], $metadata );
}
}

/**
* Load Gutenberg assets.
*
* @action enqueue_block_editor_assets
*/
public function register_block_editor_assets() {
// Register block editor assets.
Expand Down
63 changes: 36 additions & 27 deletions php/class-hotlink.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,25 @@ public function __construct( Plugin $plugin ) {
* Initiate the class.
*/
public function init() {
$this->plugin->add_doc_hooks( $this );
add_action( 'attachment_submitbox_misc_actions', [ $this, 'attachment_submitbox_misc_actions' ], 11 );
add_filter( 'wp_get_attachment_url', [ $this, 'wp_get_attachment_url' ], 10, 2 );
add_filter( 'wp_prepare_attachment_for_js', [ $this, 'wp_prepare_attachment_for_js' ], 99, 2 );
add_filter( 'rest_prepare_attachment', [ $this, 'rest_prepare_attachment' ], 99, 3 );
add_filter( 'content_save_pre', [ $this, 'replace_hotlinked_images_in_content' ], 99, 1 );
add_filter( 'the_content', [ $this, 'hotlink_images_in_content' ], 99, 1 );
add_filter( 'wp_get_attachment_image_src', [ $this, 'wp_get_attachment_image_src' ], 10, 5 );
add_filter( 'image_downsize', [ $this, 'image_downsize' ], 10, 3 );
add_filter( 'wp_calculate_image_srcset', [ $this, 'wp_calculate_image_srcset' ], 99, 5 );
add_filter( 'get_image_tag', [ $this, 'get_image_tag' ], 10, 6 );
add_filter( 'wp_get_attachment_caption', [ $this, 'wp_get_attachment_caption' ], 10, 2 );
add_filter( 'render_block', [ $this, 'render_block' ], 10, 2 );
add_filter( 'wp_edited_image_metadata', [ $this, 'add_edited_attachment_metadata' ], 10, 3 );
add_filter( 'wp_image_file_matches_image_meta', [ $this, 'make_unsplash_images_cropable' ], 10, 4 );
}

/**
* Filter wp_get_attachment_url
*
* @filter wp_get_attachment_url, 10, 2
*
* @param string $url Original URL.
* @param int $id Attachment ID.
*
Expand Down Expand Up @@ -77,8 +88,6 @@ public function get_attachment_url( $attachment_id ) {
* @param array $response Data for admin ajax.
* @param WP_Post $attachment Attachment object.
*
* @filter wp_prepare_attachment_for_js, 99, 2
*
* @return mixed
*/
public function wp_prepare_attachment_for_js( array $response, $attachment ) {
Expand Down Expand Up @@ -112,8 +121,6 @@ public function wp_prepare_attachment_for_js( array $response, $attachment ) {
* @param WP_Post $attachment The original attachment post.
* @param WP_REST_Request $wp_request Request used to generate the response.
*
* @filter rest_prepare_attachment, 99, 3
*
* @return mixed
*/
public function rest_prepare_attachment( $wp_response, $attachment, $wp_request ) {
Expand Down Expand Up @@ -176,8 +183,6 @@ public function rest_prepare_attachment( $wp_response, $attachment, $wp_request

/**
* Add unsplash original link to attachment edit page.
*
* @action attachment_submitbox_misc_actions, 11
*/
public function attachment_submitbox_misc_actions() {
$post = get_post();
Expand Down Expand Up @@ -240,8 +245,6 @@ public function change_full_url( array $sizes, $field, $url ) {
/**
* Filter image downsize.
*
* @filter image_downsize, 10, 3
*
* @param array $should_resize Array.
* @param int $id Attachment ID.
* @param array|string $size Size.
Expand Down Expand Up @@ -289,8 +292,6 @@ public function image_downsize( $should_resize, $id, $size ) {
/**
* Work around for image preview in Attachment screen.
*
* @filter wp_get_attachment_image_src, 10, 5
*
* @param array|false $image rray of image data, or boolean false if no image is available.
* @param int $attachment_id Image attachment ID.
* @param string|int[] $size Requested size of image. Image size name, or array of width
Expand Down Expand Up @@ -357,8 +358,6 @@ public function get_attachments_from_content( $content ) {
/**
* Replace hotlinked image URLs in content with ones from WordPress.
*
* @filter content_save_pre, 99, 1
*
* @param string $content Content.
* @return string Converted content with local images.
*/
Expand Down Expand Up @@ -411,8 +410,6 @@ public function replace_hotlinked_images_in_content( $content ) {
*
* @param string $content The raw post content to be filtered.
*
* @filter the_content, 99, 1
*
* @return string Converted content with hotlinked images.
*/
public function hotlink_images_in_content( $content ) {
Expand All @@ -432,8 +429,6 @@ public function hotlink_images_in_content( $content ) {
/**
* Filter source sets to give hotlink images.
*
* @filter wp_calculate_image_srcset, 99, 5
*
* @param array $sources {
* One or more arrays of source data to include in the 'srcset'.
*
Expand Down Expand Up @@ -648,8 +643,6 @@ public function prime_post_caches( array $attachment_ids ) {
* @param string|array $size Size of image. Image size or array of width and height values (in that order).
* Default 'medium'.
*
* @filter get_image_tag, 10, 6
*
* @return string Image tag.
*/
public function get_image_tag( $html, $id, $alt, $title, $align, $size ) {
Expand All @@ -668,8 +661,6 @@ public function get_image_tag( $html, $id, $alt, $title, $align, $size ) {
/**
* Remove html for captions, as some themes esc_html captions before displaying.
*
* @filter wp_get_attachment_caption, 10, 2
*
* @param string $caption Caption for the given attachment.
* @param int $attachment_id Attachment ID.
*
Expand All @@ -688,8 +679,6 @@ public function wp_get_attachment_caption( $caption, $attachment_id ) {
/**
* Filters the content of a single block.
*
* @filter render_block, 10, 2
*
* @param string $block_content The block content about to be appended.
* @param array $block The full block, including name and attributes.
*
Expand All @@ -710,8 +699,6 @@ public function render_block( $block_content, $block ) {
/**
* Add Unsplash metadata for edited attachment
*
* @filter wp_edited_image_metadata, 10, 3
*
* @param array $data Array of updated attachment meta data.
* @param int $new_attachment_id Attachment post ID.
* @param int $attachment_id Original Attachment post ID.
Expand All @@ -731,4 +718,26 @@ public function add_edited_attachment_metadata( $data, $new_attachment_id, $atta

return $data;
}

/**
* Filter whether an image path or URI matches image meta.
*
* @param bool $match Whether the image relative path from the image meta
* matches the end of the URI or path to the image file.
* @param string $image_location Full path or URI to the tested image file.
* @param array $image_meta (Unused) The image meta data as returned by 'wp_get_attachment_metadata()'.
* @param int $attachment_id The image attachment ID or 0 if not supplied.
*
* @return bool Can an image cropable.
*/
public function make_unsplash_images_cropable( $match, $image_location, $image_meta, $attachment_id ) {
$unsplash_url = $this->get_unsplash_url( $attachment_id );
$cropped = $this->is_cropped_image( $attachment_id );
$is_unsplash = strpos( $image_location, 'images.unsplash.com' );
if ( ! $unsplash_url || $cropped || ( false === $is_unsplash ) ) {
return $match;
}

return true;
}
}
2 changes: 1 addition & 1 deletion php/class-plugin-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function locate_plugin() {
}

$plugin_dir = dirname( dirname( $file_name ) );
$plugin_path = $this->relative_path( $plugin_dir, basename( content_url() ), \DIRECTORY_SEPARATOR );
$plugin_path = $this->relative_path( $plugin_dir, basename( content_url() ), '/' );

$dir_url = content_url( trailingslashit( $plugin_path ) );
$dir_path = $plugin_dir;
Expand Down
Loading