Skip to content

Commit 2144986

Browse files
Cherry-pick PR #524 with conflicts - manual resolution needed (#525)
1 parent 7f7a348 commit 2144986

File tree

4 files changed

+225
-16
lines changed

4 files changed

+225
-16
lines changed

modules/admin-home/rest/admin-config.php

Lines changed: 76 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
exit; // Exit if accessed directly.
77
}
88

9+
use Elementor\Core\DocumentTypes\Page;
910
use HelloTheme\Includes\Utils;
1011
use WP_REST_Server;
1112

@@ -24,9 +25,11 @@ public function register_routes() {
2425
}
2526

2627
public function get_admin_config() {
28+
$elementor_page_id = Utils::is_elementor_active() ? $this->ensure_elementor_page_exists() : null;
29+
2730
$config = $this->get_welcome_box_config( [] );
2831

29-
$config = $this->get_site_parts( $config );
32+
$config = $this->get_site_parts( $config, $elementor_page_id );
3033

3134
$config = $this->get_resources( $config );
3235

@@ -40,6 +43,57 @@ public function get_admin_config() {
4043
return rest_ensure_response( [ 'config' => $config ] );
4144
}
4245

46+
private function ensure_elementor_page_exists(): int {
47+
$existing_page = \Elementor\Core\DocumentTypes\Page::get_elementor_page();
48+
49+
if ( $existing_page ) {
50+
return $existing_page->ID;
51+
}
52+
53+
$page_data = [
54+
'post_title' => 'Hello Theme page',
55+
'post_content' => '',
56+
'post_status' => 'draft',
57+
'post_type' => 'page',
58+
'meta_input' => [
59+
'_elementor_edit_mode' => 'builder',
60+
'_elementor_template_type' => 'wp-page',
61+
],
62+
];
63+
64+
$page_id = wp_insert_post( $page_data );
65+
66+
if ( is_wp_error( $page_id ) ) {
67+
throw new \RuntimeException( 'Failed to create Elementor page: ' . esc_html( $page_id->get_error_message() ) );
68+
}
69+
70+
if ( ! $page_id ) {
71+
throw new \RuntimeException( 'Page creation returned invalid ID' );
72+
}
73+
74+
wp_update_post([
75+
'ID' => $page_id,
76+
'post_title' => 'Hello Theme #' . $page_id,
77+
]);
78+
return $page_id;
79+
}
80+
81+
private function get_elementor_editor_url( ?int $page_id, string $active_tab ): string {
82+
$active_kit_id = Utils::elementor()->kits_manager->get_active_id();
83+
84+
$url = add_query_arg(
85+
[
86+
'post' => $page_id,
87+
'action' => 'elementor',
88+
'active-tab' => $active_tab,
89+
'active-document' => $active_kit_id,
90+
],
91+
admin_url( 'post.php' )
92+
);
93+
94+
return $url . '#e:run:panel/global/open';
95+
}
96+
4397
public function get_resources( array $config ) {
4498
$config['resourcesData'] = [
4599
'community' => [
@@ -92,7 +146,7 @@ public function get_resources( array $config ) {
92146
return $config;
93147
}
94148

95-
public function get_site_parts( array $config ): array {
149+
public function get_site_parts( array $config, ?int $elementor_page_id = null ): array {
96150
$last_five_pages_query = new \WP_Query(
97151
[
98152
'posts_per_page' => 5,
@@ -136,7 +190,7 @@ public function get_site_parts( array $config ): array {
136190

137191
$common_parts = [];
138192

139-
$customizer_header_footer_url = $this->get_open_homepage_with_tab( '', [ 'autofocus[section]' => 'hello-options' ] );
193+
$customizer_header_footer_url = $this->get_open_homepage_with_tab( $elementor_page_id, '', null, [ 'autofocus[section]' => 'hello-options' ] );
140194

141195
$header_part = [
142196
'id' => 'header',
@@ -161,8 +215,8 @@ public function get_site_parts( array $config ): array {
161215
'icon' => 'ThemeBuilderIcon',
162216
],
163217
];
164-
$header_part['link'] = $this->get_open_homepage_with_tab( 'hello-settings-header' );
165-
$footer_part['link'] = $this->get_open_homepage_with_tab( 'hello-settings-footer' );
218+
$header_part['link'] = $this->get_open_homepage_with_tab( $elementor_page_id, 'hello-settings-header' );
219+
$footer_part['link'] = $this->get_open_homepage_with_tab( $elementor_page_id, 'hello-settings-footer' );
166220

167221
if ( Utils::has_pro() ) {
168222
$header_part = $this->update_pro_part( $header_part, 'header' );
@@ -184,7 +238,7 @@ public function get_site_parts( array $config ): array {
184238

185239
$config['siteParts'] = apply_filters( 'hello-plus-theme/template-parts', $site_parts );
186240

187-
return $this->get_quicklinks( $config );
241+
return $this->get_quicklinks( $config, $elementor_page_id );
188242
}
189243

190244
private function update_pro_part( array $part, string $location ): array {
@@ -197,7 +251,7 @@ private function update_pro_part( array $part, string $location ): array {
197251
$edit_link = get_edit_post_link( $first_document_id, 'admin' ) . '&action=elementor';
198252

199253
} else {
200-
$edit_link = $this->get_open_homepage_with_tab( 'hello-settings-' . $location );
254+
$edit_link = $this->get_open_homepage_with_tab( null, 'hello-settings-' . $location );
201255
}
202256
$part['sublinks'] = [
203257
[
@@ -213,44 +267,50 @@ private function update_pro_part( array $part, string $location ): array {
213267
return $part;
214268
}
215269

216-
public function get_open_homepage_with_tab( $action, $customizer_fallback_args = [] ): string {
217-
if ( Utils::is_elementor_active() && method_exists( \Elementor\Core\DocumentTypes\Page::class, 'get_site_settings_url_config' ) ) {
218-
return \Elementor\Core\DocumentTypes\Page::get_site_settings_url_config( $action )['url'];
270+
public function get_open_homepage_with_tab( ?int $page_id, $action, $section = null, $customizer_fallback_args = [] ): string {
271+
if ( Utils::is_elementor_active() ) {
272+
$url = $page_id ? $this->get_elementor_editor_url( $page_id, $action ) : Page::get_site_settings_url_config( $action )['url'];
273+
274+
if ( $section ) {
275+
$url = add_query_arg( 'active-section', $section, $url );
276+
}
277+
278+
return $url;
219279
}
220280

221281
return add_query_arg( $customizer_fallback_args, self_admin_url( 'customize.php' ) );
222282
}
223283

224-
public function get_quicklinks( $config ): array {
284+
public function get_quicklinks( $config, ?int $elementor_page_id = null ): array {
225285
$config['quickLinks'] = [
226286
'site_name' => [
227287
'title' => __( 'Site Name', 'hello-elementor' ),
228-
'link' => $this->get_open_homepage_with_tab( 'settings-site-identity', [ 'autofocus[section]' => 'title_tagline' ] ),
288+
'link' => $this->get_open_homepage_with_tab( $elementor_page_id, 'settings-site-identity', null, [ 'autofocus[section]' => 'title_tagline' ] ),
229289
'icon' => 'TextIcon',
230290

231291
],
232292
'site_logo' => [
233293
'title' => __( 'Site Logo', 'hello-elementor' ),
234-
'link' => $this->get_open_homepage_with_tab( 'settings-site-identity', [ 'autofocus[section]' => 'title_tagline' ] ),
294+
'link' => $this->get_open_homepage_with_tab( $elementor_page_id, 'settings-site-identity', null, [ 'autofocus[section]' => 'title_tagline' ] ),
235295
'icon' => 'PhotoIcon',
236296
],
237297
'site_favicon' => [
238298
'title' => __( 'Site Favicon', 'hello-elementor' ),
239-
'link' => $this->get_open_homepage_with_tab( 'settings-site-identity', [ 'autofocus[section]' => 'title_tagline' ] ),
299+
'link' => $this->get_open_homepage_with_tab( $elementor_page_id, 'settings-site-identity', null, [ 'autofocus[section]' => 'title_tagline' ] ),
240300
'icon' => 'AppsIcon',
241301
],
242302
];
243303

244304
if ( Utils::is_elementor_active() ) {
245305
$config['quickLinks']['site_colors'] = [
246306
'title' => __( 'Site Colors', 'hello-elementor' ),
247-
'link' => $this->get_open_homepage_with_tab( 'global-colors' ),
307+
'link' => $this->get_open_homepage_with_tab( $elementor_page_id, 'global-colors' ),
248308
'icon' => 'BrushIcon',
249309
];
250310

251311
$config['quickLinks']['site_fonts'] = [
252312
'title' => __( 'Site Fonts', 'hello-elementor' ),
253-
'link' => $this->get_open_homepage_with_tab( 'global-typography' ),
313+
'link' => $this->get_open_homepage_with_tab( $elementor_page_id, 'global-typography' ),
254314
'icon' => 'UnderlineIcon',
255315
];
256316
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { parallelTest as test } from '../../parallelTest.ts';
2+
import { expect } from '@playwright/test';
3+
4+
test.describe( 'Hello Theme Admin Home Page', () => {
5+
test.beforeEach( async ( { page } ) => {
6+
await page.goto( '/wp-admin/admin.php?page=hello-elementor' );
7+
} );
8+
9+
test( 'should display Welcome to Hello Theme message and take screenshot', async ( { page } ) => {
10+
const welcomeSection = page.locator( 'text=Go Pro, Go Limitless' ).locator( '..' ).locator( '..' );
11+
await expect.soft( welcomeSection ).toHaveScreenshot( 'welcome-section.png' );
12+
} );
13+
14+
test( 'should display Quick Links section', async ( { page } ) => {
15+
const quickLinksHeading = page.locator( 'h6:has-text("Quick Links")' );
16+
await expect( quickLinksHeading ).toBeVisible();
17+
await expect( quickLinksHeading ).toContainText( 'Quick Links' );
18+
const quickLinksSection = page.locator( 'text=Quick Links' ).locator( '..' ).locator( '..' );
19+
await expect( quickLinksSection ).toContainText( 'These quick actions will get your site airborne in a flash.' );
20+
const expectedQuickLinks = [
21+
'Site Name',
22+
'Site Logo',
23+
'Site Favicon',
24+
'Site Colors',
25+
'Site Fonts',
26+
];
27+
for ( const linkText of expectedQuickLinks ) {
28+
const linkElement = page.locator( `h6:has-text("${ linkText }")` );
29+
await expect( linkElement ).toBeVisible();
30+
}
31+
} );
32+
33+
test( 'should navigate to correct pages from Quick Links', async ( { page } ) => {
34+
const quickLinksTests = [
35+
{
36+
linkText: 'Site Name',
37+
expectedUrlPattern: /post\.php\?post=\d+&action=elementor.*active-tab=settings-site-identity/,
38+
expectedPageSection: '.elementor-control-section_settings-site-identity',
39+
},
40+
{
41+
linkText: 'Site Logo',
42+
expectedUrlPattern: /post\.php\?post=\d+&action=elementor.*active-tab=settings-site-identity/,
43+
expectedPageSection: '.elementor-control-section_settings-site-identity',
44+
},
45+
{
46+
linkText: 'Site Favicon',
47+
expectedUrlPattern: /post\.php\?post=\d+&action=elementor.*active-tab=settings-site-identity/,
48+
expectedPageSection: '.elementor-control-section_settings-site-identity',
49+
},
50+
{
51+
linkText: 'Site Colors',
52+
expectedUrlPattern: /post\.php\?post=\d+&action=elementor.*active-tab=global-colors/,
53+
expectedPageSection: '.elementor-control-section_global_colors',
54+
},
55+
{
56+
linkText: 'Site Fonts',
57+
expectedUrlPattern: /post\.php\?post=\d+&action=elementor.*active-tab=global-typography/,
58+
expectedPageSection: '.elementor-control-section_text_style',
59+
},
60+
];
61+
for ( const linkTest of quickLinksTests ) {
62+
await page.goto( '/wp-admin/admin.php?page=hello-elementor' );
63+
const linkElement = page.locator( `h6:has-text("${ linkTest.linkText }") a` );
64+
await expect( linkElement ).toBeVisible();
65+
66+
await Promise.all( [
67+
page.waitForURL( linkTest.expectedUrlPattern ),
68+
linkElement.click(),
69+
] );
70+
71+
expect( page.url() ).toMatch( linkTest.expectedUrlPattern );
72+
await page.waitForSelector( '#elementor-kit-panel' );
73+
const location = page.locator( linkTest.expectedPageSection );
74+
await expect( location ).toBeVisible();
75+
}
76+
} );
77+
} );
14.8 KB
Loading

tests/wp-env/config/setup.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/bash
2+
set -eox pipefail
3+
4+
echo "=== SETUP.SH DEBUG ==="
5+
echo "Current working directory:"
6+
pwd
7+
echo ""
8+
9+
echo "WordPress themes directory contents:"
10+
ls -la /var/www/html/wp-content/themes/ || echo "Could not list themes directory"
11+
echo ""
12+
13+
echo "Checking for hello-elementor theme specifically:"
14+
if [ -d "/var/www/html/wp-content/themes/hello-elementor" ]; then
15+
echo "✅ hello-elementor directory found"
16+
echo "Contents:"
17+
ls -la /var/www/html/wp-content/themes/hello-elementor/ | head -10
18+
echo ""
19+
20+
echo "Checking for style.css:"
21+
if [ -f "/var/www/html/wp-content/themes/hello-elementor/style.css" ]; then
22+
echo "✅ style.css found"
23+
echo "Theme header:"
24+
head -10 /var/www/html/wp-content/themes/hello-elementor/style.css
25+
else
26+
echo "❌ style.css missing"
27+
fi
28+
else
29+
echo "❌ hello-elementor directory not found"
30+
echo "Available theme directories:"
31+
ls -la /var/www/html/wp-content/themes/
32+
fi
33+
echo ""
34+
35+
wp plugin activate elementor
36+
echo "Available themes (via WP-CLI):"
37+
wp theme list
38+
echo ""
39+
40+
echo "Attempting to activate hello-theme theme..."
41+
wp theme activate hello-theme || {
42+
echo "❌ Failed to activate hello-theme, trying hello-elementor..."
43+
wp theme activate hello-elementor || {
44+
echo "❌ Both activation attempts failed. Final theme list:"
45+
wp theme list
46+
echo "❌ Available theme directories in WordPress:"
47+
ls -la /var/www/html/wp-content/themes/
48+
echo "❌ Theme activation completely failed"
49+
exit 1
50+
}
51+
}
52+
53+
WP_CLI_CONFIG_PATH=hello-elementor-config/wp-cli.yml wp rewrite structure '/%postname%/' --hard
54+
55+
# Remove the Guttenberg welcome guide popup
56+
wp user meta add admin wp_persisted_preferences 'a:2:{s:14:\"core/edit-post\";a:2:{b:1;s:12:\"welcomeGuide\";b:0;}}'
57+
58+
# Reset editor counter to avoid auto trigger of the checklist popup when entering the editor for the 2nd time
59+
wp option update e_editor_counter 10
60+
wp option update elementor_checklist '{"last_opened_timestamp":null,"first_closed_checklist_in_editor":true,"is_popup_minimized":false,"steps":[],"should_open_in_editor":false,"editor_visit_count":10}'
61+
62+
wp option set elementor_onboarded true
63+
64+
# Add user meta so the announcement popup will not be displayed - ED-9723
65+
for id in $(wp user list --field=ID)
66+
do wp user meta add "$id" "announcements_user_counter" 999
67+
wp user meta add "$id" "elementor_onboarded" "a:1:{s:27:\"ai-get-started-announcement\";b:1;}"
68+
done
69+
70+
wp cache flush
71+
wp rewrite flush --hard
72+
wp elementor flush-css

0 commit comments

Comments
 (0)