%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' ), '' . esc_html( $this->get_plugin()->get_plugin_name() ) . '', '', '', '', '' ); } return $message; } /** * Registers a milestone message to be displayed in the admin. * * @since 5.1.0 * @see Lifecycle::generate_milestone_notice_message() * * @param string $id milestone ID * @param string $message message to display to the user * @return bool whether the message was successfully registered */ public function register_milestone_message( $id, $message ) { $milestone_messages = $this->get_milestone_messages(); $dismissed_notices = array_keys( $this->get_plugin()->get_admin_notice_handler()->get_dismissed_notices() ); // get the total number of dismissed milestone messages $dismissed_milestone_messages = array_intersect( array_keys( $milestone_messages ), $dismissed_notices ); // if the user has dismissed more than three milestone messages already, don't add any more if ( count( $dismissed_milestone_messages ) > 3 ) { return false; } $milestone_messages[ $id ] = $message; return update_option( 'wc_' . $this->get_plugin()->get_id() . '_milestone_messages', $milestone_messages ); } /** Event history methods *****************************************************************************************/ /** * Adds an upgrade lifecycle event. * * @since 5.4.0 * * @param string $from_version version upgrading from * @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 ); return $this->store_event( 'upgrade', $data ); } /** * Adds a migration lifecycle event. * * @since 5.4.0 * * @param string $from_plugin plugin migrating from * @param string $from_version version migrating from * @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 ); return $this->store_event( 'migrate', $data ); } /** * Stores a lifecycle event. * * This can be used to log installs, upgrades, etc... * * Uses a direct database query to avoid cache issues. * * @since 5.4.0 * * @param string $name lifecycle event name * @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( 'name' => wc_clean( $name ), 'time' => (int) current_time( 'timestamp' ), 'version' => wc_clean( $this->get_plugin()->get_version() ), ); if ( ! empty( $data ) ) { $event['data'] = wc_clean( $data ); } array_unshift( $history, $event ); // limit to the last 30 events $history = array_slice( $history, 0, 29 ); return $wpdb->replace( $wpdb->options, array( 'option_name' => $this->get_event_history_option_name(), 'option_value' => json_encode( $history ), 'autoload' => 'no', ), array( '%s', '%s', ) ); } /** * Gets the lifecycle event history. * * The last 30 events are stored, with the latest first. * * @since 5.4.0 * * @return array */ public function get_event_history() { global $wpdb; $history = []; $results = $wpdb->get_var( $wpdb->prepare( " SELECT option_value FROM {$wpdb->options} WHERE option_name = %s ", $this->get_event_history_option_name() ) ); if ( $results ) { $history = json_decode( $results, true ); } return is_array( $history ) ? $history : []; } /** * Gets the event history option name. * * @since 5.4.0 * * @return string */ protected function get_event_history_option_name() { return 'wc_' . $this->get_plugin()->get_id() . '_lifecycle_events'; } /** Utility Methods *******************************************************/ /** * Gets the registered milestone messages. * * @since 5.1.0 * * @return array */ protected function get_milestone_messages() { return get_option( 'wc_' . $this->get_plugin()->get_id() . '_milestone_messages', [] ); } /** * Sets the milestone version. * * @since 5.1.0 * * @param string $version plugin version * @return bool */ public function set_milestone_version( $version ) { $this->milestone_version = $version; return update_option( 'wc_' . $this->get_plugin()->get_id() . '_milestone_version', $version ); } /** * Gets the milestone version. * * @since 5.1.0 * * @return string */ public function get_milestone_version() { if ( ! $this->milestone_version ) { $this->milestone_version = get_option( 'wc_' . $this->get_plugin()->get_id() . '_milestone_version', '' ); } return $this->milestone_version; } /** * Gets the currently installed plugin version. * * @since 5.2.0 * * @return string */ protected function get_installed_version() { return get_option( $this->get_plugin()->get_plugin_version_name() ); } /** * Sets the installed plugin version. * * @since 5.2.0 * * @param string $version version to set */ protected function set_installed_version( $version ) { update_option( $this->get_plugin()->get_plugin_version_name(), $version ); } /** * Gets the plugin instance. * * @return Plugin */ protected function get_plugin() { return $this->plugin; } }