Changeset 2425279
- Timestamp:
- 11/25/2020 05:06:56 AM (5 years ago)
- Location:
- simplesitemap
- Files:
-
- 4 added
- 2 edited
-
tags/1.3.1 (added)
-
tags/1.3.1/admin.css (added)
-
tags/1.3.1/readme.txt (added)
-
tags/1.3.1/simplesitemap.php (added)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/simplesitemap.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
simplesitemap/trunk/readme.txt
r1289675 r2425279 4 4 Requires at least: 3.0 5 5 Tested up to: 4.4 6 Stable tag: 1.3 6 Stable tag: 1.3.1 7 7 8 8 Generates a simple sitemap for your site. … … 41 41 == Changelog == 42 42 43 = 1.3.1 = 44 * Code formatting changes to bring inline with WordPress PHP Code Standards 45 * Convert class to singleton model 46 43 47 = 1.3 = 44 48 * Update code to suit WordPress 4.4 standards -
simplesitemap/trunk/simplesitemap.php
r1289675 r2425279 1 1 <?php 2 /* 3 Plugin Name: SimpleSitemap 4 Plugin URI: http://www.fergusweb.net/software/simplesitemap/ 5 Description: Generate a sitemap to a page on your site. By default, it will generate a list of Pages, Posts and Products. You can use the shortcode to show custom types if you want to: <code>[simplesitemap view="POST_TYPE"]</code> 6 Version: 1.3 7 Author: Anthony Ferguson 8 Author URI: http://www.fergusweb.net 9 */ 10 11 12 $sitemap = new SimpleSitemapGenerator(); 13 2 /** 3 * Plugin Name: SimpleSitemap 4 * Plugin URI: http://www.fergusweb.net/software/simplesitemap/ 5 * Description: Generate a sitemap to a page on your site. By default, it will generate a list of Pages, Posts and Products. You can use the shortcode to show custom types if you want to: <code>[simplesitemap view="POST_TYPE"]</code> 6 * Version: 1.3.1 7 * Author: Anthony Ferguson 8 * Author URI: https://www.fergusweb.net 9 * 10 * @package SimpleSitemap 11 */ 12 13 // If this file is called directly, abort. 14 if ( ! defined( 'WPINC' ) ) { 15 die; 16 } 17 18 /** 19 * Simple Sitemap Generator 20 */ 14 21 class SimpleSitemapGenerator { 15 protected $option_key = 'sitemap-options'; 16 protected $nonce = 'sitemap-verify'; 17 protected $shortcode = 'simplesitemap'; 18 protected $opts = false; 19 20 /** 21 * Constructor 22 */ 23 function __construct() { 24 // Pre-load Options 22 23 /** 24 * Container for the main instance of the class. 25 * 26 * @var NRSigns_Services|null 27 */ 28 private static $instance = null; 29 30 /** 31 * Return instance of this class 32 * 33 * @return SimpleSitemapGenerator 34 */ 35 public static function instance() { 36 if ( ! self::$instance ) { 37 self::$instance = new self(); 38 } 39 return self::$instance; 40 } 41 42 /** 43 * Option key to save settings 44 * 45 * @var string 46 */ 47 protected $option_key = 'sitemap-options'; 48 49 /** 50 * Shortcode 51 * 52 * @var string 53 */ 54 protected $shortcode = 'simplesitemap'; 55 56 /** 57 * Options 58 * 59 * @var array 60 */ 61 protected $opts = array(); 62 63 64 65 /** 66 * Constructor 67 */ 68 public function __construct() { 69 // Pre-load Options. 25 70 $this->load_options(); 26 // Launch 27 if ( !is_admin()) {28 add_action( 'wp_loaded', array($this,'public_init'));71 // Launch. 72 if ( ! is_admin() ) { 73 add_action( 'wp_loaded', array( $this, 'public_init' ) ); 29 74 } else { 30 add_action('init', array($this,'admin_init')); 31 } 32 } 33 34 35 /** 36 * Option helper functions 37 */ 38 function load_default_options() { 75 add_action( 'init', array( $this, 'admin_init' ) ); 76 } 77 } 78 79 80 /** 81 * Load default options 82 * 83 * @return void 84 */ 85 private function load_default_options() { 39 86 $this->opts = array( 40 'sitemap_page' => false, 41 'sel_sitemap_position' => 'after', 42 'exclude_posts' => array(), 43 'exclude_terms' => array(), 44 ); 45 } 46 function load_options() { 47 $this->opts = get_option($this->option_key); 48 if (!$this->opts) $this->load_default_options(); 49 50 // Update options from old system 51 if (isset($this->opts['exclude_pages']) && !($this->opts['exclude_posts'])) $this->opts['exclude_posts'] = $this->opts['exclude_pages']; 52 if (isset($this->opts['exclude_cats']) && !($this->opts['exclude_terms'])) $this->opts['exclude_terms'] = $this->opts['exclude_cats']; 87 'sitemap_page' => false, 88 'sel_sitemap_position' => 'after', 89 'exclude_posts' => array(), 90 'exclude_terms' => array(), 91 ); 92 } 93 94 /** 95 * Load options from database, with default fallback 96 * 97 * @return void 98 */ 99 private function load_options() { 100 $this->opts = get_option( $this->option_key ); 101 if ( ! $this->opts ) { 102 $this->load_default_options(); 103 } 104 105 // Update options from old system. 106 if ( isset( $this->opts['exclude_pages'] ) && ! ( $this->opts['exclude_posts'] ) ) { 107 $this->opts['exclude_posts'] = $this->opts['exclude_pages']; 108 } 109 if ( isset( $this->opts['exclude_cats'] ) && ! ( $this->opts['exclude_terms'] ) ) { 110 $this->opts['exclude_terms'] = $this->opts['exclude_cats']; 111 } 53 112 unset( $this->opts['exclude_pages'], $this->opts['exclude_cats'] ); 54 55 if (!$this->opts['exclude_posts'] || !is_array($this->opts['exclude_posts'])) $this->opts['exclude_posts'] = array(); 56 if (!$this->opts['exclude_terms'] || !is_array($this->opts['exclude_terms'])) $this->opts['exclude_terms'] = array(); 57 58 } 59 function save_options($options = false) { 60 if (!$options) { $options = $this->opts; } 61 update_option($this->option_key, $options); 62 } 63 64 65 66 67 68 /** 69 * Public functions 70 */ 71 function public_init() { 72 add_action('template_redirect', array($this,'template_redirect')); 73 } 74 75 function template_redirect() { 76 // Register Shortcode 77 add_shortcode($this->shortcode, array($this,'handle_shortcode')); 78 // Only filter content if a page was selected 79 if (!empty($this->opts['sitemap_page']) && is_page($this->opts['sitemap_page'])) { 80 add_filter('the_content', array($this,'sitemap_filter_content')); 81 } 82 } 83 84 85 /** 86 * Insert the sitemap via a hook instead of a shortcode 87 */ 88 function sitemap_filter_content($content='') { 113 114 if ( ! $this->opts['exclude_posts'] || ! is_array( $this->opts['exclude_posts'] ) ) { 115 $this->opts['exclude_posts'] = array(); 116 } 117 if ( ! $this->opts['exclude_terms'] || ! is_array( $this->opts['exclude_terms'] ) ) { 118 $this->opts['exclude_terms'] = array(); 119 } 120 } 121 122 /** 123 * Save optoins to database 124 * 125 * @param array $options Array of options, use $this->opts if not provided. 126 * @return void 127 */ 128 private function save_options( $options = false ) { 129 if ( ! $options ) { 130 $options = $this->opts; } 131 update_option( $this->option_key, $options ); 132 } 133 134 135 136 137 138 /** 139 * Public function loader 140 */ 141 public function public_init() { 142 add_action( 'template_redirect', array( $this, 'template_redirect' ) ); 143 } 144 145 /** 146 * Register shortcode, and set up the_filter for an auto-add page if one is set 147 * 148 * @return void 149 */ 150 public function template_redirect() { 151 // Register Shortcode. 152 add_shortcode( $this->shortcode, array( $this, 'handle_shortcode' ) ); 153 // Only filter content if a page was selected. 154 if ( ! empty( $this->opts['sitemap_page'] ) && is_page( $this->opts['sitemap_page'] ) ) { 155 add_filter( 'the_content', array( $this, 'sitemap_filter_content' ) ); 156 } 157 } 158 159 /** 160 * Insert the sitemap via a hook instead of a shortcode 161 * 162 * @param string $content To prefix or append. 163 * @return string 164 */ 165 public function sitemap_filter_content( $content = '' ) { 89 166 ob_start(); 90 167 $post_types = array( 91 'page' => 'Pages', 92 'post' => 'Posts', 93 'product' => 'Products', 94 ); 95 foreach ($post_types as $type => $heading) { 96 if (!post_type_exists($type)) unset( $post_types[$type] ); 97 } 98 echo '<div class="simple-sitemap">'."\n"; 99 foreach ($post_types as $type => $heading) { 100 do_action( 'simple_sitemap_before_group_'.$type ); 101 echo '<div class="group-type">'."\n"; 102 echo '<h3>'.$heading.'</h3>'."\n"; 103 echo $this->handle_shortcode(array( 'view'=>$type )); 104 echo '</div><!-- group-type -->'."\n"; 105 do_action( 'simple_sitemap_after_group_'.$type ); 106 } 107 echo '</div><!-- simple-sitemap -->'."\n"; 108 $output = ob_get_clean(); 109 $content = ($this->opts['sel_sitemap_position'] == 'before') ? $output.$content : $content.$output; 168 'page' => 'Pages', 169 'post' => 'Posts', 170 'product' => 'Products', 171 ); 172 foreach ( $post_types as $type => $heading ) { 173 if ( ! post_type_exists( $type ) ) { 174 unset( $post_types[ $type ] ); 175 } 176 } 177 echo '<div class="simple-sitemap">' . "\n"; 178 foreach ( $post_types as $type => $heading ) { 179 do_action( 'simple_sitemap_before_group_' . $type ); 180 echo '<div class="group-type">' . "\n"; 181 echo '<h3>' . esc_html( $heading ) . '</h3>' . "\n"; 182 $this->handle_shortcode( 183 array( 184 'view' => $type, 185 'echo' => true, 186 ) 187 ); 188 echo '</div><!-- group-type -->' . "\n"; 189 do_action( 'simple_sitemap_after_group_' . $type ); 190 } 191 echo '</div><!-- simple-sitemap -->' . "\n"; 192 $output = ob_get_clean(); 193 $content = ( 'before' === $this->opts['sel_sitemap_position'] ) ? $output . $content : $content . $output; 110 194 return $content; 111 195 } 112 113 114 /** 115 * Shortcode Handler 116 * Defaults to showing Page and Post types 117 * You can specify a particular type by [shortcode view="product"] or other post_type 118 */ 119 function handle_shortcode($atts=false) { 120 $atts = shortcode_atts(array( 121 'view' => 'all' 122 ), $atts); 196 197 198 199 /** 200 * Shortcode Handler 201 * 202 * Defaults to showing Page and Post types 203 * You can specify a particular type by [shortcode view="product"] or other post_type 204 * 205 * @param boolean $atts Array of attributes. 206 * @return void|string 207 */ 208 public function handle_shortcode( $atts = false ) { 209 $atts = shortcode_atts( 210 array( 211 'view' => 'all', 212 'echo' => false, 213 ), 214 $atts 215 ); 123 216 ob_start(); 124 if ( post_type_exists($atts['view'])) {125 if ( is_post_type_hierarchical( $atts['view'])) {217 if ( post_type_exists( $atts['view'] ) ) { 218 if ( is_post_type_hierarchical( $atts['view'] ) ) { 126 219 $this->sitemap_show_hierarchical( $atts['view'] ); 127 220 } else { … … 129 222 } 130 223 } else { 131 echo $this->sitemap_filter_content(); 132 } 133 return ob_get_clean(); 134 } 135 136 /** 137 * Displays the sitemap for hierarchical post_types, like pages 138 */ 139 function sitemap_show_hierarchical( $post_type='page', $classes=false ) { 140 if (is_string($classes)) $classes = array( $classes ); 141 if (!is_array($classes)) $classes = array( 'sitemap-'.$post_type ); 142 143 echo '<ul class="simplesitemap '.implode(' ', $classes).'">'."\n"; 144 wp_list_pages(array( 145 'post_type' => $post_type, 146 'sort_column' => 'menu_order', 147 'sort_order' => 'DESC', 148 'echo' => true, 149 'title_li' => false, 150 'exclude_tree' => $this->opts['exclude_posts'], 151 )); 224 echo wp_kses_post( $this->sitemap_filter_content() ); 225 } 226 $output = ob_get_clean(); 227 if ( $atts['echo'] ) { 228 echo wp_kses_post( $output ); 229 } 230 return $output; 231 } 232 233 234 /** 235 * Displays the sitemap for hierarchical post_types, like pages 236 * 237 * @param string $post_type WordPress post type to show. 238 * @param boolean $classes CSS classes to include. 239 * @return void 240 */ 241 private function sitemap_show_hierarchical( $post_type = 'page', $classes = false ) { 242 if ( is_string( $classes ) ) { 243 $classes = array( $classes ); 244 } 245 if ( ! is_array( $classes ) ) { 246 $classes = array( 'sitemap-' . $post_type ); 247 } 248 249 echo '<ul class="simplesitemap ' . esc_attr( implode( ' ', $classes ) ) . '">' . "\n"; 250 wp_list_pages( 251 array( 252 'post_type' => $post_type, 253 'sort_column' => 'menu_order', 254 'sort_order' => 'DESC', 255 'echo' => true, 256 'title_li' => false, 257 'exclude_tree' => $this->opts['exclude_posts'], 258 ) 259 ); 152 260 echo '</ul>'; 153 261 } 154 155 /** 156 * Displays the sitemap for hierarchical post_types, like pages 157 */ 158 function sitemap_show_non_hierarchical( $post_type='page', $classes=false ) { 159 if (is_string($classes)) $classes = array( $classes ); 160 if (!is_array($classes)) $classes = array( 'sitemap-'.$post_type ); 161 262 263 /** 264 * Displays the sitemap for hierarchical post_types, like pages 265 * 266 * @param string $post_type WordPress post type to show. 267 * @param boolean $classes CSS classes to include. 268 * @return void|array 269 */ 270 private function sitemap_show_non_hierarchical( $post_type = 'page', $classes = false ) { 271 if ( is_string( $classes ) ) { 272 $classes = array( $classes ); 273 } 274 if ( ! is_array( $classes ) ) { 275 $classes = array( 'sitemap-' . $post_type ); 276 } 277 162 278 $query = array( 163 'post_type' => $post_type,164 'numberposts' => -1,165 'order' => ($post_type=='post') ? 'date' : 'title',166 'orderby' => 'DESC',167 'post__not_in' => $this->opts['exclude_posts'],168 ); 169 if ( $this->opts['exclude_terms']) {279 'post_type' => $post_type, 280 'numberposts' => -1, 281 'order' => ( 'post' === $post_type ) ? 'date' : 'title', 282 'orderby' => 'DESC', 283 'post__not_in' => $this->opts['exclude_posts'], 284 ); 285 if ( $this->opts['exclude_terms'] ) { 170 286 $query['tax_query'][] = array( 171 'taxonomy' => 'category',172 'field' => 'term_id',173 'terms' => $this->opts['exclude_terms'],174 'operator' => 'NOT IN',287 'taxonomy' => 'category', 288 'field' => 'term_id', 289 'terms' => $this->opts['exclude_terms'], 290 'operator' => 'NOT IN', 175 291 ); 176 292 } 177 $posts = get_posts($query); 178 if (!$posts) return $posts; 179 echo '<ul class="simplesitemap '.implode(' ', $classes).'">'."\n"; 180 foreach ($posts as $post) { 181 echo '<li><a href="'.get_permalink($post).'">'.$post->post_title.'</a></li>'; 293 $posts = get_posts( $query ); 294 if ( ! $posts ) { 295 return $posts; 296 } 297 echo '<ul class="simplesitemap ' . esc_attr( implode( ' ', $classes ) ) . '">' . "\n"; 298 foreach ( $posts as $post ) { 299 echo '<li><a href="' . esc_attr( get_permalink( $post ) ) . '">' . esc_html( $post->post_title ) . '</a></li>'; 182 300 } 183 301 echo '</ul>'; 184 302 } 185 186 187 188 189 190 /** 191 * Admin functions 192 */ 193 function admin_init() { 194 add_action('admin_menu', array($this,'admin_menu')); 195 } 196 197 198 function admin_menu() { 199 $hooks[] = add_submenu_page('options-general.php', 'Sitemap', 'Sitemap', 'administrator', 'sitemap', array($this,'admin_settings_page')); 200 foreach ($hooks as $hook) { add_action("load-$hook", array($this,'admin_enqueue')); } 201 } 202 203 function admin_enqueue() { 204 wp_enqueue_style('simplesitemap', plugins_url('admin.css', __FILE__)); 205 } 206 207 function admin_settings_page() { 208 echo '<div class="wrap">'."\n"; 209 echo '<h2>Sitemap Settings</h2>'."\n"; 210 211 if (isset($_POST['SaveSitemapSettings'])) { 212 if (!wp_verify_nonce($_POST['_wpnonce'], $this->nonce)) { echo '<p class="alert">Invalid Security</p></div>'."\n"; return; } 213 $this->opts = array_merge($this->opts, array( 214 'sitemap_page' => $_POST['sel_sitemap_page'], 215 'sel_sitemap_position' => $_POST['sel_sitemap_position'], 216 'exclude_posts' => (array)$_POST['exclude_posts'], 217 'exclude_terms' => (array)$_POST['exclude_terms'], 218 )); 303 304 305 306 307 308 /** 309 * Admin functions 310 */ 311 public function admin_init() { 312 add_action( 'admin_menu', array( $this, 'admin_menu' ) ); 313 } 314 315 /** 316 * Admin Menu 317 * 318 * @return void 319 */ 320 public function admin_menu() { 321 $hooks[] = add_submenu_page( 'options-general.php', 'Sitemap', 'Sitemap', 'administrator', 'sitemap', array( $this, 'admin_settings_page' ) ); 322 foreach ( $hooks as $hook ) { 323 add_action( "load-$hook", array( $this, 'admin_enqueue' ) ); 324 } 325 } 326 327 /** 328 * Admin enqueue styles 329 * 330 * @return void 331 */ 332 public function admin_enqueue() { 333 wp_enqueue_style( 'simplesitemap', plugins_url( 'admin.css', __FILE__ ), null, '1.0' ); 334 } 335 336 /** 337 * Admin settings page 338 * 339 * @return void 340 */ 341 public function admin_settings_page() { 342 echo '<div class="wrap">' . "\n"; 343 echo '<h2>Sitemap Settings</h2>' . "\n"; 344 345 if ( isset( $_POST['SaveSitemapSettings'] ) ) { 346 if ( ! check_admin_referer( $this->option_key ) ) { 347 echo '<p class="alert">Invalid Security</p></div>' . PHP_EOL; 348 return; 349 } 350 351 $settings = array(); 352 $setting_keys = array( 353 'sel_sitemap_page' => 'sitemap_page', 354 'sel_sitemap_position' => 'sel_sitemap_position', 355 'exclude_posts' => 'exclude_posts', 356 'exclude_terms' => 'exclude_terms', 357 ); 358 foreach ( $setting_keys as $postkey => $opkey ) { 359 if ( isset( $_POST[ $postkey ] ) ) { 360 if ( 'exclude_posts' === $opkey || 'exclude_terms' === $opkey ) { 361 $settings[ $opkey ] = array_map( 'sanitize_text_field', wp_unslash( $_POST[ $postkey ] ) ); 362 } else { 363 $settings[ $opkey ] = sanitize_text_field( wp_unslash( $_POST[ $postkey ] ) ); 364 } 365 } 366 } 367 if ( ! isset( $settings['exclude_posts'] ) || ! is_array( $settings['exclude_posts'] ) ) { 368 $settings['exclude_posts'] = array(); 369 } 370 if ( ! isset( $settings['exclude_terms'] ) || ! is_array( $settings['exclude_terms'] ) ) { 371 $settings['exclude_terms'] = array(); 372 } 373 374 $this->opts = array_merge( $this->opts, $settings ); 375 219 376 $this->save_options(); 220 377 echo '<div id="message" class="updated fade"><p><strong>Settings have been saved.</strong></p></div>'; 221 378 } 222 223 224 // echo '<pre>'; print_r($this->opts); echo '</pre>'; 379 225 380 ?> 226 <form class="sitemap" method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>">227 <?php wp_nonce_field($this->nonce); ?>381 <form class="sitemap" method="post" action="<?php echo esc_url( 'options-general.php?page=sitemap' ); ?>"> 382 <?php wp_nonce_field( $this->option_key ); ?> 228 383 <fieldset> 229 384 <legend>Display Settings</legend> 230 385 <p><label for="sel_sitemap_page">Auto-add to page:</label> 231 <?php echo wp_dropdown_pages(array( 232 'name' => 'sel_sitemap_page', 233 'echo' => 0, 234 'show_option_none' => __( '— None —' ), 235 'option_none_value' => '0', 236 'selected' => $this->opts['sitemap_page'], 237 )); 238 ?></p> 386 <?php 387 wp_dropdown_pages( 388 array( 389 'name' => 'sel_sitemap_page', 390 'echo' => 1, 391 'show_option_none' => esc_attr( __( '— None —' ) ), 392 'option_none_value' => '0', 393 'selected' => esc_attr( $this->opts['sitemap_page'] ), 394 ) 395 ); 396 ?> 397 </p> 239 398 <p><label for="sel_sitemap_position">Auto-add Position:</label> 240 399 <select name="sel_sitemap_position" id="sel_sitemap_position"> 241 400 <?php 242 401 $poss_positions = array( 243 'below' => 'After existing post content',244 'above' => 'Before existing post content',402 'below' => 'After existing post content', 403 'above' => 'Before existing post content', 245 404 ); 246 foreach ( $poss_positions as $pos => $label) {247 $sel = ( $this->opts['sel_sitemap_position'] == $pos) ? ' selected="selected"' : '';248 echo '<option value="' .$pos.'"'.$sel.'>'.$label.'</option>';405 foreach ( $poss_positions as $pos => $label ) { 406 $sel = ( $this->opts['sel_sitemap_position'] === $pos ) ? ' selected="selected"' : ''; 407 echo '<option value="' . esc_attr( $pos ) . '"' . esc_html( $sel ) . '>' . esc_html( $label ) . '</option>'; 249 408 } 250 409 ?> 251 410 </select></p> 252 411 </fieldset> 253 412 254 413 <fieldset> 255 414 <legend>Exclude these pages:</legend> 256 415 <p class="tick"><span class="scrolling"> 257 <?php $this->admin_show_page_items(); ?>416 <?php $this->admin_show_page_items(); ?> 258 417 </span></p> 259 418 </fieldset> 260 419 261 420 <fieldset> 262 421 <legend>Exclude these post categories:</legend> 263 422 <p class="tick"><span class="scrolling"> 264 <?php $this->admin_show_category_items(); ?>423 <?php $this->admin_show_category_items(); ?> 265 424 </span></p> 266 425 </fieldset> 267 268 <p><label> </label> 269 <input type="submit" name="SaveSitemapSettings" value="Save Changes" class="button-primary save" /></p> 270 <?php 271 ?> 272 </form> 273 <?php 274 echo '</div>'."\n"; 275 } 276 277 function admin_show_page_items($parentID=0, $level=0) { 278 $pages = get_pages(array( 279 'parent' => $parentID, 280 'child_of' => $parentID, 281 'hierarchical' => false, 282 )); 283 foreach ($pages as $page) { 284 $s = (in_array($page->ID, $this->opts['exclude_posts'])) ? ' checked="checked"' : ''; 285 echo '<label class="level_'.$level.'"><input type="checkbox" name="exclude_posts[]" value="'.$page->ID.'" '.$s.'/>'.$page->post_title.'</label>'; 286 $this->admin_show_page_items($page->ID, $level+1); 287 } 288 } 289 290 function admin_show_category_items($parentID=0, $level=0) { 291 $cats = get_categories(array( 292 'parent' => $parentID, 293 'child_of' => $parentID, 294 'hierarchical' => false, 295 'hide_empty' => false, 296 )); 297 foreach ($cats as $cat) { 298 $s = (in_array($cat->term_id, $this->opts['exclude_terms'])) ? ' checked="checked"' : ''; 299 echo '<label class="level_'.$level.'"><input type="checkbox" name="exclude_terms[]" value="'.$cat->term_id.'" '.$s.'/>'.$cat->name.'</label>'; 300 $this->admin_show_category_items($cat->term_id, $level+1); 301 } 302 } 303 304 426 427 <p><label> </label> 428 <input type="submit" name="SaveSitemapSettings" value="Save Changes" class="button-primary save" /></p> 429 </form> 430 <?php 431 echo '</div>' . "\n"; 432 } 433 434 /** 435 * Helper to get page items, and output as indented list 436 * 437 * @param integer $parent_id Start with 0, and loop for each parent id. 438 * @param integer $level Keep track of which level we're on for indentation. 439 * @return void 440 */ 441 public function admin_show_page_items( int $parent_id = 0, $level = 0 ) { 442 $pages = get_pages( 443 array( 444 'parent' => $parent_id, 445 'child_of' => $parent_id, 446 'hierarchical' => false, 447 ) 448 ); 449 foreach ( $pages as $page ) { 450 $s = ( in_array( $page->ID, $this->opts['exclude_posts'] ) ) ? ' checked="checked"' : ''; 451 echo '<label class="level_' . esc_attr( $level ) . '"><input type="checkbox" name="exclude_posts[]" value="' . esc_attr( $page->ID ) . '" ' . esc_html( $s ) . '/>' . esc_html( $page->post_title ) . '</label>'; 452 $this->admin_show_page_items( $page->ID, $level + 1 ); 453 } 454 } 455 456 /** 457 * Helper to get term items, and output as indented list 458 * 459 * @param integer $parent_id Start with 0, and loop for each parent id. 460 * @param integer $level Keep track of which level we're on for indentation. 461 * @return void 462 */ 463 public function admin_show_category_items( $parent_id = 0, $level = 0 ) { 464 $cats = get_categories( 465 array( 466 'parent' => $parent_id, 467 'child_of' => $parent_id, 468 'hierarchical' => false, 469 'hide_empty' => false, 470 ) 471 ); 472 foreach ( $cats as $cat ) { 473 $s = ( in_array( $cat->term_id, $this->opts['exclude_terms'] ) ) ? ' checked="checked"' : ''; 474 echo '<label class="level_' . esc_attr( $level ) . '"><input type="checkbox" name="exclude_terms[]" value="' . esc_attr( $cat->term_id ) . '" ' . esc_html( $s ) . '/>' . esc_html( $cat->name ) . '</label>'; 475 $this->admin_show_category_items( $cat->term_id, $level + 1 ); 476 } 477 } 305 478 } 306 479 307 480 308 309 ?> 481 SimpleSitemapGenerator::instance();
Note: See TracChangeset
for help on using the changeset viewer.