クラス
Activation
Activation/setup methods
ソース ソース
ファイル: src/Activation.php
class Activation { /** * Runs on plugin activation. Creates wishlist page and table * * @author Evan D Shaw <evandanielshaw@gmail.com> * @return void */ public function activate() { $this->makeWishlistPage(); $this->createWishlistTable(); } /** * Creates wishlist page * * @author Evan D Shaw <evandanielshaw@gmail.com> * @global \wpdb $wpdb * @return void */ private function makeWishlistPage() { global $wpdb; $datetime = get_date_from_gmt(gmdate('Y-m-d H:i:s', time())); $datetime_gmt = gmdate('Y-m-d H:i:s', time()); $query = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_name = %s", WCEXWL_PAGE_SLUG); $pageid = $wpdb->get_var($query); if ($pageid === null) { $query = $wpdb->prepare( "INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_content_filtered, post_parent, guid, menu_order, post_type, post_mime_type, comment_count) VALUES (%d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %s, %d, %s, %s, %d)", 1, $datetime, $datetime_gmt, '', __('Wishlist', 'wcexwl'), '', 'publish', 'closed', 'closed', '', WCEXWL_PAGE_SLUG, '', '', $datetime, $datetime_gmt, '', 0, '', 0, 'page', '', 0 ); $wpdb->query($query); $pageid = $wpdb->insert_id; if ($pageid !== null) { update_post_meta($pageid, '_wp_page_template', 'wishlist.php'); } } update_option('wcex_wishlist_post_id', $pageid); } /** * Creates wishlist table * * @author Evan D Shaw <evandanielshaw@gmail.com> * @global \wpdb $wpdb * @return void */ private function createWishlistTable() { global $wpdb; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); $charset_collate = $wpdb->get_charset_collate(); $table = Master::getWishlistTableName(); if ($wpdb->get_var("SHOW TABLES LIKE '$table'") !== $table) { $sql = "CREATE TABLE $table ( id BIGINT(20) AUTO_INCREMENT PRIMARY KEY, mem_id BIGINT(20) NOT NULL, quantity INTEGER NOT NULL, price DECIMAL(15, 2) DEFAULT NULL, advance VARCHAR(100) DEFAULT NULL, item_serial TEXT ) ENGINE=InnoDB {$charset_collate};"; dbDelta($sql); } } }
- activate — Runs on plugin activation. Creates wishlist page and table
- createWishlistTable — Creates wishlist table
- makeWishlistPage — Creates wishlist page