Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚀 enhance: StoreGrowth listed to the admin setup wizard recommendation plugins #2512

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Binary file added assets/images/store-growth-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
129 changes: 129 additions & 0 deletions includes/Admin/RecommendedPlugins.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?php

namespace WeDevs\Dokan\Admin;

/**
* Recommended Plugins Class.
*
* @since DOKAN_SINCE
*/
class RecommendedPlugins {

/**
* Array of Recommended Plugins.
*
* @var array
*/
protected array $plugins;

/**
* Class Constructor.
*
* @since DOKAN_SINCE
*/
public function __construct() {
$this->plugins = [
[
'type' => 'store_growth',
'title' => __( 'StoreGrowth', 'dokan-lite' ),
'description' => __( 'Best WooCommerce Marketing Solution!', 'dokan-lite' ),
'img_url' => DOKAN_PLUGIN_ASSEST . '/images/store-growth-logo.png',
'img_alt' => __( 'StoreGrowth logo', 'dokan-lite' ),
'plugins' => [
[
'name' => __( 'StoreGrowth', 'dokan-lite' ),
'slug' => 'storegrowth-sales-booster',
'basename' => 'storegrowth-sales-booster/storegrowth-sales-booster.php',
],
],
],
[
'type' => 'wemail',
'title' => __( 'weMail', 'dokan-lite' ),
'description' => __( 'Simplified Email Marketing Solution for WordPress!', 'dokan-lite' ),
'img_url' => DOKAN_PLUGIN_ASSEST . '/images/wemail-logo.png',
'img_alt' => __( 'weMail logo', 'dokan-lite' ),
'plugins' => [
[
'name' => __( 'weMail', 'dokan-lite' ),
'slug' => 'wemail',
'basename' => 'wemail/wemail.php',
],
],
],
[
'type' => 'wc_conversion_tracking',
'title' => __( 'WooCommerce Conversion Tracking', 'dokan-lite' ),
'description' => __( 'Track conversions on your WooCommerce store like a pro!', 'dokan-lite' ),
'img_url' => DOKAN_PLUGIN_ASSEST . '/images/wc-conversion-tracking-logo.png',
'img_alt' => __( 'WooCommerce Conversion Tracking logo', 'dokan-lite' ),
'plugins' => [
[
'name' => __( 'WooCommerce Conversion Tracking', 'dokan-lite' ),
'slug' => 'woocommerce-conversion-tracking',
'basename' => 'woocommerce-conversion-tracking/conversion-tracking.php',
],
],
],
[
'type' => 'texty',
'title' => __( 'Texty', 'dokan-lite' ),
'description' => __( 'SMS Notification for WordPress, WooCommerce, Dokan and more!', 'dokan-lite' ),
'img_url' => DOKAN_PLUGIN_ASSEST . '/images/texty-logo.png',
'img_alt' => __( 'Texty logo', 'dokan-lite' ),
'plugins' => [
[
'name' => __( 'Texty', 'dokan-lite' ),
'slug' => 'texty',
'basename' => 'texty/texty.php',
],
],
],
];
}

/**
* Get All Enlisted Plugins.
*
* @since DOKAN_SINCE
*
* @return array
*/
protected function get_enlisted_plugins(): array {
return apply_filters( 'dokan_recommended_plugins_list', $this->plugins );
}

/**
* Is Plugin Active.
*
* @since DOKAN_SINCE
*
* @param string $basename
*
* @return bool
*/
protected function is_active( string $basename ): bool {
return apply_filters( 'dokan_recommended_plugin_is_active', is_plugin_active( $basename ), $basename );
}

/**
* Get List of Recommended Inactive Plugins.
*
* @since DOKAN_SINCE
*
* @return array
*/
public function get(): array {
$enlisted_plugins = $this->get_enlisted_plugins();

$recommended_plugins = array_filter(
$enlisted_plugins,
function ( $plugin ) {
return isset( $plugin['plugins'][0]['basename'] ) && ! $this->is_active( $plugin['plugins'][0]['basename'] );
}
);

error_log( print_r( $recommended_plugins, 1 ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Remove debug error_log statement.

Production code should not contain debug logging statements.

-        error_log( print_r( $recommended_plugins, 1 ) );

return apply_filters( 'dokan_recommended_inactive_plugins', $recommended_plugins );
}
}
89 changes: 26 additions & 63 deletions includes/Admin/SetupWizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -699,58 +699,10 @@ public function dokan_setup_recommended() {
<ul class="recommended-step">
<?php
if ( $this->user_can_install_plugin() ) {
if ( ! $this->is_wc_conversion_tracking_active() ) {
$this->display_recommended_item(
[
'type' => 'wc_conversion_tracking',
'title' => __( 'WooCommerce Conversion Tracking', 'dokan-lite' ),
'description' => __( 'Track conversions on your WooCommerce store like a pro!', 'dokan-lite' ),
'img_url' => DOKAN_PLUGIN_ASSEST . '/images/wc-conversion-tracking-logo.png',
'img_alt' => __( 'WooCommerce Conversion Tracking logo', 'dokan-lite' ),
'plugins' => [
[
'name' => __( 'WooCommerce Conversion Tracking', 'dokan-lite' ),
'slug' => 'woocommerce-conversion-tracking',
],
],
]
);
}
$recommended_plugins = new RecommendedPlugins();

if ( ! $this->is_wemail_active() ) {
$this->display_recommended_item(
[
'type' => 'wemail',
'title' => __( 'weMail', 'dokan-lite' ),
'description' => __( 'Simplified Email Marketing Solution for WordPress!', 'dokan-lite' ),
'img_url' => DOKAN_PLUGIN_ASSEST . '/images/wemail-logo.png',
'img_alt' => __( 'weMail logo', 'dokan-lite' ),
'plugins' => [
[
'name' => __( 'weMail', 'dokan-lite' ),
'slug' => 'wemail',
],
],
]
);
}

if ( ! $this->is_texty_active() ) {
$this->display_recommended_item(
[
'type' => 'texty',
'title' => __( 'Texty', 'dokan-lite' ),
'description' => __( 'SMS Notification for WordPress, WooCommerce, Dokan and more', 'dokan-lite' ),
'img_url' => DOKAN_PLUGIN_ASSEST . '/images/texty-logo.png',
'img_alt' => __( 'Texty logo', 'dokan-lite' ),
'plugins' => [
[
'name' => __( 'Texty', 'dokan-lite' ),
'slug' => 'texty',
],
],
]
);
foreach ( $recommended_plugins->get() as $plugin ) {
$this->display_recommended_item( $plugin );
}
}
?>
Expand All @@ -774,10 +726,22 @@ public function dokan_setup_recommended() {
public function dokan_setup_recommended_save() {
check_admin_referer( 'dokan-setup' );

$setup_store_growth = isset( $_POST['setup_store_growth'] ) && 'yes' === sanitize_text_field( wp_unslash( $_POST['setup_store_growth'] ) );
$setup_wc_conversion_tracking = isset( $_POST['setup_wc_conversion_tracking'] ) && 'yes' === sanitize_text_field( wp_unslash( $_POST['setup_wc_conversion_tracking'] ) );
$setup_wemail = isset( $_POST['setup_wemail'] ) && 'yes' === sanitize_text_field( wp_unslash( $_POST['setup_wemail'] ) );
$setup_texty = isset( $_POST['setup_texty'] ) && 'yes' === sanitize_text_field( wp_unslash( $_POST['setup_texty'] ) );

if ( $setup_store_growth && ! $this->is_store_growth_active() ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Pls also refactor this section so that we can handle it dynamically.
  • Check the current_user_can( 'manage_woocommerce' ) before the install.

$this->install_plugin(
'storegrowth-sales-booster',
[
'name' => __( 'StoreGrowth', 'dokan-lite' ),
'repo-slug' => 'storegrowth-sales-booster',
'file' => 'storegrowth-sales-booster.php',
]
);
}

if ( $setup_wc_conversion_tracking && ! $this->is_wc_conversion_tracking_active() ) {
$this->install_plugin(
'woocommerce-conversion-tracking',
Expand Down Expand Up @@ -891,21 +855,20 @@ protected function should_show_recommended_step() {
return false;
}

if ( $this->is_wc_conversion_tracking_active() ) {
return false;
}

if ( $this->is_wemail_active() ) {
return false;
}

if ( $this->is_texty_active() ) {
return false;
}

return true;
}

/**
* Check if StoreGrowth is active or not.
*
* @since DOKAN_SINCE
*
* @return bool
*/
protected function is_store_growth_active() {
return is_plugin_active( 'storegrowth-sales-booster/storegrowth-sales-booster.php' );
}

/**
* Check if WC Conversion Tracking is active or not
*
Expand Down
Loading