本文整理汇总了PHP中WPSEO_Utils类的典型用法代码示例。如果您正苦于以下问题:PHP WPSEO_Utils类的具体用法?PHP WPSEO_Utils怎么用?PHP WPSEO_Utils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WPSEO_Utils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Checks if Yoast SEO is installed for the first time.
*/
public function __construct()
{
$is_first_install = $this->is_first_install();
if ($is_first_install && WPSEO_Utils::is_api_available()) {
add_action('wpseo_activate', array($this, 'set_first_install_options'));
}
}
示例2: get_home_url
/**
* Get Home URL
*
* This has been moved from the constructor because wp_rewrite is not available on plugins_loaded in multisite.
* It will now be requested on need and not on initialization.
*
* @return string
*/
protected function get_home_url()
{
if (!isset($this->home_url)) {
$this->home_url = WPSEO_Utils::home_url();
}
return $this->home_url;
}
示例3: get_home_url
/**
* Get Home URL
*
* This has been moved from the constructor because wp_rewrite is not available on plugins_loaded in multisite.
* It will now be requested on need and not on initialization.
*
* @return string
*/
protected function get_home_url()
{
if (!isset(self::$home_url)) {
self::$home_url = WPSEO_Utils::home_url();
}
return self::$home_url;
}
示例4: add_admin
/**
* Adding a new admin
*
* @param string $admin_name Name string.
* @param string $admin_id ID string.
*
* @return string
*/
public function add_admin($admin_name, $admin_id)
{
$success = 0;
// If one of the fields is empty.
if (empty($admin_name) || empty($admin_id)) {
$response_body = $this->get_response_body('not_present');
} else {
$admin_id = $this->parse_admin_id($admin_id);
if (!isset($this->options['fb_admins'][$admin_id])) {
$name = sanitize_text_field(urldecode($admin_name));
$admin_id = sanitize_text_field($admin_id);
if (preg_match('/[0-9]+?/', $admin_id) && preg_match('/[\\w\\s]+?/', $name)) {
$this->options['fb_admins'][$admin_id]['name'] = $name;
$this->options['fb_admins'][$admin_id]['link'] = urldecode('http://www.facebook.com/' . $admin_id);
$this->save_options();
$success = 1;
$response_body = $this->form->get_admin_link($admin_id, $this->options['fb_admins'][$admin_id]);
} else {
$response_body = $this->get_response_body('invalid_format');
}
} else {
$response_body = $this->get_response_body('already_exists');
}
}
return WPSEO_Utils::json_encode(array('success' => $success, 'html' => $response_body));
}
示例5: __construct
/**
* Constructor for the WPSEO_Local_Core class.
*
* @since 1.0
*/
function __construct()
{
$this->options = get_option("wpseo_local");
$this->days = array('monday' => __('Monday', 'yoast-local-seo'), 'tuesday' => __('Tuesday', 'yoast-local-seo'), 'wednesday' => __('Wednesday', 'yoast-local-seo'), 'thursday' => __('Thursday', 'yoast-local-seo'), 'friday' => __('Friday', 'yoast-local-seo'), 'saturday' => __('Saturday', 'yoast-local-seo'), 'sunday' => __('Sunday', 'yoast-local-seo'));
if (wpseo_has_multiple_locations()) {
add_action('init', array($this, 'create_custom_post_type'), 10, 1);
add_action('init', array($this, 'create_taxonomies'), 10, 1);
add_action('init', array($this, 'exclude_taxonomy'), 10, 1);
}
if (is_admin()) {
$this->license_manager = $this->get_license_manager();
$this->license_manager->setup_hooks();
add_action('wpseo_licenses_forms', array($this->license_manager, 'show_license_form'));
add_action('update_option_wpseo_local', array($this, 'save_permalinks_on_option_save'), 10, 2);
// Setting action for removing the transient on update options
if (method_exists('WPSEO_Utils', 'register_cache_clear_option')) {
WPSEO_Utils::register_cache_clear_option('wpseo_local', 'kml');
}
} else {
// XML Sitemap Index addition
add_action('template_redirect', array($this, 'redirect_old_sitemap'));
add_action('init', array($this, 'init'), 11);
add_filter('wpseo_sitemap_index', array($this, 'add_to_index'));
}
// Add support for Jetpack's Omnisearch
add_action('init', array($this, 'support_jetpack_omnisearch'));
add_action('save_post', array($this, 'invalidate_sitemap'));
// Run update if needed
add_action('plugins_loaded', array(&$this, 'do_upgrade'), 14);
// Extend the search with metafields
add_action('pre_get_posts', array(&$this, 'enhance_search'));
add_filter('the_excerpt', array(&$this, 'enhance_location_search_results'));
}
示例6: filter_input_post
/**
* Filter POST variables.
*
* @param string $var_name
*
* @return mixed
*/
private function filter_input_post($var_name)
{
$val = filter_input(INPUT_POST, $var_name);
if ($val) {
return WPSEO_Utils::sanitize_text_field($val);
}
return '';
}
示例7: print_scripts
/**
* Prints the pointer script
*
* @param string $selector The CSS selector the pointer is attached to.
* @param array $options The options for the pointer.
*/
public function print_scripts($selector, $options)
{
// Button1 is the close button, which always exists.
$button_array_defaults = array('button2' => array('text' => false, 'function' => ''), 'button3' => array('text' => false, 'function' => ''));
$this->button_array = wp_parse_args($this->button_array, $button_array_defaults);
?>
<script type="text/javascript">
//<![CDATA[
(function ($) {
// Don't show the tour on screens with an effective width smaller than 1024px or an effective height smaller than 768px.
if (jQuery(window).width() < 1024 || jQuery(window).availWidth < 1024) {
return;
}
var wpseo_pointer_options = <?php
echo WPSEO_Utils::json_encode($options);
?>
, setup;
wpseo_pointer_options = $.extend(wpseo_pointer_options, {
buttons: function (event, t) {
var button = jQuery('<a href="<?php
echo $this->get_ignore_url();
?>
" id="pointer-close" style="margin:0 5px;" class="button-secondary">' + '<?php
_e('Close', 'wordpress-seo');
?>
' + '</a>');
button.bind('click.pointer', function () {
t.element.pointer('close');
});
return button;
},
close: function () {
}
});
setup = function () {
$('<?php
echo $selector;
?>
').pointer(wpseo_pointer_options).pointer('open');
var lastOpenedPointer = jQuery( '.wp-pointer').slice( -1 );
<?php
$this->button2();
$this->button3();
?>
};
if (wpseo_pointer_options.position && wpseo_pointer_options.position.defer_loading)
$(window).bind('load.wp-pointers', setup);
else
$(document).ready(setup);
})(jQuery);
//]]>
</script>
<?php
}
示例8: init
/**
* Make sure the needed scripts are loaded for admin pages
*/
function init()
{
if (filter_input(INPUT_GET, 'wpseo_reset_defaults') && wp_verify_nonce(filter_input(INPUT_GET, 'nonce'), 'wpseo_reset_defaults') && current_user_can('manage_options')) {
WPSEO_Options::reset();
wp_redirect(admin_url('admin.php?page=wpseo_dashboard'));
}
if (WPSEO_Utils::grant_access()) {
add_action('admin_enqueue_scripts', array($this, 'config_page_scripts'));
add_action('admin_enqueue_scripts', array($this, 'config_page_styles'));
}
}
示例9: get_post
/**
* Retrieves post data given a post ID or the global
*
* @return array|null|WP_Post Returns a post if found, otherwise returns an empty array.
*/
private function get_post()
{
if ($post = filter_input(INPUT_GET, 'post')) {
$post_id = (int) WPSEO_Utils::validate_int($post);
return get_post($post_id);
}
if (isset($GLOBALS['post'])) {
return $GLOBALS['post'];
}
return array();
}
示例10: recalculate_scores
/**
* Start recalculation
*/
public function recalculate_scores()
{
check_ajax_referer('wpseo_recalculate', 'nonce');
$fetch_object = $this->get_fetch_object();
if (!empty($fetch_object)) {
$paged = filter_input(INPUT_POST, 'paged', FILTER_VALIDATE_INT);
$response = $fetch_object->get_items_to_recalculate($paged);
if (!empty($response)) {
wp_die(WPSEO_Utils::json_encode($response));
}
}
wp_die('');
}
示例11: get_datetime_with_timezone
/**
* Get the datetime object, in site's time zone, if the datetime string was valid
*
* @todo This is messed up, output type changed, doc wrong. Revert, add new method for formatted. R.
*
* @param string $datetime_string The datetime string in UTC time zone, that needs to be converted to a DateTime object.
* @param string $format Date format to use.
*
* @return DateTime|null in site's time zone
*/
public function get_datetime_with_timezone($datetime_string, $format = 'c')
{
static $utc_timezone, $local_timezone;
if (!isset($utc_timezone)) {
$utc_timezone = new DateTimeZone('UTC');
$local_timezone = new DateTimeZone($this->get_timezone_string());
}
if (!empty($datetime_string) && WPSEO_Utils::is_valid_datetime($datetime_string)) {
$datetime = new DateTime($datetime_string, $utc_timezone);
$datetime->setTimezone($local_timezone);
return $datetime->format($format);
}
return null;
}
示例12: addPostMeta
/**
* Post Meta
*/
public function addPostMeta($post)
{
// Hidden in Nested Pages?
$np_status = get_post_meta($post->ID, 'nested_pages_status', true);
$this->post_data->np_status = $np_status == 'hide' ? 'hide' : 'show';
// Yoast Score
if (function_exists('wpseo_auto_load')) {
$yoast_score = get_post_meta($post->ID, '_yoast_wpseo_meta-robots-noindex', true);
if (!$yoast_score) {
$yoast_score = get_post_meta($post->ID, '_yoast_wpseo_linkdex', true);
$this->post_data->score = \WPSEO_Utils::translate_score($yoast_score);
} else {
$this->post_data->score = 'noindex';
}
}
}
示例13: init
/**
* Run init logic.
*/
public function init()
{
// Setting the screen option.
if (filter_input(INPUT_GET, 'page') === 'wpseo_search_console') {
if (filter_input(INPUT_GET, 'tab') !== 'settings' && WPSEO_GSC_Settings::get_profile() === '') {
wp_redirect(add_query_arg('tab', 'settings'));
exit;
}
$this->set_hooks();
$this->set_dependencies();
$this->request_handler();
} elseif (WPSEO_Utils::is_yoast_seo_page() && current_user_can('manage_options') && WPSEO_GSC_Settings::get_profile() === '' && get_user_option('wpseo_dismissed_gsc_notice', get_current_user_id()) !== '1') {
add_action('admin_init', array($this, 'register_gsc_notification'));
}
add_action('admin_init', array($this, 'register_settings'));
}
示例14: config_page_scripts
/**
* Loads the required scripts for the config page.
*/
function config_page_scripts()
{
$this->asset_manager->enqueue_script('admin-script');
wp_localize_script(WPSEO_Admin_Asset_Manager::PREFIX . 'admin-script', 'wpseoAdminL10n', $this->localize_admin_script());
wp_enqueue_script('dashboard');
wp_enqueue_script('thickbox');
$page = filter_input(INPUT_GET, 'page');
wp_localize_script(WPSEO_Admin_Asset_Manager::PREFIX . 'admin-script', 'wpseoSelect2Locale', WPSEO_Utils::get_language(get_locale()));
if (in_array($page, array('wpseo_social', WPSEO_Admin::PAGE_IDENTIFIER))) {
wp_enqueue_media();
$this->asset_manager->enqueue_script('admin-media');
wp_localize_script(WPSEO_Admin_Asset_Manager::PREFIX . 'admin-media', 'wpseoMediaL10n', $this->localize_media_script());
}
if ('wpseo_tools' === $page) {
$this->enqueue_tools_scripts();
}
}
示例15: addPostMeta
/**
* Post Meta
*/
public function addPostMeta($post)
{
$meta = get_metadata('post', $post->ID);
$this->post_data->nav_title = isset($meta['np_nav_title'][0]) ? $meta['np_nav_title'][0] : null;
$this->post_data->link_target = isset($meta['np_link_target'][0]) ? $meta['np_link_target'][0] : null;
$this->post_data->nav_title_attr = isset($meta['np_title_attribute'][0]) ? $meta['np_title_attribute'][0] : null;
$this->post_data->nav_css = isset($meta['np_nav_css_classes'][0]) ? $meta['np_nav_css_classes'][0] : null;
$this->post_data->nav_object = isset($meta['np_nav_menu_item_object'][0]) ? $meta['np_nav_menu_item_object'][0] : null;
$this->post_data->nav_object_id = isset($meta['np_nav_menu_item_object_id'][0]) ? $meta['np_nav_menu_item_object_id'][0] : null;
$this->post_data->nav_type = isset($meta['np_nav_menu_item_type'][0]) ? $meta['np_nav_menu_item_type'][0] : null;
$this->post_data->nav_status = isset($meta['np_nav_status'][0]) && $meta['np_nav_status'][0] == 'hide' ? 'hide' : 'show';
$this->post_data->np_status = isset($meta['nested_pages_status'][0]) && $meta['nested_pages_status'][0] == 'hide' ? 'hide' : 'show';
$this->post_data->template = isset($meta['_wp_page_template'][0]) ? $meta['_wp_page_template'][0] : false;
// Yoast Score
if (function_exists('wpseo_auto_load')) {
$yoast_score = get_post_meta($post->ID, '_yoast_wpseo_meta-robots-noindex', true);
if (!$yoast_score) {
$yoast_score = get_post_meta($post->ID, '_yoast_wpseo_linkdex', true);
$this->post_data->score = \WPSEO_Utils::translate_score($yoast_score);
} else {
$this->post_data->score = 'noindex';
}
}
}