Skip to content

Commit

Permalink
Merge pull request #2446 from johngodley/fix/cap-checks
Browse files Browse the repository at this point in the history
Fix cap checks so they don’t error if Redirectioni10n isnt defined
  • Loading branch information
johngodley authored Sep 3, 2020
2 parents f582206 + 672956c commit 35239b6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
5 changes: 2 additions & 3 deletions client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ const show = ( dom ) => {
ReactDOM.render( <App />, document.getElementById( dom ) );
};

if ( document.querySelector( '#react-ui' ) ) {
if ( document.querySelector( '#react-ui' ) && Redirectioni10n ) {
show( 'react-ui' );
window.redirection = Redirectioni10n.version;
}

window.redirection = Redirectioni10n.version;
4 changes: 2 additions & 2 deletions client/lib/capabilities/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* global Redirectioni10n */

export function has_capability( cap ) {
return Redirectioni10n.caps.capabilities.indexOf( cap ) !== -1;
return Redirectioni10n?.caps?.capabilities.indexOf( cap ) !== -1;
}

export function has_page_access( page ) {
return Redirectioni10n.caps.pages.indexOf( page ) !== -1;
return Redirectioni10n?.caps?.pages.indexOf( page ) !== -1;
}

export const CAP_REDIRECT_MANAGE = 'redirection_cap_redirect_manage';
Expand Down
2 changes: 1 addition & 1 deletion redirection-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ function showError() {
document.querySelector( '.react-loading' ).style.display = 'none';
document.querySelector( '.react-error' ).style.display = 'block';

if ( typeof Redirectioni10n !== 'undefined' ) {
if ( typeof Redirectioni10n !== 'undefined' && Redirectioni10n ) {
document.querySelector( '.versions' ).innerHTML = Redirectioni10n.versions.replace( /\n/g, '<br />' );
document.querySelector( '.react-error .button-primary' ).href += '&body=' + encodeURIComponent( errorText ) + encodeURIComponent( Redirectioni10n.versions );
}
Expand Down

0 comments on commit 35239b6

Please sign in to comment.