Skip to content

WP 3.5 conflicts: $wpdb #26

Closed
not-only-code opened this Issue Jan 17, 2013 · 1 comment

2 participants

@not-only-code
Owner

Looks like there are some kind of conflict with wpdb::prepare() arguments in Wordpress 3.5

Warning: Missing argument 2 for wpdb::prepare(), called in ..../wp-content/plugins/qtranslate-slug/qtranslate-slug.php on line 1857 and defined in ..../wp-includes/wp-db.php on line 990

@kuchenundkakao
Collaborator

Well, the function "unique_term_slug" doesn't use the $wpdb->prepare method not as intended.

Change the Function into this:

public function unique_term_slug($slug, $term, $lang) {
        global $wpdb;
        $meta_key_name = $this->get_meta_key($lang);
        $query = $wpdb->prepare("SELECT term_id FROM $wpdb->termmeta WHERE meta_key = '%s' AND meta_value = '%s' AND term_id != %d ",
                       $meta_key_name,
                       $slug,
                       $term->term_id);
        $exists_slug = $wpdb->get_results($query);

        if ( empty($exists_slug) )
            return $slug;

        // If we didn't get a unique slug, try appending a number to make it unique.
        $query = $wpdb->prepare(
                    "SELECT meta_value FROM $wpdb->termmeta WHERE meta_key = '%s' AND meta_value = '%s' AND term_id != %d",
                    $meta_key_name,
                    $slug,
                    $term->term_id);

        if ( $wpdb->get_var( $query ) ) {
            $num = 2;
            do {
                $alt_slug = $slug . "-$num";
                $num++;
                $slug_check = $wpdb->get_var(
                                 $wpdb->prepare(
                                "SELECT meta_value FROM $wpdb->termmeta WHERE meta_key = '%s' AND meta_value = '%s'",
                                $meta_key_name,
                                $alt_slug) );
            } while ( $slug_check );
            $slug = $alt_slug;
        }

        return $slug;
    }
@not-only-code not-only-code pushed a commit that closed this issue Mar 22, 2013
Carlos Sanz Garcia fixes not-only-code/qtranslate-slug#26 5a2a667
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.