Forums

Admin Enque for JQuery in custom Admin Page gives error (2 posts)

  1. NNR01
    Member
    Posted 4 months ago #

    Hi all,
    WP v3.3.1
    'Fatal error: Call to undefined function admin_register_script() in ...'

    Frustrated beyond belief.
    I've been trying to load and enqueue JQuery for 8/9 days now into an admin custom page (got nothing to do with posts,blogs etc, purely custom maint of db files for fast food sandwich outlet) but no joy.just the error.

    No matter what I find in the codex or other forums, I have no success.even tried an init.php and edited a Clean install's theme files header files to

    <?php wp_enqueue_script("jquery"); ?>
    
    wp_head();
    ?>
    
    </head>

    overview:
    I am attempting to use jquery for a modal dialog form (to edit /insert data to a custom table in the wp_db)
    But this from inside the admin area, (from a custom TopLevel menu's sub menu.)

    This is my primary page beneath, which creates the TopLevel menu and submenu(s)...All fine here

    also, ..No extra css or anything, just the basics for functioanlity for now.
    and the attempt to use jquery (specifically dialog-modal) in my admin sub menu pages.
    But that means getting jquery registered and enqueued successfully.

    <?php
    /*
    Plugin Name: SB RestaurantMenu
    etc etc...*/
    
    //add script to head of website //tried add_action('admin_init', 'register_my_script2'); as well,..same problem
    add_action('init', 'register_my_script2');
    
    function register_my_script2() {
        wp_deregister_script('jquery');
        admin_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js');
    //3rd param of reigister scripts : $deps = jquery-ui-dialog : /wp-includes/js/jquery/ui/jquery.ui.dialog.min.js
        admin_enqueue_script( 'jquery' );
    
    }
    
    // Hook for adding SB admin menus
    add_action('admin_menu', 'Add_SBMenu_Pages');
    
    // action function for above hook
    function Add_SBMenu_Pages() {
         add_menu_page('Page title', 'SandwichBaron', 'manage_options', 'my-top-level-handle', 'fn_SBMenus_page');
         add_submenu_page( 'my-top-level-handle', 'Page title', 'Branch Maintenance', 'manage_options', 'my-
    
    submenu-handle', 'fn_SB_Branches_Menus_page');
    }
    
    unction fn_SBMenus_page() {
        include('SBBranchMenusMaint.php');   
    
    "</h2>";
    }
    
    function fn_SB_Branches_Menus_page() {
       include('SBBranchMaint.php');
    }
    
    ?>
  2. NNR01
    Member
    Posted 4 months ago #

    The answer is, ..Most admin sections already auto enqueue Jquery, so no need to do it manually, ..or You can deregister it first then manually register it.

    Also if you require JQuery UI in Admin pages, be they Theme, Edit, Pages,Tools or in Custom (i.e. your own TopLevel menu), ...from admin_init, enqueue the UI core and whatever else. .. eg.

    add_action('admin_init', 'register_jquery_ui');
    function register_jquery_ui() {
         wp_enqueue_script( ‘jquery-ui-core’ );
         wp_enqueue_script( 'jquery-ui-dialog' );
    }

    Thanks David at Presscoders.com

Reply

You must log in to post.

About this Topic