コード例 #1
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;
    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 -->
    ';
}
コード例 #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>
        ';
    }
}
コード例 #3
0
ファイル: amt-utils.php プロジェクト: ashenkar/sanga
function amt_get_review_data($post)
{
    // Get review information from custom field
    $data = amt_get_post_meta_express_review($post->ID);
    //
    // REVIEW_AMPERSAND_NOTE
    //
    // Note about conversion of ampersand:
    // Data is returned with & converted to &amp; by amt_get_post_meta_express_review().
    // This character mainly exists in sameAs URLs  (TODO: Find better replacement using preg_replace to spacifically target sameAs attributes)
    // The problem is that ';' is interpretted as a comment in the INI specification,
    // so parse_ini_string() strips part of the URL, which is wrong.
    // Here we convert &amp; to & and leave it as is in the generated review data.
    // To convert it back to &amp; after parse_ini_string() add something like:
    //     $value = str_replace('&', '&amp;', $value);
    // inside the foreach loop below.
    //
    //var_dump($data);
    $data = str_replace('&amp;', '&', $data);
    //var_dump($data);
    if (empty($data)) {
        return;
    }
    // Parse as INI
    $review_data_raw = parse_ini_string($data, true, INI_SCANNER_RAW);
    //var_dump($review_data_raw);
    // Check for mandatory properties
    if (!array_key_exists('ratingValue', $review_data_raw)) {
        return;
    } elseif (!array_key_exists('object', $review_data_raw)) {
        return;
    } elseif (!array_key_exists('name', $review_data_raw)) {
        return;
    } elseif (!array_key_exists('sameAs', $review_data_raw)) {
        return;
    }
    // Construct final review data array.
    // Extra properties are collected into ['extraprop'] sub array.
    $review_data = array();
    $review_data['extra'] = array();
    $mandatory_arr = array('ratingValue', 'object', 'name', 'sameAs');
    // Add extra properties
    foreach ($review_data_raw as $key => $value) {
        // Reverse the ampersand replacement. (see note above)
        $key = str_replace('&', '&amp;', $key);
        $value = str_replace('&', '&amp;', $value);
        if (in_array($key, $mandatory_arr)) {
            $review_data[$key] = $value;
        } else {
            $review_data['extra'][$key] = $value;
        }
    }
    //var_dump($review_data);
    return $review_data;
}
コード例 #4
0
ファイル: amt-utils.php プロジェクト: RomualdKarbido/Zeroom
function amt_get_review_data($post)
{
    // Get review information from custom field
    $data = amt_get_post_meta_express_review($post->ID);
    if (empty($data)) {
        return;
    }
    // Parse as INI
    $review_data_raw = parse_ini_string($data, true, INI_SCANNER_RAW);
    //var_dump($review_data_raw);
    // Check for mandatory properties
    if (!array_key_exists('ratingValue', $review_data_raw)) {
        return;
    } elseif (!array_key_exists('object', $review_data_raw)) {
        return;
    } elseif (!array_key_exists('name', $review_data_raw)) {
        return;
    } elseif (!array_key_exists('sameAs', $review_data_raw)) {
        return;
    }
    // Construct final review data array.
    // Extra properties are collected into ['extraprop'] sub array.
    $review_data = array();
    $review_data['extra'] = array();
    $mandatory_arr = array('ratingValue', 'object', 'name', 'sameAs');
    // Add extra properties
    foreach ($review_data_raw as $key => $value) {
        if (in_array($key, $mandatory_arr)) {
            $review_data[$key] = $value;
        } else {
            $review_data['extra'][$key] = $value;
        }
    }
    //var_dump($review_data);
    return $review_data;
}
コード例 #5
0
/**
 * Filter function that generates and embeds Schema.org metadata in the content.
 */
function amt_add_schemaorg_metadata_content_filter($post_body)
{
    if (is_feed()) {
        return $post_body;
    }
    if (!is_singular() || is_front_page()) {
        // is_front_page() is used for the case in which a static page is used as the front page.
        // In this filter function we only deal with content and attachments.
        return $post_body;
    }
    // Get the options the DB
    $options = get_option("add_meta_tags_opts");
    $do_auto_schemaorg = $options["auto_schemaorg"] == "1" ? true : false;
    if (!$do_auto_schemaorg) {
        return $post_body;
    }
    // Get current post object
    $post = get_queried_object();
    $metadata_arr = array();
    // Since this is a function that is hooked to the 'the_content' filter
    // of WordPress, the post type check has not run, so this happens here.
    // Check if metadata is supported on this content type.
    $post_type = get_post_type($post);
    if (!in_array($post_type, amt_get_supported_post_types())) {
        return $post_body;
    }
    // Get an array containing the attachments
    $attachments = amt_get_ordered_attachments($post);
    //var_dump($attachments);
    // Get an array containing the URLs of the embedded media
    $embedded_media = amt_get_embedded_media($post);
    //var_dump($embedded_media);
    // Products
    if (amt_is_product()) {
        // Scope BEGIN: Product: http://schema.org/Product
        $metadata_arr[] = '<!-- Scope BEGIN: Product -->';
        // Construct itemref attribute. Should contain a comma delimited list of IDs.
        $itemref = apply_filters('amt_schemaorg_itemref_product', '');
        if (!empty($itemref)) {
            $itemref_attrib = ' itemref="' . $itemref . '"';
        } else {
            $itemref_attrib = '';
        }
        $metadata_arr[] = '<div itemscope itemtype="http://schema.org/Product"' . $itemref_attrib . '>';
        // URL - Uses amt_get_permalink_for_multipage()
        $metadata_arr[] = '<meta itemprop="url" content="' . esc_url_raw(amt_get_permalink_for_multipage($post)) . '" />';
        // name
        // Note: Contains multipage information through amt_process_paged()
        $metadata_arr[] = '<meta itemprop="name" content="' . esc_attr(amt_process_paged(get_the_title($post->ID))) . '" />';
        // Description - We use the description defined by Add-Meta-Tags
        // Note: Contains multipage information through amt_process_paged()
        $content_desc = amt_get_content_description($post);
        if (empty($content_desc)) {
            // Use the post body as the description. Product objects do not support body text.
            $content_desc = sanitize_text_field(amt_sanitize_description($post_body));
        }
        if (!empty($content_desc)) {
            $metadata_arr[] = '<meta itemprop="description" content="' . esc_attr(amt_process_paged($content_desc)) . '" />';
        }
        // Dates
        $metadata_arr[] = '<meta itemprop="releaseDate" content="' . esc_attr(amt_iso8601_date($post->post_date)) . '" />';
        // Images
        // First check if a global image override URL has been entered.
        // If yes, use this image URL and override all other images.
        $global_image_override_url = amt_get_post_meta_image_url($post->ID);
        if (!empty($global_image_override_url)) {
            $metadata_arr[] = '<!-- Scope BEGIN: ImageObject -->';
            $metadata_arr[] = '<span itemprop="image" itemscope itemtype="http://schema.org/ImageObject">';
            $metadata_arr[] = '<meta itemprop="contentUrl" content="' . esc_url_raw($global_image_override_url) . '" />';
            $metadata_arr[] = '</span> <!-- Scope END: ImageObject -->';
            // Further image processing
        } else {
            // Set to true if any image attachments are found. Use to finally add the default image
            // if no image attachments have been found.
            $has_images = false;
            // Scope BEGIN: ImageObject: http://schema.org/ImageObject
            // Image - Featured image is checked first, so that it can be the first associated image.
            if (function_exists('has_post_thumbnail') && has_post_thumbnail($post->ID)) {
                // Get the image attachment object
                $image = get_post(get_post_thumbnail_id($post->ID));
                // metadata BEGIN
                $metadata_arr[] = '<!-- Scope BEGIN: ImageObject -->';
                $metadata_arr[] = '<span itemprop="image" itemscope itemtype="http://schema.org/ImageObject">';
                // Allow filtering of the image size.
                $image_size = apply_filters('amt_image_size_product', 'full');
                // Get image metatags.
                $metadata_arr = array_merge($metadata_arr, amt_get_schemaorg_image_metatags($image, $size = $image_size));
                // metadata END
                $metadata_arr[] = '</span> <!-- Scope END: ImageObject -->';
                // Images have been found.
                $has_images = true;
            }
            // Scope END: ImageObject
            // If no images have been found so far use the default image, if set.
            // Scope BEGIN: ImageObject: http://schema.org/ImageObject
            if ($has_images === false && !empty($options["default_image_url"])) {
                $metadata_arr[] = '<!-- Scope BEGIN: ImageObject -->';
                $metadata_arr[] = '<span itemprop="image" itemscope itemtype="http://schema.org/ImageObject">';
                $metadata_arr[] = '<meta itemprop="contentUrl" content="' . esc_url_raw($options["default_image_url"]) . '" />';
                $metadata_arr[] = '</span> <!-- Scope END: ImageObject -->';
            }
            // Scope END: ImageObject
        }
        // Extend the current metadata with properties of the Product object.
        // See: http://schema.org/Product
        $metadata_arr = apply_filters('amt_product_data_schemaorg', $metadata_arr, $post);
        // Scope END: Product
        $metadata_arr[] = '</div> <!-- Scope END: Product -->';
        // Filtering of the generated Schema.org metadata
        $metadata_arr = apply_filters('amt_schemaorg_metadata_product', $metadata_arr);
        // Add post body
        // Remove last closing '</div>' tag, add post body and re-add the closing div afterwards.
        $closing_product_tag = array_pop($metadata_arr);
        // Product objects do not support a 'text' itemprop. We just add a div for now
        // for consistency with Article objects.
        // TODO: it should allow filtering '<div>'
        $metadata_arr[] = '<div> <!-- Product text body: BEGIN -->';
        $metadata_arr[] = $post_body;
        $metadata_arr[] = '</div> <!-- Product text body: END -->';
        // Now add closing tag for Article
        $metadata_arr[] = $closing_product_tag;
        // Attachemnts
    } elseif (is_attachment()) {
        $mime_type = get_post_mime_type($post->ID);
        //$attachment_type = strstr( $mime_type, '/', true );
        // See why we do not use strstr(): http://www.codetrax.org/issues/1091
        $attachment_type = preg_replace('#\\/[^\\/]*$#', '', $mime_type);
        // Early metatags - Scope starts
        if ('image' == $attachment_type) {
            // Scope BEGIN: ImageObject: http://schema.org/ImageObject
            $metadata_arr[] = '<!-- Scope BEGIN: ImageObject -->';
            // Construct itemref attribute. Should contain a comma delimited list of IDs.
            $itemref = apply_filters('amt_schemaorg_itemref_attachment_image', '');
            if (!empty($itemref)) {
                $itemref_attrib = ' itemref="' . $itemref . '"';
            } else {
                $itemref_attrib = '';
            }
            $metadata_arr[] = '<div itemscope itemtype="http://schema.org/ImageObject"' . $itemref_attrib . '>';
        } elseif ('video' == $attachment_type) {
            // Scope BEGIN: VideoObject: http://schema.org/VideoObject
            $metadata_arr[] = '<!-- Scope BEGIN: VideoObject -->';
            // Construct itemref attribute. Should contain a comma delimited list of IDs.
            $itemref = apply_filters('amt_schemaorg_itemref_attachment_video', '');
            if (!empty($itemref)) {
                $itemref_attrib = ' itemref="' . $itemref . '"';
            } else {
                $itemref_attrib = '';
            }
            $metadata_arr[] = '<div itemscope itemtype="http://schema.org/VideoObject"' . $itemref_attrib . '>';
        } elseif ('audio' == $attachment_type) {
            // Scope BEGIN: AudioObject: http://schema.org/AudioObject
            $metadata_arr[] = '<!-- Scope BEGIN: AudioObject -->';
            // Construct itemref attribute. Should contain a comma delimited list of IDs.
            $itemref = apply_filters('amt_schemaorg_itemref_attachment_audio', '');
            if (!empty($itemref)) {
                $itemref_attrib = ' itemref="' . $itemref . '"';
            } else {
                $itemref_attrib = '';
            }
            $metadata_arr[] = '<div itemscope itemtype="http://schema.org/AudioObject"' . $itemref_attrib . '>';
        } else {
            // we do not currently support other attachment types, so we stop processing here
            return $post_body;
        }
        // Metadata commong to all attachments
        // Publisher
        // Scope BEGIN: Organization: http://schema.org/Organization
        $metadata_arr[] = '<!-- Scope BEGIN: Organization -->';
        $metadata_arr[] = '<span itemprop="publisher" itemscope itemtype="http://schema.org/Organization">';
        // Get publisher metatags
        $metadata_arr = array_merge($metadata_arr, amt_get_schemaorg_publisher_metatags($options, $post->post_author));
        // Scope END: Organization
        $metadata_arr[] = '</span> <!-- Scope END: Organization -->';
        // Author
        // Scope BEGIN: Person: http://schema.org/Person
        $metadata_arr[] = '<!-- Scope BEGIN: Person -->';
        $metadata_arr[] = '<span itemprop="author" itemscope itemtype="http://schema.org/Person">';
        // Get author metatags
        $metadata_arr = array_merge($metadata_arr, amt_get_schemaorg_author_metatags($post->post_author));
        // Scope END: Person
        $metadata_arr[] = '</span> <!-- Scope END: Person -->';
        // Dates
        $metadata_arr[] = '<meta itemprop="datePublished" content="' . esc_attr(amt_iso8601_date($post->post_date)) . '" />';
        $metadata_arr[] = '<meta itemprop="dateModified" content="' . esc_attr(amt_iso8601_date($post->post_modified)) . '" />';
        $metadata_arr[] = '<meta itemprop="copyrightYear" content="' . esc_attr(mysql2date('Y', $post->post_date)) . '" />';
        // Language
        $metadata_arr[] = '<meta itemprop="inLanguage" content="' . esc_attr(str_replace('-', '_', amt_get_language_content($options))) . '" />';
        // Metadata specific to each attachment type
        if ('image' == $attachment_type) {
            // Allow filtering of the image size.
            $image_size = apply_filters('amt_image_size_attachment', 'full');
            // Get image metatags. $post is an image object.
            $metadata_arr = array_merge($metadata_arr, amt_get_schemaorg_image_metatags($post, $size = $image_size, $is_representative = true));
            // Add the post body here
            $metadata_arr[] = $post_body;
            // Scope END: ImageObject
            $metadata_arr[] = '</div> <!-- Scope END: ImageObject -->';
        } elseif ('video' == $attachment_type) {
            // Video specific metatags
            // URL (for attachments: links to attachment page)
            $metadata_arr[] = '<meta itemprop="url" content="' . esc_url_raw(get_permalink($post->ID)) . '" />';
            $metadata_arr[] = '<meta itemprop="contentUrl" content="' . esc_url_raw(wp_get_attachment_url($post->ID)) . '" />';
            $metadata_arr[] = '<meta itemprop="encodingFormat" content="' . esc_attr($mime_type) . '" />';
            // Add the post body here
            $metadata_arr[] = $post_body;
            // Scope END: VideoObject
            $metadata_arr[] = '</div> <!-- Scope END: VideoObject -->';
        } elseif ('audio' == $attachment_type) {
            // Audio specific metatags
            // URL (for attachments: links to attachment page)
            $metadata_arr[] = '<meta itemprop="url" content="' . esc_url_raw(get_permalink($post->ID)) . '" />';
            $metadata_arr[] = '<meta itemprop="contentUrl" content="' . esc_url_raw(wp_get_attachment_url($post->ID)) . '" />';
            $metadata_arr[] = '<meta itemprop="encodingFormat" content="' . esc_attr($mime_type) . '" />';
            // Add the post body here
            $metadata_arr[] = $post_body;
            // Scope END: AudioObject
            $metadata_arr[] = '</div> <!-- Scope END: AudioObject -->';
        }
        // Content
    } else {
        // Set main metadata entity. By default this set to Article.
        $main_content_object = 'Article';
        // Check for Page
        // Main entity is set to WebPage on pages
        // DEV NOTE: Since many themes already set the WebPage itemscope on the
        // body element of the web page, set it to WebPage automatically would
        // result in duplicate entities. So this has to be done manually via
        // a filtering function.
        //        if  ( is_page() ) {
        //            $main_content_object = 'WebPage';
        //        }
        // Check for Review
        $express_review_field_data = amt_get_post_meta_express_review($post->ID);
        $review_data = array();
        if (!empty($express_review_field_data)) {
            $review_data = amt_get_review_data($express_review_field_data);
            if (!empty($review_data)) {
                $main_content_object = 'Review';
            }
        }
        // Allow filtering the main metadata object for content.
        $main_content_object = apply_filters('amt_schemaorg_object_main', $main_content_object);
        // Scope BEGIN: Article: http://schema.org/Article
        $metadata_arr[] = '<!-- Scope BEGIN: ' . esc_attr($main_content_object) . ' -->';
        // Construct itemref attribute. Should contain a comma delimited list of IDs.
        $itemref = apply_filters('amt_schemaorg_itemref_content', '');
        if (!empty($itemref)) {
            $itemref_attrib = ' itemref="' . $itemref . '"';
        } else {
            $itemref_attrib = '';
        }
        $metadata_arr[] = '<div itemscope itemtype="http://schema.org/' . esc_attr($main_content_object) . '"' . $itemref_attrib . '>';
        // Publisher
        // Scope BEGIN: Organization: http://schema.org/Organization
        $metadata_arr[] = '<!-- Scope BEGIN: Organization -->';
        $metadata_arr[] = '<span itemprop="publisher" itemscope itemtype="http://schema.org/Organization">';
        // Get publisher metatags
        $metadata_arr = array_merge($metadata_arr, amt_get_schemaorg_publisher_metatags($options, $post->post_author));
        // Scope END: Organization
        $metadata_arr[] = '</span> <!-- Scope END: Organization -->';
        // Author
        // Scope BEGIN: Person: http://schema.org/Person
        $metadata_arr[] = '<!-- Scope BEGIN: Person -->';
        $metadata_arr[] = '<span itemprop="author" itemscope itemtype="http://schema.org/Person">';
        // Get publisher metatags
        $metadata_arr = array_merge($metadata_arr, amt_get_schemaorg_author_metatags($post->post_author));
        // Scope END: Person
        $metadata_arr[] = '</span> <!-- Scope END: Person -->';
        // URL - Uses amt_get_permalink_for_multipage()
        $metadata_arr[] = '<meta itemprop="url" content="' . esc_url_raw(amt_get_permalink_for_multipage($post)) . '" />';
        // Dates
        $metadata_arr[] = '<meta itemprop="datePublished" content="' . esc_attr(amt_iso8601_date($post->post_date)) . '" />';
        $metadata_arr[] = '<meta itemprop="dateModified" content="' . esc_attr(amt_iso8601_date($post->post_modified)) . '" />';
        $metadata_arr[] = '<meta itemprop="copyrightYear" content="' . esc_attr(mysql2date('Y', $post->post_date)) . '" />';
        // Language
        $metadata_arr[] = '<meta itemprop="inLanguage" content="' . esc_attr(str_replace('-', '_', amt_get_language_content($options))) . '" />';
        // name
        // Note: Contains multipage information through amt_process_paged()
        $metadata_arr[] = '<meta itemprop="name" content="' . esc_attr(amt_process_paged(get_the_title($post->ID))) . '" />';
        // headline
        $metadata_arr[] = '<meta itemprop="headline" content="' . esc_attr(get_the_title($post->ID)) . '" />';
        // Description - We use the description defined by Add-Meta-Tags
        // Note: Contains multipage information through amt_process_paged()
        $content_desc = amt_get_content_description($post);
        if (!empty($content_desc)) {
            $metadata_arr[] = '<meta itemprop="description" content="' . esc_attr(amt_process_paged($content_desc)) . '" />';
        }
        /*
        // Section: We use the first category as the section
        $first_cat = sanitize_text_field( amt_sanitize_keywords( amt_get_first_category($post) ) );
        if (!empty($first_cat)) {
            $metadata_arr[] = '<meta itemprop="articleSection" content="' . esc_attr( $first_cat ) . '" />';
        }
        */
        // Add articleSection in Article object only.
        if ($main_content_object == 'Article') {
            $categories = get_the_category($post->ID);
            $categories = apply_filters('amt_post_categories_for_schemaorg', $categories);
            foreach ($categories as $cat) {
                $section = trim($cat->cat_name);
                if (!empty($section) && $cat->slug != 'uncategorized') {
                    $metadata_arr[] = '<meta itemprop="articleSection" content="' . esc_attr($section) . '" />';
                }
            }
        }
        // Add review properties if Review
        if ($main_content_object == 'Review') {
            $metadata_arr[] = '<!-- Review Information BEGIN -->';
            $metadata_arr[] = amt_get_review_info_box($review_data);
            $metadata_arr[] = '<!-- Review Information END -->';
        }
        // Keywords - We use the keywords defined by Add-Meta-Tags
        $keywords = amt_get_content_keywords($post);
        if (!empty($keywords)) {
            $metadata_arr[] = '<meta itemprop="keywords" content="' . esc_attr($keywords) . '" />';
        }
        // Referenced Items
        $referenced_url_list = amt_get_referenced_items($post);
        foreach ($referenced_url_list as $referenced_url) {
            $referenced_url = trim($referenced_url);
            if (!empty($referenced_url)) {
                $metadata_arr[] = '<meta itemprop="referencedItem" content="' . esc_url_raw($referenced_url) . '" />';
            }
        }
        // Images
        // First check if a global image override URL has been entered.
        // If yes, use this image URL and override all other images.
        $global_image_override_url = amt_get_post_meta_image_url($post->ID);
        if (!empty($global_image_override_url)) {
            $metadata_arr[] = '<!-- Scope BEGIN: ImageObject -->';
            $metadata_arr[] = '<span itemprop="image" itemscope itemtype="http://schema.org/ImageObject">';
            $metadata_arr[] = '<meta itemprop="contentUrl" content="' . esc_url_raw($global_image_override_url) . '" />';
            $metadata_arr[] = '</span> <!-- Scope END: ImageObject -->';
            // Further image processing
        } else {
            // We store the featured image ID in this variable so that it can easily be excluded
            // when all images are parsed from the $attachments array.
            $featured_image_id = 0;
            // Set to true if any image attachments are found. Use to finally add the default image
            // if no image attachments have been found.
            $has_images = false;
            // Scope BEGIN: ImageObject: http://schema.org/ImageObject
            // Image - Featured image is checked first, so that it can be the first associated image.
            if (function_exists('has_post_thumbnail') && has_post_thumbnail($post->ID)) {
                // Thumbnail URL
                // First add the thumbnail URL of the featured image
                $thumbnail_info = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'thumbnail');
                $metadata_arr[] = '<meta itemprop="thumbnailUrl" content="' . esc_url_raw($thumbnail_info[0]) . '" />';
                // Add full image object for featured image.
                // Get the image attachment object
                $image = get_post(get_post_thumbnail_id($post->ID));
                // metadata BEGIN
                $metadata_arr[] = '<!-- Scope BEGIN: ImageObject -->';
                $metadata_arr[] = '<span itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">';
                // Allow filtering of the image size.
                $image_size = apply_filters('amt_image_size_content', 'full');
                // Get image metatags.
                $metadata_arr = array_merge($metadata_arr, amt_get_schemaorg_image_metatags($image, $size = $image_size));
                // metadata END
                $metadata_arr[] = '</span> <!-- Scope END: ImageObject -->';
                // Finally, set the $featured_image_id
                $featured_image_id = get_post_thumbnail_id($post->ID);
                // Images have been found.
                $has_images = true;
            }
            // Scope END: ImageObject
            // Process all attachments and add metatags (featured image will be excluded)
            foreach ($attachments as $attachment) {
                // Excluded the featured image since
                if ($attachment->ID != $featured_image_id) {
                    $mime_type = get_post_mime_type($attachment->ID);
                    //$attachment_type = strstr( $mime_type, '/', true );
                    // See why we do not use strstr(): http://www.codetrax.org/issues/1091
                    $attachment_type = preg_replace('#\\/[^\\/]*$#', '', $mime_type);
                    if ('image' == $attachment_type) {
                        // metadata BEGIN
                        $metadata_arr[] = '<!-- Scope BEGIN: ImageObject -->';
                        $metadata_arr[] = '<span itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">';
                        // Allow filtering of the image size.
                        $image_size = apply_filters('amt_image_size_content', 'full');
                        // Get image metatags.
                        $metadata_arr = array_merge($metadata_arr, amt_get_schemaorg_image_metatags($attachment, $size = $image_size));
                        // metadata END
                        $metadata_arr[] = '</span> <!-- Scope END: ImageObject -->';
                        // Images have been found.
                        $has_images = true;
                    } elseif ('video' == $attachment_type) {
                        // Scope BEGIN: VideoObject: http://schema.org/VideoObject
                        $metadata_arr[] = '<!-- Scope BEGIN: VideoObject -->';
                        $metadata_arr[] = '<span itemprop="associatedMedia" itemscope itemtype="http://schema.org/VideoObject">';
                        // Video specific metatags
                        // URL (for attachments: links to attachment page)
                        $metadata_arr[] = '<meta itemprop="url" content="' . esc_url_raw(get_permalink($attachment->ID)) . '" />';
                        $metadata_arr[] = '<meta itemprop="contentUrl" content="' . esc_url_raw(wp_get_attachment_url($attachment->ID)) . '" />';
                        $metadata_arr[] = '<meta itemprop="encodingFormat" content="' . esc_attr($mime_type) . '" />';
                        // Scope END: VideoObject
                        $metadata_arr[] = '</span> <!-- Scope END: VideoObject -->';
                    } elseif ('audio' == $attachment_type) {
                        // Scope BEGIN: AudioObject: http://schema.org/AudioObject
                        $metadata_arr[] = '<!-- Scope BEGIN: AudioObject -->';
                        $metadata_arr[] = '<span itemprop="associatedMedia" itemscope itemtype="http://schema.org/AudioObject">';
                        // Audio specific metatags
                        // URL (for attachments: links to attachment page)
                        $metadata_arr[] = '<meta itemprop="url" content="' . esc_url_raw(get_permalink($attachment->ID)) . '" />';
                        $metadata_arr[] = '<meta itemprop="contentUrl" content="' . esc_url_raw(wp_get_attachment_url($attachment->ID)) . '" />';
                        $metadata_arr[] = '<meta itemprop="encodingFormat" content="' . esc_attr($mime_type) . '" />';
                        // Scope END: AudioObject
                        $metadata_arr[] = '</span> <!-- Scope END: AudioObject -->';
                    }
                }
            }
            // Embedded Media
            foreach ($embedded_media['images'] as $embedded_item) {
                // Scope BEGIN: ImageObject: http://schema.org/ImageObject
                $metadata_arr[] = '<!-- Scope BEGIN: ImageObject -->';
                $metadata_arr[] = '<span itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">';
                // name (title)
                $metadata_arr[] = '<meta itemprop="name" content="' . esc_attr($embedded_item['alt']) . '" />';
                // caption
                $metadata_arr[] = '<meta itemprop="caption" content="' . esc_attr($embedded_item['alt']) . '" />';
                // alt
                $metadata_arr[] = '<meta itemprop="text" content="' . esc_attr($embedded_item['alt']) . '" />';
                // URL (links to web page containing the image)
                $metadata_arr[] = '<meta itemprop="url" content="' . esc_url_raw($embedded_item['page']) . '" />';
                // thumbnail url
                $metadata_arr[] = '<meta itemprop="thumbnailUrl" content="' . esc_url_raw($embedded_item['thumbnail']) . '" />';
                // main image
                $metadata_arr[] = '<meta itemprop="contentUrl" content="' . esc_url_raw($embedded_item['image']) . '" />';
                if (apply_filters('amt_extended_image_tags', true)) {
                    $metadata_arr[] = '<meta itemprop="width" content="' . esc_attr($embedded_item['width']) . '" />';
                    $metadata_arr[] = '<meta itemprop="height" content="' . esc_attr($embedded_item['height']) . '" />';
                    $metadata_arr[] = '<meta itemprop="encodingFormat" content="image/jpeg" />';
                }
                // embedURL
                $metadata_arr[] = '<meta itemprop="embedURL" content="' . esc_url_raw($embedded_item['player']) . '" />';
                // Scope END: ImageObject
                $metadata_arr[] = '</span> <!-- Scope END: ImageObject -->';
                // Images have been found.
                $has_images = true;
            }
            foreach ($embedded_media['videos'] as $embedded_item) {
                // Scope BEGIN: VideoObject: http://schema.org/VideoObject
                // See: http://googlewebmastercentral.blogspot.gr/2012/02/using-schemaorg-markup-for-videos.html
                // See: https://support.google.com/webmasters/answer/2413309?hl=en
                $metadata_arr[] = '<!-- Scope BEGIN: VideoObject -->';
                $metadata_arr[] = '<span itemprop="video" itemscope itemtype="http://schema.org/VideoObject">';
                // Video Embed URL
                $metadata_arr[] = '<meta itemprop="embedURL" content="' . esc_url_raw($embedded_item['player']) . '" />';
                // playerType
                $metadata_arr[] = '<meta itemprop="playerType" content="application/x-shockwave-flash" />';
                // size
                $metadata_arr[] = '<meta itemprop="width" content="' . esc_attr($embedded_item['width']) . '" />';
                $metadata_arr[] = '<meta itemprop="height" content="' . esc_attr($embedded_item['height']) . '" />';
                // Scope END: VideoObject
                $metadata_arr[] = '</span> <!-- Scope END: VideoObject -->';
            }
            foreach ($embedded_media['sounds'] as $embedded_item) {
                // Scope BEGIN: AudioObject: http://schema.org/AudioObject
                $metadata_arr[] = '<!-- Scope BEGIN: AudioObject -->';
                $metadata_arr[] = '<span itemprop="audio" itemscope itemtype="http://schema.org/AudioObject">';
                // Audio Embed URL
                $metadata_arr[] = '<meta itemprop="embedURL" content="' . esc_url_raw($embedded_item['player']) . '" />';
                // playerType
                $metadata_arr[] = '<meta itemprop="playerType" content="application/x-shockwave-flash" />';
                // Scope END: AudioObject
                $metadata_arr[] = '</span> <!-- Scope END: AudioObject -->';
            }
            // If no images have been found so far use the default image, if set.
            // Scope BEGIN: ImageObject: http://schema.org/ImageObject
            if ($has_images === false && !empty($options["default_image_url"])) {
                $metadata_arr[] = '<!-- Scope BEGIN: ImageObject -->';
                $metadata_arr[] = '<span itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">';
                $metadata_arr[] = '<meta itemprop="contentUrl" content="' . esc_url_raw($options["default_image_url"]) . '" />';
                $metadata_arr[] = '</span> <!-- Scope END: ImageObject -->';
            }
            // Scope END: ImageObject
        }
        // Article Body
        // The article body is added after filtering the generated microdata below.
        // TODO: also check: comments, contributor, copyrightHolder, , creator, dateCreated, discussionUrl, editor, version (use post revision if possible)
        // Scope END: Article
        $metadata_arr[] = '</div> <!-- Scope END: ' . esc_attr($main_content_object) . ' -->';
        // Filtering of the generated Schema.org metadata
        $metadata_arr = apply_filters('amt_schemaorg_metadata_content', $metadata_arr);
        // Add articleBody to Artice
        // Now add the article. Remove last closing '</span>' tag, add articleBody and re-add the closing span afterwards.
        $closing_article_tag = array_pop($metadata_arr);
        // Use the 'text' itemprop by default for the main text body of the CreativeWork,
        // so it can be used by more subtypes than Article.
        // But set it explicitly to 'articleBody if the main entiry is 'Article'
        // or 'reviewBody' if the main entity is a 'Review'.
        $main_text_property = 'text';
        if ($main_content_object == 'Article') {
            $main_text_property = 'articleBody';
        } elseif ($main_content_object == 'Review') {
            $main_text_property = 'reviewBody';
        }
        // Allow filtering of the main text property.
        $main_text_property = apply_filters('amt_schemaorg_property_main_text', $main_text_property);
        $metadata_arr[] = '<div itemprop="' . esc_attr($main_text_property) . '">';
        $metadata_arr[] = $post_body;
        $metadata_arr[] = '</div> <!-- Itemprop END: ' . esc_attr($main_text_property) . ' -->';
        // Now add closing tag for Article
        $metadata_arr[] = $closing_article_tag;
    }
    // Add our comment
    if (count($metadata_arr) > 0) {
        array_unshift($metadata_arr, "<!-- BEGIN Schema.org microdata added by Add-Meta-Tags WordPress plugin -->");
        array_unshift($metadata_arr, "");
        // Intentionaly left empty
        array_push($metadata_arr, "<!-- END Schema.org microdata added by Add-Meta-Tags WordPress plugin -->");
        array_push($metadata_arr, "");
        // Intentionaly left empty
    }
    //return $post_body;
    return implode(PHP_EOL, $metadata_arr);
}