'Version' ) ); $version = isset( $hdr['Version'] ) ? trim( (string) $hdr['Version'] ) : ''; } set_transient( self::TRANSIENT, array( 'core' => $core, 'version' => $version ), HOUR_IN_SECONDS ); return $version; } public static function pro_mismatched() { $core = defined( 'AIEO_VERSION' ) ? (string) AIEO_VERSION : ''; $pro = self::pro_version(); if ( '' === $core || '' === $pro || '0' === $core || '0' === $pro ) { return false; } return 0 !== version_compare( $core, $pro ); } public static function pro_state() { if ( ! self::pro_installed() ) { return 'absent'; } if ( ! self::pro_active() ) { return 'inactive'; } return self::pro_mismatched() ? 'mismatch' : 'active'; } public static function entitlement_summary() { $pro = class_exists( 'AIEO_DMM_Module_Base' ) ? AIEO_DMM_Module_Base::is_aieo_pro_user() : false; $ent = ( class_exists( 'AIEO_Rooster_Signup' ) && method_exists( 'AIEO_Rooster_Signup', 'entitlement' ) ) ? AIEO_Rooster_Signup::entitlement() : null; $days = ( class_exists( 'AIEO_Rooster_Signup' ) && method_exists( 'AIEO_Rooster_Signup', 'days_remaining' ) ) ? AIEO_Rooster_Signup::days_remaining() : null; $binding = class_exists( 'AIEO_Entitlement_Binding' ) ? AIEO_Entitlement_Binding::verdict() : 'ok'; $seat_free = is_array( $ent ) && isset( $ent['site']['status'] ) && 'free' === (string) $ent['site']['status']; $tier_free = is_array( $ent ) && isset( $ent['tier'] ) && 'free' === (string) $ent['tier']; if ( ! $pro ) { if ( $tier_free ) { return array( 'state' => 'off', 'pill' => __( 'Upgrade to Pro', 'ai-eshop-optimizer' ), 'detail' => __( 'The trial has ended. The free features keep working exactly as they are.', 'ai-eshop-optimizer' ), 'pro' => false, 'cta' => 'buy', ); } if ( $seat_free ) { return array( 'state' => 'off', 'pill' => __( 'No seat for this site', 'ai-eshop-optimizer' ), 'detail' => __( 'The subscription is active, but this site does not hold one of its seats, so Pro is locked here. The storefront is untouched.', 'ai-eshop-optimizer' ), 'pro' => false, 'cta' => 'seat', ); } if ( 'foreign' === $binding ) { return array( 'state' => 'off', 'pill' => __( 'Pro locked here', 'ai-eshop-optimizer' ), 'detail' => ( method_exists( 'AIEO_Entitlement_Binding', 'explain' ) ? (string) AIEO_Entitlement_Binding::explain() : '' ), 'pro' => false, 'cta' => 'seat', ); } return array( 'state' => 'off', 'pill' => __( 'Upgrade to Pro', 'ai-eshop-optimizer' ), 'detail' => __( 'Pro unlocks the paid screens on this site. There is a free trial, and the free features keep working either way.', 'ai-eshop-optimizer' ), 'pro' => false, 'cta' => 'buy', ); } if ( 'grace' === $binding ) { return array( 'state' => 'hold', 'pill' => __( 'Pro · reconnecting', 'ai-eshop-optimizer' ), 'detail' => ( method_exists( 'AIEO_Entitlement_Binding', 'explain' ) ? (string) AIEO_Entitlement_Binding::explain() : '' ), 'pro' => true, 'cta' => '', ); } if ( is_array( $ent ) && ! empty( $ent['trial'] ) && null !== $days ) { return array( 'state' => ( (int) $days <= 3 ) ? 'hold' : 'on', 'pill' => sprintf( _n( 'Pro trial · %d day left', 'Pro trial · %d days left', (int) $days, 'ai-eshop-optimizer' ), (int) $days ), 'detail' => __( 'The trial unlocks the Pro screens that ship inside this plugin. Screens that need the separate Rooster One Pro plugin still need that download.', 'ai-eshop-optimizer' ), 'pro' => true, 'cta' => 'buy', ); } $checked = (int) get_option( 'aieo_entitlement_checked_at', 0 ); $max_age = class_exists( 'AIEO_Credit_Notifier' ) ? (int) AIEO_Credit_Notifier::MAX_AGE : 90000; if ( null === $ent || 0 === $checked || ( time() - $checked ) > $max_age ) { return array( 'state' => 'hold', 'pill' => __( 'Pro', 'ai-eshop-optimizer' ), 'detail' => $checked ? sprintf( __( 'Pro is on. We have not been able to confirm it with rooster.systems for %s, so it is running on trust until the next check.', 'ai-eshop-optimizer' ), human_time_diff( $checked ) ) : __( 'Pro is on. It has not been confirmed with rooster.systems yet, so it is running on trust until the first check.', 'ai-eshop-optimizer' ), 'pro' => true, 'cta' => '', ); } return array( 'state' => 'on', 'pill' => __( 'Pro', 'ai-eshop-optimizer' ), 'detail' => __( 'Pro is active on this site.', 'ai-eshop-optimizer' ), 'pro' => true, 'cta' => '', ); } public static function rows() { $core = defined( 'AIEO_VERSION' ) ? (string) AIEO_VERSION : ''; $map = array( 'absent' => 'off', 'inactive' => 'hold', 'mismatch' => 'hold', 'active' => 'on' ); $tier_text = __( 'Free', 'ai-eshop-optimizer' ); $state1 = 'on'; if ( class_exists( 'AIEO_Rooster_Signup' ) && method_exists( 'AIEO_Rooster_Signup', 'entitlement' ) ) { $ent = AIEO_Rooster_Signup::entitlement(); $days = method_exists( 'AIEO_Rooster_Signup', 'days_remaining' ) ? AIEO_Rooster_Signup::days_remaining() : null; if ( is_array( $ent ) && ! empty( $ent['tier'] ) && 'free' !== (string) $ent['tier'] ) { if ( ! empty( $ent['trial'] ) && null !== $days ) { $tier_text = sprintf( _n( 'Pro trial · %d day left', 'Pro trial · %d days left', (int) $days, 'ai-eshop-optimizer' ), (int) $days ); } else { $tier_text = __( 'Pro', 'ai-eshop-optimizer' ); } } elseif ( is_array( $ent ) && isset( $ent['tier'] ) && 'free' === (string) $ent['tier'] ) { $tier_text = __( 'Free · trial ended', 'ai-eshop-optimizer' ); } if ( is_array( $ent ) && isset( $ent['site']['status'] ) && 'free' === (string) $ent['site']['status'] ) { $state1 = 'off'; $tier_text = __( 'no seat for this site · Pro locked here', 'ai-eshop-optimizer' ); } } if ( class_exists( 'AIEO_Entitlement_Binding' ) ) { $binding = AIEO_Entitlement_Binding::verdict(); if ( 'grace' === $binding ) { $state1 = 'hold'; $tier_text = $tier_text . ' · ' . __( 'reconnecting after a domain change', 'ai-eshop-optimizer' ); } elseif ( 'foreign' === $binding ) { $state1 = 'off'; $tier_text = __( 'issued for another site', 'ai-eshop-optimizer' ); } } $ps = self::pro_state(); switch ( $ps ) { case 'absent': $d2 = __( 'not installed', 'ai-eshop-optimizer' ); break; case 'inactive': $d2 = __( 'downloaded but not activated: one click on the Plugins screen', 'ai-eshop-optimizer' ); break; case 'mismatch': $d2 = sprintf( __( 'version mismatch: the Pro plugin is %1$s and Rooster One is %2$s. Update them together', 'ai-eshop-optimizer' ), self::pro_version(), $core ); break; default: $d2 = __( 'installed', 'ai-eshop-optimizer' ); } $rs = class_exists( 'AIEO_Runtime_Presence' ) ? (string) AIEO_Runtime_Presence::state() : 'absent'; $d3 = class_exists( 'AIEO_Runtime_Presence' ) ? (string) AIEO_Runtime_Presence::status_text() : __( 'Not installed', 'ai-eshop-optimizer' ); $panel = self::panel_url(); $plugins = admin_url( 'plugins.php' ); return array( array( 'id' => 'core', 'name' => __( 'Rooster One', 'ai-eshop-optimizer' ), 'state' => $state1, 'version' => $core, 'detail' => $tier_text, 'url' => $panel, ), array( 'id' => 'pro', 'name' => __( 'the Pro plugin', 'ai-eshop-optimizer' ), 'state' => $map[ $ps ], 'version' => 'absent' === $ps ? '' : self::pro_version(), 'detail' => $d2, 'url' => 'inactive' === $ps ? $plugins : $panel, ), array( 'id' => 'runtime', 'name' => __( 'the front-end runtime', 'ai-eshop-optimizer' ), 'state' => isset( $map[ $rs ] ) ? $map[ $rs ] : 'off', 'version' => 'absent' === $rs ? '' : ( class_exists( 'AIEO_Runtime_Presence' ) ? (string) AIEO_Runtime_Presence::version() : '' ), 'detail' => $d3, 'url' => 'inactive' === $rs ? $plugins : $panel, ), ); } public static function render( $context = 'card' ) { if ( ! class_exists( '\Rooster\Admin\Ui' ) ) { return; } $tones = array( 'on' => 'success', 'hold' => 'warning', ); $facts = array(); foreach ( self::rows() as $r ) { $name = (string) $r['name']; $text = ( '' !== $r['version'] ? $r['version'] . ' · ' : '' ) . $r['detail']; $fact = array( 'label' => mb_strtoupper( mb_substr( $name, 0, 1 ) ) . mb_substr( $name, 1 ) ); if ( isset( $tones[ $r['state'] ] ) ) { $fact['tone'] = $tones[ $r['state'] ]; } if ( 'on' !== $r['state'] && '' !== $r['url'] ) { $fact['html'] = esc_html( $text ) . ' ' . esc_html__( 'Fix', 'ai-eshop-optimizer' ) . ''; } else { $fact['value'] = $text; } $facts[] = $fact; } echo '
'; echo \Rooster\Admin\Ui::facts( $facts ); self::render_notes(); self::render_actions(); echo '
'; } private static function render_notes() { if ( ! class_exists( 'AIEO_Entitlement_Binding' ) ) { return; } $explain = AIEO_Entitlement_Binding::explain(); if ( '' === $explain ) { return; } echo \Rooster\Admin\Ui::notice( esc_html( $explain ), 'info', array( 'inline' => true ) ); } private static function print_check_script() { static $printed = false; if ( $printed ) { return; } $printed = true; ?> __( 'Pro plugin', 'ai-eshop-optimizer' ), 'runtime' => __( 'front-end runtime', 'ai-eshop-optimizer' ), ); $buttons = ''; foreach ( AIEO_One_Installer::PLUGINS as $slug => $dir ) { unset( $dir ); $buttons .= \Rooster\Admin\Ui::button( sprintf( __( 'Download the %s', 'ai-eshop-optimizer' ), isset( $names[ $slug ] ) ? $names[ $slug ] : $slug ), array( 'variant' => 'ghost', 'size' => 'sm', 'icon' => 'download', 'href' => AIEO_One_Installer::download_link( $slug ), ) ); } $buttons .= \Rooster\Admin\Ui::button( __( 'Check for updates now', 'ai-eshop-optimizer' ), array( 'variant' => 'ghost', 'size' => 'sm', 'icon' => 'refresh-cw', 'href' => AIEO_One_Installer::update_check_link(), 'class' => 'aieo-is-check', 'attrs' => array( 'data-nonce' => wp_create_nonce( 'aieo_one_update_check' ), 'data-ajax' => admin_url( 'admin-ajax.php' ), 'data-busy' => __( 'Checking…', 'ai-eshop-optimizer' ), 'data-failed' => __( 'Could not check just now.', 'ai-eshop-optimizer' ), ), ) ); echo '
' . $buttons . '
'; echo ''; self::print_check_script(); } } add_action( 'activated_plugin', static function () { delete_transient( AIEO_Install_Status::TRANSIENT ); } ); add_action( 'deactivated_plugin', static function () { delete_transient( AIEO_Install_Status::TRANSIENT ); } );