Skip to content

Instantly share code, notes, and snippets.

@DrewAPicture
Last active December 24, 2018 05:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DrewAPicture/a84a0ef3843ee563f7eef4352c8e0caa to your computer and use it in GitHub Desktop.
Save DrewAPicture/a84a0ef3843ee563f7eef4352c8e0caa to your computer and use it in GitHub Desktop.
Demonstration for how AffiliateWP registers a table to be compatible with the core metadata API.
<?php
/**
* Core class used to implement affiliate meta.
*
* @since 1.6
*
* @see Affiliate_WP_DB
*/
class Affiliate_WP_Affiliate_Meta_DB extends Affiliate_WP_DB {
/**
* Sets up the Affiliate Meta DB class.
*
* @access public
* @since 1.6
*/
public function __construct() {
global $wpdb;
$this->table_name = $wpdb->prefix . 'affiliate_wp_affiliatemeta';
add_action( 'plugins_loaded', array( $this, 'register_table' ), 11 );
}
// other code
/**
* Registers the table with $wpdb so the metadata api can find it.
*
* @access public
* @since 1.6
*
* @global wpdb $wpdb WordPress database abstraction object.
*/
public function register_table() {
global $wpdb;
$wpdb->affiliatemeta = $this->table_name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment