GithubHelp home page GithubHelp logo

Comments (6)

toolstack avatar toolstack commented on June 18, 2024

I'd vote for skipping it if the number of args is only 1.

from glotpress.

toolstack avatar toolstack commented on June 18, 2024

Actually digging in to the code some more this should already be handled correctly, from thing.php:

    function prepare( $args ) {
        global $wpdb;
        if ( 1 == count( $args ) ) {
            return $args[0];
        } else {
            $query = array_shift( $args );
            return $wpdb->prepare( $query, $args );
        }
    }

Where are you trying to delete the glossary/project from? I don't see any UI for it...

from glotpress.

toolstack avatar toolstack commented on June 18, 2024

Ok, I found the issue:

    function delete_all( $where = null  ) {
        $query = "DELETE FROM $this->table";
        $conditions_sql = $this->sql_from_conditions( $where );
        if ( $conditions_sql ) $query .= " WHERE $conditions_sql";
        return $this->query( $query, $this->id );
    }

Notice the call to $this->query always adds in $this->id, which forces the args count to be 2 even if the query returned does not require it.

Backpress (I assume) like older versions of WordPress (pre 3.5?) didn't throw an error if you passed in a string without any placeholders to prepare() so it wasn't a problem in standalone.

The "off the top of my head" solution is to replace the above with:

    function delete_all( $where = null  ) {
        $query = "DELETE FROM $this->table";
        $conditions_sql = $this->sql_from_conditions( $where );
        if ( $conditions_sql ) $query .= " WHERE $conditions_sql";

        // If there are placeholders in the query, pass in the id otherwise don't because $wpdb->prepare will throw an error.
        if ( preg_match( '/\%[sdf]/i', $query ) ) {
            return $this->query( $query, $this->id );
        } else {
            return $this->query( $query );
        }
    }

but that's kind of ugly 😦

Though since it won't be called all that often it may be reasonable.

from glotpress.

toolstack avatar toolstack commented on June 18, 2024

I've poked at this some more and I think there's an easier solution than the above, which is just to remove $this->id from the query call. None of the delete methods use it as far as I can tell.

I'll create a PR for it.

from glotpress.

ocean90 avatar ocean90 commented on June 18, 2024

@toolstack Looks like you're right, seems to be a copy&paste issue in https://glotpress.trac.wordpress.org/changeset/500.

from glotpress.

toolstack avatar toolstack commented on June 18, 2024

Woohoo! I like it when I'm right 😄

from glotpress.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.