最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Clicking custom plugin admin menu redirects to "No Update Required" on live site

programmeradmin1浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

The 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.

发布评论

评论列表(0)

  1. 暂无评论
ok 不同模板 switch ($forum['model']) { /*case '0': include _include(APP_PATH . 'view/htm/read.htm'); break;*/ default: include _include(theme_load('read', $fid)); break; } } break; case '10': // 主题外链 / thread external link http_location(htmlspecialchars_decode(trim($thread['description']))); break; case '11': // 单页 / single page $attachlist = array(); $imagelist = array(); $thread['filelist'] = array(); $threadlist = NULL; $thread['files'] > 0 and list($attachlist, $imagelist, $thread['filelist']) = well_attach_find_by_tid($tid); $data = data_read_cache($tid); empty($data) and message(-1, lang('data_malformation')); $tidlist = $forum['threads'] ? page_find_by_fid($fid, $page, $pagesize) : NULL; if ($tidlist) { $tidarr = arrlist_values($tidlist, 'tid'); $threadlist = well_thread_find($tidarr, $pagesize); // 按之前tidlist排序 $threadlist = array2_sort_key($threadlist, $tidlist, 'tid'); } $allowpost = forum_access_user($fid, $gid, 'allowpost'); $allowupdate = forum_access_mod($fid, $gid, 'allowupdate'); $allowdelete = forum_access_mod($fid, $gid, 'allowdelete'); $access = array('allowpost' => $allowpost, 'allowupdate' => $allowupdate, 'allowdelete' => $allowdelete); $header['title'] = $thread['subject']; $header['mobile_link'] = $thread['url']; $header['keywords'] = $thread['keyword'] ? $thread['keyword'] : $thread['subject']; $header['description'] = $thread['description'] ? $thread['description'] : $thread['brief']; $_SESSION['fid'] = $fid; if ($ajax) { empty($conf['api_on']) and message(0, lang('closed')); $apilist['header'] = $header; $apilist['extra'] = $extra; $apilist['access'] = $access; $apilist['thread'] = well_thread_safe_info($thread); $apilist['thread_data'] = $data; $apilist['forum'] = $forum; $apilist['imagelist'] = $imagelist; $apilist['filelist'] = $thread['filelist']; $apilist['threadlist'] = $threadlist; message(0, $apilist); } else { include _include(theme_load('single_page', $fid)); } break; default: message(-1, lang('data_malformation')); break; } ?>