Support » Plugin: Shortlinks by Pretty Links - Best WordPress Link Tracking Plugin » Increase number of default characters from 4?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author cartpauj

    (@cartpauj)

    Not without hacking one of the files currently.

    http://plugins.svn.wordpress.org/pretty-link/tags/1.6.5/classes/models/PrliLink.php

    public function generateValidSlug($num_chars = 4)
        {
          global $wpdb;
    
          $slug = PrliUtils::gen_random_string($num_chars);
    
          $query = "SELECT slug FROM {$this->table_name}";
          $slugs = $wpdb->get_col($query,0);
    
          // It is highly unlikely that we'll ever see 2 identical random slugs
          // but just in case, here's some code to prevent collisions
          while( in_array($slug,$slugs) or !PrliUtils::slugIsAvailable($slug) )
            $slug = PrliUtils::gen_random_string($num_chars);
    
          return $slug;
        }

    Change that to:

    public function generateValidSlug($num_chars = 4)
        {
          global $wpdb;
    
          $num_chars = 4; //THIS LINE IS WHAT YOU'LL EDIT
    
          $slug = PrliUtils::gen_random_string($num_chars);
    
          $query = "SELECT slug FROM {$this->table_name}";
          $slugs = $wpdb->get_col($query,0);
    
          // It is highly unlikely that we'll ever see 2 identical random slugs
          // but just in case, here's some code to prevent collisions
          while( in_array($slug,$slugs) or !PrliUtils::slugIsAvailable($slug) )
            $slug = PrliUtils::gen_random_string($num_chars);
    
          return $slug;
        }

    Can I use an action/filter to acheive this, rather than changing the core plugin files?

    Any chance of an option to increase the characters in a later version?

    Plugin Author cartpauj

    (@cartpauj)

    I will see if Blair would be interested in adding an option for this. But our next version will actually look like this (with a filter hook on the returned slug “prli-auto-generated-slug”):

    public function generateValidSlug($num_chars = 4)
        {
          global $wpdb;
    
          $slug = PrliUtils::gen_random_string($num_chars);
    
          $query = "SELECT slug FROM {$this->table_name}";
          $slugs = $wpdb->get_col($query,0);
    
          // It is highly unlikely that we'll ever see 2 identical random slugs
          // but just in case, here's some code to prevent collisions
          while(in_array($slug, $slugs) or !PrliUtils::slugIsAvailable($slug))
            $slug = PrliUtils::gen_random_string($num_chars);
    
          return apply_filters('prli-auto-generated-slug', $slug, $slugs, $num_chars);
        }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Increase number of default characters from 4?’ is closed to new replies.