Give 2.2.0 – Resolving the known conflict with Restrict Content Pro

We want Give to run reliably alongside all plugins within WordPress. Sometimes, though, this can be difficult with 40,000+ free plugins and many more Pro ones. One such conflict we found was with Restrict Content Pro from Sandhills Development. This is a popular membership plugin that is useful alongside Give, so we wanted to get a fix out for it and also reduce the chances of other plugin conflicts.

The Conflict Explained

The GitHub issue explains the problem pretty well however we’ll explain it here briefly: Both Give and RCP have a custom table called “paymentmeta”. This resulted in missing data when donations were submitted to the tables. It also caused issues with our API and add-ons like Zapier.

We found the conflict between RCP and Give happened because we have a common $wpdb property paymentmeta. This resulted in data being lost when donations occurred.

Restrict Content Pro Plugin Screenshot

The Restrict Content Pro $wpdb->paymentmeta call conflicting with Give 2.0.* and 2.1.*.

The Solution

In order to fix the issue we are now making our custom table name more unique. This will resolve the conflict with RCP and reduce the chances of other plugin conflicts using the same meta table name.

To go more in depth, here’s exactly the steps we are taking:

  1. Renaming the meta type payment to donation (Give/includes/class-give-db-payment-meta.php)
  2. Renaming the table {*}_give_paymentmeta to {*}_give_donationmeta (Give/includes/class-give-db-payment-meta.php)
  3. Renaming the column within the payment meta table payment_id to donation_id
  4. Renaming the $wpdb property paymentmeta to donationmeta

Backwards Compatibility

Ensuring smooth upgrades is important to us. Thus we have added backward compatibility and a database upgrade in 2.2.0 to make the transition easy for you.

Developers Note

Do not use hardcoded table names in your queries (use $wpdb->paymentmeta instead). For example:

Incorrect:

$wpdb->get_query( "SELECT * FROM {$wpdb->prefix}give_paymentmeta WHERE meta_key='_give_payment_total' AND meta_value > 100 " )

Correct:

$wpdb->get_query( "SELECT * FROM $wpdb->paymentmeta WHERE meta_key='_give_payment_total' AND meta_value > 100" )

As well, do not use hardcoded payment_id for the column name (the payment meta table’s second column name). According to WordPress’ database schema, the meta table’s second column name must have meta type as the prefix.

For example:

  1. post_id (postmeta table and meta type is post)
  2. comment_id (commentmeta table and meta type is comment)
  3. user_id (usermeta table and meta type is user)
  4. term_id (termmeta table and meta type is post)

In Give 2.0.2, we have renamed the meta type to “donation”, so now the meta table’s second column name will be donation_id (not payment_id).

If you construct the column name dynamically then your code will run without any issue on Give 2.2.0+.

Query Example:

Incorrect:

$wpdb->get_query( "SELECT * FROM {$wpdb->prefix}give_paymentmeta WHERE meta_key='payment_id'" )

Correct:

// Set column name variable.
$donation_id_col_name = Give()->payment_meta->get_meta_type() . '_id';
// Use variable in query.
$wpdb->get_query( "SELECT * FROM $wpdb->paymentmeta WHERE meta_key='{$donation_id_col_name}'" )

Note: After, 2.2.0 we recommend you to use $wpdb->donationmeta for the table name and donation_id for the column.

 

Ravinder Kumar

Open source lover, the father of a daughter, continually improving developer, and Senior WordPress Engineer at GiveWP.

 

Leave a Comment