/** * Loads ingot if not already loaded. * * @since 0.0.5 */ public static function maybe_load() { if (did_action('ingot_loaded')) { return; } if (!defined('INGOT_DEV_MODE')) { /** * Puts Ingot into dev mode * * Don't use on a live site -- makes API totally open * * @since 0.0.5 */ define('INGOT_DEV_MODE', false); } $load = true; if (!version_compare(PHP_VERSION, '5.5.0', '>=')) { $load = false; } $autoloader = dirname(__FILE__) . '/vendor/autoload.php'; if (!file_exists($autoloader)) { $load = false; } if ($load) { include_once $autoloader; self::maybe_add_tables(); self::maybe_upgrade(); self::maybe_load_trial(); if (\ingot\testing\db\delta::check_if_tables_exist()) { ingot\testing\ingot::instance(); //make admin go in admin if (is_admin()) { new ingot\ui\make(); } if (ingot_is_front_end() || ingot_is_admin_ajax()) { //setup destination tests $destination_tests = \ingot\testing\tests\click\destination\init::set_tracking(); //run cookies add_action('ingot_loaded', function () { /** * Disable running cookies * * @since 1.1.0 * * @param bool $run */ if (true == (bool) apply_filters('ingot_run_cookies', true) && !did_action('ingot_cookies_set')) { if (!empty($destination_tests)) { \ingot\testing\tests\click\destination\init::setup_cookies($destination_tests); } \ingot\testing\cookies\set::run(); } }); } /** * Runs when Ingot has loaded. * * @since 0.0.5 */ do_action('ingot_loaded'); } else { if (is_admin()) { printf('<div class="error"><p>%s</p></div>', __('Ingot Not Loaded', 'ingot')); } /** * Runs if Ingot failed to load * * @since 0.3.0 * */ do_action('ingot_loaded_failed'); return; } } }
/** * Check if this is a front-end request * * @since 0.0.9 * * @return bool */ function ingot_is_front_end() { if (is_admin() || ingot_is_admin_ajax() || ingot_is_rest_api() || defined('DOING_CRON') && DOING_CRON || defined('XMLRPC_REQUEST') && XMLRPC_REQUEST) { return false; } return true; }
/** * Inititialize Ingot session * * @uses "parse_request" * * @since 0.3.0 */ public function init_session() { if (ingot_is_front_end() && !ingot_is_no_testing_mode() && !ingot_is_admin_ajax() && !is_admin() && !ingot_is_rest_api()) { $id = null; if (isset($_GET['ingot_session_ID']) && ingot_verify_session_nonce(helpers::v('ingot_session_nonce', $_GET, ''))) { $id = helpers::v('ingot_session_ID', $_GET, null); } $session = new \ingot\testing\object\session($id); $session_data = $session->get_session_info(); /** * Fired when Ingot session is setup at parse_request * * @since 0.3.0 * * @param array $session_data has ID (session ID) and ingot_ID */ do_action('ingot_session_initialized', $session_data); $this->current_session_data = $session_data; } }
/** * Check if this is a front-end request * * @since 0.0.9 * * @return bool */ function ingot_is_front_end() { if (is_admin() || ingot_is_admin_ajax() || ingot_is_rest_api() || defined('DOING_CRON') && DOING_CRON || defined('XMLRPC_REQUEST') && XMLRPC_REQUEST || isset($_REQUEST, $_REQUEST['action ']) && 'heartbeat' !== $_REQUEST['action']) { return false; } return true; }