@@ -42,28 +42,10 @@ public function checkOrCreateFilamentUser(): void
4242 return ;
4343 }
4444
45- alert ("🚨 No users found in ' { $ table } ' . Let's create the first Filament user. " );
45+ alert ("🚨 No users found. Let's create the first user " );
4646 $ this ->createFilamentUser ($ userModel );
4747 }
4848
49- public function hasFilamentUsers (): bool
50- {
51- /** @var class-string<Model> $userModel */
52- $ userModel = Config::get ('filament.auth.providers.users.model ' ) ?? \App \Models \User::class;
53-
54- if (! class_exists ($ userModel )) {
55- return false ;
56- }
57-
58- $ table = (new $ userModel )->getTable ();
59-
60- if (! Schema::hasTable ($ table )) {
61- return false ;
62- }
63-
64- return $ userModel ::count () > 0 ;
65- }
66-
6749 protected function createFilamentUser (string $ userModel ): void
6850 {
6951 info ("🧑 Creating new admin user for model ' {$ userModel }'... " );
@@ -80,4 +62,54 @@ protected function createFilamentUser(string $userModel): void
8062
8163 info ("✅ User ' {$ user ->email }' created successfully. " );
8264 }
65+
66+ public function checkOrCreateWpUser (): void
67+ {
68+ $ wpUserModel = \Moox \Press \Models \WpUser::class;
69+
70+ if (! class_exists ($ wpUserModel )) {
71+ warning ("⚠️ WP User model ' {$ wpUserModel }' does not exist. " );
72+
73+ return ;
74+ }
75+
76+ $ table = (new $ wpUserModel )->getTable ();
77+
78+ info ("🔍 Checking WP user setup for Press Panel [Model: {$ wpUserModel }]... " );
79+
80+ if (! Schema::hasTable ($ table )) {
81+ warning ("⚠️ Table ' {$ table }' not found. Did you run migrations? " );
82+
83+ return ;
84+ }
85+
86+ if ($ wpUserModel ::count () > 0 ) {
87+ info ("✅ Found existing WP users in ' {$ table }'. Skipping user creation. " );
88+
89+ return ;
90+ }
91+
92+ alert ("🚨 No WP users found. Let's create the first WP user " );
93+ $ this ->createWpUser ($ wpUserModel );
94+ }
95+
96+ protected function createWpUser (string $ wpUserModel ): void
97+ {
98+ info ("🧑 Creating new WP user for model ' {$ wpUserModel }'... " );
99+
100+ $ login = text ('Enter login ' , default: 'wpadmin ' );
101+ $ email =
text (
'Enter email ' , default:
'[email protected] ' );
102+ $ password = password ('Enter password ' , required: true );
103+ $ displayName = text ('Enter display name ' , default: $ login );
104+
105+ $ user = $ wpUserModel ::create ([
106+ 'user_login ' => $ login ,
107+ 'user_email ' => $ email ,
108+ 'user_pass ' => $ password ,
109+ 'display_name ' => $ displayName ,
110+ 'user_registered ' => now (),
111+ ]);
112+
113+ info ("✅ WP user ' {$ user ->user_login }' created successfully. " );
114+ }
83115}
0 commit comments