get_limitations()->visits->get_limit())) { return; } // end if; 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); } // end if; } // end maybe_lock_site; /** * 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() { if (is_main_site() && is_admin()) { return; // bail on main site. } // end if; $site = wu_get_current_site(); if ($site->get_type() !== 'customer_owned') { return; } // end if; $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'); } // end if; die('1'); } // end count_visits; /** * Enqueues the visits count script when necessary. * * @since 2.0.0 * @return void */ public function enqueue_visit_counter_script() { if (is_user_logged_in()) { return; // bail if user is logged in. } // end if; wp_register_script('wu-visits-counter', wu_get_asset('visits-counter.js', 'js'), array(), wu_get_version()); wp_localize_script('wu-visits-counter', 'wu_visits_counter', array( 'ajaxurl' => admin_url('admin-ajax.php'), 'code' => wp_create_nonce('wu-visit-counter'), )); wp_enqueue_script('wu-visits-counter'); } // end enqueue_visit_counter_script; } // end class Visits_Manager;