__( 'Primary Navigation', 'videomaker' ), 'social' => __( 'Social Navigation', 'videomaker' ), 'footer' => __( 'Footer Navigation', 'videomaker' ) ) ); } add_action( 'after_setup_theme', 'videomaker_editor_styles' ); add_action( 'after_setup_theme', 'videomaker_trial_setup_on_wpcom' ); function videomaker_trial_setup_on_wpcom() { VideomakerTrialSetup::instance()->init(); } class VideomakerTrialSetup { /** * Caches trial eligibility for this http request cycle. * * @var bool|null */ private $is_trial_mode_cache = null; /** * The only instance of this class allowed. * * @var VideomakerTrialSetup */ private static $instance = null; private $done_init = false; public function __construct() { } private function is_trial_mode() { if ( null !== $this->is_trial_mode_cache ) { return $this->is_trial_mode_cache; } require_lib( 'videopress' ); $this->is_trial_mode_cache = (bool) VideoPress\videopress_hq_has_active_trial( get_current_blog_id() ); return $this->is_trial_mode_cache; } public static function instance() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } public function should_show_marketing_bar( $should_show ) { $is_trial_mode = $this->is_trial_mode(); if ( $is_trial_mode ) { $should_show = true; } return $should_show; } public function init() { if ( $this->done_init ) { return; } $this->done_init = true; add_filter( 'wpcom_launchpad_bar_should_show', '__return_false', 10, 1 ); add_filter( 'wpcom_marketing_bar_should_show', array( $this, 'should_show_marketing_bar' ), 10, 1 ); add_filter( 'wpcom_marketing_bar_cta_text_element_owner', array( $this, 'update_cta_text_element' ), 10, 2 ); add_filter( 'wpcom_marketing_bar_cta_button_element_text', array( $this, 'update_cta_button_text' ), 10, 2 ); } public function update_cta_text_element( $element, $owner ) { if ( $this->is_trial_mode() ) { $element = $this->get_trial_message( get_current_blog_id() ); } return $element; } private function get_trial_message( $blog_id ) { $video_count = max( intval( apply_filters( 'videopress_hq_trial_video_upload_limit', VideoPress\VIDEOPRESS_HQ_TRIAL_VIDEO_UPLOAD_LIMIT ) ) - VideoPress\get_video_count_for_site( $blog_id ), 0 ); $blog_age_in_days = round( get_blog_age_in_seconds( $blog_id ) / DAY_IN_SECONDS ); $trial_days_left = max( intval( apply_filters('videopress_hq_trial_limit_days', VideoPress\VIDEOPRESS_HQ_TRIAL_LIMIT_DAYS ) ) - $blog_age_in_days, 0 ); $trial_message = sprintf( /* translators: 1: Pluralized video count: "2 videos", 2: Pluralized day count: "2 days" */ __( '%1$s and %2$s remaining in trial. Upgrade to add more videos and publish your site!', 'videomaker' ), /* translators: Placeholder is a count of videos */ sprintf( _n( '%s video', '%s videos', $video_count ), number_format_i18n( $video_count ), 'videomaker' ), /* translators: Placeholder is a count of days */ sprintf( _n( '%s day', '%s days', $trial_days_left ), number_format_i18n( $trial_days_left ), 'videomaker' ) ); return $trial_message; } private function is_current_user_blog_owner() { if ( ! defined( 'IS_WPCOM' ) || ! IS_WPCOM ) { return false; } $owner = (int) wpcom_get_blog_owner( get_current_blog_id() ); return $owner && get_current_user_id() === $owner; } public function update_cta_button_text( $text, $owner ) { if ( $this->is_trial_mode() && $this->is_current_user_blog_owner() ) { $text = 'Upgrade'; } return $text; } }