flexible-shipping
/
src
/
WPDesk
/
FS
/
TableRate
/
ShippingMethod
/
Duplicate
/
DuplicateNotice.php
DuplicateAction.php
2 weeks ago
DuplicateNotice.php
2 weeks ago
DuplicateScript.php
2 weeks ago
DuplicateTracker.php
2 weeks ago
DuplicatorChecker.php
2 weeks ago
DuplicateNotice.php
54 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class DuplicateNotice |
| 4 | * |
| 5 | * @package WPDesk\FS\TableRate\ShippingMethod\Duplicate |
| 6 | */ |
| 7 | |
| 8 | namespace WPDesk\FS\TableRate\ShippingMethod\Duplicate; |
| 9 | |
| 10 | use FSVendor\WPDesk\Notice\Notice; |
| 11 | use FSVendor\WPDesk\PluginBuilder\Plugin\Hookable; |
| 12 | |
| 13 | /** |
| 14 | * Display admin notices. |
| 15 | */ |
| 16 | class DuplicateNotice implements Hookable { |
| 17 | /** |
| 18 | * Hooks. |
| 19 | */ |
| 20 | public function hooks() { |
| 21 | add_action( 'woocommerce_settings_shipping', [ $this, 'add_admin_notice' ] ); |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Add admin notices. |
| 26 | */ |
| 27 | public function add_admin_notice() { |
| 28 | if ( ! isset( $_GET['status'], $_GET[ DuplicateAction::ACTION ], $_GET['method_title'] ) ) { |
| 29 | return; |
| 30 | } |
| 31 | |
| 32 | $status = in_array( $_GET['status'], [ 'success', 'error' ] ) ? $_GET['status'] : 'warning'; // phpcs:ignore |
| 33 | $title = sanitize_text_field( urldecode( wp_unslash( $_GET['method_title'] ) ) ); // phpcs:ignore |
| 34 | |
| 35 | if ( $status === 'success' ) { |
| 36 | $message = __( '%1$s%2$s%3$s successfully duplicated.', 'flexible-shipping' ); // phpcs:ignore |
| 37 | } else { |
| 38 | $message = __( '%1$s%2$s%3$s shipping method duplication error. Please try again later.', 'flexible-shipping' ); // phpcs:ignore |
| 39 | } |
| 40 | |
| 41 | $this->display_notice( sprintf( $message, '<strong>', $title, '</strong>' ), $status ); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * @param string $content . |
| 46 | * @param string $type . |
| 47 | * |
| 48 | * @codeCoverageIgnore |
| 49 | */ |
| 50 | protected function display_notice( string $content, string $type ) { |
| 51 | new Notice( $content, $type, true ); |
| 52 | } |
| 53 | } |
| 54 |