55 * @author Darren Cooney
66 * @link https://github.com/dcooney/wordpress-plugin-installer
77 * @link https://connekthq.com
8- * @version 1.0
8+ * @version 1.0.2
99 * @package Indieweb
1010 */
1111
@@ -20,9 +20,9 @@ class Plugin_Installer {
2020 * Start the installer.
2121 */
2222 public function start () {
23- \add_action ( 'admin_enqueue_scripts ' , array ( $ this , 'enqueue_scripts ' ) ); // Enqueue scripts and Localize.
24- \add_action ( 'wp_ajax_cnkt_plugin_installer ' , array ( $ this , 'cnkt_plugin_installer ' ) ); // Install plugin.
25- \add_action ( 'wp_ajax_cnkt_plugin_activation ' , array ( $ this , 'cnkt_plugin_activation ' ) ); // Activate plugin.
23+ \add_action ( 'cnkt_installer_enqueue_scripts ' , array ( $ this , 'enqueue_scripts ' ) );
24+ \add_action ( 'wp_ajax_cnkt_plugin_installer ' , array ( $ this , 'cnkt_plugin_installer ' ) );
25+ \add_action ( 'wp_ajax_cnkt_plugin_activation ' , array ( $ this , 'cnkt_plugin_activation ' ) );
2626 }
2727
2828 /**
@@ -31,6 +31,8 @@ public function start() {
3131 * @param array $plugins Array of plugin data.
3232 */
3333 public static function init ( $ plugins ) {
34+ // Add the required plugin scripts.
35+ \do_action ( 'cnkt_installer_enqueue_scripts ' );
3436 ?>
3537
3638 <div class="cnkt-plugin-installer">
@@ -63,10 +65,12 @@ public static function init( $plugins ) {
6365 )
6466 );
6567
66- if ( ! \is_wp_error ( $ api ) ) { // Confirm error free.
68+ if ( ! \is_wp_error ( $ api ) ) {
6769
6870 $ main_plugin_file = self ::get_plugin_file ( $ plugin ['slug ' ] ); // Get main plugin file.
69- if ( self ::check_file_extension ( $ main_plugin_file ) ) { // Check file extension.
71+
72+ // Plugin is installed.
73+ if ( $ main_plugin_file ) {
7074 if ( \is_plugin_active ( $ main_plugin_file ) ) {
7175 // Plugin activation, confirmed!
7276 $ button_classes = 'button disabled ' ;
@@ -299,26 +303,11 @@ public static function get_plugin_file( $plugin_slug ) {
299303 return null ;
300304 }
301305
302- /**
303- * A helper to check file extension.
304- *
305- * @param string $filename The filename of the plugin.
306- * @return bool True if PHP file, false otherwise.
307- */
308- public static function check_file_extension ( $ filename ) {
309- if ( substr ( strrchr ( $ filename , '. ' ), 1 ) === 'php ' ) {
310- // Has .php extension.
311- return true ;
312- } else {
313- return false ;
314- }
315- }
316-
317306 /**
318307 * Enqueue admin scripts and scripts localization.
319308 */
320309 public function enqueue_scripts () {
321- \wp_enqueue_script ( 'plugin-installer ' , CNKT_INSTALLER_PATH . 'static/js/installer.js ' , array ( 'jquery ' ), Indieweb:: $ version , true );
310+ \wp_enqueue_script ( 'plugin-installer ' , CNKT_INSTALLER_PATH . 'static/js/installer.js ' , array ( 'jquery ' ), INDIEWEB_VERSION , true );
322311 \wp_localize_script (
323312 'plugin-installer ' ,
324313 'cnkt_installer_localize ' ,
@@ -332,11 +321,6 @@ public function enqueue_scripts() {
332321 )
333322 );
334323
335- \wp_enqueue_style ( 'plugin-installer ' , CNKT_INSTALLER_PATH . 'static/css/installer.css ' , array (), Indieweb:: $ version );
324+ \wp_enqueue_style ( 'plugin-installer ' , CNKT_INSTALLER_PATH . 'static/css/installer.css ' , array (), INDIEWEB_VERSION );
336325 }
337326}
338-
339-
340- // Initialize.
341- $ indieweb_plugin_installer = new Plugin_Installer ();
342- $ indieweb_plugin_installer ->start ();
0 commit comments