I built a custom WordPress plugin that sends Woocommerce purchase info to a CRM. The plugin works perfectly on localhost. But on the live site, whenever I click on the admin menu, I always get redirected to "No Update Required" page.
Here is my main plugin file:
/**
* Plugin Name: Woo Crm
* Description: Sends customer data to the CRM on purchase.
*/
if (!defined('ABSPATH')) {
echo 'I am a plugin I cannot do anything when called directly.';
exit;
}
// Config
define('PLUGIN_NAME', 'Woo Crm');
define('PLUGIN_SLUG', 'woo_crm');
define('PLUGIN_URL', plugin_dir_url(__FILE__));
define('PLUGIN_PATH', plugin_dir_path(__FILE__));
// Imports
require_once(PLUGIN_PATH . 'utils/utils.php');
require_once(PLUGIN_PATH . 'views/views.php');
require_once(PLUGIN_PATH . 'services/crm/crm.php');
require_once(PLUGIN_PATH . 'views/components/settings/settings.php');
class WooCrm
{
function __construct()
{
// Register Styles
add_action('admin_enqueue_scripts', array($this, 'register_styles'));
// Create Menu Page
add_action('admin_menu', array($this, 'plugin_setup_menu'));
// Add Settings Fields to Menu Page
add_action('admin_init', array('settings', 'init'));
// Woocommerce dynamic hook from Settings API
$hook = get_when_to_send_data_hook();
add_action($hook, array($this, 'woo_order_create_client'));
}
function woo_order_create_client($order_id)
{
// Create client logic
}
function plugin_setup_menu()
{
$icon_url = PLUGIN_URL . "public/images/dash-icon.png";
add_menu_page(__(PLUGIN_NAME, PLUGIN_SLUG), __(PLUGIN_NAME, PLUGIN_SLUG), 'manage_options', PLUGIN_SLUG, array('views', 'admin'), $icon_url);
}
function register_styles()
{
wp_register_style('woo_crm_admin', PLUGIN_URL . 'public/css/admin.css');
wp_enqueue_style('woo_crm_admin');
}
}
new WooCrm();
Any help would be highly appreciated.
I built a custom WordPress plugin that sends Woocommerce purchase info to a CRM. The plugin works perfectly on localhost. But on the live site, whenever I click on the admin menu, I always get redirected to "No Update Required" page.
Here is my main plugin file:
/**
* Plugin Name: Woo Crm
* Description: Sends customer data to the CRM on purchase.
*/
if (!defined('ABSPATH')) {
echo 'I am a plugin I cannot do anything when called directly.';
exit;
}
// Config
define('PLUGIN_NAME', 'Woo Crm');
define('PLUGIN_SLUG', 'woo_crm');
define('PLUGIN_URL', plugin_dir_url(__FILE__));
define('PLUGIN_PATH', plugin_dir_path(__FILE__));
// Imports
require_once(PLUGIN_PATH . 'utils/utils.php');
require_once(PLUGIN_PATH . 'views/views.php');
require_once(PLUGIN_PATH . 'services/crm/crm.php');
require_once(PLUGIN_PATH . 'views/components/settings/settings.php');
class WooCrm
{
function __construct()
{
// Register Styles
add_action('admin_enqueue_scripts', array($this, 'register_styles'));
// Create Menu Page
add_action('admin_menu', array($this, 'plugin_setup_menu'));
// Add Settings Fields to Menu Page
add_action('admin_init', array('settings', 'init'));
// Woocommerce dynamic hook from Settings API
$hook = get_when_to_send_data_hook();
add_action($hook, array($this, 'woo_order_create_client'));
}
function woo_order_create_client($order_id)
{
// Create client logic
}
function plugin_setup_menu()
{
$icon_url = PLUGIN_URL . "public/images/dash-icon.png";
add_menu_page(__(PLUGIN_NAME, PLUGIN_SLUG), __(PLUGIN_NAME, PLUGIN_SLUG), 'manage_options', PLUGIN_SLUG, array('views', 'admin'), $icon_url);
}
function register_styles()
{
wp_register_style('woo_crm_admin', PLUGIN_URL . 'public/css/admin.css');
wp_enqueue_style('woo_crm_admin');
}
}
new WooCrm();
Any help would be highly appreciated.
Share Improve this question edited Mar 7, 2021 at 5:38 Roshan Chapagain asked Mar 5, 2021 at 6:25 Roshan ChapagainRoshan Chapagain 1231 gold badge1 silver badge6 bronze badges1 Answer
Reset to default 0The bug was caused because of sloppy code design. Which lead to using too many require
.
Changing
function plugin_setup_menu()
{
$icon_url = PLUGIN_URL . "public/images/dash-icon.png";
add_menu_page(__(PLUGIN_NAME, PLUGIN_SLUG), __(PLUGIN_NAME, PLUGIN_SLUG), 'manage_options', PLUGIN_SLUG, array('views', 'admin'), $icon_url);
}
to
function plugin_setup_menu()
{
$icon_url = PLUGIN_URL . "public/images/dash-icon.png";
add_menu_page(PLUGIN_NAME, PLUGIN_NAME, 'manage_options', PLUGIN_SLUG, array($this,'admin_menu_view'), $icon_url);
}
and adding another method
function admin_menu_view()
{
include_once PLUGIN_PATH . 'views/admin.php';
}
fixed the issue for me.