Пример #1
0
/**
 * Function that adds the help tabs for the options.
 */
function amt_options_page()
{
    // Permission Check
    if (!current_user_can('manage_options')) {
        wp_die(__('You do not have sufficient permissions to access this page.'));
    }
    // Default Add-Meta-Tags Settings
    $default_options = amt_get_default_options();
    if (isset($_POST['info_update'])) {
        // Save the Add-Meta-Tags settings
        amt_save_settings($_POST);
        // Also, since it may happen that the rewrite rules have not been flushed
        // this is a good place to do it.
        flush_rewrite_rules();
        // Also, clear the metadata cache automatically on every save.
        $result = amt_delete_all_transient_metadata_cache();
        if (intval($result) > 0) {
            amt_show_info_msg(sprintf(__('Deleted %d transient metadata cache entries.', 'add-meta-tags'), $result));
        }
    } elseif (isset($_POST["info_reset"])) {
        amt_reset_settings();
    }
    // Get the options from the DB.
    $options = get_option("add_meta_tags_opts");
    //var_dump($options);
    /*
    Configuration Page
    */
    print '
    <!-- #add-meta-tags-settings is required by the media selector -->
    <span id="add-meta-tags-settings">    
    ';
    print '
    <div class="wrap">
        <div id="icon-options-general" class="icon32"><br /></div>
        <h2>' . __('Metadata Settings', 'add-meta-tags') . '</h2>

        <p>' . __('Welcome to the administration panel of the Add-Meta-Tags plugin.', 'add-meta-tags') . '</p>

    </div>

    <div class="wrap amt-settings-notice">

        <!-- <h3>' . __('Notice', 'add-meta-tags') . '</h3> -->

        <p>' . __('Press the <code>Help</code> button on the top right corner for an introduction to metadata and also for detailed <strong>documentation</strong> about the available settings and the metadata generators. All help texts will gradually be moved to this integrated WordPress help system in order to reduce the size of this page and make it more user-friendly.', 'add-meta-tags') . '</p>

    </div>

    <!--
    <div class="wrap amt-settings-notice">

        <p>' . __('It is no longer possible to enter the URLs of the Publisher\'s social media profiles in the WordPress user profile page. Instead, this information should be entered in the relevant fields of the <strong>Publisher Settings</strong> section below.', 'add-meta-tags') . '</p>

    </div>
    -->

    <div class="wrap amt-settings-donations-msg" style="' . ($options["i_have_donated"] == "1" ? 'display: none;' : '') . '">

        <h3>' . __('Message from the author', 'add-meta-tags') . '</h3>

        <p><em>Add-Meta-Tags</em> is released under the terms of the <a href="http://www.apache.org/licenses/LICENSE-2.0.html">Apache License version 2</a> and, therefore, is <strong>Free software</strong>. It is actively maintained and supported free of charge since 2006.</p>

        <p>However, a significant amount of <strong>time</strong> and <strong>energy</strong> has been put into the development of this plugin, so, its production has not been free from cost. If you find this plugin useful and if it has helped your blog get indexed better and rank higher, I would appreciate an <a href="http://bit.ly/HvUakt">extra cup of coffee</a>.</p>
        <!--
        <p">Donations in BitCoin (BTC) are also accepted and welcome. Send the donated coin to the following address:</p>
        <ul>
            <li style="margin-left: 1em;">BitCoin (BTC): <code>1KkgpmaBKqQVk643VRhFRkL19Bbci4Mwn9</code></li>
        </ul>
        -->
        <p>Thank you in advance,<br />George Notaras</p>
        <div style="text-align: right;"><small>' . __('This message can be deactivated in the settings below.', 'add-meta-tags') . '</small></div>
    </div>

    <div class="wrap">
        <h2>' . __('Configuration', 'add-meta-tags') . '</h2>

        <p>' . __('This section contains global configuration options for the metadata that is added to your web site.', 'add-meta-tags') . '</p>

        <form name="formamt" method="post" action="' . admin_url('options-general.php?page=add-meta-tags-options') . '">

        <table class="form-table">
        <tbody>
    ';
    // General Settings
    if (amt_has_page_on_front()) {
        /* Options:
        
                    Example No pages
                    +-----------+----------------+--------------+----------+
                    | option_id | option_name    | option_value | autoload |
                    +-----------+----------------+--------------+----------+
                    |        58 | show_on_front  | posts        | yes      |
                    |        93 | page_for_posts | 0            | yes      |
                    |        94 | page_on_front  | 0            | yes      |
                    +-----------+----------------+--------------+----------+
        
                    Example pages as front page and posts page
                    +-----------+----------------+--------------+----------+
                    | option_id | option_name    | option_value | autoload |
                    +-----------+----------------+--------------+----------+
                    |        58 | show_on_front  | page         | yes      |
                    |        93 | page_for_posts | 28           | yes      |
                    |        94 | page_on_front  | 25           | yes      |
                    +-----------+----------------+--------------+----------+
        
                */
        print '
            <tr valign="top">
            <th scope="row">' . __('Front Page Metadata', 'add-meta-tags') . '</th>
            <td>
            <fieldset>
                <legend class="screen-reader-text"><span>' . __('Front Page Metadata', 'add-meta-tags') . '</span></legend>
                ' . __('It appears that you use static pages on the <em>front page</em> and the <em>latest posts page</em> of this web site. Please visit the editing panel of these pages and set the <code>description</code> and the <code>keywords</code> meta tags in the relevant Metadata box.', 'add-meta-tags') . '
                ';
        print '<ul>';
        $front_page_id = get_option('page_on_front');
        if (intval($front_page_id) > 0) {
            printf('<li>&raquo; ' . __('Edit the <a href="%s">front page</a>', 'add-meta-tags') . '</li>', get_edit_post_link(intval($front_page_id)));
        }
        $posts_page_id = get_option('page_for_posts');
        if (intval($posts_page_id) > 0) {
            printf('<li>&raquo; ' . __('Edit the <a href="%s">posts page</a>', 'add-meta-tags') . '</li>', get_edit_post_link(intval($posts_page_id)));
        }
        print '</ul>';
        print '
            </fieldset>
            </td>
            </tr>
        ';
    } else {
        print '
            <tr valign="top">
            <th scope="row">' . __('Front Page Description', 'add-meta-tags') . '</th>
            <td>
            <fieldset>
                <legend class="screen-reader-text"><span>' . __('Front Page Description', 'add-meta-tags') . '</span></legend>
                
                <textarea name="site_description" id="site_description" cols="100" rows="2" class="code">' . esc_attr(stripslashes(amt_get_site_description($options))) . '</textarea>
                <br />
                <label for="site_description">
                    ' . __('Enter a short description of your web site.', 'add-meta-tags') . '
                </label>
                <br />
            </fieldset>
            </td>
            </tr>

            <tr valign="top">
            <th scope="row">' . __('Front Page Keywords', 'add-meta-tags') . '</th>
            <td>
            <fieldset>
                <legend class="screen-reader-text"><span>' . __('Front Page Keywords', 'add-meta-tags') . '</span></legend>
                
                <textarea name="site_keywords" id="site_keywords" cols="100" rows="2" class="code">' . esc_attr(stripslashes(amt_get_site_keywords($options))) . '</textarea>
                <br />
                <label for="site_keywords">' . __('Enter a comma-delimited list of keywords for your web site.', 'add-meta-tags') . '</label>
                <br />
            </fieldset>
            </td>
            </tr>
        ';
    }
    print '
            <tr valign="top">
            <th scope="row">' . __('Global Keywords', 'add-meta-tags') . '</th>
            <td>
            <fieldset>
                <legend class="screen-reader-text"><span>' . __('Global Keywords', 'add-meta-tags') . '</span></legend>
                
                <textarea name="global_keywords" id="global_keywords" cols="100" rows="2" class="code">' . esc_attr(stripslashes(amt_get_site_global_keywords($options))) . '</textarea>
                <br />
                <label for="global_keywords">' . __('Enter a comma-delimited list of global keywords. Please consult the integrated help for more information.', 'add-meta-tags') . '</label>
                <br />
            </fieldset>
            </td>
            </tr>

            <tr valign="top">
            <th scope="row">' . __('Site-wide META tags', 'add-meta-tags') . '</th>
            <td>
            <fieldset>
                <legend class="screen-reader-text"><span>' . __('Site-wide META tags', 'add-meta-tags') . '</span></legend>

                <textarea name="site_wide_meta" id="site_wide_meta" cols="100" rows="10" class="code">' . stripslashes($options["site_wide_meta"]) . '</textarea>
                <br />
                <label for="site_wide_meta">
                ' . __('Enter complete <a href="http://en.wikipedia.org/wiki/Meta_element" target="_blank">meta tags</a> which will appear on all web pages.', 'add-meta-tags') . '
                ' . __('Please, do not enter keywords here.', 'add-meta-tags') . '
                </label>
                <br />
            </fieldset>
            </td>
            </tr>

    ';
    // Publisher Settings
    print '
            <tr valign="top">
            <th scope="row">' . __('Publisher Settings', 'add-meta-tags') . '</th>
            <td>
            <fieldset>
                <legend class="screen-reader-text"><span>' . __('Publisher Settings', 'add-meta-tags') . '</span></legend>

                <p>' . __('This section contains options related to your web site; the publisher of the content.', 'add-meta-tags') . '</p>
                <p>' . __('The following publisher related settings are shared among all users. Filling in these settings is entirely optional.', 'add-meta-tags') . '</p>

                <h4>' . __('Facebook publisher profile URL', 'add-meta-tags') . ':</h4>

                <input name="social_main_facebook_publisher_profile_url" type="text" id="social_main_facebook_publisher_profile_url" class="code" value="' . esc_url_raw(stripslashes($options["social_main_facebook_publisher_profile_url"])) . '" size="100" maxlength="1024" />
                <br />
                <label for="social_main_facebook_publisher_profile_url">
                ' . __('Enter an absolute URL to the Facebook profile of the publisher. If this is filled in, it will be used in the <code>article:publisher</code> meta tag.', 'add-meta-tags') . '
                </label>
                <p><strong>' . __('Example', 'add-meta-tags') . '</strong>: <code>https://www.facebook.com/awesome.editors</code></p>
                <br />

                <!-- We currently let users add the full meta tags for fb:app_id and fb:admins in the site wide meta tags box.

                <h4>' . __('Facebook App ID', 'add-meta-tags') . ':</h4>

                <input name="social_main_facebook_app_id" type="text" id="social_main_facebook_app_id" class="code" value=" . esc_url_raw( stripslashes( $options["social_main_facebook_app_id"] ) ) . " size="100" maxlength="1024" />
                <br />
                <label for="social_main_facebook_app_id">
                ' . __('Enter the App ID for <a target="_blank" href="https://developers.facebook.com/docs/platforminsights">Facebook Insights</a>.', 'add-meta-tags') . '
                </label>
                <p><strong>' . __('Example', 'add-meta-tags') . '</strong>: <code>1234567890</code></p>
                <br />

                <h4>' . __('Facebook Admin ID list', 'add-meta-tags') . ':</h4>

                <input name="social_main_facebook_admins" type="text" id="social_main_facebook_admins" class="code" value=" . esc_url_raw( stripslashes( $options["social_main_facebook_admins"] ) ) . " size="100" maxlength="1024" />
                <br />
                <label for="social_main_facebook_admins">
                ' . __('Enter a comma delimited list of numerical Facebook user IDs which will have access to <a target="_blank" href="https://developers.facebook.com/docs/platforminsights">Facebook Insights</a>.', 'add-meta-tags') . '
                </label>
                <p><strong>' . __('Example', 'add-meta-tags') . '</strong>: <code>1111111111,2222222222</code></p>
                <br />

                -->

                <h4>' . __('Google+ publisher profile URL', 'add-meta-tags') . ':</h4>

                <input name="social_main_googleplus_publisher_profile_url" type="text" id="social_main_googleplus_publisher_profile_url" class="code" value="' . esc_url_raw(stripslashes($options["social_main_googleplus_publisher_profile_url"])) . '" size="100" maxlength="1024" />
                <br />
                <label for="social_main_googleplus_publisher_profile_url">
                ' . __('Enter an absolute URL to the Google+ profile of the publisher. If this is filled in, it will be used in the link with <code>rel="publisher"</code> in the HEAD area of the web page.', 'add-meta-tags') . '
                </label>
                <p><strong>' . __('Example', 'add-meta-tags') . '</strong>: <code>https://plus.google.com/+AwesomeEditors/</code></p>
                <br />

                <h4>' . __('Twitter publisher username', 'add-meta-tags') . ':</h4>

                <input name="social_main_twitter_publisher_username" type="text" id="social_main_twitter_publisher_username" class="code" value="' . esc_attr(stripslashes($options["social_main_twitter_publisher_username"])) . '" size="100" maxlength="1024" />
                <br />
                <label for="social_main_twitter_publisher_username">
                ' . __('Enter the Twitter username of the publisher (without @).', 'add-meta-tags') . '
                </label>
                <p><strong>' . __('Example', 'add-meta-tags') . '</strong>: <code>AwesomeEditors</code></p>
                <br />

            </fieldset>
            </td>
            </tr>
    ';
    // Author Settings
    print '
            <tr valign="top">
            <th scope="row">' . __('Author Settings', 'add-meta-tags') . '</th>
            <td>
            <fieldset>
                <legend class="screen-reader-text"><span>' . __('Author Settings', 'add-meta-tags') . '</span></legend>

                <p>' . __('This section contains options related to the authors of the content.', 'add-meta-tags') . '</p>

                <h4>' . __('URLs of author profiles on social networks', 'add-meta-tags') . ':</h4>

                <p>' . __('Each author may fill in the the URLs of the profiles on external social networks in the WordPress user profile page (fields marked with <em>AMT</em>).', 'add-meta-tags') . '</p>

                <h4>' . __('Main source of local author profiles', 'add-meta-tags') . ':</h4>

                <select name="author_profile_source" type="text" id="author_profile_source" class="code">
                    <option ' . ($options["author_profile_source"] == "default" ? 'selected="selected"' : '') . ' value="default">' . __('First page of the author archive', 'add-meta-tags') . ' ' . __('(default)', 'add-meta-tags') . ' &mdash; ' . __('Organization web site', 'add-meta-tags') . '</option>
                    <option ' . ($options["author_profile_source"] == "frontpage" ? 'selected="selected"' : '') . ' value="frontpage">' . __('Front page (with static page only)', 'add-meta-tags') . ' &mdash; ' . __('Personal web site', 'add-meta-tags') . '</option>
                    <option ' . ($options["author_profile_source"] == "buddypress" ? 'selected="selected"' : '') . ' value="buddypress">' . __('BuddyPress member page', 'add-meta-tags') . ' &mdash; ' . __('Organization web site', 'add-meta-tags') . '</option>
                    <option ' . ($options["author_profile_source"] == "url" ? 'selected="selected"' : '') . ' value="url">' . __('Author\'s external web site URL', 'add-meta-tags') . ' &mdash; ' . __('Organization web site', 'add-meta-tags') . '</option>
                </select> 

                <br /><br />
                <p>' . __('This is an advanced option and should not be changed, unless you have consulted the integrated help for more information.', 'add-meta-tags') . '</p>
                <br />

            </fieldset>
            </td>
            </tr>
    ';
    // Basic Metadata
    print '
            <tr valign="top">
            <th scope="row">' . __('Basic Metadata', 'add-meta-tags') . '</th>
            <td>
            <fieldset>
                <legend class="screen-reader-text"><span>' . __('Basic Metadata', 'add-meta-tags') . '</span></legend>

                <input id="auto_description" type="checkbox" value="1" name="auto_description" ' . ($options["auto_description"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="auto_description">' . __('Automatically generate the <em>description</em> meta tag.', 'add-meta-tags') . '</label>
                <br />

                <input id="auto_keywords" type="checkbox" value="1" name="auto_keywords" ' . ($options["auto_keywords"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="auto_keywords">' . __('Automatically generate the <em>keywords</em> meta tag.', 'add-meta-tags') . '</label>
                <br />

            </fieldset>
            </td>
            </tr>

            <tr valign="top">
            <th scope="row">' . __('Opengraph Metadata', 'add-meta-tags') . '</th>
            <td>
            <fieldset>
                <legend class="screen-reader-text"><span>' . __('Opengraph Metadata', 'add-meta-tags') . '</span></legend>

                <input id="auto_opengraph" type="checkbox" value="1" name="auto_opengraph" ' . ($options["auto_opengraph"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="auto_opengraph">' . __('Automatically generate Opengraph meta tags.', 'add-meta-tags') . '</label>
                <br />

                <input id="og_add_xml_namespaces" type="checkbox" value="1" name="og_add_xml_namespaces" ' . ($options["og_add_xml_namespaces"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="og_add_xml_namespaces">' . __('Add Facebook\'s XML namespaces.', 'add-meta-tags') . '</label>
                <br />

                <input id="og_omit_video_metadata" type="checkbox" value="1" name="og_omit_video_metadata" ' . ($options["og_omit_video_metadata"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="og_omit_video_metadata">' . __('Omit <code>og:video</code> meta tags.', 'add-meta-tags') . '</label>
                <br />

            </fieldset>
            </td>
            </tr>

            <tr valign="top">
            <th scope="row">' . __('Twitter Cards Metadata', 'add-meta-tags') . '</th>
            <td>
            <fieldset>
                <legend class="screen-reader-text"><span>' . __('Twitter Cards Metadata', 'add-meta-tags') . '</span></legend>

                <input id="auto_twitter" type="checkbox" value="1" name="auto_twitter" ' . ($options["auto_twitter"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="auto_twitter">' . __('Automatically generate Twitter Cards meta tags.', 'add-meta-tags') . '</label>
                <br />

                <input id="tc_enforce_summary_large_image" type="checkbox" value="1" name="tc_enforce_summary_large_image" ' . ($options["tc_enforce_summary_large_image"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="tc_enforce_summary_large_image">' . __('Enforce the use of <code>summary_large_image</code> as default card type.', 'add-meta-tags') . '</label>
                <br />

                <input id="tc_enable_player_card_local" type="checkbox" value="1" name="tc_enable_player_card_local" ' . ($options["tc_enable_player_card_local"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="tc_enable_player_card_local">' . __('Enable the generation of <em>player</em> cards for local media.', 'add-meta-tags') . '</label>
                <br />

            </fieldset>
            </td>
            </tr>

            <tr valign="top">
            <th scope="row">' . __('Dublin Core Metadata', 'add-meta-tags') . '</th>
            <td>
            <fieldset>
                <legend class="screen-reader-text"><span>' . __('Dublin Core Metadata', 'add-meta-tags') . '</span></legend>

                <input id="auto_dublincore" type="checkbox" value="1" name="auto_dublincore" ' . ($options["auto_dublincore"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="auto_dublincore">' . __('Automatically generate Dublin Core metadata.', 'add-meta-tags') . '</label>
                <br />

                <input id="dc_add_xml_namespaces" type="checkbox" value="1" name="dc_add_xml_namespaces" ' . ($options["dc_add_xml_namespaces"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="dc_add_xml_namespaces">' . __('Add the Dublin Core XML namespace.', 'add-meta-tags') . '</label>
                <br />

            </fieldset>
            </td>
            </tr>

            <tr valign="top">
            <th scope="row">' . __('Schema.org Metadata', 'add-meta-tags') . '</th>
            <td>
            <fieldset>
                <legend class="screen-reader-text"><span>' . __('Schema.org Metadata', 'add-meta-tags') . '</span></legend>

                <input id="auto_schemaorg" type="checkbox" value="1" name="auto_schemaorg" ' . ($options["auto_schemaorg"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="auto_schemaorg">' . __('Automatically generate and embed Schema.org Microdata.', 'add-meta-tags') . '</label>
                <br />

                <input id="schemaorg_force_jsonld" type="checkbox" value="1" name="schemaorg_force_jsonld" ' . ($options["schemaorg_force_jsonld"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="schemaorg_force_jsonld">' . __('Enforce the generation of schema.org metadata as JSON-LD data.', 'add-meta-tags') . '</label>
                <br />

            </fieldset>
            </td>
            </tr>

            <tr valign="top">
            <th scope="row">' . __('Locale', 'add-meta-tags') . '</th>
            <td>
            <fieldset>
                <legend class="screen-reader-text"><span>' . __('Locale', 'add-meta-tags') . '</span></legend>

                <input name="global_locale" type="text" id="global_locale" class="code" value="' . esc_attr(stripslashes($options["global_locale"])) . '" size="20" maxlength="32" />
                <br />
                <label for="global_locale">
                ' . __('Enter a locale, for example <code>en_US</code> or <code>zh_Hans_TW</code>, which will be used globally in the generated metadata overriding the default locale as returned by WordPress.', 'add-meta-tags') . '
                ' . __('The locale can be overridden on a per post basis. For this purpose, enabling the relevant metabox feature below is required.', 'add-meta-tags') . '
                </label>
                <br />

                <input id="manage_html_lang_attribute" type="checkbox" value="1" name="manage_html_lang_attribute" ' . ($options["manage_html_lang_attribute"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="manage_html_lang_attribute">' . __('Automatically set the HTML document\'s <code>lang</code> attribute according to the locale of the content.', 'add-meta-tags') . '</label>
                <br />

                <input id="generate_hreflang_links" type="checkbox" value="1" name="generate_hreflang_links" ' . ($options["generate_hreflang_links"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="generate_hreflang_links">' . __('Enable the generation of a <code>link</code> element with the <code>hreflang</code> attribute.', 'add-meta-tags') . '</label>
                <br />

                <input id="hreflang_strip_region" type="checkbox" value="1" name="hreflang_strip_region" ' . ($options["hreflang_strip_region"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="hreflang_strip_region">' . __('Strip region code from the hreflang attribute.', 'add-meta-tags') . '</label>
                <br />

            </fieldset>
            </td>
            </tr>

            <tr valign="top">
            <th scope="row">' . __('Metabox Features', 'add-meta-tags') . '</th>
            <td>
            <fieldset>
                <legend class="screen-reader-text"><span>' . __('Metabox Features', 'add-meta-tags') . '</span></legend>

                <p>' . __('It is possible to partially customize the generated metadata on a per post basis through the <em>Metadata</em> metabox which exists in the post editing screen. Below you can choose which metabox features should be enabled. Enabling or disabling these features has no effect on the custom data that has been stored for each post.', 'add-meta-tags') . '</p>

                <p><input id="metabox_enable_description" type="checkbox" value="1" name="metabox_enable_description" ' . ($options["metabox_enable_description"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="metabox_enable_description">
                ' . __('Custom description.', 'add-meta-tags') . ' (' . __('Recommended', 'add-meta-tags') . ')
                </label></p>

                <p><input id="metabox_enable_keywords" type="checkbox" value="1" name="metabox_enable_keywords" ' . ($options["metabox_enable_keywords"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="metabox_enable_keywords">
                ' . __('Custom keywords.', 'add-meta-tags') . ' (' . __('Recommended', 'add-meta-tags') . ')
                </label></p>

                <p><input id="metabox_enable_title" type="checkbox" value="1" name="metabox_enable_title" ' . ($options["metabox_enable_title"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="metabox_enable_title">
                ' . __('Custom content of the <code>title</code> HTML element.', 'add-meta-tags') . '
                </label></p>

                <p><input id="metabox_enable_news_keywords" type="checkbox" value="1" name="metabox_enable_news_keywords" ' . ($options["metabox_enable_news_keywords"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="metabox_enable_news_keywords">
                ' . __('Custom news keywords. (<a target="_blank" href="http://support.google.com/news/publisher/bin/answer.py?hl=en&answer=68297">more info</a>)', 'add-meta-tags') . '
                </label></p>

                <p><input id="metabox_enable_full_metatags" type="checkbox" value="1" name="metabox_enable_full_metatags" ' . ($options["metabox_enable_full_metatags"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="metabox_enable_full_metatags">
                ' . __('Full meta tags box.', 'add-meta-tags') . '
                </label></p>

                <p><input id="metabox_enable_image_url" type="checkbox" value="1" name="metabox_enable_image_url" ' . ($options["metabox_enable_image_url"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="metabox_enable_image_url">
                ' . __('Global image override.', 'add-meta-tags') . '
                </label></p>

                <p><input id="metabox_enable_content_locale" type="checkbox" value="1" name="metabox_enable_content_locale" ' . ($options["metabox_enable_content_locale"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="metabox_enable_content_locale">
                ' . __('Content locale override. (Not to be used in conjunction with a multilingual plugin.) ', 'add-meta-tags') . '
                </label></p>

                <p><input id="metabox_enable_express_review" type="checkbox" value="1" name="metabox_enable_express_review" ' . ($options["metabox_enable_express_review"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="metabox_enable_express_review">
                ' . __('Express review.', 'add-meta-tags') . ' (' . __('For advanced users only', 'add-meta-tags') . ')
                </label></p>

                <p><input id="metabox_enable_referenced_list" type="checkbox" value="1" name="metabox_enable_referenced_list" ' . ($options["metabox_enable_referenced_list"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="metabox_enable_referenced_list">
                ' . __('Referenced items.', 'add-meta-tags') . ' (' . __('Not recommended', 'add-meta-tags') . ')
                </label></p>

            ';
    // The term meta API was implemented in 4.4
    if (version_compare(get_bloginfo('version'), '4.4', '>=')) {
        print '
                    <h4>' . __('Taxonomy terms', 'add-meta-tags') . ':</h4>

                    <p><input id="metabox_term_enable_full_metatags" type="checkbox" value="1" name="metabox_term_enable_full_metatags" ' . ($options["metabox_term_enable_full_metatags"] == "1" ? 'checked="checked"' : '') . '" />
                    <label for="metabox_term_enable_full_metatags">
                    ' . __('Full meta tags box.', 'add-meta-tags') . '
                    </label></p>

                    <p><input id="metabox_term_enable_image_url" type="checkbox" value="1" name="metabox_term_enable_image_url" ' . ($options["metabox_term_enable_image_url"] == "1" ? 'checked="checked"' : '') . '" />
                    <label for="metabox_term_enable_image_url">
                    ' . __('Global image override.', 'add-meta-tags') . '
                    </label></p>

                ';
    }
    print '

                <h4>' . __('WordPress user profiles', 'add-meta-tags') . ':</h4>

                <p><input id="metabox_user_enable_full_metatags" type="checkbox" value="1" name="metabox_user_enable_full_metatags" ' . ($options["metabox_user_enable_full_metatags"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="metabox_user_enable_full_metatags">
                ' . __('Full meta tags box.', 'add-meta-tags') . '
                </label></p>

                <p><input id="metabox_user_enable_image_url" type="checkbox" value="1" name="metabox_user_enable_image_url" ' . ($options["metabox_user_enable_image_url"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="metabox_user_enable_image_url">
                ' . __('Global image override.', 'add-meta-tags') . '
                </label></p>

                <br />

            </fieldset>
            </td>
            </tr>

            <tr valign="top">
            <th scope="row">' . __('Extra SEO Options', 'add-meta-tags') . '</th>
            <td>
            <fieldset>
                <legend class="screen-reader-text"><span>' . __('Extra SEO Options', 'add-meta-tags') . '</span></legend>

                <input id="noodp_description" type="checkbox" value="1" name="noodp_description" ' . ($options["noodp_description"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="noodp_description">' . __('Add <code>NOODP</code> and <code>NOYDIR</code> to the <em>robots</em> meta tag.', 'add-meta-tags') . '</label>
                <br />
                <br />

                <p>' . __('Add <code>NOINDEX,FOLLOW</code> to the <em>robots</em> meta tag on following types of archives:', 'add-meta-tags') . '</p>

                <p><input id="noindex_search_results" type="checkbox" value="1" name="noindex_search_results" ' . ($options["noindex_search_results"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="noindex_search_results">
                ' . __('Search results.', 'add-meta-tags') . ' (' . __('Highly recommended', 'add-meta-tags') . ')
                </label></p>

                <p><input id="noindex_date_archives" type="checkbox" value="1" name="noindex_date_archives" ' . ($options["noindex_date_archives"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="noindex_date_archives">
                ' . __('Date based archives.', 'add-meta-tags') . ' (' . __('Recommended', 'add-meta-tags') . ')
                </label></p>

                <p><input id="noindex_category_archives" type="checkbox" value="1" name="noindex_category_archives" ' . ($options["noindex_category_archives"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="noindex_category_archives">
                ' . __('Category based archives.', 'add-meta-tags') . ' (' . __('Even if checked, the first page of this type of archive is always indexed.', 'add-meta-tags') . ')
                </label></p>

                <p><input id="noindex_tag_archives" type="checkbox" value="1" name="noindex_tag_archives" ' . ($options["noindex_tag_archives"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="noindex_tag_archives">
                ' . __('Tag based archives.', 'add-meta-tags') . ' (' . __('Even if checked, the first page of this type of archive is always indexed.', 'add-meta-tags') . ')
                </label></p>

                <p><input id="noindex_taxonomy_archives" type="checkbox" value="1" name="noindex_taxonomy_archives" ' . ($options["noindex_taxonomy_archives"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="noindex_taxonomy_archives">
                ' . __('Custom taxonomy based archives.', 'add-meta-tags') . ' (' . __('Even if checked, the first page of this type of archive is always indexed.', 'add-meta-tags') . ')
                </label></p>

                <p><input id="noindex_author_archives" type="checkbox" value="1" name="noindex_author_archives" ' . ($options["noindex_author_archives"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="noindex_author_archives">
                ' . __('Author based archives.', 'add-meta-tags') . ' (' . __('Even if checked, the first page of this type of archive is always indexed.', 'add-meta-tags') . ')
                </label></p>

                <br />

                <p><input id="enforce_custom_title_in_metadata" type="checkbox" value="1" name="enforce_custom_title_in_metadata" ' . ($options["enforce_custom_title_in_metadata"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="enforce_custom_title_in_metadata">
                ' . __('Enforce the use of the content\'s custom title in the generated metadata.', 'add-meta-tags') . '
                </label></p>

                <br />

                <p><input id="enable_advanced_title_management" type="checkbox" value="1" name="enable_advanced_title_management" ' . ($options["enable_advanced_title_management"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="enable_advanced_title_management">
                ' . __('Enable advanced title management.', 'add-meta-tags') . '
                (<a target="_blank" href="http://www.codetrax.org/projects/wp-add-meta-tags/wiki/Advanced_Title_Management">' . __('Learn more', 'add-meta-tags') . '</a>)
                </label>

                <br />
            </fieldset>
            </td>
            </tr>

            <tr valign="top">
            <th scope="row">' . __('Copyright URL', 'add-meta-tags') . '</th>
            <td>
            <fieldset>
                <legend class="screen-reader-text"><span>' . __('Copyright URL', 'add-meta-tags') . '</span></legend>

                <input name="copyright_url" type="text" id="copyright_url" class="code" value="' . esc_url(stripslashes(amt_get_site_copyright_url($options))) . '" size="100" maxlength="1024" />
                <br />
                <label for="copyright_url">
                ' . __('Enter an absolute URL to a document containing copyright and licensing information about your work.', 'add-meta-tags') . '
                </label>
                <br />
            </fieldset>
            </td>
            </tr>

            <tr valign="top">
            <th scope="row">' . __('Default Image', 'add-meta-tags') . '</th>
            <td>
            <fieldset>
                <legend class="screen-reader-text"><span>' . __('Default Image', 'add-meta-tags') . '</span></legend>

                <input name="default_image_url" type="text" id="default_image_url" class="code" value="' . amt_esc_id_or_url_notation(stripslashes($options["default_image_url"])) . '" size="100" maxlength="1024" />
                <br />

                <span id="amt-default-image-selector-button" class="amt-default-image-selector-button wp-media-buttons-icon loadmediawindow button updatemeta button-small">Select image</span>
                <br />

                <label for="default_image_url">
                ' . __('Enter an absolute URL to an image that represents your website, for instance the logo. To specify the image dimensions you can use the special notation <code>URL,WIDTHxHEIGHT</code>.', 'add-meta-tags') . '
                </label>
                <br />
        ';
    // Default image preview
    $image_data = amt_get_default_image_data();
    $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>
                ';
    }
    print '
            </fieldset>
            </td>
            </tr>


            <tr valign="top">
            <th scope="row">' . __('Shortcodes', 'add-meta-tags') . '</th>
            <td>
            <fieldset>
                <legend class="screen-reader-text"><span>' . __('Shortcodes', 'add-meta-tags') . '</span></legend>

                <input id="expand_shortcodes" type="checkbox" value="1" name="expand_shortcodes" ' . ($options["expand_shortcodes"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="expand_shortcodes">' . __('Enforce the expansion of shortcodes before generating a description.', 'add-meta-tags') . '</label>
                <br />

            </fieldset>
            </td>
            </tr>

            <tr valign="top">
            <th scope="row">' . __('Secure Access', 'add-meta-tags') . '</th>
            <td>
            <fieldset>
                <legend class="screen-reader-text"><span>' . __('Secure Access', 'add-meta-tags') . '</span></legend>

                <input id="has_https_access" type="checkbox" value="1" name="has_https_access" ' . ($options["has_https_access"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="has_https_access">' . __('Media are accessible over HTTPS.', 'add-meta-tags') . '</label>
                <br />
            </fieldset>
            </td>
            </tr>

            <tr valign="top">
            <th scope="row">' . __('Media Limit', 'add-meta-tags') . '</th>
            <td>
            <fieldset>
                <legend class="screen-reader-text"><span>' . __('Media Limit', 'add-meta-tags') . '</span></legend>

                <input id="force_media_limit" type="checkbox" value="1" name="force_media_limit" ' . ($options["force_media_limit"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="force_media_limit">' . __('Do not generate metadata for more than one media file of each type (image, video, audio).', 'add-meta-tags') . '</label>
                <br />
            </fieldset>
            </td>
            </tr>

            <tr valign="top">
            <th scope="row">' . __('Review Mode', 'add-meta-tags') . '</th>
            <td>
            <fieldset>
                <legend class="screen-reader-text"><span>' . __('Review Mode', 'add-meta-tags') . '</span></legend>

                <input id="review_mode" type="checkbox" value="1" name="review_mode" ' . ($options["review_mode"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="review_mode">' . __('Enable <em>Metadata Review Mode</em>.', 'add-meta-tags') . '</label>
                <br />

                <input id="review_mode_metadata_report" type="checkbox" value="1" name="review_mode_metadata_report" ' . ($options["review_mode_metadata_report"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="review_mode_metadata_report">' . __('Enable keyword analysis and statistics.', 'add-meta-tags') . '</label>
                (<a target="_blank" href="http://www.codetrax.org/projects/wp-add-meta-tags/wiki/Metadata_Overview">' . __('Learn more', 'add-meta-tags') . '</a>)
                (<span style="color:red;">' . __('Experimental', 'add-meta-tags') . '</span>)
                <br />

                <input id="review_mode_omit_notices" type="checkbox" value="1" name="review_mode_omit_notices" ' . ($options["review_mode_omit_notices"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="review_mode_omit_notices">' . __('Omit help messages and notices. I have read, understood and agreed to them.', 'add-meta-tags') . '</label>
                <br />

            </fieldset>
            </td>
            </tr>

            <tr valign="top">
            <th scope="row">' . __('Extended Metadata Support', 'add-meta-tags') . '</th>
            <td>
            <fieldset>
                <legend class="screen-reader-text"><span>' . __('Extended Metadata Support', 'add-meta-tags') . '</span></legend>

                <p>' . __('Add-Meta-Tags supports the generation of metadata for products and other post types. Please enable any of the following generators of extended metadata.', 'add-meta-tags') . '</p>

                <br />

                <p><input id="extended_support_woocommerce" type="checkbox" value="1" name="extended_support_woocommerce" ' . ($options["extended_support_woocommerce"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="extended_support_woocommerce">
                ' . __('Metadata for WooCommerce products and product groups.', 'add-meta-tags') . '
                </label></p>

                <p><input id="extended_support_edd" type="checkbox" value="1" name="extended_support_edd" ' . ($options["extended_support_edd"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="extended_support_edd">
                ' . __('Metadata for Easy-Digital-Downloads products and product groups.', 'add-meta-tags') . ' (<span style="color:red;">' . __('Work in progress', 'add-meta-tags') . '</span>)
                </label></p>

                <p><input id="extended_support_buddypress" type="checkbox" value="1" name="extended_support_buddypress" ' . ($options["extended_support_buddypress"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="extended_support_buddypress">
                ' . __('Metadata for BuddyPress profiles.', 'add-meta-tags') . '
                </label></p>

                <p><input id="extended_support_bbpress" type="checkbox" value="1" name="extended_support_bbpress" ' . ($options["extended_support_bbpress"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="extended_support_bbpress">
                ' . __('Metadata for bbPress.', 'add-meta-tags') . ' (<span style="color:red;">' . __('Work in progress', 'add-meta-tags') . '</span>)
                </label></p>

                <br />

                <p>' . __('Please consult the integrated help for more information about these features.', 'add-meta-tags') . '</p>

                <br />

            </fieldset>
            </td>
            </tr>
    ';
    // Metadata Caching
    if (apply_filters('amt_enable_metadata_cache', true)) {
        print '
            <tr valign="top">
            <th scope="row">' . __('Metadata Caching', 'add-meta-tags') . '</th>
            <td>
            <fieldset>
                <legend class="screen-reader-text"><span>' . __('Metadata Caching', 'add-meta-tags') . '</span></legend>

                <input id="enable_timings" type="checkbox" value="1" name="enable_timings" ' . ($options["enable_timings"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="enable_timings">' . __('Show timing information.', 'add-meta-tags') . '</label>
                <br /><br />

                <label for="transient_cache_expiration">' . __('Cache metadata for this number of seconds:', 'add-meta-tags') . '</label>
                <input id="transient_cache_expiration" type="text" name="transient_cache_expiration" value="' . esc_attr($options["transient_cache_expiration"]) . '" size="10" maxlength="16" class="code" />
                <br /><br />

                <p>' . __('Metadata caching is an advanced feature and should only be used after you have read and fully understood the <em>Metadata caching</em> section of the integrated help.', 'add-meta-tags') . '</p>
                <br />
        ';
        // Metadata cache status
        if (absint($options["transient_cache_expiration"]) > 0) {
            // Get the number of cached entries
            // This only works when the database is used as the Transient Data storage backend.
            // If external storage backends are used for the transient data, this is always going to be zeo.
            $nr_cached_blocks = amt_count_transient_metadata_cache_entries();
            if (absint($nr_cached_blocks) > 0) {
                print '
                    <p>' . __('<strong>Metadata cache status</strong>: <em>Activated</em>, <strong style="color: green;">' . esc_attr($nr_cached_blocks) . '</strong> metadata blocks have been cached. All cached metadata blocks will be automatically purged the next time these settings are saved.', 'add-meta-tags') . '</p>
                    <br />
                ';
            } else {
                print '
                    <p>' . __('<strong>Metadata cache status</strong>: <em>Activated</em>, but no cached metadata blocks have been detected. This means that either no metadata blocks have been cached yet in the database or your WordPress installation uses an external storage backend for the transient data.', 'add-meta-tags') . '</p>
                    <br />
                ';
            }
        } else {
            print '
                <p>' . __('<strong>Metadata cache status</strong>: <em>Deactivated</em>. The caching timeout is set to zero, so metadata blocks are not cached.', 'add-meta-tags') . '</p>
                <br />
            ';
        }
        print '
            </fieldset>
            </td>
            </tr>
        ';
    }
    print '
            <tr valign="top">
            <th scope="row">' . __('Vendor HTML comments', 'add-meta-tags') . '</th>
            <td>
            <fieldset>
                <legend class="screen-reader-text"><span>' . __('Vendor HTML comments', 'add-meta-tags') . '</span></legend>

                <p>
                    ' . __('Add-Meta-Tags has always been enclosing its output in <a target="_blank" href="http://www.codetrax.org/projects/wp-add-meta-tags/wiki/Screenshots#Vendor-HTML-comments">HTML comments</a>, which contain the plugin\'s name. This is common practice among WordPress plugin developers as it makes it easier for users to identify the output of a specific plugin and also lets those who check the HTML source code of the page know which plugin has generated this specific output. For a free product with limited resources like Add-Meta-Tags this practice is also its only means of exposure in a safe and non intrusive way.', 'add-meta-tags') . '
                </p>
                <br />

                <p>
                    ' . __('Although we don\'t like it, we have added the following option which deactivates the generation of those HTML comments*. We do not recommend checking the following box, but, if for whatever reason you have to turn these comments off, please go ahead and do it. To make it a little harder for you, an artificial requirement of a one time donation for any number of web sites you own has been added. Please keep in mind that there are no special donation links for this purpose. We do not force or keep track of your donations. You are free to go ahead and check this box without donating. What you do is totally your own decision and has nothing to do with us.', 'add-meta-tags') . '
                </p>
                <br />

                <input id="omit_vendor_html_comments" type="checkbox" value="1" name="omit_vendor_html_comments" ' . ($options["omit_vendor_html_comments"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="omit_vendor_html_comments">' . sprintf(__('I have made a one time <a target="_blank" href="%s">donation</a> of 5 USD or more for all the web sites I own.', 'add-meta-tags'), 'http://bit.ly/HvUakt') . '</label> **
                <br />

                <p>
                    ' . __('<em>* HTML comments that are generated as part of the Schema.org microdata are always retained.</em>', 'add-meta-tags') . '
                </p>
                <p>
                    ' . __('<em>** All Add-Meta-Tags contributors should feel free to check the option above without donating.</em>', 'add-meta-tags') . '
                </p>
                <br />

            </fieldset>
            </td>
            </tr>
    ';
    print '
            <tr valign="top">
            <th scope="row">' . __('Donations', 'add-meta-tags') . '</th>
            <td>
            <fieldset>
                <legend class="screen-reader-text"><span>' . __('Donations', 'add-meta-tags') . '</span></legend>

                <input id="i_have_donated" type="checkbox" value="1" name="i_have_donated" ' . ($options["i_have_donated"] == "1" ? 'checked="checked"' : '') . '" />
                <label for="i_have_donated">' . sprintf(__('If checked, the <em>message from the author</em> above goes away. Thanks for <a target="_blank" href="%s">donating</a>!', 'add-meta-tags'), 'http://bit.ly/HvUakt') . '</label>
                <br />
            </fieldset>
            </td>
            </tr>

        </tbody>
        </table>

        <!-- Submit Buttons -->
        <table class="form-table">
        <tbody>
            <tr valign="top">
                <th scope="row">
                    <input id="submit" class="button-primary" type="submit" value="' . __('Save Changes', 'add-meta-tags') . '" name="info_update" />
                </th>

<!--
                <th scope="row">
                    <input id="reset" class="button-primary" type="submit" value="' . __('Reset to defaults', 'add-meta-tags') . '" name="info_reset" />
                </th>
-->

                <th></th><th></th><th></th><th></th>
            </tr>
        </tbody>
        </table>

        <br /><br /><br />

        <h2 class="title">' . __('Notes', 'add-meta-tags') . '</h2>

        <p>' . __('More management tools are available via the <code>amt</code> command of <code>wp-cli</code>. Learn more about the <a target="_blank" href="http://www.codetrax.org/projects/wp-add-meta-tags/wiki/Command_Line_Interface">Add-Meta-Tags command line interface</a>.', 'add-meta-tags') . '</p>


        </form>
        
    </div>

    ';
    print '
    </span> <!-- #add-meta-tags-settings -->
    ';
}
Пример #2
0
/**
 * Generates Opengraph metadata.
 *
 * Currently for:
 * - home page
 * - author archive
 * - content
 */
function amt_add_opengraph_metadata_head($post, $attachments, $embedded_media, $options)
{
    if (apply_filters('amt_exclude_opengraph_metadata', false)) {
        return array();
    }
    $do_auto_opengraph = $options["auto_opengraph"] == "1" ? true : false;
    if (!$do_auto_opengraph) {
        return array();
    }
    $metadata_arr = array();
    // fb:app_id & fb:admins
    // We currently let users add the full meta tags for fb:app_id and fb:admins in the site wide meta tags box.
    // fb:app_id appears everywhere
    //if ( ! empty($options['social_main_facebook_app_id']) ) {
    //    $metadata_arr[] = '<meta property="fb:app_id" content="' . esc_attr( $options['social_main_facebook_app_id'] ) . '" />';
    //}
    // fb:admins appear everywhere
    //if ( ! empty($options['social_main_facebook_admins']) ) {
    //    $fb_admins_arr = explode(',', $options['social_main_facebook_admins']);
    //    foreach ( $fb_admins_arr as $fb_admin ) {
    //        $metadata_arr[] = '<meta property="fb:admins" content="' . esc_attr( trim($fb_admin) ) . '" />';
    //    }
    //}
    // no publisher meta tag for facebook, unless it is content
    // Custom content override
    if (amt_is_custom($post, $options)) {
        // Return metadata with:
        // add_filter( 'amt_custom_metadata_opengraph', '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_opengraph', $metadata_arr, $post, $options, $attachments, $embedded_media);
        // Default front page displaying the latest posts
    } elseif (amt_is_default_front_page()) {
        // Type
        $metadata_arr[] = '<meta property="og:type" content="website" />';
        // Site Name
        $metadata_arr[] = '<meta property="og:site_name" content="' . esc_attr(get_bloginfo('name')) . '" />';
        // Title - Note: Contains multipage information
        $metadata_arr['og:title'] = '<meta property="og:title" content="' . esc_attr(amt_get_title_for_metadata($options, $post)) . '" />';
        // URL - Note: different method to get the permalink on paged archives
        if (is_paged()) {
            $metadata_arr[] = '<meta property="og:url" content="' . esc_url_raw(get_pagenum_link(get_query_var('paged'))) . '" />';
        } else {
            $metadata_arr[] = '<meta property="og:url" content="' . esc_url_raw(trailingslashit(get_bloginfo('url'))) . '" />';
        }
        // Site description - Note: Contains multipage information through amt_process_paged()
        $site_description = amt_get_site_description($options);
        if (empty($site_description)) {
            $site_description = get_bloginfo('description');
        }
        if (!empty($site_description)) {
            $metadata_arr[] = '<meta property="og:description" content="' . esc_attr(amt_process_paged($site_description)) . '" />';
        }
        // Locale
        $metadata_arr[] = '<meta property="og:locale" content="' . esc_attr(str_replace('-', '_', amt_get_language_site($options))) . '" />';
        // Site Image
        // Use the default image, if one has been set.
        $image_data = amt_get_default_image_data();
        if (!empty($image_data)) {
            $image_size = apply_filters('amt_image_size_index', 'full');
            $image_meta_tags = amt_get_opengraph_image_metatags($options, $image_data, $size = $image_size);
            if (!empty($image_meta_tags)) {
                $metadata_arr = array_merge($metadata_arr, $image_meta_tags);
            }
        }
        // Front page using a static page
        // Note: might also contain a listing of posts which may be paged, so use amt_process_paged()
    } elseif (amt_is_static_front_page()) {
        // Type
        if ($options['author_profile_source'] == 'frontpage') {
            // The front page is treated as the profile page.
            $metadata_arr[] = '<meta property="og:type" content="profile" />';
        } else {
            $metadata_arr[] = '<meta property="og:type" content="website" />';
        }
        // Site Name
        $metadata_arr[] = '<meta property="og:site_name" content="' . esc_attr(get_bloginfo('name')) . '" />';
        // Title - Note: Contains multipage information
        $metadata_arr['og:title'] = '<meta property="og:title" content="' . esc_attr(amt_get_title_for_metadata($options, $post)) . '" />';
        // URL - Note: different method to get the permalink on paged archives
        if (is_paged()) {
            $metadata_arr[] = '<meta property="og:url" content="' . esc_url_raw(get_pagenum_link(get_query_var('paged'))) . '" />';
        } else {
            $metadata_arr[] = '<meta property="og:url" content="' . esc_url_raw(trailingslashit(get_bloginfo('url'))) . '" />';
        }
        // Site Description - Note: Contains multipage information through amt_process_paged()
        $content_desc = amt_get_content_description($post);
        if (!empty($content_desc)) {
            // Use the pages custom description
            $metadata_arr[] = '<meta property="og:description" content="' . esc_attr(amt_process_paged($content_desc)) . '" />';
        } elseif (get_bloginfo('description')) {
            // Alternatively use the blog's description
            $metadata_arr[] = '<meta property="og:description" content="' . esc_attr(amt_process_paged(get_bloginfo('description'))) . '" />';
        }
        // Locale
        $metadata_arr[] = '<meta property="og:locale" content="' . esc_attr(str_replace('-', '_', amt_get_language_content($options, $post))) . '" />';
        // Site Image
        // First check if a global image override URL has been entered.
        // If yes, use this image URL and override all other images.
        $image_data = amt_get_image_attributes_array(amt_get_post_meta_image_url($post->ID));
        if (!empty($image_data)) {
            $image_size = apply_filters('amt_image_size_index', 'full');
            $image_meta_tags = amt_get_opengraph_image_metatags($options, $image_data, $size = $image_size);
            if (!empty($image_meta_tags)) {
                $metadata_arr = array_merge($metadata_arr, $image_meta_tags);
            }
            //$global_image_override_url = amt_get_post_meta_image_url($post->ID);
            //if ( ! empty( $global_image_override_url ) ) {
            //    $metadata_arr[] = '<meta property="og:image" content="' . esc_url_raw( $global_image_override_url ) . '" />';
            //    if ( is_ssl() || ( ! is_ssl() && $options["has_https_access"] == "1" ) ) {
            //        $metadata_arr[] = '<meta property="og:image:secure_url" content="' . esc_url_raw( str_replace('http:', 'https:', $global_image_override_url ) ) . '" />';
            //    }
            // Then try the featured image, if exists.
        } elseif (function_exists('has_post_thumbnail') && has_post_thumbnail($post->ID)) {
            // Allow filtering of the image size.
            $image_size = apply_filters('amt_image_size_index', 'full');
            $metadata_arr = array_merge($metadata_arr, amt_get_opengraph_image_metatags($options, get_post_thumbnail_id($post->ID), $size = $image_size));
        } else {
            // Use the default image, if one has been set.
            $image_data = amt_get_default_image_data();
            if (!empty($image_data)) {
                $image_size = apply_filters('amt_image_size_index', 'full');
                $image_meta_tags = amt_get_opengraph_image_metatags($options, $image_data, $size = $image_size);
                if (!empty($image_meta_tags)) {
                    $metadata_arr = array_merge($metadata_arr, $image_meta_tags);
                }
            }
            // Alternatively, use default image
            //$metadata_arr[] = '<meta property="og:image" content="' . esc_url_raw( $options["default_image_url"] ) . '" />';
            //if ( is_ssl() || ( ! is_ssl() && $options["has_https_access"] == "1" ) ) {
            //    $metadata_arr[] = '<meta property="og:image:secure_url" content="' . esc_url_raw( str_replace('http:', 'https:', $options["default_image_url"] ) ) . '" />';
            //}
        }
        // Profile data (only if the front page has been set as the source of profile.)
        if ($options['author_profile_source'] == 'frontpage') {
            // Profile first and last name
            $last_name = get_the_author_meta('last_name', $post->post_author);
            if (!empty($last_name)) {
                $metadata_arr[] = '<meta property="profile:last_name" content="' . esc_attr($last_name) . '" />';
            }
            $first_name = get_the_author_meta('first_name', $post->post_author);
            if (!empty($first_name)) {
                $metadata_arr[] = '<meta property="profile:first_name" content="' . esc_attr($first_name) . '" />';
            }
        }
        // The posts index page - a static page displaying the latest posts
    } elseif (amt_is_static_home()) {
        // Type
        $metadata_arr[] = '<meta property="og:type" content="website" />';
        // Site Name
        $metadata_arr[] = '<meta property="og:site_name" content="' . esc_attr(get_bloginfo('name')) . '" />';
        // Title - Note: Contains multipage information
        $metadata_arr['og:title'] = '<meta property="og:title" content="' . esc_attr(amt_get_title_for_metadata($options, $post)) . '" />';
        // URL - Note: different method to get the permalink on paged archives
        if (is_paged()) {
            $metadata_arr[] = '<meta property="og:url" content="' . esc_url_raw(get_pagenum_link(get_query_var('paged'))) . '" />';
        } else {
            $metadata_arr[] = '<meta property="og:url" content="' . esc_url_raw(get_permalink($post->ID)) . '" />';
        }
        // Site Description - Note: Contains multipage information through amt_process_paged()
        $content_desc = amt_get_content_description($post);
        if (!empty($content_desc)) {
            // Use the pages custom description
            $metadata_arr[] = '<meta property="og:description" content="' . esc_attr(amt_process_paged($content_desc)) . '" />';
        } elseif (get_bloginfo('description')) {
            // Alternatively use a generic description
            $metadata_arr[] = '<meta property="og:description" content="' . amt_process_paged("An index of the latest content.") . '" />';
        }
        // Locale
        $metadata_arr[] = '<meta property="og:locale" content="' . esc_attr(str_replace('-', '_', amt_get_language_content($options, $post))) . '" />';
        // Site Image
        // First check if a global image override URL has been entered.
        // If yes, use this image URL and override all other images.
        $image_data = amt_get_image_attributes_array(amt_get_post_meta_image_url($post->ID));
        if (!empty($image_data)) {
            $image_size = apply_filters('amt_image_size_index', 'full');
            $image_meta_tags = amt_get_opengraph_image_metatags($options, $image_data, $size = $image_size);
            if (!empty($image_meta_tags)) {
                $metadata_arr = array_merge($metadata_arr, $image_meta_tags);
            }
            //$global_image_override_url = amt_get_post_meta_image_url($post->ID);
            //if ( ! empty( $global_image_override_url ) ) {
            //    $metadata_arr[] = '<meta property="og:image" content="' . esc_url_raw( $global_image_override_url ) . '" />';
            //    if ( is_ssl() || ( ! is_ssl() && $options["has_https_access"] == "1" ) ) {
            //        $metadata_arr[] = '<meta property="og:image:secure_url" content="' . esc_url_raw( str_replace('http:', 'https:', $global_image_override_url ) ) . '" />';
            //    }
            // Then try the featured image, if exists.
        } elseif (function_exists('has_post_thumbnail') && has_post_thumbnail($post->ID)) {
            // Allow filtering of the image size.
            $image_size = apply_filters('amt_image_size_index', 'full');
            $metadata_arr = array_merge($metadata_arr, amt_get_opengraph_image_metatags($options, get_post_thumbnail_id($post->ID), $size = $image_size));
        } else {
            // Use the default image, if one has been set.
            $image_data = amt_get_default_image_data();
            if (!empty($image_data)) {
                $image_size = apply_filters('amt_image_size_index', 'full');
                $image_meta_tags = amt_get_opengraph_image_metatags($options, $image_data, $size = $image_size);
                if (!empty($image_meta_tags)) {
                    $metadata_arr = array_merge($metadata_arr, $image_meta_tags);
                }
            }
            // Alternatively, use default image
            //$metadata_arr[] = '<meta property="og:image" content="' . esc_url_raw( $options["default_image_url"] ) . '" />';
            //if ( is_ssl() || ( ! is_ssl() && $options["has_https_access"] == "1" ) ) {
            //    $metadata_arr[] = '<meta property="og:image:secure_url" content="' . esc_url_raw( str_replace('http:', 'https:', $options["default_image_url"] ) ) . '" />';
            //}
        }
        // Category, Tag, Taxonomy archives
        // Note: product groups should pass the is_tax() validation, so no need for
        // amt_is_product_group(). We do not support other product groups.
        // amt_is_product_group() is used below to set the og:type to product.group.
    } elseif (is_category() || is_tag() || 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);
        // Type
        // In case of a product group taxonomy, we set the og:type to product.group
        if (amt_is_product_group()) {
            $metadata_arr[] = '<meta property="og:type" content="product.group" />';
        } else {
            $metadata_arr[] = '<meta property="og:type" content="website" />';
        }
        // Site Name
        $metadata_arr[] = '<meta property="og:site_name" content="' . esc_attr(get_bloginfo('name')) . '" />';
        // Title - Note: Contains multipage information
        $metadata_arr['og:title'] = '<meta property="og:title" content="' . esc_attr(amt_get_title_for_metadata($options, $post)) . '" />';
        // URL - Note: different method to get the permalink on paged archives
        $url = get_term_link($tax_term_object);
        if (is_paged()) {
            $url = trailingslashit($url) . get_query_var('paged') . '/';
        }
        $metadata_arr[] = '<meta property="og:url" content="' . esc_url_raw($url) . '" />';
        // 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.
            // Filter name
            if (is_category()) {
                $generic_description = apply_filters('amt_generic_description_category_archive', __('Content filed under the %s category.', 'add-meta-tags'));
            } elseif (is_tag()) {
                $generic_description = apply_filters('amt_generic_description_tag_archive', __('Content tagged with %s.', 'add-meta-tags'));
            } elseif (is_tax()) {
                // 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
                $generic_description = apply_filters($taxonomy_description_filter_name, __('Content filed under the %s taxonomy.', 'add-meta-tags'));
            }
            // Final generic description
            $generic_description = sprintf($generic_description, single_term_title($prefix = '', $display = false));
            $metadata_arr[] = '<meta property="og:description" content="' . esc_attr(amt_process_paged($generic_description)) . '" />';
        } else {
            $metadata_arr[] = '<meta property="og:description" content="' . esc_attr(amt_process_paged($description_content)) . '" />';
        }
        // Locale
        $metadata_arr[] = '<meta property="og:locale" content="' . esc_attr(str_replace('-', '_', amt_get_language_site($options))) . '" />';
        // Image
        // Use an image from the 'Global image override' field.
        // Otherwise, use a user defined image via filter.
        // Otherwise use default image.
        $image_data = amt_get_image_attributes_array(amt_get_term_meta_image_url($tax_term_object->term_id));
        if (!empty($image_data)) {
            $image_size = apply_filters('amt_image_size_index', 'full');
            $image_meta_tags = amt_get_opengraph_image_metatags($options, $image_data, $size = $image_size);
            if (!empty($image_meta_tags)) {
                $metadata_arr = array_merge($metadata_arr, $image_meta_tags);
            }
        } else {
            // First filter using a term/taxonomy agnostic filter name.
            $taxonomy_image_url = apply_filters('amt_taxonomy_force_image_url', '', $tax_term_object);
            if (empty($taxonomy_image_url)) {
                // Second filter (term/taxonomy dependent).
                // Construct the filter name. Template: ``amt_taxonomy_image_url_TAXONOMYSLUG_TERMSLUG``
                $taxonomy_image_url_filter_name = sprintf('amt_taxonomy_image_url_%s_%s', $tax_term_object->taxonomy, $tax_term_object->slug);
                //var_dump($taxonomy_image_url_filter_name);
                // The default image, if set, is used by default.
                $taxonomy_image_url = apply_filters($taxonomy_image_url_filter_name, $options["default_image_url"]);
            }
            if (!empty($taxonomy_image_url)) {
                $image_data = amt_get_image_attributes_array($taxonomy_image_url);
                if (!empty($image_data)) {
                    $image_size = apply_filters('amt_image_size_index', 'full');
                    $image_meta_tags = amt_get_opengraph_image_metatags($options, $image_data, $size = $image_size);
                    if (!empty($image_meta_tags)) {
                        $metadata_arr = array_merge($metadata_arr, $image_meta_tags);
                    }
                }
                //$metadata_arr[] = '<meta property="og:image" content="' . esc_url_raw( $taxonomy_image_url ) . '" />';
                //if ( is_ssl() || ( ! is_ssl() && $options["has_https_access"] == "1" ) ) {
                //    $metadata_arr[] = '<meta property="og:image:secure_url" content="' . esc_url_raw( str_replace('http:', 'https:', $taxonomy_image_url ) ) . '" />';
                //}
            }
        }
        // Author archive. First page is considered a profile page.
    } 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;
        // Type
        if (!is_paged() && $options['author_profile_source'] == 'default') {
            // We treat the first page of the archive as a profile, only if
            // the profile source has been set to 'default'
            $metadata_arr[] = '<meta property="og:type" content="profile" />';
        } else {
            $metadata_arr[] = '<meta property="og:type" content="website" />';
        }
        // Site Name
        $metadata_arr[] = '<meta property="og:site_name" content="' . esc_attr(get_bloginfo('name')) . '" />';
        // Title - Note: Contains multipage information
        //if ( ! is_paged() ) {
        //    // We treat the first page of the archive as a profile
        //    $metadata_arr[] = '<meta property="og:title" content="' . esc_attr( $author->display_name ) . ' profile page" />';
        //} else {
        //    $metadata_arr[] = '<meta property="og:title" content="' . esc_attr( amt_process_paged( "Content published by " . $author->display_name ) ) . '" />';
        //}
        $metadata_arr['og:title'] = '<meta property="og:title" content="' . esc_attr(amt_get_title_for_metadata($options, $post)) . ' profile page" />';
        // URL - Note: different method to get the permalink on paged archives
        // If a Facebook author profile URL has been provided, it has priority,
        // Otherwise fall back to the WordPress author archive.
        $fb_author_url = $author->amt_facebook_author_profile_url;
        if (!empty($fb_author_url)) {
            $metadata_arr[] = '<meta property="og:url" content="' . esc_url_raw($fb_author_url, array('http', 'https')) . '" />';
        } else {
            if (is_paged()) {
                $metadata_arr[] = '<meta property="og:url" content="' . esc_url_raw(get_pagenum_link(get_query_var('paged'))) . '" />';
            } else {
                $metadata_arr[] = '<meta property="og:url" content="' . esc_url_raw(get_author_posts_url($author->ID)) . '" />';
                // The following makes no sense here. 'get_author_posts_url( $author->ID )' will do in all cases.
                //$metadata_arr[] = '<meta property="og:url" content="' . esc_url_raw( amt_get_local_author_profile_url( $author->ID, $options ) ) . '" />';
            }
        }
        // description - Note: Contains multipage information through amt_process_paged()
        if (is_paged()) {
            $metadata_arr[] = '<meta property="og:description" content="' . esc_attr(amt_process_paged("Content published by " . $author->display_name)) . '" />';
        } else {
            // Here we sanitize the provided description for safety
            // We treat the first page of the archive as a profile
            $author_description = sanitize_text_field(amt_sanitize_description($author->description));
            if (empty($author_description)) {
                $metadata_arr[] = '<meta property="og:description" content="' . esc_attr("Content published by " . $author->display_name) . '" />';
            } else {
                $metadata_arr[] = '<meta property="og:description" content="' . esc_attr($author_description) . '" />';
            }
        }
        // Locale
        $metadata_arr[] = '<meta property="og:locale" content="' . esc_attr(str_replace('-', '_', amt_get_language_site($options))) . '" />';
        // Profile Image
        // First use the global image override URL
        $image_data = amt_get_image_attributes_array(amt_get_user_meta_image_url($author->ID));
        if (!empty($image_data)) {
            $image_size = apply_filters('amt_image_size_index', 'full');
            $image_meta_tags = amt_get_opengraph_image_metatags($options, $image_data, $size = $image_size);
            if (!empty($image_meta_tags)) {
                $metadata_arr = array_merge($metadata_arr, $image_meta_tags);
            }
        } else {
            $author_email = sanitize_email($author->user_email);
            $avatar_size = apply_filters('amt_avatar_size', 128);
            $avatar_url = '';
            // First try to get the avatar link by using get_avatar().
            // Important: for this to work the "Show Avatars" option should be enabled in Settings > Discussion.
            $avatar_img = get_avatar(get_the_author_meta('ID', $author->ID), $avatar_size, '', get_the_author_meta('display_name', $author->ID));
            if (!empty($avatar_img)) {
                if (preg_match("#src=['\"]([^'\"]+)['\"]#", $avatar_img, $matches)) {
                    $avatar_url = $matches[1];
                }
            } elseif (!empty($author_email)) {
                // If the user has provided an email, we use it to construct a gravatar link.
                $avatar_url = "http://www.gravatar.com/avatar/" . md5($author_email) . "?s=" . $avatar_size;
            }
            if (!empty($avatar_url)) {
                //$avatar_url = html_entity_decode($avatar_url, ENT_NOQUOTES, 'UTF-8');
                $metadata_arr[] = '<meta property="og:image" content="' . esc_url_raw($avatar_url) . '" />';
                // Add an og:imagesecure_url if the image URL uses HTTPS
                if (strpos($avatar_url, 'https://') !== false) {
                    $metadata_arr[] = '<meta property="og:imagesecure_url" content="' . esc_url_raw($avatar_url) . '" />';
                }
                if (apply_filters('amt_extended_image_tags', true)) {
                    $metadata_arr[] = '<meta property="og:image:width" content="' . esc_attr($avatar_size) . '" />';
                    $metadata_arr[] = '<meta property="og:image:height" content="' . esc_attr($avatar_size) . '" />';
                    // Since we do not have a way to determine the image type, the following meta tag is commented out
                    // TODO: make a function that detects the image type from the file extension (if a file extension is available)
                    //$metadata_arr[] = '<meta property="og:image:type" content="image/jpeg" />';
                }
            }
        }
        // Profile data (only on the 1st page of the archive)
        if (!is_paged() && $options['author_profile_source'] == 'default') {
            // Profile first and last name
            $last_name = $author->last_name;
            if (!empty($last_name)) {
                $metadata_arr[] = '<meta property="profile:last_name" content="' . esc_attr($last_name) . '" />';
            }
            $first_name = $author->first_name;
            if (!empty($first_name)) {
                $metadata_arr[] = '<meta property="profile:first_name" content="' . esc_attr($first_name) . '" />';
            }
        }
        // Custom Post Type archives
    } 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);
        // Type
        $metadata_arr[] = '<meta property="og:type" content="website" />';
        // Site Name
        $metadata_arr[] = '<meta property="og:site_name" content="' . esc_attr(get_bloginfo('name')) . '" />';
        // Title - Note: Contains multipage information
        $metadata_arr['og:title'] = '<meta property="og:title" content="' . esc_attr(amt_get_title_for_metadata($options, $post)) . '" />';
        // URL - Note: different method to get the permalink on paged archives
        $url = get_post_type_archive_link($post_type_object->name);
        if (is_paged()) {
            $url = trailingslashit($url) . get_query_var('paged') . '/';
        }
        $metadata_arr[] = '<meta property="og:url" content="' . esc_url_raw($url) . '" />';
        // 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[] = '<meta property="og:description" content="' . esc_attr(amt_process_paged($generic_description)) . '" />';
        // Locale
        $metadata_arr[] = '<meta property="og:locale" content="' . esc_attr(str_replace('-', '_', amt_get_language_site($options))) . '" />';
        // Image
        // Use a user defined image via filter. Otherwise use default image.
        // First filter using a term/taxonomy agnostic filter name.
        $posttype_image_url = apply_filters('amt_posttype_force_image_url', '', $post_type_object);
        if (empty($posttype_image_url)) {
            // Second filter (post type dependent).
            // Construct the filter name. Template: ``amt_posttype_image_url_POSTTYPESLUG``
            $posttype_image_url_filter_name = sprintf('amt_posttype_image_url_%s', $post_type_object->name);
            //var_dump($posttype_image_url_filter_name);
            // The default image, if set, is used by default.
            $posttype_image_url = apply_filters($posttype_image_url_filter_name, $options["default_image_url"]);
        }
        if (!empty($posttype_image_url)) {
            $image_data = amt_get_image_attributes_array($posttype_image_url);
            if (!empty($image_data)) {
                $image_size = apply_filters('amt_image_size_index', 'full');
                $image_meta_tags = amt_get_opengraph_image_metatags($options, $image_data, $size = $image_size);
                if (!empty($image_meta_tags)) {
                    $metadata_arr = array_merge($metadata_arr, $image_meta_tags);
                }
            }
            //$metadata_arr[] = '<meta property="og:image" content="' . esc_url_raw( $posttype_image_url ) . '" />';
            //if ( is_ssl() || ( ! is_ssl() && $options["has_https_access"] == "1" ) ) {
            //    $metadata_arr[] = '<meta property="og:image:secure_url" content="' . esc_url_raw( str_replace('http:', 'https:', $posttype_image_url ) ) . '" />';
            //}
        }
        // Attachments
    } 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);
        // First add metadata common to all attachment types.
        // Type
        // Note: there is no specific type for images/audio. We use article amd video
        // TODO: Check whether we could use another type specific to each attachment type.
        if ('video' == $attachment_type) {
            // video.other og:type for video attachment pages
            $og_type = 'video.other';
        } else {
            $og_type = 'article';
        }
        $og_type = apply_filters('amt_opengraph_og_type_attachment', $og_type);
        $metadata_arr[] = '<meta property="og:type" content="' . esc_attr($og_type) . '" />';
        // Site Name
        $metadata_arr[] = '<meta property="og:site_name" content="' . esc_attr(get_bloginfo('name')) . '" />';
        // Title
        $metadata_arr['og:title'] = '<meta property="og:title" content="' . esc_attr(amt_get_title_for_metadata($options, $post)) . '" />';
        // URL
        $metadata_arr[] = '<meta property="og:url" content="' . esc_url_raw(get_permalink($post->ID)) . '" />';
        // Description - We use the description defined by Add-Meta-Tags
        $content_desc = amt_get_content_description($post);
        if (!empty($content_desc)) {
            $metadata_arr[] = '<meta property="og:description" content="' . esc_attr($content_desc) . '" />';
        }
        // Locale
        $metadata_arr[] = '<meta property="og:locale" content="' . esc_attr(str_replace('-', '_', amt_get_language_content($options, $post))) . '" />';
        // og:updated_time
        $metadata_arr[] = '<meta property="og:updated_time" content="' . esc_attr(amt_iso8601_date($post->post_modified)) . '" />';
        // 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');
            $metadata_arr = array_merge($metadata_arr, amt_get_opengraph_image_metatags($options, $post->ID, $size = $image_size));
        } elseif ('video' == $attachment_type) {
            if ($options["og_omit_video_metadata"] != "1") {
                // Video tags
                $metadata_arr[] = '<meta property="og:video" content="' . esc_url_raw(wp_get_attachment_url($post->ID)) . '" />';
                if (is_ssl() || !is_ssl() && $options["has_https_access"] == "1") {
                    $metadata_arr[] = '<meta property="og:video:secure_url" content="' . esc_url_raw(str_replace('http:', 'https:', wp_get_attachment_url($post->ID))) . '" />';
                }
                //
                //$metadata_arr[] = '<meta property="og:video:width" content="' . esc_attr( $main_size_meta[1] ) . '" />';
                //$metadata_arr[] = '<meta property="og:video:height" content="' . esc_attr( $main_size_meta[2] ) . '" />';
                $metadata_arr[] = '<meta property="og:video:type" content="' . esc_attr($mime_type) . '" />';
            }
        } elseif ('audio' == $attachment_type) {
            // Audio tags
            $metadata_arr[] = '<meta property="og:audio" content="' . esc_url_raw(wp_get_attachment_url($post->ID)) . '" />';
            if (is_ssl() || !is_ssl() && $options["has_https_access"] == "1") {
                $metadata_arr[] = '<meta property="og:audio:secure_url" content="' . esc_url_raw(str_replace('http:', 'https:', wp_get_attachment_url($post->ID))) . '" />';
            }
            $metadata_arr[] = '<meta property="og:audio:type" content="' . esc_attr($mime_type) . '" />';
        }
        // Article: meta tags
        // Dates
        $metadata_arr[] = '<meta property="article:published_time" content="' . esc_attr(amt_iso8601_date($post->post_date)) . '" />';
        $metadata_arr[] = '<meta property="article:modified_time" content="' . esc_attr(amt_iso8601_date($post->post_modified)) . '" />';
        // Author
        // If a Facebook author profile URL has been provided, it has priority,
        // Otherwise fall back to the WordPress author archive.
        $fb_author_url = get_the_author_meta('amt_facebook_author_profile_url', $post->post_author);
        if (!empty($fb_author_url)) {
            $metadata_arr[] = '<meta property="article:author" content="' . esc_url_raw($fb_author_url, array('http', 'https', 'mailto')) . '" />';
        } else {
            //$metadata_arr[] = '<meta property="article:author" content="' . esc_url_raw( get_author_posts_url( get_the_author_meta( 'ID', $post->post_author ) ) ) . '" />';
            $metadata_arr[] = '<meta property="article:author" content="' . esc_url_raw(amt_get_local_author_profile_url(get_the_author_meta('ID', $post->post_author), $options)) . '" />';
        }
        // Publisher
        // If a Facebook publisher profile URL has been provided, it has priority.
        // Otherwise fall back to the WordPress blog home url.
        if (!empty($options['social_main_facebook_publisher_profile_url'])) {
            $metadata_arr[] = '<meta property="article:publisher" content="' . esc_url_raw($options['social_main_facebook_publisher_profile_url'], array('http', 'https', 'mailto')) . '" />';
        } else {
            $metadata_arr[] = '<meta property="article:publisher" content="' . esc_url_raw(trailingslashit(get_bloginfo('url'))) . '" />';
        }
        // Posts, pages, custom content types (attachments excluded, caught in previous clause)
        // Note: content might be multipage. Process with amt_process_paged() wherever needed.
    } elseif (is_singular()) {
        // Site Name
        $metadata_arr[] = '<meta property="og:site_name" content="' . esc_attr(get_bloginfo('name')) . '" />';
        // Type
        // og:type set to 'video.other' for posts with post format set to video
        if (get_post_format($post->ID) == 'video') {
            $og_type = 'video.other';
            // og:type set to 'product' if amt_is_product() validates
            // See:
            //  * https://developers.facebook.com/docs/reference/opengraph/object-type/product/
            //  * https://developers.facebook.com/docs/payments/product
        } elseif (amt_is_product()) {
            $og_type = 'product';
            // In any other case 'article' is used as the og:type
        } else {
            $og_type = 'article';
        }
        // Allow filtering of og:type
        $og_type = apply_filters('amt_opengraph_og_type_content', $og_type);
        // Set og:type meta tag.
        $metadata_arr[] = '<meta property="og:type" content="' . esc_attr($og_type) . '" />';
        // Title
        // Note: Contains multipage information
        $metadata_arr['og:title'] = '<meta property="og:title" content="' . esc_attr(amt_get_title_for_metadata($options, $post)) . '" />';
        // URL - Uses amt_get_permalink_for_multipage()
        $metadata_arr[] = '<meta property="og:url" content="' . esc_url_raw(amt_get_permalink_for_multipage($post)) . '" />';
        // 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 property="og:description" content="' . esc_attr(amt_process_paged($content_desc)) . '" />';
        }
        // Locale
        $metadata_arr[] = '<meta property="og:locale" content="' . esc_attr(str_replace('-', '_', amt_get_language_content($options, $post))) . '" />';
        // og:updated_time
        $metadata_arr[] = '<meta property="og:updated_time" content="' . esc_attr(amt_iso8601_date($post->post_modified)) . '" />';
        // Image
        // First check if a global image override URL has been entered.
        // If yes, use this image URL and override all other images.
        $image_data = amt_get_image_attributes_array(amt_get_post_meta_image_url($post->ID));
        if (!empty($image_data)) {
            $image_size = apply_filters('amt_image_size_content', 'full');
            $image_meta_tags = amt_get_opengraph_image_metatags($options, $image_data, $size = $image_size);
            if (!empty($image_meta_tags)) {
                $metadata_arr = array_merge($metadata_arr, $image_meta_tags);
            }
            //$global_image_override_url = amt_get_post_meta_image_url($post->ID);
            //if ( ! empty( $global_image_override_url ) ) {
            //    $metadata_arr[] = '<meta property="og:image" content="' . esc_url_raw( $global_image_override_url ) . '" />';
            //    if ( is_ssl() || ( ! is_ssl() && $options["has_https_access"] == "1" ) ) {
            //        $metadata_arr[] = '<meta property="og:image:secure_url" content="' . esc_url_raw( str_replace('http:', 'https:', $global_image_override_url ) ) . '" />';
            //    }
            // Further image processing
        } else {
            // Media Limits
            $image_limit = amt_metadata_get_image_limit($options);
            $video_limit = amt_metadata_get_video_limit($options);
            $audio_limit = amt_metadata_get_audio_limit($options);
            // Counters
            $ic = 0;
            // image counter
            $vc = 0;
            // video counter
            $ac = 0;
            // audio counter
            // 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;
            if (function_exists('has_post_thumbnail') && has_post_thumbnail($post->ID)) {
                // Allow filtering of the image size.
                $image_size = apply_filters('amt_image_size_content', 'full');
                $metadata_arr = array_merge($metadata_arr, amt_get_opengraph_image_metatags($options, get_post_thumbnail_id($post->ID), $size = $image_size));
                // Finally, set the $featured_image_id
                $featured_image_id = get_post_thumbnail_id($post->ID);
                // Images have been found.
                $has_images = true;
                // Increase image counter
                $ic++;
            }
            // 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 && $ic < $image_limit) {
                        // Image tags
                        // Allow filtering of the image size.
                        $image_size = apply_filters('amt_image_size_content', 'full');
                        $metadata_arr = array_merge($metadata_arr, amt_get_opengraph_image_metatags($options, $attachment->ID, $size = $image_size));
                        // Images have been found.
                        $has_images = true;
                        // Increase image counter
                        $ic++;
                    } elseif ('video' == $attachment_type && $vc < $video_limit) {
                        if ($options["og_omit_video_metadata"] != "1") {
                            // Video tags
                            $metadata_arr[] = '<meta property="og:video" content="' . esc_url_raw(wp_get_attachment_url($attachment->ID)) . '" />';
                            if (is_ssl() || !is_ssl() && $options["has_https_access"] == "1") {
                                $metadata_arr[] = '<meta property="og:video:secure_url" content="' . esc_url_raw(str_replace('http:', 'https:', wp_get_attachment_url($attachment->ID))) . '" />';
                            }
                            //$metadata_arr[] = '<meta property="og:video:width" content="' . esc_attr( $main_size_meta[1] ) . '" />';
                            //$metadata_arr[] = '<meta property="og:video:height" content="' . esc_attr( $main_size_meta[2] ) . '" />';
                            $metadata_arr[] = '<meta property="og:video:type" content="' . esc_attr($mime_type) . '" />';
                            // Increase video counter
                            $vc++;
                        }
                    } elseif ('audio' == $attachment_type && $ac < $audio_limit) {
                        // Audio tags
                        $metadata_arr[] = '<meta property="og:audio" content="' . esc_url_raw(wp_get_attachment_url($attachment->ID)) . '" />';
                        if (is_ssl() || !is_ssl() && $options["has_https_access"] == "1") {
                            $metadata_arr[] = '<meta property="og:audio:secure_url" content="' . esc_url_raw(str_replace('http:', 'https:', wp_get_attachment_url($attachment->ID))) . '" />';
                        }
                        $metadata_arr[] = '<meta property="og:audio:type" content="' . esc_attr($mime_type) . '" />';
                        // Increase audio counter
                        $ac++;
                    }
                }
            }
            // Embedded Media
            foreach ($embedded_media['images'] as $embedded_item) {
                if ($ic == $image_limit) {
                    break;
                }
                $metadata_arr[] = '<meta property="og:image" content="' . esc_url_raw($embedded_item['image']) . '" />';
                $metadata_arr[] = '<meta property="og:image:secure_url" content="' . esc_url_raw(str_replace('http:', 'https:', $embedded_item['image'])) . '" />';
                if (apply_filters('amt_extended_image_tags', true)) {
                    $metadata_arr[] = '<meta property="og:image:width" content="' . esc_attr($embedded_item['width']) . '" />';
                    $metadata_arr[] = '<meta property="og:image:height" content="' . esc_attr($embedded_item['height']) . '" />';
                    $metadata_arr[] = '<meta property="og:image:type" content="image/jpeg" />';
                }
                // Images have been found.
                $has_images = true;
                // Increase image counter
                $ic++;
            }
            foreach ($embedded_media['videos'] as $embedded_item) {
                if ($options["og_omit_video_metadata"] != "1") {
                    if ($vc == $video_limit) {
                        break;
                    }
                    $metadata_arr[] = '<meta property="og:video" content="' . esc_url_raw($embedded_item['player']) . '" />';
                    $metadata_arr[] = '<meta property="og:video:secure_url" content="' . esc_url_raw(str_replace('http:', 'https:', $embedded_item['player'])) . '" />';
                    $metadata_arr[] = '<meta property="og:video:type" content="application/x-shockwave-flash" />';
                    $metadata_arr[] = '<meta property="og:video:width" content="' . esc_attr($embedded_item['width']) . '" />';
                    $metadata_arr[] = '<meta property="og:video:height" content="' . esc_attr($embedded_item['height']) . '" />';
                    // Increase video counter
                    $vc++;
                }
            }
            foreach ($embedded_media['sounds'] as $embedded_item) {
                if ($ac == $audio_limit) {
                    break;
                }
                $metadata_arr[] = '<meta property="og:audio" content="' . esc_url_raw($embedded_item['player']) . '" />';
                $metadata_arr[] = '<meta property="og:audio:secure_url" content="' . esc_url_raw(str_replace('http:', 'https:', $embedded_item['player'])) . '" />';
                $metadata_arr[] = '<meta property="og:audio:type" content="application/x-shockwave-flash" />';
                // Increase audio counter
                $ac++;
            }
            // If no images have been found so far use the default image, if set.
            if ($has_images === false) {
                // Use the default image, if one has been set.
                $image_data = amt_get_default_image_data();
                if (!empty($image_data)) {
                    $image_size = apply_filters('amt_image_size_content', 'full');
                    $image_meta_tags = amt_get_opengraph_image_metatags($options, $image_data, $size = $image_size);
                    if (!empty($image_meta_tags)) {
                        $metadata_arr = array_merge($metadata_arr, $image_meta_tags);
                    }
                }
                //$metadata_arr[] = '<meta property="og:image" content="' . esc_url_raw( $options["default_image_url"] ) . '" />';
                //if ( is_ssl() || ( ! is_ssl() && $options["has_https_access"] == "1" ) ) {
                //    $metadata_arr[] = '<meta property="og:image:secure_url" content="' . esc_url_raw( str_replace('http:', 'https:', $options["default_image_url"] ) ) . '" />';
                //}
            }
        }
        // og:referenced
        $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 property="og:referenced" content="' . esc_url_raw($referenced_url) . '" />';
            }
        }
        // Article: meta tags
        if ($og_type == 'article') {
            // Dates
            $metadata_arr[] = '<meta property="article:published_time" content="' . esc_attr(amt_iso8601_date($post->post_date)) . '" />';
            $metadata_arr[] = '<meta property="article:modified_time" content="' . esc_attr(amt_iso8601_date($post->post_modified)) . '" />';
            // Author
            // If a Facebook author profile URL has been provided, it has priority,
            // Otherwise fall back to the WordPress author archive.
            $fb_author_url = get_the_author_meta('amt_facebook_author_profile_url', $post->post_author);
            if (!empty($fb_author_url)) {
                $metadata_arr[] = '<meta property="article:author" content="' . esc_url_raw($fb_author_url, array('http', 'https', 'mailto')) . '" />';
            } else {
                //$metadata_arr[] = '<meta property="article:author" content="' . esc_url_raw( get_author_posts_url( get_the_author_meta( 'ID', $post->post_author ) ) ) . '" />';
                $metadata_arr[] = '<meta property="article:author" content="' . esc_url_raw(amt_get_local_author_profile_url(get_the_author_meta('ID', $post->post_author), $options)) . '" />';
            }
            // Publisher
            // If a Facebook publisher profile URL has been provided, it has priority.
            // Otherwise fall back to the WordPress blog home url.
            if (!empty($options['social_main_facebook_publisher_profile_url'])) {
                $metadata_arr[] = '<meta property="article:publisher" content="' . esc_url_raw($options['social_main_facebook_publisher_profile_url'], array('http', 'https', 'mailto')) . '" />';
            } else {
                $metadata_arr[] = '<meta property="article:publisher" content="' . esc_url_raw(trailingslashit(get_bloginfo('url'))) . '" />';
            }
            /*
            // article:section: We use the first category as the section.
            $first_cat = amt_get_first_category($post);
            if ( ! empty( $first_cat ) ) {
                $metadata_arr[] = '<meta property="article:section" content="' . esc_attr( $first_cat ) . '" />';
            }
            */
            // article:section: We use print an ``article:section`` meta tag for each of the post's categories.
            $categories = get_the_category($post->ID);
            $categories = apply_filters('amt_post_categories_for_opengraph', $categories);
            foreach ($categories as $cat) {
                $section = trim($cat->cat_name);
                if (!empty($section) && $cat->slug != 'uncategorized') {
                    $metadata_arr[] = '<meta property="article:section" content="' . esc_attr($section) . '" />';
                }
            }
            // article:tag: Keywords are listed as post tags
            $keywords = explode(',', amt_get_content_keywords($post, $auto = true, $exclude_categories = true));
            foreach ($keywords as $tag) {
                $tag = trim($tag);
                if (!empty($tag)) {
                    $metadata_arr[] = '<meta property="article:tag" content="' . esc_attr($tag) . '" />';
                }
            }
        } elseif ($og_type == 'video.other') {
            // Dates
            $metadata_arr[] = '<meta property="video:release_date" content="' . esc_attr(amt_iso8601_date($post->post_date)) . '" />';
            // video:tag: Keywords are listed as post tags
            $keywords = explode(',', amt_get_content_keywords($post));
            foreach ($keywords as $tag) {
                $tag = trim($tag);
                if (!empty($tag)) {
                    $metadata_arr[] = '<meta property="video:tag" content="' . esc_attr($tag) . '" />';
                }
            }
        } elseif ($og_type == 'product') {
            // Extend the current metadata with properties of the Product object.
            // See:
            //  * https://developers.facebook.com/docs/reference/opengraph/object-type/product/
            //  * https://developers.facebook.com/docs/payments/product
            $metadata_arr = apply_filters('amt_product_data_opengraph', $metadata_arr, $post);
        }
    }
    // Filtering of the generated Opengraph metadata
    $metadata_arr = apply_filters('amt_opengraph_metadata_head', $metadata_arr);
    return $metadata_arr;
}
Пример #3
0
/**
 * Return an array of Schema.org metatags suitable for the publisher object of
 * the content. Accepts the $post object as argument.
 */
function amt_get_jsonld_schemaorg_publisher_array($options, $author_id = null)
{
    $metadata_arr = array();
    // Schema.org type
    $metadata_arr['@type'] = 'Organization';
    // name
    $metadata_arr['name'] = esc_attr(get_bloginfo('name'));
    // description
    // First use the site description from the Add-Meta-Tags settings
    $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 (!empty($site_description)) {
        $metadata_arr['description'] = esc_attr($site_description);
    }
    // logo
    $image_data = amt_get_default_image_data();
    if (!empty($image_data)) {
        $image_size = apply_filters('amt_image_size_content', 'full');
        $image_meta_array = amt_get_jsonld_schemaorg_image_array($options, $image_data, $size = $image_size);
        if (!empty($image_meta_array)) {
            $metadata_arr['logo'] = array();
            $logo_obj = array();
            // Type
            $logo_obj['@type'] = 'ImageObject';
            // name (title)
            $logo_obj['name'] = esc_attr(get_bloginfo('name')) . ' ' . __('logo', 'add-meta-tags');
            // caption
            //$logo_obj['caption'] = esc_attr( rtrim(get_bloginfo('description'), '.') ) . '.';
            // alt
            $logo_obj['text'] = esc_attr(get_bloginfo('name')) . ' ' . __('logo', 'add-meta-tags');
            // Image URL & attributes
            $logo_obj = array_merge($logo_obj, $image_meta_array);
            // URL (links to web page containing the image)
            //$logo_obj['url'] = esc_url( $options["default_image_url"] );
            // thumbnail url
            //$logo_obj['thumbnailUrl'] = esc_url( ... );
            // main image
            //$logo_obj['contentUrl'] = esc_url( $options["default_image_url"] );
            //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" />';
            //}
            // Add logo entity to metadata
            $metadata_arr['logo'][] = $logo_obj;
        }
    }
    ////if ( ! empty($options["default_image_url"]) ) {
    ////$metadata_arr['logo'] = array();
    ////$logo_obj = array();
    // Type
    ////$logo_obj['@type'] = 'ImageObject';
    // name (title)
    ////$logo_obj['name'] = esc_attr( get_bloginfo('name') ) . ' ' . __('logo', 'add-meta-tags');
    // caption
    //$logo_obj['caption'] = esc_attr( rtrim(get_bloginfo('description'), '.') ) . '.';
    // alt
    ////$logo_obj['text'] = esc_attr( get_bloginfo('name') ) . ' ' . __('logo', 'add-meta-tags');
    // URL (links to web page containing the image)
    ////$logo_obj['url'] = esc_url( $options["default_image_url"] );
    // thumbnail url
    //$logo_obj['thumbnailUrl'] = esc_url( ... );
    // main image
    ////$logo_obj['contentUrl'] = esc_url( $options["default_image_url"] );
    //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" />';
    //}
    // Add logo entity to metadata
    ////$metadata_arr['logo'][] = $logo_obj;
    ////}
    // url
    // The blog url is used by default. Google+, Facebook and Twitter profile URLs are added as sameAs.
    $metadata_arr['url'] = esc_url_raw(trailingslashit(get_bloginfo('url')));
    // sameAs
    $metadata_arr['sameAs'] = array();
    // Social Profile Links are added as sameAs properties
    // By default, those of the Publisher Settings  are used.
    // WARNING: Publisher profile URLs from the user profile page are now deprecated.
    // Google+ Publisher
    if (!empty($options['social_main_googleplus_publisher_profile_url'])) {
        $metadata_arr['sameAs'][] = esc_url_raw($options['social_main_googleplus_publisher_profile_url'], array('http', 'https'));
    }
    // Facebook
    if (!empty($options['social_main_facebook_publisher_profile_url'])) {
        $metadata_arr['sameAs'][] = esc_url_raw($options['social_main_facebook_publisher_profile_url'], array('http', 'https'));
    }
    // Twitter
    if (!empty($options['social_main_twitter_publisher_username'])) {
        $metadata_arr['sameAs'][] = 'https://twitter.com/' . esc_attr($options['social_main_twitter_publisher_username']);
    }
    // Allow filtering of the Publisher meta tags
    $metadata_arr = apply_filters('amt_jsonld_schemaorg_publisher_extra', $metadata_arr);
    return $metadata_arr;
}
/**
 * Generate Twitter Cards metadata for the content pages.
 */
function amt_add_twitter_cards_metadata_head($post, $attachments, $embedded_media, $options)
{
    if (apply_filters('amt_exclude_twitter_cards_metadata', false)) {
        return array();
    }
    $do_auto_twitter = $options["auto_twitter"] == "1" ? true : false;
    if (!$do_auto_twitter) {
        return array();
    }
    $metadata_arr = array();
    // Custom content override
    if (amt_is_custom($post, $options)) {
        // Return metadata with:
        // add_filter( 'amt_custom_metadata_twitter_cards', '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_twitter_cards', $metadata_arr, $post, $options, $attachments, $embedded_media);
        return $metadata_arr;
    }
    // Front page and archives
    if (!is_singular() && !amt_is_static_home() && !amt_is_static_front_page() || amt_is_default_front_page() || is_category() || is_tag() || is_tax() || is_post_type_archive()) {
        // Note1: is_front_page() is used for the case in which a static page is used as the front page.
        // Note2: product groups should pass the is_tax() validation, so no need for
        // amt_is_product_group(). We do not support other product groups.
        // Default front page containing latest posts
        // Add a basic Twitter Card to the default home page that contains latest posts.
        // If static pages are used as the front page or the latest-posts page,
        // then they are treated as content and are processed below.
        if (amt_is_default_front_page()) {
            // Generate the card only if a publisher username has been set in the publisher settings
            if (!empty($options['social_main_twitter_publisher_username'])) {
                // Type
                $metadata_arr[] = '<meta name="twitter:card" content="' . amt_get_default_twitter_card_type($options) . '" />';
                // Creator
                $metadata_arr[] = '<meta name="twitter:creator" content="@' . esc_attr($options['social_main_twitter_publisher_username']) . '" />';
                // Publisher
                $metadata_arr[] = '<meta name="twitter:site" content="@' . esc_attr($options['social_main_twitter_publisher_username']) . '" />';
                // Title
                // Note: Contains multipage information
                $metadata_arr['twitter:title'] = '<meta name="twitter:title" content="' . esc_attr(amt_get_title_for_metadata($options, $post)) . '" />';
                // Site description - Note: Contains multipage information through amt_process_paged()
                $site_description = amt_get_site_description($options);
                if (empty($site_description)) {
                    $site_description = get_bloginfo('description');
                }
                if (!empty($site_description)) {
                    $metadata_arr[] = '<meta name="twitter:description" content="' . esc_attr(amt_process_paged($site_description)) . '" />';
                }
                // Image. Use the default image (if set).
                $image_data = amt_get_default_image_data();
                if (!empty($image_data)) {
                    $image_size = apply_filters('amt_image_size_index', 'full');
                    $image_meta_tags = amt_get_twitter_cards_image_metatags($options, $image_data, $size = $image_size);
                    if (!empty($image_meta_tags)) {
                        $metadata_arr = array_merge($metadata_arr, $image_meta_tags);
                    }
                }
                //$image_url = apply_filters( 'amt_twitter_cards_image_url_index', $options["default_image_url"] );
                //$metadata_arr[] = '<meta name="twitter:image" content="' . esc_url_raw( $image_url ) . '" />';
            }
            // Taxonomy archives
            // Note: product groups should pass the is_tax() validation, so no need for
            // amt_is_product_group(). We do not support other product groups.
        } elseif (is_category() || is_tag() || 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);
            // Generate the card only if a publisher username has been set in the publisher settings
            if (!empty($options['social_main_twitter_publisher_username'])) {
                // Type
                $metadata_arr[] = '<meta name="twitter:card" content="' . amt_get_default_twitter_card_type($options) . '" />';
                // Creator
                $metadata_arr[] = '<meta name="twitter:creator" content="@' . esc_attr($options['social_main_twitter_publisher_username']) . '" />';
                // Publisher
                $metadata_arr[] = '<meta name="twitter:site" content="@' . esc_attr($options['social_main_twitter_publisher_username']) . '" />';
                // Title
                // Note: Contains multipage information
                $metadata_arr['twitter:title'] = '<meta name="twitter:title" content="' . esc_attr(amt_get_title_for_metadata($options, $post)) . '" />';
                // 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.
                    // Filter name
                    if (is_category()) {
                        $generic_description = apply_filters('amt_generic_description_category_archive', __('Content filed under the %s category.', 'add-meta-tags'));
                    } elseif (is_tag()) {
                        $generic_description = apply_filters('amt_generic_description_tag_archive', __('Content tagged with %s.', 'add-meta-tags'));
                    } elseif (is_tax()) {
                        // 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
                        $generic_description = apply_filters($taxonomy_description_filter_name, __('Content filed under the %s taxonomy.', 'add-meta-tags'));
                    }
                    // Final generic description
                    $generic_description = sprintf($generic_description, single_term_title($prefix = '', $display = false));
                    $metadata_arr[] = '<meta name="twitter:description" content="' . esc_attr(amt_process_paged($generic_description)) . '" />';
                } else {
                    $metadata_arr[] = '<meta name="twitter:description" content="' . esc_attr(amt_process_paged($description_content)) . '" />';
                }
                // Image
                // Use an image from the 'Global image override' field.
                // Otherwise, use a user defined image via filter.
                // Otherwise use default image.
                $image_data = amt_get_image_data(amt_get_term_meta_image_url($tax_term_object->term_id));
                if (!empty($image_data)) {
                    $image_size = apply_filters('amt_image_size_index', 'full');
                    $image_meta_tags = amt_get_twitter_cards_image_metatags($options, $image_data, $size = $image_size);
                    if (!empty($image_meta_tags)) {
                        $metadata_arr = array_merge($metadata_arr, $image_meta_tags);
                    }
                } else {
                    // First filter using a term/taxonomy agnostic filter name.
                    $taxonomy_image_url = apply_filters('amt_taxonomy_force_image_url', '', $tax_term_object);
                    if (empty($taxonomy_image_url)) {
                        // Second filter (term/taxonomy dependent).
                        // Construct the filter name. Template: ``amt_taxonomy_image_url_TAXONOMYSLUG_TERMSLUG``
                        $taxonomy_image_url_filter_name = sprintf('amt_taxonomy_image_url_%s_%s', $tax_term_object->taxonomy, $tax_term_object->slug);
                        //var_dump($taxonomy_image_url_filter_name);
                        // The default image, if set, is used by default.
                        $taxonomy_image_url = apply_filters($taxonomy_image_url_filter_name, $options["default_image_url"]);
                    }
                    if (!empty($taxonomy_image_url)) {
                        $image_data = amt_get_image_data($taxonomy_image_url);
                        if (!empty($image_data)) {
                            $image_size = apply_filters('amt_image_size_index', 'full');
                            $image_meta_tags = amt_get_twitter_cards_image_metatags($options, $image_data, $size = $image_size);
                            if (!empty($image_meta_tags)) {
                                $metadata_arr = array_merge($metadata_arr, $image_meta_tags);
                            }
                        }
                        //$metadata_arr[] = '<meta name="twitter:image" content="' . esc_url_raw( $taxonomy_image_url ) . '" />';
                    }
                }
            }
            // Custom Post type Archives
        } 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);
            // Generate the card only if a publisher username has been set in the publisher settings
            if (!empty($options['social_main_twitter_publisher_username'])) {
                // Type
                $metadata_arr[] = '<meta name="twitter:card" content="' . amt_get_default_twitter_card_type($options) . '" />';
                // Creator
                $metadata_arr[] = '<meta name="twitter:creator" content="@' . esc_attr($options['social_main_twitter_publisher_username']) . '" />';
                // Publisher
                $metadata_arr[] = '<meta name="twitter:site" content="@' . esc_attr($options['social_main_twitter_publisher_username']) . '" />';
                // Title
                // Note: Contains multipage information
                $metadata_arr['twitter:title'] = '<meta name="twitter:title" content="' . esc_attr(amt_get_title_for_metadata($options, $post)) . '" />';
                // 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[] = '<meta name="twitter:description" content="' . esc_attr(amt_process_paged($generic_description)) . '" />';
                // Image
                // Use a user defined image via filter. Otherwise use default image.
                // First filter using a term/taxonomy agnostic filter name.
                $posttype_image_url = apply_filters('amt_posttype_force_image_url', '', $post_type_object);
                if (empty($posttype_image_url)) {
                    // Second filter (post type dependent).
                    // Construct the filter name. Template: ``amt_posttype_image_url_POSTTYPESLUG``
                    $posttype_image_url_filter_name = sprintf('amt_posttype_image_url_%s', $post_type_object->name);
                    //var_dump($posttype_image_url_filter_name);
                    // The default image, if set, is used by default.
                    $posttype_image_url = apply_filters($posttype_image_url_filter_name, $options["default_image_url"]);
                }
                if (!empty($posttype_image_url)) {
                    $image_data = amt_get_image_data($posttype_image_url);
                    if (!empty($image_data)) {
                        $image_size = apply_filters('amt_image_size_index', 'full');
                        $image_meta_tags = amt_get_twitter_cards_image_metatags($options, $image_data, $size = $image_size);
                        if (!empty($image_meta_tags)) {
                            $metadata_arr = array_merge($metadata_arr, $image_meta_tags);
                        }
                    }
                    //$metadata_arr[] = '<meta name="twitter:image" content="' . esc_url_raw( $posttype_image_url ) . '" />';
                }
            }
        }
        return $metadata_arr;
    }
    // Further check (required in some reported cases)
    // Go no further if the content type does not validate is_singular().
    if (!is_singular()) {
        return array();
    }
    // Products
    // A 'product' Twitter Card is generated. See: https://dev.twitter.com/cards/types/product
    if (amt_is_product()) {
        // Type
        $metadata_arr[] = '<meta name="twitter:card" content="product" />';
        // Author and Publisher
        $metadata_arr = array_merge($metadata_arr, amt_get_twitter_cards_author_publisher_metatags($options, $post));
        // Title
        // Note: Contains multipage information
        //$metadata_arr[] = '<meta name="twitter:title" content="' . esc_attr( amt_process_paged( strip_tags( get_the_title($post->ID) ) ) ) . '" />';
        $metadata_arr['twitter:title'] = '<meta name="twitter:title" content="' . esc_attr(amt_get_title_for_metadata($options, $post)) . '" />';
        // 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 name="twitter:description" content="' . esc_attr(amt_process_paged($content_desc)) . '" />';
        }
        // Image
        // Use the featured image or the default image as a fallback.
        // Set to true if image meta tags have been added to the card, so that it does not
        // search for any more images.
        $image_metatags_added = false;
        // First check if a global image override URL has been entered.
        // If yes, use this image URL and override all other images.
        $image_data = amt_get_image_data(amt_get_post_meta_image_url($post->ID));
        if (!empty($image_data)) {
            $image_size = apply_filters('amt_image_size_product', 'full');
            $image_meta_tags = amt_get_twitter_cards_image_metatags($options, $image_data, $size = $image_size);
            if (!empty($image_meta_tags)) {
                $metadata_arr = array_merge($metadata_arr, $image_meta_tags);
            }
            //$global_image_override_url = amt_get_post_meta_image_url($post->ID);
            //if ( $image_metatags_added === false && ! empty( $global_image_override_url ) ) {
            //    $metadata_arr[] = '<meta name="twitter:image" content="' . esc_url_raw( $global_image_override_url ) . '" />';
            // Images have been found.
            $image_metatags_added = true;
        }
        // Set the image size to use
        $image_size = apply_filters('amt_image_size_product', 'full');
        // If the content has a featured image, then we use it.
        if ($image_metatags_added === false && function_exists('has_post_thumbnail') && has_post_thumbnail($post->ID)) {
            $main_size_meta = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), $image_size);
            $metadata_arr[] = '<meta name="twitter:image" content="' . esc_url_raw($main_size_meta[0]) . '" />';
            if (apply_filters('amt_extended_image_tags', true)) {
                $metadata_arr[] = '<meta name="twitter:image:width" content="' . esc_attr($main_size_meta[1]) . '" />';
                $metadata_arr[] = '<meta name="twitter:image:height" content="' . esc_attr($main_size_meta[2]) . '" />';
            }
            // Images have been found.
            $image_metatags_added = true;
        }
        // If an image is still missing, then use the default image (if set).
        if ($image_metatags_added === false) {
            $image_data = amt_get_default_image_data();
            if (!empty($image_data)) {
                //$image_size = apply_filters( 'amt_image_size_index', 'full' );
                $image_meta_tags = amt_get_twitter_cards_image_metatags($options, $image_data, $size = $image_size);
                if (!empty($image_meta_tags)) {
                    $metadata_arr = array_merge($metadata_arr, $image_meta_tags);
                }
            }
            //$metadata_arr[] = '<meta name="twitter:image" content="' . esc_url_raw( $options["default_image_url"] ) . '" />';
        }
        //
        // The Product Twitter Card needs to be extended with the following required
        // in order to be valid: label1, data1, label2, data2
        //
        // For instance:
        //<meta name="twitter:label1" content="Genre">
        //<meta name="twitter:data1" content="Classic Rock">
        //<meta name="twitter:label2" content="Location">
        //<meta name="twitter:data2" content="National">
        //
        // The following filter is provided.
        // Filtering of the generated Twitter Cards metadata. $post is also passed.
        $metadata_arr = apply_filters('amt_product_data_twitter_cards', $metadata_arr, $post);
        // Attachments
    } 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);
        // Images
        if ('image' == $attachment_type) {
            // $post is an image attachment
            // Image attachments
            //$image_meta = wp_get_attachment_metadata( $post->ID );   // contains info about all sizes
            // We use wp_get_attachment_image_src() since it constructs the URLs
            // Allow filtering of the image size.
            $image_size = apply_filters('amt_image_size_attachment', 'full');
            $main_size_meta = wp_get_attachment_image_src($post->ID, $image_size);
            // Type
            $metadata_arr[] = '<meta name="twitter:card" content="photo" />';
            // Author and Publisher
            $metadata_arr = array_merge($metadata_arr, amt_get_twitter_cards_author_publisher_metatags($options, $post));
            // Title
            $metadata_arr['twitter:title'] = '<meta name="twitter:title" content="' . esc_attr(amt_get_title_for_metadata($options, $post)) . '" />';
            // Description - We use the description defined by Add-Meta-Tags
            $content_desc = amt_get_content_description($post);
            if (!empty($content_desc)) {
                $metadata_arr[] = '<meta name="twitter:description" content="' . esc_attr($content_desc) . '" />';
            }
            // Image
            $metadata_arr[] = '<meta name="twitter:image" content="' . esc_url_raw($main_size_meta[0]) . '" />';
            if (apply_filters('amt_extended_image_tags', true)) {
                $metadata_arr[] = '<meta name="twitter:image:width" content="' . esc_attr($main_size_meta[1]) . '" />';
                $metadata_arr[] = '<meta name="twitter:image:height" content="' . esc_attr($main_size_meta[2]) . '" />';
            }
            // Audio & Video
        } elseif ($options["tc_enable_player_card_local"] == "1" && in_array($attachment_type, array('video', 'audio'))) {
            // Create player card for local video and audio attachments.
            // $post is an audio or video attachment
            // Type
            $metadata_arr[] = '<meta name="twitter:card" content="player" />';
            // Author and Publisher
            $metadata_arr = array_merge($metadata_arr, amt_get_twitter_cards_author_publisher_metatags($options, $post));
            // Title
            $metadata_arr['twitter:title'] = '<meta name="twitter:title" content="' . esc_attr(amt_get_title_for_metadata($options, $post)) . '" />';
            // Description - We use the description defined by Add-Meta-Tags
            $content_desc = amt_get_content_description($post);
            if (!empty($content_desc)) {
                $metadata_arr[] = '<meta name="twitter:description" content="' . esc_attr($content_desc) . '" />';
            }
            // twitter:player
            $metadata_arr[] = sprintf('<meta name="twitter:player" content="%s" />', esc_url_raw(amt_make_https(amt_embed_get_container_url($post->ID))));
            // Player size
            if ('video' == $attachment_type) {
                // Player size (this should be considered irrelevant of the video size)
                $player_size = apply_filters('amt_twitter_cards_video_player_size', array(640, 480));
            } elseif ('audio' == $attachment_type) {
                $player_size = apply_filters('amt_twitter_cards_audio_player_size', array(320, 30));
            }
            // twitter:player:width
            $metadata_arr[] = sprintf('<meta name="twitter:player:width" content="%d" />', esc_attr($player_size[0]));
            // twitter:player:height
            $metadata_arr[] = sprintf('<meta name="twitter:player:height" content="%d" />', esc_attr($player_size[1]));
            // twitter:image
            $preview_image_url = amt_embed_get_preview_image($post->ID);
            if (!empty($preview_image_url)) {
                $metadata_arr[] = '<meta name="twitter:image" content="' . esc_url_raw(amt_make_https($preview_image_url)) . '" />';
            }
            // twitter:player:stream
            $metadata_arr[] = '<meta name="twitter:player:stream" content="' . esc_url_raw(amt_make_https(amt_embed_get_stream_url($post->ID))) . '" />';
            // twitter:player:stream:content_type
            $metadata_arr[] = '<meta name="twitter:player:stream:content_type" content="' . esc_attr($mime_type) . '" />';
            //$metadata_arr[] = '<meta name="twitter:player:stream:content_type" content="video/mp4; codecs=&quot;avc1.42E01E1, mp4a.40.2&quot;">';
        }
        // Content
        // - standard format (post_format === false), aside, link, quote, status, chat (create summary card or summary_large_image if enforced)
        // - photo format (creates (summary_large_image card)
    } elseif (get_post_format($post->ID) === false || in_array(get_post_format($post->ID), array('image', 'aside', 'link', 'quote', 'status', 'chat'))) {
        // Render a summary card if standard format (or summary_large_image if enforced).
        // Render a summary_large_image card if image format.
        // Type
        if (get_post_format($post->ID) === false || in_array(get_post_format($post->ID), array('aside', 'link', 'quote', 'status', 'chat'))) {
            $metadata_arr[] = '<meta name="twitter:card" content="' . amt_get_default_twitter_card_type($options) . '" />';
            // Set the image size to use
            $image_size = apply_filters('amt_image_size_content', 'full');
        } elseif (get_post_format($post->ID) == 'image') {
            $metadata_arr[] = '<meta name="twitter:card" content="summary_large_image" />';
            // Set the image size to use
            // Since we need a bigger image, here we filter the image size through 'amt_image_size_attachment',
            // which typically returns a size bigger than 'amt_image_size_content'.
            $image_size = apply_filters('amt_image_size_attachment', 'full');
        }
        // Author and Publisher
        $metadata_arr = array_merge($metadata_arr, amt_get_twitter_cards_author_publisher_metatags($options, $post));
        // Title
        // Note: Contains multipage information
        $metadata_arr['twitter:title'] = '<meta name="twitter:title" content="' . esc_attr(amt_get_title_for_metadata($options, $post)) . '" />';
        // 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 name="twitter:description" content="' . esc_attr(amt_process_paged($content_desc)) . '" />';
        }
        // Image
        // Use the FIRST image ONLY
        // Set to true if image meta tags have been added to the card, so that it does not
        // search for any more images.
        $image_metatags_added = false;
        // First check if a global image override URL has been entered.
        // If yes, use this image URL and override all other images.
        $image_data = amt_get_image_data(amt_get_post_meta_image_url($post->ID));
        if (!empty($image_data)) {
            $image_size = apply_filters('amt_image_size_content', 'full');
            $image_meta_tags = amt_get_twitter_cards_image_metatags($options, $image_data, $size = $image_size);
            if (!empty($image_meta_tags)) {
                $metadata_arr = array_merge($metadata_arr, $image_meta_tags);
            }
            //$global_image_override_url = amt_get_post_meta_image_url($post->ID);
            //if ( $image_metatags_added === false && ! empty( $global_image_override_url ) ) {
            //    $metadata_arr[] = '<meta name="twitter:image" content="' . esc_url_raw( $global_image_override_url ) . '" />';
            // Images have been found.
            $image_metatags_added = true;
        }
        // If the content has a featured image, then we use it.
        if ($image_metatags_added === false && function_exists('has_post_thumbnail') && has_post_thumbnail($post->ID)) {
            $main_size_meta = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), $image_size);
            $metadata_arr[] = '<meta name="twitter:image:src" content="' . esc_url_raw($main_size_meta[0]) . '" />';
            if (apply_filters('amt_extended_image_tags', true)) {
                $metadata_arr[] = '<meta name="twitter:image:width" content="' . esc_attr($main_size_meta[1]) . '" />';
                $metadata_arr[] = '<meta name="twitter:image:height" content="' . esc_attr($main_size_meta[2]) . '" />';
            }
            // Images have been found.
            $image_metatags_added = true;
        }
        // If a featured image is not set for this content, try to find the first image
        if ($image_metatags_added === false) {
            // Process all attachments and add metatags for the first image.
            foreach ($attachments as $attachment) {
                $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) {
                    // Image tags
                    $main_size_meta = wp_get_attachment_image_src($attachment->ID, $image_size);
                    $metadata_arr[] = '<meta name="twitter:image:src" content="' . esc_url_raw($main_size_meta[0]) . '" />';
                    if (apply_filters('amt_extended_image_tags', true)) {
                        $metadata_arr[] = '<meta name="twitter:image:width" content="' . esc_attr($main_size_meta[1]) . '" />';
                        $metadata_arr[] = '<meta name="twitter:image:height" content="' . esc_attr($main_size_meta[2]) . '" />';
                    }
                    // Images have been found.
                    $image_metatags_added = true;
                    // If an image is added, break.
                    break;
                }
            }
        }
        // If a local image-attachment is not set, try to find any embedded images
        if ($image_metatags_added === false) {
            // Embedded Media
            foreach ($embedded_media['images'] as $embedded_item) {
                if (get_post_format($post->ID) === false || in_array(get_post_format($post->ID), array('aside', 'link', 'quote', 'status', 'chat'))) {
                    $metadata_arr[] = '<meta name="twitter:image:src" content="' . esc_url_raw($embedded_item['thumbnail']) . '" />';
                    if (apply_filters('amt_extended_image_tags', true)) {
                        $metadata_arr[] = '<meta name="twitter:image:width" content="150" />';
                        $metadata_arr[] = '<meta name="twitter:image:height" content="150" />';
                    }
                } elseif (get_post_format($post->ID) == 'image') {
                    $metadata_arr[] = '<meta name="twitter:image:src" content="' . esc_url_raw($embedded_item['image']) . '" />';
                    if (apply_filters('amt_extended_image_tags', true)) {
                        $metadata_arr[] = '<meta name="twitter:image:width" content="' . esc_attr($embedded_item['width']) . '" />';
                        $metadata_arr[] = '<meta name="twitter:image:height" content="' . esc_attr($embedded_item['height']) . '" />';
                    }
                }
                // Images have been found.
                $image_metatags_added = true;
                // If an image is added, break.
                break;
            }
        }
        // If an image is still missing, then use the default image (if set).
        if ($image_metatags_added === false) {
            $image_data = amt_get_default_image_data();
            if (!empty($image_data)) {
                // Image size already set
                //$image_size = apply_filters( 'amt_image_size_index', 'full' );
                $image_meta_tags = amt_get_twitter_cards_image_metatags($options, $image_data, $size = $image_size);
                if (!empty($image_meta_tags)) {
                    $metadata_arr = array_merge($metadata_arr, $image_meta_tags);
                }
            }
            //$metadata_arr[] = '<meta name="twitter:image" content="' . esc_url_raw( $options["default_image_url"] ) . '" />';
        }
        // Content
        // - gallery format (creates gallery card)
    } elseif (get_post_format($post->ID) == 'gallery') {
        // Render a gallery card if gallery format.
        // Type
        $metadata_arr[] = '<meta name="twitter:card" content="gallery" />';
        // Author and Publisher
        $metadata_arr = array_merge($metadata_arr, amt_get_twitter_cards_author_publisher_metatags($options, $post));
        // Title
        // Note: Contains multipage information
        $metadata_arr['twitter:title'] = '<meta name="twitter:title" content="' . esc_attr(amt_get_title_for_metadata($options, $post)) . '" />';
        // 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 name="twitter:description" content="' . esc_attr(amt_process_paged($content_desc)) . '" />';
        }
        // Image
        // Set to true if image meta tags have been added to the card, so that it does not
        // search for any more images.
        $image_metatags_added = false;
        // First check if a global image override URL has been entered.
        // If yes, use this image URL and override all other images.
        $image_data = amt_get_image_data(amt_get_post_meta_image_url($post->ID));
        if (!empty($image_data)) {
            $image_size = apply_filters('amt_image_size_content', 'full');
            $image_meta_tags = amt_get_twitter_cards_image_metatags($options, $image_data, $size = $image_size);
            if (!empty($image_meta_tags)) {
                $metadata_arr = array_merge($metadata_arr, $image_meta_tags);
            }
            //$global_image_override_url = amt_get_post_meta_image_url($post->ID);
            //if ( $image_metatags_added === false && ! empty( $global_image_override_url ) ) {
            // Note 'image0'
            //    $metadata_arr[] = '<meta name="twitter:image0" content="' . esc_url_raw( $global_image_override_url ) . '" />';
            // Images have been found.
            $image_metatags_added = true;
        }
        // Build the gallery
        if ($image_metatags_added === false) {
            // Image counter
            $k = 0;
            // Process all attachments and add metatags for the first image
            foreach ($attachments as $attachment) {
                $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) {
                    // Image tags
                    // Allow filtering of the image size.
                    $image_size = apply_filters('amt_image_size_content', 'full');
                    $main_size_meta = wp_get_attachment_image_src($attachment->ID, $image_size);
                    $metadata_arr[] = '<meta name="twitter:image' . $k . '" content="' . esc_url_raw($main_size_meta[0]) . '" />';
                    // Increment the counter
                    $k++;
                }
            }
            // Embedded Media
            foreach ($embedded_media['images'] as $embedded_item) {
                $metadata_arr[] = '<meta name="twitter:image' . $k . '" content="' . esc_url_raw($embedded_item['image']) . '" />';
                // Increment the counter
                $k++;
            }
        }
        // Content
        // - video/audio format (creates player card)
        // Note: The ``tc_enable_player_card_local`` option is checked after this initial check,
        // because 'player' twitter cards are always generated for embedded audio and video.
    } elseif (get_post_format($post->ID) == 'video' || get_post_format($post->ID) == 'audio') {
        $post_format = get_post_format($post->ID);
        $audio_video_metatags_complete = false;
        // Process local media only if it is allowed by the user.
        if ($audio_video_metatags_complete === false && $options["tc_enable_player_card_local"] == "1") {
            // Local media - Process all attachments and add metatags for the first video
            foreach ($attachments as $attachment) {
                $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);
                // Get attachment metadata from WordPress
                $attachment_metadata = wp_get_attachment_metadata($attachment->ID);
                // We create player cards for video and audio attachments.
                // The post might have attachments of other types.
                if (!in_array($attachment_type, array('video', 'audio'))) {
                    continue;
                } elseif ($attachment_type != $post_format) {
                    continue;
                }
                // Render a player card for the first attached audio or video.
                // twitter:card
                $metadata_arr[] = '<meta name="twitter:card" content="player" />';
                // Author and Publisher
                $metadata_arr = array_merge($metadata_arr, amt_get_twitter_cards_author_publisher_metatags($options, $post));
                // twitter:title
                // Title - Note: Contains multipage information
                $metadata_arr['twitter:title'] = '<meta name="twitter:title" content="' . esc_attr(amt_get_title_for_metadata($options, $post)) . '" />';
                // twitter:description
                // 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 name="twitter:description" content="' . esc_attr(amt_process_paged($content_desc)) . '" />';
                }
                // twitter:player
                $metadata_arr[] = sprintf('<meta name="twitter:player" content="%s" />', esc_url_raw(amt_make_https(amt_embed_get_container_url($attachment->ID))));
                // Player size
                if ($post_format == 'video') {
                    // Player size (this should be considered irrelevant of the video size)
                    $player_size = apply_filters('amt_twitter_cards_video_player_size', array(640, 480));
                } elseif ($post_format == 'audio') {
                    $player_size = apply_filters('amt_twitter_cards_audio_player_size', array(320, 30));
                }
                // twitter:player:width
                $metadata_arr[] = sprintf('<meta name="twitter:player:width" content="%d" />', esc_attr($player_size[0]));
                // twitter:player:height
                $metadata_arr[] = sprintf('<meta name="twitter:player:height" content="%d" />', esc_attr($player_size[1]));
                // twitter:player:stream
                $metadata_arr[] = '<meta name="twitter:player:stream" content="' . esc_url_raw(amt_make_https(amt_embed_get_stream_url($attachment->ID))) . '" />';
                // twitter:player:stream:content_type
                $metadata_arr[] = '<meta name="twitter:player:stream:content_type" content="' . esc_attr($mime_type) . '" />';
                //$metadata_arr[] = '<meta name="twitter:player:stream:content_type" content="video/mp4; codecs=&quot;avc1.42E01E1, mp4a.40.2&quot;">';
                // twitter:image
                // First check if a global image override URL has been set in the post's metabox.
                // If yes, use this image URL and override all other images.
                $image_data = amt_get_image_data(amt_get_post_meta_image_url($post->ID));
                if (!empty($image_data)) {
                    $image_size = apply_filters('amt_image_size_content', 'full');
                    $image_meta_tags = amt_get_twitter_cards_image_metatags($options, $image_data, $size = $image_size);
                    if (!empty($image_meta_tags)) {
                        $metadata_arr = array_merge($metadata_arr, $image_meta_tags);
                    }
                    //$global_image_override_url = amt_get_post_meta_image_url($post->ID);
                    //if ( ! empty( $global_image_override_url ) ) {
                    //    $metadata_arr[] = '<meta name="twitter:image" content="' . esc_url_raw( $global_image_override_url ) . '" />';
                    // Else use the featured image if it exists
                } elseif (function_exists('has_post_thumbnail') && has_post_thumbnail($post->ID)) {
                    // Set the image size to use
                    $image_size = apply_filters('amt_image_size_content', 'full');
                    $main_size_meta = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), $image_size);
                    $metadata_arr[] = '<meta name="twitter:image" content="' . esc_url_raw($main_size_meta[0]) . '" />';
                    //if ( apply_filters( 'amt_extended_image_tags', true ) ) {
                    //    $metadata_arr[] = '<meta name="twitter:image:width" content="' . esc_attr( $main_size_meta[1] ) . '" />';
                    //    $metadata_arr[] = '<meta name="twitter:image:height" content="' . esc_attr( $main_size_meta[2] ) . '" />';
                    //}
                    // Else use the attachment's featured image, if set.
                } else {
                    // Else use the attachment's featured image, if set.
                    $image_data = amt_embed_get_preview_image($attachment->ID);
                    if (!empty($image_data)) {
                        $image_size = apply_filters('amt_image_size_content', 'full');
                        $image_meta_tags = amt_get_twitter_cards_image_metatags($options, $image_data, $size = $image_size);
                        if (!empty($image_meta_tags)) {
                            $metadata_arr = array_merge($metadata_arr, $image_meta_tags);
                        }
                    }
                    //$preview_image_url = amt_embed_get_preview_image( $attachment->ID );
                    //if ( ! empty( $preview_image_url ) ) {
                    //    $metadata_arr[] = '<meta name="twitter:image" content="' . esc_url_raw( amt_make_https( $preview_image_url ) ) . '" />';
                    //}
                }
                $audio_video_metatags_complete = true;
                break;
            }
        }
        // Process embedded media only if a twitter player card has not been generated.
        if ($audio_video_metatags_complete === false) {
            // Determine the relevant array (videos or sounds)
            if ($post_format == 'video') {
                $embedded_items = $embedded_media['videos'];
            } elseif ($post_format == 'audio') {
                $embedded_items = $embedded_media['sounds'];
            }
            // Embedded Media
            foreach ($embedded_items as $embedded_item) {
                // Render a player card for the first embedded video.
                // twitter:card
                $metadata_arr[] = '<meta name="twitter:card" content="player" />';
                // Author and Publisher
                $metadata_arr = array_merge($metadata_arr, amt_get_twitter_cards_author_publisher_metatags($options, $post));
                // twitter:title
                // Title - Note: Contains multipage information
                $metadata_arr['twitter:title'] = '<meta name="twitter:title" content="' . esc_attr(amt_get_title_for_metadata($options, $post)) . '" />';
                // twitter:description
                // 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 name="twitter:description" content="' . esc_attr(amt_process_paged($content_desc)) . '" />';
                }
                // twitter:player
                $metadata_arr[] = '<meta name="twitter:player" content="' . esc_url_raw($embedded_item['player']) . '" />';
                // Player size
                // Alt Method: Size uses  $content_width
                //global $content_width;
                //$width = $content_width;
                //$height = absint(absint($content_width)*3/4);
                //$metadata_arr[] = '<meta name="twitter:width" content="' . esc_attr( $width ) . '" />';
                //$metadata_arr[] = '<meta name="twitter:height" content="' . esc_attr( $height ) . '" />';
                // twitter:player:width
                $metadata_arr[] = sprintf('<meta name="twitter:player:width" content="%d" />', esc_attr($embedded_item['width']));
                // twitter:player:height
                $metadata_arr[] = sprintf('<meta name="twitter:player:height" content="%d" />', esc_attr($embedded_item['height']));
                // twitter:image
                // First check if a global image override URL has been set in the post's metabox.
                // If yes, use this image URL and override all other images.
                $image_data = amt_get_image_data(amt_get_post_meta_image_url($post->ID));
                if (!empty($image_data)) {
                    $image_size = apply_filters('amt_image_size_content', 'full');
                    $image_meta_tags = amt_get_twitter_cards_image_metatags($options, $image_data, $size = $image_size);
                    if (!empty($image_meta_tags)) {
                        $metadata_arr = array_merge($metadata_arr, $image_meta_tags);
                    }
                    //$global_image_override_url = amt_get_post_meta_image_url($post->ID);
                    //if ( ! empty( $global_image_override_url ) ) {
                    //    $metadata_arr[] = '<meta name="twitter:image" content="' . esc_url_raw( $global_image_override_url ) . '" />';
                    // Else use the featured image if it exists
                } elseif (function_exists('has_post_thumbnail') && has_post_thumbnail($post->ID)) {
                    // Set the image size to use
                    $image_size = apply_filters('amt_image_size_content', 'full');
                    $main_size_meta = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), $image_size);
                    $metadata_arr[] = '<meta name="twitter:image" content="' . esc_url_raw($main_size_meta[0]) . '" />';
                    //if ( apply_filters( 'amt_extended_image_tags', true ) ) {
                    //    $metadata_arr[] = '<meta name="twitter:image:width" content="' . esc_attr( $main_size_meta[1] ) . '" />';
                    //    $metadata_arr[] = '<meta name="twitter:image:height" content="' . esc_attr( $main_size_meta[2] ) . '" />';
                    //}
                    // Else use the attachment's featured image, if set.
                } else {
                    $image_data = amt_get_image_data($embedded_item['thumbnail']);
                    if (!empty($image_data)) {
                        $image_size = apply_filters('amt_image_size_content', 'full');
                        $image_meta_tags = amt_get_twitter_cards_image_metatags($options, $image_data, $size = $image_size);
                        if (!empty($image_meta_tags)) {
                            $metadata_arr = array_merge($metadata_arr, $image_meta_tags);
                        }
                    }
                }
                // Else use the discovered preview image, if any.
                //} elseif ( ! empty( $embedded_item['thumbnail'] ) ) {
                //    $metadata_arr[] = '<meta name="twitter:image" content="' . esc_url_raw( $embedded_item['thumbnail'] ) . '" />';
                //}
                //
                $audio_video_metatags_complete = true;
                break;
            }
        }
    }
    // Filtering of the generated Twitter Card metadata
    $metadata_arr = apply_filters('amt_twitter_cards_metadata_head', $metadata_arr);
    return $metadata_arr;
}