2013-07-24 16:01:36 +00:00
< ? php
/**
2015-11-03 13:53:50 +00:00
* Display notices in admin
2013-07-24 16:01:36 +00:00
*
2018-04-17 20:44:11 +00:00
* @ package WooCommerce\Admin
* @ version 3.4 . 0
2013-07-24 16:01:36 +00:00
*/
2020-02-01 06:18:47 +00:00
use Automattic\Jetpack\Constants ;
2018-04-17 20:44:11 +00:00
defined ( 'ABSPATH' ) || exit ;
2013-07-24 16:01:36 +00:00
/**
2015-11-03 12:28:01 +00:00
* WC_Admin_Notices Class .
2013-07-24 16:01:36 +00:00
*/
class WC_Admin_Notices {
2016-06-06 17:20:10 +00:00
/**
* Stores notices .
2018-03-05 18:59:17 +00:00
*
2016-06-06 17:20:10 +00:00
* @ var array
*/
private static $notices = array ();
2013-07-24 16:01:36 +00:00
/**
2015-11-03 12:28:01 +00:00
* Array of notices - name => callback .
2018-03-05 18:59:17 +00:00
*
2015-01-20 15:23:34 +00:00
* @ var array
*/
2016-05-11 13:22:06 +00:00
private static $core_notices = array (
2020-05-05 17:03:12 +00:00
'update' => 'update_notice' ,
'template_files' => 'template_file_check_notice' ,
'legacy_shipping' => 'legacy_shipping_notice' ,
'no_shipping_methods' => 'no_shipping_methods_notice' ,
'regenerating_thumbnails' => 'regenerating_thumbnails_notice' ,
'regenerating_lookup_table' => 'regenerating_lookup_table_notice' ,
'no_secure_connection' => 'secure_connection_notice' ,
WC_PHP_MIN_REQUIREMENTS_NOTICE => 'wp_php_min_requirements_notice' ,
'maxmind_license_key' => 'maxmind_missing_license_key_notice' ,
'redirect_download_method' => 'redirect_download_method_notice' ,
'uploads_directory_is_unprotected' => 'uploads_directory_is_unprotected_notice' ,
2020-05-11 18:09:53 +00:00
'base_tables_missing' => 'base_tables_missing_notice' ,
2015-01-20 15:23:34 +00:00
);
/**
2015-11-03 12:28:01 +00:00
* Constructor .
2013-07-24 16:01:36 +00:00
*/
2016-05-11 13:22:06 +00:00
public static function init () {
self :: $notices = get_option ( 'woocommerce_admin_notices' , array () );
add_action ( 'switch_theme' , array ( __CLASS__ , 'reset_admin_notices' ) );
add_action ( 'woocommerce_installed' , array ( __CLASS__ , 'reset_admin_notices' ) );
2020-01-13 13:27:25 +00:00
add_action ( 'wp_loaded' , array ( __CLASS__ , 'add_redirect_download_method_notice' ) );
2016-05-11 13:22:06 +00:00
add_action ( 'wp_loaded' , array ( __CLASS__ , 'hide_notices' ) );
2020-02-07 11:58:31 +00:00
// @TODO: This prevents Action Scheduler async jobs from storing empty list of notices during WC installation.
// That could lead to OBW not starting and 'Run setup wizard' notice not appearing in WP admin, which we want
// to avoid.
2020-02-07 10:06:35 +00:00
if ( ! WC_Install :: is_new_install () || ! wc_is_running_from_async_action_scheduler () ) {
2020-02-06 23:21:03 +00:00
add_action ( 'shutdown' , array ( __CLASS__ , 'store_notices' ) );
}
2015-04-29 11:08:15 +00:00
if ( current_user_can ( 'manage_woocommerce' ) ) {
2016-05-11 13:22:06 +00:00
add_action ( 'admin_print_styles' , array ( __CLASS__ , 'add_notices' ) );
2015-04-29 11:08:15 +00:00
}
2015-04-29 09:47:57 +00:00
}
2021-01-20 15:06:23 +00:00
/**
* Parses query to create nonces when available .
*
* @ param object $response The WP_REST_Response we ' re working with .
* @ return object $response The prepared WP_REST_Response object .
*/
public static function prepare_note_with_nonce ( $response ) {
if ( 'wc-update-db-reminder' !== $response -> data [ 'name' ] || ! isset ( $response -> data [ 'actions' ] ) ) {
return $response ;
}
foreach ( $response -> data [ 'actions' ] as $action_key => $action ) {
$url_parts = ! empty ( $action -> query ) ? wp_parse_url ( $action -> query ) : '' ;
if ( ! isset ( $url_parts [ 'query' ] ) ) {
continue ;
}
wp_parse_str ( $url_parts [ 'query' ], $params );
if ( array_key_exists ( '_nonce_action' , $params ) && array_key_exists ( '_nonce_name' , $params ) ) {
2021-01-21 20:08:20 +00:00
$org_params = $params ;
2021-01-20 15:06:23 +00:00
2021-01-21 20:08:20 +00:00
// Check to make sure we're acting on the whitelisted nonce actions.
if ( 'wc_db_update' !== $params [ '_nonce_action' ] && 'woocommerce_hide_notices_nonce' !== $params [ '_nonce_action' ] ) {
continue ;
}
unset ( $org_params [ '_nonce_action' ] );
unset ( $org_params [ '_nonce_name' ] );
2021-01-20 15:06:23 +00:00
$url = $url_parts [ 'scheme' ] . '://' . $url_parts [ 'host' ] . $url_parts [ 'path' ];
2021-01-21 20:08:20 +00:00
$nonce = array ( $params [ '_nonce_name' ] => wp_create_nonce ( $params [ '_nonce_action' ] ) );
$merged_params = array_merge ( $nonce , $org_params );
$parsed_query = add_query_arg ( $merged_params , $url );
2021-01-20 15:06:23 +00:00
2021-01-21 20:17:22 +00:00
$response -> data [ 'actions' ][ $action_key ] -> query = $parsed_query ;
$response -> data [ 'actions' ][ $action_key ] -> url = $parsed_query ;
2021-01-20 15:06:23 +00:00
}
}
return $response ;
}
2016-05-11 13:22:06 +00:00
/**
* Store notices to DB
*/
public static function store_notices () {
update_option ( 'woocommerce_admin_notices' , self :: get_notices () );
}
/**
* Get notices
2018-03-05 18:59:17 +00:00
*
2016-05-11 13:22:06 +00:00
* @ return array
*/
public static function get_notices () {
return self :: $notices ;
}
2015-04-29 09:47:57 +00:00
/**
2015-11-03 12:28:01 +00:00
* Remove all notices .
2015-04-29 09:47:57 +00:00
*/
public static function remove_all_notices () {
2016-05-11 13:22:06 +00:00
self :: $notices = array ();
2013-07-24 16:01:36 +00:00
}
2014-02-11 13:33:56 +00:00
/**
2015-11-03 12:28:01 +00:00
* Reset notices for themes when switched or a new version of WC is installed .
2014-02-11 13:33:56 +00:00
*/
2016-05-11 13:22:06 +00:00
public static function reset_admin_notices () {
2018-10-29 14:10:09 +00:00
if ( ! self :: is_ssl () ) {
self :: add_notice ( 'no_secure_connection' );
2020-04-17 21:39:15 +00:00
}
2020-05-05 17:03:12 +00:00
if ( ! self :: is_uploads_directory_protected () ) {
self :: add_notice ( 'uploads_directory_is_unprotected' );
2018-04-17 21:26:08 +00:00
}
2015-02-02 14:40:08 +00:00
self :: add_notice ( 'template_files' );
2019-06-26 17:09:20 +00:00
self :: add_min_version_notice ();
2020-01-10 18:07:05 +00:00
self :: add_maxmind_missing_license_key_notice ();
2014-02-11 13:33:56 +00:00
}
2013-07-24 16:01:36 +00:00
/**
2015-11-03 12:28:01 +00:00
* Show a notice .
2018-03-05 18:59:17 +00:00
*
2018-04-17 20:44:11 +00:00
* @ param string $name Notice name .
2020-02-25 13:58:02 +00:00
* @ param bool $force_save Force saving inside this method instead of at the 'shutdown' .
2013-07-24 16:01:36 +00:00
*/
2020-02-25 13:58:02 +00:00
public static function add_notice ( $name , $force_save = false ) {
2016-05-11 13:22:06 +00:00
self :: $notices = array_unique ( array_merge ( self :: get_notices (), array ( $name ) ) );
2020-02-23 20:59:03 +00:00
2020-02-25 13:58:02 +00:00
if ( $force_save ) {
// Adding early save to prevent more race conditions with notices.
self :: store_notices ();
}
2015-01-20 15:23:34 +00:00
}
2013-07-24 16:01:36 +00:00
2015-01-20 15:23:34 +00:00
/**
2015-11-03 12:28:01 +00:00
* Remove a notice from being displayed .
2018-03-05 18:59:17 +00:00
*
2018-04-17 20:44:11 +00:00
* @ param string $name Notice name .
2020-02-25 13:58:02 +00:00
* @ param bool $force_save Force saving inside this method instead of at the 'shutdown' .
2015-01-20 15:23:34 +00:00
*/
2020-02-25 13:58:02 +00:00
public static function remove_notice ( $name , $force_save = false ) {
2016-05-11 13:22:06 +00:00
self :: $notices = array_diff ( self :: get_notices (), array ( $name ) );
2016-04-01 16:30:04 +00:00
delete_option ( 'woocommerce_admin_notice_' . $name );
2020-02-23 20:59:03 +00:00
2020-02-25 13:58:02 +00:00
if ( $force_save ) {
// Adding early save to prevent more race conditions with notices.
self :: store_notices ();
}
2015-01-20 15:23:34 +00:00
}
2013-07-24 16:01:36 +00:00
2015-01-20 15:23:34 +00:00
/**
2015-11-03 12:28:01 +00:00
* See if a notice is being shown .
2018-03-05 18:59:17 +00:00
*
2018-11-15 13:26:19 +00:00
* @ param string $name Notice name .
*
2015-01-20 15:23:34 +00:00
* @ return boolean
*/
public static function has_notice ( $name ) {
2018-04-17 20:44:11 +00:00
return in_array ( $name , self :: get_notices (), true );
2015-01-20 15:23:34 +00:00
}
2013-07-24 16:01:36 +00:00
2015-01-20 15:23:34 +00:00
/**
* Hide a notice if the GET variable is set .
*/
2016-05-11 13:22:06 +00:00
public static function hide_notices () {
2018-04-17 20:44:11 +00:00
if ( isset ( $_GET [ 'wc-hide-notice' ] ) && isset ( $_GET [ '_wc_notice_nonce' ] ) ) { // WPCS: input var ok, CSRF ok.
if ( ! wp_verify_nonce ( sanitize_key ( wp_unslash ( $_GET [ '_wc_notice_nonce' ] ) ), 'woocommerce_hide_notices_nonce' ) ) { // WPCS: input var ok, CSRF ok.
wp_die ( esc_html__ ( 'Action failed. Please refresh the page and retry.' , 'woocommerce' ) );
2015-05-20 18:14:53 +00:00
}
if ( ! current_user_can ( 'manage_woocommerce' ) ) {
2018-04-17 20:44:11 +00:00
wp_die ( esc_html__ ( 'You don’t have permission to do this.' , 'woocommerce' ) );
2015-05-20 18:14:53 +00:00
}
2018-04-17 20:44:11 +00:00
$hide_notice = sanitize_text_field ( wp_unslash ( $_GET [ 'wc-hide-notice' ] ) ); // WPCS: input var ok, CSRF ok.
2018-01-24 17:18:28 +00:00
2015-01-20 15:23:34 +00:00
self :: remove_notice ( $hide_notice );
2018-01-24 17:18:28 +00:00
update_user_meta ( get_current_user_id (), 'dismissed_' . $hide_notice . '_notice' , true );
2015-01-20 15:23:34 +00:00
do_action ( 'woocommerce_hide_' . $hide_notice . '_notice' );
2014-02-11 13:33:56 +00:00
}
2015-01-20 15:23:34 +00:00
}
2013-07-24 16:01:36 +00:00
2015-01-20 15:23:34 +00:00
/**
* Add notices + styles if needed .
*/
2016-05-11 13:22:06 +00:00
public static function add_notices () {
$notices = self :: get_notices ();
2014-06-04 16:01:38 +00:00
2018-04-18 13:08:31 +00:00
if ( empty ( $notices ) ) {
return ;
}
2017-07-06 06:03:15 +00:00
2018-04-18 13:08:31 +00:00
$screen = get_current_screen ();
$screen_id = $screen ? $screen -> id : '' ;
$show_on_screens = array (
'dashboard' ,
'plugins' ,
);
2017-07-06 06:03:15 +00:00
2018-04-18 13:08:31 +00:00
// Notices should only show on WooCommerce screens, the main dashboard, and on the plugins screen.
if ( ! in_array ( $screen_id , wc_get_screen_ids (), true ) && ! in_array ( $screen_id , $show_on_screens , true ) ) {
return ;
}
2020-02-01 06:18:47 +00:00
wp_enqueue_style ( 'woocommerce-activation' , plugins_url ( '/assets/css/activation.css' , WC_PLUGIN_FILE ), array (), Constants :: get_constant ( 'WC_VERSION' ) );
2018-04-18 13:08:31 +00:00
// Add RTL support.
wp_style_add_data ( 'woocommerce-activation' , 'rtl' , 'replace' );
foreach ( $notices as $notice ) {
if ( ! empty ( self :: $core_notices [ $notice ] ) && apply_filters ( 'woocommerce_show_admin_notice' , true , $notice ) ) {
add_action ( 'admin_notices' , array ( __CLASS__ , self :: $core_notices [ $notice ] ) );
} else {
add_action ( 'admin_notices' , array ( __CLASS__ , 'output_custom_notices' ) );
2016-04-01 16:30:04 +00:00
}
}
}
/**
* Add a custom notice .
2018-03-05 18:59:17 +00:00
*
2018-04-17 20:44:11 +00:00
* @ param string $name Notice name .
* @ param string $notice_html Notice HTML .
2016-04-01 16:30:04 +00:00
*/
public static function add_custom_notice ( $name , $notice_html ) {
self :: add_notice ( $name );
update_option ( 'woocommerce_admin_notice_' . $name , wp_kses_post ( $notice_html ) );
}
/**
* Output any stored custom notices .
*/
2016-05-11 13:22:06 +00:00
public static function output_custom_notices () {
$notices = self :: get_notices ();
2016-06-06 16:24:31 +00:00
if ( ! empty ( $notices ) ) {
2016-04-01 16:30:04 +00:00
foreach ( $notices as $notice ) {
2016-05-11 13:22:06 +00:00
if ( empty ( self :: $core_notices [ $notice ] ) ) {
2016-04-01 16:30:04 +00:00
$notice_html = get_option ( 'woocommerce_admin_notice_' . $notice );
if ( $notice_html ) {
2018-04-17 20:44:11 +00:00
include dirname ( __FILE__ ) . '/views/html-notice-custom.php' ;
2016-04-01 16:30:04 +00:00
}
2015-04-29 11:21:48 +00:00
}
2015-04-29 09:47:57 +00:00
}
2014-06-04 16:01:38 +00:00
}
2015-01-20 15:23:34 +00:00
}
2015-01-14 12:17:03 +00:00
2015-01-20 15:23:34 +00:00
/**
2020-02-23 20:59:03 +00:00
* If we need to update the database , include a message with the DB update button .
2015-01-20 15:23:34 +00:00
*/
2016-05-11 13:22:06 +00:00
public static function update_notice () {
2020-03-05 11:37:10 +00:00
$screen = get_current_screen ();
$screen_id = $screen ? $screen -> id : '' ;
if ( WC () -> is_wc_admin_active () && in_array ( $screen_id , wc_get_screen_ids (), true ) ) {
2020-03-05 11:21:04 +00:00
return ;
}
2019-02-28 11:52:56 +00:00
if ( WC_Install :: needs_db_update () ) {
2019-02-28 11:11:08 +00:00
$next_scheduled_date = WC () -> queue () -> get_next ( 'woocommerce_run_update_callback' , null , 'woocommerce-db-updates' );
if ( $next_scheduled_date || ! empty ( $_GET [ 'do_update_woocommerce' ] ) ) { // WPCS: input var ok, CSRF ok.
2018-04-17 20:44:11 +00:00
include dirname ( __FILE__ ) . '/views/html-notice-updating.php' ;
2016-06-13 17:15:07 +00:00
} else {
2018-04-17 20:44:11 +00:00
include dirname ( __FILE__ ) . '/views/html-notice-update.php' ;
2016-06-13 11:44:16 +00:00
}
2016-05-11 13:22:06 +00:00
} else {
2018-04-17 20:44:11 +00:00
include dirname ( __FILE__ ) . '/views/html-notice-updated.php' ;
2016-05-11 13:22:06 +00:00
}
2016-05-11 11:43:35 +00:00
}
2013-07-24 16:01:36 +00:00
/**
2015-11-03 12:28:01 +00:00
* If we have just installed , show a message with the install pages button .
2020-06-23 18:29:58 +00:00
*
2020-09-18 16:16:46 +00:00
* @ deprecated 4.6 . 0
2013-07-24 16:01:36 +00:00
*/
2016-05-11 13:22:06 +00:00
public static function install_notice () {
2020-09-18 16:16:46 +00:00
_deprecated_function ( __CLASS__ . '::' . __FUNCTION__ , '4.6.0' , __ ( 'Onboarding is maintained in WooCommerce Admin.' , 'woocommerce' ) );
2013-07-24 16:01:36 +00:00
}
2014-02-11 13:33:56 +00:00
/**
2015-11-03 12:28:01 +00:00
* Show a notice highlighting bad template files .
2014-02-11 13:33:56 +00:00
*/
2016-05-11 13:22:06 +00:00
public static function template_file_check_notice () {
2014-06-04 10:16:19 +00:00
$core_templates = WC_Admin_Status :: scan_template_files ( WC () -> plugin_path () . '/templates' );
2014-02-11 13:33:56 +00:00
$outdated = false ;
foreach ( $core_templates as $file ) {
2015-04-01 13:33:56 +00:00
2014-02-11 13:33:56 +00:00
$theme_file = false ;
if ( file_exists ( get_stylesheet_directory () . '/' . $file ) ) {
$theme_file = get_stylesheet_directory () . '/' . $file ;
2017-10-16 11:03:12 +00:00
} elseif ( file_exists ( get_stylesheet_directory () . '/' . WC () -> template_path () . $file ) ) {
$theme_file = get_stylesheet_directory () . '/' . WC () -> template_path () . $file ;
2014-02-11 13:33:56 +00:00
} elseif ( file_exists ( get_template_directory () . '/' . $file ) ) {
$theme_file = get_template_directory () . '/' . $file ;
2017-10-16 11:03:12 +00:00
} elseif ( file_exists ( get_template_directory () . '/' . WC () -> template_path () . $file ) ) {
$theme_file = get_template_directory () . '/' . WC () -> template_path () . $file ;
2014-02-11 13:33:56 +00:00
}
2016-09-07 22:32:24 +00:00
if ( false !== $theme_file ) {
2014-06-13 15:17:23 +00:00
$core_version = WC_Admin_Status :: get_file_version ( WC () -> plugin_path () . '/templates/' . $file );
$theme_version = WC_Admin_Status :: get_file_version ( $theme_file );
2014-02-11 13:33:56 +00:00
if ( $core_version && $theme_version && version_compare ( $theme_version , $core_version , '<' ) ) {
$outdated = true ;
break ;
}
}
}
2014-02-11 15:13:47 +00:00
if ( $outdated ) {
2018-04-17 20:44:11 +00:00
include dirname ( __FILE__ ) . '/views/html-notice-template-check.php' ;
2015-01-20 15:23:34 +00:00
} else {
self :: remove_notice ( 'template_files' );
2014-02-11 15:13:47 +00:00
}
2014-02-11 13:33:56 +00:00
}
2016-03-15 15:58:00 +00:00
/**
* Show a notice asking users to convert to shipping zones .
2019-04-10 10:23:04 +00:00
*
* @ todo remove in 4.0 . 0
2016-03-15 15:58:00 +00:00
*/
2016-05-11 13:22:06 +00:00
public static function legacy_shipping_notice () {
2016-03-15 15:58:00 +00:00
$maybe_load_legacy_methods = array ( 'flat_rate' , 'free_shipping' , 'international_delivery' , 'local_delivery' , 'local_pickup' );
$enabled = false ;
foreach ( $maybe_load_legacy_methods as $method ) {
$options = get_option ( 'woocommerce_' . $method . '_settings' );
if ( $options && isset ( $options [ 'enabled' ] ) && 'yes' === $options [ 'enabled' ] ) {
$enabled = true ;
}
}
if ( $enabled ) {
2018-04-17 20:44:11 +00:00
include dirname ( __FILE__ ) . '/views/html-notice-legacy-shipping.php' ;
2016-03-15 15:58:00 +00:00
} else {
self :: remove_notice ( 'template_files' );
}
}
2016-03-31 17:54:33 +00:00
/**
* No shipping methods .
*/
2016-05-11 13:22:06 +00:00
public static function no_shipping_methods_notice () {
2018-04-17 20:44:11 +00:00
if ( wc_shipping_enabled () && ( empty ( $_GET [ 'page' ] ) || empty ( $_GET [ 'tab' ] ) || 'wc-settings' !== $_GET [ 'page' ] || 'shipping' !== $_GET [ 'tab' ] ) ) { // WPCS: input var ok, CSRF ok.
2016-03-31 17:54:33 +00:00
$product_count = wp_count_posts ( 'product' );
2016-05-25 11:05:23 +00:00
$method_count = wc_get_shipping_method_count ();
2016-03-31 17:54:33 +00:00
if ( $product_count -> publish > 0 && 0 === $method_count ) {
2018-04-17 20:44:11 +00:00
include dirname ( __FILE__ ) . '/views/html-notice-no-shipping-methods.php' ;
2016-03-31 17:54:33 +00:00
}
if ( $method_count > 0 ) {
self :: remove_notice ( 'no_shipping_methods' );
}
}
}
2016-04-19 12:14:13 +00:00
2018-02-13 12:02:24 +00:00
/**
* Notice shown when regenerating thumbnails background process is running .
*/
public static function regenerating_thumbnails_notice () {
2018-04-17 20:44:11 +00:00
include dirname ( __FILE__ ) . '/views/html-notice-regenerating-thumbnails.php' ;
2018-02-13 12:02:24 +00:00
}
2018-04-17 20:39:18 +00:00
/**
* Notice about secure connection .
*/
public static function secure_connection_notice () {
2018-10-29 14:10:09 +00:00
if ( self :: is_ssl () || get_user_meta ( get_current_user_id (), 'dismissed_no_secure_connection_notice' , true ) ) {
2018-04-17 21:26:08 +00:00
return ;
}
2018-04-17 20:39:18 +00:00
include dirname ( __FILE__ ) . '/views/html-notice-secure-connection.php' ;
}
2018-06-13 18:36:36 +00:00
2019-03-13 12:25:20 +00:00
/**
* Notice shown when regenerating thumbnails background process is running .
*
* @ since 3.6 . 0
*/
public static function regenerating_lookup_table_notice () {
// See if this is still relevent.
if ( ! wc_update_product_lookup_tables_is_running () ) {
self :: remove_notice ( 'regenerating_lookup_table' );
return ;
}
include dirname ( __FILE__ ) . '/views/html-notice-regenerating-lookup-table.php' ;
}
2019-06-26 17:09:20 +00:00
/**
* Add notice about minimum PHP and WordPress requirement .
*
* @ since 3.6 . 5
*/
public static function add_min_version_notice () {
2019-07-02 16:44:43 +00:00
if ( version_compare ( phpversion (), WC_NOTICE_MIN_PHP_VERSION , '<' ) || version_compare ( get_bloginfo ( 'version' ), WC_NOTICE_MIN_WP_VERSION , '<' ) ) {
2019-10-15 09:45:34 +00:00
self :: add_notice ( WC_PHP_MIN_REQUIREMENTS_NOTICE );
2019-06-26 17:09:20 +00:00
}
}
/**
* Notice about WordPress and PHP minimum requirements .
*
* @ since 3.6 . 5
* @ return void
*/
public static function wp_php_min_requirements_notice () {
2019-10-15 09:45:34 +00:00
if ( apply_filters ( 'woocommerce_hide_php_wp_nag' , get_user_meta ( get_current_user_id (), 'dismissed_' . WC_PHP_MIN_REQUIREMENTS_NOTICE . '_notice' , true ) ) ) {
self :: remove_notice ( WC_PHP_MIN_REQUIREMENTS_NOTICE );
2019-06-26 17:09:20 +00:00
return ;
}
2019-07-02 16:44:43 +00:00
$old_php = version_compare ( phpversion (), WC_NOTICE_MIN_PHP_VERSION , '<' );
$old_wp = version_compare ( get_bloginfo ( 'version' ), WC_NOTICE_MIN_WP_VERSION , '<' );
2019-06-26 17:09:20 +00:00
// Both PHP and WordPress up to date version => no notice.
if ( ! $old_php && ! $old_wp ) {
return ;
}
if ( $old_php && $old_wp ) {
$msg = sprintf (
/* translators: 1: Minimum PHP version 2: Minimum WordPress version */
__ ( 'Update required: WooCommerce will soon require PHP version %1$s and WordPress version %2$s or newer.' , 'woocommerce' ),
2019-07-02 16:44:43 +00:00
WC_NOTICE_MIN_PHP_VERSION ,
WC_NOTICE_MIN_WP_VERSION
2019-06-26 17:09:20 +00:00
);
} elseif ( $old_php ) {
$msg = sprintf (
/* translators: %s: Minimum PHP version */
__ ( 'Update required: WooCommerce will soon require PHP version %s or newer.' , 'woocommerce' ),
2019-07-02 16:44:43 +00:00
WC_NOTICE_MIN_PHP_VERSION
2019-06-26 17:09:20 +00:00
);
} elseif ( $old_wp ) {
$msg = sprintf (
/* translators: %s: Minimum WordPress version */
__ ( 'Update required: WooCommerce will soon require WordPress version %s or newer.' , 'woocommerce' ),
2019-07-02 16:44:43 +00:00
WC_NOTICE_MIN_WP_VERSION
2019-06-26 17:09:20 +00:00
);
}
include dirname ( __FILE__ ) . '/views/html-notice-wp-php-minimum-requirements.php' ;
}
2020-01-10 18:07:05 +00:00
/**
2020-01-14 19:45:57 +00:00
* Add MaxMind missing license key notice .
2020-01-10 18:07:05 +00:00
*
* @ since 3.9 . 0
*/
public static function add_maxmind_missing_license_key_notice () {
$default_address = get_option ( 'woocommerce_default_customer_address' );
if ( ! in_array ( $default_address , array ( 'geolocation' , 'geolocation_ajax' ), true ) ) {
return ;
}
$integration_options = get_option ( 'woocommerce_maxmind_geolocation_settings' );
if ( empty ( $integration_options [ 'license_key' ] ) ) {
self :: add_notice ( 'maxmind_license_key' );
2020-01-13 13:27:25 +00:00
}
}
/**
* Add notice about Redirect - only download method , nudging user to switch to a different method instead .
*/
public static function add_redirect_download_method_notice () {
if ( 'redirect' === get_option ( 'woocommerce_file_download_method' ) ) {
2020-02-05 09:35:26 +00:00
self :: add_notice ( 'redirect_download_method' );
2020-01-13 13:27:25 +00:00
} else {
2020-02-05 09:35:26 +00:00
self :: remove_notice ( 'redirect_download_method' );
2020-01-10 18:07:05 +00:00
}
}
/**
2020-01-14 19:45:57 +00:00
* Display MaxMind missing license key notice .
2020-01-10 18:07:05 +00:00
*
* @ since 3.9 . 0
*/
public static function maxmind_missing_license_key_notice () {
2020-01-15 02:32:55 +00:00
$user_dismissed_notice = get_user_meta ( get_current_user_id (), 'dismissed_maxmind_license_key_notice' , true );
$filter_dismissed_notice = ! apply_filters ( 'woocommerce_maxmind_geolocation_display_notices' , true );
2020-01-14 18:22:53 +00:00
2020-01-15 02:32:55 +00:00
if ( $user_dismissed_notice || $filter_dismissed_notice ) {
2020-01-10 18:07:05 +00:00
self :: remove_notice ( 'maxmind_license_key' );
return ;
}
include dirname ( __FILE__ ) . '/views/html-notice-maxmind-license-key.php' ;
}
2020-01-13 13:27:25 +00:00
/**
* Notice about Redirect - Only download method .
*
2020-02-05 10:09:46 +00:00
* @ since 4.0
2020-01-13 13:27:25 +00:00
*/
2020-02-05 09:35:26 +00:00
public static function redirect_download_method_notice () {
if ( apply_filters ( 'woocommerce_hide_redirect_method_nag' , get_user_meta ( get_current_user_id (), 'dismissed_redirect_download_method_notice' , true ) ) ) {
self :: remove_notice ( 'redirect_download_method' );
2020-01-13 13:27:25 +00:00
return ;
}
include dirname ( __FILE__ ) . '/views/html-notice-redirect-only-download.php' ;
}
2020-04-17 21:21:29 +00:00
/**
2020-05-05 17:03:12 +00:00
* Notice about uploads directory begin unprotected .
2020-04-17 21:21:29 +00:00
*
* @ since 4.2 . 0
*/
2020-05-05 17:03:12 +00:00
public static function uploads_directory_is_unprotected_notice () {
if ( get_user_meta ( get_current_user_id (), 'dismissed_uploads_directory_is_unprotected_notice' , true ) || self :: is_uploads_directory_protected () ) {
self :: remove_notice ( 'uploads_directory_is_unprotected' );
2020-04-17 21:21:29 +00:00
return ;
}
2020-05-05 17:03:12 +00:00
include dirname ( __FILE__ ) . '/views/html-notice-uploads-directory-is-unprotected.php' ;
2020-04-17 21:21:29 +00:00
}
2020-05-11 18:09:53 +00:00
/**
* Notice about base tables missing .
*/
public static function base_tables_missing_notice () {
$notice_dismissed = apply_filters (
'woocommerce_hide_base_tables_missing_nag' ,
get_user_meta ( get_current_user_id (), 'dismissed_base_tables_missing_notice' , true )
);
if ( $notice_dismissed ) {
self :: remove_notice ( 'base_tables_missing' );
}
include dirname ( __FILE__ ) . '/views/html-notice-base-table-missing.php' ;
}
2018-10-29 14:10:09 +00:00
/**
* Determine if the store is running SSL .
*
* @ return bool Flag SSL enabled .
2018-11-15 13:26:19 +00:00
* @ since 3.5 . 1
2018-10-29 14:10:09 +00:00
*/
protected static function is_ssl () {
2019-01-23 12:49:21 +00:00
$shop_page = wc_get_page_permalink ( 'shop' );
2018-10-29 14:10:09 +00:00
return ( is_ssl () && 'https' === substr ( $shop_page , 0 , 5 ) );
}
2019-02-27 15:25:27 +00:00
/**
* Wrapper for is_plugin_active .
*
* @ param string $plugin Plugin to check .
* @ return boolean
*/
protected static function is_plugin_active ( $plugin ) {
if ( ! function_exists ( 'is_plugin_active' ) ) {
include_once ABSPATH . 'wp-admin/includes/plugin.php' ;
}
return is_plugin_active ( $plugin );
}
2019-03-13 10:37:30 +00:00
/**
* Simplify Commerce is no longer in core .
*
* @ deprecated 3.6 . 0 No longer shown .
*/
public static function simplify_commerce_notice () {
wc_deprecated_function ( 'WC_Admin_Notices::simplify_commerce_notice' , '3.6.0' );
}
/**
* Show the Theme Check notice .
*
* @ deprecated 3.3 . 0 No longer shown .
*/
public static function theme_check_notice () {
wc_deprecated_function ( 'WC_Admin_Notices::theme_check_notice' , '3.3.0' );
}
2020-04-17 21:21:29 +00:00
/**
2020-05-05 17:03:12 +00:00
* Check if uploads directory is protected .
2020-04-17 21:21:29 +00:00
*
* @ since 4.2 . 0
* @ return bool
*/
2020-05-05 17:03:12 +00:00
protected static function is_uploads_directory_protected () {
$cache_key = '_woocommerce_upload_directory_status' ;
$status = get_transient ( $cache_key );
// Check for cache.
if ( false !== $status ) {
return 'protected' === $status ;
}
2020-05-07 00:41:04 +00:00
// Get only data from the uploads directory.
$uploads = wp_get_upload_dir ();
// Check for the "uploads/woocommerce_uploads" directory.
2020-05-25 13:31:58 +00:00
$response = wp_safe_remote_get (
2020-05-26 20:23:37 +00:00
esc_url_raw ( $uploads [ 'baseurl' ] . '/woocommerce_uploads/' ),
2020-05-25 13:31:58 +00:00
array (
'redirection' => 0 ,
)
);
2020-05-07 00:41:04 +00:00
$response_code = intval ( wp_remote_retrieve_response_code ( $response ) );
$response_content = wp_remote_retrieve_body ( $response );
// Check if returns 200 with empty content in case can open an index.html file,
// and check for non-200 codes in case the directory is protected.
$is_protected = ( 200 === $response_code && empty ( $response_content ) ) || ( 200 !== $response_code );
set_transient ( $cache_key , $is_protected ? 'protected' : 'unprotected' , 1 * DAY_IN_SECONDS );
2020-04-17 21:21:29 +00:00
2020-05-05 17:03:12 +00:00
return $is_protected ;
2020-04-17 21:21:29 +00:00
}
2013-07-24 16:01:36 +00:00
}
2016-05-11 13:22:06 +00:00
WC_Admin_Notices :: init ();