Skip to content

Commit

Permalink
Merge pull request #91 from joanrodas/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
joanrodas authored Jun 28, 2023
2 parents b49fff1 + ad81245 commit 831aaa9
Show file tree
Hide file tree
Showing 14 changed files with 2,052 additions and 232 deletions.
216 changes: 109 additions & 107 deletions Includes/AssetsLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,111 +4,113 @@

class AssetsLoader
{
private static $instance = NULL;
private $scripts;
private $styles;
private $admin_scripts;
private $admin_styles;

private function __construct()
{
$this->scripts = [];
$this->styles = [];
$this->admin_scripts = [];
$this->admin_styles = [];

add_action('wp_enqueue_scripts', [$this, 'load_assets'], 100);
add_action('admin_enqueue_scripts', [$this, 'load_admin_assets'], 100);
}

// Clone not allowed
private function __clone()
{
}

public static function getInstance()
{
if (is_null(self::$instance)) {
self::$instance = new AssetsLoader();
}
return self::$instance;
}

public function add_style(string $name, string $path, callable $condition = null, array $dependencies = [])
{
$this->styles[] = [
'name' => $name,
'path' => $path,
'condition' => $condition,
'dependencies' => $dependencies
];
}

public function add_script(string $name, string $path, callable $condition = null, array $dependencies = [], $localize = false)
{
$this->scripts[] = [
'name' => $name,
'path' => $path,
'condition' => $condition,
'dependencies' => $dependencies,
'localize' => $localize
];
}

public function add_admin_style(string $name, string $path, callable $condition = null, array $dependencies = [])
{
$this->admin_styles[] = [
'name' => $name,
'path' => $path,
'condition' => $condition,
'dependencies' => $dependencies
];
}

public function add_admin_script(string $name, string $path, callable $condition = null, array $dependencies = [], $localize = false)
{
$this->admin_scripts[] = [
'name' => $name,
'path' => $path,
'condition' => $condition,
'dependencies' => $dependencies,
'localize' => $localize
];
}

public function load_assets($handler)
{
foreach ($this->styles as $style) {
if(is_null($style['condition']) || call_user_func($style['condition'], $handler)) wp_enqueue_style("plugin-placeholder/{$style['name']}", $style['path'], $style['dependencies'], PLUGIN_PLACEHOLDER_VERSION);
}

foreach ($this->scripts as $script) {
if(is_null($script['condition']) || call_user_func($script['condition'], $handler)) {
wp_enqueue_script("plugin-placeholder/{$script['name']}", $script['path'], $script['dependencies'], PLUGIN_PLACEHOLDER_VERSION);

if($script['localize']) {
wp_localize_script("plugin-placeholder/{$script['name']}", $script['localize']['name'], $script['localize']['args']);
}
}
}
}

public function load_admin_assets($handler)
{
foreach ($this->admin_styles as $style) {
if(is_null($style['condition']) || call_user_func($style['condition'], $handler)) wp_enqueue_style("plugin-placeholder/{$style['name']}", $style['path'], $style['dependencies'], PLUGIN_PLACEHOLDER_VERSION);
}

foreach ($this->admin_scripts as $script) {
if(is_null($script['condition']) || call_user_func($script['condition'], $handler)) {
wp_enqueue_script("plugin-placeholder/{$script['name']}", $script['path'], $script['dependencies'], PLUGIN_PLACEHOLDER_VERSION);

if($script['localize']) {
wp_localize_script("plugin-placeholder/{$script['name']}", $script['localize']['name'], $script['localize']['args']);
}
}
}
}


private static $instance = null;
private $scripts;
private $styles;
private $admin_scripts;
private $admin_styles;

private function __construct()
{
$this->scripts = [];
$this->styles = [];
$this->admin_scripts = [];
$this->admin_styles = [];

add_action('wp_enqueue_scripts', [$this, 'loadAssets'], 100);
add_action('admin_enqueue_scripts', [$this, 'loadAdminAssets'], 100);
}

// Clone not allowed
private function __clone()
{
}

public static function getInstance()
{
if (is_null(self::$instance)) {
self::$instance = new AssetsLoader();
}
return self::$instance;
}

public function addStyle(string $name, string $path, callable $condition = null, array $dependencies = [])
{
$this->styles[] = [
'name' => $name,
'path' => $path,
'condition' => $condition,
'dependencies' => $dependencies
];
}

public function addScript(string $name, string $path, callable $condition = null, array $dependencies = [], $localize = false)
{
$this->scripts[] = [
'name' => $name,
'path' => $path,
'condition' => $condition,
'dependencies' => $dependencies,
'localize' => $localize
];
}

public function addAdminStyle(string $name, string $path, callable $condition = null, array $dependencies = [])
{
$this->admin_styles[] = [
'name' => $name,
'path' => $path,
'condition' => $condition,
'dependencies' => $dependencies
];
}

public function addAdminScript(string $name, string $path, callable $condition = null, array $dependencies = [], $localize = false)
{
$this->admin_scripts[] = [
'name' => $name,
'path' => $path,
'condition' => $condition,
'dependencies' => $dependencies,
'localize' => $localize
];
}

public function loadAssets($handler)
{
foreach ($this->styles as $style) {
if (is_null($style['condition']) || call_user_func($style['condition'], $handler)) {
wp_enqueue_style("plugin-placeholder/{$style['name']}", $style['path'], $style['dependencies'], PLUGIN_PLACEHOLDER_VERSION);
}
}

foreach ($this->scripts as $script) {
if (is_null($script['condition']) || call_user_func($script['condition'], $handler)) {
wp_enqueue_script("plugin-placeholder/{$script['name']}", $script['path'], $script['dependencies'], PLUGIN_PLACEHOLDER_VERSION);

if ($script['localize']) {
wp_localize_script("plugin-placeholder/{$script['name']}", $script['localize']['name'], $script['localize']['args']);
}
}
}
}

public function loadAdminAssets($handler)
{
foreach ($this->admin_styles as $style) {
if (is_null($style['condition']) || call_user_func($style['condition'], $handler)) {
wp_enqueue_style("plugin-placeholder/{$style['name']}", $style['path'], $style['dependencies'], PLUGIN_PLACEHOLDER_VERSION);
}
}

foreach ($this->admin_scripts as $script) {
if (is_null($script['condition']) || call_user_func($script['condition'], $handler)) {
wp_enqueue_script("plugin-placeholder/{$script['name']}", $script['path'], $script['dependencies'], PLUGIN_PLACEHOLDER_VERSION);

if ($script['localize']) {
wp_localize_script("plugin-placeholder/{$script['name']}", $script['localize']['name'], $script['localize']['args']);
}
}
}
}
}
63 changes: 33 additions & 30 deletions Includes/BladeLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,37 @@

class BladeLoader
{
private static $instance = NULL;
private $blade;

private function __construct()
{
$this->blade = new Blade(PLUGIN_PLACEHOLDER_PATH . 'resources/views', PLUGIN_PLACEHOLDER_PATH . 'resources/cache');
}

// Clone not allowed
private function __clone()
{
}

public static function getInstance()
{
if (is_null(self::$instance)) {
self::$instance = new BladeLoader();
}
return self::$instance;
}

public function make_directive(string $name, callable $handler)
{
$this->blade->directive($name, $handler);
}

public function template($name, $args = [])
{
return $this->blade->render($name, $args);
}
private static $instance = null;
private $blade;

private function __construct()
{
$this->blade = new Blade(
PLUGIN_PLACEHOLDER_PATH . 'resources/views',
PLUGIN_PLACEHOLDER_PATH . 'resources/cache'
);
}

// Clone not allowed
private function __clone()
{
}

public static function getInstance()
{
if (is_null(self::$instance)) {
self::$instance = new BladeLoader();
}
return self::$instance;
}

public function makeDirective(string $name, callable $handler)
{
$this->blade->directive($name, $handler);
}

public function template($name, $args = [])
{
return $this->blade->render($name, $args);
}
}
56 changes: 28 additions & 28 deletions Includes/Loader.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
<?php

namespace PluginPlaceholder\Includes;

class Loader
{
protected $plugin_name;
protected $plugin_version;
protected $plugin_name;
protected $plugin_version;

public function __construct()
{
$this->plugin_version = defined('PLUGIN_PLACEHOLDER_VERSION') ? PLUGIN_PLACEHOLDER_VERSION : '1.0.0';
$this->plugin_name = 'plugin-placeholder';
$this->load_dependencies();
public function __construct()
{
$this->plugin_version = defined('PLUGIN_PLACEHOLDER_VERSION') ? PLUGIN_PLACEHOLDER_VERSION : '1.0.0';
$this->plugin_name = 'plugin-placeholder';
$this->loadDependencies();

add_action('plugins_loaded', [$this, 'load_plugin_textdomain']);
}
add_action('plugins_loaded', [$this, 'loadPluginTextdomain']);
}

private function load_dependencies()
{
foreach (glob(PLUGIN_PLACEHOLDER_PATH . 'Functionality/*.php') as $filename) {
$class_name = '\\PluginPlaceholder\Functionality\\'. basename($filename, '.php');
if (class_exists($class_name)) {
try {
new $class_name($this->plugin_name, $this->plugin_version);
}
catch (\Throwable $e) {
pb_log($e);
continue;
}
}
}
}
private function loadDependencies()
{
foreach (glob(PLUGIN_PLACEHOLDER_PATH . 'Functionality/*.php') as $filename) {
$class_name = '\\PluginPlaceholder\Functionality\\' . basename($filename, '.php');
if (class_exists($class_name)) {
try {
new $class_name($this->plugin_name, $this->plugin_version);
} catch (\Throwable $e) {
pb_log($e);
continue;
}
}
}
}

public function load_plugin_textdomain()
{
load_plugin_textdomain('plugin-placeholder', false, dirname(PLUGIN_PLACEHOLDER_BASENAME) . '/languages/');
}
public function loadPluginTextdomain()
{
load_plugin_textdomain('plugin-placeholder', false, dirname(PLUGIN_PLACEHOLDER_BASENAME) . '/languages/');
}
}
26 changes: 13 additions & 13 deletions Includes/Lyfecycle.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?php

namespace PluginPlaceholder\Includes;

class Lyfecycle
{
public static function activate()
{
do_action('PluginPlaceholder/setup');
}

public static function deactivate()
{
public static function activate()
{
do_action('PluginPlaceholder/setup');
}

public static function deactivate()
{
}

}

public static function uninstall()
{
do_action('PluginPlaceholder/cleanup');
}
public static function uninstall()
{
do_action('PluginPlaceholder/cleanup');
}
}
3 changes: 2 additions & 1 deletion React/apps.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?php

global $react_apps;
$react_apps = array();
$react_apps = [];
Loading

0 comments on commit 831aaa9

Please sign in to comment.