function amt_add_schemaorg_metadata_comment_filter($comment_text) { global $post, $comment; $options = amt_get_options(); if ($options["omit_vendor_html_comments"] == "0") { $metadata_arr[] = '<!-- BEGIN Metadata added by the Add-Meta-Tags WordPress plugin -->'; } $metadata_arr[] = '<!-- Scope BEGIN: UserComments -->'; $metadata_arr[] = '<div itemprop="comment" itemscope itemtype="http://schema.org/UserComments">'; // Comment Author $metadata_arr[] = '<!-- Scope BEGIN: Person -->'; $metadata_arr[] = '<span itemprop="creator" itemscope itemtype="http://schema.org/Person"' . amt_get_schemaorg_itemref('person_commenter') . '>'; // name $metadata_arr[] = '<meta itemprop="name" content="' . esc_attr($comment->comment_author) . '" />'; // url if (!empty($comment->comment_author_url)) { // $metadata_arr[] = '<meta itemprop="url" content="' . esc_url( $comment->comment_author_url ) . '" />'; } // gravatar if (!empty($comment->comment_author_email)) { // Contruct gravatar link $gravatar_url = "http://www.gravatar.com/avatar/" . md5($comment->comment_author_email) . "?s=" . 44; $metadata_arr[] = '<meta itemprop="image" content="' . esc_url_raw($gravatar_url) . '" />'; } // END $metadata_arr[] = '</span> <!-- Scope END: Person -->'; $metadata_arr[] = '<meta itemprop="url" content="' . esc_url_raw(get_permalink($post->ID) . '#comment-' . get_comment_ID()) . '" />'; $metadata_arr[] = '<meta itemprop="commentTime" content="' . esc_attr(get_comment_time('c')) . '" />'; $metadata_arr[] = '<meta itemprop="replyToUrl" content="' . get_permalink($post->ID) . '?replytocom=' . $comment->comment_ID . '#respond' . '" />'; $metadata_arr[] = '<div itemprop="commentText">'; $metadata_arr[] = $comment_text; $metadata_arr[] = '</div> <!-- itemprop.commentText -->'; $metadata_arr[] = '</div> <!-- Scope END: UserComments -->'; if ($options["omit_vendor_html_comments"] == "0") { $metadata_arr[] = '<!-- END Metadata added by the Add-Meta-Tags WordPress plugin -->'; } // Allow filtering of the generated metadata $metadata_arr = apply_filters('amt_schemaorg_comments_extra', $metadata_arr, $post, $comment); return PHP_EOL . implode(PHP_EOL, $metadata_arr) . PHP_EOL . PHP_EOL; //return implode( '', $metadata_arr ); }
function amt_buddypress_schemaorg_footer($metadata_arr, $post, $options, $attachments, $embedded_media) { // User Profiles // Determines if a BuddyPress user profile has been requested if (bp_is_user_profile()) { // https://codex.buddypress.org/developer/the-bp-global/ global $bp; // $user_id = $bp->displayed_user->id; $user_id = bp_displayed_user_id(); // $user_domain = $bp->displayed_user->domain; // bp_core_get_user_domain( bp_displayed_user_id() ) $user_domain = bp_displayed_user_domain(); $user_profile_url = trailingslashit(bp_displayed_user_domain() . amt_bp_get_profile_slug()); $user_fullname = $bp->displayed_user->fullname; // $user_fullname = bp_displayed_user_fullname(); // $user_username = $bp->displayed_user->user_login; $user_username = bp_get_displayed_user_username(); //$wp_user_obj = get_user_by( 'id', $user_id ); $wp_user_obj = get_userdata($user_id); //var_dump($wp_user_obj); // Author // Scope BEGIN: Person: http://schema.org/Person $metadata_arr[] = '<!-- Scope BEGIN: Person -->'; $metadata_arr[] = '<span itemprop="author" itemscope itemtype="http://schema.org/Person"' . amt_get_schemaorg_itemref('person_author') . '>'; // name $metadata_arr[] = '<meta itemprop="name" content="' . esc_attr($user_fullname) . '" />'; // URL $metadata_arr[] = '<meta itemprop="url" content="' . esc_url($user_profile_url, array('http', 'https')) . '" />'; // mainEntityOfPage $metadata_arr[] = '<meta itemprop="mainEntityOfPage" content="' . esc_url($user_profile_url, array('http', 'https')) . '" />'; // Related resources as sameAs // Facebook Profile //$fb_author_url = get_the_author_meta('amt_facebook_author_profile_url', $user_id); $fb_author_url = get_user_meta($user_id, 'amt_facebook_author_profile_url', true); if (!empty($fb_author_url)) { $metadata_arr[] = '<meta itemprop="sameAs" content="' . esc_url($fb_author_url, array('http', 'https')) . '" />'; } // Twitter //$twitter_author_username = get_the_author_meta('amt_twitter_author_username', $user_id); $twitter_author_username = get_user_meta($user_id, 'amt_twitter_author_username', true); if (!empty($twitter_author_username)) { $metadata_arr[] = '<meta itemprop="sameAs" content="https://twitter.com/' . esc_attr($twitter_author_username) . '" />'; } // Google+ //$googleplus_author_url = get_the_author_meta('amt_googleplus_author_profile_url', $wp_user_obj); $googleplus_author_url = get_user_meta($user_id, 'amt_googleplus_author_profile_url', true); if (!empty($googleplus_author_url)) { $metadata_arr[] = '<meta itemprop="sameAs" content="' . esc_url($googleplus_author_url, array('http', 'https')) . '" />'; } // Determines if Extended Profiles component is active. if (!bp_is_active('xprofile')) { // Website //$website_url = get_user_meta($user_id, 'amt_googleplus_author_profile_url', true); $website_url = get_the_author_meta('user_url', $user_id); if (!empty($website_url)) { $metadata_arr[] = '<meta itemprop="sameAs" content="' . esc_url($website_url, array('http', 'https')) . '" />'; } // Description $author_description = sanitize_text_field(amt_sanitize_description($wp_user_obj->description)); if (empty($author_description)) { $metadata_arr[] = '<meta itemprop="description" content="' . esc_attr(__('Profile of', 'add-meta-tags') . ' ' . $wp_user_obj->display_name) . '" />'; } else { $metadata_arr[] = '<meta itemprop="description" content="' . esc_attr($author_description) . '" />'; } // Profile Image $author_email = sanitize_email($wp_user_obj->user_email); $avatar_size = apply_filters('amt_bp_avatar_size', array('width' => 50, 'height' => 50)); $avatar_url = ''; // First try to get the avatar link by using get_avatar(). // Important: for this to work the "Show Avatars" option should be enabled in Settings > Discussion. $avatar_img = get_avatar(get_the_author_meta('ID', $wp_user_obj->ID), $avatar_size, '', get_the_author_meta('display_name', $wp_user_obj->ID)); if (!empty($avatar_img)) { if (preg_match("#src=['\"]([^'\"]+)['\"]#", $avatar_img, $matches)) { $avatar_url = $matches[1]; } } elseif (!empty($author_email)) { // If the user has provided an email, we use it to construct a gravatar link. $avatar_url = "http://www.gravatar.com/avatar/" . md5($author_email) . "?s=" . $avatar_size; } if (!empty($avatar_url)) { //$avatar_url = html_entity_decode($avatar_url, ENT_NOQUOTES, 'UTF-8'); $metadata_arr[] = '<meta itemprop="image" content="' . esc_url_raw($avatar_url) . '" />'; } // familyName $last_name = $wp_user_obj->last_name; if (!empty($last_name)) { $metadata_arr[] = '<meta itemprop="familyName" content="' . esc_attr($last_name) . '" />'; } // givenName $first_name = $wp_user_obj->first_name; if (!empty($first_name)) { $metadata_arr[] = '<meta itemprop="givenName" content="' . esc_attr($first_name) . '" />'; } // Extended Profiles } else { // https://codex.buddypress.org/themes/guides/displaying-extended-profile-fields-on-member-profiles/ $xprofile_field_map = amt_buddypress_get_xprofile_field_map(); // Get list of IDs of public fields $xprofile_public_fields = bp_xprofile_get_fields_by_visibility_levels($user_id, array('public')); // Website $field_value = amt_bp_get_profile_field_data('website', $user_id, $xprofile_field_map, $xprofile_public_fields); $field_value = sanitize_text_field($field_value); if (!empty($field_value)) { $metadata_arr[] = '<meta itemprop="sameAs" content="' . esc_url($field_value, array('http', 'https')) . '" />'; } // Description $field_value = amt_bp_get_profile_field_data('description', $user_id, $xprofile_field_map, $xprofile_public_fields); $field_value = sanitize_text_field(amt_sanitize_description($field_value)); if (!empty($field_value)) { $metadata_arr[] = '<meta itemprop="description" content="' . esc_attr($field_value) . '" />'; } else { $metadata_arr[] = '<meta itemprop="description" content="' . esc_attr(__('Profile of', 'add-meta-tags') . ' ' . $user_fullname) . '" />'; } // Profile Image // Important: for this to work the "Show Avatars" option should be enabled in Settings > Discussion. $avatar_size = apply_filters('amt_bp_avatar_size', array('width' => 50, 'height' => 50)); $avatar_url = ''; $avatar_args = array('item_id' => $user_id, 'width' => $avatar_size['width'], 'height' => $avatar_size['height']); $avatar_img = bp_core_fetch_avatar($avatar_args); if (!empty($avatar_img)) { if (preg_match("#src=['\"]([^'\"]+)['\"]#", $avatar_img, $matches)) { $avatar_url = $matches[1]; } } if (!empty($avatar_url)) { //$avatar_url = html_entity_decode($avatar_url, ENT_NOQUOTES, 'UTF-8'); $metadata_arr[] = '<meta itemprop="image" content="' . esc_url_raw($avatar_url) . '" />'; } // familyName $has_last_name = false; $field_value = amt_bp_get_profile_field_data('last_name', $user_id, $xprofile_field_map, $xprofile_public_fields); $field_value = sanitize_text_field($field_value); if (!empty($field_value)) { $metadata_arr[] = '<meta itemprop="familyName" content="' . esc_attr($field_value) . '" />'; $has_last_name = true; } // givenName $has_first_name = false; $field_value = amt_bp_get_profile_field_data('first_name', $user_id, $xprofile_field_map, $xprofile_public_fields); $field_value = sanitize_text_field($field_value); if (!empty($field_value)) { $metadata_arr[] = '<meta itemprop="givenName" content="' . esc_attr($field_value) . '" />'; $has_first_name = true; } // Generate first and last name from full name if needed. if (!$has_last_name && !$has_first_name && !empty($user_fullname)) { $parts = explode(' ', $user_fullname); $last_name = sanitize_text_field(array_pop($parts)); // Removes and returns the element off the end of array if (!empty($last_name)) { $metadata_arr[] = '<meta itemprop="familyName" content="' . esc_attr($last_name) . '" />'; } $first_name = sanitize_text_field(implode(' ', $parts)); if (!empty($first_name)) { $metadata_arr[] = '<meta itemprop="givenName" content="' . esc_attr($first_name) . '" />'; } } // alternateName $field_value = amt_bp_get_profile_field_data('nickname', $user_id, $xprofile_field_map, $xprofile_public_fields); $field_value = sanitize_text_field($field_value); if (!empty($field_value)) { $metadata_arr[] = '<meta itemprop="alternateName" content="' . esc_attr($field_value) . '" />'; } // additionalName $field_value = amt_bp_get_profile_field_data('additional_name', $user_id, $xprofile_field_map, $xprofile_public_fields); $field_value = sanitize_text_field($field_value); if (!empty($field_value)) { $metadata_arr[] = '<meta itemprop="additionalName" content="' . esc_attr($field_value) . '" />'; } // honorificPrefix $field_value = amt_bp_get_profile_field_data('honorific_prefix', $user_id, $xprofile_field_map, $xprofile_public_fields); $field_value = sanitize_text_field($field_value); if (!empty($field_value)) { $metadata_arr[] = '<meta itemprop="honorificPrefix" content="' . esc_attr($field_value) . '" />'; } // honorificSuffix $field_value = amt_bp_get_profile_field_data('honorific_suffix', $user_id, $xprofile_field_map, $xprofile_public_fields); $field_value = sanitize_text_field($field_value); if (!empty($field_value)) { $metadata_arr[] = '<meta itemprop="honorificSuffix" content="' . esc_attr($field_value) . '" />'; } // gender $field_value = amt_bp_get_profile_field_data('gender', $user_id, $xprofile_field_map, $xprofile_public_fields); $field_value = sanitize_text_field($field_value); if (!empty($field_value)) { $metadata_arr[] = '<meta itemprop="gender" content="' . esc_attr($field_value) . '" />'; } // nationality $field_value = amt_bp_get_profile_field_data('nationality', $user_id, $xprofile_field_map, $xprofile_public_fields); $field_value = sanitize_text_field($field_value); if (!empty($field_value)) { $metadata_arr[] = '<!-- Scope BEGIN: Country -->'; $metadata_arr[] = '<span itemprop="nationality" itemscope itemtype="http://schema.org/Country">'; $metadata_arr[] = '<meta itemprop="name" content="' . esc_attr($field_value) . '" />'; $metadata_arr[] = '</span> <!-- Scope END: Country -->'; } // telephone $field_value = amt_bp_get_profile_field_data('telephone', $user_id, $xprofile_field_map, $xprofile_public_fields); $field_value = sanitize_text_field($field_value); if (!empty($field_value)) { $metadata_arr[] = '<meta itemprop="telephone" content="' . esc_attr($field_value) . '" />'; } // faxNumber $field_value = amt_bp_get_profile_field_data('fax', $user_id, $xprofile_field_map, $xprofile_public_fields); $field_value = sanitize_text_field($field_value); if (!empty($field_value)) { $metadata_arr[] = '<meta itemprop="faxNumber" content="' . esc_attr($field_value) . '" />'; } // email $field_value = amt_bp_get_profile_field_data('email', $user_id, $xprofile_field_map, $xprofile_public_fields); $field_value = sanitize_text_field($field_value); if (!empty($field_value)) { $metadata_arr[] = '<meta itemprop="email" content="' . esc_attr($field_value) . '" />'; } // jobTitle $field_value = amt_bp_get_profile_field_data('job_title', $user_id, $xprofile_field_map, $xprofile_public_fields); $field_value = sanitize_text_field($field_value); if (!empty($field_value)) { $metadata_arr[] = '<meta itemprop="jobTitle" content="' . esc_attr($field_value) . '" />'; } // worksFor $work_name = ''; $field_value = amt_bp_get_profile_field_data('works_for', $user_id, $xprofile_field_map, $xprofile_public_fields); $field_value = sanitize_text_field($field_value); if (!empty($field_value)) { $work_name = esc_attr($field_value); } // worksFor URL $work_url = ''; $field_value = amt_bp_get_profile_field_data('works_for_url', $user_id, $xprofile_field_map, $xprofile_public_fields); $field_value = sanitize_text_field($field_value); if (!empty($field_value)) { $work_url = esc_url($field_value); } if (!empty($work_name) || !empty($work_url)) { $metadata_arr[] = '<!-- Scope BEGIN: Organization -->'; $metadata_arr[] = '<span itemprop="worksFor" itemscope itemtype="http://schema.org/Organization">'; if (!empty($work_name)) { $metadata_arr[] = '<meta itemprop="name" content="' . esc_attr($work_name) . '" />'; } if (!empty($work_url)) { $metadata_arr[] = '<meta itemprop="url" content="' . esc_url($work_url) . '" />'; } $metadata_arr[] = '</span> <!-- Scope END: Organization -->'; } // Home Location Geo Coordinates // home latitude $latitude = ''; $field_value = amt_bp_get_profile_field_data('home_latitude', $user_id, $xprofile_field_map, $xprofile_public_fields); $field_value = sanitize_text_field($field_value); if (!empty($field_value)) { $latitude = esc_attr($field_value); } // home longitude $longitude = ''; $field_value = amt_bp_get_profile_field_data('home_longitude', $user_id, $xprofile_field_map, $xprofile_public_fields); $field_value = sanitize_text_field($field_value); if (!empty($field_value)) { $longitude = esc_attr($field_value); } if (!empty($latitude) && !empty($longitude)) { $metadata_arr[] = '<!-- Scope BEGIN: Place -->'; $metadata_arr[] = '<span itemprop="homeLocation" itemscope itemtype="http://schema.org/Place">'; $metadata_arr[] = '<meta itemprop="latitude" content="' . esc_attr($latitude) . '" />'; $metadata_arr[] = '<meta itemprop="longitude" content="' . esc_attr($longitude) . '" />'; $metadata_arr[] = '</span> <!-- Scope END: Place -->'; } // Work Location Geo Coordinates // work latitude $latitude = ''; $field_value = amt_bp_get_profile_field_data('work_latitude', $user_id, $xprofile_field_map, $xprofile_public_fields); $field_value = sanitize_text_field($field_value); if (!empty($field_value)) { $latitude = esc_attr($field_value); } // work longitude $longitude = ''; $field_value = amt_bp_get_profile_field_data('work_longitude', $user_id, $xprofile_field_map, $xprofile_public_fields); $field_value = sanitize_text_field($field_value); if (!empty($field_value)) { $longitude = esc_attr($field_value); } if (!empty($latitude) && !empty($longitude)) { $metadata_arr[] = '<!-- Scope BEGIN: Place -->'; $metadata_arr[] = '<span itemprop="workLocation" itemscope itemtype="http://schema.org/Place">'; $metadata_arr[] = '<meta itemprop="latitude" content="' . esc_attr($latitude) . '" />'; $metadata_arr[] = '<meta itemprop="longitude" content="' . esc_attr($longitude) . '" />'; $metadata_arr[] = '</span> <!-- Scope END: Place -->'; } } // Scope END: Person $metadata_arr[] = '</span> <!-- Scope END: Person -->'; } // Allow filtering of the generated metadata // Customize with: add_filter('amt_buddypress_schemaorg_footer_extra', 'my_function', 10, 5); $metadata_arr = apply_filters('amt_buddypress_schemaorg_footer_extra', $metadata_arr, $post, $options, $attachments, $embedded_media); return $metadata_arr; }