Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions class-wc-facebookcommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) ) :

Expand Down Expand Up @@ -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 <a> HTML link tag, %2$s - closing </a> HTML link tag */
esc_html__( 'Heads up! The Facebook menu is now located under the %1$sMarketing%2$s menu.', 'facebook-for-woocommerce' ),
'<a href="' . esc_url( $this->get_settings_url() ) . '">',
'</a>'
),
'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();
Expand Down
88 changes: 88 additions & 0 deletions includes/Admin/Notes/SettingsMoved.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php
/**
* Facebook Menu Settings moved note.
*
* Adds a note to merchant's inbox about Facebook Menu being moved to Marketing menu.
*
* @package FacebookCommerce
*/

namespace SkyVerge\WooCommerce\Facebook\Admin\Notes;

defined( 'ABSPATH' ) || exit;

use \Automattic\WooCommerce\Admin\Notes\Note;
use \Automattic\WooCommerce\Admin\Notes\NoteTraits;

/**
* SettingsMoved class.
*/
class SettingsMoved {
/**
* Note traits.
*/
use NoteTraits;

/**
* Name of the note for use in the database.
*/
const NOTE_NAME = 'facebook-for-woocommerce-settings-moved-to-marketing';

/**
* Checks if this note should be displayed.
*
* @return bool
*/
public static function should_display() {
/**
* The Facebook menu was moved under Marketing menu in v2.2.0. Display this note
* only to users updating from a version prior to v2.2.0.
*/
$should_display = false;
$last_event = facebook_for_woocommerce()->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;
}
}