Example #1
0
/**
 * Add help tabs
 *
 * @param array $tabs Current help center tabs.
 *
 * @return array
 */
function yoast_option_tab_help_center_metas($tabs)
{
    $tabs[] = new WPSEO_Help_Center_Item('basic-help', __('Template explanation', 'wordpress-seo'), array('content' => '<p>' . sprintf(__('The title &amp; metas settings for %1$s are made up of variables that are replaced by specific values from the page when the page is displayed. The tabs on the left explain the available variables.', 'wordpress-seo'), 'Yoast SEO') . '</p>' . '<p>' . __('Note that not all variables can be used in every template.', 'wordpress-seo') . '</p>'));
    $tabs[] = new WPSEO_Help_Center_Item('title-vars', __('Basic Variables', 'wordpress-seo'), array('content' => '<h2>' . __('Basic Variables', 'wordpress-seo') . '</h2>' . WPSEO_Replace_Vars::get_basic_help_texts()));
    $tabs[] = new WPSEO_Help_Center_Item('title-vars-advanced', __('Advanced Variables', 'wordpress-seo'), array('content' => '<h2>' . __('Advanced Variables', 'wordpress-seo') . '</h2>' . WPSEO_Replace_Vars::get_advanced_help_texts()));
    return $tabs;
}
Example #2
0
 /**
  * Adds contextual help to the titles & metas page.
  */
 function title_metas_help_tab()
 {
     $screen = get_current_screen();
     $screen->set_help_sidebar('<p><strong>' . __('For more information:', 'wordpress-seo') . '</strong></p>' . '<p><a target="_blank" href="https://yoast.com/articles/wordpress-seo/#titles">' . __('Title optimization', 'wordpress-seo') . '</a></p>' . '<p><a target="_blank" href="https://yoast.com/google-page-title/">' . __('Why Google won\'t display the right page title', 'wordpress-seo') . '</a></p>');
     $screen->add_help_tab(array('id' => 'basic-help', 'title' => __('Template explanation', 'wordpress-seo'), 'content' => '<p>' . __('The title &amp; metas settings for WordPress SEO are made up of variables that are replaced by specific values from the page when the page is displayed. The tabs on the left explain the available variables.', 'wordpress-seo') . '</p>'));
     $screen->add_help_tab(array('id' => 'title-vars', 'title' => __('Basic Variables', 'wordpress-seo'), 'content' => "\n\t\t<h2>" . __('Basic Variables', 'wordpress-seo') . "</h2>\n\t\t" . WPSEO_Replace_Vars::get_basic_help_texts()));
     $screen->add_help_tab(array('id' => 'title-vars-advanced', 'title' => __('Advanced Variables', 'wordpress-seo'), 'content' => "\n\t\t<h2>" . __('Advanced Variables', 'wordpress-seo') . "</h2>\n\t\t" . WPSEO_Replace_Vars::get_advanced_help_texts()));
 }
/**
 * Retrieve a post's terms, comma delimited.
 *
 * @deprecated 1.5.4
 * @deprecated use WPSEO_Replace_Vars::get_terms()
 * @see        WPSEO_Replace_Vars::get_terms()
 *
 * @param int    $id            ID of the post to get the terms for.
 * @param string $taxonomy      The taxonomy to get the terms for this post from.
 * @param bool   $return_single If true, return the first term.
 *
 * @return string either a single term or a comma delimited string of terms.
 */
function wpseo_get_terms($id, $taxonomy, $return_single = false)
{
    _deprecated_function(__FUNCTION__, 'WPSEO 1.5.4', 'WPSEO_Replace_Vars::get_terms()');
    $replacer = new WPSEO_Replace_Vars();
    return $replacer->get_terms($id, $taxonomy, $return_single);
}
        if (is_category() || is_tag() || is_tax()) {
            $term = $GLOBALS['wp_query']->get_queried_object();
            $output = $term->name;
        } elseif (!empty($id) && !empty($taxonomy)) {
            $terms = get_the_terms($id, $taxonomy);
            if (is_array($terms) && $terms !== array()) {
                foreach ($terms as $term) {
                    if ($return_single) {
                        $output = $term->name;
                        break;
                    } else {
                        $output .= $term->name . ', ';
                    }
                }
                $output = rtrim(trim($output), ',');
            }
        }
        unset($terms, $term);
        /**
         * Allows filtering of the terms list used to replace %%category%%, %%tag%% and %%ct_<custom-tax-name>%% variables
         * @api    string    $output    Comma-delimited string containing the terms
         */
        return apply_filters('wpseo_terms', $output);
    }
}
/* End of class WPSEO_Replace_Vars */
/**
 * Setup the class statics when the file is first loaded
 */
WPSEO_Replace_Vars::setup_statics_once();
Example #5
0
/**
 * Register a new variable replacement
 *
 * This function is for use by other plugins/themes to easily add their own additional variables to replace.
 * This function should be called from a function on the 'wpseo_register_extra_replacements' action hook.
 * The use of this function is preferred over the older 'wpseo_replacements' filter as a way to add new replacements.
 * The 'wpseo_replacements' filter should still be used to adjust standard WPSEO replacement values.
 * The function can not be used to replace standard WPSEO replacement value functions and will thrown a warning
 * if you accidently try.
 * To avoid conflicts with variables registered by WPSEO and other themes/plugins, try and make the
 * name of your variable unique. Variable names also can not start with "%%cf_" or "%%ct_" as these are reserved
 * for the standard WPSEO variable variables 'cf_<custom-field-name>', 'ct_<custom-tax-name>' and
 * 'ct_desc_<custom-tax-name>'.
 * The replacement function will be passed the undelimited name (i.e. stripped of the %%) of the variable
 * to replace in case you need it.
 *
 * Example code:
 * <code>
 * <?php
 * function retrieve_var1_replacement( $var1 ) {
 *        return 'your replacement value';
 * }
 *
 * function register_my_plugin_extra_replacements() {
 *        wpseo_register_var_replacement( '%%myvar1%%', 'retrieve_var1_replacement', 'advanced', 'this is a help text for myvar1' );
 *        wpseo_register_var_replacement( 'myvar2', array( 'class', 'method_name' ), 'basic', 'this is a help text for myvar2' );
 * }
 * add_action( 'wpseo_register_extra_replacements', 'register_my_plugin_extra_replacements' );
 * ?>
 * </code>
 *
 * @since 1.5.4
 *
 * @param  string $var              The name of the variable to replace, i.e. '%%var%%'
 *                                  - the surrounding %% are optional, name can only contain [A-Za-z0-9_-].
 * @param  mixed  $replace_function Function or method to call to retrieve the replacement value for the variable
 *                                  Uses the same format as add_filter/add_action function parameter and
 *                                  should *return* the replacement value. DON'T echo it.
 * @param  string $type             Type of variable: 'basic' or 'advanced', defaults to 'advanced'.
 * @param  string $help_text        Help text to be added to the help tab for this variable.
 *
 * @return bool  Whether the replacement function was succesfully registered
 */
function wpseo_register_var_replacement($var, $replace_function, $type = 'advanced', $help_text = '')
{
    return WPSEO_Replace_Vars::register_replacement($var, $replace_function, $type, $help_text);
}