本文整理汇总了PHP中WPSEO_Options::get_option_instance方法的典型用法代码示例。如果您正苦于以下问题:PHP WPSEO_Options::get_option_instance方法的具体用法?PHP WPSEO_Options::get_option_instance怎么用?PHP WPSEO_Options::get_option_instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WPSEO_Options
的用法示例。
在下文中一共展示了WPSEO_Options::get_option_instance方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_custom_field_names
/**
* Retrieve all custom field names set in SEO ->
*
* @return array
*/
private function get_custom_field_names()
{
$custom_field_names = array();
$post = $this->get_post();
$options = get_option(WPSEO_Options::get_option_instance('wpseo_titles')->option_name, array());
if (is_object($post)) {
$target_option = 'page-analyse-extra-' . $post->post_type;
if (array_key_exists($target_option, $options)) {
$custom_field_names = explode(',', $options[$target_option]);
}
}
return $custom_field_names;
}
示例2: filter_page_analysis
/**
* Filter for adding custom fields to page analysis
*
* Based on the configured custom fields for page analysis. this filter will get the needed values from post_meta
* and add them to the $page_content. Page analysis will be able to scan the content of these customs fields by
* doing this. - If value doesn't exists as a post-meta value, there will be nothing included.
*
* @param string $page_content The content of the current post text.
* @param object $post The total object of the post content.
*
* @return string $page_content
*/
public function filter_page_analysis($page_content, $post)
{
$options = get_option(WPSEO_Options::get_option_instance('wpseo_titles')->option_name, array());
$target_option = 'page-analyse-extra-' . $post->post_type;
if (array_key_exists($target_option, $options)) {
$custom_fields = explode(',', $options[$target_option]);
if (is_array($custom_fields)) {
foreach ($custom_fields as $custom_field) {
$custom_field_data = get_post_meta($post->ID, $custom_field, true);
if (!empty($custom_field_data)) {
$page_content .= ' ' . $custom_field_data;
}
}
}
}
return $page_content;
}
示例3: unzip_file
$unzipped = unzip_file($file['file'], $p_path);
if (!is_wp_error($unzipped)) {
$filename = $p_path . 'settings.ini';
if (@is_file($filename) && is_readable($filename)) {
$options = parse_ini_file($filename, true);
if (is_array($options) && $options !== array()) {
$old_wpseo_version = null;
if (isset($options['wpseo']['version']) && $options['wpseo']['version'] !== '') {
$old_wpseo_version = $options['wpseo']['version'];
}
foreach ($options as $name => $optgroup) {
if ($name === 'wpseo_taxonomy_meta') {
$optgroup = json_decode(urldecode($optgroup['wpseo_taxonomy_meta']), true);
}
// Make sure that the imported options are cleaned/converted on import
$option_instance = WPSEO_Options::get_option_instance($name);
if (is_object($option_instance) && method_exists($option_instance, 'import')) {
$optgroup = $option_instance->import($optgroup, $old_wpseo_version, $options);
} elseif (WP_DEBUG === true || defined('WPSEO_DEBUG') && WPSEO_DEBUG === true) {
$content .= '<p><strong>' . sprintf(__('Setting "%s" is no longer used and has been discarded.', 'wordpress-seo'), $name) . '</strong></p>';
}
}
$content .= '<p><strong>' . __('Settings successfully imported.', 'wordpress-seo') . '</strong></p>';
} else {
$content .= '<p><strong>' . __('Settings could not be imported:', 'wordpress-seo') . ' ' . __('No settings found in file.', 'wordpress-seo') . '</strong></p>';
}
unset($options, $name, $optgroup);
} else {
$content .= '<p><strong>' . __('Settings could not be imported:', 'wordpress-seo') . ' ' . __('Unzipping failed - file settings.ini not found.', 'wordpress-seo') . '</strong></p>';
}
@unlink($filename);
示例4: parse_option_group
/**
* Parse the option group and import it
*
* @param string $name
* @param array $opt_group
* @param array $options
*/
private function parse_option_group($name, $opt_group, $options)
{
if ($name === 'wpseo_taxonomy_meta') {
$opt_group = json_decode(urldecode($opt_group['wpseo_taxonomy_meta']), true);
}
// Make sure that the imported options are cleaned/converted on import
$option_instance = WPSEO_Options::get_option_instance($name);
if (is_object($option_instance) && method_exists($option_instance, 'import')) {
$option_instance->import($opt_group, $this->old_wpseo_version, $options);
} elseif (WP_DEBUG === true || defined('WPSEO_DEBUG') && WPSEO_DEBUG === true) {
$this->msg = sprintf(__('Setting "%s" is no longer used and has been discarded.', 'wordpress-seo'), $name);
}
}
示例5: import_seo_settings
public function import_seo_settings($file)
{
if (!empty($file)) {
$upload_dir = wp_upload_dir();
if (!defined('DIRECTORY_SEPARATOR')) {
define('DIRECTORY_SEPARATOR', '/');
}
$p_path = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'wpseo-import' . DIRECTORY_SEPARATOR;
if (!isset($GLOBALS['wp_filesystem']) || !is_object($GLOBALS['wp_filesystem'])) {
WP_Filesystem();
}
$unzipped = unzip_file($file, $p_path);
if (!is_wp_error($unzipped)) {
$filename = $p_path . 'settings.ini';
if (@is_file($filename) && is_readable($filename)) {
$options = parse_ini_file($filename, true);
if (is_array($options) && $options !== array()) {
$old_wpseo_version = null;
if (isset($options['wpseo']['version']) && $options['wpseo']['version'] !== '') {
$old_wpseo_version = $options['wpseo']['version'];
}
foreach ($options as $name => $optgroup) {
if ($name === 'wpseo_taxonomy_meta') {
$optgroup = json_decode(urldecode($optgroup['wpseo_taxonomy_meta']), true);
}
// Make sure that the imported options are cleaned/converted on import
$option_instance = WPSEO_Options::get_option_instance($name);
if (is_object($option_instance) && method_exists($option_instance, 'import')) {
$optgroup = $option_instance->import($optgroup, $old_wpseo_version, $options);
}
}
return true;
} else {
throw new Exception(__('Settings could not be imported:', 'wordpress-seo'));
}
unset($options, $name, $optgroup);
} else {
throw new Exception(__('Settings could not be imported:', 'wordpress-seo'));
}
@unlink($filename);
@unlink($p_path);
} else {
throw new Exception(__('Settings could not be imported:', 'wordpress-seo') . ' ' . sprintf(__('Unzipping failed with error "%s".', 'wordpress-seo'), $unzipped->get_error_message()));
}
unset($zip, $unzipped);
@unlink($file);
} else {
throw new Exception(__('Settings could not be imported:', 'wordpress-seo') . ' ' . __('Upload failed.', 'wordpress-seo'));
}
return false;
}