/** * 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)); }
/** * 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 }
/** * 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(''); }
/** * Adds string (view) behaviour to the Notification * * @return string */ public function __toString() { $attributes = array(); // Default notification classes. $classes = array('yoast-notice', 'notice'); if (!empty($this->options['type'])) { $classes[] = $this->options['type']; } if ($this->is_persistent()) { $attributes['id'] = $this->options['id']; $classes[] = 'yoast-dismissible'; $classes[] = 'is-dismissible'; } if (!empty($classes)) { $attributes['class'] = implode(' ', $classes); } $nonce = $this->get_nonce(); if (!empty($nonce)) { $attributes['data-nonce'] = $nonce; } if (!empty($this->options['data_json'])) { $attributes['data-json'] = WPSEO_Utils::json_encode($this->options['data_json']); } // Combined attribute key and value into a string. array_walk($attributes, array($this, 'parse_attributes')); // Build the output DIV. return '<div ' . implode(' ', $attributes) . '>' . wpautop($this->message) . '</div>' . PHP_EOL; }
/** * Retrieves the keyword for the keyword doubles of the termpages. */ function ajax_get_term_keyword_usage() { $post_id = filter_input(INPUT_POST, 'post_id'); $keyword = filter_input(INPUT_POST, 'keyword'); $taxonomy = filter_input(INPUT_POST, 'taxonomy'); wp_die(WPSEO_Utils::json_encode(WPSEO_Taxonomy_Meta::get_keyword_usage($keyword, $post_id, $taxonomy))); }
/** * Write the notifications to a cookie (hooked on shutdown) */ public function set_transient() { // Count local stored notifications. if (count($this->notifications) > 0) { // Create array with all notifications. $arr_notifications = array(); // Add each notification as array to $arr_notifications. foreach ($this->notifications as $notification) { $arr_notifications[] = $notification->to_array(); } // Set the cookie with notifications. set_transient(self::TRANSIENT_KEY, WPSEO_Utils::json_encode($arr_notifications), MINUTE_IN_SECONDS * 10); } }
/** * Save persistent notifications to storage * * We need to be able to retrieve these so they can be dismissed at any time during the execution. * * @since 3.2 * * @return void */ public function update_storage() { $notifications = array_filter($this->notifications, array($this, 'filter_persistent_notifications')); // No notifications to store, clear storage. if (empty($notifications)) { $this->remove_storage(); return; } $notifications = array_map(array($this, 'notification_to_array'), $notifications); // Save the notifications to the storage. update_option(self::STORAGE_KEY, WPSEO_Utils::json_encode($notifications), true); }
/** * Adds the taxonomy meta data if there is any */ private function taxonomy_metadata() { if ($this->include_taxonomy) { $taxonomy_meta = get_option('wpseo_taxonomy_meta'); if (is_array($taxonomy_meta)) { $this->write_line('[wpseo_taxonomy_meta]', true); $this->write_setting('wpseo_taxonomy_meta', urlencode(WPSEO_Utils::json_encode($taxonomy_meta))); } else { $this->write_line('; ' . __('No taxonomy metadata found', 'wordpress-seo'), true); } } }
/** * Retrieves the keyword for the keyword doubles of the termpages. */ function ajax_get_term_keyword_usage() { $post_id = filter_input(INPUT_POST, 'post_id'); $keyword = filter_input(INPUT_POST, 'keyword'); $taxonomy = filter_input(INPUT_POST, 'taxonomy'); if (!current_user_can('edit_terms')) { die('-1'); } $usage = WPSEO_Taxonomy_Meta::get_keyword_usage($keyword, $post_id, $taxonomy); // Normalize the result so it it the same as the post keyword usage AJAX request. $usage = $usage[$keyword]; wp_die(WPSEO_Utils::json_encode($usage)); }
/** * Make it possible to pass some JSON data * * @return string */ private function parse_data_json_attribute() { if (empty($this->options['data_json'])) { return ''; } return " data-json='" . WPSEO_Utils::json_encode($this->options['data_json']) . "'"; }
/** * Outputs the JSON LD code in a valid JSON+LD wrapper * * @since 1.8 * * @param string $context The context of the output, useful for filtering. */ private function output($context) { /** * Filter: 'wpseo_json_ld_output' - Allows filtering of the JSON+LD output * * @api array $output The output array, before its JSON encoded * * @param string $context The context of the output, useful to determine whether to filter or not. */ $this->data = apply_filters('wpseo_json_ld_output', $this->data, $context); if (is_array($this->data) && !empty($this->data)) { $json_data = WPSEO_Utils::json_encode($this->data); echo "<script type='application/ld+json'>", $json_data, '</script>', "\n"; } // Empty the $data array so we don't output it twice. $this->data = array(); }