Changeset 386701
- Timestamp:
- 05/19/2011 06:29:03 PM (15 years ago)
- Location:
- custom-menu-images/trunk
- Files:
-
- 2 edited
-
custom-menu-images.php (modified) (8 diffs)
-
readme.txt (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
custom-menu-images/trunk/custom-menu-images.php
r377564 r386701 4 4 Plugin URI: http://8manos.com 5 5 Description: None 6 Version: 0.8.16 Version: 1.0 7 7 Author: 8manos 8 8 Author URI: http://8manos.com … … 34 34 add_action('admin_head', array(&$this, 'add_js')); 35 35 add_action('wp_footer', array(&$this, 'print_custom_menu_image_css')); 36 add_action('admin_menu', array(&$this, 'custom_menu_images_menu'));36 37 37 add_action('wp_head', array(&$this, 'front_end_head')); 38 38 add_action( 'admin_print_scripts-media-upload-popup', array( &$this, 'media_upload_popup_js' ), 2000 ); … … 73 73 // add style into front-end header 74 74 function front_end_head(){ 75 $menu = $this->findMenu(); 76 wp_register_style("custom-menu-images", site_url()."/wp-content/plugins/custom-menu-images/css/custom_menu_images_".$menu->term_id.".css"); 75 wp_register_style("custom-menu-images", site_url()."/wp-content/plugins/custom-menu-images/css/custom_menu_images.css"); 77 76 wp_print_styles(array( 78 77 'custom-menu-images' … … 99 98 function save_config(){ 100 99 if(strpos($_POST['_wp_http_referer'], 'nav-menus.php')!==false){ 101 102 $ parentID = $_POST['menu'];103 $menu = $this->findMenu($parentID); 100 101 $needSaveID = $_POST['menu']; 102 104 103 $urls = $_POST[$this->prefix.'-url']; 105 104 $urls_type = $_POST[$this->prefix.'-url-type']; … … 114 113 ); 115 114 } 116 if(get_option($this->prefix."_".$parentID)){ 117 update_option($this->prefix."_".$parentID, $data); 118 }else{ 119 add_option($this->prefix."_".$parentID, $data); 120 } 121 115 $menus = wp_get_nav_menus(); 116 117 if(count($menus)){ 122 118 $this->styles = array(); 123 $this->styles[] = "@charset \"utf-8\";\n/* 1/CSS Document */"; 124 //echo $nav_menu_selected_id; 125 $custom_options = (get_option($this->prefix."_".$parentID)); 126 127 $settings = get_option($this->prefix."_settings"); 128 $element = $menu->slug ? "#menu-".$menu->slug:""; 129 //$element .= $settings['cmi_class'] ? ".".$settings['cmi_class'] : ""; 130 $element = "ul".$element; 131 132 $this->styles[] = $element.' ul{width:auto;}'; 133 $this->styles[] = '' 134 .$element.' li > a,' 135 .$element.' li:hover > a{ 136 background-repeat: no-repeat; 137 background-position: 5px center; 138 padding-left: 23px; 139 }'; 140 foreach ($urls as $key => $val ) { 141 $image_url = ($custom_options[$key]['url_type'] != 'lib' ? $custom_options[$key]['url'] : $custom_options[$key]['media_lib']); 142 if($image_url){ 143 $this->styles[] = '' 144 .$element.' li.cmi_menu_item_'.$key.' > a,' 145 .$element.' li.cmi_menu_item_'.$key.':hover > a { 146 background-image: url('.$image_url.'); 147 }'; 119 $this->styles[] = "@charset \"utf-8\";\n/* 1/CSS Document */"; 120 121 122 foreach($menus as $menu){ 123 $parentID = $menu->term_id; 124 125 $settings = get_option($this->prefix."_settings"); 126 127 128 $element = $menu->slug ? "#menu-".$menu->slug:""; 129 $element = "ul".$element; 130 $this->styles[] = "\n\n".'/* START <'.strtoupper($menu->slug).'>*/'; 131 $this->styles[] = $element.' ul{width:auto;}'; 132 $this->styles[] = '' 133 .$element.' li > a,' 134 .$element.' li:hover > a{ 135 background-repeat: no-repeat; 136 background-position: 5px center; 137 padding-left: 23px; 138 }'; 139 if($menu->term_id== $needSaveID){ 140 if(get_option($this->prefix."_".$parentID)){ 141 update_option($this->prefix."_".$parentID, $data); 142 }else{ 143 add_option($this->prefix."_".$parentID, $data); 144 } 145 $custom_options = (get_option($this->prefix."_".$parentID)); 146 147 }else{ 148 $custom_options = (get_option($this->prefix."_".$parentID)); 148 149 } 149 } 150 file_put_contents($this->dir."/css/custom_menu_images_$parentID.css", implode("\n", $this->styles)); 150 foreach ($custom_options as $key => $val ) { 151 $image_url = ($custom_options[$key]['url_type'] != 'lib' ? $custom_options[$key]['url'] : $custom_options[$key]['media_lib']); 152 if($image_url){ 153 $this->styles[] = '' 154 .$element.' li.cmi_menu_item_'.$key.' > a,' 155 .$element.' li.cmi_menu_item_'.$key.':hover > a { 156 background-image: url('.$image_url.'); 157 }'; 158 } 159 } 160 $this->styles[] = '/* END <'.strtoupper($menu->slug).'>*/'; 161 } 162 } 163 file_put_contents($this->dir."/css/custom_menu_images.css", preg_replace("#[\t]+#", "\t", implode("\n", $this->styles))); 151 164 } 152 165 } … … 182 195 function admin_head_script(){ 183 196 global $nav_menu_selected_id; 184 //echo "<pre>1";print_r($nav_menu_selected_id);echo "</pre>";185 197 ?> 186 198 <script> … … 196 208 ?> 197 209 jQuery(document).ready(function(){ 198 199 210 CustomMenuImages 200 211 .init({prefix: '<?php echo $this->prefix?>', mediaUploadUrl: '<?php echo admin_url('media-upload.php');?>'}) … … 275 286 ))); 276 287 } 277 function custom_menu_images_menu(){ 278 return; 279 add_options_page('Custom Menu Images', 'Custom Menu Images', 7, __FILE__, array($this, 'cmi_settings') ); 280 } 281 function cmi_settings(){ 282 $key = $this->prefix."_settings"; 283 284 if(strtolower($_SERVER['REQUEST_METHOD']) == 'post'){ 285 $settings = $_POST['cmi_settings']; 286 update_option($key, $settings); 287 } 288 $options = get_option($key); 289 $styles = array(); 290 $styles[] = "@charset \"utf-8\";\n/* 1/CSS Document */"; 291 292 $settings = get_option($this->prefix."_settings"); 293 $element = $settings['cmi_id'] ? "#".$settings['cmi_id']:""; 294 $element .= $settings['cmi_class'] ? ".".$settings['cmi_class'] : ""; 295 $element = "ul".$element; 296 $styles[] = $element.' ul{width:auto;}'; 297 $styles[] = '' 298 .$element.' li > a,' 299 .$element.' li:hover > a{ 300 background-repeat: no-repeat; 301 background-position: 5px center; 302 padding-left: 23px; 303 }'; 304 $menu = $this->findMenu(); 305 $item_options = get_option($this->prefix."_".$menu->term_id); 306 foreach ($item_options as $key => $val ) { 307 //$menuItems[$key]->classes = array('menu_item_'.$key); 308 $image_url = ($item_options[$key]['url_type'] != 'lib' ? $item_options[$key]['url'] : $item_options[$key]['media_lib']); 309 if($image_url){ 310 $styles[] = '' 311 .$element.' li.cmi_menu_item_'.$key.' > a,' 312 .$element.' li.cmi_menu_item_'.$key.':hover > a { 313 background-image: url('.$image_url.'); 314 }'; 315 } 316 } 317 file_put_contents($this->dir."/css/custom_menu_images_".$menu->term_id.".css", implode("\n", $styles)); 318 ?> 319 <div class='wrap'> 320 <h2><?php echo wp_specialchars( "Custom Menu Images Settings" ) ;?></h2> 321 <div> 322 <form name="" action="" method="post"> 323 <table> 324 <tr> 325 <td>Menu ID/Class</td> 326 <td> 327 <input type="text" name="cmi_settings[cmi_id]" value="<?php echo $options['cmi_id'];?>" /> / 328 <input type="text" name="cmi_settings[cmi_class]" value="<?php echo $options['cmi_class'];?>" /> 329 </td> 330 </tr> 331 <tr> 332 <td> </td> 333 <td> 334 <input type="submit" value="Save Settings" /> 335 </td> 336 </tr> 337 </table> 338 </form> 339 </div> 340 </div> 341 <?php 342 } 288 343 289 } 344 290 $custom_menu_image = new CustomMenuImage(); -
custom-menu-images/trunk/readme.txt
r377564 r386701 5 5 Requires at least: 3.0 6 6 Tested up to: 3.1.2 7 Stable tag: 0.8. 17 Stable tag: 0.8.5 8 8 9 9 Adds an image field to all menu items and generates CSS, for user side background image manipulation. … … 15 15 It can be used to set thumbnails and make mega-dropdowns, or to add a custom icon to each menu item 16 16 17 Once configured by the developer, the administrator can easily change each image without touching a line of code.17 Once configured by the developer, the site administrator can easily change each image without touching a line of code. 18 18 19 It wont always look nice ly out of the box (actually it never does), it is intended for developers who want extra functionality in the menu.19 It wont always look nice out of the box (actually it never does), it is intended for developers who want extra functionality in the menu, and ease of use for their site administrators. 20 20 21 21 == Installation == … … 24 24 2. Activate the plugin through the 'Plugins' menu in WordPress 25 25 3. Go to manage menus and each item will have a Custom image field. 26 4. You should now go add some images and configure your CSS to display background images as you want. 26 4. You should now go add some images and save. 27 5. Configure your CSS to display background images as you want. Just the image url is set by the menu so you should set background position, repeating, and menu item size. Even sprites can be used, or image replacement techniques. 27 28 28 29 == Frequently Asked Questions == … … 47 48 == Changelog == 48 49 50 = 0.8.5 = 51 * We now generate a single CSS file for all menus, that means less HTTP requests and avoiding a common error where the active menu IDs where not correctly identified. 52 49 53 = 0.8.1 = 50 54 * Minor fixes … … 63 67 == Upgrade Notice == 64 68 69 = 0.8.5 = 70 If you are having a 404 error from the CSS file, this version will fix your problem, just update, go and save your menus. CSS will be correctly generated now. 71 65 72 = 0.8.1 = 66 73 We like quick iterating. Thank for testing with us.
Note: See TracChangeset
for help on using the changeset viewer.