get_option( 'admin_email' ), 'from_name' => get_bloginfo( 'name' ), 'ai_provider' => 'offline', 'ai_model' => '', 'load_css' => 'yes', ) ); } Fillnova_Forms::register_post_type(); add_rewrite_rule( '^fillnova-form/([0-9]+)/?$', 'index.php?fillnova_form=$matches[1]', 'top' ); flush_rewrite_rules(); update_option( 'fillnova_db_version', FILLNOVA_DB_VERSION ); set_transient( 'fillnova_activation_redirect', 1, 60 ); } /** * Deactivation. */ public static function deactivate() { flush_rewrite_rules(); } /** * Run upgrades if needed. */ public static function maybe_upgrade() { if ( get_option( 'fillnova_db_version' ) !== FILLNOVA_DB_VERSION ) { self::create_tables(); update_option( 'fillnova_db_version', FILLNOVA_DB_VERSION ); } } /** * Create tables. */ public static function create_tables() { global $wpdb; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; $charset = $wpdb->get_charset_collate(); $entries = "CREATE TABLE {$wpdb->prefix}fillnova_entries ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, form_id bigint(20) unsigned NOT NULL DEFAULT 0, data longtext NOT NULL, meta longtext NULL, status varchar(20) NOT NULL DEFAULT 'unread', starred tinyint(1) NOT NULL DEFAULT 0, user_id bigint(20) unsigned NOT NULL DEFAULT 0, ip varchar(64) NOT NULL DEFAULT '', user_agent varchar(255) NOT NULL DEFAULT '', source_url varchar(255) NOT NULL DEFAULT '', token varchar(64) NOT NULL DEFAULT '', created_at datetime NOT NULL, updated_at datetime NOT NULL, PRIMARY KEY (id), KEY form_id (form_id), KEY status (status), KEY token (token) ) $charset;"; $stats = "CREATE TABLE {$wpdb->prefix}fillnova_stats ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, form_id bigint(20) unsigned NOT NULL DEFAULT 0, day date NOT NULL, views int(11) unsigned NOT NULL DEFAULT 0, starts int(11) unsigned NOT NULL DEFAULT 0, submits int(11) unsigned NOT NULL DEFAULT 0, PRIMARY KEY (id), UNIQUE KEY form_day (form_id,day) ) $charset;"; dbDelta( $entries ); dbDelta( $stats ); } /** * Protected upload directory. */ public static function create_upload_dir() { $upload = wp_upload_dir(); $dir = trailingslashit( $upload['basedir'] ) . 'fillnova'; if ( ! file_exists( $dir ) ) { wp_mkdir_p( $dir ); } if ( ! file_exists( $dir . '/index.php' ) ) { // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents @file_put_contents( $dir . '/index.php', "\nRequire all denied\n\n" ); } } }