/**
 * Install the plugin
 * 
 * This function runs when the plugin is activated. Checks if database table exists and creates it.
 * 
 * @since 0.1
 */
function was_install()
{
    global $wpdb;
    add_option('was_show_per_page', '10');
    $was_db_version = '0.1';
    $table_name = $wpdb->prefix . 'was_data';
    if ($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") != $table_name) {
        $sql = "CREATE TABLE `" . $table_name . "` (\n\t\t\t`advertisment_id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t`advertisment_active` int(11) DEFAULT '1' NOT NULL,\n\t\t\t`advertisment_vendor` varchar(200) DEFAULT '' NOT NULL,\n\t\t\t`advertisment_name` varchar(200) DEFAULT '' NOT NULL,\n\t\t\t`advertisment_code` text NOT NULL,\n\t\t\t`advertisment_weight` int(11) DEFAULT '1' NOT NULL,\n\t\t\t`advertisment_size` varchar(20) DEFAULT '125x125' NOT NULL,\n\t\t\tPRIMARY KEY  (`advertisment_id`)\n\t\t\t);";
        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
        dbDelta($sql);
        add_option('was_db_version', $was_db_version);
    }
    $ad = new Advertisment();
    $ad->setName('Wordpress Trac');
    $ad->setHtml('http://core.trac.wordpress.org/timeline');
    $ad->updateDatabase();
}
Пример #2
0
 /**
  * Delete an entry from the database
  *
  * @param int $id
  */
 function deleteEntry($id)
 {
     $ad = new Advertisment($id);
     $ad->delete();
 }
        $this->_type = $type;
        $this->_price = $price;
        $this->_image = $image;
    }
    public function getType()
    {
        return $this->_type;
    }
    public function getPrice()
    {
        return $this->_price;
    }
    public function getImage()
    {
        return $this->_image;
    }
}
class AdImage
{
    public function __construct($location)
    {
        $this->_location = $location;
    }
    public function getLocation()
    {
        return $this->_location;
    }
}
$ad = new Advertisment("Username", new AdContent("cars", "1500", new AdImage("somewhere")));
echo "Advertisment posted by " . $ad->getUsername() . " in " . $ad->getType() . "<br />";
echo "Image Location: " . $ad->getImage();