Skip to content

Commit ce9f933

Browse files
committed
move stackable settings to top level menu
1 parent 73ce320 commit ce9f933

File tree

5 files changed

+152
-44
lines changed

5 files changed

+152
-44
lines changed

freemius.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function sugb_fs() {
2525
// Do not redirect to the getting started when in network activating
2626
// in multisite or in the mainsite because it will redirect to a 404
2727
// page.
28-
$first_path = 'options-general.php?page=stackable-getting-started';
28+
$first_path = 'admin.php?page=stackable';
2929
if ( is_multisite() && is_main_site() ) {
3030
$first_path = 'plugins.php';
3131
}
@@ -34,7 +34,7 @@ function sugb_fs() {
3434
// https://github.com/Freemius/wordpress-sdk/issues/674 If the menu
3535
// slug is options-general, for a network activated plugin, all
3636
// admin URLs will be broken. This is a temporary fix.
37-
$menu_slug = 'options-general.php';
37+
$menu_slug = 'stackable';
3838
if ( is_multisite() && is_main_site() && is_plugin_active_for_network( plugin_basename( STACKABLE_FILE ) ) ) {
3939
if ( ! empty( $_SERVER ) && isset( $_SERVER['REQUEST_URI'] ) && stripos( $_SERVER['REQUEST_URI'], '/admin.php' ) !== false ) {
4040
$menu_slug = 'admin.php';

src/welcome/admin.scss

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,16 +344,16 @@ body[class*="page_stk-"] {
344344
margin-bottom: 32px;
345345
padding-bottom: 0;
346346
}
347-
body.settings_page_stackable {
347+
body.stackable_page_stackable-settings {
348348
#wpwrap {
349349
background: #fff;
350350
}
351351
.s-box {
352352
box-shadow: none !important;
353353
}
354354
}
355-
body.settings_page_stackable,
356-
body.settings_page_stackable-getting-started {
355+
body.stackable_page_stackable-settings,
356+
body.toplevel_page_stackable {
357357
// Hide admin notices to not mess up the welcome screen.
358358
.s-header > *:not(h1):not(img) {
359359
display: none !important;
@@ -369,9 +369,10 @@ body.settings_page_stackable-getting-started {
369369
padding-bottom: 0;
370370
}
371371
}
372-
body.settings_page_stackable,
373-
body.settings_page_stackable-getting-started,
374-
body.toplevel_page_stk-custom-fields {
372+
body.stackable_page_stackable-settings,
373+
body.toplevel_page_stackable,
374+
body.stackable_page_stk-custom-fields,
375+
body.stackable_page_stackable-go-premium {
375376
img {
376377
max-width: 100%;
377378
}
@@ -912,6 +913,29 @@ body.toplevel_page_stk-custom-fields {
912913
}
913914
}
914915

916+
body.stackable_page_stackable-go-premium {
917+
.s-side {
918+
display: grid;
919+
padding: 50px;
920+
grid-template-columns: 1fr 1fr;
921+
grid-template-rows: 1fr 1fr;
922+
grid-column-gap: 50px;
923+
align-items: start;
924+
}
925+
926+
.s-premium-box {
927+
grid-row: 1/3;
928+
.s-check-list {
929+
margin: auto;
930+
width: fit-content;
931+
text-align: left;
932+
}
933+
}
934+
.s-box {
935+
text-align: center;
936+
}
937+
}
938+
915939
@import "news";
916940
@import "getting-started";
917941
@import "freemius";

src/welcome/freemius.scss

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,8 @@
128128
* Contact and pricing/checkout pages have an SSL banner on the top, add more space.
129129
*/
130130
body.stackable_page_stackable-contact {
131-
.s-header {
132-
padding-top: 65px !important;
133-
padding-bottom: 100px !important;
131+
.s-header-wrap {
132+
padding-top: 10px !important;
134133
}
135134
}
136135
body.stackable_page_stackable-pricing {

src/welcome/getting-started.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111
}
1212

13-
.settings_page_stackable-getting-started {
13+
.toplevel_page_stackable {
1414
.s-body {
1515
max-width: 1200px;
1616
margin: 0 auto;

src/welcome/index.php

Lines changed: 117 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,70 @@ function __construct() {
1616
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_dashboard_script' ) );
1717

1818
add_action( 'admin_init', array( $this, 'redirect_to_welcome_page' ) );
19+
add_action('admin_init', array( $this, 'redirect_to_docs' ) );
20+
21+
add_action('admin_head', array( $this, 'redirect_to_docs_newtab' ) );
1922

2023
$plugin = plugin_basename( STACKABLE_FILE );
2124
add_filter( 'plugin_action_links_' . $plugin, array( $this, 'add_settings_link' ) );
2225
}
2326

2427
public function add_dashboard_page() {
2528

26-
// Our settings page.
27-
add_submenu_page(
28-
'options-general.php', // Parent slug.
29+
$icon = 'data:image/svg+xml;base64,PHN2ZyBlbmFibGUtYmFja2dyb3VuZD0ibmV3IDAgMCAyMDAgMjAwIiB2aWV3Qm94PSIwIDAgMjAwIDIwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48ZyBmaWxsPSIjZmZmIj48cGF0aCBkPSJtMTc2LjIgMjQuMmMtLjUtMS44LTIuMi0zLTQtMi44aC0xMDBsLTM5LjEgNDEuMmMtMi43IDIuNy0uOSA2LjQgMyA2LjRoODQuMWw1NC42LTQwLjZjMS4yLTEgMS44LTIuNiAxLjQtNC4yeiIvPjxwYXRoIGQ9Im0xNjcuMiAxMTUuNy0zOC40LTM3LjkuMS0uMWgtOTMuOGMtMS44IDAtMy4zIDEuNS0zLjMgMy4zIDAgLjkuNCAxLjcgMSAyLjNsMzguMiAzNy45LS4xLjFoOTQuMWMxLjgtLjEgMy4yLTEuNiAzLjItMy40IDAtLjgtLjQtMS42LTEtMi4yeiIvPjxwYXRoIGQ9Im0xNjcuMiAxMzEuMWMtLjctLjYtMS42LTEtMi41LTFoLTg0LjhsLTU0LjYgNDAuN2MtMS43IDEuMi0yLjEgMy42LS44IDUuNC44IDEuMSAyLjEgMS43IDMuNCAxLjZoMTAwbDM5LjUtNDEuNWMxLjItMS42IDEuMi0zLjktLjItNS4yeiIvPjwvZz48L3N2Zz4=';
30+
31+
add_menu_page(
2932
__( 'Stackable', STACKABLE_I18N ), // Page title.
3033
__( 'Stackable', STACKABLE_I18N ) . ' ' . stackable_notification_count(), // Menu title.
3134
'manage_options', // Capability.
3235
'stackable', // Menu slug.
33-
array( $this, 'stackable_settings_content' ), // Callback function.
34-
null // Position
36+
array( $this, 'stackable_getting_started_content' ), // Callback function.
37+
$icon,
38+
25
3539
);
3640

3741
// Our getting started page.
3842
add_submenu_page(
39-
isset( $_GET['page'] ) && $_GET['page'] === 'stackable-getting-started' ? 'options-general.php' : '', // Parent slug. Only show when in the page.
40-
__( 'Get Started', STACKABLE_I18N ), // Page title.
41-
'<span class="fs-submenu-item fs-sub"></span>' . __( 'Get Started', STACKABLE_I18N ), // Menu title.
43+
'stackable', // Parent slug.
44+
__( 'Getting Started', STACKABLE_I18N ), // Page title.
45+
__( 'Getting Started', STACKABLE_I18N ), // Menu title.
4246
'manage_options', // Capability.
43-
'stackable-getting-started', // Menu slug.
47+
'stackable', // Menu slug.
4448
array( $this, 'stackable_getting_started_content' ), // Callback function.
45-
null // Position
4649
);
50+
51+
// Our settings page.
52+
add_submenu_page(
53+
'stackable', // Parent slug.
54+
__( 'Stackable', STACKABLE_I18N ), // Page title.
55+
__( 'Settings', STACKABLE_I18N ) . ' ' . stackable_notification_count(), // Menu title.
56+
'manage_options', // Capability.
57+
'stackable-settings', // Menu slug.
58+
array( $this, 'stackable_settings_content' ), // Callback function.
59+
);
60+
61+
do_action( 'stackable_submenu_register' );
62+
63+
// Documentation
64+
add_submenu_page(
65+
'stackable', // Parent slug.
66+
__( 'Documentation', STACKABLE_I18N ), // Page title.
67+
__( 'Documentation', STACKABLE_I18N ), // Menu title.
68+
'manage_options', // Capability.
69+
'stackable-documentation', // Menu slug.
70+
'__return_null',
71+
);
72+
73+
if ( STACKABLE_BUILD === 'free' || ! sugb_fs()->can_use_premium_code() ) {
74+
add_submenu_page(
75+
'stackable', // Parent slug.
76+
__( 'Go Premium', STACKABLE_I18N ), // Page title.
77+
__( 'Go Premium', STACKABLE_I18N ), // Menu title.
78+
'manage_options', // Capability.
79+
'stackable-go-premium', // Menu slug.
80+
array( $this, 'stackable_go_premium_content' ),
81+
);
82+
}
4783
}
4884

4985
public function enqueue_dashboard_script( $hook ) {
@@ -55,7 +91,7 @@ public function enqueue_dashboard_script( $hook ) {
5591
}
5692

5793
// For the options page, load our options script.
58-
if ( 'settings_page_stackable' === $hook || stripos( $hook, 'page_stackable-settings' ) !== false || 'settings_page_stackable-getting-started' === $hook ) {
94+
if ( 'settings_page_stackable' === $hook || stripos( $hook, 'page_stackable-settings' ) !== false || 'toplevel_page_stackable' === $hook ) {
5995

6096
wp_enqueue_script( 'wp-i18n' );
6197
wp_enqueue_script( 'wp-element' );
@@ -95,7 +131,7 @@ public static function print_tabs() {
95131
$display_account_tab = true;
96132
$display_contact_tab = true;
97133
$account_url = STACKABLE_BUILD === 'free' ? '' : sugb_fs()->get_account_url();
98-
$contact_url = admin_url( 'options-general.php?page=stackable-contact' );
134+
$contact_url = admin_url( 'admin.php?page=stackable-contact' );
99135

100136
// If network activated and in multisite, the accounts page is in a different URL.
101137
if ( STACKABLE_BUILD === 'free' ) {
@@ -117,47 +153,54 @@ public static function print_tabs() {
117153

118154
?>
119155
<div class="s-body s-tabs">
120-
<a class="s-tab <?php echo $screen->base === 'settings_page_stackable-getting-started' ? 's-active' : '' ?>"
121-
href="<?php echo admin_url( 'options-general.php?page=stackable-getting-started' ) ?>">
156+
<a class="s-tab <?php echo $screen->base === 'toplevel_page_stackable' ? 's-active' : '' ?>"
157+
href="<?php echo admin_url( 'admin.php?page=stackable' ) ?>">
122158
<span><?php _e( 'Getting Started', STACKABLE_I18N ) ?></span>
123159
</a>
124160

125-
<a class="s-tab <?php echo $screen->base === 'settings_page_stackable' ? 's-active' : '' ?>"
126-
href="<?php echo admin_url( 'options-general.php?page=stackable' ) ?>">
161+
<a class="s-tab <?php echo $screen->base === 'stackable_page_stackable-settings' ? 's-active' : '' ?>"
162+
href="<?php echo admin_url( 'admin.php?page=stackable-settings' ) ?>">
127163
<span><?php _e( 'Settings', STACKABLE_I18N ) ?></span>
128164
</a>
129165

130166
<?php if ( $display_account_tab && STACKABLE_BUILD !== 'free' && sugb_fs()->get_user() ) { ?>
131-
<a class="s-tab <?php echo $screen->base === 'settings_page_stackable-account' ? 's-active' : '' ?>"
167+
<a class="s-tab <?php echo $screen->base === 'stackable_page_stackable-account' ? 's-active' : '' ?>"
132168
href="<?php echo $account_url ?>">
133169
<span><?php _e( 'Account', STACKABLE_I18N ) ?></span>
134170
</a>
135171
<?php } ?>
136172

137173
<?php if ( STACKABLE_BUILD !== 'free' && sugb_fs()->has_affiliate_program() ) { ?>
138-
<a class="s-tab <?php echo $screen->base === 'settings_page_stackable-affiliation' ? 's-active' : '' ?>"
174+
<a class="s-tab <?php echo $screen->base === 'stackable_page_stackable-affiliation' ? 's-active' : '' ?>"
139175
href="<?php echo admin_url( 'options-general.php?page=stackable-affiliation' ) ?>">
140176
<span><?php _e( 'Affiliation', STACKABLE_I18N ) ?></span>
141177
</a>
142178
<?php } ?>
143179

180+
<?php if ( function_exists( 'stackable_is_custom_fields_enabled' ) ) { ?>
181+
<?php if ( stackable_is_custom_fields_enabled() && current_user_can( 'manage_stackable_custom_fields' ) ) { ?>
182+
<a class="s-tab <?php echo $screen->base === 'stackable_page_stk-custom-fields' ? 's-active' : '' ?>"
183+
href="<?php echo admin_url( 'admin.php?page=stk-custom-fields' ) ?>">
184+
<span><?php _e( 'Custom Fields', STACKABLE_I18N ) ?></span>
185+
</a>
186+
<?php } ?>
187+
<?php } ?>
188+
144189
<a class="s-tab" href="https://docs.wpstackable.com" target="_docs">
145190
<span><?php _e( 'Documentation', STACKABLE_I18N ) ?></span></a>
146191

147192
<?php if ( $display_contact_tab && STACKABLE_BUILD !== 'free' ) { ?>
148-
<a class="s-tab <?php echo $screen->base === 'settings_page_stackable-contact' ? 's-active' : '' ?>"
193+
<a class="s-tab <?php echo $screen->base === 'stackable_page_stackable-contact' ? 's-active' : '' ?>"
149194
href="<?php echo $contact_url ?>">
150195
<span><?php _e( 'Contact Us', STACKABLE_I18N ) ?></span>
151196
</a>
152197
<?php } ?>
153198

154-
<?php if ( function_exists( 'stackable_is_custom_fields_enabled' ) ) { ?>
155-
<?php if ( stackable_is_custom_fields_enabled() && current_user_can( 'manage_stackable_custom_fields' ) ) { ?>
156-
<a class="s-tab <?php echo $screen->base === 'toplevel_page_stk-custom-fields' ? 's-active' : '' ?>"
157-
href="<?php echo admin_url( 'admin.php?page=stk-custom-fields' ) ?>">
158-
<span><?php _e( 'Custom Fields', STACKABLE_I18N ) ?></span>
159-
</a>
160-
<?php } ?>
199+
<?php if ( STACKABLE_BUILD === 'free' || ! sugb_fs()->can_use_premium_code() ) { ?>
200+
<a class="s-tab <?php echo $screen->base === 'stackable_page_stackable-go-premium' ? 's-active' : '' ?>"
201+
href="<?php echo admin_url( 'admin.php?page=stackable-go-premium' )?>">
202+
<span><?php _e( 'Go Premium', STACKABLE_I18N ) ?></span>
203+
</a>
161204
<?php } ?>
162205
</div>
163206
<?php
@@ -203,7 +246,27 @@ public function stackable_settings_content() {
203246
<div class="s-content" id="settings-content"></div>
204247
<?php do_action( 'stackable_settings_page_mid' ); ?>
205248
</div>
206-
<!-- <div class="s-side">
249+
</section>
250+
</div>
251+
<?php
252+
}
253+
254+
public function stackable_go_premium_content() {
255+
?>
256+
<div class="wrap wrap-settings">
257+
<div class="s-header-wrap s-header-settings">
258+
<?php $this->print_header() ?>
259+
<?php echo $this->print_premium_button() ?>
260+
<?php echo $this->print_tabs() ?>
261+
</div>
262+
<h1 aria-hidden="true" class="s-admin-notice-marker"></h1>
263+
<section id="settings-notice">
264+
<div class="s-rest-settings-notice"></div>
265+
<div class="s-save-settings-notice"></div>
266+
</section>
267+
<?php stackable_welcome_notification() ?>
268+
<section class="s-body-container s-body-container-with-sidenav">
269+
<div class="s-side">
207270
<?php if ( STACKABLE_BUILD === 'free' || ! sugb_fs()->can_use_premium_code() ) : ?>
208271
<aside class="s-box s-premium-box">
209272
<h3><?php _e( '🚀 Stackable Premium', STACKABLE_I18N ) ?></h3>
@@ -241,10 +304,7 @@ public function stackable_settings_content() {
241304
<p><?php _e( 'Keep up to date by subscribing to our newsletter.', STACKABLE_I18N ) ?></p>
242305
<p><a href="http://eepurl.com/dJY9xI" class="s-button" target="_new" title="<?php esc_attr_e( 'Subscribe', STACKABLE_I18N ) ?>"><?php _e( 'Subscribe', STACKABLE_I18N ) ?></a></p>
243306
</aside>
244-
</div> -->
245-
246-
247-
307+
</div>
248308
</section>
249309
</div>
250310
<?php
@@ -279,6 +339,31 @@ public function stackable_getting_started_content() {
279339
<?php
280340
}
281341

342+
/**
343+
* Redirect to the Stackable Documentation page.
344+
*/
345+
public function redirect_to_docs() {
346+
if ( empty( $_GET['page'] ) ) {
347+
return;
348+
}
349+
350+
if ( 'stackable-documentation' === $_GET['page'] ) {
351+
wp_redirect('https://docs.wpstackable.com');
352+
exit;
353+
}
354+
}
355+
356+
public function redirect_to_docs_newtab() {
357+
?>
358+
<script>
359+
document.addEventListener('DOMContentLoaded', function() {
360+
const link = document.querySelector('a[href="admin.php?page=stackable-documentation"]');
361+
if (link) link.setAttribute('target', '_blank');
362+
});
363+
</script>
364+
<?php
365+
}
366+
282367
/**
283368
* Adds links to the plugins page entry.
284369
*
@@ -342,7 +427,7 @@ public function redirect_to_welcome_page() {
342427
}
343428

344429
// Or go to the getting started page.
345-
wp_redirect( esc_url( admin_url( 'options-general.php?page=stackable-getting-started' ) ) );
430+
wp_redirect( esc_url( admin_url( 'admin.php?page=stackable' ) ) );
346431

347432
die();
348433
}

0 commit comments

Comments
 (0)