Commits

George Notaras committed 6f3b633

Added Metadata Review Mode.

  • Participants
  • Parent commits 11fee71

Comments (0)

Files changed (5)

add-meta-tags.php

 add_filter('wp_title', 'amt_custom_title_tag');
 
 
-function amt_add_metadata() {
+function amt_get_metadata() {
 
     // Get the options the DB
     $options = get_option("add_meta_tags_opts");
     $metadata_arr[] = "";
     $metadata_arr[] = "";
 
-    echo implode("\n", $metadata_arr);
+    return $metadata_arr;
+}
+
+
+function amt_add_metadata() {
+    echo implode("\n", amt_get_metadata());
 }
 
 add_action('wp_head', 'amt_add_metadata', 0);
 
+
+
+// Review mode
+
+function amt_get_metadata_review() {
+    // Returns metadata review code
+    return '<pre>' . htmlentities( implode("\n", amt_get_metadata()) ) . '</pre>';
+}
+
+function amt_add_metadata_review($post_body) {
+    // Automatic addition in posts, pages, attachments and custom post types
+    if ( !is_single() && !is_page()) {
+        return $post_body;
+    }
+
+    // Check if Review Mode is enabled
+    $options = get_option("add_meta_tags_opts");
+    if ( $options["review_mode"] == "0" ) {
+        return $post_body;
+    }
+
+    // Adds metadata review code only for admins
+    $user_info = get_userdata(get_current_user_id());
+    
+    // See: http://codex.wordpress.org/User_Levels
+    // Admin -> User level 10
+    if ( $user_info->user_level == '10' ) {
+        $post_body = amt_get_metadata_review() . '<br /><br />' . $post_body;
+    }
+
+    return $post_body;
+}
+
+add_filter('the_content', 'amt_add_metadata_review');
+
 ?>

amt-admin-panel.php

             </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>. When enabled, WordPress users with administrator privileges see a box containing the metadata exactly as it is added in the HTML head. The box is displayed for posts, pages, attachments and custom post types.', 'add-meta-tags').'
+                </label>
+                <br />
+            </fieldset>
+            </td>
+            </tr>
+
+            <tr valign="top">
             <th scope="row">'.__('Donations', 'add-meta-tags').'</th>
             <td>
             <fieldset>
  */
 function amt_get_default_options() {
     return array(
-        "settings_version"  => 2,       // IMPORTANT: SETTINGS UPGRADE: Every time settings are added or removed this has to be incremented.
+        "settings_version"  => 3,       // IMPORTANT: SETTINGS UPGRADE: Every time settings are added or removed this has to be incremented.
         "site_description"  => "",      // Front page description
         "site_keywords"     => "",      // Front page keywords
         "global_keywords"   => "",      // These keywords are added to the 'keywords' meta tag on all posts and pages
         "noindex_author_archives"    => "0",
         "copyright_url"     => "",
         "default_image_url" => "",
+        "review_mode"       => "0",
         "i_have_donated"    => "0",
         );
 }
     // Removed ``noindex_archives``
     // No migrations required. Clean-up takes place in step (3) below.
 
+    // Version 2.2.1 (settings_version 2->3)
+    // Added ``review_mode``
+    // No migrations required. Addition takes place in (1).
+
     // 3) Clean stored options.
     foreach ($stored_options as $opt => $value) {
         if ( !array_key_exists($opt, $default_options) ) {

amt-template-tags.php

     echo amt_get_content_keywords_mesh();
 }
 
+function amt_metadata() {
+    // Prints full metadata.
+    echo implode("\n", amt_get_metadata());
+}
+
+function amt_metadata_review() {
+    // Prints full metadata in review mode. No user level checks here.
+    echo amt_get_metadata_inspect();
+}
+
 - Add the `NOODP,NOYDIR` option to the robots meta tag.
 - Add the `NOINDEX,FOLLOW` options to the robots meta tag on category, tag, author or time based archives and search results.
 
+**Metadata Review Mode**
+
+When enabled, WordPress users with administrator privileges see a box that contains the full metadata (exactly as it is added in the HTML head) above the content for easier examination.
+
 **Languages**
 
 Add-Meta-Tags is available in the following languages: