/**
 * On plugins_loaded: load the minimum amount of essential files for this plugin
 */
function wpseo_init()
{
    require_once WPSEO_PATH . 'inc/wpseo-functions.php';
    // Make sure our option and meta value validation routines and default values are always registered and available
    WPSEO_Options::get_instance();
    WPSEO_Meta::init();
    $options = WPSEO_Options::get_all();
    if (version_compare($options['version'], WPSEO_VERSION, '<')) {
        new WPSEO_Upgrade();
        // get a cleaned up version of the $options
        $options = WPSEO_Options::get_all();
    }
    if ($options['stripcategorybase'] === true) {
        $GLOBALS['wpseo_rewrite'] = new WPSEO_Rewrite();
    }
    if ($options['enablexmlsitemap'] === true) {
        $GLOBALS['wpseo_sitemaps'] = new WPSEO_Sitemaps();
    }
    if (!defined('DOING_AJAX') || !DOING_AJAX) {
        require_once WPSEO_PATH . 'inc/wpseo-non-ajax-functions.php';
    }
}
/**
 * On plugins_loaded: load the minimum amount of essential files for this plugin
 */
function wpseo_init()
{
    require_once WPSEO_PATH . 'inc/wpseo-functions.php';
    // Make sure our option and meta value validation routines and default values are always registered and available.
    WPSEO_Options::get_instance();
    WPSEO_Meta::init();
    $options = WPSEO_Options::get_options(array('wpseo', 'wpseo_permalinks', 'wpseo_xml'));
    if (version_compare($options['version'], WPSEO_VERSION, '<')) {
        new WPSEO_Upgrade();
        // Get a cleaned up version of the $options.
        $options = WPSEO_Options::get_options(array('wpseo', 'wpseo_permalinks', 'wpseo_xml'));
    }
    if ($options['stripcategorybase'] === true) {
        $GLOBALS['wpseo_rewrite'] = new WPSEO_Rewrite();
    }
    if ($options['enablexmlsitemap'] === true) {
        $GLOBALS['wpseo_sitemaps'] = new WPSEO_Sitemaps();
    }
    if (!defined('DOING_AJAX') || !DOING_AJAX) {
        require_once WPSEO_PATH . 'inc/wpseo-non-ajax-functions.php';
    }
    // Init it here because the filter must be present on the frontend as well or it won't work in the customizer.
    new WPSEO_Customizer();
}
/**
 * Removes stopword from the sample permalink that is generated in an AJAX request
 *
 * @param array  $permalink The permalink generated for this post by WordPress.
 * @param int    $post_ID The ID of the post.
 * @param string $title The title for the post that the user used.
 * @param string $name The name for the post that the user used.
 *
 * @return array
 */
function wpseo_remove_stopwords_sample_permalink($permalink, $post_ID, $title, $name)
{
    WPSEO_Options::get_instance();
    $options = WPSEO_Options::get_options(array('wpseo_permalinks'));
    if ($options['cleanslugs'] !== true) {
        return $permalink;
    }
    /*
     * If the name is empty and the title is not, WordPress will generate a slug. In that case we want to remove stop
     * words from the slug.
     */
    if (empty($name) && !empty($title)) {
        $stop_words = new WPSEO_Admin_Stop_Words();
        // The second element is the slug.
        $permalink[1] = $stop_words->remove_in($permalink[1]);
    }
    return $permalink;
}