function amt_inner_metadata_box($post)
{
    /* For future implementation. Basic code for tabs. */
    /*
    print('<br /><br />
        <div id="amt-metabox-tabs">
            <ul id="amt-metabox-tabs-list" class="category-tabs">
                <li><a href="#metadata-basic">Basic</a></li>
                <li><a href="#metadata-advanced">Advanced</a></li>
                <li><a href="#metadata-extra">Extra</a></li>
            </ul>
    
            <br class="clear" />
            <div id="metadata-basic">
                <p>#1 - basic</p>
            </div>
            <div class="hidden" id="metadata-advanced">
                <p>#2 - advanced</p>
            </div>
            <div class="hidden" id="metadata-extra">
                <p>#3 - extra</p>
            </div>
        </div>
        <br /><br />
    ');
    */
    // Use a nonce field for verification
    wp_nonce_field(plugin_basename(AMT_PLUGIN_FILE), 'amt_noncename');
    // Get the Metadata metabox permissions (filtered)
    $metabox_permissions = amt_get_metadata_metabox_permissions();
    // Get the post type. Will be used to customize the displayed notes.
    $post_type = get_post_type($post->ID);
    // Get the Add-Meta-Tags options.
    $options = get_option("add_meta_tags_opts");
    // Display the meta box HTML code.
    $metabox_has_features = false;
    print '
    <!-- #add-meta-tags-settings is required by the media selector -->
    <span id="add-meta-tags-settings">
    ';
    // Custom description
    // Description box permission check (can be user customized via filter).
    if ($options['metabox_enable_description'] == '1' && current_user_can($metabox_permissions['description_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_description_value = amt_get_post_meta_description($post->ID);
        print '
            <p>
                <label for="amt_custom_description"><strong>' . __('Description', 'add-meta-tags') . '</strong>:</label>
                <textarea class="code" style="width: 99%" id="amt_custom_description" name="amt_custom_description" cols="30" rows="2" >' . esc_attr(stripslashes($custom_description_value)) . '</textarea>
                <br>
                ' . __('Enter a custom description of 30-50 words (based on an average word length of 5 characters).', 'add-meta-tags') . '
            </p>
        ';
        // Different notes based on post type
        if ($post_type == 'post') {
            print '
                <p>
                    ' . __('If the <em>description</em> field is left blank, a <em>description</em> meta tag will be <strong>automatically</strong> generated from the excerpt or, if an excerpt has not been set, directly from the first paragraph of the content.', 'add-meta-tags') . '
                </p>
            ';
        } elseif ($post_type == 'page') {
            print '
                <p>
                    ' . __('If the <em>description</em> field is left blank, a <em>description</em> meta tag will be <strong>automatically</strong> generated from the first paragraph of the content.', 'add-meta-tags') . '
                </p>
            ';
        } else {
            // Custom post types
            print '
                <p>
                    ' . __('If the <em>description</em> field is left blank, a <em>description</em> meta tag will be <strong>automatically</strong> generated from the first paragraph of the content.', 'add-meta-tags') . '
                </p>
            ';
        }
        // Add warning about the automatic descriptions being turned off.
        if (!apply_filters('amt_generate_description_if_no_manual_data', true)) {
            print '
                <p>
                    <em>' . __('Warning: the automatic generation of descriptions has been turned off.', 'add-meta-tags') . '</em>
                </p>
            ';
        }
    }
    // Custom keywords
    // Keywords box permission check (can be user customized via filter).
    if ($options['metabox_enable_keywords'] == '1' && current_user_can($metabox_permissions['keywords_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_keywords_value = amt_get_post_meta_keywords($post->ID);
        // Alt input:  <input type="text" class="code" style="width: 99%" id="amt_custom_keywords" name="amt_custom_keywords" value="'.$custom_keywords_value.'" />
        print '
            <p>
                <label for="amt_custom_keywords"><strong>' . __('Keywords', 'add-meta-tags') . '</strong>:</label>
                <textarea class="code" style="width: 99%" id="amt_custom_keywords" name="amt_custom_keywords" cols="30" rows="2" >' . esc_attr(stripslashes($custom_keywords_value)) . '</textarea>
                <br>
                ' . __('Enter keywords separated with commas.', 'add-meta-tags') . '
            </p>
        ';
        // Different notes based on post type
        if ($post_type == 'post') {
            print '
                <p>
                    ' . __('If the <em>keywords</em> field is left blank, a <em>keywords</em> meta tag will be <strong>automatically</strong> generated from the post\'s categories, tags, custom taxonomy terms and from the global keywords, if any such global keywords have been set in the plugin settings. In case you decide to set a custom list of keywords for this post, it is possible to easily include the post\'s categories, tags and custom taxonomy terms in that list by using the special placeholders <code>%cats%</code>, <code>%tags%</code> and <code>%terms%</code> respectively.', 'add-meta-tags') . '
                    <br />
                    ' . __('Example', 'add-meta-tags') . ': <code>keyword1, keyword2, %cats%, keyword3, %tags%, keyword4</code>
                </p>
            ';
        } elseif ($post_type == 'page') {
            print '
                <p>
                    ' . __('If the <em>keywords</em> field is left blank, a <em>keywords</em> meta tag will only be automatically generated from global keywords, if any such global keywords have been set in the plugin settings.', 'add-meta-tags') . '
                </p>
            ';
        } else {
            // Custom post types
            print '
                <p>
                    ' . __('If the <em>keywords</em> field is left blank, a <em>keywords</em> meta tag will only be automatically generated from global keywords, if any such global keywords have been set in the plugin settings.', 'add-meta-tags') . '
                </p>
            ';
        }
        // Add warning about the automatic keywords being turned off.
        if (!apply_filters('amt_generate_keywords_if_no_manual_data', true)) {
            print '
                <p>
                    <em>' . __('Warning: the automatic generation of keywords has been turned off.', 'add-meta-tags') . '</em>
                </p>
            ';
        }
    }
    // Advanced options
    // Custom title tag
    // Custom title box permission check (can be user customized via filter).
    if ($options['metabox_enable_title'] == '1' && current_user_can($metabox_permissions['title_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_title_value = amt_get_post_meta_title($post->ID);
        print '
            <p>
                <label for="amt_custom_title"><strong>' . __('Title', 'add-meta-tags') . '</strong>:</label>
                <input type="text" class="code" style="width: 99%" id="amt_custom_title" name="amt_custom_title" value="' . esc_attr(stripslashes($custom_title_value)) . '" />
                <br>
                ' . __('Enter a custom title to be used in the <em>title</em> HTML element of the page.', 'add-meta-tags') . '
            </p>
            <p>
                ' . __('The <code>%title%</code> placeholder is automatically expanded to the current title of the content.', 'add-meta-tags') . '
            </p>
        ';
    }
    // 'news_keywords' meta tag
    // 'news_keywords' box permission check (can be user customized via filter).
    if ($options['metabox_enable_news_keywords'] == '1' && current_user_can($metabox_permissions['news_keywords_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_newskeywords_value = amt_get_post_meta_newskeywords($post->ID);
        print '
            <p>
                <label for="amt_custom_newskeywords"><strong>' . __('News Keywords', 'add-meta-tags') . '</strong>:</label>
                <input type="text" class="code" style="width: 99%" id="amt_custom_newskeywords" name="amt_custom_newskeywords" value="' . esc_attr(stripslashes($custom_newskeywords_value)) . '" />
                <br>
                ' . __('Enter a comma-delimited list of <strong>news keywords</strong>. For more info about this meta tag, please see this <a target="_blank" href="http://support.google.com/news/publisher/bin/answer.py?hl=en&answer=68297">Google help page</a>.', 'add-meta-tags') . '
            </p>
        ';
    }
    // per post full meta tags
    // Full meta tags box permission check (can be user customized via filter).
    if ($options['metabox_enable_full_metatags'] == '1' && current_user_can($metabox_permissions['full_metatags_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_full_metatags_value = amt_get_post_meta_full_metatags($post->ID);
        print '
            <p>
                <label for="amt_custom_full_metatags"><strong>' . __('Full meta tags', 'add-meta-tags') . '</strong>:</label>
                ' . amt_get_full_meta_tag_sets($custom_full_metatags_value) . '
                <textarea class="code" style="width: 99%" id="amt_custom_full_metatags" name="amt_custom_full_metatags" cols="30" rows="6" >' . stripslashes($custom_full_metatags_value) . '</textarea>
                <br />
                ' . __('Provide the full XHTML code of extra <a target="_blank" href="http://en.wikipedia.org/wiki/Meta_element" target="_blank"><code>meta</code></a> and <code>link</code> <a target="_blank" href="https://en.wikipedia.org/wiki/HTML_element">HTML elements</a> you would like to add to this content.', 'add-meta-tags') . '
                ' . __('For example, to prevent a cached copy of this content from being available in search engine results, you can add the following metatag:', 'add-meta-tags') . '
                <br /><br />
                <code>&lt;meta name="robots" content="noarchive" /&gt;</code>
            </p>

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

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

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

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

        ';
        // Image preview
        $image_data = amt_get_image_data(amt_esc_id_or_url_notation(stripslashes($custom_image_url_value)));
        $img_html = '';
        if (is_numeric($image_data['id'])) {
            $main_size_meta = wp_get_attachment_image_src($image_data['id'], 'medium');
            $img_html = '<img src="' . esc_url($main_size_meta[0]) . '" width="' . esc_attr($main_size_meta[1]) . '" height="' . esc_attr($main_size_meta[2]) . '" />';
        } elseif (!is_null($image_data['url'])) {
            $img_html = '<img src="' . esc_url($image_data['url']) . '" width="' . esc_attr($image_data['width']) . '" height="' . esc_attr($image_data['height']) . '" />';
        }
        if (!empty($img_html)) {
            print '
                <p>' . __('Image preview', 'add-meta-tags') . ':</p>
                <br />
                <div id="amt-image-preview" class="amt-image-preview">' . $img_html . '</div>
                ';
        }
    }
    // Content locale override
    // 'content_locale' box permission check (can be user customized via filter).
    if ($options['metabox_enable_content_locale'] == '1' && current_user_can($metabox_permissions['content_locale_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_content_locale_value = amt_get_post_meta_content_locale($post->ID);
        print '
            <p>
                <label for="amt_custom_content_locale"><strong>' . __('Content locale', 'add-meta-tags') . '</strong>:</label>
                <input type="text" class="code" style="width: 99%" id="amt_custom_content_locale" name="amt_custom_content_locale" value="' . esc_attr(stripslashes($custom_content_locale_value)) . '" />
                <br>
                ' . __('Override the default locale setting by entering a custom locale for this content in the form <code>language_TERRITORY</code>, for example: <code>en_US</code>.', 'add-meta-tags') . '
            </p>
        ';
    }
    // Express review
    // Express review box permission check (can be user customized via filter).
    if ($options['metabox_enable_express_review'] == '1' && current_user_can($metabox_permissions['express_review_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_express_review_value = amt_get_post_meta_express_review($post->ID);
        print '
            <p>
                <label for="amt_custom_express_review"><strong>' . __('Express review', 'add-meta-tags') . '</strong>:</label>
                ' . amt_get_sample_review_sets() . '
                <textarea class="code" style="width: 99%" id="amt_custom_express_review" name="amt_custom_express_review" cols="30" rows="12" >' . stripslashes($custom_express_review_value) . '</textarea>
                <br />
                ' . __('This field accepts review related information using INI file syntax. If this info is provided in the correct form, then Add-Meta-Tags treats your content as being a review of an item and generates proper Schema.org metadata. <a href="http://www.codetrax.org/projects/wp-add-meta-tags/wiki/Metadata_Generators_Key_Notes#Metadata-for-reviews" target="_blank">Read more</a> about the correct syntax of the review information.', 'add-meta-tags') . '
                <br />
            </p>
        ';
        // Add javascipt to fill textarea with sample review data.
        // CURRENTLY NOT USED
        print '
<script>
// To click on a link like:
// <a id="amt_fill_sample_review" href="#">Click here</a>
// and replace the textarea data.
jQuery(document).ready(function() {
    jQuery("#amt_fill_sample_review").click(function(event) {
        event.preventDefault();
        //jQuery("#amt_fill_sample_review").live(\'click\',function(e){
        var samplereview = "; Review rating (required)\\n\\
ratingValue = 4.2\\n\\
; Mandatory reviewed item properties (required)\\n\\
object = Book\\n\\
name = On the Origin of Species\\n\\
sameAs = http://en.wikipedia.org/wiki/On_the_Origin_of_Species\\n\\
; Extra reviewed item properties (optional)\\n\\
;isbn = 123456\\n\\
;[author]\\n\\
;object = Person\\n\\
;name = Charles Darwin\\n\\
;sameAs = https://en.wikipedia.org/wiki/Charles_Darwin";
        jQuery("#amt_custom_express_review").val(samplereview);
    });
});
</script>
        ';
    }
    // List of URLs of items referenced in the post.
    // Referenced items box permission check (can be user customized via filter).
    if ($options['metabox_enable_referenced_list'] == '1' && current_user_can($metabox_permissions['referenced_list_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_referenced_list_value = amt_get_post_meta_referenced_list($post->ID);
        print '
            <p>
                <label for="amt_custom_referenced_list"><strong>' . __('URLs of referenced items', 'add-meta-tags') . '</strong>:</label>
                <textarea class="code" style="width: 99%" id="amt_custom_referenced_list" name="amt_custom_referenced_list" cols="30" rows="4" >' . stripslashes($custom_referenced_list_value) . '</textarea>
                <br>
                ' . __('Enter a list of canonical URLs (one per line) of items referenced in the content. The page referenced need not be on the same domain as the content. For example, you might reference a page where a product can be purchased or a page that further describes a place. If such references are provided and if OpenGraph/Schema.org metadata is enabled, then the relevant <code>og:referenced</code> and <code>referencedItem</code> meta tags will be generated.', 'add-meta-tags') . ' (<span style="color:red;">' . __('Experimental feature', 'add-meta-tags') . '</span>)
            </p>
        ';
    }
    // If no features have been enabled, print an informative message
    if ($metabox_has_features === false) {
        print '
            <p>' . __(sprintf('No features have been enabled for this metabox in the Add-Meta-Tags <a href="%s">settings</a> or you do not have enough permissions to access the available features.', admin_url('options-general.php?page=add-meta-tags-options')), 'add-meta-tags') . '</p>
        ';
    } else {
        print '
            <p style="font-size: 85%; text-align: right; margin-top: 10px;">' . __(sprintf('Note: more features for this metabox might be available in the Add-Meta-Tags <a href="%s">settings</a>.', admin_url('options-general.php?page=add-meta-tags-options')), 'add-meta-tags') . '</p>
        ';
    }
    print '
    </span> <!-- #add-meta-tags-settings -->
    ';
}
/**
 * Replaces the text to be used in the title element, if a replacement text has been set.
 */
function amt_custom_title_tag($title)
{
    if (is_singular() || amt_is_static_front_page() || amt_is_static_home()) {
        // Get current post object
        $post = get_queried_object();
        if (is_null($post)) {
            return $title;
        }
        // Check if metadata is supported on this content type.
        $post_type = get_post_type($post);
        if (!in_array($post_type, amt_get_supported_post_types())) {
            return $title;
        }
        $custom_title = amt_get_post_meta_title($post->ID);
        if (!empty($custom_title)) {
            $custom_title = str_replace('%title%', $title, $custom_title);
            // Allow filtering of the custom title
            $custom_title = apply_filters('amt_custom_title', $custom_title);
            // Note: Contains multipage information through amt_process_paged()
            return esc_attr(amt_process_paged($custom_title));
        }
    }
    // WordPress adds multipage information if a custom title is not set.
    return $title;
}
Example #3
0
function amt_inner_metadata_box($post)
{
    /* For future implementation. Basic code for tabs. */
    /*
    print('<br /><br />
        <div id="amt-metabox-tabs">
            <ul id="amt-metabox-tabs-list" class="category-tabs">
                <li><a href="#metadata-basic">Basic</a></li>
                <li><a href="#metadata-advanced">Advanced</a></li>
                <li><a href="#metadata-extra">Extra</a></li>
            </ul>
    
            <br class="clear" />
            <div id="metadata-basic">
                <p>#1 - basic</p>
            </div>
            <div class="hidden" id="metadata-advanced">
                <p>#2 - advanced</p>
            </div>
            <div class="hidden" id="metadata-extra">
                <p>#3 - extra</p>
            </div>
        </div>
        <br /><br />
    ');
    */
    // Use a nonce field for verification
    wp_nonce_field(plugin_basename(AMT_PLUGIN_FILE), 'amt_noncename');
    // Get the Metadata metabox permissions (filtered)
    $metabox_permissions = amt_get_metadata_metabox_permissions();
    // Get the post type. Will be used to customize the displayed notes.
    $post_type = get_post_type($post->ID);
    // Get the Add-Meta-Tags options.
    $options = get_option("add_meta_tags_opts");
    // Display the meta box HTML code.
    $metabox_has_features = false;
    // Custom description
    // Description box permission check (can be user customized via filter).
    if ($options['metabox_enable_description'] == '1' && current_user_can($metabox_permissions['description_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_description_value = amt_get_post_meta_description($post->ID);
        print '
            <p>
                <label for="amt_custom_description"><strong>' . __('Description', 'add-meta-tags') . '</strong>:</label>
                <textarea class="code" style="width: 99%" id="amt_custom_description" name="amt_custom_description" cols="30" rows="2" >' . esc_attr(stripslashes($custom_description_value)) . '</textarea>
                <br>
                ' . __('Enter a custom description of 30-50 words (based on an average word length of 5 characters).', 'add-meta-tags') . '
            </p>
        ';
        // Different notes based on post type
        if ($post_type == 'post') {
            print '
                <p>
                    ' . __('If the <em>description</em> field is left blank, a <em>description</em> meta tag will be <strong>automatically</strong> generated from the excerpt or, if an excerpt has not been set, directly from the first paragraph of the content.', 'add-meta-tags') . '
                </p>
            ';
        } elseif ($post_type == 'page') {
            print '
                <p>
                    ' . __('If the <em>description</em> field is left blank, a <em>description</em> meta tag will be <strong>automatically</strong> generated from the first paragraph of the content.', 'add-meta-tags') . '
                </p>
            ';
        } else {
            // Custom post types
            print '
                <p>
                    ' . __('If the <em>description</em> field is left blank, a <em>description</em> meta tag will be <strong>automatically</strong> generated from the first paragraph of the content.', 'add-meta-tags') . '
                </p>
            ';
        }
    }
    // Custom keywords
    // Keywords box permission check (can be user customized via filter).
    if ($options['metabox_enable_keywords'] == '1' && current_user_can($metabox_permissions['keywords_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_keywords_value = amt_get_post_meta_keywords($post->ID);
        // Alt input:  <input type="text" class="code" style="width: 99%" id="amt_custom_keywords" name="amt_custom_keywords" value="'.$custom_keywords_value.'" />
        print '
            <p>
                <label for="amt_custom_keywords"><strong>' . __('Keywords', 'add-meta-tags') . '</strong>:</label>
                <textarea class="code" style="width: 99%" id="amt_custom_keywords" name="amt_custom_keywords" cols="30" rows="2" >' . esc_attr(stripslashes($custom_keywords_value)) . '</textarea>
                <br>
                ' . __('Enter keywords separated with commas.', 'add-meta-tags') . '
            </p>
        ';
        // Different notes based on post type
        if ($post_type == 'post') {
            print '
                <p>
                    ' . __('If the <em>keywords</em> field is left blank, a <em>keywords</em> meta tag will be <strong>automatically</strong> generated from the post\'s categories, tags, custom taxonomy terms and from the global keywords, if any such global keywords have been set in the plugin settings. In case you decide to set a custom list of keywords for this post, it is possible to easily include the post\'s categories, tags and custom taxonomy terms in that list by using the special placeholders <code>%cats%</code>, <code>%tags%</code> and <code>%terms%</code> respectively.', 'add-meta-tags') . '
                    <br />
                    ' . __('Example', 'add-meta-tags') . ': <code>keyword1, keyword2, %cats%, keyword3, %tags%, keyword4</code>
                </p>
            ';
        } elseif ($post_type == 'page') {
            print '
                <p>
                    ' . __('If the <em>keywords</em> field is left blank, a <em>keywords</em> meta tag will only be automatically generated from global keywords, if any such global keywords have been set in the plugin settings.', 'add-meta-tags') . '
                </p>
            ';
        } else {
            // Custom post types
            print '
                <p>
                    ' . __('If the <em>keywords</em> field is left blank, a <em>keywords</em> meta tag will only be automatically generated from global keywords, if any such global keywords have been set in the plugin settings.', 'add-meta-tags') . '
                </p>
            ';
        }
    }
    // Advanced options
    // Custom title tag
    // Custom title box permission check (can be user customized via filter).
    if ($options['metabox_enable_title'] == '1' && current_user_can($metabox_permissions['title_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_title_value = amt_get_post_meta_title($post->ID);
        print '
            <p>
                <label for="amt_custom_title"><strong>' . __('Title', 'add-meta-tags') . '</strong>:</label>
                <input type="text" class="code" style="width: 99%" id="amt_custom_title" name="amt_custom_title" value="' . esc_attr(stripslashes($custom_title_value)) . '" />
                <br>
                ' . __('Enter a custom title to be used in the <em>title</em> HTML element of the page.', 'add-meta-tags') . '
            </p>
        ';
    }
    // 'news_keywords' meta tag
    // 'news_keywords' box permission check (can be user customized via filter).
    if ($options['metabox_enable_news_keywords'] == '1' && current_user_can($metabox_permissions['news_keywords_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_newskeywords_value = amt_get_post_meta_newskeywords($post->ID);
        print '
            <p>
                <label for="amt_custom_newskeywords"><strong>' . __('News Keywords', 'add-meta-tags') . '</strong>:</label>
                <input type="text" class="code" style="width: 99%" id="amt_custom_newskeywords" name="amt_custom_newskeywords" value="' . esc_attr(stripslashes($custom_newskeywords_value)) . '" />
                <br>
                ' . __('Enter a comma-delimited list of <strong>news keywords</strong>. For more info about this meta tag, please see this <a target="_blank" href="http://support.google.com/news/publisher/bin/answer.py?hl=en&answer=68297">Google help page</a>.', 'add-meta-tags') . '
            </p>
        ';
    }
    // per post full meta tags
    // Full meta tags box permission check (can be user customized via filter).
    if ($options['metabox_enable_full_metatags'] == '1' && current_user_can($metabox_permissions['full_metatags_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_full_metatags_value = amt_get_post_meta_full_metatags($post->ID);
        print '
            <p>
                <label for="amt_custom_full_metatags"><strong>' . __('Full meta tags', 'add-meta-tags') . '</strong>:</label>
                <textarea class="code" style="width: 99%" id="amt_custom_full_metatags" name="amt_custom_full_metatags" cols="30" rows="4" >' . stripslashes($custom_full_metatags_value) . '</textarea>
                <br>
                ' . __('Provide the full XHTML code of extra META elements you would like to add to this content (read more about the <a href="http://en.wikipedia.org/wiki/Meta_element" target="_blank">META HTML element</a> on Wikipedia).', 'add-meta-tags') . '
            </p>
            <p>
                ' . __('For example, to prevent a cached copy of this content from being available in search engine results, you can add the following metatag:', 'add-meta-tags') . '
                <br /><code>&lt;meta name="robots" content="noarchive" /&gt;</code>
            </p>

            <p>
                ' . __('Important note: for security reasons only <code>meta</code> elements are allowed in this box. All other HTML elements are automatically removed.', 'add-meta-tags') . '
            </p>
        ';
    }
    // Image URL (global override)
    // 'image_url' box permission check (can be user customized via filter).
    if ($options['metabox_enable_image_url'] == '1' && current_user_can($metabox_permissions['image_url_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_image_url_value = amt_get_post_meta_image_url($post->ID);
        print '
            <p>
                <label for="amt_custom_image_url"><strong>' . __('Image URL', 'add-meta-tags') . '</strong>:</label>
                <input type="text" class="code" style="width: 99%" id="amt_custom_image_url" name="amt_custom_image_url" value="' . esc_url_raw(stripslashes($custom_image_url_value)) . '" />
                <br>
                ' . __('Enter an image URL to override all media related meta tags.', 'add-meta-tags') . '
            </p>
        ';
    }
    // Content locale override
    // 'content_locale' box permission check (can be user customized via filter).
    if ($options['metabox_enable_content_locale'] == '1' && current_user_can($metabox_permissions['content_locale_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_content_locale_value = amt_get_post_meta_content_locale($post->ID);
        print '
            <p>
                <label for="amt_custom_content_locale"><strong>' . __('Content locale', 'add-meta-tags') . '</strong>:</label>
                <input type="text" class="code" style="width: 99%" id="amt_custom_content_locale" name="amt_custom_content_locale" value="' . esc_attr(stripslashes($custom_content_locale_value)) . '" />
                <br>
                ' . __('Override the default locale setting by entering a custom locale for this content in the form <code>language_TERRITORY</code>, for example: <code>en_US</code>.', 'add-meta-tags') . '
            </p>
        ';
    }
    // Express review
    // Express review box permission check (can be user customized via filter).
    if ($options['metabox_enable_express_review'] == '1' && current_user_can($metabox_permissions['express_review_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_express_review_value = amt_get_post_meta_express_review($post->ID);
        print '
            <p>
                <label for="amt_custom_express_review"><strong>' . __('Express review', 'add-meta-tags') . '</strong>:</label>
                <textarea class="code" style="width: 99%" id="amt_custom_express_review" name="amt_custom_express_review" cols="30" rows="2" >' . stripslashes($custom_express_review_value) . '</textarea>
                <br />
                ' . __('This field accepts special notation of review related information. If this info is provided in the correct form, then Add-Meta-Tags treats your content as being a review of an item and generates proper Schema.org metadata. This field must contain a <code>__</code> (double underscore) delimited list of the following information (all in one line): a rating, the name of a valid schema.org <a href="http://schema.org/Thing">Thing</a> derivative object, a title, and a URL. For instance:', 'add-meta-tags') . '
                <br />
                <code>4.2__Book__On the Origin of Species__http://en.wikipedia.org/wiki/On_the_Origin_of_Species</code>
            </p>
        ';
    }
    // List of URLs of items referenced in the post.
    // Referenced items box permission check (can be user customized via filter).
    if ($options['metabox_enable_referenced_list'] == '1' && current_user_can($metabox_permissions['referenced_list_box_capability'])) {
        $metabox_has_features = true;
        // Retrieve the field data from the database.
        $custom_referenced_list_value = amt_get_post_meta_referenced_list($post->ID);
        print '
            <p>
                <label for="amt_custom_referenced_list"><strong>' . __('URLs of referenced items', 'add-meta-tags') . '</strong>:</label>
                <textarea class="code" style="width: 99%" id="amt_custom_referenced_list" name="amt_custom_referenced_list" cols="30" rows="4" >' . stripslashes($custom_referenced_list_value) . '</textarea>
                <br>
                ' . __('Enter a list of canonical URLs (one per line) of items referenced in the content. The page referenced need not be on the same domain as the content. For example, you might reference a page where a product can be purchased or a page that further describes a place. If such references are provided and if OpenGraph/Schema.org metadata is enabled, then the relevant <code>og:referenced</code> and <code>referencedItem</code> meta tags will be generated.', 'add-meta-tags') . ' (<span style="color:red;">EXPERIMENTAL</span>)
            </p>
        ';
    }
    // If no features have been enabled, print an informative message
    if ($metabox_has_features === false) {
        print '
            <p>' . __(sprintf('No features have been enabled for this metabox in the Add-Meta-Tags <a href="%s">settings</a> or you do not have enough permissions to access the available features.', admin_url('options-general.php?page=add-meta-tags-options')), 'add-meta-tags') . '</p>
        ';
    } else {
        print '
            <p style="font-size: 85%; text-align: right; margin-top: 10px;">' . __(sprintf('Note: more features for this metabox might be available in the Add-Meta-Tags <a href="%s">settings</a>.', admin_url('options-general.php?page=add-meta-tags-options')), 'add-meta-tags') . '</p>
        ';
    }
}
Example #4
0
function amt_internal_get_title($options, $post, $title_templates, $force_custom_title_if_set = false, $caller_is_metadata_generator = false)
{
    // EARLY PROCESSING
    // First we check for a custom title whgich may have been inserted in the
    // relevant Custom Field of the supported types.
    $custom_title = '';
    if (is_singular() || amt_is_static_front_page() || amt_is_static_home()) {
        if (!is_null($post)) {
            // Check if metadata is supported on this content type.
            $post_type = get_post_type($post);
            if (in_array($post_type, amt_get_supported_post_types())) {
                // Store the custom title. Should be empty for post types which do not support a custom title or which have an empty custom title.
                $custom_title = amt_get_post_meta_title($post->ID);
                //$custom_title = str_replace('%title%', $title, $custom_title);
                // Allow filtering of the custom title
                $custom_title = apply_filters('amt_custom_title', $custom_title);
            }
        }
    }
    // Early processing in case advanced title management is TURNED OFF
    // This early processing takes place only for calls from the 'amt_get_title_for_title_element()' function.
    // WordPress constructs its own titles for the 'title' HTML element, so we
    // do not need to do further processing and title guessing here.
    // This early processing is NOT performed for calls from the 'amt_get_title_for_metadata()' function,
    // because the metadata generators
    if (!$caller_is_metadata_generator && array_key_exists('enable_advanced_title_management', $options) && $options['enable_advanced_title_management'] == '0') {
        if (is_singular() || amt_is_static_front_page() || amt_is_static_home()) {
            if (!empty($custom_title)) {
                // Contains paging information
                return amt_process_paged($custom_title);
            }
        }
        return;
    }
    // From now on Add-Meta-Tags generates the title.
    // TEMPLATE VARIABLES
    // Set template variable values
    // #entity_title#, #Entity_title#, #Entity_Title#, #page#, #page_total#, #site_name#, #site_tagline#, #year#, #month#, #month_name#, #day#
    // Date variables
    // Credit for the following here: http://wordpress.stackexchange.com/a/109674
    // https://developer.wordpress.org/reference/classes/wp_locale/
    $var_year = 0;
    $var_month = 0;
    $var_month_name = '';
    $var_day = 0;
    if (is_date()) {
        // On date archives the following have a value. On the default front page are zero
        $var_year = get_query_var('year');
        $var_month = get_query_var('monthnum');
        $var_month_name = '';
        if ($var_month) {
            $var_month_name = $GLOBALS['wp_locale']->get_month($var_month);
        }
        $var_day = get_query_var('day');
    } elseif (is_singular() || amt_is_static_front_page() || amt_is_static_home()) {
        $var_year = mysql2date('Y', $post->post_date);
        $var_month = mysql2date('m', $post->post_date);
        $var_month_name = '';
        if ($var_month) {
            $var_month_name = $GLOBALS['wp_locale']->get_month($var_month);
        }
        $var_day = mysql2date('d', $post->post_date);
    }
    // #page_total#
    global $wp_query;
    $page_total = 1;
    if (isset($wp_query->max_num_pages)) {
        $page_total = $wp_query->max_num_pages;
    }
    // #page#
    $page = 1;
    // For paginated archives or paginated main page with latest posts.
    if (is_paged()) {
        $paged = get_query_var('paged');
        // paged
        if ($paged && $paged >= 2) {
            $page = $paged;
        }
        // For a Post or Page that has been divided into pages using the <!--nextpage--> QuickTag
    } else {
        $paged = get_query_var('page');
        // page
        if ($paged && $paged >= 2) {
            $page = $paged;
        }
    }
    // #site_name#
    $site_name = get_bloginfo('name');
    // #site_tagline#
    $site_tagline = get_bloginfo('description');
    // MAIN PROCESSING
    // 1) generate title, 2) determine title template
    // #entity_title# and $entity_title_template
    $entity_title = '';
    $entity_title_template = '';
    // Default front page displaying the latest posts
    if (amt_is_default_front_page()) {
        // Entity title
        // $post is NULL
        $entity_title = get_bloginfo('name');
        // No custom title
        // Entity title template
        if (array_key_exists('enable_advanced_title_management', $options) && $options['enable_advanced_title_management'] == '1') {
            if ($page && $page >= 2 && array_key_exists('front_page_default_paged', $title_templates)) {
                $entity_title_template = $title_templates['front_page_default_paged'];
            } elseif (array_key_exists('front_page_default', $title_templates)) {
                $entity_title_template = $title_templates['front_page_default'];
            }
        }
        // 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()) {
        // Entity title
        $entity_title = strip_tags(get_the_title($post->ID));
        if (!empty($custom_title) && $force_custom_title_if_set) {
            $custom_title = str_replace('%title%', $entity_title, $custom_title);
            $entity_title = $custom_title;
        }
        // Entity title template
        if (array_key_exists('enable_advanced_title_management', $options) && $options['enable_advanced_title_management'] == '1') {
            if ($page && $page >= 2 && array_key_exists('front_page_static_paged', $title_templates)) {
                $entity_title_template = $title_templates['front_page_static_paged'];
            } elseif (array_key_exists('front_page_static', $title_templates)) {
                $entity_title_template = $title_templates['front_page_static'];
            }
        }
        // The posts index page - a static page displaying the latest posts
    } elseif (amt_is_static_home()) {
        // Entity title
        $entity_title = strip_tags(get_the_title($post->ID));
        if (!empty($custom_title) && $force_custom_title_if_set) {
            $custom_title = str_replace('%title%', $entity_title, $custom_title);
            $entity_title = $custom_title;
        }
        // Entity title template
        if (array_key_exists('enable_advanced_title_management', $options) && $options['enable_advanced_title_management'] == '1') {
            if ($page && $page >= 2 && array_key_exists('blog_index_static_paged', $title_templates)) {
                $entity_title_template = $title_templates['blog_index_static_paged'];
            } elseif (array_key_exists('blog_index_static', $title_templates)) {
                $entity_title_template = $title_templates['blog_index_static'];
            }
        }
        // Date Archives
        // Yearly Archive
    } elseif (is_year()) {
        // Entity title
        $entity_title = $var_year;
        // Entity title template
        if (array_key_exists('enable_advanced_title_management', $options) && $options['enable_advanced_title_management'] == '1') {
            if ($page && $page >= 2 && array_key_exists('archive_date_yearly_paged', $title_templates)) {
                $entity_title_template = $title_templates['archive_date_yearly_paged'];
            } elseif (array_key_exists('archive_date_yearly', $title_templates)) {
                $entity_title_template = $title_templates['archive_date_yearly'];
            }
        }
        // Monthly Archive
    } elseif (is_month()) {
        // Entity title
        $entity_title = $var_month_name;
        // Entity title template
        if (array_key_exists('enable_advanced_title_management', $options) && $options['enable_advanced_title_management'] == '1') {
            if ($page && $page >= 2 && array_key_exists('archive_date_monthly_paged', $title_templates)) {
                $entity_title_template = $title_templates['archive_date_monthly_paged'];
            } elseif (array_key_exists('archive_date_monthly', $title_templates)) {
                $entity_title_template = $title_templates['archive_date_monthly'];
            }
        }
        // Daily Archive
    } elseif (is_day()) {
        // Entity title
        $entity_title = $var_day;
        // Entity title template
        if (array_key_exists('enable_advanced_title_management', $options) && $options['enable_advanced_title_management'] == '1') {
            if ($page && $page >= 2 && array_key_exists('archive_date_daily_paged', $title_templates)) {
                $entity_title_template = $title_templates['archive_date_daily_paged'];
            } elseif (array_key_exists('archive_date_daily', $title_templates)) {
                $entity_title_template = $title_templates['archive_date_daily'];
            }
        }
        // Taxonomy Archive
        // $post is a taxonomy term object
    } elseif (is_category() || is_tag() || is_tax()) {
        // Entity title
        $entity_title = single_term_title($prefix = '', $display = false);
        // Entity title template
        $template_name = 'archive_taxonomy_' . $post->taxonomy;
        if (array_key_exists('enable_advanced_title_management', $options) && $options['enable_advanced_title_management'] == '1') {
            if ($page && $page >= 2 && array_key_exists($template_name . '_paged', $title_templates)) {
                $entity_title_template = $title_templates[$template_name . '_paged'];
            } elseif (array_key_exists($template_name, $title_templates)) {
                $entity_title_template = $title_templates[$template_name];
            }
        }
        // Author Archive
        // $post is an author object
    } elseif (is_author()) {
        // Entity title
        $entity_title = $post->display_name;
        // Entity title template
        if (array_key_exists('enable_advanced_title_management', $options) && $options['enable_advanced_title_management'] == '1') {
            if ($page && $page >= 2 && array_key_exists('archive_author_paged', $title_templates)) {
                $entity_title_template = $title_templates['archive_author_paged'];
            } elseif (array_key_exists('archive_author', $title_templates)) {
                $entity_title_template = $title_templates['archive_author'];
            }
        }
        // Custom Post Type Archive
    } elseif (is_post_type_archive()) {
        // Entity title
        $entity_title = post_type_archive_title($prefix = '', $display = false);
        // Entity title template
        // $post is a content type object
        $template_name = 'archive_posttype_' . $post->name;
        if (array_key_exists('enable_advanced_title_management', $options) && $options['enable_advanced_title_management'] == '1') {
            if ($page && $page >= 2 && array_key_exists($template_name . '_paged', $title_templates)) {
                $entity_title_template = $title_templates[$template_name . '_paged'];
            } elseif (array_key_exists($template_name, $title_templates)) {
                $entity_title_template = $title_templates[$template_name];
            }
        }
        // Content
    } elseif (is_singular()) {
        // Entity title
        // In some cases, like EDD downloads, get_the_title() also returns escaped HTML. Use strip_tags().
        $entity_title = strip_tags(get_the_title($post->ID));
        // Alternatively, use the_title_attribute(). See: https://codex.wordpress.org/Function_Reference/the_title_attribute
        //$entity_title = the_title_attribute( array( 'before'=>'', 'after'=>'', 'echo'=>false, $post->ID) );
        if (!empty($custom_title) && $force_custom_title_if_set) {
            $custom_title = str_replace('%title%', $entity_title, $custom_title);
            $entity_title = $custom_title;
        }
        // Attachments
        if (is_attachment()) {
            // Attachment type
            $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);
            $template_name = 'content_attachment';
            if (array_key_exists('content_attachment_' . $attachment_type, $title_templates)) {
                $template_name = 'content_attachment_' . $attachment_type;
            }
            // Entity title template
            if (array_key_exists('enable_advanced_title_management', $options) && $options['enable_advanced_title_management'] == '1') {
                // No paging info
                if (array_key_exists($template_name, $title_templates)) {
                    $entity_title_template = $title_templates[$template_name];
                }
            }
            // Page
        } elseif (is_page()) {
            // Entity title template
            if (array_key_exists('enable_advanced_title_management', $options) && $options['enable_advanced_title_management'] == '1') {
                if ($page && $page >= 2 && array_key_exists('content_page_paged', $title_templates)) {
                    $entity_title_template = $title_templates['content_page_paged'];
                } elseif (array_key_exists('content_page', $title_templates)) {
                    $entity_title_template = $title_templates['content_page'];
                }
            }
            // Posts and custom post types (with post format checking)
        } else {
            $post_type = get_post_type($post);
            $post_format = get_post_format($post->ID);
            $template_name = 'content_' . $post_type;
            if ($post_format !== false && array_key_exists($template_name . '_' . $post_format, $title_templates)) {
                $template_name = $template_name . '_' . $post_format;
            }
            // Entity title template
            if (array_key_exists('enable_advanced_title_management', $options) && $options['enable_advanced_title_management'] == '1') {
                if ($page && $page >= 2 && array_key_exists($template_name . '_paged', $title_templates)) {
                    $entity_title_template = $title_templates[$template_name . '_paged'];
                } elseif (array_key_exists($template_name, $title_templates)) {
                    $entity_title_template = $title_templates[$template_name];
                }
            }
        }
    }
    // LATE PROCESSING
    $title = '';
    // Late processing in case advanced title management is TURNED OFF
    // This late processing takes place only for calls from the 'amt_get_title_for_metadata()' function.
    // The metadata generators do not construct a title, so this has to be done here (above $entity_title).
    if ($caller_is_metadata_generator && array_key_exists('enable_advanced_title_management', $options) && $options['enable_advanced_title_management'] == '0') {
        if (!empty($entity_title)) {
            if ($page && $page >= 2) {
                $title = amt_process_paged($entity_title);
            } else {
                $title = $entity_title;
            }
        } else {
            // TODO: This appears in BuddyPress member pages. Maybe it should just set $title to an empty string.
            //$title = 'PROGRAMMING ERROR - MISSING TITLE';
            $title = '';
        }
    } elseif (empty($entity_title_template)) {
        // If the caller is a metadata generator, then the title cannot be determined otherwise.
        // So, if an $entity_title has been found we return it.
        if ($caller_is_metadata_generator) {
            // If a metadata generator requested a title, but a template was
            // not found, return an error message as the title, unless the
            // $entity_title is not empty, in which case set the title to it as is.
            if (!empty($entity_title)) {
                $title = $entity_title;
            } else {
                // TODO: Maybe it should just set $title to an empty string.
                //$title = 'TITLE TEMPLATE NOT FOUND';
                $title = '';
            }
        } else {
            // If the title was requested for the 'title' HTML element, but a template
            //was not found, return an empty string, so that the default WordPress title is used.
            // TODO: Check if still required
            $title = '';
        }
        // If advanced title management is enabled
    } elseif (array_key_exists('enable_advanced_title_management', $options) && $options['enable_advanced_title_management'] == '1') {
        $template_vars = array('#year#' => $var_year, '#month#' => $var_month, '#month_name#' => $var_month_name, '#day#' => $var_day, '#page#' => $page, '#page_total#' => $page_total, '#site_name#' => $site_name, '#site_tagline#' => $site_tagline, '#entity_title#' => $entity_title, '#Entity_title#' => ucfirst(strtolower($entity_title)), '#Entity_Title#' => ucwords(strtolower($entity_title)));
        // Replace variables in the template
        foreach ($template_vars as $var_name => $var_value) {
            $entity_title_template = str_replace($var_name, $var_value, $entity_title_template);
        }
        $title = $entity_title_template;
    }
    return $title;
}