Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/Internal/Admin/Notes
File: MarketingJetpack.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WooCommerce Admin Jetpack Marketing Note Provider.
[2] Fix | Delete
*
[3] Fix | Delete
* Adds notes to the merchant's inbox concerning Jetpack Backup.
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
namespace Automattic\WooCommerce\Internal\Admin\Notes;
[7] Fix | Delete
[8] Fix | Delete
defined( 'ABSPATH' ) || exit;
[9] Fix | Delete
[10] Fix | Delete
use Automattic\Jetpack\Constants;
[11] Fix | Delete
use Automattic\WooCommerce\Admin\Notes\Note;
[12] Fix | Delete
use Automattic\WooCommerce\Admin\Notes\Notes;
[13] Fix | Delete
use Automattic\WooCommerce\Admin\Notes\NoteTraits;
[14] Fix | Delete
use Automattic\WooCommerce\Admin\PluginsHelper;
[15] Fix | Delete
[16] Fix | Delete
/**
[17] Fix | Delete
* Suggest Jetpack Backup to Woo users.
[18] Fix | Delete
*
[19] Fix | Delete
* Note: This should probably live in the Jetpack plugin in the future.
[20] Fix | Delete
*
[21] Fix | Delete
* @see https://developer.woocommerce.com/2020/10/16/using-the-admin-notes-inbox-in-woocommerce/
[22] Fix | Delete
*/
[23] Fix | Delete
class MarketingJetpack {
[24] Fix | Delete
// Shared Note Traits.
[25] Fix | Delete
use NoteTraits;
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* Name of the note for use in the database.
[29] Fix | Delete
*/
[30] Fix | Delete
const NOTE_NAME = 'wc-admin-marketing-jetpack-backup';
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* Product IDs that include Backup.
[34] Fix | Delete
*/
[35] Fix | Delete
const BACKUP_IDS = [
[36] Fix | Delete
2010,
[37] Fix | Delete
2011,
[38] Fix | Delete
2012,
[39] Fix | Delete
2013,
[40] Fix | Delete
2014,
[41] Fix | Delete
2015,
[42] Fix | Delete
2100,
[43] Fix | Delete
2101,
[44] Fix | Delete
2102,
[45] Fix | Delete
2103,
[46] Fix | Delete
2005,
[47] Fix | Delete
2006,
[48] Fix | Delete
2000,
[49] Fix | Delete
2003,
[50] Fix | Delete
2001,
[51] Fix | Delete
2004,
[52] Fix | Delete
];
[53] Fix | Delete
[54] Fix | Delete
/**
[55] Fix | Delete
* Maybe add a note on Jetpack Backups for Jetpack sites older than a week without Backups.
[56] Fix | Delete
*/
[57] Fix | Delete
public static function possibly_add_note() {
[58] Fix | Delete
/**
[59] Fix | Delete
* Check if Jetpack is installed.
[60] Fix | Delete
*/
[61] Fix | Delete
$installed_plugins = PluginsHelper::get_installed_plugin_slugs();
[62] Fix | Delete
if ( ! in_array( 'jetpack', $installed_plugins, true ) ) {
[63] Fix | Delete
return;
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
$data_store = \WC_Data_Store::load( 'admin-note' );
[67] Fix | Delete
[68] Fix | Delete
// Do we already have this note?
[69] Fix | Delete
$note_ids = $data_store->get_notes_with_name( self::NOTE_NAME );
[70] Fix | Delete
if ( ! empty( $note_ids ) ) {
[71] Fix | Delete
[72] Fix | Delete
$note_id = array_pop( $note_ids );
[73] Fix | Delete
$note = Notes::get_note( $note_id );
[74] Fix | Delete
if ( false === $note ) {
[75] Fix | Delete
return;
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
// If Jetpack Backups was purchased after the note was created, mark this note as actioned.
[79] Fix | Delete
if ( self::has_backups() && Note::E_WC_ADMIN_NOTE_ACTIONED !== $note->get_status() ) {
[80] Fix | Delete
$note->set_status( Note::E_WC_ADMIN_NOTE_ACTIONED );
[81] Fix | Delete
$note->save();
[82] Fix | Delete
}
[83] Fix | Delete
[84] Fix | Delete
return;
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
// Check requirements.
[88] Fix | Delete
if ( ! self::is_wc_admin_active_in_date_range( 'week-1-4', DAY_IN_SECONDS * 3 ) || ! self::can_be_added() || self::has_backups() ) {
[89] Fix | Delete
return;
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
// Add note.
[93] Fix | Delete
$note = self::get_note();
[94] Fix | Delete
$note->save();
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
/**
[98] Fix | Delete
* Get the note.
[99] Fix | Delete
*/
[100] Fix | Delete
public static function get_note() {
[101] Fix | Delete
$note = new Note();
[102] Fix | Delete
$note->set_title( __( 'Protect your WooCommerce Store with Jetpack Backup.', 'woocommerce' ) );
[103] Fix | Delete
$note->set_content( __( 'Store downtime means lost sales. One-click restores get you back online quickly if something goes wrong.', 'woocommerce' ) );
[104] Fix | Delete
$note->set_type( Note::E_WC_ADMIN_NOTE_MARKETING );
[105] Fix | Delete
$note->set_name( self::NOTE_NAME );
[106] Fix | Delete
$note->set_layout( 'thumbnail' );
[107] Fix | Delete
$note->set_image(
[108] Fix | Delete
WC_ADMIN_IMAGES_FOLDER_URL . '/admin_notes/marketing-jetpack-2x.png'
[109] Fix | Delete
);
[110] Fix | Delete
$note->set_content_data( (object) array() );
[111] Fix | Delete
$note->set_source( 'woocommerce-admin-notes' );
[112] Fix | Delete
$note->add_action(
[113] Fix | Delete
'jetpack-backup-woocommerce',
[114] Fix | Delete
__( 'Get backups', 'woocommerce' ),
[115] Fix | Delete
esc_url( 'https://jetpack.com/upgrade/backup-woocommerce/?utm_source=inbox&utm_medium=automattic_referred&utm_campaign=jp_backup_to_woo' ),
[116] Fix | Delete
Note::E_WC_ADMIN_NOTE_ACTIONED
[117] Fix | Delete
);
[118] Fix | Delete
return $note;
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
/**
[122] Fix | Delete
* Check if this blog already has a Jetpack Backups product.
[123] Fix | Delete
*
[124] Fix | Delete
* @return boolean Whether or not this blog has backups.
[125] Fix | Delete
*/
[126] Fix | Delete
protected static function has_backups() {
[127] Fix | Delete
$product_ids = [];
[128] Fix | Delete
[129] Fix | Delete
$plan = get_option( 'jetpack_active_plan' );
[130] Fix | Delete
if ( ! empty( $plan ) ) {
[131] Fix | Delete
$product_ids[] = $plan['product_id'];
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
$products = get_option( 'jetpack_site_products' );
[135] Fix | Delete
if ( ! empty( $products ) ) {
[136] Fix | Delete
foreach ( $products as $product ) {
[137] Fix | Delete
$product_ids[] = $product['product_id'];
[138] Fix | Delete
}
[139] Fix | Delete
}
[140] Fix | Delete
[141] Fix | Delete
return (bool) array_intersect( self::BACKUP_IDS, $product_ids );
[142] Fix | Delete
}
[143] Fix | Delete
[144] Fix | Delete
}
[145] Fix | Delete
[146] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function