/**
 * Generates basic metadata for the head area.
 *
 */
function amt_add_basic_metadata_head($post, $attachments, $embedded_media, $options)
{
    $do_description = $options["auto_description"] == "1" ? true : false;
    $do_keywords = $options["auto_keywords"] == "1" ? true : false;
    $do_noodp_description = $options["noodp_description"] == "1" ? true : false;
    // Array to store metadata
    $metadata_arr = array();
    // Robots Meta Tag.
    $robots_content = '';
    if ($do_noodp_description && (is_front_page() || is_singular())) {
        // Add NOODP on posts and pages
        $robots_content = 'NOODP,NOYDIR';
        // Allow filtering of the robots meta tag content.
        $robots_content = apply_filters('amt_robots_data', $robots_content);
    }
    // Add a robots meta tag if its content is not empty.
    if (!empty($robots_content)) {
        $metadata_arr[] = '<meta name="robots" content="' . $robots_content . '" />';
    }
    // Default front page displaying latest posts
    if (amt_is_default_front_page()) {
        // Description and Keywords from the Add-Meta-Tags settings override
        // default behaviour.
        // Description
        if ($do_description) {
            // Use the site description from the Add-Meta-Tags settings.
            // Fall back to the blog description.
            $site_description = $options["site_description"];
            if (empty($site_description)) {
                // Alternatively, use the blog description
                // Here we sanitize the provided description for safety
                $site_description = sanitize_text_field(amt_sanitize_description(get_bloginfo('description')));
            }
            // If we have a description, use it in the description meta-tag of the front page
            if (!empty($site_description)) {
                // Note: Contains multipage information through amt_process_paged()
                $metadata_arr[] = '<meta name="description" content="' . esc_attr(amt_process_paged($site_description)) . '" />';
            }
        }
        // Keywords
        if ($do_keywords) {
            // Use the site keywords from the Add-Meta-Tags settings.
            // Fall back to the blog categories.
            $site_keywords = $options["site_keywords"];
            if (empty($site_keywords)) {
                // Alternatively, use the blog categories
                // Here we sanitize the provided keywords for safety
                $site_keywords = sanitize_text_field(amt_sanitize_keywords(amt_get_all_categories()));
            }
            // If we have keywords, use them in the keywords meta-tag of the front page
            if (!empty($site_keywords)) {
                $metadata_arr[] = '<meta name="keywords" content="' . esc_attr($site_keywords) . '" />';
            }
        }
        // Attachments
    } elseif (is_attachment()) {
        // has to be before is_singular() since is_singular() is true for attachments.
        // Description
        if ($do_description) {
            $description = amt_get_content_description($post, $auto = $do_description);
            if (!empty($description)) {
                // Note: Contains multipage information through amt_process_paged()
                $metadata_arr[] = '<meta name="description" content="' . esc_attr(amt_process_paged($description)) . '" />';
            }
        }
        // No keywords
        // Content pages and static pages used as "front page" and "posts page"
        // This also supports products via is_singular()
    } elseif (is_singular() || amt_is_static_front_page() || amt_is_static_home()) {
        // Description
        if ($do_description) {
            $description = amt_get_content_description($post, $auto = $do_description);
            if (!empty($description)) {
                // Note: Contains multipage information through amt_process_paged()
                $metadata_arr[] = '<meta name="description" content="' . esc_attr(amt_process_paged($description)) . '" />';
            }
        }
        // Keywords
        if ($do_keywords) {
            $keywords = amt_get_content_keywords($post, $auto = $do_keywords);
            if (!empty($keywords)) {
                $metadata_arr[] = '<meta name="keywords" content="' . esc_attr($keywords) . '" />';
                // Static Posts Index Page
                // If no keywords have been set in the metabox and this is the static page,
                // which displayes the latest posts, use the categories of the posts in the loop.
            } elseif (amt_is_static_home()) {
                // Here we sanitize the provided keywords for safety
                $cats_from_loop = sanitize_text_field(amt_sanitize_keywords(implode(', ', amt_get_categories_from_loop())));
                if (!empty($cats_from_loop)) {
                    $metadata_arr[] = '<meta name="keywords" content="' . esc_attr($cats_from_loop) . '" />';
                }
            }
        }
        // 'news_keywords'
        $newskeywords = amt_get_post_meta_newskeywords($post->ID);
        if (!empty($newskeywords)) {
            $metadata_arr[] = '<meta name="news_keywords" content="' . esc_attr($newskeywords) . '" />';
        }
        // per post full meta tags
        $full_metatags_for_content = amt_get_post_meta_full_metatags($post->ID);
        if (!empty($full_metatags_for_content)) {
            $metadata_arr[] = html_entity_decode(stripslashes($full_metatags_for_content));
        }
        // Category based archives
    } elseif (is_category()) {
        if ($do_description) {
            // If set, the description of the category is used in the 'description' metatag.
            // Otherwise, a generic description is used.
            // Here we sanitize the provided description for safety
            $description_content = sanitize_text_field(amt_sanitize_description(category_description()));
            // Note: Contains multipage information through amt_process_paged()
            if (empty($description_content)) {
                // Add a filtered generic description.
                $generic_description = apply_filters('amt_generic_description_category_archive', __('Content filed under the %s category.', 'add-meta-tags'));
                $generic_description = sprintf($generic_description, single_cat_title($prefix = '', $display = false));
                $metadata_arr[] = '<meta name="description" content="' . esc_attr(amt_process_paged($generic_description)) . '" />';
            } else {
                $metadata_arr[] = '<meta name="description" content="' . esc_attr(amt_process_paged($description_content)) . '" />';
            }
        }
        if ($do_keywords) {
            // The category name alone is included in the 'keywords' metatag
            // Here we sanitize the provided keywords for safety
            $cur_cat_name = sanitize_text_field(amt_sanitize_keywords(single_cat_title($prefix = '', $display = false)));
            if (!empty($cur_cat_name)) {
                $metadata_arr[] = '<meta name="keywords" content="' . esc_attr($cur_cat_name) . '" />';
            }
        }
    } elseif (is_tag()) {
        if ($do_description) {
            // If set, the description of the tag is used in the 'description' metatag.
            // Otherwise, a generic description is used.
            // Here we sanitize the provided description for safety
            $description_content = sanitize_text_field(amt_sanitize_description(tag_description()));
            // Note: Contains multipage information through amt_process_paged()
            if (empty($description_content)) {
                // Add a filtered generic description.
                $generic_description = apply_filters('amt_generic_description_tag_archive', __('Content tagged with %s.', 'add-meta-tags'));
                $generic_description = sprintf($generic_description, single_tag_title($prefix = '', $display = false));
                $metadata_arr[] = '<meta name="description" content="' . esc_attr(amt_process_paged($generic_description)) . '" />';
            } else {
                $metadata_arr[] = '<meta name="description" content="' . esc_attr(amt_process_paged($description_content)) . '" />';
            }
        }
        if ($do_keywords) {
            // The tag name alone is included in the 'keywords' metatag
            // Here we sanitize the provided keywords for safety
            $cur_tag_name = sanitize_text_field(amt_sanitize_keywords(single_tag_title($prefix = '', $display = false)));
            if (!empty($cur_tag_name)) {
                $metadata_arr[] = '<meta name="keywords" content="' . esc_attr($cur_tag_name) . '" />';
            }
        }
        // Custom taxonomies - Should be after is_category() and is_tag(), as it would catch those taxonomies as well.
        // This also supports product groups via is_tax(). Only product groups that are WordPress custom taxonomies are supported.
    } elseif (is_tax()) {
        // Taxonomy term object.
        // When viewing taxonomy archives, the $post object is the taxonomy term object. Check with: var_dump($post);
        $tax_term_object = $post;
        //var_dump($tax_term_object);
        if ($do_description) {
            // If set, the description of the custom taxonomy term is used in the 'description' metatag.
            // Otherwise, a generic description is used.
            // Here we sanitize the provided description for safety
            $description_content = sanitize_text_field(amt_sanitize_description(term_description($tax_term_object->term_id, $tax_term_object->taxonomy)));
            // Note: Contains multipage information through amt_process_paged()
            if (empty($description_content)) {
                // Add a filtered generic description.
                // Construct the filter name. Template: ``amt_generic_description_TAXONOMYSLUG_archive``
                $taxonomy_description_filter_name = sprintf('amt_generic_description_%s_archive', $tax_term_object->taxonomy);
                // var_dump($taxonomy_description_filter_name);
                $generic_description = apply_filters($taxonomy_description_filter_name, __('Content filed under the %s taxonomy.', 'add-meta-tags'));
                $generic_description = sprintf($generic_description, single_term_title($prefix = '', $display = false));
                $metadata_arr[] = '<meta name="description" content="' . esc_attr(amt_process_paged($generic_description)) . '" />';
            } else {
                $metadata_arr[] = '<meta name="description" content="' . esc_attr(amt_process_paged($description_content)) . '" />';
            }
        }
        if ($do_keywords) {
            // The taxonomy term name alone is included in the 'keywords' metatag.
            // Here we sanitize the provided keywords for safety.
            $cur_tax_term_name = sanitize_text_field(amt_sanitize_keywords(single_term_title($prefix = '', $display = false)));
            if (!empty($cur_tax_term_name)) {
                $metadata_arr[] = '<meta name="keywords" content="' . esc_attr($cur_tax_term_name) . '" />';
            }
        }
    } elseif (is_author()) {
        // Author object
        // NOTE: Inside the author archives `$post->post_author` does not contain the author object.
        // In this case the $post (get_queried_object()) contains the author object itself.
        // We also can get the author object with the following code. Slug is what WP uses to construct urls.
        // $author = get_user_by( 'slug', get_query_var( 'author_name' ) );
        // Also, ``get_the_author_meta('....', $author)`` returns nothing under author archives.
        // Access user meta with:  $author->description, $author->user_email, etc
        // $author = get_queried_object();
        $author = $post;
        // If a bio has been set in the user profile, use it in the description metatag of the
        // first page of the author archive *ONLY*. The other pages of the author archive use a generic description.
        // This happens because the 1st page of the author archive is considered the profile page
        // by the other metadata modules.
        // Otherwise use a generic meta tag.
        if ($do_description) {
            // Here we sanitize the provided description for safety
            $author_description = sanitize_text_field(amt_sanitize_description($author->description));
            if (empty($author_description) || is_paged()) {
                // Note: Contains multipage information through amt_process_paged()
                // Add a filtered generic description.
                $generic_description = apply_filters('amt_generic_description_author_archive', __('Content published by %s.', 'add-meta-tags'));
                $generic_description = sprintf($generic_description, $author->display_name);
                $metadata_arr[] = '<meta name="description" content="' . esc_attr(amt_process_paged($generic_description)) . '" />';
            } else {
                $metadata_arr[] = '<meta name="description" content="' . esc_attr($author_description) . '" />';
            }
        }
        // For the keywords metatag use the categories of the posts the author has written and are displayed in the current page.
        if ($do_keywords) {
            // Here we sanitize the provided keywords for safety
            $cats_from_loop = sanitize_text_field(amt_sanitize_keywords(implode(', ', amt_get_categories_from_loop())));
            if (!empty($cats_from_loop)) {
                $metadata_arr[] = '<meta name="keywords" content="' . esc_attr($cats_from_loop) . '" />';
            }
        }
    }
    // Add site wide meta tags
    if (!empty($options["site_wide_meta"])) {
        $metadata_arr[] = html_entity_decode(stripslashes($options["site_wide_meta"]));
    }
    // On every page print the copyright head link
    if (!empty($options["copyright_url"])) {
        $metadata_arr[] = '<link rel="copyright" type="text/html" title="' . esc_attr(get_bloginfo('name')) . ' Copyright Information" href="' . esc_url_raw($options["copyright_url"]) . '" />';
    }
    // Filtering of the generated basic metadata
    $metadata_arr = apply_filters('amt_basic_metadata_head', $metadata_arr);
    return $metadata_arr;
}
Example #2
0
function amt_inner_metadata_box($post)
{
    /* For future implementation. Basic code for tabs. */
    /*
    print('<br /><br />
        <div id="amt-metabox-tabs">
            <ul id="amt-metabox-tabs-list" class="category-tabs">
                <li><a href="#metadata-basic">Basic</a></li>
                <li><a href="#metadata-advanced">Advanced</a></li>
                <li><a href="#metadata-extra">Extra</a></li>
            </ul>
    
            <br class="clear" />
            <div id="metadata-basic">
                <p>#1 - basic</p>
            </div>
            <div class="hidden" id="metadata-advanced">
                <p>#2 - advanced</p>
            </div>
            <div class="hidden" id="metadata-extra">
                <p>#3 - extra</p>
            </div>
        </div>
        <br /><br />
    ');
    */
    // Use a nonce field for verification
    wp_nonce_field(plugin_basename(AMT_PLUGIN_FILE), 'amt_noncename');
    // Get the Metadata metabox permissions (filtered)
    $metabox_permissions = amt_get_metadata_metabox_permissions();
    // Get the post type. Will be used to customize the displayed notes.
    $post_type = get_post_type($post->ID);
    // Get the Add-Meta-Tags options.
    $options = get_option("add_meta_tags_opts");
    // Display the meta box HTML code.
    $metabox_has_features = false;
    // Custom description
    // Description box permission check (can be user customized via filter).
    if ($options['metabox_enable_description'] == '1' && current_user_can($metabox_permissions['description_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_description_value = amt_get_post_meta_description($post->ID);
        print '
            <p>
                <label for="amt_custom_description"><strong>' . __('Description', 'add-meta-tags') . '</strong>:</label>
                <textarea class="code" style="width: 99%" id="amt_custom_description" name="amt_custom_description" cols="30" rows="2" >' . esc_attr(stripslashes($custom_description_value)) . '</textarea>
                <br>
                ' . __('Enter a custom description of 30-50 words (based on an average word length of 5 characters).', 'add-meta-tags') . '
            </p>
        ';
        // Different notes based on post type
        if ($post_type == 'post') {
            print '
                <p>
                    ' . __('If the <em>description</em> field is left blank, a <em>description</em> meta tag will be <strong>automatically</strong> generated from the excerpt or, if an excerpt has not been set, directly from the first paragraph of the content.', 'add-meta-tags') . '
                </p>
            ';
        } elseif ($post_type == 'page') {
            print '
                <p>
                    ' . __('If the <em>description</em> field is left blank, a <em>description</em> meta tag will be <strong>automatically</strong> generated from the first paragraph of the content.', 'add-meta-tags') . '
                </p>
            ';
        } else {
            // Custom post types
            print '
                <p>
                    ' . __('If the <em>description</em> field is left blank, a <em>description</em> meta tag will be <strong>automatically</strong> generated from the first paragraph of the content.', 'add-meta-tags') . '
                </p>
            ';
        }
    }
    // Custom keywords
    // Keywords box permission check (can be user customized via filter).
    if ($options['metabox_enable_keywords'] == '1' && current_user_can($metabox_permissions['keywords_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_keywords_value = amt_get_post_meta_keywords($post->ID);
        // Alt input:  <input type="text" class="code" style="width: 99%" id="amt_custom_keywords" name="amt_custom_keywords" value="'.$custom_keywords_value.'" />
        print '
            <p>
                <label for="amt_custom_keywords"><strong>' . __('Keywords', 'add-meta-tags') . '</strong>:</label>
                <textarea class="code" style="width: 99%" id="amt_custom_keywords" name="amt_custom_keywords" cols="30" rows="2" >' . esc_attr(stripslashes($custom_keywords_value)) . '</textarea>
                <br>
                ' . __('Enter keywords separated with commas.', 'add-meta-tags') . '
            </p>
        ';
        // Different notes based on post type
        if ($post_type == 'post') {
            print '
                <p>
                    ' . __('If the <em>keywords</em> field is left blank, a <em>keywords</em> meta tag will be <strong>automatically</strong> generated from the post\'s categories, tags, custom taxonomy terms and from the global keywords, if any such global keywords have been set in the plugin settings. In case you decide to set a custom list of keywords for this post, it is possible to easily include the post\'s categories, tags and custom taxonomy terms in that list by using the special placeholders <code>%cats%</code>, <code>%tags%</code> and <code>%terms%</code> respectively.', 'add-meta-tags') . '
                    <br />
                    ' . __('Example', 'add-meta-tags') . ': <code>keyword1, keyword2, %cats%, keyword3, %tags%, keyword4</code>
                </p>
            ';
        } elseif ($post_type == 'page') {
            print '
                <p>
                    ' . __('If the <em>keywords</em> field is left blank, a <em>keywords</em> meta tag will only be automatically generated from global keywords, if any such global keywords have been set in the plugin settings.', 'add-meta-tags') . '
                </p>
            ';
        } else {
            // Custom post types
            print '
                <p>
                    ' . __('If the <em>keywords</em> field is left blank, a <em>keywords</em> meta tag will only be automatically generated from global keywords, if any such global keywords have been set in the plugin settings.', 'add-meta-tags') . '
                </p>
            ';
        }
    }
    // Advanced options
    // Custom title tag
    // Custom title box permission check (can be user customized via filter).
    if ($options['metabox_enable_title'] == '1' && current_user_can($metabox_permissions['title_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_title_value = amt_get_post_meta_title($post->ID);
        print '
            <p>
                <label for="amt_custom_title"><strong>' . __('Title', 'add-meta-tags') . '</strong>:</label>
                <input type="text" class="code" style="width: 99%" id="amt_custom_title" name="amt_custom_title" value="' . esc_attr(stripslashes($custom_title_value)) . '" />
                <br>
                ' . __('Enter a custom title to be used in the <em>title</em> HTML element of the page.', 'add-meta-tags') . '
            </p>
        ';
    }
    // 'news_keywords' meta tag
    // 'news_keywords' box permission check (can be user customized via filter).
    if ($options['metabox_enable_news_keywords'] == '1' && current_user_can($metabox_permissions['news_keywords_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_newskeywords_value = amt_get_post_meta_newskeywords($post->ID);
        print '
            <p>
                <label for="amt_custom_newskeywords"><strong>' . __('News Keywords', 'add-meta-tags') . '</strong>:</label>
                <input type="text" class="code" style="width: 99%" id="amt_custom_newskeywords" name="amt_custom_newskeywords" value="' . esc_attr(stripslashes($custom_newskeywords_value)) . '" />
                <br>
                ' . __('Enter a comma-delimited list of <strong>news keywords</strong>. For more info about this meta tag, please see this <a target="_blank" href="http://support.google.com/news/publisher/bin/answer.py?hl=en&answer=68297">Google help page</a>.', 'add-meta-tags') . '
            </p>
        ';
    }
    // per post full meta tags
    // Full meta tags box permission check (can be user customized via filter).
    if ($options['metabox_enable_full_metatags'] == '1' && current_user_can($metabox_permissions['full_metatags_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_full_metatags_value = amt_get_post_meta_full_metatags($post->ID);
        print '
            <p>
                <label for="amt_custom_full_metatags"><strong>' . __('Full meta tags', 'add-meta-tags') . '</strong>:</label>
                <textarea class="code" style="width: 99%" id="amt_custom_full_metatags" name="amt_custom_full_metatags" cols="30" rows="4" >' . stripslashes($custom_full_metatags_value) . '</textarea>
                <br>
                ' . __('Provide the full XHTML code of extra META elements you would like to add to this content (read more about the <a href="http://en.wikipedia.org/wiki/Meta_element" target="_blank">META HTML element</a> on Wikipedia).', 'add-meta-tags') . '
            </p>
            <p>
                ' . __('For example, to prevent a cached copy of this content from being available in search engine results, you can add the following metatag:', 'add-meta-tags') . '
                <br /><code>&lt;meta name="robots" content="noarchive" /&gt;</code>
            </p>

            <p>
                ' . __('Important note: for security reasons only <code>meta</code> elements are allowed in this box. All other HTML elements are automatically removed.', 'add-meta-tags') . '
            </p>
        ';
    }
    // Image URL (global override)
    // 'image_url' box permission check (can be user customized via filter).
    if ($options['metabox_enable_image_url'] == '1' && current_user_can($metabox_permissions['image_url_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_image_url_value = amt_get_post_meta_image_url($post->ID);
        print '
            <p>
                <label for="amt_custom_image_url"><strong>' . __('Image URL', 'add-meta-tags') . '</strong>:</label>
                <input type="text" class="code" style="width: 99%" id="amt_custom_image_url" name="amt_custom_image_url" value="' . esc_url_raw(stripslashes($custom_image_url_value)) . '" />
                <br>
                ' . __('Enter an image URL to override all media related meta tags.', 'add-meta-tags') . '
            </p>
        ';
    }
    // Content locale override
    // 'content_locale' box permission check (can be user customized via filter).
    if ($options['metabox_enable_content_locale'] == '1' && current_user_can($metabox_permissions['content_locale_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_content_locale_value = amt_get_post_meta_content_locale($post->ID);
        print '
            <p>
                <label for="amt_custom_content_locale"><strong>' . __('Content locale', 'add-meta-tags') . '</strong>:</label>
                <input type="text" class="code" style="width: 99%" id="amt_custom_content_locale" name="amt_custom_content_locale" value="' . esc_attr(stripslashes($custom_content_locale_value)) . '" />
                <br>
                ' . __('Override the default locale setting by entering a custom locale for this content in the form <code>language_TERRITORY</code>, for example: <code>en_US</code>.', 'add-meta-tags') . '
            </p>
        ';
    }
    // Express review
    // Express review box permission check (can be user customized via filter).
    if ($options['metabox_enable_express_review'] == '1' && current_user_can($metabox_permissions['express_review_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_express_review_value = amt_get_post_meta_express_review($post->ID);
        print '
            <p>
                <label for="amt_custom_express_review"><strong>' . __('Express review', 'add-meta-tags') . '</strong>:</label>
                <textarea class="code" style="width: 99%" id="amt_custom_express_review" name="amt_custom_express_review" cols="30" rows="2" >' . stripslashes($custom_express_review_value) . '</textarea>
                <br />
                ' . __('This field accepts special notation of review related information. If this info is provided in the correct form, then Add-Meta-Tags treats your content as being a review of an item and generates proper Schema.org metadata. This field must contain a <code>__</code> (double underscore) delimited list of the following information (all in one line): a rating, the name of a valid schema.org <a href="http://schema.org/Thing">Thing</a> derivative object, a title, and a URL. For instance:', 'add-meta-tags') . '
                <br />
                <code>4.2__Book__On the Origin of Species__http://en.wikipedia.org/wiki/On_the_Origin_of_Species</code>
            </p>
        ';
    }
    // List of URLs of items referenced in the post.
    // Referenced items box permission check (can be user customized via filter).
    if ($options['metabox_enable_referenced_list'] == '1' && current_user_can($metabox_permissions['referenced_list_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_referenced_list_value = amt_get_post_meta_referenced_list($post->ID);
        print '
            <p>
                <label for="amt_custom_referenced_list"><strong>' . __('URLs of referenced items', 'add-meta-tags') . '</strong>:</label>
                <textarea class="code" style="width: 99%" id="amt_custom_referenced_list" name="amt_custom_referenced_list" cols="30" rows="4" >' . stripslashes($custom_referenced_list_value) . '</textarea>
                <br>
                ' . __('Enter a list of canonical URLs (one per line) of items referenced in the content. The page referenced need not be on the same domain as the content. For example, you might reference a page where a product can be purchased or a page that further describes a place. If such references are provided and if OpenGraph/Schema.org metadata is enabled, then the relevant <code>og:referenced</code> and <code>referencedItem</code> meta tags will be generated.', 'add-meta-tags') . ' (<span style="color:red;">EXPERIMENTAL</span>)
            </p>
        ';
    }
    // If no features have been enabled, print an informative message
    if ($metabox_has_features === false) {
        print '
            <p>' . __(sprintf('No features have been enabled for this metabox in the Add-Meta-Tags <a href="%s">settings</a> or you do not have enough permissions to access the available features.', admin_url('options-general.php?page=add-meta-tags-options')), 'add-meta-tags') . '</p>
        ';
    } else {
        print '
            <p style="font-size: 85%; text-align: right; margin-top: 10px;">' . __(sprintf('Note: more features for this metabox might be available in the Add-Meta-Tags <a href="%s">settings</a>.', admin_url('options-general.php?page=add-meta-tags-options')), 'add-meta-tags') . '</p>
        ';
    }
}
function amt_inner_metadata_box($post)
{
    /* For future implementation. Basic code for tabs. */
    /*
    print('<br /><br />
        <div id="amt-metabox-tabs">
            <ul id="amt-metabox-tabs-list" class="category-tabs">
                <li><a href="#metadata-basic">Basic</a></li>
                <li><a href="#metadata-advanced">Advanced</a></li>
                <li><a href="#metadata-extra">Extra</a></li>
            </ul>
    
            <br class="clear" />
            <div id="metadata-basic">
                <p>#1 - basic</p>
            </div>
            <div class="hidden" id="metadata-advanced">
                <p>#2 - advanced</p>
            </div>
            <div class="hidden" id="metadata-extra">
                <p>#3 - extra</p>
            </div>
        </div>
        <br /><br />
    ');
    */
    // Use a nonce field for verification
    wp_nonce_field(plugin_basename(AMT_PLUGIN_FILE), 'amt_noncename');
    // Get the Metadata metabox permissions (filtered)
    $metabox_permissions = amt_get_metadata_metabox_permissions();
    // Get the post type. Will be used to customize the displayed notes.
    $post_type = get_post_type($post->ID);
    // Get the Add-Meta-Tags options.
    $options = get_option("add_meta_tags_opts");
    // Display the meta box HTML code.
    $metabox_has_features = false;
    print '
    <!-- #add-meta-tags-settings is required by the media selector -->
    <span id="add-meta-tags-settings">
    ';
    // Custom description
    // Description box permission check (can be user customized via filter).
    if ($options['metabox_enable_description'] == '1' && current_user_can($metabox_permissions['description_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_description_value = amt_get_post_meta_description($post->ID);
        print '
            <p>
                <label for="amt_custom_description"><strong>' . __('Description', 'add-meta-tags') . '</strong>:</label>
                <textarea class="code" style="width: 99%" id="amt_custom_description" name="amt_custom_description" cols="30" rows="2" >' . esc_attr(stripslashes($custom_description_value)) . '</textarea>
                <br>
                ' . __('Enter a custom description of 30-50 words (based on an average word length of 5 characters).', 'add-meta-tags') . '
            </p>
        ';
        // Different notes based on post type
        if ($post_type == 'post') {
            print '
                <p>
                    ' . __('If the <em>description</em> field is left blank, a <em>description</em> meta tag will be <strong>automatically</strong> generated from the excerpt or, if an excerpt has not been set, directly from the first paragraph of the content.', 'add-meta-tags') . '
                </p>
            ';
        } elseif ($post_type == 'page') {
            print '
                <p>
                    ' . __('If the <em>description</em> field is left blank, a <em>description</em> meta tag will be <strong>automatically</strong> generated from the first paragraph of the content.', 'add-meta-tags') . '
                </p>
            ';
        } else {
            // Custom post types
            print '
                <p>
                    ' . __('If the <em>description</em> field is left blank, a <em>description</em> meta tag will be <strong>automatically</strong> generated from the first paragraph of the content.', 'add-meta-tags') . '
                </p>
            ';
        }
        // Add warning about the automatic descriptions being turned off.
        if (!apply_filters('amt_generate_description_if_no_manual_data', true)) {
            print '
                <p>
                    <em>' . __('Warning: the automatic generation of descriptions has been turned off.', 'add-meta-tags') . '</em>
                </p>
            ';
        }
    }
    // Custom keywords
    // Keywords box permission check (can be user customized via filter).
    if ($options['metabox_enable_keywords'] == '1' && current_user_can($metabox_permissions['keywords_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_keywords_value = amt_get_post_meta_keywords($post->ID);
        // Alt input:  <input type="text" class="code" style="width: 99%" id="amt_custom_keywords" name="amt_custom_keywords" value="'.$custom_keywords_value.'" />
        print '
            <p>
                <label for="amt_custom_keywords"><strong>' . __('Keywords', 'add-meta-tags') . '</strong>:</label>
                <textarea class="code" style="width: 99%" id="amt_custom_keywords" name="amt_custom_keywords" cols="30" rows="2" >' . esc_attr(stripslashes($custom_keywords_value)) . '</textarea>
                <br>
                ' . __('Enter keywords separated with commas.', 'add-meta-tags') . '
            </p>
        ';
        // Different notes based on post type
        if ($post_type == 'post') {
            print '
                <p>
                    ' . __('If the <em>keywords</em> field is left blank, a <em>keywords</em> meta tag will be <strong>automatically</strong> generated from the post\'s categories, tags, custom taxonomy terms and from the global keywords, if any such global keywords have been set in the plugin settings. In case you decide to set a custom list of keywords for this post, it is possible to easily include the post\'s categories, tags and custom taxonomy terms in that list by using the special placeholders <code>%cats%</code>, <code>%tags%</code> and <code>%terms%</code> respectively.', 'add-meta-tags') . '
                    <br />
                    ' . __('Example', 'add-meta-tags') . ': <code>keyword1, keyword2, %cats%, keyword3, %tags%, keyword4</code>
                </p>
            ';
        } elseif ($post_type == 'page') {
            print '
                <p>
                    ' . __('If the <em>keywords</em> field is left blank, a <em>keywords</em> meta tag will only be automatically generated from global keywords, if any such global keywords have been set in the plugin settings.', 'add-meta-tags') . '
                </p>
            ';
        } else {
            // Custom post types
            print '
                <p>
                    ' . __('If the <em>keywords</em> field is left blank, a <em>keywords</em> meta tag will only be automatically generated from global keywords, if any such global keywords have been set in the plugin settings.', 'add-meta-tags') . '
                </p>
            ';
        }
        // Add warning about the automatic keywords being turned off.
        if (!apply_filters('amt_generate_keywords_if_no_manual_data', true)) {
            print '
                <p>
                    <em>' . __('Warning: the automatic generation of keywords has been turned off.', 'add-meta-tags') . '</em>
                </p>
            ';
        }
    }
    // Advanced options
    // Custom title tag
    // Custom title box permission check (can be user customized via filter).
    if ($options['metabox_enable_title'] == '1' && current_user_can($metabox_permissions['title_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_title_value = amt_get_post_meta_title($post->ID);
        print '
            <p>
                <label for="amt_custom_title"><strong>' . __('Title', 'add-meta-tags') . '</strong>:</label>
                <input type="text" class="code" style="width: 99%" id="amt_custom_title" name="amt_custom_title" value="' . esc_attr(stripslashes($custom_title_value)) . '" />
                <br>
                ' . __('Enter a custom title to be used in the <em>title</em> HTML element of the page.', 'add-meta-tags') . '
            </p>
            <p>
                ' . __('The <code>%title%</code> placeholder is automatically expanded to the current title of the content.', 'add-meta-tags') . '
            </p>
        ';
    }
    // 'news_keywords' meta tag
    // 'news_keywords' box permission check (can be user customized via filter).
    if ($options['metabox_enable_news_keywords'] == '1' && current_user_can($metabox_permissions['news_keywords_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_newskeywords_value = amt_get_post_meta_newskeywords($post->ID);
        print '
            <p>
                <label for="amt_custom_newskeywords"><strong>' . __('News Keywords', 'add-meta-tags') . '</strong>:</label>
                <input type="text" class="code" style="width: 99%" id="amt_custom_newskeywords" name="amt_custom_newskeywords" value="' . esc_attr(stripslashes($custom_newskeywords_value)) . '" />
                <br>
                ' . __('Enter a comma-delimited list of <strong>news keywords</strong>. For more info about this meta tag, please see this <a target="_blank" href="http://support.google.com/news/publisher/bin/answer.py?hl=en&answer=68297">Google help page</a>.', 'add-meta-tags') . '
            </p>
        ';
    }
    // per post full meta tags
    // Full meta tags box permission check (can be user customized via filter).
    if ($options['metabox_enable_full_metatags'] == '1' && current_user_can($metabox_permissions['full_metatags_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_full_metatags_value = amt_get_post_meta_full_metatags($post->ID);
        print '
            <p>
                <label for="amt_custom_full_metatags"><strong>' . __('Full meta tags', 'add-meta-tags') . '</strong>:</label>
                ' . amt_get_full_meta_tag_sets($custom_full_metatags_value) . '
                <textarea class="code" style="width: 99%" id="amt_custom_full_metatags" name="amt_custom_full_metatags" cols="30" rows="6" >' . stripslashes($custom_full_metatags_value) . '</textarea>
                <br />
                ' . __('Provide the full XHTML code of extra <a target="_blank" href="http://en.wikipedia.org/wiki/Meta_element" target="_blank"><code>meta</code></a> and <code>link</code> <a target="_blank" href="https://en.wikipedia.org/wiki/HTML_element">HTML elements</a> you would like to add to this content.', 'add-meta-tags') . '
                ' . __('For example, to prevent a cached copy of this content from being available in search engine results, you can add the following metatag:', 'add-meta-tags') . '
                <br /><br />
                <code>&lt;meta name="robots" content="noarchive" /&gt;</code>
            </p>

            <p>' . __('Moreover, the full meta tags box accepts the special notation <code>[field=Field Name]</code> which lets you use data from a Custom Field with name <em>Field Name</em>. This special notation may exist anywhere inside the meta tag. To automatically add paging information to URLs, append the <code>PAGEINFO</code> placeholder.', 'add-meta-tags') . '</p>

        ';
    }
    // Image URL (global override)
    // 'image_url' box permission check (can be user customized via filter).
    if ($options['metabox_enable_image_url'] == '1' && current_user_can($metabox_permissions['image_url_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_image_url_value = amt_get_post_meta_image_url($post->ID);
        print '
            <p>
                <label for="amt_custom_image_url"><strong>' . __('Image URL', 'add-meta-tags') . '</strong>:</label>
                <input type="text" class="code" style="width: 99%" id="amt_custom_image_url" name="amt_custom_image_url" value="' . amt_esc_id_or_url_notation(stripslashes($custom_image_url_value)) . '" />

                <span id="amt-image-selector-button" class="amt-image-selector-button wp-media-buttons-icon loadmediawindow button updatemeta button-small">' . __('Select image', 'add-meta-tags') . '</span>
                <br />

                ' . __('Enter an absolute image URL in order to enforce the use of this image in the metadata. To specify the image dimensions you can use the special notation <code>URL,WIDTHxHEIGHT</code>.', 'add-meta-tags') . '
                ' . __('Alternatively, you can select an image by pressing the <em>Select image</em> button.', 'add-meta-tags') . '
                ' . __('If this image is set, the plugin will not generate metadata for other media.', 'add-meta-tags') . '
            </p>

        ';
        // Image preview
        $image_data = amt_get_image_data(amt_esc_id_or_url_notation(stripslashes($custom_image_url_value)));
        $img_html = '';
        if (is_numeric($image_data['id'])) {
            $main_size_meta = wp_get_attachment_image_src($image_data['id'], 'medium');
            $img_html = '<img src="' . esc_url($main_size_meta[0]) . '" width="' . esc_attr($main_size_meta[1]) . '" height="' . esc_attr($main_size_meta[2]) . '" />';
        } elseif (!is_null($image_data['url'])) {
            $img_html = '<img src="' . esc_url($image_data['url']) . '" width="' . esc_attr($image_data['width']) . '" height="' . esc_attr($image_data['height']) . '" />';
        }
        if (!empty($img_html)) {
            print '
                <p>' . __('Image preview', 'add-meta-tags') . ':</p>
                <br />
                <div id="amt-image-preview" class="amt-image-preview">' . $img_html . '</div>
                ';
        }
    }
    // Content locale override
    // 'content_locale' box permission check (can be user customized via filter).
    if ($options['metabox_enable_content_locale'] == '1' && current_user_can($metabox_permissions['content_locale_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_content_locale_value = amt_get_post_meta_content_locale($post->ID);
        print '
            <p>
                <label for="amt_custom_content_locale"><strong>' . __('Content locale', 'add-meta-tags') . '</strong>:</label>
                <input type="text" class="code" style="width: 99%" id="amt_custom_content_locale" name="amt_custom_content_locale" value="' . esc_attr(stripslashes($custom_content_locale_value)) . '" />
                <br>
                ' . __('Override the default locale setting by entering a custom locale for this content in the form <code>language_TERRITORY</code>, for example: <code>en_US</code>.', 'add-meta-tags') . '
            </p>
        ';
    }
    // Express review
    // Express review box permission check (can be user customized via filter).
    if ($options['metabox_enable_express_review'] == '1' && current_user_can($metabox_permissions['express_review_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_express_review_value = amt_get_post_meta_express_review($post->ID);
        print '
            <p>
                <label for="amt_custom_express_review"><strong>' . __('Express review', 'add-meta-tags') . '</strong>:</label>
                ' . amt_get_sample_review_sets() . '
                <textarea class="code" style="width: 99%" id="amt_custom_express_review" name="amt_custom_express_review" cols="30" rows="12" >' . stripslashes($custom_express_review_value) . '</textarea>
                <br />
                ' . __('This field accepts review related information using INI file syntax. If this info is provided in the correct form, then Add-Meta-Tags treats your content as being a review of an item and generates proper Schema.org metadata. <a href="http://www.codetrax.org/projects/wp-add-meta-tags/wiki/Metadata_Generators_Key_Notes#Metadata-for-reviews" target="_blank">Read more</a> about the correct syntax of the review information.', 'add-meta-tags') . '
                <br />
            </p>
        ';
        // Add javascipt to fill textarea with sample review data.
        // CURRENTLY NOT USED
        print '
<script>
// To click on a link like:
// <a id="amt_fill_sample_review" href="#">Click here</a>
// and replace the textarea data.
jQuery(document).ready(function() {
    jQuery("#amt_fill_sample_review").click(function(event) {
        event.preventDefault();
        //jQuery("#amt_fill_sample_review").live(\'click\',function(e){
        var samplereview = "; Review rating (required)\\n\\
ratingValue = 4.2\\n\\
; Mandatory reviewed item properties (required)\\n\\
object = Book\\n\\
name = On the Origin of Species\\n\\
sameAs = http://en.wikipedia.org/wiki/On_the_Origin_of_Species\\n\\
; Extra reviewed item properties (optional)\\n\\
;isbn = 123456\\n\\
;[author]\\n\\
;object = Person\\n\\
;name = Charles Darwin\\n\\
;sameAs = https://en.wikipedia.org/wiki/Charles_Darwin";
        jQuery("#amt_custom_express_review").val(samplereview);
    });
});
</script>
        ';
    }
    // List of URLs of items referenced in the post.
    // Referenced items box permission check (can be user customized via filter).
    if ($options['metabox_enable_referenced_list'] == '1' && current_user_can($metabox_permissions['referenced_list_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_referenced_list_value = amt_get_post_meta_referenced_list($post->ID);
        print '
            <p>
                <label for="amt_custom_referenced_list"><strong>' . __('URLs of referenced items', 'add-meta-tags') . '</strong>:</label>
                <textarea class="code" style="width: 99%" id="amt_custom_referenced_list" name="amt_custom_referenced_list" cols="30" rows="4" >' . stripslashes($custom_referenced_list_value) . '</textarea>
                <br>
                ' . __('Enter a list of canonical URLs (one per line) of items referenced in the content. The page referenced need not be on the same domain as the content. For example, you might reference a page where a product can be purchased or a page that further describes a place. If such references are provided and if OpenGraph/Schema.org metadata is enabled, then the relevant <code>og:referenced</code> and <code>referencedItem</code> meta tags will be generated.', 'add-meta-tags') . ' (<span style="color:red;">' . __('Experimental feature', 'add-meta-tags') . '</span>)
            </p>
        ';
    }
    // If no features have been enabled, print an informative message
    if ($metabox_has_features === false) {
        print '
            <p>' . __(sprintf('No features have been enabled for this metabox in the Add-Meta-Tags <a href="%s">settings</a> or you do not have enough permissions to access the available features.', admin_url('options-general.php?page=add-meta-tags-options')), 'add-meta-tags') . '</p>
        ';
    } else {
        print '
            <p style="font-size: 85%; text-align: right; margin-top: 10px;">' . __(sprintf('Note: more features for this metabox might be available in the Add-Meta-Tags <a href="%s">settings</a>.', admin_url('options-general.php?page=add-meta-tags-options')), 'add-meta-tags') . '</p>
        ';
    }
    print '
    </span> <!-- #add-meta-tags-settings -->
    ';
}
Example #4
0
/**
 * Generates basic metadata for the head area.
 *
 */
function amt_add_basic_metadata_head($post, $attachments, $embedded_media, $options)
{
    if (apply_filters('amt_exclude_basic_metadata', false)) {
        return array();
    }
    $do_description = $options["auto_description"] == "1" ? true : false;
    $do_keywords = $options["auto_keywords"] == "1" ? true : false;
    $do_noodp_description = $options["noodp_description"] == "1" ? true : false;
    // Array to store metadata
    $metadata_arr = array();
    // Pre-processing
    // Store hreflang links in array
    $hreflang_links_arr = array();
    // Store base robots options
    $robots_options = array();
    if ($do_noodp_description && (is_front_page() || is_singular() || is_category() || is_tag() || is_tax() || is_author())) {
        // Add NOODP on posts and pages
        $robots_options[] = 'noodp';
        $robots_options[] = 'noydir';
    }
    // Store full meta tags (site wide and post specific)
    // Add site wide meta tags
    $full_metatags_as_string = '';
    if (!empty($options['site_wide_meta'])) {
        $full_metatags_for_site = html_entity_decode(stripslashes($options['site_wide_meta']));
        $full_metatags_as_string .= apply_filters('amt_full_metatags_site', $full_metatags_for_site);
        $full_metatags_as_string .= PHP_EOL;
    }
    // Full meta tags
    if (is_singular() || amt_is_static_front_page() || amt_is_static_home()) {
        // per post full meta tags
        $full_metatags_for_content = amt_get_post_meta_full_metatags($post->ID);
        $full_metatags_for_content = html_entity_decode(stripslashes($full_metatags_for_content));
        $full_metatags_as_string .= apply_filters('amt_full_metatags_post', $full_metatags_for_content);
    } elseif (is_category() || is_tag() || is_tax()) {
        // Term specific full meta tags ($post is a term object)
        $full_metatags_for_term = amt_get_term_meta_full_metatags($post->term_id);
        $full_metatags_for_term = html_entity_decode(stripslashes($full_metatags_for_term));
        $full_metatags_as_string .= apply_filters('amt_full_metatags_term', $full_metatags_for_term);
    } elseif (is_author()) {
        // User specific full meta tags ($post is a user object)
        $full_metatags_for_user = amt_get_user_meta_full_metatags($post->ID);
        $full_metatags_for_user = html_entity_decode(stripslashes($full_metatags_for_user));
        $full_metatags_as_string .= apply_filters('amt_full_metatags_term', $full_metatags_for_user);
    }
    // Sanitize
    //$full_metatags_as_string = esc_textarea( wp_kses( $full_metatags_as_string, amt_get_allowed_html_kses() ) );
    $full_metatags_as_string = wp_kses($full_metatags_as_string, amt_get_allowed_html_kses());
    // Make array of full meta tags
    $full_meta_tags = preg_split('#\\R#', $full_metatags_as_string, NULL, PREG_SPLIT_NO_EMPTY);
    // Process
    if (apply_filters('amt_full_metatags_processor_enable', true)) {
        // Store processed meta tags here
        $processed_full_meta_tags = array();
        // Field substitutions currently take place only on content pages.
        // TODO: See if this can be expanded to terms, authors.
        // Store the post's custom fields
        $custom_fields = null;
        // Store the post object's custom fields.
        //
        if (is_singular() || amt_is_static_front_page() || amt_is_static_home()) {
            // Get an array of all custom fields names of the post object.
            $custom_fields = get_post_custom_keys($post->ID);
        }
        // Iterate over full meta tags
        foreach ($full_meta_tags as $single_meta_tag) {
            // Note: Field value substitutions take place first, outside the elseif clauses.
            // Process substitutions of special notation with data from Custom Fields
            // Supported special notation:
            //   [field=Field Name]
            // Notes:
            // - 'Field Name' is the name of custom field.
            // - If the custom field with name 'Field Name' does not exist, the meta tag
            //   that contains it is omitted.
            // - If the value of the field is an empty string, then the substitution
            //   takes place normally.
            //
            // The regex pattern fo our special notation.
            $special_notation_pattern = '#(?:\\[field\\=)([^\\]]+)(?:\\])#';
            // The following covers content pages, as $custom_fields is only set on content pages. See above.
            if (!empty($custom_fields) && isset($post->ID)) {
                // This also assumes that we have a post object since custom fields
                // are set only on content pages, otherwise it is null.
                // Check for special notation
                if (preg_match($special_notation_pattern, $single_meta_tag, $matches)) {
                    //var_dump($matches);
                    // If the field name of the special notation does not match
                    // any custom field name, omit the meta tag as per the rules above.
                    if (!in_array($matches[1], $custom_fields)) {
                        continue;
                    }
                    // Since there is special notation and the field name from the special
                    // notation exists in the $custom_fields array, iterate over the available
                    // custom fields and perform the substitutions.
                    foreach ($custom_fields as $custom_field) {
                        // Check if it matches the field name of the special notation
                        if ($custom_field == $matches[1]) {
                            // Fetch the custom field's value
                            $field_value = get_post_meta($post->ID, $custom_field, true);
                            // Sanitize value
                            // TODO: this can be a problem depending on the value and the used sanitization function.
                            $field_value = esc_attr(sanitize_text_field($field_value));
                            // Perform the substitution even if the the value is an empty string as per the rules above
                            $single_meta_tag = str_replace(sprintf('[field=%s]', $custom_field), $field_value, $single_meta_tag);
                        }
                    }
                }
            } else {
                // In any other case, just remove the meta tags which contain the special notation.
                if (preg_match($special_notation_pattern, $single_meta_tag, $tmp)) {
                    continue;
                }
            }
            // Process the PAGEINFO variable.
            // If the current page is the 1st page of any archive or of multipage content,
            // PAGEINFO is just stripped. For subsequent pages of archives or multipage
            // content, PAGEINFO is replaced with page based path (page/N/ for archives or N/ for multipage content)
            //
            // For paginated archives or paginated main page with latest posts.
            $has_paging_info = false;
            if (is_paged()) {
                $paged = get_query_var('paged');
                // paged
                if ($paged && $paged >= 2) {
                    $single_meta_tag = str_replace('PAGEINFO', 'page/' . $paged . '/', $single_meta_tag);
                    $has_paging_info = true;
                }
                // For a Post or Page that has been divided into pages using the <!--nextpage--> QuickTag
            } else {
                $paged = get_query_var('page');
                // page
                if ($paged && $paged >= 2) {
                    $single_meta_tag = str_replace('PAGEINFO', $paged . '/', $single_meta_tag);
                    $has_paging_info = true;
                }
            }
            // If this is not paged, strip PAGEINFO
            if ($has_paging_info === false) {
                $single_meta_tag = str_replace('PAGEINFO', '', $single_meta_tag);
            }
            // Process custom canonical link
            // If a rel="canonical" meta tags exists, we deactivate WordPress' 'rel_canonical' action,
            // Since it is assumed that a custom canonical link has been added.
            //if ( preg_match( '# rel="canonical" #', $post_full_meta_tags, $tmp ) ) {
            if (strpos($single_meta_tag, ' rel="canonical" ') !== false) {
                // Remove default WordPress action
                remove_action('wp_head', 'rel_canonical');
            } elseif (strpos($single_meta_tag, ' name="robots" ') !== false) {
                if (preg_match('# content="([^"]+)" #', $single_meta_tag, $matches)) {
                    $tmp_robots_opts = explode(',', $matches[1]);
                    foreach ($tmp_robots_opts as $single_robots_option) {
                        $single_robots_option_cleaned = strtolower(trim($single_robots_option));
                        if (!empty($single_robots_option_cleaned)) {
                            $robots_options[] = $single_robots_option_cleaned;
                        }
                    }
                }
                // We simply collect options. Do not add any robots meta tags to the processed meta tags array.
                continue;
            } elseif (strpos($single_meta_tag, ' hreflang="') !== false) {
                // Simply add to the hreflang links array for later processing
                $hreflang_links_arr[] = $single_meta_tag;
                // We simply collect hreflang links for later processing. Do not add them to the processed meta tags array.
                continue;
            }
            // If we have reached here, add the meta tags to the array with processed meta tags.
            $processed_full_meta_tags[] = $single_meta_tag;
        }
    } else {
        // Full meta tags processor not enabled
        $processed_full_meta_tags = $full_meta_tags;
    }
    //var_dump($full_meta_tags);
    //var_dump($processed_full_meta_tags);
    // Add Meta Tags
    // Add a robots meta tag if robots options exist.
    // Backwards compatible filter. TODO: This is deprecated. Needs to be deleted after a while.
    $old_options_as_string = apply_filters('amt_robots_data', '');
    if (!empty($old_options_as_string)) {
        foreach (explode(',', $old_options_as_string) as $single_robots_option) {
            $single_robots_option_cleaned = strtolower(trim($single_robots_option));
            if (!empty($single_robots_option_cleaned)) {
                $robots_options[] = $single_robots_option_cleaned;
            }
        }
    }
    // Add robot_options filtering
    $robots_options = apply_filters('amt_robots_options', $robots_options);
    if (version_compare(PHP_VERSION, '5.3', '<')) {
        // The flag is not supported
        $robots_options = array_unique($robots_options);
    } else {
        $robots_options = array_unique($robots_options, SORT_STRING);
    }
    if (!empty($robots_options)) {
        $metadata_arr['basic:robots'] = '<meta name="robots" content="' . esc_attr(implode(',', $robots_options)) . '" />';
    }
    // Add full meta tags
    // Merge meta tags
    $processed_full_meta_tags = apply_filters('amt_full_metatags_processed', $processed_full_meta_tags);
    if (!empty($processed_full_meta_tags)) {
        $metadata_arr = array_merge($metadata_arr, $processed_full_meta_tags);
    }
    // Add copyright link
    // On every page print the copyright head link
    $copyright_url = amt_get_site_copyright_url($options);
    //if ( empty($copyright_url)) {
    //    $copyright_url = trailingslashit( get_bloginfo('url') );
    //}
    if (!empty($copyright_url)) {
        $metadata_arr['basic:copyright'] = '<link rel="copyright" type="text/html" title="' . esc_attr(get_bloginfo('name')) . ' ' . __('copyright information', 'add-meta-tags') . '" href="' . esc_url($copyright_url) . '" />';
    }
    // hreflang link element
    // This section also expects an array of extra hreflang links that may have
    // been collected from the full meta tags boxes.
    if ($options['generate_hreflang_links'] == '1') {
        if (is_singular()) {
            $locale = amt_get_language_content($options, $post);
            $hreflang = amt_get_the_hreflang($locale, $options);
            $hreflang_url = amt_get_permalink_for_multipage($post);
        } else {
            $locale = amt_get_language_site($options);
            $hreflang = amt_get_the_hreflang($locale, $options);
            $hreflang_url = '';
            if (amt_is_default_front_page()) {
                $hreflang_url = trailingslashit(get_bloginfo('url'));
            } elseif (is_category() || is_tag() || is_tax()) {
                // $post is a term object
                $hreflang_url = get_term_link($post);
            } elseif (is_author()) {
                // $post is an author object
                $hreflang_url = get_author_posts_url($post->ID);
            } elseif (is_year()) {
                $archive_year = get_the_time('Y');
                $hreflang_url = get_year_link($archive_year);
            } elseif (is_month()) {
                $archive_year = get_the_time('Y');
                $archive_month = get_the_time('m');
                $hreflang_url = get_month_link($archive_year, $archive_month);
            } elseif (is_day()) {
                $archive_year = get_the_time('Y');
                $archive_month = get_the_time('m');
                $archive_day = get_the_time('d');
                $hreflang_url = get_day_link($archive_year, $archive_month, $archive_day);
            }
            // If paged information is available
            if (is_paged()) {
                //$hreflang_url = trailingslashit( $hreflang_url ) . get_query_var('paged') . '/';
                $hreflang_url = get_pagenum_link(get_query_var('paged'));
            }
        }
        // hreflang links array
        $hreflang_arr = array();
        // Add link element
        if (!empty($hreflang) && !empty($hreflang_url)) {
            $hreflang_arr[] = '<link rel="alternate" hreflang="' . esc_attr($hreflang) . '" href="' . esc_url_raw($hreflang_url) . '" />';
        }
        // Add extra hreflang links that have been collected from the full meta tags boxes
        if (!empty($hreflang_links_arr)) {
            $hreflang_arr = array_merge($hreflang_arr, $hreflang_links_arr);
        }
        // Allow filtering of the hreflang array
        $hreflang_arr = apply_filters('amt_hreflang_links', $hreflang_arr);
        // Add to to metadata array
        foreach ($hreflang_arr as $hreflang_link) {
            if (preg_match('# hreflang="([^"]+)" #', $hreflang_link, $matches)) {
                $metadata_arr['basic:hreflang:' . $matches[1]] = $hreflang_link;
            }
        }
    }
    // Basic Meta Tags
    // Custom content override
    if (amt_is_custom($post, $options)) {
        // Return metadata with:
        // add_filter( 'amt_custom_metadata_basic', 'my_function', 10, 5 );
        // Return an array of meta tags. Array item format: ['key_can_be_whatever'] = '<meta name="foo" content="bar" />'
        $metadata_arr = apply_filters('amt_custom_metadata_basic', $metadata_arr, $post, $options, $attachments, $embedded_media);
        // Default front page displaying latest posts
    } elseif (amt_is_default_front_page()) {
        // Description and Keywords from the Add-Meta-Tags settings override
        // default behaviour.
        // Description
        if ($do_description) {
            // Use the site description from the Add-Meta-Tags settings.
            // Fall back to the blog description.
            $site_description = amt_get_site_description($options);
            if (empty($site_description)) {
                // Alternatively, use the blog description
                // Here we sanitize the provided description for safety
                $site_description = sanitize_text_field(amt_sanitize_description(get_bloginfo('description')));
            }
            // If we have a description, use it in the description meta-tag of the front page
            if (!empty($site_description)) {
                // Note: Contains multipage information through amt_process_paged()
                $metadata_arr['basic:description'] = '<meta name="description" content="' . esc_attr(amt_process_paged($site_description)) . '" />';
            }
        }
        // Keywords
        if ($do_keywords) {
            // Use the site keywords from the Add-Meta-Tags settings.
            // Fall back to the blog categories.
            $site_keywords = amt_get_site_keywords($options);
            if (empty($site_keywords)) {
                // Alternatively, use the blog categories
                // Here we sanitize the provided keywords for safety
                $site_keywords = sanitize_text_field(amt_sanitize_keywords(amt_get_all_categories()));
            }
            // If we have keywords, use them in the keywords meta-tag of the front page
            if (!empty($site_keywords)) {
                $metadata_arr['basic:keywords'] = '<meta name="keywords" content="' . esc_attr($site_keywords) . '" />';
            }
        }
        // Attachments
    } elseif (is_attachment()) {
        // has to be before is_singular() since is_singular() is true for attachments.
        // Description
        if ($do_description) {
            $description = amt_get_content_description($post, $auto = $do_description);
            if (!empty($description)) {
                // Note: Contains multipage information through amt_process_paged()
                $metadata_arr['basic:description'] = '<meta name="description" content="' . esc_attr(amt_process_paged($description)) . '" />';
            }
        }
        // No keywords
        // Content pages and static pages used as "front page" and "posts page"
        // This also supports products via is_singular()
    } elseif (is_singular() || amt_is_static_front_page() || amt_is_static_home()) {
        // Description
        if ($do_description) {
            $description = amt_get_content_description($post, $auto = $do_description);
            if (!empty($description)) {
                // Note: Contains multipage information through amt_process_paged()
                $metadata_arr['basic:description'] = '<meta name="description" content="' . esc_attr(amt_process_paged($description)) . '" />';
            }
        }
        // Keywords
        if ($do_keywords) {
            $keywords = amt_get_content_keywords($post, $auto = $do_keywords);
            if (!empty($keywords)) {
                $metadata_arr['basic:keywords'] = '<meta name="keywords" content="' . esc_attr($keywords) . '" />';
                // Static Posts Index Page
                // If no keywords have been set in the metabox and this is the static page,
                // which displayes the latest posts, use the categories of the posts in the loop.
            } elseif (amt_is_static_home()) {
                // Here we sanitize the provided keywords for safety
                $cats_from_loop = sanitize_text_field(amt_sanitize_keywords(implode(', ', amt_get_categories_from_loop())));
                if (!empty($cats_from_loop)) {
                    $metadata_arr['basic:keywords'] = '<meta name="keywords" content="' . esc_attr($cats_from_loop) . '" />';
                }
            }
        }
        // 'news_keywords'
        $newskeywords = amt_get_post_meta_newskeywords($post->ID);
        if (!empty($newskeywords)) {
            $metadata_arr['basic:news_keywords'] = '<meta name="news_keywords" content="' . esc_attr($newskeywords) . '" />';
        }
        // Category based archives
    } elseif (is_category()) {
        if ($do_description) {
            // If set, the description of the category is used in the 'description' metatag.
            // Otherwise, a generic description is used.
            // Here we sanitize the provided description for safety
            $description_content = sanitize_text_field(amt_sanitize_description(category_description()));
            // Note: Contains multipage information through amt_process_paged()
            if (empty($description_content)) {
                // Add a filtered generic description.
                $generic_description = apply_filters('amt_generic_description_category_archive', __('Content filed under the %s category.', 'add-meta-tags'));
                $generic_description = sprintf($generic_description, single_cat_title($prefix = '', $display = false));
                $metadata_arr['basic:description'] = '<meta name="description" content="' . esc_attr(amt_process_paged($generic_description)) . '" />';
            } else {
                $metadata_arr['basic:description'] = '<meta name="description" content="' . esc_attr(amt_process_paged($description_content)) . '" />';
            }
        }
        if ($do_keywords) {
            // The category name alone is included in the 'keywords' metatag
            // Here we sanitize the provided keywords for safety
            $cur_cat_name = sanitize_text_field(amt_sanitize_keywords(single_cat_title($prefix = '', $display = false)));
            if (!empty($cur_cat_name)) {
                $metadata_arr['basic:keywords'] = '<meta name="keywords" content="' . esc_attr($cur_cat_name) . '" />';
            }
        }
    } elseif (is_tag()) {
        if ($do_description) {
            // If set, the description of the tag is used in the 'description' metatag.
            // Otherwise, a generic description is used.
            // Here we sanitize the provided description for safety
            $description_content = sanitize_text_field(amt_sanitize_description(tag_description()));
            // Note: Contains multipage information through amt_process_paged()
            if (empty($description_content)) {
                // Add a filtered generic description.
                $generic_description = apply_filters('amt_generic_description_tag_archive', __('Content tagged with %s.', 'add-meta-tags'));
                $generic_description = sprintf($generic_description, single_tag_title($prefix = '', $display = false));
                $metadata_arr['basic:description'] = '<meta name="description" content="' . esc_attr(amt_process_paged($generic_description)) . '" />';
            } else {
                $metadata_arr['basic:description'] = '<meta name="description" content="' . esc_attr(amt_process_paged($description_content)) . '" />';
            }
        }
        if ($do_keywords) {
            // The tag name alone is included in the 'keywords' metatag
            // Here we sanitize the provided keywords for safety
            $cur_tag_name = sanitize_text_field(amt_sanitize_keywords(single_tag_title($prefix = '', $display = false)));
            if (!empty($cur_tag_name)) {
                $metadata_arr['basic:keywords'] = '<meta name="keywords" content="' . esc_attr($cur_tag_name) . '" />';
            }
        }
        // Custom taxonomies - Should be after is_category() and is_tag(), as it would catch those taxonomies as well.
        // This also supports product groups via is_tax(). Only product groups that are WordPress custom taxonomies are supported.
    } elseif (is_tax()) {
        // Taxonomy term object.
        // When viewing taxonomy archives, the $post object is the taxonomy term object. Check with: var_dump($post);
        $tax_term_object = $post;
        //var_dump($tax_term_object);
        if ($do_description) {
            // If set, the description of the custom taxonomy term is used in the 'description' metatag.
            // Otherwise, a generic description is used.
            // Here we sanitize the provided description for safety
            $description_content = sanitize_text_field(amt_sanitize_description(term_description($tax_term_object->term_id, $tax_term_object->taxonomy)));
            // Note: Contains multipage information through amt_process_paged()
            if (empty($description_content)) {
                // Add a filtered generic description.
                // Construct the filter name. Template: ``amt_generic_description_TAXONOMYSLUG_archive``
                $taxonomy_description_filter_name = sprintf('amt_generic_description_%s_archive', $tax_term_object->taxonomy);
                // var_dump($taxonomy_description_filter_name);
                $generic_description = apply_filters($taxonomy_description_filter_name, __('Content filed under the %s taxonomy.', 'add-meta-tags'));
                $generic_description = sprintf($generic_description, single_term_title($prefix = '', $display = false));
                $metadata_arr['basic:description'] = '<meta name="description" content="' . esc_attr(amt_process_paged($generic_description)) . '" />';
            } else {
                $metadata_arr['basic:description'] = '<meta name="description" content="' . esc_attr(amt_process_paged($description_content)) . '" />';
            }
        }
        if ($do_keywords) {
            // The taxonomy term name alone is included in the 'keywords' metatag.
            // Here we sanitize the provided keywords for safety.
            $cur_tax_term_name = sanitize_text_field(amt_sanitize_keywords(single_term_title($prefix = '', $display = false)));
            if (!empty($cur_tax_term_name)) {
                $metadata_arr['basic:keywords'] = '<meta name="keywords" content="' . esc_attr($cur_tax_term_name) . '" />';
            }
        }
    } elseif (is_author()) {
        // Author object
        // NOTE: Inside the author archives `$post->post_author` does not contain the author object.
        // In this case the $post (get_queried_object()) contains the author object itself.
        // We also can get the author object with the following code. Slug is what WP uses to construct urls.
        // $author = get_user_by( 'slug', get_query_var( 'author_name' ) );
        // Also, ``get_the_author_meta('....', $author)`` returns nothing under author archives.
        // Access user meta with:  $author->description, $author->user_email, etc
        // $author = get_queried_object();
        $author = $post;
        // If a bio has been set in the user profile, use it in the description metatag of the
        // first page of the author archive *ONLY*. The other pages of the author archive use a generic description.
        // This happens because the 1st page of the author archive is considered the profile page
        // by the other metadata modules.
        // Otherwise use a generic meta tag.
        if ($do_description) {
            // Here we sanitize the provided description for safety
            $author_description = sanitize_text_field(amt_sanitize_description($author->description));
            if (empty($author_description) || is_paged()) {
                // Note: Contains multipage information through amt_process_paged()
                // Add a filtered generic description.
                $generic_description = apply_filters('amt_generic_description_author_archive', __('Content published by %s.', 'add-meta-tags'));
                $generic_description = sprintf($generic_description, $author->display_name);
                $metadata_arr['basic:description'] = '<meta name="description" content="' . esc_attr(amt_process_paged($generic_description)) . '" />';
            } else {
                $metadata_arr['basic:description'] = '<meta name="description" content="' . esc_attr($author_description) . '" />';
            }
        }
        // For the keywords metatag use the categories of the posts the author has written and are displayed in the current page.
        if ($do_keywords) {
            // Here we sanitize the provided keywords for safety
            $cats_from_loop = sanitize_text_field(amt_sanitize_keywords(implode(', ', amt_get_categories_from_loop())));
            if (!empty($cats_from_loop)) {
                $metadata_arr['basic:keywords'] = '<meta name="keywords" content="' . esc_attr($cats_from_loop) . '" />';
            }
        }
        // Custom Post Type Archive
    } elseif (is_post_type_archive()) {
        // Custom post type object.
        // When viewing custom post type archives, the $post object is the custom post type object. Check with: var_dump($post);
        $post_type_object = $post;
        //var_dump($post_type_object);
        if ($do_description) {
            // Description
            // Note: Contains multipage information through amt_process_paged()
            // Add a filtered generic description.
            // Construct the filter name. Template: ``amt_generic_description_posttype_POSTTYPESLUG_archive``
            $custom_post_type_description_filter_name = sprintf('amt_generic_description_posttype_%s_archive', $post_type_object->name);
            // var_dump($custom_post_type_description_filter_name);
            // Generic description
            $generic_description = apply_filters($custom_post_type_description_filter_name, __('%s archive.', 'add-meta-tags'));
            // Final generic description
            $generic_description = sprintf($generic_description, post_type_archive_title($prefix = '', $display = false));
            $metadata_arr['basic:description'] = '<meta name="description" content="' . esc_attr(amt_process_paged($generic_description)) . '" />';
        }
        // For the keywords metatag use the categories of the posts that are listed in the current page.
        if ($do_keywords) {
            // Here we sanitize the provided keywords for safety
            $cats_from_loop = sanitize_text_field(amt_sanitize_keywords(implode(', ', amt_get_categories_from_loop())));
            if (!empty($cats_from_loop)) {
                $metadata_arr['basic:keywords'] = '<meta name="keywords" content="' . esc_attr($cats_from_loop) . '" />';
            }
        }
    }
    // Filtering of the generated basic metadata
    $metadata_arr = apply_filters('amt_basic_metadata_head', $metadata_arr);
    return $metadata_arr;
}