Changeset 2329065
- Timestamp:
- 06/23/2020 08:07:09 AM (6 years ago)
- Location:
- simple-meta-tags
- Files:
-
- 5 added
- 2 edited
-
tags/1.4 (added)
-
tags/1.4/readme.txt (added)
-
tags/1.4/screenshot-1.jpg (added)
-
tags/1.4/screenshot-2.jpg (added)
-
tags/1.4/simple-meta-tags.php (added)
-
trunk/readme.txt (modified) (1 diff)
-
trunk/simple-meta-tags.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
simple-meta-tags/trunk/readme.txt
r1732845 r2329065 3 3 Tags: SEO, Meta tags, keywords, description, hotscot 4 4 Requires at least: 3.1 5 Tested up to: 4.8.25 Tested up to: 5.4.2 6 6 Stable tag: trunk 7 7 License: GPLv2 or later -
simple-meta-tags/trunk/simple-meta-tags.php
r1732845 r2329065 3 3 Plugin Name: Simple Meta Tags 4 4 Description: Allows you to set global meta tags and customize on each individual page/post. 5 Version: 1. 35 Version: 1.4 6 6 Author: Hotscot 7 7 … … 23 23 */ 24 24 if (!class_exists("sc_simple_meta_tags")) { 25 class sc_simple_meta_tags{ 26 27 function __construct() { 25 class sc_simple_meta_tags{ 26 27 function __construct() { 28 //Admin actions 29 add_action('admin_init', array(&$this, 'registerMetaSettings') ); 30 add_action('admin_menu', array(&$this, 'addAdminPages') ); 31 add_action('add_meta_boxes', array(&$this, 'addMetaMetaBoxes') ); 28 32 add_action("save_post", array(&$this, 'saveMetaData')); 29 add_action("wp_head", array(&$this, 'displayOnFrontEnd')); 30 add_action('admin_init', array(&$this, 'registerMetaSettings') ); 31 add_action('add_meta_boxes', array(&$this, 'addMetaMetaBoxes') ); 32 add_action('admin_menu', array(&$this, 'addAdminPages') ); 33 } 34 35 function saveMetaData($post_id) { 36 //If autosave quit 37 if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id; 38 39 //stop values submitting if this is a "quick edit" 40 if(!isset($_POST['scmesbmt'])) return $post_id; 41 42 $scmTitle = isset($_POST['scmetatitle']) ? $_POST['scmetatitle'] : ''; 43 $scmDesc = isset($_POST['scmetadescription']) ? $_POST['scmetadescription'] : ''; 44 $scmKey = isset($_POST['scmetakeywords']) ? $_POST['scmetakeywords'] : ''; 45 46 update_post_meta($post_id, '_sc_m_title', $scmTitle); 47 update_post_meta($post_id, '_sc_m_description', $scmDesc); 48 update_post_meta($post_id, '_sc_m_keywords', $scmKey); 49 } 50 51 function displayOnFrontEnd(){ 52 global $post; 53 if(!is_404()){ 54 $isImplemeted = false; 55 $meta_title = ""; 56 $meta_description = ""; 57 $meta_keywords = ""; 58 59 if(is_page() || is_home()){ 60 if(get_option('use_pages_meta_data') == 'on'){ 61 $isImplemeted = true; 62 $meta_title = (get_post_meta($post->ID, '_sc_m_title', true) != '') ? get_post_meta($post->ID, '_sc_m_title', true) : get_option('page_meta_title'); 63 $meta_description = (get_post_meta($post->ID, '_sc_m_description', true) != '') ? get_post_meta($post->ID, '_sc_m_description', true) : get_option('page_meta_description'); 64 $meta_keywords = (get_post_meta($post->ID, '_sc_m_keywords', true) != '') ? get_post_meta($post->ID, '_sc_m_keywords', true) : get_option('page_meta_keywords'); 65 } 66 } 67 68 if(is_single()){ 69 if(get_option('use_posts_meta_data') == 'on'){ 70 $isImplemeted = true; 71 $meta_title = (get_post_meta($post->ID, '_sc_m_title', true) != '') ? get_post_meta($post->ID, '_sc_m_title', true) : get_option('post_meta_title'); 72 $meta_description = (get_post_meta($post->ID, '_sc_m_description', true) != '') ? get_post_meta($post->ID, '_sc_m_description', true) : get_option('post_meta_description'); 73 $meta_keywords = (get_post_meta($post->ID, '_sc_m_keywords', true) != '') ? get_post_meta($post->ID, '_sc_m_keywords', true) : get_option('post_meta_keywords'); 74 } 75 } 76 77 if($isImplemeted){ 78 if($meta_title!=''){ 79 echo '<title>' . $this->returnFormat($meta_title) . '</title>' . "\n"; 80 }else{ 81 echo '<title>'. (get_bloginfo('name','display') . wp_title(' | ',false)) .'</title>'; 82 } 83 echo '<meta name="description" content="'. $this->returnFormat($meta_description) .'" />' . "\n"; 84 echo '<meta name="keywords" content="'. $this->returnFormat($meta_keywords) .'" />' . "\n"; 85 }else{ 86 echo '<title>'. (get_bloginfo('name','display') . wp_title(' | ',false)) .'</title>'; 87 } 88 } 89 } 90 91 function returnFormat($text){ 92 return htmlentities(stripslashes($text), ENT_COMPAT, "UTF-8"); 93 } 94 95 function sc_create_wonder_form(){ 96 global $post; 97 ?> 98 <input type="hidden" id="scmesbmt" name="scmesbmt" value="1" /> 33 34 //Frontend actions 35 add_action("wp_head", array(&$this, 'displayOnFrontEnd')); 36 } 37 38 39 /** 40 * Run when the plugin is first installed. It adds options into the wp-options 41 */ 42 function registerMetaSettings(){ 43 register_setting( 'meta-tag-settings', 'page_meta_title' ); 44 register_setting( 'meta-tag-settings', 'page_meta_keywords' ); 45 register_setting( 'meta-tag-settings', 'page_meta_description' ); 46 47 register_setting( 'meta-tag-settings', 'post_meta_title' ); 48 register_setting( 'meta-tag-settings', 'post_meta_keywords' ); 49 register_setting( 'meta-tag-settings', 'post_meta_description' ); 50 51 register_setting( 'meta-tag-settings', 'use_pages_meta_data' ); 52 register_setting( 'meta-tag-settings', 'use_posts_meta_data' ); 53 54 55 /** 56 * The get_option([meta_title,meta_description,meta_keywords]) check is here 57 * to allow older versions of the plugin which didn't differentiate between 58 * posts and pages to seemlesly upgrade to this version of the plugin 59 * without manual intervention. 60 * 61 * In essence, we: 62 * - check if old global value exists 63 * - update both page and posts settings to it 64 * - set to blank so as not to be used in future 65 */ 66 if(get_option('meta_title') != ''){ 67 update_option('page_meta_title', get_option('meta_title')); 68 update_option('post_meta_title', get_option('meta_title')); 69 update_option('meta_title', ''); 70 } 71 if(get_option('meta_description') != ''){ 72 update_option('page_meta_description', get_option('meta_description')); 73 update_option('post_meta_description', get_option('meta_description')); 74 update_option('meta_description', ''); 75 } 76 if(get_option('meta_keywords') != ''){ 77 update_option('page_meta_keywords', get_option('meta_keywords')); 78 update_option('post_meta_keywords', get_option('meta_keywords')); 79 update_option('meta_keywords', ''); 80 } 81 } 82 83 84 function addAdminPages(){ 85 add_options_page('Meta tag defaults', 'Meta Tags', 'manage_options', 'meta_tags', array(&$this, 'renderSettingsPage')); 86 } 87 88 89 function renderSettingsPage(){ 90 ?> 91 <div class="wrap"> 92 <h1>Simple Meta Tag Options</h1> 93 <p>Here you can decide on what sections of the site to use this plugin on, and define the default meta values for those sections.</p> 94 <form method="post" action="options.php"> 95 <?php settings_fields( 'meta-tag-settings' ); ?> 96 <h2>Pages</h2> 97 <hr> 98 <table class="form-table"> 99 100 101 <tr valign="top"> 102 <th scope="row"><label for="page_meta_title">Title</label></th> 103 <td> 104 <input placeholder="Example Co." size="50" type="text" name="page_meta_title" id="page_meta_title" value="<?php echo get_option('page_meta_title'); ?>" /> 105 <p class="description"><strong>Note:</strong> If you leave the title empty it will use the default WordPress Title: <em>blog name | page title</em></p> 106 </td> 107 </tr> 108 109 <tr valign="top"> 110 <th scope="row"><label for="page_meta_description">Description</label></th> 111 <td><input placeholder="We make X, Y, and Z" size="50" type="text" name="page_meta_description" id="page_meta_description" value="<?php echo get_option('page_meta_description'); ?>" /></td> 112 </tr> 113 114 <tr valign="top"> 115 <th scope="row"><label for="page_meta_keywords">Keywords</label></th> 116 <td><input placeholder="X, Y, Z" size="50" type="text" name="page_meta_keywords" id="page_meta_keywords" value="<?php echo get_option('page_meta_keywords'); ?>" /></td> 117 </tr> 118 119 <tr valign="top"> 120 <th><label for="use_pages_meta_data">Use plugin on pages</label></th> 121 <td colspan="2"><label><input type="checkbox" name="use_pages_meta_data" id="use_pages_meta_data" <?php if(get_option("use_pages_meta_data") == "on"){ echo 'checked="checked"'; } ?> /> Tick to use</label></td> 122 </tr> 123 </table> 124 <h2>Posts</h2> 125 <hr> 126 <table class="form-table"> 127 128 <tr valign="top"> 129 <th scope="row"><label for="post_meta_title">Title</label></th> 130 <td> 131 <input placeholder="Example Co. Blog" size="50" type="text" name="post_meta_title" id="post_meta_title" value="<?php echo get_option('post_meta_title'); ?>" /> 132 <p class="description"><strong>Note:</strong> If you leave the title empty it will use the default WordPress Title: <em>blog name | post title</em></p> 133 </td> 134 </tr> 135 136 <tr valign="top"> 137 <th scope="row"><label for="post_meta_description">Description</label></th> 138 <td><input placeholder="Our blog about X, Y, and Z" size="50" type="text" name="post_meta_description" id="post_meta_description" value="<?php echo get_option('post_meta_description'); ?>" /></td> 139 </tr> 140 141 <tr valign="top"> 142 <th scope="row"><label for="post_meta_keywords">Keywords</label></th> 143 <td><input placeholder="Blog, X, Y, Z" size="50" type="text" name="post_meta_keywords" id="post_meta_keywords" value="<?php echo get_option('post_meta_keywords'); ?>" /></td> 144 </tr> 145 146 <tr valign="top"> 147 <th><label for="use_posts_meta_data">Use plugin on posts</label></th> 148 <td colspan="2"><label><input type="checkbox" name="use_posts_meta_data" id="use_posts_meta_data" <?php if(get_option("use_posts_meta_data") == "on"){ echo 'checked="checked"'; } ?> /> Tick to use</label></td> 149 </tr> 150 </table> 151 <hr> 152 <p class="submit"> 153 <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" /> 154 </p> 155 <p class="description"><strong>Note to theme developers</strong> – please remove <code><title></code> tag from your template files or there will be duplicate tags.</p> 156 </form> 157 </div> 158 <?php 159 } 160 161 162 function addMetaMetaBoxes() { 163 add_meta_box( 'MetaTagsPlugin', 'Simple Meta Tags', array(&$this, 'renderMetaBox'), 'page', 'advanced', 'high' ); 164 add_meta_box( 'MetaTagsPlugin', 'Simple Meta Tags', array(&$this, 'renderMetaBox'), 'post', 'advanced', 'high' ); 165 } 166 167 168 function renderMetaBox(){ 169 global $post; 170 ?> 171 <input type="hidden" id="scmesbmt" name="scmesbmt" value="1" /> 99 172 <p> 100 173 <label for="scmetatitle">Meta Title</label><br /> … … 112 185 </p> 113 186 114 <?php115 }116 117 118 function addAdminPages(){119 add_options_page('Meta tag defaults', 'Meta Tags', 'manage_options', 'meta_tags', array(&$this, 'renderAdminPage'));120 }121 122 function addMetaMetaBoxes() {123 add_meta_box( 'MetaTagsPlugin', 'Simple Meta Tags', array(&$this, 'sc_create_wonder_form'), 'page', 'advanced', 'high' );124 add_meta_box( 'MetaTagsPlugin', 'Simple Meta Tags', array(&$this, 'sc_create_wonder_form'), 'post', 'advanced', 'high' );125 126 }127 128 129 /**130 * registerMetaSettings131 *132 * Run when the plugin is first installed. It adds options into the wp-options133 */134 function registerMetaSettings()135 {136 register_setting( 'meta-tag-settings', 'page_meta_title' );137 register_setting( 'meta-tag-settings', 'page_meta_keywords' );138 register_setting( 'meta-tag-settings', 'page_meta_description' );139 140 register_setting( 'meta-tag-settings', 'post_meta_title' );141 register_setting( 'meta-tag-settings', 'post_meta_keywords' );142 register_setting( 'meta-tag-settings', 'post_meta_description' );143 144 register_setting( 'meta-tag-settings', 'use_pages_meta_data' );145 register_setting( 'meta-tag-settings', 'use_posts_meta_data' );146 147 148 if(get_option('meta_title') != ''){149 update_option('page_meta_title', get_option('meta_title'));150 update_option('post_meta_title', get_option('meta_title'));151 update_option('meta_title', '');152 }153 if(get_option('meta_description') != ''){154 update_option('page_meta_description', get_option('meta_description'));155 update_option('post_meta_description', get_option('meta_description'));156 update_option('meta_description', '');157 }158 if(get_option('meta_keywords') != ''){159 update_option('page_meta_keywords', get_option('meta_keywords'));160 update_option('post_meta_keywords', get_option('meta_keywords'));161 update_option('meta_keywords', '');162 }163 }164 165 166 /**167 * renderAdminPage()168 *169 * Paints the tag_options page170 */171 function renderAdminPage(){172 ?>173 <div class="wrap">174 <h1>Simple Meta Tag Options</h1>175 <p>Here you can decide on what sections of the site to use this plugin on, and define the default meta values for those sections.</p>176 <form method="post" action="options.php">177 <?php settings_fields( 'meta-tag-settings' ); ?>178 <h2>Pages</h2>179 <hr>180 <table class="form-table">181 182 183 <tr valign="top">184 <th scope="row"><label for="page_meta_title">Title</label></th>185 <td>186 <input placeholder="Example Co." size="50" type="text" name="page_meta_title" id="page_meta_title" value="<?php echo get_option('page_meta_title'); ?>" />187 <p class="description"><strong>Note:</strong> If you leave the title empty it will use the default WordPress Title: <em>blog name | page title</em></p>188 </td>189 </tr>190 191 <tr valign="top">192 <th scope="row"><label for="page_meta_description">Description</label></th>193 <td><input placeholder="We make X, Y, and Z" size="50" type="text" name="page_meta_description" id="page_meta_description" value="<?php echo get_option('page_meta_description'); ?>" /></td>194 </tr>195 196 <tr valign="top">197 <th scope="row"><label for="page_meta_keywords">Keywords</label></th>198 <td><input placeholder="X, Y, Z" size="50" type="text" name="page_meta_keywords" id="page_meta_keywords" value="<?php echo get_option('page_meta_keywords'); ?>" /></td>199 </tr>200 201 <tr valign="top">202 <th><label for="use_pages_meta_data">Use plugin on pages</label></th>203 <td colspan="2"><label><input type="checkbox" name="use_pages_meta_data" id="use_pages_meta_data" <?php if(get_option("use_pages_meta_data") == "on"){ echo 'checked="checked"'; } ?> /> Tick to use</label></td>204 </tr>205 </table>206 <h2>Posts</h2>207 <hr>208 <table class="form-table">209 210 <tr valign="top">211 <th scope="row"><label for="post_meta_title">Title</label></th>212 <td>213 <input placeholder="Example Co. Blog" size="50" type="text" name="post_meta_title" id="post_meta_title" value="<?php echo get_option('post_meta_title'); ?>" />214 <p class="description"><strong>Note:</strong> If you leave the title empty it will use the default WordPress Title: <em>blog name | post title</em></p>215 </td>216 </tr>217 218 <tr valign="top">219 <th scope="row"><label for="post_meta_description">Description</label></th>220 <td><input placeholder="Our blog about X, Y, and Z" size="50" type="text" name="post_meta_description" id="post_meta_description" value="<?php echo get_option('post_meta_description'); ?>" /></td>221 </tr>222 223 <tr valign="top">224 <th scope="row"><label for="post_meta_keywords">Keywords</label></th>225 <td><input placeholder="Blog, X, Y, Z" size="50" type="text" name="post_meta_keywords" id="post_meta_keywords" value="<?php echo get_option('post_meta_keywords'); ?>" /></td>226 </tr>227 228 <tr valign="top">229 <th><label for="use_posts_meta_data">Use plugin on posts</label></th>230 <td colspan="2"><label><input type="checkbox" name="use_posts_meta_data" id="use_posts_meta_data" <?php if(get_option("use_posts_meta_data") == "on"){ echo 'checked="checked"'; } ?> /> Tick to use</label></td>231 </tr>232 </table>233 <hr>234 <p class="submit">235 <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />236 </p>237 <p class="description"><strong>Note to theme developers</strong> – please remove <code><title></code> tag from your template files or there will be duplicate tags.</p>238 </form>239 </div>240 187 <?php 241 188 } 242 } 243 244 //initialize the class to a variable 245 $sc_meta_var = new sc_simple_meta_tags(); 246 247 189 190 191 function saveMetaData($post_id) { 192 //If autosave quit 193 if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id; 194 195 //stop values submitting if this is a "quick edit" 196 if(!isset($_POST['scmesbmt'])) return $post_id; 197 198 $scmTitle = isset($_POST['scmetatitle']) ? $_POST['scmetatitle'] : ''; 199 $scmDesc = isset($_POST['scmetadescription']) ? $_POST['scmetadescription'] : ''; 200 $scmKey = isset($_POST['scmetakeywords']) ? $_POST['scmetakeywords'] : ''; 201 202 update_post_meta($post_id, '_sc_m_title', $scmTitle); 203 update_post_meta($post_id, '_sc_m_description', $scmDesc); 204 update_post_meta($post_id, '_sc_m_keywords', $scmKey); 205 } 206 207 208 function displayOnFrontEnd(){ 209 global $post; 210 if(!is_404()){ 211 $isImplemeted = false; 212 $meta_title = ""; 213 $meta_description = ""; 214 $meta_keywords = ""; 215 216 if(is_page() || is_home()){ 217 if(get_option('use_pages_meta_data') == 'on'){ 218 $isImplemeted = true; 219 $meta_title = (get_post_meta($post->ID, '_sc_m_title', true) != '') ? get_post_meta($post->ID, '_sc_m_title', true) : get_option('page_meta_title'); 220 $meta_description = (get_post_meta($post->ID, '_sc_m_description', true) != '') ? get_post_meta($post->ID, '_sc_m_description', true) : get_option('page_meta_description'); 221 $meta_keywords = (get_post_meta($post->ID, '_sc_m_keywords', true) != '') ? get_post_meta($post->ID, '_sc_m_keywords', true) : get_option('page_meta_keywords'); 222 } 223 } 224 225 if(is_single()){ 226 if(get_option('use_posts_meta_data') == 'on'){ 227 $isImplemeted = true; 228 $meta_title = (get_post_meta($post->ID, '_sc_m_title', true) != '') ? get_post_meta($post->ID, '_sc_m_title', true) : get_option('post_meta_title'); 229 $meta_description = (get_post_meta($post->ID, '_sc_m_description', true) != '') ? get_post_meta($post->ID, '_sc_m_description', true) : get_option('post_meta_description'); 230 $meta_keywords = (get_post_meta($post->ID, '_sc_m_keywords', true) != '') ? get_post_meta($post->ID, '_sc_m_keywords', true) : get_option('post_meta_keywords'); 231 } 232 } 233 234 if($isImplemeted){ 235 if($meta_title!=''){ 236 echo '<title>' . $this->returnFormat($meta_title) . '</title>' . "\n"; 237 }else{ 238 echo '<title>'. (get_bloginfo('name','display') . wp_title(' | ',false)) .'</title>'; 239 } 240 echo '<meta name="description" content="'. $this->returnFormat($meta_description) .'" />' . "\n"; 241 echo '<meta name="keywords" content="'. $this->returnFormat($meta_keywords) .'" />' . "\n"; 242 }else{ 243 echo '<title>'. (get_bloginfo('name','display') . wp_title(' | ',false)) .'</title>'; 244 } 245 } 246 } 247 248 249 /* Utility Functions */ 250 function returnFormat($text){ 251 return htmlentities(stripslashes($text), ENT_COMPAT, "UTF-8"); 252 } 253 } 254 255 //initialize the class to a variable 256 $sc_meta_var = new sc_simple_meta_tags(); 248 257 } 249 258 ?>
Note: See TracChangeset
for help on using the changeset viewer.