get_limitations()->visits->get_limit())) { return; } if ($site->has_limitations() && $site->get_visits_count() > $site->get_limitations()->visits->get_limit()) { wp_die(__('This site is not available at this time.', 'wp-ultimo'), __('Not available', 'wp-ultimo'), 404); } } /** * Counts visits to network sites. * * This needs to be extremely light-weight. * The flow happens more or less like this: * 1. Gets the site current total; * 2. Adds one and re-save; * 3. Checks limits and see if we need to flush caches and such; * 4. Delegate these heavy tasks to action_scheduler. * * @since 2.0.0 * @return void */ public function count_visits(): void { if (is_main_site() && is_admin()) { return; // bail on main site. } $site = wu_get_current_site(); if ($site->get_type() !== 'customer_owned') { return; } $visits_manager = new \WP_Ultimo\Objects\Visits($site->get_id()); /* * Add a new visit. */ $visits_manager->add_visit(); /* * Checks against the limitations. */ if (false) { Cache_Manager::get_instance()->flush_known_caches(); echo 'flushing caches'; die('2'); } die('1'); } /** * Enqueues the visits count script when necessary. * * @since 2.0.0 * @return void */ public function enqueue_visit_counter_script(): void { if (is_user_logged_in()) { return; // bail if user is logged in. } wp_register_script('wu-visits-counter', wu_get_asset('visits-counter.js', 'js'), [], wu_get_version()); wp_localize_script( 'wu-visits-counter', 'wu_visits_counter', [ 'ajaxurl' => admin_url('admin-ajax.php'), 'code' => wp_create_nonce('wu-visit-counter'), ] ); wp_enqueue_script('wu-visits-counter'); } }