diff --git a/class-wc-facebookcommerce.php b/class-wc-facebookcommerce.php index 05801bb7a..855e2fd06 100644 --- a/class-wc-facebookcommerce.php +++ b/class-wc-facebookcommerce.php @@ -18,6 +18,7 @@ use SkyVerge\WooCommerce\Facebook\ProductSync\ProductValidator as ProductSyncValidator; use SkyVerge\WooCommerce\Facebook\Utilities\Heartbeat; use Automattic\WooCommerce\Admin\Features\Features as WooAdminFeatures; +use SkyVerge\WooCommerce\Facebook\Admin\Notes\SettingsMoved; if ( ! class_exists( 'WC_Facebookcommerce' ) ) : @@ -390,25 +391,26 @@ public function add_admin_notices() { } if ( $is_marketing_enabled ) { - - $this->get_admin_notice_handler()->add_admin_notice( - sprintf( - /* translators: Placeholders: %1$s - opening HTML link tag, %2$s - closing HTML link tag */ - esc_html__( 'Heads up! The Facebook menu is now located under the %1$sMarketing%2$s menu.', 'facebook-for-woocommerce' ), - '', - '' - ), - 'settings_moved_to_marketing', - array( - 'dismissible' => true, - 'always_show_on_settings' => false, - 'notice_class' => 'notice-info', - ) - ); + SettingsMoved::possibly_add_or_delete_note(); } } } + /** + * Get the last event from the plugin lifecycle. + * + * @since x.x.x + * @return array + */ + public function get_last_event_from_history() { + $last_event = array(); + $history_events = $this->lifecycle_handler->get_event_history(); + + if ( isset( $history_events[0] ) ) { + $last_event = $history_events[0]; + } + return $last_event; + } public function add_wordpress_integration() { new WP_Facebook_Integration(); diff --git a/includes/Admin/Notes/SettingsMoved.php b/includes/Admin/Notes/SettingsMoved.php new file mode 100644 index 000000000..85319e4a4 --- /dev/null +++ b/includes/Admin/Notes/SettingsMoved.php @@ -0,0 +1,88 @@ +get_last_event_from_history(); + + if ( isset( $last_event['name'] ) && 'upgrade' === $last_event['name'] ) { + $last_version = $last_event['data']['from_version']; + if ( version_compare( $last_version, '2.2.0', '<' ) ) { + $should_display = true; + } + } + + return $should_display; + } + + /** + * Add or delete note depending on the conditions to display the note. + * + * @throws NotesUnavailableException Throws exception when notes are unavailable. + */ + public static function possibly_add_or_delete_note() { + // Verify the conditions to display the note. + if ( self::should_display() ) { + self::possibly_add_note(); + } elseif ( self::note_exists() ) { + self::possibly_delete_note(); + } + } + + /** + * Get the note. + * + * @return Note + */ + public static function get_note() { + + $settings_url = facebook_for_woocommerce()->get_settings_url(); + $content = esc_html__( 'Sync your products and reach customers across Facebook, Instagram, Messenger and WhatsApp through your Facebook plugin, which can be found at Marketing > Facebook.', 'facebook-for-woocommerce' ); + + $note = new Note(); + $note->set_title( esc_html__( 'Facebook is now found under Marketing', 'facebook-for-woocommerce' ) ); + $note->set_content( $content ); + $note->set_content_data( (object) array() ); + $note->set_type( Note::E_WC_ADMIN_NOTE_INFORMATIONAL ); + $note->set_name( self::NOTE_NAME ); + $note->set_source( 'facebook-for-woocommerce' ); + $note->add_action( 'settings', esc_html__( 'Go to Facebook', 'facebook-for-woocommerce' ), $settings_url ); + return $note; + } +}