Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/Internal/Admin/Notes
File: WooSubscriptionsNotes.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WooCommerce Admin (Dashboard) WooCommerce.com Extension Subscriptions Note Provider.
[2] Fix | Delete
*
[3] Fix | Delete
* Adds notes to the merchant's inbox concerning WooCommerce.com extension subscriptions.
[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\WooCommerce\Admin\Notes\Note;
[11] Fix | Delete
use Automattic\WooCommerce\Admin\Notes\Notes;
[12] Fix | Delete
use Automattic\WooCommerce\Admin\PageController;
[13] Fix | Delete
[14] Fix | Delete
/**
[15] Fix | Delete
* Woo_Subscriptions_Notes
[16] Fix | Delete
*/
[17] Fix | Delete
class WooSubscriptionsNotes {
[18] Fix | Delete
const LAST_REFRESH_OPTION_KEY = 'woocommerce_admin-wc-helper-last-refresh';
[19] Fix | Delete
const NOTE_NAME = 'wc-admin-wc-helper-connection';
[20] Fix | Delete
const CONNECTION_NOTE_NAME = 'wc-admin-wc-helper-connection'; // deprecated.
[21] Fix | Delete
const SUBSCRIPTION_NOTE_NAME = 'wc-admin-wc-helper-subscription';
[22] Fix | Delete
const NOTIFY_WHEN_DAYS_LEFT = 60;
[23] Fix | Delete
const BUMP_THRESHOLDS = array( 60, 45, 20, 7, 1 ); // days.
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* Hook all the things.
[27] Fix | Delete
*/
[28] Fix | Delete
public function __construct() {
[29] Fix | Delete
add_action( 'admin_head', array( $this, 'admin_head' ) );
[30] Fix | Delete
add_action( 'update_option_woocommerce_helper_data', array( $this, 'update_option_woocommerce_helper_data' ), 10, 2 );
[31] Fix | Delete
}
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* Reacts to changes in the helper option.
[35] Fix | Delete
*
[36] Fix | Delete
* @param array $old_value The previous value of the option.
[37] Fix | Delete
* @param array $value The new value of the option.
[38] Fix | Delete
*/
[39] Fix | Delete
public function update_option_woocommerce_helper_data( $old_value, $value ) {
[40] Fix | Delete
if ( ! is_array( $old_value ) ) {
[41] Fix | Delete
$old_value = array();
[42] Fix | Delete
}
[43] Fix | Delete
if ( ! is_array( $value ) ) {
[44] Fix | Delete
$value = array();
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
$old_auth = array_key_exists( 'auth', $old_value ) ? $old_value['auth'] : array();
[48] Fix | Delete
$new_auth = array_key_exists( 'auth', $value ) ? $value['auth'] : array();
[49] Fix | Delete
$old_token = array_key_exists( 'access_token', $old_auth ) ? $old_auth['access_token'] : '';
[50] Fix | Delete
$new_token = array_key_exists( 'access_token', $new_auth ) ? $new_auth['access_token'] : '';
[51] Fix | Delete
[52] Fix | Delete
// The site just disconnected.
[53] Fix | Delete
if ( ! empty( $old_token ) && empty( $new_token ) ) {
[54] Fix | Delete
$this->remove_notes();
[55] Fix | Delete
return;
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
// The site is connected.
[59] Fix | Delete
if ( $this->is_connected() ) {
[60] Fix | Delete
$this->remove_notes();
[61] Fix | Delete
$this->refresh_subscription_notes();
[62] Fix | Delete
return;
[63] Fix | Delete
}
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
/**
[67] Fix | Delete
* Runs on `admin_head` hook. Checks the connection and refreshes subscription notes on relevant pages.
[68] Fix | Delete
*/
[69] Fix | Delete
public function admin_head() {
[70] Fix | Delete
if ( ! PageController::is_admin_or_embed_page() ) {
[71] Fix | Delete
// To avoid unnecessarily calling Helper API, we only want to refresh subscription notes,
[72] Fix | Delete
// if the request is initiated from the wc admin dashboard or a WC related page which includes
[73] Fix | Delete
// the Activity button in WC header.
[74] Fix | Delete
return;
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
$this->check_connection();
[78] Fix | Delete
[79] Fix | Delete
if ( $this->is_connected() ) {
[80] Fix | Delete
$refresh_notes = false;
[81] Fix | Delete
[82] Fix | Delete
// Did the user just do something on the helper page?.
[83] Fix | Delete
if ( isset( $_GET['wc-helper-status'] ) ) { // @codingStandardsIgnoreLine.
[84] Fix | Delete
$refresh_notes = true;
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
// Has it been more than a day since we last checked?
[88] Fix | Delete
// Note: We do it this way and not wp_scheduled_task since WC_Helper_Options is not loaded for cron.
[89] Fix | Delete
$time_now_gmt = current_time( 'timestamp', 0 );
[90] Fix | Delete
$last_refresh = intval( get_option( self::LAST_REFRESH_OPTION_KEY, 0 ) );
[91] Fix | Delete
if ( $last_refresh + DAY_IN_SECONDS <= $time_now_gmt ) {
[92] Fix | Delete
update_option( self::LAST_REFRESH_OPTION_KEY, $time_now_gmt );
[93] Fix | Delete
$refresh_notes = true;
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
if ( $refresh_notes ) {
[97] Fix | Delete
$this->refresh_subscription_notes();
[98] Fix | Delete
}
[99] Fix | Delete
}
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
/**
[103] Fix | Delete
* Checks the connection. Adds a note (as necessary) if there is no connection.
[104] Fix | Delete
*/
[105] Fix | Delete
public function check_connection() {
[106] Fix | Delete
if ( ! $this->is_connected() ) {
[107] Fix | Delete
$data_store = Notes::load_data_store();
[108] Fix | Delete
$note_ids = $data_store->get_notes_with_name( self::CONNECTION_NOTE_NAME );
[109] Fix | Delete
if ( ! empty( $note_ids ) ) {
[110] Fix | Delete
// We already have a connection note. Exit early.
[111] Fix | Delete
return;
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
$this->remove_notes();
[115] Fix | Delete
}
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
/**
[119] Fix | Delete
* Whether or not we think the site is currently connected to WooCommerce.com.
[120] Fix | Delete
*
[121] Fix | Delete
* @return bool
[122] Fix | Delete
*/
[123] Fix | Delete
public function is_connected() {
[124] Fix | Delete
$auth = \WC_Helper_Options::get( 'auth' );
[125] Fix | Delete
return ( ! empty( $auth['access_token'] ) );
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
/**
[129] Fix | Delete
* Returns the WooCommerce.com provided site ID for this site.
[130] Fix | Delete
*
[131] Fix | Delete
* @return int|false
[132] Fix | Delete
*/
[133] Fix | Delete
public function get_connected_site_id() {
[134] Fix | Delete
if ( ! $this->is_connected() ) {
[135] Fix | Delete
return false;
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
$auth = \WC_Helper_Options::get( 'auth' );
[139] Fix | Delete
return absint( $auth['site_id'] );
[140] Fix | Delete
}
[141] Fix | Delete
[142] Fix | Delete
/**
[143] Fix | Delete
* Returns an array of product_ids whose subscriptions are active on this site.
[144] Fix | Delete
*
[145] Fix | Delete
* @return array
[146] Fix | Delete
*/
[147] Fix | Delete
public function get_subscription_active_product_ids() {
[148] Fix | Delete
$site_id = $this->get_connected_site_id();
[149] Fix | Delete
if ( ! $site_id ) {
[150] Fix | Delete
return array();
[151] Fix | Delete
}
[152] Fix | Delete
[153] Fix | Delete
$product_ids = array();
[154] Fix | Delete
[155] Fix | Delete
if ( $this->is_connected() ) {
[156] Fix | Delete
try {
[157] Fix | Delete
$subscriptions = \WC_Helper::get_subscriptions();
[158] Fix | Delete
} catch ( \Exception $e ) {
[159] Fix | Delete
$subscriptions = array();
[160] Fix | Delete
}
[161] Fix | Delete
[162] Fix | Delete
foreach ( (array) $subscriptions as $subscription ) {
[163] Fix | Delete
if ( in_array( $site_id, $subscription['connections'], true ) ) {
[164] Fix | Delete
$product_ids[] = $subscription['product_id'];
[165] Fix | Delete
}
[166] Fix | Delete
}
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
return $product_ids;
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
/**
[173] Fix | Delete
* Clears all connection or subscription notes.
[174] Fix | Delete
*/
[175] Fix | Delete
public function remove_notes() {
[176] Fix | Delete
Notes::delete_notes_with_name( self::CONNECTION_NOTE_NAME );
[177] Fix | Delete
Notes::delete_notes_with_name( self::SUBSCRIPTION_NOTE_NAME );
[178] Fix | Delete
}
[179] Fix | Delete
[180] Fix | Delete
/**
[181] Fix | Delete
* Gets the product_id (if any) associated with a note.
[182] Fix | Delete
*
[183] Fix | Delete
* @param Note $note The note object to interrogate.
[184] Fix | Delete
* @return int|false
[185] Fix | Delete
*/
[186] Fix | Delete
public function get_product_id_from_subscription_note( &$note ) {
[187] Fix | Delete
if ( ! is_object( $note ) ) {
[188] Fix | Delete
return false;
[189] Fix | Delete
}
[190] Fix | Delete
$content_data = $note->get_content_data();
[191] Fix | Delete
[192] Fix | Delete
if ( property_exists( $content_data, 'product_id' ) ) {
[193] Fix | Delete
return intval( $content_data->product_id );
[194] Fix | Delete
}
[195] Fix | Delete
[196] Fix | Delete
return false;
[197] Fix | Delete
}
[198] Fix | Delete
[199] Fix | Delete
/**
[200] Fix | Delete
* Removes notes for product_ids no longer active on this site.
[201] Fix | Delete
*/
[202] Fix | Delete
public function prune_inactive_subscription_notes() {
[203] Fix | Delete
$active_product_ids = $this->get_subscription_active_product_ids();
[204] Fix | Delete
[205] Fix | Delete
$data_store = Notes::load_data_store();
[206] Fix | Delete
$note_ids = $data_store->get_notes_with_name( self::SUBSCRIPTION_NOTE_NAME );
[207] Fix | Delete
[208] Fix | Delete
foreach ( (array) $note_ids as $note_id ) {
[209] Fix | Delete
$note = Notes::get_note( $note_id );
[210] Fix | Delete
$product_id = $this->get_product_id_from_subscription_note( $note );
[211] Fix | Delete
if ( ! empty( $product_id ) ) {
[212] Fix | Delete
if ( ! in_array( $product_id, $active_product_ids, true ) ) {
[213] Fix | Delete
$note->delete();
[214] Fix | Delete
}
[215] Fix | Delete
}
[216] Fix | Delete
}
[217] Fix | Delete
}
[218] Fix | Delete
[219] Fix | Delete
/**
[220] Fix | Delete
* Finds a note for a given product ID, if the note exists at all.
[221] Fix | Delete
*
[222] Fix | Delete
* @param int $product_id The product ID to search for.
[223] Fix | Delete
* @return Note|false
[224] Fix | Delete
*/
[225] Fix | Delete
public function find_note_for_product_id( $product_id ) {
[226] Fix | Delete
$product_id = intval( $product_id );
[227] Fix | Delete
[228] Fix | Delete
$data_store = Notes::load_data_store();
[229] Fix | Delete
$note_ids = $data_store->get_notes_with_name( self::SUBSCRIPTION_NOTE_NAME );
[230] Fix | Delete
foreach ( (array) $note_ids as $note_id ) {
[231] Fix | Delete
$note = Notes::get_note( $note_id );
[232] Fix | Delete
$found_product_id = $this->get_product_id_from_subscription_note( $note );
[233] Fix | Delete
[234] Fix | Delete
if ( $product_id === $found_product_id ) {
[235] Fix | Delete
return $note;
[236] Fix | Delete
}
[237] Fix | Delete
}
[238] Fix | Delete
[239] Fix | Delete
return false;
[240] Fix | Delete
}
[241] Fix | Delete
[242] Fix | Delete
/**
[243] Fix | Delete
* Deletes a note for a given product ID, if the note exists at all.
[244] Fix | Delete
*
[245] Fix | Delete
* @param int $product_id The product ID to search for.
[246] Fix | Delete
*/
[247] Fix | Delete
public function delete_any_note_for_product_id( $product_id ) {
[248] Fix | Delete
$product_id = intval( $product_id );
[249] Fix | Delete
[250] Fix | Delete
$note = $this->find_note_for_product_id( $product_id );
[251] Fix | Delete
if ( $note ) {
[252] Fix | Delete
$note->delete();
[253] Fix | Delete
}
[254] Fix | Delete
}
[255] Fix | Delete
[256] Fix | Delete
/**
[257] Fix | Delete
* Adds or updates a note for an expiring subscription.
[258] Fix | Delete
*
[259] Fix | Delete
* @param array $subscription The subscription to work with.
[260] Fix | Delete
*/
[261] Fix | Delete
public function add_or_update_subscription_expiring( $subscription ) {
[262] Fix | Delete
$product_id = $subscription['product_id'];
[263] Fix | Delete
$product_name = $subscription['product_name'];
[264] Fix | Delete
$expires = intval( $subscription['expires'] );
[265] Fix | Delete
$time_now_gmt = current_time( 'timestamp', 0 );
[266] Fix | Delete
$days_until_expiration = intval( ceil( ( $expires - $time_now_gmt ) / DAY_IN_SECONDS ) );
[267] Fix | Delete
[268] Fix | Delete
$note = $this->find_note_for_product_id( $product_id );
[269] Fix | Delete
[270] Fix | Delete
// Note: There is no reason this property should not exist. This is just defensive programming.
[271] Fix | Delete
if ( $note && property_exists( $note->get_content_data(), 'days_until_expiration' ) ) {
[272] Fix | Delete
$note_days_until_expiration = intval( $note->get_content_data()->days_until_expiration );
[273] Fix | Delete
if ( $days_until_expiration === $note_days_until_expiration ) {
[274] Fix | Delete
// Note is already up to date. Bail.
[275] Fix | Delete
return;
[276] Fix | Delete
}
[277] Fix | Delete
[278] Fix | Delete
// If we have a note and we are at or have crossed a threshold, we should delete
[279] Fix | Delete
// the old note and create a new one, thereby "bumping" the note to the top of the inbox.
[280] Fix | Delete
foreach ( (array) self::BUMP_THRESHOLDS as $bump_threshold ) {
[281] Fix | Delete
if ( ( $note_days_until_expiration > $bump_threshold ) && ( $days_until_expiration <= $bump_threshold ) ) {
[282] Fix | Delete
$note->delete();
[283] Fix | Delete
$note = false;
[284] Fix | Delete
break;
[285] Fix | Delete
}
[286] Fix | Delete
}
[287] Fix | Delete
}
[288] Fix | Delete
[289] Fix | Delete
$note_title = sprintf(
[290] Fix | Delete
/* translators: name of the extension subscription expiring soon */
[291] Fix | Delete
__( '%s subscription expiring soon', 'woocommerce' ),
[292] Fix | Delete
$product_name
[293] Fix | Delete
);
[294] Fix | Delete
[295] Fix | Delete
$note_content = sprintf(
[296] Fix | Delete
/* translators: number of days until the subscription expires */
[297] Fix | Delete
__( 'Your subscription expires in %d days. Enable autorenew to avoid losing updates and access to support.', 'woocommerce' ),
[298] Fix | Delete
$days_until_expiration
[299] Fix | Delete
);
[300] Fix | Delete
[301] Fix | Delete
$note_content_data = (object) array(
[302] Fix | Delete
'product_id' => $product_id,
[303] Fix | Delete
'product_name' => $product_name,
[304] Fix | Delete
'expired' => false,
[305] Fix | Delete
'days_until_expiration' => $days_until_expiration,
[306] Fix | Delete
);
[307] Fix | Delete
[308] Fix | Delete
if ( ! $note ) {
[309] Fix | Delete
$note = new Note();
[310] Fix | Delete
}
[311] Fix | Delete
[312] Fix | Delete
// Reset everything in case we are repurposing an expired note as an expiring note.
[313] Fix | Delete
$note->set_title( $note_title );
[314] Fix | Delete
$note->set_type( Note::E_WC_ADMIN_NOTE_WARNING );
[315] Fix | Delete
$note->set_name( self::SUBSCRIPTION_NOTE_NAME );
[316] Fix | Delete
$note->set_source( 'woocommerce-admin' );
[317] Fix | Delete
$note->clear_actions();
[318] Fix | Delete
$note->add_action(
[319] Fix | Delete
'enable-autorenew',
[320] Fix | Delete
__( 'Enable Autorenew', 'woocommerce' ),
[321] Fix | Delete
'https://woocommerce.com/my-account/my-subscriptions/?utm_medium=product'
[322] Fix | Delete
);
[323] Fix | Delete
$note->set_content( $note_content );
[324] Fix | Delete
$note->set_content_data( $note_content_data );
[325] Fix | Delete
$note->save();
[326] Fix | Delete
}
[327] Fix | Delete
[328] Fix | Delete
/**
[329] Fix | Delete
* Adds a note for an expired subscription, or updates an expiring note to expired.
[330] Fix | Delete
*
[331] Fix | Delete
* @param array $subscription The subscription to work with.
[332] Fix | Delete
*/
[333] Fix | Delete
public function add_or_update_subscription_expired( $subscription ) {
[334] Fix | Delete
$product_id = $subscription['product_id'];
[335] Fix | Delete
$product_name = $subscription['product_name'];
[336] Fix | Delete
$product_page = $subscription['product_url'];
[337] Fix | Delete
$expires = intval( $subscription['expires'] );
[338] Fix | Delete
$expires_date = gmdate( 'F jS', $expires );
[339] Fix | Delete
[340] Fix | Delete
$note = $this->find_note_for_product_id( $product_id );
[341] Fix | Delete
if ( $note ) {
[342] Fix | Delete
$note_content_data = $note->get_content_data();
[343] Fix | Delete
if ( $note_content_data->expired ) {
[344] Fix | Delete
// We've already got a full fledged expired note for this. Bail.
[345] Fix | Delete
// Expired notes' content don't change with time.
[346] Fix | Delete
return;
[347] Fix | Delete
}
[348] Fix | Delete
}
[349] Fix | Delete
[350] Fix | Delete
$note_title = sprintf(
[351] Fix | Delete
/* translators: name of the extension subscription that expired */
[352] Fix | Delete
__( '%s subscription expired', 'woocommerce' ),
[353] Fix | Delete
$product_name
[354] Fix | Delete
);
[355] Fix | Delete
[356] Fix | Delete
$note_content = sprintf(
[357] Fix | Delete
/* translators: date the subscription expired, e.g. Jun 7th 2018 */
[358] Fix | Delete
__( 'Your subscription expired on %s. Get a new subscription to continue receiving updates and access to support.', 'woocommerce' ),
[359] Fix | Delete
$expires_date
[360] Fix | Delete
);
[361] Fix | Delete
[362] Fix | Delete
$note_content_data = (object) array(
[363] Fix | Delete
'product_id' => $product_id,
[364] Fix | Delete
'product_name' => $product_name,
[365] Fix | Delete
'expired' => true,
[366] Fix | Delete
'expires' => $expires,
[367] Fix | Delete
'expires_date' => $expires_date,
[368] Fix | Delete
);
[369] Fix | Delete
[370] Fix | Delete
if ( ! $note ) {
[371] Fix | Delete
$note = new Note();
[372] Fix | Delete
}
[373] Fix | Delete
[374] Fix | Delete
$note->set_title( $note_title );
[375] Fix | Delete
$note->set_content( $note_content );
[376] Fix | Delete
$note->set_content_data( $note_content_data );
[377] Fix | Delete
$note->set_type( Note::E_WC_ADMIN_NOTE_WARNING );
[378] Fix | Delete
$note->set_name( self::SUBSCRIPTION_NOTE_NAME );
[379] Fix | Delete
$note->set_source( 'woocommerce-admin' );
[380] Fix | Delete
$note->clear_actions();
[381] Fix | Delete
$note->add_action(
[382] Fix | Delete
'renew-subscription',
[383] Fix | Delete
__( 'Renew Subscription', 'woocommerce' ),
[384] Fix | Delete
$product_page
[385] Fix | Delete
);
[386] Fix | Delete
$note->save();
[387] Fix | Delete
}
[388] Fix | Delete
[389] Fix | Delete
/**
[390] Fix | Delete
* For each active subscription on this site, checks the expiration date and creates/updates/deletes notes.
[391] Fix | Delete
*/
[392] Fix | Delete
public function refresh_subscription_notes() {
[393] Fix | Delete
if ( ! $this->is_connected() ) {
[394] Fix | Delete
return;
[395] Fix | Delete
}
[396] Fix | Delete
[397] Fix | Delete
$this->prune_inactive_subscription_notes();
[398] Fix | Delete
[399] Fix | Delete
try {
[400] Fix | Delete
$subscriptions = \WC_Helper::get_subscriptions();
[401] Fix | Delete
} catch ( \Exception $e ) {
[402] Fix | Delete
$subscriptions = array();
[403] Fix | Delete
}
[404] Fix | Delete
$active_product_ids = $this->get_subscription_active_product_ids();
[405] Fix | Delete
[406] Fix | Delete
foreach ( (array) $subscriptions as $subscription ) {
[407] Fix | Delete
// Only concern ourselves with active products.
[408] Fix | Delete
$product_id = $subscription['product_id'];
[409] Fix | Delete
if ( ! in_array( $product_id, $active_product_ids, true ) ) {
[410] Fix | Delete
continue;
[411] Fix | Delete
}
[412] Fix | Delete
[413] Fix | Delete
// If the subscription will auto-renew, clean up and exit.
[414] Fix | Delete
if ( $subscription['autorenew'] ) {
[415] Fix | Delete
$this->delete_any_note_for_product_id( $product_id );
[416] Fix | Delete
continue;
[417] Fix | Delete
}
[418] Fix | Delete
[419] Fix | Delete
// If the subscription is not expiring by the first threshold, clean up and exit.
[420] Fix | Delete
$first_threshold = DAY_IN_SECONDS * self::BUMP_THRESHOLDS[0];
[421] Fix | Delete
$expires = intval( $subscription['expires'] );
[422] Fix | Delete
$time_now_gmt = current_time( 'timestamp', 0 );
[423] Fix | Delete
if ( $expires > $time_now_gmt + $first_threshold ) {
[424] Fix | Delete
$this->delete_any_note_for_product_id( $product_id );
[425] Fix | Delete
continue;
[426] Fix | Delete
}
[427] Fix | Delete
[428] Fix | Delete
// Otherwise, if the subscription can still have auto-renew enabled, let them know that now.
[429] Fix | Delete
if ( $expires > $time_now_gmt ) {
[430] Fix | Delete
$this->add_or_update_subscription_expiring( $subscription );
[431] Fix | Delete
continue;
[432] Fix | Delete
}
[433] Fix | Delete
[434] Fix | Delete
// If we got this far, the subscription has completely expired, let them know.
[435] Fix | Delete
$this->add_or_update_subscription_expired( $subscription );
[436] Fix | Delete
}
[437] Fix | Delete
}
[438] Fix | Delete
}
[439] Fix | Delete
[440] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function