is_premium() ) { return false; } // the free edition: the Pro code is not here, whatever the account says return (bool) $fs->can_use_premium_code(); } /** Is this the Pro codebase (as opposed to the free edition from wordpress.org)? */ public static function premium_build() { $fs = self::fs(); return $fs ? (bool) $fs->is_premium() : true; } /** "Free", "Pro", "Pro + AI", with " · trial" while trialling. */ public static function plan_title() { $fs = self::fs(); if ( ! $fs || ! self::pro() ) { return __( 'Free', 'chatdozo' ); } $t = (string) $fs->get_plan_title(); if ( $t === '' || $t === 'PLAN_TITLE' || strtolower( $t ) === 'free' ) { $t = 'Pro'; } // the SDK's placeholder until the plan has synced return (string) apply_filters( 'chatdozo_plan_title', $t ); } public static function trial() { $fs = self::fs(); return $fs ? (bool) $fs->is_trial() : false; } /** Whole days left in the trial, 0 when not trialling. */ public static function trial_days_left() { $fs = self::fs(); if ( ! $fs || ! $fs->is_trial() ) { return 0; } $site = $fs->get_site(); if ( ! is_object( $site ) || empty( $site->trial_ends ) ) { return 0; } $ends = strtotime( $site->trial_ends ); return $ends ? max( 0, (int) ceil( ( $ends - time() ) / DAY_IN_SECONDS ) ) : 0; } /** Has this site already had its free trial? Then the Pro card offers the plans, not the trial. */ public static function trial_used() { $fs = self::fs(); if ( ! $fs || ! $fs->is_registered() ) { return false; } $site = $fs->get_site(); return is_object( $site ) && method_exists( $site, 'is_trial_utilized' ) ? (bool) $site->is_trial_utilized() : false; } /** The trial has run out and nothing was bought: the Pro edition with its extras switched off. */ public static function lapsed() { $fs = self::fs(); return $fs && $fs->is_premium() && $fs->is_registered() && ! $fs->can_use_premium_code() && self::trial_used(); } /* ---------- where to go ---------- */ public static function account_url() { $fs = self::fs(); return $fs ? (string) $fs->get_account_url() : admin_url( 'admin.php?page=chatdozo' ); } public static function pricing_url() { $fs = self::fs(); return $fs ? (string) $fs->pricing_url() : 'https://chatdozo.com/pricing/'; } /** Start the 14-day trial (no card) from inside wp-admin. */ public static function trial_url() { $fs = self::fs(); return $fs ? (string) $fs->get_trial_url() : 'https://chatdozo.com/pricing/'; } /** The in-dashboard checkout for a plan change on an existing licence. */ public static function upgrade_url() { $fs = self::fs(); return $fs ? (string) $fs->get_upgrade_url() : 'https://chatdozo.com/pricing/'; } /** The plan as the Settings header shows it: the words, where the link goes, and a class for colour. */ public static function plan_line() { $on = self::pro(); $text = self::plan_title(); if ( self::trial() ) { /* translators: %d: number of days */ $text .= ' · ' . sprintf( _n( '%d day of trial left', '%d days of trial left', self::trial_days_left(), 'chatdozo' ), self::trial_days_left() ); } return array( 'text' => $text, 'url' => $on ? self::account_url() : self::pro_url(), 'class' => $on ? 'is-on' : 'is-off' ); } /** Where the Pro card's button goes: the trial when it is still to be had, otherwise the plans. */ public static function pro_url() { return ( ! self::trial_used() && ! self::pro() ) ? self::trial_url() : self::pricing_url(); } public static function pro_label() { return ( ! self::trial_used() && ! self::pro() ) ? __( 'Try Pro free for 14 days', 'chatdozo' ) : __( 'See the Pro plans', 'chatdozo' ); } public static function init() { $fs = self::fs(); if ( ! $fs ) { return; } // Chatdozo's own wording on the licence screens $fs->add_filter( 'connect-message_on-premium', array( __CLASS__, 'connect_message' ), 10, 3 ); $fs->add_filter( 'connect_message', array( __CLASS__, 'connect_message_free' ), 10, 6 ); $fs->add_filter( 'show_trial', '__return_false' ); // our own Pro card in Settings says it, once, in our words if ( is_admin() ) { add_action( 'admin_notices', array( __CLASS__, 'notice' ) ); } } public static function connect_message( $message, $user_first_name, $product_title ) { return sprintf( /* translators: %s: first name */ __( 'Hi %s, paste your Chatdozo licence key below. It came by email with your purchase; if you cannot find it, the link under the box sends it again.', 'chatdozo' ), esc_html( $user_first_name ) ) . '
' . esc_html__( 'No key yet? Start the free trial on chatdozo.com', 'chatdozo' ) . ''; } /** The opt-in screen of the free edition: plain words about what is shared, nothing else. */ public static function connect_message_free( $message, $user_first_name, $product_title, $user_login, $site_link, $freemius_link ) { return sprintf( /* translators: %s: first name */ __( 'Hi %s, Chatdozo is ready. Allow it to send a note when the plugin is activated, updated or removed, so you get security updates and we hear when something breaks. No chat content ever leaves your site. Skip if you prefer; everything works the same.', 'chatdozo' ), esc_html( $user_first_name ) ); } /** * Two notices, both on Chatdozo's own pages only: * - the free edition after a trial was started here: the Pro edition still has to be installed (one click, Dashboard → Updates); * - the Pro edition when the trial has run out: the extras are off, the chat itself keeps working. */ public static function notice() { $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; $on_ours = $screen && strpos( (string) $screen->id, 'chatdozo' ) !== false; if ( ! $on_ours ) { return; } if ( ! current_user_can( 'manage_options' ) ) { return; } $fs = self::fs(); if ( ! $fs || $fs->is_activation_mode() ) { return; } if ( ! $fs->is_premium() && $fs->can_use_premium_code() ) { echo '

' . esc_html__( 'Your Pro trial has started. One step left: install the Pro edition.', 'chatdozo' ) . ' ' . esc_html__( 'It arrives as an ordinary plugin update. Your settings and chats stay exactly as they are.', 'chatdozo' ) . '

' . esc_html__( 'Go to Updates and update Chatdozo', 'chatdozo' ) . '

'; return; } if ( self::lapsed() ) { echo '

' . esc_html__( 'Your 14-day Pro trial has ended.', 'chatdozo' ) . ' ' . esc_html__( 'The chat, the inbox and your team keep working exactly as in the free edition; the Pro extras are waiting, with everything you set up still saved.', 'chatdozo' ) . '

' . esc_html__( 'Keep Pro', 'chatdozo' ) . '

'; } } }