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

Fix getWPAdminUrl function to actually return the /wp-admin/ URL #7096

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion editor/components/post-last-revision/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import { sprintf, _n } from '@wordpress/i18n';
import { IconButton } from '@wordpress/components';
import { withSelect } from '@wordpress/data';
import { getWPAdminURL } from '@wordpress/utils';

/**
* Internal dependencies
*/
import './style.scss';
import PostLastRevisionCheck from './check';
import { getWPAdminURL } from '../../utils/url';

function LastRevision( { lastRevisionId, revisionsCount } ) {
return (
Expand Down
2 changes: 1 addition & 1 deletion editor/components/post-permalink/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { withDispatch, withSelect } from '@wordpress/data';
import { Component, compose } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { ClipboardButton, Button } from '@wordpress/components';
import { getWPAdminURL } from '@wordpress/utils';

/**
* Internal Dependencies
*/
import './style.scss';
import PostPermalinkEditor from './editor.js';
import { getWPAdminURL } from '../../utils/url';

class PostPermalink extends Component {
constructor() {
Expand Down
2 changes: 1 addition & 1 deletion editor/store/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { speak } from '@wordpress/a11y';
/**
* Internal dependencies
*/
import { getWPAdminURL } from '../utils/url';
import { getWPAdminURL } from '@wordpress/utils';
import {
setupEditorState,
resetAutosave,
Expand Down
18 changes: 0 additions & 18 deletions editor/utils/url.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
/**
* WordPress dependencies
*/
import { addQueryArgs } from '@wordpress/url';

/**
* Returns the URL of a WPAdmin Page.
*
* TODO: This should be moved to a module less specific to the editor.
*
* @param {string} page Page to navigate to.
* @param {Object} query Query Args.
*
* @return {string} WPAdmin URL.
*/
export function getWPAdminURL( page, query ) {
return addQueryArgs( page, query );
}

/**
* Returns a URL for display.
Expand Down
1 change: 1 addition & 0 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ function gutenberg_register_scripts_and_styles() {
);
wp_add_inline_script( 'wp-utils', 'var originalUtils = window.wp && window.wp.utils ? window.wp.utils : {};', 'before' );
wp_add_inline_script( 'wp-utils', 'for ( var key in originalUtils ) wp.utils[ key ] = originalUtils[ key ];' );
wp_add_inline_script( 'wp-utils', sprintf( 'wp.utils.setWPAdminURL( %s );', wp_json_encode( admin_url() ) ), 'after' );
wp_register_script(
'wp-date',
gutenberg_url( 'build/date/index.js' ),
Expand Down
2 changes: 2 additions & 0 deletions utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ export { keycodes };
export * from './mediaupload';
export * from './terms';

export { setWPAdminURL, getWPAdminURL } from './urls';

// Deprecations
export * from './deprecated';
23 changes: 23 additions & 0 deletions utils/urls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* WordPress dependencies
*/
import { addQueryArgs } from '@wordpress/url';

let wpAdminURL = '';

/**
* Returns the URL of a WPAdmin Page.
*
* @param {string} page Page to navigate to.
* @param {Object} query Query Args.
*
* @return {string} WPAdmin URL.
*/
export function getWPAdminURL( page, query ) {
const url = wpAdminURL + page;
return addQueryArgs( url, query );
}

export function setWPAdminURL( url ) {
wpAdminURL = url;
}