array( __( 'Submit a Post', 'postfee' ), Blocks::default_form() ), 'dashboard_page' => array( __( 'My Posts', 'postfee' ), Blocks::default_dashboard() ), ); foreach ( $pages as $key => $page ) { if ( $settings[ $key ] && get_post( $settings[ $key ] ) ) { continue; } $page_id = wp_insert_post( array( 'post_type' => 'page', 'post_status' => 'publish', 'post_title' => $page[0], 'post_content' => $page[1], ) ); if ( $page_id && ! is_wp_error( $page_id ) ) { $settings[ $key ] = $page_id; } } update_option( 'postfee_settings', $settings ); self::schedule_cron(); } public static function deactivate() { wp_clear_scheduled_hook( 'postfee_cron' ); } public static function maybe_upgrade() { if ( get_option( 'postfee_db_version' ) !== POSTFEE_DB_VERSION ) { self::create_tables(); } self::schedule_cron(); } private static function schedule_cron() { if ( ! wp_next_scheduled( 'postfee_cron' ) ) { wp_schedule_event( time() + HOUR_IN_SECONDS, 'hourly', 'postfee_cron' ); } } private static function create_tables() { global $wpdb; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; $charset = $wpdb->get_charset_collate(); dbDelta( "CREATE TABLE {$wpdb->prefix}postfee_orders ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, user_id bigint(20) unsigned NOT NULL DEFAULT 0, plan_id bigint(20) unsigned NOT NULL DEFAULT 0, post_id bigint(20) unsigned NOT NULL DEFAULT 0, plan_type varchar(20) NOT NULL DEFAULT '', description varchar(255) NOT NULL DEFAULT '', amount bigint(20) NOT NULL DEFAULT 0, currency varchar(3) NOT NULL DEFAULT '', gateway varchar(30) NOT NULL DEFAULT '', gateway_ref varchar(191) NOT NULL DEFAULT '', status varchar(20) NOT NULL DEFAULT 'pending', created_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00', paid_at datetime DEFAULT NULL, PRIMARY KEY (id), KEY user_id (user_id), KEY gateway_ref (gateway_ref), KEY status (status) ) $charset;" ); dbDelta( "CREATE TABLE {$wpdb->prefix}postfee_entitlements ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, user_id bigint(20) unsigned NOT NULL DEFAULT 0, plan_id bigint(20) unsigned NOT NULL DEFAULT 0, order_id bigint(20) unsigned NOT NULL DEFAULT 0, credits_total bigint(20) DEFAULT NULL, credits_used bigint(20) NOT NULL DEFAULT 0, listing_days int(11) NOT NULL DEFAULT 0, featured_days int(11) NOT NULL DEFAULT 0, gateway varchar(30) NOT NULL DEFAULT '', gateway_sub_id varchar(191) NOT NULL DEFAULT '', status varchar(20) NOT NULL DEFAULT 'active', created_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00', expires_at datetime DEFAULT NULL, PRIMARY KEY (id), KEY user_id (user_id), KEY gateway_sub_id (gateway_sub_id), KEY status (status) ) $charset;" ); update_option( 'postfee_db_version', POSTFEE_DB_VERSION ); } }