/**
  * generate()
  *
  * @return bool $success
  **/
 function generate()
 {
     $opts = xml_sitemaps::get_options();
     if ($opts['mobile_sitemap']) {
         $this->mobile_sitemap = true;
     }
     if (!$this->open()) {
         return false;
     }
     # private site
     if (!xml_sitemaps_debug && !intval(get_option('blog_public'))) {
         $this->close();
         return true;
     }
     # static front page
     if (get_option('show_on_front') == 'page') {
         $this->front_page_id = intval(get_option('page_on_front'));
         $this->blog_page_id = intval(get_option('page_for_posts'));
     } else {
         $this->front_page_id = false;
         $this->blog_page_id = false;
     }
     $this->posts_per_page = get_option('posts_per_page');
     $this->stats = (object) null;
     $this->home($opts['exclude_pages']);
     $this->blog($opts['exclude_pages']);
     add_filter('posts_where_request', array('xml_sitemaps', 'kill_query'));
     $this->pages($opts['exclude_pages']);
     $this->posts();
     if ($opts['inc_categories']) {
         $this->categories();
     }
     if ($opts['inc_tags']) {
         $this->tags();
     }
     if ($opts['inc_authors']) {
         $this->authors($opts['empty_author']);
     }
     if ($opts['inc_archives']) {
         $this->archives();
     }
     remove_filter('posts_where_request', array('xml_sitemaps', 'kill_query'));
     #
     # to add pages in your plugin, create a function like so:
     # function my_sitemap_pages(&$sitemap) {
     #   $sitemap->write($loc, $lastmod, $changefreq, $priority);
     # }
     # add_action('xml_sitemaps', 'my_sitemap_pages');
     #
     do_action_ref_array('xml_sitemaps', array(&$this));
     $this->close();
     return true;
 }
Esempio n. 2
0
 /**
  * init()
  *
  * @return void
  **/
 function init()
 {
     // more stuff: register actions and filters
     register_activation_hook(__FILE__, array($this, 'activate'));
     register_deactivation_hook(__FILE__, array($this, 'deactivate'));
     if (intval(get_option('xml_sitemaps'))) {
         if (!xml_sitemaps_debug) {
             add_filter('mod_rewrite_rules', array($this, 'rewrite_rules'));
         }
         xml_sitemaps::get_options();
         add_action('template_redirect', array($this, 'template_redirect'));
         add_action('save_post', array($this, 'save_post'));
         add_action('xml_sitemaps_ping', array($this, 'ping'));
         add_action('do_robots', array($this, 'do_robots'));
     } else {
         add_action('admin_notices', array($this, 'inactive_notice'));
     }
     add_action('update_option_permalink_structure', array($this, 'reactivate'));
     add_action('update_option_blog_public', array($this, 'reactivate'));
     add_action('update_option_active_plugins', array($this, 'reactivate'));
     add_action('after_db_upgrade', array($this, 'reactivate'));
     add_action('flush_cache', array($this, 'reactivate'));
     add_action('wp_upgrade', array($this, 'reactivate'));
     if (is_admin()) {
         add_action('admin_menu', array($this, 'admin_menu'));
         add_action('load-settings_page_xml-sitemaps', array($this, 'xml_sitemaps_admin'));
     }
 }
 /**
  * edit_options()
  *
  * @return void
  **/
 static function edit_options()
 {
     $options = xml_sitemaps::get_options();
     echo '<div class="wrap">' . "\n" . '<form method="post" action="">' . "\n";
     wp_nonce_field('xml_sitemaps');
     echo '<h2>' . __('XML Sitemaps Settings', 'xml-sitemaps') . '</h2>' . "\n";
     echo '<table class="form-table">' . "\n";
     echo '<tr>' . "\n" . '<th scope="row">' . __('Include Archive Pages', 'xml-sitemaps') . '</th>' . "\n" . '<td>' . '<label>' . '<input type="checkbox" name="inc_archives"' . checked((bool) $options['inc_archives'], true, false) . ' />' . '&nbsp;' . __('Check to include date archive pages, such as YYYY or YYYY/MM, in your sitemap.', 'xml-sitemaps') . '</label>' . '</td>' . "\n" . '</tr>' . "\n";
     echo '<tr>' . "\n" . '<th scope="row">' . __('Include Author Pages', 'xml-sitemaps') . '</th>' . "\n" . '<td>' . '<label>' . '<input type="checkbox" name="inc_authors"' . checked((bool) $options['inc_authors'], true, false) . ' />' . '&nbsp;' . __('Check to include author pages in your sitemap.', 'xml-sitemaps') . '</label>' . '</td>' . "\n" . '</tr>' . "\n";
     echo '<tr>' . "\n" . '<th scope="row">' . __('Empty Author Pages', 'xml-sitemaps') . '</th>' . "\n" . '<td>' . '<label>' . '<input type="checkbox" name="empty_author"' . checked((bool) $options['empty_author'], true, false) . ' />' . '&nbsp;' . __('Check to include author page in your sitemap if the author(s) has not published any pages or posts yet.', 'xml-sitemaps') . '</label>' . '</td>' . "\n" . '</tr>' . "\n";
     echo '<tr>' . "\n" . '<th scope="row">' . __('Include Category Pages', 'xml-sitemaps') . '</th>' . "\n" . '<td>' . '<label>' . '<input type="checkbox" name="inc_categories"' . checked((bool) $options['inc_categories'], true, false) . ' />' . '&nbsp;' . __('Check to include category pages in your sitemap.', 'xml-sitemaps') . '</label>' . '</td>' . "\n" . '</tr>' . "\n";
     echo '<tr>' . "\n" . '<th scope="row">' . __('Include Tag Pages', 'xml-sitemaps') . '</th>' . "\n" . '<td>' . '<label>' . '<input type="checkbox" name="inc_tags"' . checked((bool) $options['inc_tags'], true, false) . ' />' . '&nbsp;' . __('Check to include tag pages in your sitemap.', 'xml-sitemaps') . '</label>' . '</td>' . "\n" . '</tr>' . "\n";
     echo '<tr valign="top">' . '<th scope="row">' . __('Exclude Pages', 'xml-sitemaps') . '</th>' . '<td>' . '<p>' . __('IDs of pages you do not wish to include in your sitemap separated by commas (\',\'):', 'xml-sitemaps') . '</p>' . "\n" . '<input type="text" name="exclude_pages"' . ' class="widefat code"' . ' value="' . esc_attr($options['exclude_pages']) . '"' . ' />' . '</td>' . '</tr>';
     echo '<tr>' . "\n" . '<th scope="row">' . __('Generate Mobile Sitemap', 'xml-sitemaps') . '</th>' . "\n" . '<td>' . '<label>' . '<input type="checkbox" name="mobile_sitemap"' . checked((bool) $options['mobile_sitemap'], true, false) . ' />' . '&nbsp;' . __('Check if this plugin is installed on an mobile-only site, such as m.example.com or example.mobi.', 'xml-sitemaps') . '</label>' . '</td>' . "\n" . '</tr>' . "\n";
     echo "</table>\n";
     echo '<div class="submit">' . '<input type="submit"' . ' value="' . esc_attr(__('Save Changes', 'xml-sitemaps')) . '"' . " />" . "</div>\n";
     echo '</form>' . "\n";
     echo '</div>' . "\n";
 }