From be1fc1852584b0895d8768a2e5657af2cf312e1e Mon Sep 17 00:00:00 2001 From: Ramya krishna Date: Mon, 7 Oct 2024 14:48:39 +0530 Subject: [PATCH] adding install, activate && learn more logic --- includes/Solutions.php | 5 ++++- includes/js/myPluginsTools.js | 26 ++++++++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/includes/Solutions.php b/includes/Solutions.php index 583264b..c5cd81d 100644 --- a/includes/Solutions.php +++ b/includes/Solutions.php @@ -109,7 +109,10 @@ public static function my_plugins_and_tools_tab_enqueue_assets() { } wp_enqueue_style( 'nfd_myplugin_solutions_css', NFD_SOLUTIONS_PLUGIN_URL . 'vendor/newfold-labs/wp-module-solutions/includes/css/myPluginsTools.css', array(), '1.0' ); wp_enqueue_script('nfd_myplugin_solutions_js', NFD_SOLUTIONS_PLUGIN_URL . 'vendor/newfold-labs/wp-module-solutions/includes/js/myPluginsTools.js', array(), '1.0', true ); - + wp_localize_script( 'nfd_myplugin_solutions_js', 'pluigin_details', array( + 'installed_plugins' => get_plugins(), + 'active_plugins' => get_option( 'active_plugins' ) + ) ); } } diff --git a/includes/js/myPluginsTools.js b/includes/js/myPluginsTools.js index 5bdcee5..48902d5 100644 --- a/includes/js/myPluginsTools.js +++ b/includes/js/myPluginsTools.js @@ -16,23 +16,37 @@ class MyPluginTools { .then((response) => response.json()).then(res => { const pluginsData = res?.data?.entitlements?.filter(data => data?.type === 'plugin' ); - - console.log(pluginsData) - this.setUpContainer(pluginsData); - this.entitlements_list = res?.data; + const installedPlugins = Object.keys(pluigin_details?.installed_plugins) + const pluginWithStatus = pluginsData.map(val => ({ + ...val, + isInstalled: installedPlugins?.includes( val.basename ), + isActive: pluigin_details?.active_plugins?.includes( val.basename ), + nonce: pluigin_details?.nonce + })) + this.setUpContainer(pluginWithStatus); }) }) } + getElementByStatus( isActive, isInstalled, pluginData ) { + if( isActive && isInstalled ){ + return `${pluginData?.cta?.text}`; + }else if ( isInstalled ){ + return `Activate`; + }else { + return `Install`; + } + } + buildPluginsBlock( pluginData ) { return `

${pluginData?.name}

- ${pluginData?.cta?.text} + ${this.getElementByStatus( pluginData?.isActive, pluginData?.isInstalled, pluginData )}

${pluginData?.description}

@@ -50,4 +64,4 @@ class MyPluginTools { } } -const pluginList = new MyPluginTools(); \ No newline at end of file +const pluginList = new MyPluginTools();