From 04d92005dde55100ba2fd85ca272c4486ec17839 Mon Sep 17 00:00:00 2001 From: bunty Date: Fri, 1 Dec 2017 10:04:16 +0530 Subject: [PATCH 1/2] Add check for meta tags --- doctor.yml | 2 + inc/checks/class-check-meta-tags.php | 68 ++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 inc/checks/class-check-meta-tags.php diff --git a/doctor.yml b/doctor.yml index bf8fbf9..767e4d1 100644 --- a/doctor.yml +++ b/doctor.yml @@ -42,3 +42,5 @@ php-in-upload: check: PHP_In_Upload language-update: check: Language_Update +meta-tags: + check: Check_Meta_Tags diff --git a/inc/checks/class-check-meta-tags.php b/inc/checks/class-check-meta-tags.php new file mode 100644 index 0000000..e1a1e5d --- /dev/null +++ b/inc/checks/class-check-meta-tags.php @@ -0,0 +1,68 @@ +]+(?:name|property)=\"([^\"]*)\"[^>]+content=\"([^\"]*)\"[^>]*>/"; + + public function run() { + + // Fetch homepage resposne. + $response = wp_remote_get(site_url()); + + if ( ! is_wp_error( $response ) ) { + + // Get the homepage source. + $body = wp_remote_retrieve_body( $response ); + + $meta_tags = $this->getMetaTags( $body ); + + } + error_log( print_r( $meta_tags, true ) ); + $this->set_status( 'success' ); + $this->set_message( 'Meta tags checking initiated.' ); + + } + + /** + * Extract all metatags sources from content + * + * @param string $content full body source of webpage. + * @return array, an array of extracted metatags + */ + + public function getMetaTags( $content = '' ) { + + $metatags = array(); + + if ( empty( $content ) ) { + return; + } + + preg_match_all( $this->metatags_expression, $content, $match_tags ); + + if ( isset( $match_tags[2] ) && count( $match_tags[2]) ) { + + foreach ( $match_tags[2] as $key => $match_tag ) { + + $key = trim( $match_tags[1][ $key ] ); + $match_tag = trim( $match_tag ); + + if ( $match_tag ) { + $metatags[] = array( $key, $match_tag ); + } + } + } + + return $metatags; + + } + +} From 43583430e831891e30a2cb3ff1948a2fe83c4668 Mon Sep 17 00:00:00 2001 From: bunty Date: Fri, 1 Dec 2017 22:27:39 +0530 Subject: [PATCH 2/2] Remove error log --- inc/checks/class-check-meta-tags.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/checks/class-check-meta-tags.php b/inc/checks/class-check-meta-tags.php index e1a1e5d..56da848 100644 --- a/inc/checks/class-check-meta-tags.php +++ b/inc/checks/class-check-meta-tags.php @@ -25,7 +25,7 @@ public function run() { $meta_tags = $this->getMetaTags( $body ); } - error_log( print_r( $meta_tags, true ) ); + $this->set_status( 'success' ); $this->set_message( 'Meta tags checking initiated.' );