Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/Internal/Admin
File: Events.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Handle cron events.
[2] Fix | Delete
*/
[3] Fix | Delete
[4] Fix | Delete
namespace Automattic\WooCommerce\Internal\Admin;
[5] Fix | Delete
[6] Fix | Delete
defined( 'ABSPATH' ) || exit;
[7] Fix | Delete
[8] Fix | Delete
use Automattic\WooCommerce\Admin\Features\Features;
[9] Fix | Delete
use Automattic\WooCommerce\Admin\RemoteInboxNotifications\RemoteInboxNotificationsDataSourcePoller;
[10] Fix | Delete
use Automattic\WooCommerce\Admin\RemoteInboxNotifications\RemoteInboxNotificationsEngine;
[11] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Notes\CustomizeStoreWithBlocks;
[12] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Notes\CustomizingProductCatalog;
[13] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Notes\EditProductsOnTheMove;
[14] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Notes\EmailImprovements;
[15] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Notes\EUVATNumber;
[16] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Notes\FirstProduct;
[17] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Notes\InstallJPAndWCSPlugins;
[18] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Notes\LaunchChecklist;
[19] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Notes\MagentoMigration;
[20] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Notes\ManageOrdersOnTheGo;
[21] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Notes\MarketingJetpack;
[22] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Notes\MigrateFromShopify;
[23] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Notes\MobileApp;
[24] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Notes\NewSalesRecord;
[25] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Notes\OnboardingPayments;
[26] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Notes\OnlineClothingStore;
[27] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Notes\OrderMilestones;
[28] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Notes\PaymentsMoreInfoNeeded;
[29] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Notes\PaymentsRemindMeLater;
[30] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Notes\PerformanceOnMobile;
[31] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Notes\PersonalizeStore;
[32] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Notes\RealTimeOrderAlerts;
[33] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Notes\ScheduledUpdatesPromotion;
[34] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Notes\SellingOnlineCourses;
[35] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Notes\TrackingOptIn;
[36] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Notes\UnsecuredReportFiles;
[37] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Notes\WooCommercePayments;
[38] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Notes\WooCommerceSubscriptions;
[39] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Notes\WooSubscriptionsNotes;
[40] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Schedulers\MailchimpScheduler;
[41] Fix | Delete
use Automattic\WooCommerce\Admin\Notes\Note;
[42] Fix | Delete
use Automattic\WooCommerce\Admin\Features\PaymentGatewaySuggestions\PaymentGatewaySuggestionsDataSourcePoller;
[43] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\RemoteFreeExtensions\RemoteFreeExtensionsDataSourcePoller;
[44] Fix | Delete
[45] Fix | Delete
/**
[46] Fix | Delete
* Events Class.
[47] Fix | Delete
*/
[48] Fix | Delete
class Events {
[49] Fix | Delete
/**
[50] Fix | Delete
* The single instance of the class.
[51] Fix | Delete
*
[52] Fix | Delete
* @var object
[53] Fix | Delete
*/
[54] Fix | Delete
protected static $instance = null;
[55] Fix | Delete
[56] Fix | Delete
/**
[57] Fix | Delete
* Constructor
[58] Fix | Delete
*
[59] Fix | Delete
* @return void
[60] Fix | Delete
*/
[61] Fix | Delete
protected function __construct() {}
[62] Fix | Delete
[63] Fix | Delete
/**
[64] Fix | Delete
* Array of note class to be added or updated.
[65] Fix | Delete
*
[66] Fix | Delete
* @var array
[67] Fix | Delete
*/
[68] Fix | Delete
private static $note_classes_to_added_or_updated = array(
[69] Fix | Delete
CustomizeStoreWithBlocks::class,
[70] Fix | Delete
CustomizingProductCatalog::class,
[71] Fix | Delete
EditProductsOnTheMove::class,
[72] Fix | Delete
EmailImprovements::class,
[73] Fix | Delete
EUVATNumber::class,
[74] Fix | Delete
FirstProduct::class,
[75] Fix | Delete
LaunchChecklist::class,
[76] Fix | Delete
MagentoMigration::class,
[77] Fix | Delete
ManageOrdersOnTheGo::class,
[78] Fix | Delete
MarketingJetpack::class,
[79] Fix | Delete
MigrateFromShopify::class,
[80] Fix | Delete
MobileApp::class,
[81] Fix | Delete
NewSalesRecord::class,
[82] Fix | Delete
OnboardingPayments::class,
[83] Fix | Delete
OnlineClothingStore::class,
[84] Fix | Delete
PaymentsMoreInfoNeeded::class,
[85] Fix | Delete
PaymentsRemindMeLater::class,
[86] Fix | Delete
PerformanceOnMobile::class,
[87] Fix | Delete
PersonalizeStore::class,
[88] Fix | Delete
RealTimeOrderAlerts::class,
[89] Fix | Delete
ScheduledUpdatesPromotion::class,
[90] Fix | Delete
TrackingOptIn::class,
[91] Fix | Delete
WooCommercePayments::class,
[92] Fix | Delete
WooCommerceSubscriptions::class,
[93] Fix | Delete
);
[94] Fix | Delete
[95] Fix | Delete
/**
[96] Fix | Delete
* The other note classes that are added in other places.
[97] Fix | Delete
*
[98] Fix | Delete
* @var array
[99] Fix | Delete
*/
[100] Fix | Delete
private static $other_note_classes = array(
[101] Fix | Delete
InstallJPAndWCSPlugins::class,
[102] Fix | Delete
OrderMilestones::class,
[103] Fix | Delete
SellingOnlineCourses::class,
[104] Fix | Delete
UnsecuredReportFiles::class,
[105] Fix | Delete
WooSubscriptionsNotes::class,
[106] Fix | Delete
);
[107] Fix | Delete
[108] Fix | Delete
[109] Fix | Delete
/**
[110] Fix | Delete
* Get class instance.
[111] Fix | Delete
*
[112] Fix | Delete
* @return object Instance.
[113] Fix | Delete
*/
[114] Fix | Delete
final public static function instance() {
[115] Fix | Delete
if ( null === static::$instance ) {
[116] Fix | Delete
static::$instance = new static();
[117] Fix | Delete
}
[118] Fix | Delete
return static::$instance;
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
/**
[122] Fix | Delete
* Cron event handlers.
[123] Fix | Delete
*/
[124] Fix | Delete
public function init() {
[125] Fix | Delete
add_action( 'wc_admin_daily', array( $this, 'do_wc_admin_daily' ) );
[126] Fix | Delete
add_filter( 'woocommerce_get_note_from_db', array( $this, 'get_note_from_db' ), 10, 1 );
[127] Fix | Delete
[128] Fix | Delete
// Initialize the WC_Notes_Refund_Returns Note to attach hook.
[129] Fix | Delete
\WC_Notes_Refund_Returns::init();
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
/**
[133] Fix | Delete
* Daily events to run.
[134] Fix | Delete
*
[135] Fix | Delete
* Note: Order_Milestones::possibly_add_note is hooked to this as well.
[136] Fix | Delete
*/
[137] Fix | Delete
public function do_wc_admin_daily() {
[138] Fix | Delete
$this->possibly_add_notes();
[139] Fix | Delete
$this->possibly_delete_notes();
[140] Fix | Delete
$this->possibly_update_notes();
[141] Fix | Delete
$this->possibly_refresh_data_source_pollers();
[142] Fix | Delete
[143] Fix | Delete
if ( $this->is_remote_inbox_notifications_enabled() ) {
[144] Fix | Delete
RemoteInboxNotificationsDataSourcePoller::get_instance()->read_specs_from_data_sources();
[145] Fix | Delete
RemoteInboxNotificationsEngine::run();
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
if ( Features::is_enabled( 'core-profiler' ) ) {
[149] Fix | Delete
( new MailchimpScheduler() )->run();
[150] Fix | Delete
}
[151] Fix | Delete
}
[152] Fix | Delete
[153] Fix | Delete
/**
[154] Fix | Delete
* Get note.
[155] Fix | Delete
*
[156] Fix | Delete
* @param Note $note_from_db The note object from the database.
[157] Fix | Delete
*/
[158] Fix | Delete
public function get_note_from_db( $note_from_db ) {
[159] Fix | Delete
if ( ! $note_from_db instanceof Note || get_user_locale() === $note_from_db->get_locale() ) {
[160] Fix | Delete
return $note_from_db;
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
$note_classes = array_merge( self::$note_classes_to_added_or_updated, self::$other_note_classes );
[164] Fix | Delete
foreach ( $note_classes as $note_class ) {
[165] Fix | Delete
if ( defined( "$note_class::NOTE_NAME" ) && $note_class::NOTE_NAME === $note_from_db->get_name() ) {
[166] Fix | Delete
$note_from_class = method_exists( $note_class, 'get_note' ) ? $note_class::get_note() : null;
[167] Fix | Delete
[168] Fix | Delete
if ( $note_from_class instanceof Note ) {
[169] Fix | Delete
$note = clone $note_from_db;
[170] Fix | Delete
$note->set_title( $note_from_class->get_title() );
[171] Fix | Delete
$note->set_content( $note_from_class->get_content() );
[172] Fix | Delete
$actions = $note_from_class->get_actions();
[173] Fix | Delete
foreach ( $actions as $action ) {
[174] Fix | Delete
$matching_action = $note->get_action( $action->name );
[175] Fix | Delete
if ( $matching_action && $matching_action->id ) {
[176] Fix | Delete
$action->id = $matching_action->id;
[177] Fix | Delete
}
[178] Fix | Delete
}
[179] Fix | Delete
$note->set_actions( $actions );
[180] Fix | Delete
return $note;
[181] Fix | Delete
}
[182] Fix | Delete
break;
[183] Fix | Delete
}
[184] Fix | Delete
}
[185] Fix | Delete
return $note_from_db;
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
/**
[189] Fix | Delete
* Adds notes that should be added.
[190] Fix | Delete
*/
[191] Fix | Delete
protected function possibly_add_notes() {
[192] Fix | Delete
foreach ( self::$note_classes_to_added_or_updated as $note_class ) {
[193] Fix | Delete
if ( method_exists( $note_class, 'possibly_add_note' ) ) {
[194] Fix | Delete
$note_class::possibly_add_note();
[195] Fix | Delete
}
[196] Fix | Delete
}
[197] Fix | Delete
}
[198] Fix | Delete
[199] Fix | Delete
/**
[200] Fix | Delete
* Deletes notes that should be deleted.
[201] Fix | Delete
*/
[202] Fix | Delete
protected function possibly_delete_notes() {
[203] Fix | Delete
PaymentsRemindMeLater::delete_if_not_applicable();
[204] Fix | Delete
PaymentsMoreInfoNeeded::delete_if_not_applicable();
[205] Fix | Delete
}
[206] Fix | Delete
[207] Fix | Delete
/**
[208] Fix | Delete
* Updates notes that should be updated.
[209] Fix | Delete
*/
[210] Fix | Delete
protected function possibly_update_notes() {
[211] Fix | Delete
foreach ( self::$note_classes_to_added_or_updated as $note_class ) {
[212] Fix | Delete
if ( method_exists( $note_class, 'possibly_update_note' ) ) {
[213] Fix | Delete
$note_class::possibly_update_note();
[214] Fix | Delete
}
[215] Fix | Delete
}
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
/**
[219] Fix | Delete
* Checks if remote inbox notifications are enabled.
[220] Fix | Delete
*
[221] Fix | Delete
* @return bool Whether remote inbox notifications are enabled.
[222] Fix | Delete
*/
[223] Fix | Delete
protected function is_remote_inbox_notifications_enabled() {
[224] Fix | Delete
// Check if the feature flag is disabled.
[225] Fix | Delete
if ( ! Features::is_enabled( 'remote-inbox-notifications' ) ) {
[226] Fix | Delete
return false;
[227] Fix | Delete
}
[228] Fix | Delete
[229] Fix | Delete
// Check if the site has opted out of marketplace suggestions.
[230] Fix | Delete
if ( get_option( 'woocommerce_show_marketplace_suggestions', 'yes' ) !== 'yes' ) {
[231] Fix | Delete
return false;
[232] Fix | Delete
}
[233] Fix | Delete
[234] Fix | Delete
// All checks have passed.
[235] Fix | Delete
return true;
[236] Fix | Delete
}
[237] Fix | Delete
[238] Fix | Delete
/**
[239] Fix | Delete
* Checks if merchant email notifications are enabled.
[240] Fix | Delete
*
[241] Fix | Delete
* @return bool Whether merchant email notifications are enabled.
[242] Fix | Delete
*/
[243] Fix | Delete
protected function is_merchant_email_notifications_enabled() {
[244] Fix | Delete
// Check if the feature flag is disabled.
[245] Fix | Delete
if ( get_option( 'woocommerce_merchant_email_notifications', 'no' ) !== 'yes' ) {
[246] Fix | Delete
return false;
[247] Fix | Delete
}
[248] Fix | Delete
[249] Fix | Delete
// All checks have passed.
[250] Fix | Delete
return true;
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
/**
[254] Fix | Delete
* Refresh transient for the following DataSourcePollers on wc_admin_daily cron job.
[255] Fix | Delete
* - PaymentGatewaySuggestionsDataSourcePoller
[256] Fix | Delete
* - RemoteFreeExtensionsDataSourcePoller
[257] Fix | Delete
*/
[258] Fix | Delete
protected function possibly_refresh_data_source_pollers() {
[259] Fix | Delete
$completed_tasks = get_option( 'woocommerce_task_list_tracked_completed_tasks', array() );
[260] Fix | Delete
[261] Fix | Delete
if ( ! in_array( 'payments', $completed_tasks, true ) && ! in_array( 'woocommerce-payments', $completed_tasks, true ) ) {
[262] Fix | Delete
PaymentGatewaySuggestionsDataSourcePoller::get_instance()->read_specs_from_data_sources();
[263] Fix | Delete
}
[264] Fix | Delete
[265] Fix | Delete
if ( ! in_array( 'store_details', $completed_tasks, true ) && ! in_array( 'marketing', $completed_tasks, true ) ) {
[266] Fix | Delete
RemoteFreeExtensionsDataSourcePoller::get_instance()->read_specs_from_data_sources();
[267] Fix | Delete
}
[268] Fix | Delete
}
[269] Fix | Delete
}
[270] Fix | Delete
[271] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function