init
This commit is contained in:
+31
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Display a notice to merchants that have WCPay installed (and don't have UPE enabled)
|
||||
* to inform them that they can enable additional payment methods.
|
||||
*
|
||||
* @package WooCommerce\Payments\Admin
|
||||
*/
|
||||
|
||||
use Automattic\WooCommerce\Admin\Notes\NoteTraits;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class WC_Payments_Notes_Additional_Payment_Methods
|
||||
*/
|
||||
class WC_Payments_Notes_Additional_Payment_Methods {
|
||||
use NoteTraits;
|
||||
|
||||
/**
|
||||
* Name of the note for use in the database.
|
||||
*/
|
||||
const NOTE_NAME = 'wc-payments-notes-additional-payment-methods';
|
||||
|
||||
/**
|
||||
* Get the note.
|
||||
*/
|
||||
public static function get_note() {
|
||||
// The notice should not be shown anymore because UPE is the default now.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* Notify merchant that they are eligible for Instant Deposits.
|
||||
*
|
||||
* @package WooCommerce\Payments\Admin
|
||||
*/
|
||||
|
||||
use Automattic\WooCommerce\Admin\Notes\Note;
|
||||
use Automattic\WooCommerce\Admin\Notes\NoteTraits;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class WC_Payments_Notes_Instant_Deposits_Eligible
|
||||
*/
|
||||
class WC_Payments_Notes_Instant_Deposits_Eligible {
|
||||
use NoteTraits;
|
||||
|
||||
/**
|
||||
* Name of the note for use in the database.
|
||||
*/
|
||||
const NOTE_NAME = 'wc-payments-notes-instant-deposits-eligible';
|
||||
|
||||
/**
|
||||
* Get the note.
|
||||
*/
|
||||
public static function get_note() {
|
||||
$note = new Note();
|
||||
|
||||
$note->set_title(
|
||||
sprintf(
|
||||
/* translators: %s: WooPayments */
|
||||
__( 'You’re now eligible to receive Instant Payouts with %s', 'woocommerce-payments' ),
|
||||
'WooPayments'
|
||||
)
|
||||
);
|
||||
$note->set_content(
|
||||
WC_Payments_Utils::esc_interpolated_html(
|
||||
sprintf(
|
||||
/* translators: %s: WooPayments */
|
||||
__( "Get immediate access to your funds when you need them – including nights, weekends, and holidays. With %s' <a>Instant Payouts feature</a>, you're able to transfer your earnings to a debit card within minutes.", 'woocommerce-payments' ),
|
||||
'WooPayments'
|
||||
),
|
||||
[ 'a' => '<a href="https://woocommerce.com/document/woopayments/payouts/instant-payouts/">' ]
|
||||
)
|
||||
);
|
||||
$note->set_content_data( (object) [] );
|
||||
$note->set_type( Note::E_WC_ADMIN_NOTE_INFORMATIONAL );
|
||||
$note->set_name( self::NOTE_NAME );
|
||||
$note->set_source( 'woocommerce-payments' );
|
||||
$note->add_action(
|
||||
self::NOTE_NAME,
|
||||
__( 'Request an instant payout', 'woocommerce-payments' ),
|
||||
'https://woocommerce.com/document/woopayments/payouts/instant-payouts/#request-an-instant-payout',
|
||||
'unactioned',
|
||||
true
|
||||
);
|
||||
|
||||
return $note;
|
||||
}
|
||||
}
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
/**
|
||||
* Display a notice to merchants that have WCPay installed to inform them
|
||||
* that a loan offer has been approved from Stripe.
|
||||
*
|
||||
* @package WooCommerce\Payments\Admin
|
||||
*/
|
||||
|
||||
use Automattic\WooCommerce\Admin\Notes\Note;
|
||||
use Automattic\WooCommerce\Admin\Notes\Notes;
|
||||
use Automattic\WooCommerce\Admin\Notes\NoteTraits;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class WC_Payments_Notes_Loan_Approved
|
||||
*/
|
||||
class WC_Payments_Notes_Loan_Approved {
|
||||
use NoteTraits;
|
||||
|
||||
/**
|
||||
* Prefix of the note for use in the database.
|
||||
*/
|
||||
const NOTE_NAME = 'wc-payments-notes-loan-approved';
|
||||
|
||||
/**
|
||||
* Nonce action name
|
||||
*/
|
||||
const NOTE_ACTION = 'view-capital-page';
|
||||
|
||||
/**
|
||||
* Loan information to build the message.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $loan_info;
|
||||
|
||||
/**
|
||||
* Get the note.
|
||||
*/
|
||||
public static function get_note() {
|
||||
$note = new Note();
|
||||
$dummy_order = wc_create_order();
|
||||
$dummy_order->set_currency( self::$loan_info['details']['currency'] );
|
||||
|
||||
$note->set_title( __( 'Your capital loan has been approved!', 'woocommerce-payments' ) );
|
||||
$note->set_content(
|
||||
sprintf(
|
||||
/* Translators: %1: total amount lent to the merchant formatted in the account currency, %2: WooPayments */
|
||||
__(
|
||||
'Congratulations! Your capital loan has been approved and %1$s was deposited into the bank account linked to %2$s. You\'ll automatically repay the loan, plus a flat fee, through a fixed percentage of each %2$s transaction.',
|
||||
'woocommerce-payments'
|
||||
),
|
||||
WC_Payments_Explicit_Price_Formatter::get_explicit_price(
|
||||
wc_price(
|
||||
WC_Payments_Utils::interpret_stripe_amount( self::$loan_info['details']['advance_amount'] ),
|
||||
[ 'currency' => self::$loan_info['details']['currency'] ]
|
||||
),
|
||||
$dummy_order
|
||||
),
|
||||
'WooPayments'
|
||||
)
|
||||
);
|
||||
|
||||
$note->set_content_data(
|
||||
(object) [
|
||||
'advance_amount' => self::$loan_info['details']['advance_amount'],
|
||||
'advance_paid_out_at' => self::$loan_info['details']['advance_paid_out_at'],
|
||||
]
|
||||
);
|
||||
$note->set_type( Note::E_WC_ADMIN_NOTE_INFORMATIONAL );
|
||||
$note->set_name( self::NOTE_NAME );
|
||||
$note->set_source( 'woocommerce-payments' );
|
||||
$note->add_action(
|
||||
self::NOTE_NAME,
|
||||
__( 'View loan details', 'woocommerce-payments' ),
|
||||
admin_url( 'admin.php?page=wc-admin&path=/payments/loans' ),
|
||||
Note::E_WC_ADMIN_NOTE_UNACTIONED,
|
||||
true
|
||||
);
|
||||
|
||||
return $note;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the note if it passes predefined conditions.
|
||||
*/
|
||||
public static function possibly_add_note() {
|
||||
// If we have the correct information, proceed. Otherwise, delete existing notes.
|
||||
if ( ! self::validate_inputs() ) {
|
||||
// We don't have the necessary info to create a note, do nothing.
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the current loan info matches with the received one. If it matches, don't add a new one.
|
||||
if ( ! self::check_attached_loan_data_is_different() ) {
|
||||
// Loan paid out dates are the same, do nothing.
|
||||
return;
|
||||
}
|
||||
|
||||
// Do the overridden work.
|
||||
if ( ! self::can_be_added() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$new_note = self::get_note();
|
||||
$new_note->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the stored loan info has all the values we need.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function validate_inputs() {
|
||||
// If the loan amount isn't set correctly, don't push the note, and delete the old one if exists.
|
||||
if ( ! isset(
|
||||
self::$loan_info['details']['currency'],
|
||||
self::$loan_info['details']['advance_amount'],
|
||||
self::$loan_info['details']['advance_paid_out_at']
|
||||
)
|
||||
|| ! is_numeric( self::$loan_info['details']['advance_amount'] )
|
||||
|| empty( self::$loan_info['details']['currency'] )
|
||||
) {
|
||||
// There's something wrong with the loan information, delete the existing note, just in case of wrong information.
|
||||
return false;
|
||||
}
|
||||
|
||||
self::$loan_info['details']['currency'] = strtoupper( self::$loan_info['details']['currency'] );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the saved paid out date on the previous note and deletes it if it doesn't match, to create a new one.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function check_attached_loan_data_is_different() {
|
||||
$data_store = WC_Data_Store::load( 'admin-note' );
|
||||
$note_ids = $data_store->get_notes_with_name( self::NOTE_NAME );
|
||||
|
||||
if ( ! empty( $note_ids ) ) {
|
||||
$note = Notes::get_note( $note_ids[0] );
|
||||
if ( $note instanceof Note ) {
|
||||
$content_data = (array) $note->get_content_data();
|
||||
if ( isset( $content_data['advance_paid_out_at'], $content_data['advance_amount'] ) ) {
|
||||
if ( self::$loan_info['details']['advance_paid_out_at'] === $content_data['advance_paid_out_at'] &&
|
||||
self::$loan_info['details']['advance_amount'] === $content_data['advance_amount'] ) {
|
||||
// Note already exists for the current loan. No action will be taken.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// The note isn't for the current loan. Delete it to create a new one.
|
||||
$data_store->delete( $note );
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the loan information on the class.
|
||||
*
|
||||
* @param array $loan_info loan information.
|
||||
*/
|
||||
public static function set_loan_details( array $loan_info ) {
|
||||
self::$loan_info = $loan_info;
|
||||
}
|
||||
}
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* Set up refund policy note for WooCommerce inbox.
|
||||
*
|
||||
* @package WooCommerce\Payments\Admin
|
||||
*/
|
||||
|
||||
use Automattic\WooCommerce\Admin\Notes\Note;
|
||||
use Automattic\WooCommerce\Admin\Notes\NoteTraits;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class WC_Payments_Notes_Set_Up_Refund_Policy
|
||||
*/
|
||||
class WC_Payments_Notes_Qualitative_Feedback {
|
||||
use NoteTraits;
|
||||
|
||||
/**
|
||||
* Name of the note for use in the database.
|
||||
*/
|
||||
const NOTE_NAME = 'wc-payments-notes-qualitative-feedback';
|
||||
|
||||
/**
|
||||
* Name of the note for use in the database.
|
||||
*/
|
||||
const NOTE_DOCUMENTATION_URL = 'http://automattic.survey.fm/wc-pay-existing';
|
||||
|
||||
/**
|
||||
* Get the note.
|
||||
*/
|
||||
public static function get_note() {
|
||||
global $wpdb;
|
||||
|
||||
// Store must be at least 60 days old.
|
||||
if ( ! self::wc_admin_active_for( 60 * DAY_IN_SECONDS ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// We should have at least one transaction.
|
||||
if ( WC_Payments_Utils::is_hpos_tables_usage_enabled() ) {
|
||||
$result = $wpdb->get_var(
|
||||
"SELECT EXISTS(
|
||||
SELECT 1
|
||||
FROM {$wpdb->prefix}wc_orders_meta
|
||||
WHERE meta_key = '_wcpay_transaction_fee'
|
||||
LIMIT 1)
|
||||
AS count;"
|
||||
);
|
||||
} else {
|
||||
$result = $wpdb->get_var(
|
||||
"SELECT EXISTS(
|
||||
SELECT 1
|
||||
FROM {$wpdb->postmeta}
|
||||
WHERE meta_key = '_wcpay_transaction_fee'
|
||||
LIMIT 1)
|
||||
AS count;"
|
||||
);
|
||||
}
|
||||
|
||||
if ( 1 !== intval( $result ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$note = new Note();
|
||||
|
||||
$note->set_title(
|
||||
sprintf(
|
||||
/* translators: %s: WooPayments */
|
||||
__( 'Help us make improvements to %s', 'woocommerce-payments' ),
|
||||
'WooPayments'
|
||||
)
|
||||
);
|
||||
$note->set_content( __( 'Share your feedback in this 2 minute survey about how we can make the process of accepting payments more useful for your store.', 'woocommerce-payments' ) );
|
||||
$note->set_content_data( (object) [] );
|
||||
$note->set_type( Note::E_WC_ADMIN_NOTE_INFORMATIONAL );
|
||||
$note->set_name( self::NOTE_NAME );
|
||||
$note->set_source( 'woocommerce-payments' );
|
||||
$note->add_action(
|
||||
self::NOTE_NAME,
|
||||
__( 'Share feedback', 'woocommerce-payments' ),
|
||||
self::NOTE_DOCUMENTATION_URL,
|
||||
'unactioned',
|
||||
true
|
||||
);
|
||||
|
||||
return $note;
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* Set up ensure https on checkout note for WooCommerce inbox.
|
||||
*
|
||||
* @package WooCommerce\Payments\Admin
|
||||
*/
|
||||
|
||||
use Automattic\WooCommerce\Admin\Notes\Note;
|
||||
use Automattic\WooCommerce\Admin\Notes\NoteTraits;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class WC_Payments_Notes_Set_Https_For_Checkout
|
||||
*/
|
||||
class WC_Payments_Notes_Set_Https_For_Checkout {
|
||||
use NoteTraits {
|
||||
can_be_added as protected trait_can_be_added;
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of the note for use in the database.
|
||||
*/
|
||||
const NOTE_NAME = 'wc-payments-notes-set-https-for-checkout';
|
||||
|
||||
/**
|
||||
* Name of the note for use in the database.
|
||||
*/
|
||||
const NOTE_DOCUMENTATION_URL = 'https://woocommerce.com/document/ssl-and-https/#woocommerce-force-ssl-setting';
|
||||
|
||||
/**
|
||||
* Checks if a note can and should be added.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function can_be_added() {
|
||||
// This note only makes sense if HTTPS is not enforced yet.
|
||||
if ( 'yes' === get_option( 'woocommerce_force_ssl_checkout' ) || wc_site_is_https() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return self::trait_can_be_added();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the note.
|
||||
*/
|
||||
public static function get_note() {
|
||||
$note = new Note();
|
||||
|
||||
$note->set_title( __( 'Enable secure checkout', 'woocommerce-payments' ) );
|
||||
$note->set_content( __( 'Enable HTTPS on your checkout pages to display all available payment methods and protect your customers data.', 'woocommerce-payments' ) );
|
||||
$note->set_content_data( (object) [] );
|
||||
$note->set_type( Note::E_WC_ADMIN_NOTE_INFORMATIONAL );
|
||||
$note->set_name( self::NOTE_NAME );
|
||||
$note->set_source( 'woocommerce-payments' );
|
||||
$note->add_action(
|
||||
self::NOTE_NAME,
|
||||
__( 'Read more', 'woocommerce-payments' ),
|
||||
self::NOTE_DOCUMENTATION_URL,
|
||||
'unactioned',
|
||||
true
|
||||
);
|
||||
|
||||
return $note;
|
||||
}
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* Set up Stripe Link note for WooCommerce inbox.
|
||||
*
|
||||
* @package WooCommerce\Payments\Admin
|
||||
*/
|
||||
|
||||
use Automattic\WooCommerce\Admin\Notes\Note;
|
||||
use Automattic\WooCommerce\Admin\Notes\NoteTraits;
|
||||
use WCPay\Payment_Methods\Link_Payment_Method;
|
||||
use WCPay\Payment_Methods\CC_Payment_Method;
|
||||
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class WC_Payments_Notes_Setup_StripeLink
|
||||
*/
|
||||
class WC_Payments_Notes_Set_Up_StripeLink {
|
||||
use NoteTraits;
|
||||
|
||||
/**
|
||||
* Name of the note for use in the database.
|
||||
*/
|
||||
const NOTE_NAME = 'wc-payments-notes-set-up-stripe-link';
|
||||
|
||||
/**
|
||||
* CTA button link
|
||||
*/
|
||||
const NOTE_DOCUMENTATION_URL = 'https://woocommerce.com/document/woopayments/payment-methods/link-by-stripe/';
|
||||
|
||||
/**
|
||||
* The account service instance.
|
||||
*
|
||||
* @var WC_Payment_Gateway_WCPay
|
||||
*/
|
||||
private static $gateway;
|
||||
|
||||
/**
|
||||
* Checks if a note can and should be added.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function should_display_note(): bool {
|
||||
// Check if Link payment is available.
|
||||
$available_upe_payment_methods = self::$gateway->get_upe_available_payment_methods();
|
||||
if ( ! in_array( Link_Payment_Method::PAYMENT_METHOD_STRIPE_ID, $available_upe_payment_methods, true ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Retrieve enabled payment methods at checkout.
|
||||
$enabled_payment_methods = self::$gateway->get_payment_method_ids_enabled_at_checkout_filtered_by_fees( null, true );
|
||||
// If card payment method is not enabled or Link payment method is enabled, skip.
|
||||
if ( ! in_array( CC_Payment_Method::PAYMENT_METHOD_STRIPE_ID, $enabled_payment_methods, true )
|
||||
|| in_array( Link_Payment_Method::PAYMENT_METHOD_STRIPE_ID, $enabled_payment_methods, true ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the note.
|
||||
*/
|
||||
public static function get_note() {
|
||||
if ( ! self::should_display_note() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$note = new Note();
|
||||
|
||||
$note->set_title( __( 'Increase conversion at checkout', 'woocommerce-payments' ) );
|
||||
$note->set_content( __( 'Reduce cart abandonment and create a frictionless checkout experience with Link by Stripe. Link autofills your customer’s payment and shipping details, so they can check out in just six seconds with the Link optimized experience.', 'woocommerce-payments' ) );
|
||||
$note->set_content_data( (object) [] );
|
||||
$note->set_type( Note::E_WC_ADMIN_NOTE_INFORMATIONAL );
|
||||
$note->set_name( self::NOTE_NAME );
|
||||
$note->set_source( 'woocommerce-payments' );
|
||||
$note->add_action(
|
||||
self::NOTE_NAME,
|
||||
__( 'Set up now', 'woocommerce-payments' ),
|
||||
self::NOTE_DOCUMENTATION_URL,
|
||||
'unactioned',
|
||||
true
|
||||
);
|
||||
|
||||
return $note;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the WCPay gateway instance reference on the class.
|
||||
*
|
||||
* @param WC_Payment_Gateway_WCPay $gateway WCPay gateway instance.
|
||||
*/
|
||||
public static function set_gateway( WC_Payment_Gateway_WCPay $gateway ) {
|
||||
self::$gateway = $gateway;
|
||||
}
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
/**
|
||||
* WooCommerce inbox remote note service.
|
||||
*
|
||||
* @package WooCommerce\Payments\Admin
|
||||
*/
|
||||
|
||||
use Automattic\WooCommerce\Admin\Notes\Note;
|
||||
use WCPay\Exceptions\Rest_Request_Exception;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class WC_Payments_Remote_Note_Service
|
||||
*/
|
||||
class WC_Payments_Remote_Note_Service {
|
||||
const NOTE_NAME_PREFIX = 'wc-payments-remote-notes-';
|
||||
|
||||
/**
|
||||
* Notes data store.
|
||||
*
|
||||
* @var WC_Data_Store
|
||||
*/
|
||||
private $note_data_store;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param WC_Data_Store $note_data_store WC Admin note data store.
|
||||
*/
|
||||
public function __construct( WC_Data_Store $note_data_store ) {
|
||||
$this->note_data_store = $note_data_store;
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts the given note data in the inbox if it hasn't been added before.
|
||||
*
|
||||
* @param array $note_data Note data from the API.
|
||||
*
|
||||
* @return bool True if the note has been added.
|
||||
*
|
||||
* @throws Rest_Request_Exception If note data is invalid.
|
||||
*/
|
||||
public function put_note( array $note_data ): bool {
|
||||
$note = $this->create_note( $note_data );
|
||||
|
||||
if ( ! $this->can_note_be_added( $note->get_name() ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->note_data_store->create( $note );
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of a note from API note data.
|
||||
*
|
||||
* @param array $note_data The note data to process.
|
||||
*
|
||||
* @return Automattic\WooCommerce\Admin\Notes\WC_Admin_Note|Automattic\WooCommerce\Admin\Notes\Note Note object.
|
||||
*
|
||||
* @throws Rest_Request_Exception If note data is invalid.
|
||||
*/
|
||||
private function create_note( array $note_data ) {
|
||||
if ( ! isset( $note_data['title'], $note_data['content'] ) ) {
|
||||
throw new Rest_Request_Exception( 'Invalid note.' );
|
||||
}
|
||||
|
||||
$title = $note_data['title'];
|
||||
$content = $note_data['content'];
|
||||
$note_name = self::NOTE_NAME_PREFIX . ( $note_data['name'] ?? md5( $title . $content ) );
|
||||
|
||||
$note = new Note();
|
||||
|
||||
$note->set_title( $title );
|
||||
$note->set_content( $content );
|
||||
$note->set_content_data( (object) [] );
|
||||
$note->set_type( Note::E_WC_ADMIN_NOTE_INFORMATIONAL );
|
||||
$note->set_name( $note_name );
|
||||
$note->set_source( 'woocommerce-payments' );
|
||||
|
||||
if ( isset( $note_data['actions'] ) && is_array( $note_data['actions'] ) ) {
|
||||
foreach ( $note_data['actions'] as $action_key => $action ) {
|
||||
if ( ! isset( $action['label'], $action['url'] ) ) {
|
||||
throw new Rest_Request_Exception( 'Invalid note.' );
|
||||
}
|
||||
|
||||
if ( 'wcpay_settings' === $action['url'] ) {
|
||||
$url = WC_Payments_Admin_Settings::get_settings_url();
|
||||
} elseif ( isset( $action['url_is_admin'] ) && (bool) $action['url_is_admin'] ) {
|
||||
$url = admin_url( $action['url'] );
|
||||
} else {
|
||||
throw new Rest_Request_Exception( 'Invalid note.' );
|
||||
}
|
||||
|
||||
$note->add_action(
|
||||
$note_name . '-' . $action_key,
|
||||
$action['label'],
|
||||
$url,
|
||||
$action['status'] ?? Note::E_WC_ADMIN_NOTE_ACTIONED,
|
||||
$action['primary'] ?? false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $note;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all of the notes where names are prefixed with the value of the NOTE_NAME_PREFIX constant.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete_notes() {
|
||||
global $wpdb;
|
||||
$prefix = self::NOTE_NAME_PREFIX;
|
||||
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
$wpdb->query( "DELETE FROM {$wpdb->prefix}wc_admin_note_actions WHERE name LIKE '{$prefix}%'" );
|
||||
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
$wpdb->query( "DELETE FROM {$wpdb->prefix}wc_admin_notes WHERE name LIKE '{$prefix}%'" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the note can be added.
|
||||
*
|
||||
* @param string $note_name Name of the note to add.
|
||||
*
|
||||
* @return boolean True if the note can be added.
|
||||
*/
|
||||
private function can_note_be_added( string $note_name ): bool {
|
||||
$note_ids = $this->note_data_store->get_notes_with_name( $note_name );
|
||||
return empty( $note_ids );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user