Plugin / Add Admin JavaScript

Scott Reilly

Description

Description

Ever want to introduce custom dynamic functionality to your WordPress admin pages and otherwise harness the power of JavaScript? Any modification you may want to do with JavaScript can be facilitated via this plugin.

Using this plugin you’ll easily be able to define additional JavaScript (inline and/or by URL) to be added to all administration pages. You can define JavaScript to appear inline in the admin head, admin footer (recommended), or in the admin footer within a jQuery jQuery(document).ready(function($)) {} section, or reference JavaScript files to be linked in the page header. The referenced JavaScript files will appear in the admin head first, listed in the order defined in the plugin’s settings. Then any inline admin head JavaScript is added to the admin head. All values can be filtered for advanced customization (see Filters section).

Links: Plugin Homepage | Plugin Directory Page | GitHub | Author Homepage

Hooks

The plugin exposes four filters for hooking. Typically, these customizations would be put into your active theme’s functions.php file, or used by another plugin.

c2c_add_admin_js_files (filter)

The ‘c2c_add_admin_js_files’ filter allows programmatic modification of the list of JavaScript files to enqueue in the admin.

Arguments:

  • $files (array): Array of JavaScript files.

Example:

/**
 * Adds a JavaScript file to be enqueued in the WP admin.
 *
 * @param array $files Array of files.
 * @return array
 */
function my_admin_js_files( $files ) {
    $files[] = 'http://ajax.googleapis.com/ajax/libs/yui/2.8.1/build/yuiloader/yuiloader-min.js';
    return $files;
}
add_filter( 'c2c_add_admin_js_files', 'my_admin_js_files' );

c2c_add_admin_js_head (filter)

The ‘c2c_add_admin_js_head’ filter allows customization of the JavaScript that should be added directly to the admin page head.

Arguments:

  • $js (string): JavaScript code (without <script> tags).

Example:

/**
 * Adds JavaScript code to be added to the admin page head.
 *
 * @param string $js JavaScript code.
 * @return string
 */
function my_add_head_js( $js ) {
    $js .= "alert('Hello');";
    return $js;
}
add_filter( 'c2c_add_admin_js_head', 'my_add_head_js' );

c2c_add_admin_js_footer (filter)

The ‘c2c_add_admin_js_footer’ filter allows customization of the JavaScript that should be added directly to the admin footer.

Arguments:

  • $js (string): JavaScript code (without <script> tags).

Example:

/**
 * Adds JavaScript code to be added to the admin footer.
 *
 * @param string $js JavaScript code.
 * @return string
 */
function my_add_footer_js( $js ) {
    $js .= "alert('Hello');";
    return $js;
}
add_filter( 'c2c_add_admin_js_footer', 'my_add_footer_js' );

c2c_add_admin_js_jq (filter)

The ‘c2c_add_admin_js_jq’ filter allows customization of the JavaScript that should be added directly to the admin footer within a jQuery document ready function.

Arguments:

  • $jq_js (string): JavaScript code (without <script> tags or jQuery document ready function).

Example:

/**
 * Adds jQuery code to be added to the admin footer.
 *
 * @param string $jq_js jQuery code.
 * @return string
 */
function my_add_jq( $js_jq ) {
    $js_jq .= "$('.hide_me').hide();";
    return $js_jq;
}
add_filter( 'c2c_add_admin_js_jq', 'my_add_jq' );

Ratings

4.8
4 reviews

Rating breakdown

Details Information

Version

1.7

First Released

19 Nov, 2011

Total Downloads

17,347

Wordpress Version

4.7 or higher

Tested up to:

5.1.3

Require PHP Version:

-

Tags

Contributors

Languages

The plugin hasn't been transalated in any language other than English.

DIRECTORY DISCLAIMER

The information provided in this THEME/PLUGIN DIRECTORY is made available for information purposes only, and intended to serve as a resource to enable visitors to select a relevant theme or plugin. wpSocket gives no warranty of any kind, express or implied with regard to the information, including without limitation any warranty that the particular theme or plugin that you select is qualified on your situation.

The information in the individual theme or plugin displayed in the Directory is provided by the owners and contributors themselves. wpSocket gives no warranty as to the accuracy of the information and will not be liable to you for any loss or damage suffered by you as a consequence of your reliance on the information.

Links to respective sites are offered to assist in accessing additional information. The links may be outdated or broken. Connect to outside sites at your own risk. The Theme/Plugin Directory does not endorse the content or accuracy of any listing or external website.

While information is made available, no guarantee is given that the details provided are correct, complete or up-to-date.

wpSocket is not related to the theme or plugin, and also not responsible and expressly disclaims all liability for, damages of any kind, arising out of the use, reference to, or reliance on, any information or business listed throughout our site.

Keep Leading Your Followers!
Share it for them.