get_charset_collate(); foreach ( Requests::schema( $collate ) as $sql ) { dbDelta( $sql ); } dbDelta( Log::schema( $collate ) ); /** * Create extra tables (Pro: the store-credit ledger). * * @param string $collate Charset/collation clause. */ do_action( 'rtkt_create_tables', $collate ); update_option( self::DB_OPTION, self::DB_VERSION ); } /** * Create the portal and withdrawal pages when they don't exist yet. * * @param bool $force Create even when a page is set but missing/trashed. * @return int[] Created page IDs. */ public static function create_pages( $force = true ) { $stored = get_option( Settings::OPTION, array() ); $stored = is_array( $stored ) ? $stored : array(); $created = array(); $pages = array( 'portal_page' => array( 'title' => _x( 'Returns', 'page title', 'returnkit' ), 'slug' => _x( 'returns', 'page slug', 'returnkit' ), 'content' => '[returnkit_portal]', ), 'withdrawal_page' => array( 'title' => _x( 'Withdraw from contract', 'page title', 'returnkit' ), 'slug' => _x( 'withdraw-from-contract', 'page slug', 'returnkit' ), 'content' => '[returnkit_withdrawal]', ), ); foreach ( $pages as $key => $page ) { $id = isset( $stored[ $key ] ) ? absint( $stored[ $key ] ) : 0; if ( $id && 'publish' === get_post_status( $id ) ) { continue; } if ( $id && ! $force ) { continue; } $id = wp_insert_post( array( 'post_type' => 'page', 'post_status' => 'publish', 'post_title' => $page['title'], 'post_name' => $page['slug'], 'post_content' => $page['content'], 'comment_status' => 'closed', ) ); if ( $id && ! is_wp_error( $id ) ) { $stored[ $key ] = (int) $id; $created[] = (int) $id; } } if ( $created ) { update_option( Settings::OPTION, Settings::sanitize( wp_parse_args( $stored, Settings::defaults() ) ) ); Settings::flush(); } return $created; } }