Skip to content

Commit 7838bbd

Browse files
authored
Merge pull request #3906 from reduxframework/update-extendify-8pjxkdi
Update Extendify Library
2 parents 9ffa161 + fbc5b95 commit 7838bbd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+895
-198
lines changed

extendify-sdk/app/Assist/Admin.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public function __construct()
3333

3434
self::$instance = $this;
3535
$this->loadScripts();
36+
if (Config::$environment === 'PRODUCTION') {
37+
$this->hideSubmenus();
38+
}
3639
}
3740

3841
/**
@@ -94,4 +97,25 @@ function () {
9497
);
9598
}
9699

100+
/**
101+
* Hide Extendify 'Welcome' and 'Assist' submenus on all admin pages.
102+
*
103+
* @return void
104+
*/
105+
public function hideSubmenus()
106+
{
107+
add_action('admin_head', function () {
108+
echo '<style>
109+
#toplevel_page_extendify-assist .wp-submenu,
110+
#toplevel_page_extendify-welcome .wp-submenu {
111+
display:none!important;
112+
}
113+
#toplevel_page_extendify-assist::after,
114+
#toplevel_page_extendify-welcome::after {
115+
content:none!important;
116+
}
117+
</style>';
118+
});
119+
}
120+
97121
}

extendify-sdk/app/Assist/AdminPage.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ class AdminPage
2020
public function __construct()
2121
{
2222
if (Config::$showAssist) {
23+
\add_filter('wp_redirect', function ($url) {
24+
// No nonce for _GET.
25+
// phpcs:ignore WordPress.Security.NonceVerification
26+
if (isset($_GET['extendify-launch-successful'])) {
27+
return \admin_url() . 'admin.php?page=extendify-assist';
28+
}
29+
30+
return $url;
31+
}, 9999);
32+
2333
\add_action('admin_menu', [ $this, 'addAdminMenu' ]);
2434
$this->loadScripts();
2535
}
@@ -69,10 +79,14 @@ public function createAdminPage()
6979
{
7080
?>
7181
<div class="extendify-outer-container">
72-
<div class="wrap welcome-container">
82+
<div class="wrap" style="max-width:1000px;margin:-16px auto 24px;">
7383
<ul class="extendify-welcome-tabs">
7484
<li class="active"><a href="<?php echo \esc_url(\admin_url('admin.php?page=extendify-assist')); ?>">Assist</a></li>
7585
<li><a href="<?php echo \esc_url(\admin_url('admin.php?page=extendify-welcome')); ?>">Library</a></li>
86+
<?php if (Config::$showOnboarding) : ?>
87+
<li><a href="<?php echo \esc_url(\admin_url('post-new.php?extendify=onboarding')); ?>">Launch</a></li>
88+
<?php endif; ?>
89+
<li class="cta-button"><a href="<?php echo \esc_url_raw(\get_home_url()); ?>" target="_blank"><?php echo \esc_html(__('View Site', 'extendify')); ?></a></li>
7690
</ul>
7791
<div id="extendify-assist-landing-page" class="extendify-assist"></div>
7892
</div>

extendify-sdk/app/Assist/Controllers/AssistDataController.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,28 @@ class AssistDataController
1818
/**
1919
* Return pages created via Launch.
2020
*
21-
* @return array
21+
* @return \WP_REST_Response
2222
*/
2323
public static function getLaunchPages()
2424
{
2525
$pages = \get_pages(['sort_column' => 'post_title']);
26-
$newPages = [];
27-
28-
foreach ($pages as $page) {
26+
$pages = array_filter($pages, function ($page) {
2927
$meta = \metadata_exists( 'post', $page->ID, 'made_with_extendify_launch' );
30-
if ($meta === true) {
31-
$page->permalink = \get_the_permalink($page->ID);
32-
$path = \wp_parse_url($page->permalink)['path'];
33-
$parseSiteUrl = \wp_parse_url(\get_site_url());
34-
$page->url = $parseSiteUrl['scheme'] . '://' . $parseSiteUrl['host'] . $path;
35-
$page->madeWithLaunch = true;
36-
array_push($newPages, $page);
37-
}
38-
}
28+
return $meta === true;
29+
});
30+
31+
$data = array_map(function ($page) {
32+
$page->permalink = \get_the_permalink($page->ID);
33+
$path = \wp_parse_url($page->permalink)['path'];
34+
$parseSiteUrl = \wp_parse_url(\get_site_url());
35+
$page->url = $parseSiteUrl['scheme'] . '://' . $parseSiteUrl['host'] . $path;
36+
$page->madeWithLaunch = true;
37+
return $page;
38+
}, $pages);
3939

40-
return $newPages;
40+
return new \WP_REST_Response([
41+
'success' => true,
42+
'data' => array_values($data),
43+
]);
4144
}
4245
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/**
3+
* Controls Tasks
4+
*/
5+
6+
namespace Extendify\Assist\Controllers;
7+
8+
use Extendify\Http;
9+
10+
if (!defined('ABSPATH')) {
11+
die('No direct access.');
12+
}
13+
14+
/**
15+
* The controller for plugin dependency checking, etc
16+
*/
17+
class TasksController
18+
{
19+
20+
/**
21+
* Return tasks from either database or source.
22+
*
23+
* @return \WP_REST_Response
24+
*/
25+
public static function fetchTasks()
26+
{
27+
$response = Http::get('/tasks');
28+
return new \WP_REST_Response(
29+
$response,
30+
wp_remote_retrieve_response_code($response)
31+
);
32+
}
33+
34+
/**
35+
* Return the data
36+
*
37+
* @return \WP_REST_Response
38+
*/
39+
public static function get()
40+
{
41+
$data = get_option('extendify_assist_tasks', []);
42+
return new \WP_REST_Response($data);
43+
}
44+
45+
/**
46+
* Persist the data
47+
*
48+
* @param \WP_REST_Request $request - The request.
49+
* @return \WP_REST_Response
50+
*/
51+
public static function store($request)
52+
{
53+
$data = json_decode($request->get_param('data'), true);
54+
update_option('extendify_assist_tasks', $data);
55+
return new \WP_REST_Response($data);
56+
}
57+
}

extendify-sdk/app/Config.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class Config
8989
public static $config = [];
9090

9191
/**
92-
* Plugin completed status
92+
* Whether Launch was finished
9393
*
9494
* @var mixed
9595
*/
@@ -136,7 +136,9 @@ public function __construct()
136136

137137
self::$environment = $isDev ? 'DEVELOPMENT' : 'PRODUCTION';
138138
self::$showOnboarding = $this->showOnboarding();
139-
self::$showAssist = $isDev || self::$launchCompleted;
139+
140+
// If they can see onboarding, or they've completed it, they can see assist.
141+
self::$showAssist = self::$launchCompleted || self::$showOnboarding;
140142

141143
// Add the config.
142144
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
@@ -166,11 +168,6 @@ private function showOnboarding()
166168
return false;
167169
}
168170

169-
// time() will be truthy and 0 falsy.
170-
if (get_option('extendify_onboarding_skipped', 0)) {
171-
return false;
172-
}
173-
174171
// time() will be truthy and 0 falsy, so we reverse it.
175172
return !self::$launchCompleted;
176173
}

extendify-sdk/app/Http.php

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,7 @@ public function __construct($request)
5656
}
5757

5858
// Some special cases for library development.
59-
$this->baseUrl = $request->get_header('x_extendify_dev_mode') !== 'false' ? Config::$config['api']['dev'] : Config::$config['api']['live'];
60-
$this->baseUrl = $request->get_header('x_extendify_local_mode') !== 'false' ? Config::$config['api']['local'] : $this->baseUrl;
61-
62-
// Onboarding request.
63-
$this->baseUrl = $request->get_header('x_extendify_onboarding') === 'true' ? Config::$config['api']['onboarding'] : $this->baseUrl;
64-
$this->baseUrl = $request->get_header('x_extendify_onboarding_dev_mode') === 'true' ? Config::$config['api']['onboarding-dev'] : $this->baseUrl;
65-
$this->baseUrl = $request->get_header('x_extendify_onboarding_local_mode') === 'true' ? Config::$config['api']['onboarding-local'] : $this->baseUrl;
59+
$this->baseUrl = $this->getBaseUrl($request);
6660

6761
$this->data = [
6862
'wp_language' => \get_locale(),
@@ -163,4 +157,57 @@ public static function __callStatic($name, array $arguments)
163157

164158
return $r->$name(...$arguments);
165159
}
160+
161+
/**
162+
* Figure out the base URL to use.
163+
*
164+
* @param \WP_REST_Request $request - The request.
165+
*
166+
* @return string
167+
*/
168+
public function getBaseUrl($request)
169+
{
170+
// Library Dev request.
171+
if ($request->get_header('x_extendify_dev_mode') === 'true') {
172+
return Config::$config['api']['dev'];
173+
}
174+
175+
// Library Local request.
176+
if ($request->get_header('x_extendify_local_mode') === 'true') {
177+
return Config::$config['api']['local'];
178+
}
179+
180+
// Onboarding dev request.
181+
if ($request->get_header('x_extendify_onboarding_dev_mode') === 'true') {
182+
return Config::$config['api']['onboarding-dev'];
183+
}
184+
185+
// Onborarding local request.
186+
if ($request->get_header('x_extendify_onboarding_local_mode') === 'true') {
187+
return Config::$config['api']['onboarding-local'];
188+
}
189+
190+
// Onboarding request.
191+
if ($request->get_header('x_extendify_onboarding') === 'true') {
192+
return Config::$config['api']['onboarding'];
193+
}
194+
195+
// Assist dev request.
196+
if ($request->get_header('x_extendify_assist_dev_mode') === 'true') {
197+
return Config::$config['api']['assist-dev'];
198+
}
199+
200+
// Assist local request.
201+
if ($request->get_header('x_extendify_assist_local_mode') === 'true') {
202+
return Config::$config['api']['assist-local'];
203+
}
204+
205+
// Assist request.
206+
if ($request->get_header('x_extendify_assist') === 'true') {
207+
return Config::$config['api']['assist'];
208+
}
209+
210+
// Normal Library request.
211+
return Config::$config['api']['live'];
212+
}
166213
}

extendify-sdk/app/Library/Controllers/AuthController.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ class AuthController
2626
public static function login($request)
2727
{
2828
$response = Http::post('/login', $request->get_params());
29-
return new \WP_REST_Response($response);
29+
return new \WP_REST_Response(
30+
$response,
31+
wp_remote_retrieve_response_code($response)
32+
);
3033
}
3134

3235
/**
@@ -38,6 +41,9 @@ public static function login($request)
3841
public static function register($request)
3942
{
4043
$response = Http::post('/register', $request->get_params());
41-
return new \WP_REST_Response($response);
44+
return new \WP_REST_Response(
45+
$response,
46+
wp_remote_retrieve_response_code($response)
47+
);
4248
}
4349
}

extendify-sdk/app/Library/Controllers/MetaController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class MetaController
2525
public static function getAll($request)
2626
{
2727
$response = Http::get('/meta-data', $request->get_params());
28-
return new \WP_REST_Response($response);
28+
return new \WP_REST_Response(
29+
$response,
30+
wp_remote_retrieve_response_code($response)
31+
);
2932
}
3033
}

extendify-sdk/app/Library/Controllers/PingController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class PingController
2525
public static function ping($request)
2626
{
2727
$response = Http::post('/ping', $request->get_params());
28-
return new \WP_REST_Response($response);
28+
return new \WP_REST_Response(
29+
$response,
30+
wp_remote_retrieve_response_code($response)
31+
);
2932
}
3033
}

extendify-sdk/app/Library/Controllers/TaxonomyController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ class TaxonomyController
2424
public static function index()
2525
{
2626
$response = Http::get('/taxonomies', []);
27-
return new \WP_REST_Response($response);
27+
return new \WP_REST_Response(
28+
$response,
29+
wp_remote_retrieve_response_code($response)
30+
);
2831
}
2932
}

extendify-sdk/app/Library/Controllers/TemplateController.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ class TemplateController
2626
public static function index($request)
2727
{
2828
$response = Http::post('/templates', $request->get_params());
29-
return new \WP_REST_Response($response);
29+
return new \WP_REST_Response(
30+
$response,
31+
wp_remote_retrieve_response_code($response)
32+
);
3033
}
3134

3235
/**
@@ -38,6 +41,9 @@ public static function index($request)
3841
public static function ping($request)
3942
{
4043
$response = Http::post('/templates', $request->get_params());
41-
return new \WP_REST_Response($response);
44+
return new \WP_REST_Response(
45+
$response,
46+
wp_remote_retrieve_response_code($response)
47+
);
4248
}
4349
}

extendify-sdk/app/Library/Controllers/UserController.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ public static function delete()
7575
public static function mailingList($request)
7676
{
7777
$response = Http::post('/register-mailing-list', $request->get_params());
78-
return new \WP_REST_Response($response);
78+
return new \WP_REST_Response(
79+
$response,
80+
wp_remote_retrieve_response_code($response)
81+
);
7982
}
8083

8184
/**
@@ -86,6 +89,9 @@ public static function mailingList($request)
8689
public static function maxImports()
8790
{
8891
$response = Http::get('/max-free-imports');
89-
return new \WP_REST_Response($response);
92+
return new \WP_REST_Response(
93+
$response,
94+
wp_remote_retrieve_response_code($response)
95+
);
9096
}
9197
}

0 commit comments

Comments
 (0)