/** * Filter the stopwords from the slug * * @param string $slug The current slug, if not empty there will be done nothing. * @param string $post_title The title which will be used in case of an empty slug. * * @return string */ public function filter_stopwords_from_slug($slug, $post_title) { // Don't change an existing slug. if (isset($slug) && $slug !== '') { return $slug; } // When the post title is empty, just return the slug. if (empty($post_title)) { return $slug; } // Don't change the slug if this is a multisite installation and the site has been switched. if (is_multisite() && ms_is_switched()) { return $slug; } // Don't change slug if the post is a draft, this conflicts with polylang. // Doesn't work with filter_input() since need current value, not originally submitted one. if ('draft' === $_POST['post_status']) { return $slug; } // Lowercase the slug and strip slashes. $new_slug = sanitize_title(stripslashes($post_title)); $stop_words = new WPSEO_Admin_Stop_Words(); return $stop_words->remove_in($new_slug); }
/** * 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; }