Skip to content

Commit

Permalink
v.2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ZafarKamal123 committed Aug 12, 2021
1 parent dfb56a0 commit 42dae4d
Show file tree
Hide file tree
Showing 49 changed files with 30,640 additions and 7,550 deletions.
2 changes: 1 addition & 1 deletion dist/dashboard/build.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions extendify-sdk/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
indent: ['error', 4, {
SwitchCase: 1,
}],
'require-await': 'error',
quotes: ['error', 'single'],
'comma-dangle': ['error', 'always-multiline'],
'multiline-ternary': ['error', 'always'],
Expand Down
7 changes: 6 additions & 1 deletion extendify-sdk/app/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public function loadScripts()
\add_action(
'admin_enqueue_scripts',
function ($hook) {
if (!current_user_can(App::$requiredCapability)) {
return;
}

if (!$this->checkItsGutenbergPost($hook)) {
return;
}
Expand All @@ -63,7 +67,7 @@ function ($hook) {
*/
public function checkItsGutenbergPost($hook = '')
{
if (isset($GLOBALS['typenow']) && use_block_editor_for_post_type($GLOBALS['typenow'])) {
if (isset($GLOBALS['typenow']) && \use_block_editor_for_post_type($GLOBALS['typenow'])) {
return $hook && in_array($hook, ['post.php', 'post-new.php'], true);
}

Expand Down Expand Up @@ -99,6 +103,7 @@ public function addScopedScriptsAndStyles()
'root' => \esc_url_raw(rest_url(APP::$slug . '/' . APP::$apiVersion)),
'nonce' => \wp_create_nonce('wp_rest'),
'user' => json_decode(User::data('extendifysdk_user_data'), true),
'source' => \esc_attr(APP::$sourcePlugin),
]
);
\wp_enqueue_script(App::$slug . '-scripts');
Expand Down
15 changes: 1 addition & 14 deletions extendify-sdk/app/ApiRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ApiRouter extends \WP_REST_Controller
*/
public function __construct()
{
$this->capability = 'install_plugins';
$this->capability = App::$requiredCapability;
add_filter(
'rest_request_before_callbacks',
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
Expand All @@ -51,19 +51,6 @@ function ($response, $handler, $request) {
);
}

/**
* Check the capability
*
* @param string $capability - The capability.
*
* @return boolean
*/
public function permission($capability)
{
$this->capability = $capability;
return $this;
}

/**
* Check the authorization of the request
*
Expand Down
18 changes: 18 additions & 0 deletions extendify-sdk/app/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ class App
*/
public static $environment = '';

/**
* Host plugin
*
* @var string
*/
public static $sourcePlugin = 'Not set';

/**
* Host plugin
*
* @var string
*/
public static $requiredCapability = 'upload_files';

/**
* Plugin config
*
Expand All @@ -69,6 +83,10 @@ class App
*/
public function __construct()
{
if (isset($GLOBALS['extendifySdkSourcePlugin'])) {
self::$sourcePlugin = $GLOBALS['extendifySdkSourcePlugin'];
}

// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
$readme = file_get_contents(dirname(__DIR__) . '/readme.txt');

Expand Down
30 changes: 30 additions & 0 deletions extendify-sdk/app/Controllers/PingController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Controls Http requests
*/

namespace Extendify\ExtendifySdk\Controllers;

use Extendify\ExtendifySdk\Http;

if (!defined('ABSPATH')) {
die('No direct access.');
}

/**
* The controller for sending little bits of info
*/
class PingController
{
/**
* Send data about a specific topic
*
* @param \WP_REST_Request $request - The request.
* @return WP_REST_Response|WP_Error
*/
public static function ping($request)
{
$response = Http::post('/ping', $request->get_params());
return new \WP_REST_Response($response);
}
}
2 changes: 2 additions & 0 deletions extendify-sdk/app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ private function stateHandler()
}

$userData['state']['uuid'] = self::data('uuid');
$userData['state']['canInstallPlugins'] = \current_user_can('install_plugins');
$userData['state']['canActivatePlugins'] = \current_user_can('activate_plugins');

return \wp_json_encode($userData);
}
Expand Down
27 changes: 14 additions & 13 deletions extendify-sdk/editorplus/EditorPlus.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/**
* Handles editor related changes.
* Loaded (or not) in /bootstrap.php
*/

if (!class_exists('edpl__EditorPlus')) {
Expand Down Expand Up @@ -29,6 +30,10 @@ final class ExtendifySdkEditorPlus
*/
public static function getInstance()
{
if (!current_user_can('install_plugins')) {
return;
}

if (is_null(self::$instance)) {
self::$instance = new ExtendifySdkEditorPlus();
}
Expand Down Expand Up @@ -167,7 +172,7 @@ public function addNewTemplate($postsTemplates)
public function registerProjectTemplates($attributes)
{
// Create the key used for the themes cache.
$cacheKey = 'page_templates-' . md5(get_theme_root() . '/' . get_stylesheet());
$cacheKey = 'page_templates-' . \wp_hash(get_theme_root() . '/' . get_stylesheet());
// Retrieve the cache list.
// If it doesn't exist, or it's empty prepare an array.
$templates = wp_get_theme()->get_page_templates();
Expand Down Expand Up @@ -198,23 +203,19 @@ public function viewProjectTemplate($template)
return $template;
}

// Return default template if we don't have a custom one defined.
if (!isset($this->templates[get_post_meta($post->ID, '_wp_page_template', true)])) {
$currentTemplate = get_post_meta($post->ID, '_wp_page_template', true);

// Check that the set template is one we have defined.
if (!is_string($currentTemplate) || !array_key_exists($currentTemplate, $this->templates)) {
return $template;
}

$file = plugin_dir_path(__FILE__) . get_post_meta(
$post->ID,
'_wp_page_template',
true
);

// Just to be safe, we check if the file exist first.
if (file_exists($file)) {
return $file;
$file = plugin_dir_path(__FILE__) . $currentTemplate;
if (!file_exists($file)) {
return $template;
}

return $template;
return $file;
}
// phpcs:ignore Squiz.Classes.ClassDeclaration.SpaceBeforeCloseBrace
}
Expand Down
2 changes: 1 addition & 1 deletion extendify-sdk/extendify-sdk.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __invoke()
return;
}

if (version_compare(PHP_VERSION, '5.6', '<') || version_compare($GLOBALS['wp_version'], '5.4', '<')) {
if (version_compare(PHP_VERSION, '5.6', '<') || version_compare($GLOBALS['wp_version'], '5.5', '<')) {
return;
}

Expand Down
Loading

0 comments on commit 42dae4d

Please sign in to comment.