From 672956c0297ae9173ccad84d02fa4a14be6c5bef Mon Sep 17 00:00:00 2001 From: John Godley Date: Thu, 3 Sep 2020 19:30:06 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20cap=20checks=20so=20they=20don=E2=80=99t?= =?UTF-8?q?=20error=20if=20Redirectioni10n=20isnt=20defined?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/index.js | 5 ++--- client/lib/capabilities/index.js | 4 ++-- redirection-admin.php | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/client/index.js b/client/index.js index 63f7049a..5efc3832 100644 --- a/client/index.js +++ b/client/index.js @@ -27,8 +27,7 @@ const show = ( dom ) => { ReactDOM.render( , 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; diff --git a/client/lib/capabilities/index.js b/client/lib/capabilities/index.js index 9726e404..ff4216eb 100644 --- a/client/lib/capabilities/index.js +++ b/client/lib/capabilities/index.js @@ -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'; diff --git a/redirection-admin.php b/redirection-admin.php index 3639eab2..244c6102 100644 --- a/redirection-admin.php +++ b/redirection-admin.php @@ -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, '
' ); document.querySelector( '.react-error .button-primary' ).href += '&body=' + encodeURIComponent( errorText ) + encodeURIComponent( Redirectioni10n.versions ); }