Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.