Пример #1
0
 public function run()
 {
     $loaded_pages = 0;
     $urls = GRAV_TESTS::get_general_page_urls();
     $unique_errors = array();
     $errors = array();
     foreach ($urls as $url) {
         if ($contents = wp_remote_get(GRAV_TESTS::url_add_auth($url, $this->id), array('sslverify' => false, 'timeout' => 15))) {
             if (!empty($contents['body'])) {
                 preg_match_all('/(.+):(.+) in (\\/.+) on line ([0-9]+)/', $contents['body'], $matches);
                 if (!empty($matches[1]) && !empty($matches[2]) && !empty($matches[3]) && !empty($matches[4])) {
                     foreach ($matches[1] as $key => $error) {
                         $unique_errors[sanitize_title($matches[0][$key])] = array('message' => 'PHP ' . $matches[1][$key] . ' - ' . $matches[2][$key], 'location' => $matches[3][$key], 'line' => $matches[4][$key]);
                     }
                 }
             }
             if (strpos($contents['body'], '<html') !== false) {
                 $loaded_pages++;
             }
         }
     }
     if (!empty($unique_errors)) {
         foreach ($unique_errors as $key => $error) {
             $errors[] = $error;
         }
     }
     if (!empty($errors)) {
         return array('pass' => false, 'errors' => $errors, 'message' => 'There are (' . count($errors) . ') PHP Errors');
     }
     if (!$loaded_pages) {
         return array('pass' => null, 'message' => 'Error loading Pages');
     }
     return array('pass' => true, 'message' => 'No Errors found in (' . $loaded_pages . ') Pages');
 }
 public function run()
 {
     $header = file_get_contents(get_template_directory() . '/header.php');
     $has_head = false;
     if ($header) {
         $header = GRAV_TESTS::remove_comments($header);
     } else {
         return array('pass' => false, 'message' => 'Your Theme seems to be missing "header.php"', 'location' => '');
     }
     if (strpos($header, 'wp_head()') !== false || strpos($header, 'wp_head ()') !== false) {
         $has_head = true;
     } else {
         return array('pass' => false, 'message' => 'header.php is missing "wp_head();"', 'location' => get_template_directory() . '/header.php');
     }
     $footer = file_get_contents(get_template_directory() . '/footer.php');
     $has_footer = false;
     if ($footer) {
         $footer = GRAV_TESTS::remove_comments($footer);
     } else {
         return array('pass' => false, 'message' => 'Your Theme seems to be missing "footer.php"', 'location' => '');
     }
     if (strpos($footer, 'wp_footer()') !== false || strpos($footer, 'wp_footer ()') !== false) {
         $has_footer = true;
     } else {
         return array('pass' => false, 'message' => 'footer.php is missing "wp_footer();"', 'location' => get_template_directory() . '/footer.php');
     }
     if ($has_footer && $has_head) {
         return array('pass' => true, 'message' => 'Found both wp_head() and wp_footer()', 'location' => '');
     }
     return array('pass' => false, 'message' => 'Error finding wp_head() or wp_footer()', 'location' => '');
 }
 public function run()
 {
     if (GRAV_TESTS::guess_environment() === 'local') {
         return array('pass' => null, 'message' => 'Cannot Validate when using Localhost. Try on a valid Hostname.', 'location' => $item->url);
     }
     $urls = GRAV_TESTS::get_template_page_urls();
     $errors = array();
     $loaded_pages = 0;
     $total_score = 0;
     foreach ($urls as $url) {
         if ($response = wp_remote_get('https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=' . $url, array('sslverify' => false, 'timeout' => 30))) {
             if (!empty($response['body'])) {
                 $json = json_decode($response['body'], true);
                 if (!empty($json) && is_array($json) && !empty($json['ruleGroups']['SPEED']['score'])) {
                     $score = $json['ruleGroups']['SPEED']['score'];
                     if ($score > 0) {
                         $total_score += $score;
                         if ($score < 75) {
                             $errors[] = array('message' => 'Page Speed rating is (' . $score . '). <a target="_blank" href="https://developers.google.com/speed/pagespeed/insights/?url=' . $url . '">Learn More</a>', 'location' => $url);
                         }
                         $loaded_pages++;
                     }
                 }
             }
         }
     }
     if (!empty($errors)) {
         return array('pass' => false, 'errors' => $errors, 'message' => 'There were (' . count($errors) . ') pages that did not pass the Speed Test');
     }
     if (!$loaded_pages) {
         return array('pass' => null, 'message' => 'Unable to connect to Google Page Speed Insights API.');
     }
     return array('pass' => true, 'message' => 'Overall Page Speed rating is (' . round($total_score / $loaded_pages) . ').');
 }
Пример #4
0
 public function run()
 {
     if (GRAV_TESTS::guess_environment() === 'local') {
         return array('pass' => null, 'message' => 'Cannot Validate when using Localhost. Try on a valid Hostname.', 'location' => $item->url);
     }
     $loaded_pages = 0;
     $urls = GRAV_TESTS::get_general_page_urls();
     $errors = array();
     foreach ($urls as $url) {
         if ($contents = wp_remote_get('https://validator.w3.org/nu/?doc=' . $url, array('sslverify' => false, 'timeout' => 15))) {
             if (!empty($contents['body'])) {
                 if (strpos($contents['body'], '<div id="results">') === false) {
                     return array('pass' => null, 'message' => 'Error loading W3C Validator', 'location' => '');
                 }
                 if (strpos($contents['body'], '<li class="error">') !== false) {
                     $errors[] = array('message' => 'Page (' . $url . ') is not HTML Valid. <a target="_blank" href="' . 'https://validator.w3.org/nu/?doc=' . $url . '">Learn More</a>', 'location' => $url);
                 }
                 $loaded_pages++;
             }
         }
     }
     if (!$loaded_pages) {
         return array('pass' => null, 'message' => 'Error loading W3C Validator');
     }
     if (!empty($errors)) {
         return array('pass' => false, 'errors' => $errors, 'message' => 'There are (' . count($errors) . ') Pages with Errors');
     }
     return array('pass' => true, 'message' => 'Successfully Validated (' . $loaded_pages . ') Pages');
 }
Пример #5
0
 public function js_urls()
 {
     $urls = GRAV_TESTS::get_general_page_urls();
     $js_urls = array();
     foreach ($urls as $url) {
         $js_urls[] = array('url' => $url, 'with_admin_bar' => false, 'width' => 800, 'height' => 600);
     }
     return $js_urls;
 }
Пример #6
0
 public function can_fix()
 {
     if (GRAV_TESTS::is_editable()) {
         $path = $this->get_wp_config_path();
         if ($path && wp_is_writable($path)) {
             if ($contents = file_get_contents($path)) {
                 $contents = GRAV_TESTS::remove_comments($contents);
                 if (preg_match('/define[^;]*WP_DEBUG.*(true|TRUE)[^;]*/s', $contents, $matches)) {
                     return true;
                 }
             }
         }
     }
     return false;
 }
 public static function get_tests()
 {
     if (!empty(self::$tests)) {
         return self::$tests;
     }
     $grav_tests = array();
     foreach (glob(plugin_dir_path(__FILE__) . 'grav_tests/*.php') as $file) {
         $grav_test[] = $file;
     }
     $grav_test = apply_filters('grav_tests', $grav_test);
     $tests = array();
     foreach ($grav_test as $file) {
         if (file_exists($file)) {
             include_once $file;
             $classes = get_declared_classes();
             $test_class = end($classes);
             $test = new $test_class();
             $id = sanitize_title($test->label()) . '-' . dechex(crc32($file));
             if (strpos($file, '/gravitate-automated-tester/grav_tests/php_errors.php') !== false) {
                 $id = 'grav-test-php-errors';
             }
             $tests[$id] = array('id' => $id, 'type' => $test->type(), 'environment' => 'all', 'group' => $test->group(), 'can_run' => true, 'can_fix' => false, 'js_urls' => "''", 'file' => $file, 'class' => $test_class, 'label' => $test->label(), 'description' => $test->description(), 'fix_confirmation' => '');
             if ($test->type() === 'js' && method_exists($test, 'js_urls')) {
                 $tests[$id]['js_urls'] = stripslashes(json_encode($test->js_urls()));
             }
             if (method_exists($test, 'environment')) {
                 $tests[$id]['environment'] = $test->environment();
             }
             if (method_exists($test, 'can_run')) {
                 $tests[$id]['can_run'] = $test->can_run();
             }
             if (method_exists($test, 'can_fix') && method_exists($test, 'fix')) {
                 if ($test->can_fix()) {
                     $tests[$id]['can_fix'] = true;
                     if (method_exists($test, 'fix_confirmation')) {
                         $tests[$id]['fix_confirmation'] = $test->fix_confirmation();
                     }
                 }
             }
         }
     }
     ksort($tests);
     self::$tests = $tests;
     return self::$tests;
 }
 public function can_fix()
 {
     if (GRAV_TESTS::is_editable()) {
         $plugin_file = ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
         if (file_exists($plugin_file) && function_exists('activate_plugin')) {
             require_once $plugin_file;
             if (class_exists('Plugin_Upgrader') && method_exists('Plugin_Upgrader', 'upgrade')) {
                 return true;
             }
         }
     }
     return false;
 }