Skip to content

Commit

Permalink
Making it work
Browse files Browse the repository at this point in the history
  • Loading branch information
officiallygod committed Oct 10, 2024
1 parent ac8d961 commit 7093f12
Show file tree
Hide file tree
Showing 16 changed files with 522 additions and 70 deletions.
13 changes: 0 additions & 13 deletions includes/WPAdmin/Listeners/DataAttrListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace NewfoldLabs\WP\Module\Installer\WPAdmin\Listeners;

use NewfoldLabs\WP\Module\Installer\Services\PluginInstaller;

/**
* Manages all the data-* listening related functionalities for the module.
*/
Expand Down Expand Up @@ -34,17 +32,6 @@ public function enqueue_data_attr_listener() {
true
);

wp_add_inline_script(
'nfd-installer-data-attr-listener',
'var nfdInstaller =' . wp_json_encode(
value: array(
'restUrl' => \get_home_url() . '/index.php?rest_route=',
'pluginInstallHash' => PluginInstaller::rest_get_plugin_install_hash(),
)
) . ';',
'before'
);

wp_enqueue_script( 'nfd-installer-data-attr-listener' );
}
}
Expand Down
62 changes: 62 additions & 0 deletions includes/WPAdmin/Listeners/InstallerListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace NewfoldLabs\WP\Module\Installer\WPAdmin\Listeners;

use NewfoldLabs\WP\Module\Installer\Services\PluginInstaller;

/**
* Manages all the installer enqueue related functionalities for the module.
*/
class InstallerListener {

/**
* Constructor for the Installer class.
*/
public function __construct() {
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_installer_script' ) );
}

/**
* Enqueues the installer script.
*
* @return void
*/
public function enqueue_installer_script() {
$asset_file = NFD_INSTALLER_BUILD_DIR . '/installer.asset.php';

if ( is_readable( $asset_file ) ) {

$asset = include $asset_file;

wp_register_script(
'nfd-installer-enqueue',
NFD_INSTALLER_BUILD_URL . '/installer.js',
array_merge( $asset['dependencies'], array() ),
$asset['version'],
true
);

wp_register_style(
'nfd-installer-enqueue',
NFD_INSTALLER_BUILD_URL . '/installer.css',
array(),
$asset['version']
);

wp_add_inline_script(
'nfd-installer-enqueue',
'var nfdInstaller =' . wp_json_encode(
value: array(
'restUrl' => \get_home_url() . '/index.php?rest_route=',
'pluginInstallHash' => PluginInstaller::rest_get_plugin_install_hash(),
)
) . ';',
'before'
);


wp_enqueue_script( 'nfd-installer-enqueue' );
wp_enqueue_style( 'nfd-installer-enqueue' );
}
}
}
2 changes: 2 additions & 0 deletions includes/WPAdmin/WPAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace NewfoldLabs\WP\Module\Installer\WPAdmin;

use NewfoldLabs\WP\Module\Installer\WPAdmin\Listeners\DataAttrListener;
use NewfoldLabs\WP\Module\Installer\WPAdmin\Listeners\InstallerListener;

/**
* Manages all the wp-admin related functionalities for the module.
Expand All @@ -13,5 +14,6 @@ class WPAdmin {
*/
public function __construct() {
new DataAttrListener();
new InstallerListener();
}
}
Loading

0 comments on commit 7093f12

Please sign in to comment.