Index: /sites/trunk/wordpress.org/public_html/wp-content/themes/pub/gutenberg/functions.php
===================================================================
--- /sites/trunk/wordpress.org/public_html/wp-content/themes/pub/gutenberg/functions.php (revision 7580)
+++ /sites/trunk/wordpress.org/public_html/wp-content/themes/pub/gutenberg/functions.php (revision 7581)
@@ -35,28 +35,26 @@
// Use a middleware provider to intercept and modify API calls. Short-circuit POST requests, bound queries, allow media, etc.
wp_add_inline_script( 'wp-api-fetch',
- sprintf(
- 'wp.apiFetch.use( function( options, next ) {
- var isWhitelistedEndpoint = (
- lodash.startsWith( options.path, "/oembed/1.0/proxy" ) ||
- lodash.startsWith( options.path, "/gutenberg/v1/block-renderer" )
- );
-
- // Prevent non-whitelisted non-GET requests (ie. POST) to prevent errors
- if ( options.method && options.method !== "GET" && ! isWhitelistedEndpoint ) {
- // This works in enough cases to be the default return value.
- return Promise.resolve( options.data );
- }
-
- // Add limits to all GET queries which attempt unbound queries
- options.path = options.path.replace( "per_page=-1", "per_page=10" );
-
- // Load images with the view context, seems to work
- if ( lodash.startsWith( options.path, "/wp/v2/media/" ) ) {
- options.path = options.path.replace( "context=edit", "context=view" );
- }
-
- return next( options );
- } );'
- ),
+ 'wp.apiFetch.use( function( options, next ) {
+ var isWhitelistedEndpoint = (
+ lodash.startsWith( options.path, "/oembed/1.0/proxy" ) ||
+ lodash.startsWith( options.path, "/gutenberg/v1/block-renderer" )
+ );
+
+ // Prevent non-whitelisted non-GET requests (ie. POST) to prevent errors
+ if ( options.method && options.method !== "GET" && ! isWhitelistedEndpoint ) {
+ // This works in enough cases to be the default return value.
+ return Promise.resolve( options.data );
+ }
+
+ // Add limits to all GET queries which attempt unbound queries
+ options.path = options.path.replace( "per_page=-1", "per_page=10" );
+
+ // Load images with the view context, seems to work
+ if ( lodash.startsWith( options.path, "/wp/v2/media/" ) ) {
+ options.path = options.path.replace( "context=edit", "context=view" );
+ }
+
+ return next( options );
+ } );',
'after'
);
@@ -112,46 +110,44 @@
// Add a middleware provider which intercepts all uploads and stores them within the browser
wp_add_inline_script( 'wp-api-fetch',
- sprintf(
- 'wp.apiFetch.use( function( options, next ) {
- if ( options.method == "POST" && options.path == "/wp/v2/media" ) {
- var file = options.body.get("file");
-
- window.fakeUploadedMedia = window.fakeUploadedMedia || [];
- if ( ! window.fakeUploadedMedia.length ) {
- window.fakeUploadedMedia[9999000] = {};
- }
- var id = window.fakeUploadedMedia.length;
-
- window.fakeUploadedMedia[ id ] = {
- "id": id,
- "date": "", "date_gmt": "", "modified": "", "modified_gmt": "",
- "guid": {}, "title": { "rendered": file.name, "raw": file.name },
- "description": {}, "caption": {}, "alt_text": "",
- "slug": file.name, "status": "inherit", "type": "attachment", "link": "",
- "author": 0, "comment_status": "open", "ping_status": "closed",
- "media_details": {}, "media_type": file.type.split("/")[0], "mime_type": file.type,
- "source_url": "", // This gets filled below with a data uri
- "_links": {}
- };
-
- return new Promise( function( resolve ) {
- var a = new FileReader();
- a.onload = function(e) {
- window.fakeUploadedMedia[ id ].source_url = e.target.result;
- resolve( window.fakeUploadedMedia[ id ] );
- }
- a.readAsDataURL( file );
- } );
+ 'wp.apiFetch.use( function( options, next ) {
+ if ( options.method == "POST" && options.path == "/wp/v2/media" ) {
+ var file = options.body.get("file");
+
+ window.fakeUploadedMedia = window.fakeUploadedMedia || [];
+ if ( ! window.fakeUploadedMedia.length ) {
+ window.fakeUploadedMedia[9999000] = {};
}
-
- // Drag droped media of ID 9999xxx is stored within the Browser
- var path_id_match = options.path.match( "^/wp/v2/media/(9999\\\\d+)" );
- if ( path_id_match ) {
- return Promise.resolve( window.fakeUploadedMedia[ path_id_match[1] ] );
- }
-
- return next( options );
- } );'
- ),
+ var id = window.fakeUploadedMedia.length;
+
+ window.fakeUploadedMedia[ id ] = {
+ "id": id,
+ "date": "", "date_gmt": "", "modified": "", "modified_gmt": "",
+ "guid": {}, "title": { "rendered": file.name, "raw": file.name },
+ "description": {}, "caption": {}, "alt_text": "",
+ "slug": file.name, "status": "inherit", "type": "attachment", "link": "",
+ "author": 0, "comment_status": "open", "ping_status": "closed",
+ "media_details": {}, "media_type": file.type.split("/")[0], "mime_type": file.type,
+ "source_url": "", // This gets filled below with a data uri
+ "_links": {}
+ };
+
+ return new Promise( function( resolve ) {
+ var a = new FileReader();
+ a.onload = function(e) {
+ window.fakeUploadedMedia[ id ].source_url = e.target.result;
+ resolve( window.fakeUploadedMedia[ id ] );
+ }
+ a.readAsDataURL( file );
+ } );
+ }
+
+ // Drag droped media of ID 9999xxx is stored within the Browser
+ var path_id_match = options.path.match( "^/wp/v2/media/(9999\\\\d+)" );
+ if ( path_id_match ) {
+ return Promise.resolve( window.fakeUploadedMedia[ path_id_match[1] ] );
+ }
+
+ return next( options );
+ } );',
'after'
);