Opened 7 years ago
Last modified 2 years ago
#41558 new enhancement
create a (reusable) wp_default_admin_scripts
Reported by: | drzraf | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 2.6 |
Component: | Administration | Keywords: | |
Focuses: | ui, administration | Cc: |
Description
I had to create an admin-like form in the frontend, for guests submitting content.
I needed to provide meta/post-box
, autocompletion
and needed media-views
, wp-color-picker
, ...
I thought wp_enqueue_script()
would do the trick... until I discovered the if(is_admin())
inside wp_default_scripts()
. I had no other choice than copy/pasting ~210 WP LoC in my own PHP files
Is there a really good reason for reserving all that cool client-side stuff to admin dashboard only?
plugin/themes developers may want to load and use it for good and having all that libs already registered by core is useful.
I suggest:
- moving all the admin-oriented script into
wp_default_admin_scripts()
which should be reusable (even if non-admin), and run it if (is_admin). - moving all the
localize()
corresponding to these admin scripts into anotherwp_default_admin_scripts_settings()
function somehow wrapped byif(! is_admin())
- Document how to correctly bootstrap the dashboard in the frontend and a couple of common gotchas of these scripts (like that ajax-dashboard-pingback feature forcefully pulled as JS-dependencies and which can't be stopped, ...)
Change History (4)
#3
@
7 years ago
1) to my knownledge $script->add()
just make scripts available without actually enqueing them
2) for wp_enqueue_script()
to work, scripts would have to be registered. They are not.
3) I do enqueue selectively. This is what I enqueue to get a roughly working dashboard-style page avaiable to the frontend (it's acf_form()
based):
foreach( [ 'thickbox', 'media-views', 'imgareaselect', 'colors', 'ie', 'utils', 'svg-painter', 'acf-global', 'wp-auth-check', 'acf-input', 'acf-pro-input', 'select2', 'acf-datepicker', 'acf-timepicker', 'buttons', 'wp-color-picker' ] as $s) { wp_enqueue_style($s); }
But still, I *had* to copy the 210 LoC of wp_default_admin_scripts
in a custom wp_enqueue_scripts
hook in order to get these styles actually added.
Can't you just enqueue default scripts listed in wp_enqueue_script() instead of loading every script that is loaded on admin screen?