Skip to content

Commit 75ed46d

Browse files
authored
Merge pull request #3846 from extendify/add-library-with-utility-classes
Add library update
2 parents 734bf35 + 6a74805 commit 75ed46d

File tree

108 files changed

+9405
-33136
lines changed

Some content is hidden

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

108 files changed

+9405
-33136
lines changed

redux-core/extendify-sdk/.github/workflows/force-production-on-main.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build production assets
1+
name: Build production and deploy
22
on:
33
push:
44
branches:
@@ -53,9 +53,11 @@ jobs:
5353
npm run build
5454
env:
5555
CI: true
56+
5657
- name: Increment version number
5758
run: |
5859
perl -i -pe 's/(Stable tag: )([\d.]+)$/$1.($2+.1)/e' readme.txt
60+
perl -i -pe 's/(Version: )([\d.]+)$/$1.($2+.1)/e' extendify-sdk.php
5961
- name: Commit dist folder if needed #it fails if nothing has changed so we allow an error
6062
run: git commit -am 'Build produciton assets'
6163
continue-on-error: true
@@ -64,3 +66,9 @@ jobs:
6466
with:
6567
github_token: ${{ secrets.GITHUB_TOKEN }}
6668
branch: main
69+
70+
- name: Deploy to library.extendify.com
71+
uses: fjogeleit/http-request-action@master
72+
with:
73+
url: ${{ secrets.DEPLOY_WEBHOOK }}
74+
method: 'POST'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
14.18.1

redux-core/extendify-sdk/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
engine-strict=true

redux-core/extendify-sdk/app/Admin.php

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Extendify\ExtendifySdk\App;
99
use Extendify\ExtendifySdk\User;
10+
use Extendify\ExtendifySdk\SiteSettings;
1011

1112
/**
1213
* This class handles any file loading for the admin area.
@@ -54,6 +55,10 @@ function ($hook) {
5455
return;
5556
}
5657

58+
if (!$this->isLibraryEnabled()) {
59+
return;
60+
}
61+
5762
$this->addScopedScriptsAndStyles();
5863
}
5964
);
@@ -87,7 +92,6 @@ public function addScopedScriptsAndStyles()
8792
App::$slug . '-scripts',
8893
EXTENDIFYSDK_BASE_URL . 'public/build/extendify-sdk.js',
8994
[
90-
'wp-api',
9195
'wp-i18n',
9296
'wp-components',
9397
'wp-element',
@@ -103,7 +107,8 @@ public function addScopedScriptsAndStyles()
103107
'root' => \esc_url_raw(rest_url(APP::$slug . '/' . APP::$apiVersion)),
104108
'nonce' => \wp_create_nonce('wp_rest'),
105109
'user' => json_decode(User::data('extendifysdk_user_data'), true),
106-
'source' => \esc_attr(APP::$sourcePlugin),
110+
'sitesettings' => json_decode(SiteSettings::data()),
111+
'sdk_partner' => \esc_attr(APP::$sdkPartner),
107112
]
108113
);
109114
\wp_enqueue_script(App::$slug . '-scripts');
@@ -117,5 +122,40 @@ public function addScopedScriptsAndStyles()
117122
$version,
118123
'all'
119124
);
125+
126+
\wp_enqueue_style(
127+
App::$slug . '-utility-classes',
128+
EXTENDIFYSDK_BASE_URL . 'public/build/extendify-utilities.css',
129+
[],
130+
$version,
131+
'all'
132+
);
133+
}
134+
135+
/**
136+
* Check if current user is Admin
137+
*
138+
* @return Boolean
139+
*/
140+
private function isAdmin()
141+
{
142+
return in_array('administrator', \wp_get_current_user()->roles, true);
143+
}
144+
145+
/**
146+
* Check if scripts should add
147+
*
148+
* @return Boolean
149+
*/
150+
public function isLibraryEnabled()
151+
{
152+
$settings = json_decode(SiteSettings::data());
153+
154+
// If it's disabled, only show it for admins.
155+
if (isset($settings->state) && (isset($settings->state->enabled)) && !$settings->state->enabled) {
156+
return $this->isAdmin();
157+
}
158+
159+
return true;
120160
}
121161
}

redux-core/extendify-sdk/app/App.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ class App
5656
public static $environment = '';
5757

5858
/**
59-
* Host plugin
59+
* The partner plugin/theme
6060
*
6161
* @var string
6262
*/
63-
public static $sourcePlugin = 'Not set';
63+
public static $sdkPartner = '';
6464

6565
/**
6666
* Host plugin
@@ -83,8 +83,10 @@ class App
8383
*/
8484
public function __construct()
8585
{
86-
if (isset($GLOBALS['extendifySdkSourcePlugin'])) {
87-
self::$sourcePlugin = $GLOBALS['extendifySdkSourcePlugin'];
86+
// Set the "partner" plugin/theme here with a fallback to support the previous plugin implementation.
87+
self::$sdkPartner = isset($GLOBALS['extendify_sdk_partner']) ? $GLOBALS['extendify_sdk_partner'] : '';
88+
if (!self::$sdkPartner && isset($GLOBALS['extendifySdkSourcePlugin'])) {
89+
self::$sdkPartner = $GLOBALS['extendifySdkSourcePlugin'];
8890
}
8991

9092
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Controls User info
4+
*/
5+
6+
namespace Extendify\ExtendifySdk\Controllers;
7+
8+
use Extendify\ExtendifySdk\SiteSettings;
9+
10+
if (!defined('ABSPATH')) {
11+
die('No direct access.');
12+
}
13+
14+
/**
15+
* The controller for managing Extendify SiteSettings.
16+
*/
17+
class SiteSettingsController
18+
{
19+
20+
/**
21+
* Return Current SiteSettings meta data
22+
*
23+
* @return array
24+
*/
25+
public static function show()
26+
{
27+
return new \WP_REST_Response(SiteSettings::data());
28+
}
29+
30+
/**
31+
* Persist the data
32+
*
33+
* @param \WP_REST_Request $request - The request.
34+
* @return array
35+
*/
36+
public static function store($request)
37+
{
38+
$settingsData = json_decode($request->get_param('data'), true);
39+
\update_option(SiteSettings::key(), $settingsData, true);
40+
return new \WP_REST_Response(SiteSettings::data());
41+
}
42+
}

redux-core/extendify-sdk/app/Controllers/TaxonomyController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616
*/
1717
class TaxonomyController
1818
{
19-
2019
/**
2120
* Return all taxonomies
2221
*
2322
* @return WP_REST_Response|WP_Error
2423
*/
2524
public static function index()
2625
{
27-
$response = Http::get('/airtable-taxonomies', []);
26+
$response = Http::get('/airtable-taxonomies-simple', []);
2827
return new \WP_REST_Response($response);
2928
}
3029
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
/**
3+
* Manage any frontend related tasks here.
4+
*/
5+
6+
namespace Extendify\ExtendifySdk;
7+
8+
use Extendify\ExtendifySdk\App;
9+
10+
/**
11+
* This class handles any file loading for the frontend of the site.
12+
*/
13+
class Frontend
14+
{
15+
16+
/**
17+
* The instance
18+
*
19+
* @var $instance
20+
*/
21+
public static $instance = null;
22+
23+
/**
24+
* Adds various actions to set up the page
25+
*
26+
* @return self|void
27+
*/
28+
public function __construct()
29+
{
30+
if (self::$instance) {
31+
return self::$instance;
32+
}
33+
34+
self::$instance = $this;
35+
$this->loadScripts();
36+
}
37+
38+
/**
39+
* Adds scripts and styles to every page is enabled
40+
*
41+
* @return void
42+
*/
43+
public function loadScripts()
44+
{
45+
\add_action(
46+
'wp_enqueue_scripts',
47+
function () {
48+
// TODO: Determine a way to conditionally load assets (https://github.com/extendify/company-product/issues/72).
49+
$this->addStylesheets();
50+
}
51+
);
52+
}
53+
54+
/**
55+
* Adds stylesheets as needed
56+
*
57+
* @return void
58+
*/
59+
public function addStylesheets()
60+
{
61+
$version = App::$environment === 'PRODUCTION' ? App::$version : uniqid();
62+
\wp_enqueue_style(
63+
App::$slug . '-utility-classes',
64+
EXTENDIFYSDK_BASE_URL . 'public/build/extendify-utilities.css',
65+
[],
66+
$version,
67+
'all'
68+
);
69+
}
70+
}

redux-core/extendify-sdk/app/Http.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,13 @@ public function __construct($request)
6060
$this->baseUrl = $request->get_header('x_extendify_local_mode') !== 'false' ? App::$config['api']['local'] : $this->baseUrl;
6161

6262
$this->data = [
63+
'wp_language' => \get_locale(),
64+
'wp_theme' => \get_option('template'),
6365
'mode' => App::$environment,
6466
'uuid' => User::data('uuid'),
6567
'sdk_version' => App::$version,
66-
'wp_plugins' => $request->get_method() === 'POST' ? array_keys(\get_plugins()) : [],
68+
'wp_active_plugins' => $request->get_method() === 'POST' ? \get_option('active_plugins') : [],
69+
'sdk_partner' => App::$sdkPartner,
6770
];
6871

6972
$this->headers = [

0 commit comments

Comments
 (0)