\ BWP_Sitemaps

Copyright (c) 2011 Khang Minh <contact@betterwp.net>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Summary

Methods
Properties
Constants
__construct()
add_icon()
get_version()
get_current_php_version()
get_current_wp_version()
warn_required_versions()
show_header()
show_sidebar_right()
show_version()
build_wp_properties()
pre_init()
init()
update_options()
update_site_options()
update_some_options()
remove_some_options()
get_options_by_keys()
install()
uninstall()
upgrade_plugin()
init_upgrade_plugin()
get_admin_page_url()
safe_redirect()
plugin_action_links()
init_admin_page()
init_admin_menu()
show_option_page()
add_notice_flash()
add_error_flash()
add_container_flash()
add_notice()
show_notices()
add_error()
has_error()
show_errors()
add_url()
get_url()
get_bridge()
get_cache()
get_current_timezone()
is_option_key_valid()
is_multisite()
is_subdomain_install()
is_super_admin()
is_site_admin()
is_multisite_admin()
is_on_main_blog()
is_on_sub_blog()
can_update_site_option()
is_apache()
is_nginx()
insert_query_vars()
insert_rewrite_rules()
get_cache_directory()
get_sitemap_url()
get_sitemap_index_url()
show_option_pages()
add_external_page_modal()
handle_dynamic_generator_options()
handle_dynamic_image_sitemap_options()
handle_dynamic_google_news_options()
handle_google_news_option_changes()
add_flush_cache_buttons()
add_clear_log_button()
flush_cache()
handle_exclude_posts()
handle_exclude_terms()
commit_logs()
log_message()
elog()
log_error()
slog()
log_success()
nlog()
log_notice()
smlog()
log_sitemap()
get_sitemap_logger()
do_robots()
add_excluded_posts()
add_excluded_terms()
add_external_pages()
add_post_title_like_query_variable()
add_module()
remove_module()
request_sitemap()
is_gzipped()
ping_google_news()
ping()
set_post_excluder()
set_term_excluder()
get_provider()
get_ajax_handler()
is_image_sitemap_allowed_for()
get_news_name()
$options
$options_default
$site_options
$current_options
$option_keys
$extra_option_keys
$option_pages
$current_option_page
$plugin_key
$plugin_full_key
$plugin_ckey
$plugin_dkey
$plugin_title
$plugin_url
$urls
$plugin_file
$plugin_folder
$plugin_wp_url
$plugin_ver
$notices
$notice_shown
$errors
$error_shown
$plugin_cap
$need_media_filters
$form_tabs
$wp_ver
$php_ver
$revision
$domain
$modules
$requested_modules
$module_directory
$custom_module_directory
$module_map
$frequencies
$priorities
$pings_per_day
$ping_timeout
$post_types
$taxonomies
$terms
$templates
$module_data
$build_data
$xslt
$xslt_index
$sitemap
$sitemap_cache
$cache_time
No constants found
build_properties()
add_option_key()
add_extra_option_key()
get_dashicon()
set_version()
check_required_versions()
pre_init_actions()
init_actions()
pre_init_build_constants()
build_constants()
pre_init_build_options()
init_build_options()
build_options()
update_plugin_options()
pre_init_properties()
pre_init_load_libraries()
load_libraries()
init_shared_properties()
init_properties()
init_load_libraries()
update_plugin()
pre_init_update_plugin()
init_update_plugin()
pre_init_hooks()
init_hooks()
get_src_by_environment()
get_deps_by_environment()
register_media_file()
enqueue_media_file()
register_framework_media()
enqueue_media()
is_admin_page()
get_current_admin_page()
build_menus()
build_tabs()
build_option_page()
add_flash()
get_flash()
get_container_flash()
show_dismiss_button()
add_cap()
get_template_contents()
normalize_options()
$_menu_under_settings
$_simple_menu
$bridge
$cache
$combined_assets
$message_logger
$sitemap_logger
$post_excluder
$term_excluder
$providers
$ajax_handlers
N/A

Properties

$options

$options : array

Hold plugin options

This should return the most up-to-date options, even after a form submit

Type

array

$options_default

$options_default : array

Hold plugin default options

Type

array

$site_options

$site_options : array

Hold plugin site options (applied to whole site)

Type

array

$current_options

$current_options : array

Hold plugin current options

This should be used to get an option before it is modified by a form submit

Type

array

$option_keys

$option_keys : 

Hold db option keys

$extra_option_keys

$extra_option_keys : 

Hold extra option keys

$option_pages

$option_pages : 

Hold option pages

$current_option_page

$current_option_page : \BWP_Option_Page_V3

The current option page instance

Type

\BWP_Option_Page_V3

$plugin_key

$plugin_key : 

Key to identify plugin

$plugin_full_key

$plugin_full_key : 

Full key to identify plugin

$plugin_ckey

$plugin_ckey : 

Constant Key to identify plugin

$plugin_dkey

$plugin_dkey : 

Domain Key to identify plugin

$plugin_title

$plugin_title : 

Title of the plugin

$plugin_url

$plugin_url : 

Homepage of the plugin

$urls

$urls : 

Urls to various parts of homepage or other places

Expect to have a format of array('relative' => bool, 'url' => url)

$plugin_file

$plugin_file : 

Plugin file

$plugin_folder

$plugin_folder : 

Plugin folder

$plugin_wp_url

$plugin_wp_url : 

Plugin WP url

$plugin_ver

$plugin_ver : 

Version of the plugin

$notices

$notices : 

Message shown to user (Warning, Notes, etc.)

$notice_shown

$notice_shown : 

$errors

$errors : 

Error shown to user

$error_shown

$error_shown : 

$plugin_cap

$plugin_cap : 

Capabilities to manage this plugin

$need_media_filters

$need_media_filters : 

Whether or not to create filter for media paths

$form_tabs

$form_tabs : 

Form tabs to build

$wp_ver

$wp_ver : 

Version constraints

$php_ver

$php_ver : 

$revision

$revision : 

Number of framework revisions

$domain

$domain : 

Text domain

$modules

$modules : array

Modules to load when generating sitemapindex

Type

array

$requested_modules

$requested_modules : array

Modules to load when generating sitemapindex

Type

array

$module_directory

$module_directory : string

Directories to load modules from

Type

string

$custom_module_directory

$custom_module_directory : string

Directories to load modules from

Type

string

$module_map

$module_map : array

Mapping data for a module/sub-module

Type

array

$frequencies

$frequencies : array

Url updating frequencies

Type

array

$priorities

$priorities : array

Url crawling priorties

Type

array

$pings_per_day

$pings_per_day : integer

The maximum number of times to ping per day for each SE

Type

integer

$ping_timeout

$ping_timeout : integer

Timeout for ping request

Type

integer

$post_types

$post_types : array

A list of post type objects

Type

array

$taxonomies

$taxonomies : array

A list of taxonomy objects

Type

array

$terms

$terms : array

A list of term objects

Type

array

$templates

$templates : array

Sitemap templates

Type

array

$module_data

$module_data : array

Module data for a specific sitemap

Type

array

$build_data

$build_data : array

Sitemap generation stats

Type

array

$xslt

$xslt : string

Stylesheets for XML sitemaps

Type

string

$xslt_index

$xslt_index : string

Stylesheets for XML sitemaps

Type

string

$sitemap

$sitemap : \BWP_Sitemaps_Sitemap

The sitemap object of the currently requested sitemap

Type

\BWP_Sitemaps_Sitemap

$sitemap_cache

$sitemap_cache : \BWP_GXS_CACHE

Holds the GXS cache class

Type

\BWP_GXS_CACHE

$cache_time

$cache_time : integer

Time to keep cached sitemap files

Type

integer

$_menu_under_settings

$_menu_under_settings : 

Other special variables

$_simple_menu

$_simple_menu : 

$bridge

$bridge : \BWP_WP_Bridge

The bridge to WP

Type

\BWP_WP_Bridge

$cache

$cache : \BWP_Cache

Cache for plugins

Type

\BWP_Cache

$combined_assets

$combined_assets : array

Combined assets used for production environment

Type

array

$providers

$providers : array<mixed,\BWP_Sitemaps_Provider>

Content providers

Type

array<mixed,\BWP_Sitemaps_Provider>

Methods

__construct()

__construct(array  $meta, \BWP_WP_Bridge  $bridge = null, \BWP_Cache  $cache = null) 

Construct a new plugin with appropriate meta

Parameters

array $meta
\BWP_WP_Bridge $bridge

optional, default to null

\BWP_Cache $cache

add_icon()

add_icon() 

get_version()

get_version(  $type = '') 

Parameters

$type

get_current_php_version()

get_current_php_version(string  $version = null) 

Get or check if the current WP version is greater than a specified version

Parameters

string $version

optional

get_current_wp_version()

get_current_wp_version(string  $version = null) : string|boolean

Get or check if the current WP version is greater than a specified version

Parameters

string $version

optional

Returns

string|boolean

The current WP version or true|false if a $version parameter is provided.

warn_required_versions()

warn_required_versions() 

show_header()

show_header() 

show_sidebar_right()

show_sidebar_right() 

show_version()

show_version() 

build_wp_properties()

build_wp_properties() 

pre_init()

pre_init() 

Init parts of the plugin that require certain dependencies that are available as soon as "plugins_loaded" action is fired.

init()

init() 

Init parts of the plugin that requires certain dependencies (such as authenticated user) that are available only after WordPress fires the "init" action.

update_options()

update_options(string  $option_key, array  $options) 

Update options with a specific key

This should update $options but not $current_options. If there are site options in $options, they should use the default options.

Parameters

string $option_key
array $options

all options under the option key

update_site_options()

update_site_options(string  $option_key, array  $options) 

Update site options with a specific key, when allowed to

This should pick site options found in $options and update accordingly. This should also update $options property.

Parameters

string $option_key
array $options

all options under the option key

update_some_options()

update_some_options(string  $option_key, array  $new_options) 

Update some options under a specific key

This will update per blog options and site options. This will also accept options that have not been persisted in db.

Parameters

string $option_key
array $new_options

only the new options that need updating

remove_some_options()

remove_some_options(  $option_key, array  $options_to_remove) 

Parameters

$option_key
array $options_to_remove

get_options_by_keys()

get_options_by_keys(array  $option_keys, boolean  $default = false) 

Get current options by their keys

Parameters

array $option_keys
boolean $default

Get default options or not. Default to false.

install()

install() 

uninstall()

uninstall() 

upgrade_plugin()

upgrade_plugin(  $from,   $to) 

Parameters

$from
$to

init_upgrade_plugin()

init_upgrade_plugin(  $from,   $to) 

Parameters

$from
$to

get_admin_page_url()

get_admin_page_url(  $page = '') 

Parameters

$page

safe_redirect()

safe_redirect(  $url = null) 

Redirect internally, only when headers have not been sent

Parameters

$url

plugin_action_links()

plugin_action_links(  $links,   $file) 

Parameters

$links
$file

init_admin_page()

init_admin_page() 

init_admin_menu()

init_admin_menu() 

show_option_page()

show_option_page() 

add_notice_flash()

add_notice_flash(  $message,   $append = true) 

Parameters

$message
$append

add_error_flash()

add_error_flash(  $message,   $append = true) 

Parameters

$message
$append

add_container_flash()

add_container_flash(string  $field, string  $message, boolean  $append = true) 

Add a flash message that should be put in a form container

Parameters

string $field

the field that owns the container

string $message
boolean $append

add_notice()

add_notice(  $notice) 

Parameters

$notice

show_notices()

show_notices() 

add_error()

add_error(  $error) 

Parameters

$error

has_error()

has_error() 

show_errors()

show_errors() 

add_url()

add_url(  $key,   $url,   $relative = true) 

Parameters

$key
$url
$relative

get_url()

get_url(  $key) 

Parameters

$key

get_cache()

get_cache() : \BWP_Cache

Returns

\BWP_Cache

get_current_timezone()

get_current_timezone() : \DateTimeZone

Get current timezone set by user

Returns

\DateTimeZone

is_option_key_valid()

is_option_key_valid(string  $key) : boolean

Check whether an option key is valid

Parameters

string $key

Returns

boolean

is_multisite()

is_multisite() 

is_subdomain_install()

is_subdomain_install() 

is_super_admin()

is_super_admin() 

is_site_admin()

is_site_admin() 

is_multisite_admin()

is_multisite_admin() 

is_on_main_blog()

is_on_main_blog() 

is_on_sub_blog()

is_on_sub_blog() 

can_update_site_option()

can_update_site_option() 

is_apache()

is_apache() 

is_nginx()

is_nginx() 

insert_query_vars()

insert_query_vars(  $vars) 

Parameters

$vars

insert_rewrite_rules()

insert_rewrite_rules(  $rules) 

Parameters

$rules

get_cache_directory()

get_cache_directory() 

Gets cache directory from constant, setting or filters (in that particular order)

get_sitemap_url()

get_sitemap_url(  $slug) : string

Constructs a sitemap url (friendly or normal) based on provided slug

Parameters

$slug

Returns

string

get_sitemap_index_url()

get_sitemap_index_url() : string

Construct the url to the sitemap index

Returns

string

show_option_pages()

show_option_pages() 

add_external_page_modal()

add_external_page_modal() 

handle_dynamic_generator_options()

handle_dynamic_generator_options(array  $options) 

Parameters

array $options

handle_dynamic_image_sitemap_options()

handle_dynamic_image_sitemap_options(array  $options) 

Parameters

array $options

handle_dynamic_google_news_options()

handle_dynamic_google_news_options(array  $options) 

Parameters

array $options

handle_google_news_option_changes()

handle_google_news_option_changes() 

add_flush_cache_buttons()

add_flush_cache_buttons(  $button) 

Parameters

$button

add_clear_log_button()

add_clear_log_button(  $button) 

Parameters

$button

flush_cache()

flush_cache() : mixed

Flush sitemap cache

Returns

mixed

int|bool false if there's something wrong int the number of cached sitemaps flushed

handle_exclude_posts()

handle_exclude_posts() 

handle_exclude_terms()

handle_exclude_terms() 

commit_logs()

commit_logs() 

log_message()

log_message(string  $message, string  $type,   $deprecated = null) 

Log a message when generating a sitemap

Parameters

string $message
string $type

@since 1.4.0 before this is a boolean and optional

$deprecated

elog()

elog(  $message,   $die = false,   $error_code = 404) 

Parameters

$message
$die
$error_code

log_error()

log_error(  $message,   $die = false,   $error_code = 404) 

Parameters

$message
$die
$error_code

slog()

slog(  $message) 

Parameters

$message

log_success()

log_success(  $message) 

Parameters

$message

nlog()

nlog(  $message) 

Parameters

$message

log_notice()

log_notice(  $message) 

Parameters

$message

smlog()

smlog(  $url) 

Parameters

$url

log_sitemap()

log_sitemap(  $url) 

Parameters

$url

get_sitemap_logger()

get_sitemap_logger() 

do_robots()

do_robots(  $output,   $public) 

Parameters

$output
$public

add_excluded_posts()

add_excluded_posts(  $excluded_items,   $post_type,   $flatten = false) 

Parameters

$excluded_items
$post_type
$flatten

add_excluded_terms()

add_excluded_terms(  $excluded_items,   $taxonomy,   $flatten = false) 

Parameters

$excluded_items
$taxonomy
$flatten

add_external_pages()

add_external_pages(  $pages) 

Parameters

$pages

add_post_title_like_query_variable()

add_post_title_like_query_variable(  $where, \WP_Query  $wp_query) 

Parameters

$where
\WP_Query $wp_query

add_module()

add_module(string  $module, string|null  $sub_module = '') 

Add sitemap modules or sub modules.

This can be used to add custom sitemaps to the built-in sitemap index via the bwp_gxs_modules_built action hook.

Parameters

string $module

name of the parent module

string|null $sub_module

name of the sub module

Examples

// add to theme's functions.php
add_action('bwp_gxs_modules_built', 'bwp_gxs_modules_built');
function bwp_gxs_modules_built($modules, $post_types, $taxonomies)
{
	// need to import plugin instance
	global $bwp_gxs;

	// add "movie" post sitemap
	$bwp_gxs->add_module('post', 'movie');

	// remove "private" post sitemap
	$bwp_gxs->remove_module('post', 'private');

	// remove all page-related sitemaps
	$bwp_gxs->remove_module('page');

	// add "post format" taxonomy sitemap
	$bwp_gxs->add_module('taxonomy', 'post_format');

	// remove "tag" taxonomy sitemap
	$bwp_gxs->remove_module('taxonomy', 'post_tag');
}

remove_module()

remove_module(string  $module, string|null  $sub_module = null) 

A convenient function to remove unwanted modules or sub modules

This can be used to remove sitemaps from the built-in sitemap index via the bwp_gxs_modules_built action hook.

Parameters

string $module

name of the parent module

string|null $sub_module

name of the sub module

Examples

// add to theme's functions.php
add_action('bwp_gxs_modules_built', 'bwp_gxs_modules_built');
function bwp_gxs_modules_built($modules, $post_types, $taxonomies)
{
	// need to import plugin instance
	global $bwp_gxs;

	// add "movie" post sitemap
	$bwp_gxs->add_module('post', 'movie');

	// remove "private" post sitemap
	$bwp_gxs->remove_module('post', 'private');

	// remove all page-related sitemaps
	$bwp_gxs->remove_module('page');

	// add "post format" taxonomy sitemap
	$bwp_gxs->add_module('taxonomy', 'post_format');

	// remove "tag" taxonomy sitemap
	$bwp_gxs->remove_module('taxonomy', 'post_tag');
}

request_sitemap()

request_sitemap(  $wp_query) 

Serves sitemap when needed using correct sitemap module

Parameters

$wp_query

is_gzipped()

is_gzipped() 

ping_google_news()

ping_google_news(  $post) 

Parameters

$post

ping()

ping(  $post) 

Parameters

$post

set_post_excluder()

set_post_excluder(\BWP_Sitemaps_Excluder  $excluder) 

Parameters

set_term_excluder()

set_term_excluder(\BWP_Sitemaps_Excluder  $excluder) 

Parameters

get_provider()

get_provider(string  $name) : \BWP_Sitemaps_Provider

Get a content provider

Parameters

string $name

Returns

\BWP_Sitemaps_Provider

get_ajax_handler()

get_ajax_handler(string  $name) : \BWP_Sitemaps_Handler_AjaxHandler

Get an ajax action handler

Parameters

string $name

Returns

\BWP_Sitemaps_Handler_AjaxHandler

is_image_sitemap_allowed_for()

is_image_sitemap_allowed_for(string  $post_type) : boolean

Check whether image sitemap extension is allowed for a particular post type

This checks whether the following conditions are met:

  1. The current theme supports featured image.
  2. Image extension is enabled (this is a Google-specific extension, see https://support.google.com/webmasters/answer/178636?hl=en).
  3. The post type being checked supports featured image and is allowed to have image.

Parameters

string $post_type

Returns

boolean

get_news_name()

get_news_name() : string

Get publication name for Google news sitemap

Returns

string

build_properties()

build_properties(  $key, array  $options,   $plugin_file = '',   $plugin_url = '',   $need_media_filters = true) 

Build base properties

Parameters

$key
array $options
$plugin_file
$plugin_url
$need_media_filters

add_option_key()

add_option_key(  $key,   $option,   $title) 

Parameters

$key
$option
$title

add_extra_option_key()

add_extra_option_key(  $key,   $option,   $title) 

Parameters

$key
$option
$title

get_dashicon()

get_dashicon(  $name,   $fallback_text = '') 

Parameters

$name
$fallback_text

set_version()

set_version(  $ver = '',   $type = '') 

Parameters

$ver
$type

check_required_versions()

check_required_versions() 

pre_init_actions()

pre_init_actions() 

init_actions()

init_actions() 

pre_init_build_constants()

pre_init_build_constants() 

build_constants()

build_constants() 

pre_init_build_options()

pre_init_build_options() 

init_build_options()

init_build_options() 

build_options()

build_options() 

update_plugin_options()

update_plugin_options(  $option_key, array  $new_options) 

Parameters

$option_key
array $new_options

pre_init_properties()

pre_init_properties() 

pre_init_load_libraries()

pre_init_load_libraries() 

load_libraries()

load_libraries() 

init_shared_properties()

init_shared_properties() 

Init properties that are shared across different plugins

init_properties()

init_properties() 

init_load_libraries()

init_load_libraries() 

update_plugin()

update_plugin(  $when = '') 

Parameters

$when

pre_init_update_plugin()

pre_init_update_plugin() 

init_update_plugin()

init_update_plugin() 

pre_init_hooks()

pre_init_hooks() 

init_hooks()

init_hooks() 

get_src_by_environment()

get_src_by_environment(string  $handle, string  $dev_src, string  $prod_src = null, string  $prod_handle = null) : mixed

Get correct media src based on environment

Parameters

string $handle

media handle

string $dev_src

the source used in development environment

string $prod_src

the source used in production environment, this will be used instead of replacing $dev_src's extension when provided

string $prod_handle

the handle used in production environment

Returns

mixed

string

get_deps_by_environment()

get_deps_by_environment(array  $deps, string  $prod_handle = null) : array

Get dependencies based on environment

Parameters

array $deps

current dependencies of the item being checked

string $prod_handle

the handle used in production environment

Returns

array

register_media_file()

register_media_file(  $handle,   $src, array  $deps = array(),   $version = false, string  $prod_src = null, string  $prod_handle = null) 

Register a BWP media file

Parameters

$handle
$src
array $deps
$version
string $prod_src

the source to use when debug is off

string $prod_handle

the handle to use when debug is off

enqueue_media_file()

enqueue_media_file(  $handle,   $src, array  $deps = array(),   $version = false, string  $prod_src = null, string  $prod_handle = null) 

Enqueue a BWP media file

Parameters

$handle
$src
array $deps
$version
string $prod_src

the source to use when debug is off

string $prod_handle

the handle to use when debug is off

register_framework_media()

register_framework_media() 

Register some framework media that plugins can depend on anytime

enqueue_media()

enqueue_media() 

is_admin_page()

is_admin_page(  $page = '') 

Parameters

$page

get_current_admin_page()

get_current_admin_page() 

build_menus()

build_menus() 

Build the Menus

build_tabs()

build_tabs() 

build_option_page()

build_option_page() 

Build the option pages

add_flash()

add_flash(string  $key, string  $message, boolean  $append = true) 

Add a flash message that is shown only once

Parameters

string $key

the key to group this message

string $message

the message to display

boolean $append

append to the group or replace

get_flash()

get_flash(  $key) : array

Get all flash messages that share a key

Parameters

$key

Returns

array

get_container_flash()

get_container_flash() 

show_dismiss_button()

show_dismiss_button() 

add_cap()

add_cap(  $cap) 

Parameters

$cap

get_template_contents()

get_template_contents(string  $template_file_path, array  $data = array()) 

Get contents from a template file, with data filled with provided $data

Parameters

string $template_file_path

path to template file, starting from plugin's src directory, a leading slash is not required.

array $data

normalize_options()

normalize_options(  $options) 

Parameters

$options