Edit File by line
/home/barbar84/www/wp-conte.../plugins/wordpres.../src/helpers
File: options-helper.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Helpers;
[2] Fix | Delete
[3] Fix | Delete
use WPSEO_Option_Titles;
[4] Fix | Delete
use WPSEO_Options;
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* A helper object for options.
[8] Fix | Delete
*/
[9] Fix | Delete
class Options_Helper {
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* Retrieves a single field from any option for the SEO plugin. Keys are always unique.
[13] Fix | Delete
*
[14] Fix | Delete
* @codeCoverageIgnore We have to write test when this method contains own code.
[15] Fix | Delete
*
[16] Fix | Delete
* @param string $key The key it should return.
[17] Fix | Delete
* @param mixed $default The default value that should be returned if the key isn't set.
[18] Fix | Delete
*
[19] Fix | Delete
* @return mixed|null Returns value if found, $default if not.
[20] Fix | Delete
*/
[21] Fix | Delete
public function get( $key, $default = null ) {
[22] Fix | Delete
return WPSEO_Options::get( $key, $default );
[23] Fix | Delete
}
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* Sets a single field to the options.
[27] Fix | Delete
*
[28] Fix | Delete
* @param string $key The key to set.
[29] Fix | Delete
* @param mixed $value The value to set.
[30] Fix | Delete
*
[31] Fix | Delete
* @return mixed|null Returns value if found.
[32] Fix | Delete
*/
[33] Fix | Delete
public function set( $key, $value ) {
[34] Fix | Delete
return WPSEO_Options::set( $key, $value );
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
/**
[38] Fix | Delete
* Get a specific default value for an option.
[39] Fix | Delete
*
[40] Fix | Delete
* @param string $option_name The option for which you want to retrieve a default.
[41] Fix | Delete
* @param string $key The key within the option who's default you want.
[42] Fix | Delete
*
[43] Fix | Delete
* @return mixed The default value.
[44] Fix | Delete
*/
[45] Fix | Delete
public function get_default( $option_name, $key ) {
[46] Fix | Delete
return WPSEO_Options::get_default( $option_name, $key );
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
/**
[50] Fix | Delete
* Retrieves the title separator.
[51] Fix | Delete
*
[52] Fix | Delete
* @return string The title separator.
[53] Fix | Delete
*/
[54] Fix | Delete
public function get_title_separator() {
[55] Fix | Delete
$default = $this->get_default( 'wpseo_titles', 'separator' );
[56] Fix | Delete
[57] Fix | Delete
// Get the titles option and the separator options.
[58] Fix | Delete
$separator = $this->get( 'separator' );
[59] Fix | Delete
$seperator_options = $this->get_separator_options();
[60] Fix | Delete
[61] Fix | Delete
// This should always be set, but just to be sure.
[62] Fix | Delete
if ( isset( $seperator_options[ $separator ] ) ) {
[63] Fix | Delete
// Set the new replacement.
[64] Fix | Delete
$replacement = $seperator_options[ $separator ];
[65] Fix | Delete
}
[66] Fix | Delete
elseif ( isset( $seperator_options[ $default ] ) ) {
[67] Fix | Delete
$replacement = $seperator_options[ $default ];
[68] Fix | Delete
}
[69] Fix | Delete
else {
[70] Fix | Delete
$replacement = \reset( $seperator_options );
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
/**
[74] Fix | Delete
* Filter: 'wpseo_replacements_filter_sep' - Allow customization of the separator character(s).
[75] Fix | Delete
*
[76] Fix | Delete
* @api string $replacement The current separator.
[77] Fix | Delete
*/
[78] Fix | Delete
return \apply_filters( 'wpseo_replacements_filter_sep', $replacement );
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
/**
[82] Fix | Delete
* Retrieves a default value from the option titles.
[83] Fix | Delete
*
[84] Fix | Delete
* @param string $option_titles_key The key of the option title you wish to get.
[85] Fix | Delete
*
[86] Fix | Delete
* @return string The option title.
[87] Fix | Delete
*/
[88] Fix | Delete
public function get_title_default( $option_titles_key ) {
[89] Fix | Delete
$default_titles = $this->get_title_defaults();
[90] Fix | Delete
if ( ! empty( $default_titles[ $option_titles_key ] ) ) {
[91] Fix | Delete
return $default_titles[ $option_titles_key ];
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
return '';
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
/**
[98] Fix | Delete
* Retrieves the default option titles.
[99] Fix | Delete
*
[100] Fix | Delete
* @codeCoverageIgnore We have to write test when this method contains own code.
[101] Fix | Delete
*
[102] Fix | Delete
* @return array The title defaults.
[103] Fix | Delete
*/
[104] Fix | Delete
protected function get_title_defaults() {
[105] Fix | Delete
return WPSEO_Option_Titles::get_instance()->get_defaults();
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
/**
[109] Fix | Delete
* Get the available separator options.
[110] Fix | Delete
*
[111] Fix | Delete
* @return array
[112] Fix | Delete
*/
[113] Fix | Delete
protected function get_separator_options() {
[114] Fix | Delete
return WPSEO_Option_Titles::get_instance()->get_separator_options();
[115] Fix | Delete
}
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function