Skip to content
This repository has been archived by the owner on Mar 17, 2022. It is now read-only.

Commit

Permalink
fixes #435 get_current_screen() not available in some admin screens
Browse files Browse the repository at this point in the history
1. added defensive check to each occurrence of get_current_screen
2. removed get_current_screen test from common email string translation
to allow common strings to be translated when email sent from other
screens
  • Loading branch information
Jon007 committed Jun 29, 2019
1 parent feedc68 commit 7d42820
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
17 changes: 9 additions & 8 deletions src/Hyyan/WPI/Emails.php
Expand Up @@ -267,14 +267,15 @@ public function translateCommonString( $email_string ) {
return $email_string;
}
if ( is_admin() ) {
$screen = get_current_screen();
if ( $screen && $screen->id == 'shop_order' ) {
global $post;
if ( $post ) {
$order_locale = pll_get_post_language( $post->ID );
return pll_translate_string( $email_string, $order_locale );
}
}
//#435 allow the possibility of other screens sending email, including where current_screen is not defined
//$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : false;
//if ( $screen && $screen->id == 'shop_order' ) {
global $post;
if ( $post ) {
$locale = pll_get_post_language( $post->ID );
return pll_translate_string( $email_string, $locale );
}
//}
}
$trans = pll__( $email_string );
if ( $trans ) {
Expand Down
4 changes: 2 additions & 2 deletions src/Hyyan/WPI/Endpoints.php
Expand Up @@ -250,11 +250,11 @@ public function fixMyAccountLinkInMenus(array $items = array())
*/
public function showFlashMessages()
{
$screen = get_current_screen();
$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : false;
/*
* this only gets shown once before being dismissed so show only in the relevant place
*/
if ( $screen->id == 'woocommerce_page_wc-settings' && isset( $_GET[ 'tab' ] ) && $_GET[ 'tab' ] == 'advanced' ) {
if ( $screen && $screen->id == 'woocommerce_page_wc-settings' && isset( $_GET[ 'tab' ] ) && $_GET[ 'tab' ] == 'advanced' ) {
FlashMessages::add(
MessagesInterface::MSG_ENDPOINTS_TRANSLATION, Plugin::getView( 'Messages/endpointsTranslations' )
);
Expand Down
4 changes: 2 additions & 2 deletions src/Hyyan/WPI/Order.php
Expand Up @@ -142,9 +142,9 @@ public function correctGetOrderQuery($query, $args)
public function limitPolylangFeaturesForOrders()
{
add_action('current_screen', function () {
$screen = get_current_screen();
$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : false;

if ($screen->post_type === 'shop_order') {
if ( $screen && $screen->post_type === 'shop_order' ) {
add_action('admin_print_scripts', function () {
$jsID = 'order-translations-buttons';
$code = '$(".pll_icon_add,#post-translations").fadeOut()';
Expand Down
4 changes: 2 additions & 2 deletions src/Hyyan/WPI/Product/Meta.php
Expand Up @@ -133,8 +133,8 @@ public function saveQuickEdit(\WC_Product $product)
public function syncProductsMeta()
{
//change proposed Teemu Suoranta 3/Nov
$currentScreen = get_current_screen();
if ($currentScreen->post_type !== 'product') {
$currentScreen = function_exists( 'get_current_screen' ) ? get_current_screen() : false;
if ( $currentScreen && $currentScreen->post_type !== 'product' ) {
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Hyyan/WPI/Product/Variable.php
Expand Up @@ -384,8 +384,8 @@ public function handleVariableLimitation()
public function shouldDisableLangSwitcher()
{
add_action('current_screen', function () {
$screen = get_current_screen();
if ($screen->id !== 'settings_page_mlang') {
$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : false;
if ($screen && $screen->id !== 'settings_page_mlang') {
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Hyyan/WPI/Shipping.php
Expand Up @@ -48,8 +48,8 @@ public function __construct()
*/
public function disableSettings()
{
$currentScreen = get_current_screen();
if ($currentScreen->id !== 'settings_page_hyyan-wpi') {
$currentScreen = function_exists( 'get_current_screen' ) ? get_current_screen() : false;
if ($currentScreen && $currentScreen->id !== 'settings_page_hyyan-wpi') {
return false;
}

Expand Down
1 change: 0 additions & 1 deletion src/Hyyan/WPI/Tools/FlashMessages.php
Expand Up @@ -137,6 +137,5 @@ private static function getMessages()
$messages = array();
}
return $messages;
return get_option(static::getOptionName(), array());
}
}

0 comments on commit 7d42820

Please sign in to comment.