WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Broken Plugin in 2.8 Release, How to fix? (3 posts)

  1. Alexandre Vallières-Lagacé
    Member
    Posted 4 years ago #

    Hi,

    I'm looking to fix a plugin I was using on 2.7 that is now broken on 2.8. I'm guessing the developer stopped the support since his website is now down.

    The plugin adds slugs to the db and when visiting one of these slugs url (ex: http://mysite.com/a-big-slug) you should be redirected to the saved URL in the db.

    Adding slugs to the db with the plugin works, I checked that. The probably lies within the building of the slugs list or using this list.

    Anything changed in that scope under WP 2.8 that can break that plugin? I'm not very hot with PHP so any help on what to look for would be appreciated!

    Thanks!

  2. Alexandre Vallières-Lagacé
    Member
    Posted 4 years ago #

    Here's a bit of code to be sure I'm not doing anything wrong...

    function wp_myplug_rewrite_rules($rules)
    {
      WPD_print("in wp_myplug_rewrite_rules");
    
      global $wp_rewrite,$wpdb,$wp_myplug_prefix;
    
      $table_name = $wpdb->prefix . $wp_myplug_prefix."_links";
      $results  = $wpdb->get_results("SELECT * FROM ".$table_name,OBJECT);
      $new_rules=Array();
    
      if($results)
      {
    
        foreach($results as $result) {
          WPD_print("  --> " . get_category_slug($result->category) . " => " . $result->slug);
          $the_slug = substr(get_category_slug($result->category)."/".$result->slug,1);
    
          $new_rules[$the_slug."$"]='index.php?wpaaction=wp_myplug_redirect&wpaslug='.urlencode($result->slug);
        }
    
        $new_rules=array_merge($new_rules,$rules);
      }
    
      WPD_print("out wp_myplug_rewrite_rules");
    
      return $new_rules;
    }
    
    function wp_myplug_init()
    {
      global $wp_rewrite;
    
      WPD_print("wp_myplug_init");
    
      if (isset($wp_rewrite) && $wp_rewrite->using_permalinks()) {
      WPD_print(" in if");
    
      add_filter('rewrite_rules_array', 'wp_myplug_rewrite_rules');
      add_filter('query_vars','wp_myplug_add_query_vars');
      add_action('parse_request','wp_myplug_parse_request');
    
      WPD_print(" after if");
    
      }
    }
    add_action('init','wp_myplug_init');

    The WPD_print function simply logs a debug statement in my footer.
    I can see that it does go in the IF statement with two add_filters and add_action, but the code in the rewrite_rules_array never gets executed...

    What am I doing wrong here?

  3. Alexandre Vallières-Lagacé
    Member
    Posted 4 years ago #

    Just found the solution!

    You have to re-save the permalink structure so that WP refreshes its cached list of permalinks.

    Just to to Settings > Permalinks and hit Save.

Topic Closed

This topic has been closed to new replies.

About this Topic