Skip to content
Closed
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
60 changes: 38 additions & 22 deletions includes/Framework/Lifecycle.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?php
// phpcs:ignoreFile
/**
* Facebook for WooCommerce.
*/

namespace WooCommerce\Facebook\Framework;

defined( 'ABSPATH' ) or exit;
defined( 'ABSPATH' ) || exit;

/**
* Plugin lifecycle handler.
Expand Down Expand Up @@ -203,12 +202,13 @@ public function add_admin_notices() {
*/
$message = apply_filters(
'wc_' . $this->get_plugin()->get_id() . '_milestone_message',
$this->generate_milestone_notice_message( $message ), $id
$this->generate_milestone_notice_message( $message ),
$id
);
if ( $message ) {
$this->get_plugin()
->get_admin_notice_handler()
->add_admin_notice( $message, $id, array( 'always_show_on_settings' => false, ) );
->add_admin_notice( $message, $id, array( 'always_show_on_settings' => false ) );
// only display one notice at a time
break;
}
Expand Down Expand Up @@ -264,13 +264,15 @@ protected function generate_milestone_notice_message( $custom_message ) {
__( 'Congratulations', 'facebook-for-woocommerce' ),
__( 'Hot dog', 'facebook-for-woocommerce' ),
);
$message = $exclamations[ array_rand( $exclamations ) ] . ', ' . esc_html( $custom_message ) . ' ';
$message .= sprintf(
$message = $exclamations[ array_rand( $exclamations ) ] . ', ' . esc_html( $custom_message ) . ' ';
$message .= sprintf(
/* translators: Placeholders: %1$s - plugin name, %2$s - <a> tag, %3$s - </a> tag, %4$s - <a> tag, %5$s - </a> tag */
__( 'Are you having a great experience with %1$s so far? Please consider %2$sleaving a review%3$s! If things aren\'t going quite as expected, we\'re happy to help -- please %4$sreach out to our support team%5$s.', 'facebook-for-woocommerce' ),
'<strong>' . esc_html( $this->get_plugin()->get_plugin_name() ) . '</strong>',
'<a href="' . esc_url( $this->get_plugin()->get_reviews_url() ) . '">', '</a>',
'<a href="' . esc_url( $this->get_plugin()->get_support_url() ) . '">', '</a>'
'<a href="' . esc_url( $this->get_plugin()->get_reviews_url() ) . '">',
'</a>',
'<a href="' . esc_url( $this->get_plugin()->get_support_url() ) . '">',
'</a>'
);
}
return $message;
Expand Down Expand Up @@ -310,13 +312,16 @@ public function register_milestone_message( $id, $message ) {
* @since 5.4.0
*
* @param string $from_version version upgrading from
* @param array $data extra data to add
* @param array $data extra data to add
* @return false|int
*/
public function add_upgrade_event( $from_version, array $data = [] ) {
$data = array_merge( array(
'from_version' => $from_version,
), $data );
$data = array_merge(
array(
'from_version' => $from_version,
),
$data
);
return $this->store_event( 'upgrade', $data );
}

Expand All @@ -328,14 +333,17 @@ public function add_upgrade_event( $from_version, array $data = [] ) {
*
* @param string $from_plugin plugin migrating from
* @param string $from_version version migrating from
* @param array $data extra data to add
* @param array $data extra data to add
* @return false|int
*/
public function add_migrate_event( $from_plugin, $from_version = '', array $data = [] ) {
$data = array_merge( array(
'from_plugin' => $from_plugin,
'from_version' => $from_version,
), $data );
$data = array_merge(
array(
'from_plugin' => $from_plugin,
'from_version' => $from_version,
),
$data
);
return $this->store_event( 'migrate', $data );
}

Expand All @@ -350,14 +358,17 @@ public function add_migrate_event( $from_plugin, $from_version = '', array $data
* @since 5.4.0
*
* @param string $name lifecycle event name
* @param array $data any extra data to store
* @param array $data any extra data to store
* @return false|int
*/
public function store_event( $name, array $data = [] ) {
global $wpdb;
$history = $this->get_event_history();
$event = array(
$event = array(
'name' => wc_clean( $name ),
// We should investigate if there's a better way to get this value;
// however, for the interim, we'll keep the existing behavior unchanged.
// phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
'time' => (int) current_time( 'timestamp' ),
'version' => wc_clean( $this->get_plugin()->get_version() ),
);
Expand All @@ -371,7 +382,7 @@ public function store_event( $name, array $data = [] ) {
$wpdb->options,
array(
'option_name' => $this->get_event_history_option_name(),
'option_value' => json_encode( $history ),
'option_value' => wp_json_encode( $history ),
'autoload' => 'no',
),
array(
Expand All @@ -394,11 +405,16 @@ public function store_event( $name, array $data = [] ) {
public function get_event_history() {
global $wpdb;
$history = [];
$results = $wpdb->get_var( $wpdb->prepare( "
$results = $wpdb->get_var(
$wpdb->prepare(
"
SELECT option_value
FROM {$wpdb->options}
WHERE option_name = %s
", $this->get_event_history_option_name() ) );
",
$this->get_event_history_option_name()
)
);
if ( $results ) {
$history = json_decode( $results, true );
}
Expand Down