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..56da848 --- /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 ); + + } + + $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; + + } + +}