Skip to content

Commit

Permalink
Merge b7f898b into 98337c1
Browse files Browse the repository at this point in the history
  • Loading branch information
pierlon committed Apr 23, 2020
2 parents 98337c1 + b7f898b commit d680e0e
Show file tree
Hide file tree
Showing 14 changed files with 599 additions and 261 deletions.
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ jobs:
php: "5.6"
env: WP_VERSION=5.0 DEV_LIB_ONLY=phpunit

- name: PHP unit tests (5.6, WordPress 4.9)
php: "5.6"
env: WP_VERSION=4.9 DEV_LIB_ONLY=phpunit
script:
- npm run build:js
- source "$DEV_LIB_PATH/travis.script.sh"

- name: PHP unit tests (7.4, WordPress trunk)
php: "7.4"
env: WP_VERSION=trunk DEV_LIB_ONLY=phpunit PHPUNIT_VERSION=6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { MediaUpload } from '@wordpress/media-utils';
/**
* Internal dependencies
*/
import UnsplashState from './store/unsplash_state';
import UnsplashState from '../store/unsplash_state';

/**
* Copied from Gutenberg and adapted to initialize the Unsplash state.
Expand Down
20 changes: 20 additions & 0 deletions assets/src/media-selector/featured-image-selector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* WordPress dependencies
*/
import { addFilter } from '@wordpress/hooks';

/**
* Internal dependencies
*/
import MediaUploadWithUnsplashState from './components/MediaUploadWithUnsplashState.js';

/**
* We can't override the featured image media frame Gutenberg by extending Backbone views, meaning we can't initialize
* our own state to load the Unsplash tab. Instead, we have to filter the `editor.MediaUpload` component
* (which is used by `editor.PostFeaturedImage`) and extend it to initialize our state.
*/
addFilter(
'editor.MediaUpload',
'unsplash/extend-featured-image',
() => MediaUploadWithUnsplashState
);
16 changes: 9 additions & 7 deletions assets/src/media-selector/helpers/importImages.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import apiFetch from '@wordpress/api-fetch';

/**
* Internal dependencies
*/
import isUnsplashImage from './isUnsplashImage';
import getConfig from './getConfig';

Expand Down Expand Up @@ -28,10 +29,11 @@ export default selections => {
const importImage = image => {
const { id } = image.attributes;
const importUrl = getConfig( 'route' ) + `/import/${ id }`;
const processUrl = getConfig( 'route' ) + `/post-process/`;
const processUrl = getConfig( 'route' ) + '/post-process/';

return apiFetch( { url: importUrl } )
.then( attachmentData => {
return wp
.apiRequest( { url: importUrl } )
.done( attachmentData => {
// Update image ID from imported attachment. This will be used to fetch the <img> tag.
// Note: `image.set()` is called rather than updating `image.id` directly so that potential Backbone event listeners can be fired.
image.set( {
Expand All @@ -42,8 +44,8 @@ const importImage = image => {
nonces: attachmentData.nonces,
},
} );
apiFetch( { url: processUrl + attachmentData.id } );
wp.apiRequest( { url: processUrl + attachmentData.id } );
return attachmentData;
} )
.catch( error => Promise.reject( { ...error, ...{ image } } ) );
.fail( error => jQuery.Deferred().reject( { ...error, ...{ image } } ) );
};
17 changes: 0 additions & 17 deletions assets/src/media-selector/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
/**
* WordPress dependencies
*/
import { addFilter } from '@wordpress/hooks';

/**
* Internal dependencies
*/
import './style.css';
import withUnsplashTab from './helpers/withUnsplashTab';
import MediaUpload from './MediaUpload';

// Override media frames in the respective editors to add the Unsplash tab.

Expand All @@ -33,17 +27,6 @@ if ( wp.media && wp.media.view && wp.media.view.MediaFrame ) {
}
}

/**
* We can't override the featured image media frame Gutenberg by extending Backbone views, meaning we can't initialize
* our own state to load the Unsplash tab. Instead, we have to filter the `editor.MediaUpload` component
* (which is used by `editor.PostFeaturedImage`) and extend it to initialize our state.
*/
addFilter(
'editor.MediaUpload',
'unsplash/extend-featured-image',
() => MediaUpload
);

/**
* Work around that defaults the current media library to the 'Upload files' tab. This resolves the issue of the
* Unsplash tab not being available in some media libraries, and instead showing a blank screen in the media selector.
Expand Down
8 changes: 8 additions & 0 deletions assets/src/polyfills/wp-i18n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* WordPress dependencies
*/
import * as i18n from '@wordpress/i18n';

window.wp = window.wp || {};

window.wp.i18n = i18n;
6 changes: 6 additions & 0 deletions assets/src/polyfills/wp-polyfill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* External dependencies
*/
import * as polyfill from '@babel/polyfill';

export default polyfill;
8 changes: 8 additions & 0 deletions assets/src/polyfills/wp-url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* WordPress dependencies
*/
import * as url from '@wordpress/url';

window.wp = window.wp || {};

window.wp.url = url;
Loading

0 comments on commit d680e0e

Please sign in to comment.