Ejemplo n.º 1
0
 /**
  * If the given string ends with the given suffix or any portion thereof, the suffix or suffix portion is removed.
  * 
  * @param string $str The string from which the provided suffix should be trimmed if located.
  * @param string $totrim The suffix that should be trimmed if it or a portion of it is found.
  * @return string The possibly-trimmed string.
  */
 function rtrim_substr($str, $totrim)
 {
     for ($i = strlen($totrim); $i > 0; $i--) {
         $totrimsub = substr($totrim, 0, $i);
         if (sustr::endswith($str, $totrimsub)) {
             return sustr::rtrim_str($str, $totrimsub);
         }
     }
     return $str;
 }
 function nobase_rewrite_rules($rules)
 {
     $rules = array();
     $tax_name = sustr::rtrim_str(current_filter(), '_rewrite_rules');
     $tax_obj = get_taxonomy($tax_name);
     wp_cache_flush();
     //Otherwise get_terms() won't include the term just added
     $terms = get_terms($tax_name);
     if ($terms && !is_wp_error($terms)) {
         foreach ($terms as $term_obj) {
             $term_slug = suwp::get_term_slug($term_obj);
             if ($tax_obj->query_var && is_string($tax_obj->query_var)) {
                 $url_start = "index.php?{$tax_obj->query_var}=";
             } else {
                 $url_start = "index.php?taxonomy={$tax_name}&term=";
             }
             if ($this->get_setting('add_rule_if_conflict', true) || get_page_by_path($term_slug) === null) {
                 $rules['(' . $term_slug . ')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = $url_start . '$matches[1]&feed=$matches[2]';
                 $rules['(' . $term_slug . ')/page/?([0-9]{1,})/?$'] = $url_start . '$matches[1]&paged=$matches[2]';
                 $rules['(' . $term_slug . ')/?$'] = $url_start . '$matches[1]';
             }
         }
     }
     global $wp_rewrite;
     $old_base = $wp_rewrite->get_extra_permastruct($tax_name);
     $old_base = str_replace("%{$tax_name}%", '(.+)', $old_base);
     $old_base = trim($old_base, '/');
     $rules[$old_base . '$'] = 'index.php?su_term_redirect=$matches[1]';
     return $rules;
 }