开发者 | coffee2code |
---|---|
更新时间 | 2021年5月8日 16:07 |
捐献地址: | 去捐款 |
PHP版本: | 4.9 及以上 |
WordPress版本: | 5.7 |
版权: | GPLv2 or later |
版权网址: | 版权信息 |
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
add-admin-javascript.zip
inside the plugins directory for your site (typically wp-content/plugins/
)It is certainly possible that you can put yourself in an unfortunate position by supplying JavaScript that could render the admin (in whole or in part) inoperable or hidden, making it seeminly impossible to fix or revert your changes. Fortunately, there are a number of approaches you can take to correct the problem.
The recommended approach is to visit the URL for the plugin's settings page, but appended with a special query parameter to disable the output of its JavaScript. The plugin's settings page would typically be at a URL like https://example.com/wp-admin/options-general.php?page=add-admin-javascript%2Fadd-admin-javascript.php
. Append &c2c-no-js=1
to that, so that the URL is https://example.com/wp-admin/options-general.php?page=add-admin-javascript%2Fadd-admin-javascript.php&c2c-no-js=1
(obviously change example.com with the domain name for your site).
There are other approaches you can use, though they require direct database or server filesystem access:
wp-config.php
file, define a constant to disable output of the plugin-defined JavaScript: define( 'C2C_ADD_ADMIN_JAVASCRIPT_DISABLED', true );
. You can then visit the site's admin. Just remember to remove that line after you've fixed the JavaScript (or at least change "true" to "false"). This is an alternative to the query parameter approach described above, though it persists while the constant remains defined. There will be an admin notice on the plugin's setting page to alert you to the fact that the constant is defined and effectively disabling the plugin from adding any JavaScript.c2c_add_admin_javascript
and delete that row. The settings you saved for the plugin will be deleted and it will be like you've installed the plugin for the first time.wp option delete c2c_add_admin_javascript
Yes, via the "Admin JavaScript Files" input field on the plugin's settings page.
No, not presently. At least not directly. By default, the JavaScript is added to every admin page on the site.
However, you can preface your selectors with admin page specific class(es) on 'body' tag to ensure CSS only applies on certain admin pages. (e.g. jQuery('body.index-php h2').hide();
).
Or, you can hook all the plugin's filters and determine the current admin page content to decide whether the respective hook argument should be returned (and thus output) or not.
No, not presently. At least not directly. By default, the JavaScript is added for any user that can enter the admin section of the site. You can hook all the plugin's filters and determine the current user to decide whether the respective hook argument should be returned (and thus output) for the user or not.
The plugin's syntax highlighting of JavaScript (available as of WP 4.9) honors the built-in setting for whether syntax highlighting should be enabled or not. To disable syntax highlighting, go to your profile page. Next to "Syntax Highlighting", click the checkbox labeled "Disable syntax highlighting when editing code". Note that this checkbox disables syntax highlighting throughout the admin interface and not just specifically for the plugin's settings page.
Yes.
c2c_{PluginName}_Plugin_051
to c2c_Plugin_060
get_c2c_string()
as a getter for translated stringsget_c2c_string()
whitelist_options()
to allowed_options()
add_allowed_options()
instead of deprecated add_option_whitelist()
for WP 5.5+allowed_options
filter instead of deprecated whitelist_options
for WP 5.5+is_wp_version_cmp()
and get_c2c_string()
)is_wp_version_cmp()
as a utility to compare current WP version against a given WP versioncontextual_help()
to be easier to read, and correct function docblocksnumber_format_i18n()
to format integer value within input fieldreadme_url()
to refer to plugin's readme.txt on plugins.svn.wordpress.orgadd_codemirror()
tests/
top-level directorynumber_format_i18n()
to format integer value within input fieldreadme_url()
to refer to plugin's readme.txt on plugins.svn.wordpress.orgphpunit/
to house all files related to unit testingbin/
to phpunit/bin/
tests/bootstrap.php
to phpunit/
tests/
to phpunit/tests/
phpunit.xml
to phpunit.xml.dist
per best practicesprintf()
rather than using string concatenationoptions_page_description()
tearDown()
test_turn_on_admin()
until just before first needed now that other tests can run before it