[wp-trac] [WordPress Trac] #31636: 4.2-beta1 - PHP warning when enqueuing script on specific pages only
WordPress Trac
noreply at wordpress.org
Fri Mar 13 19:01:39 UTC 2015
#31636: 4.2-beta1 - PHP warning when enqueuing script on specific pages only
---------------------------+-----------------------------
Reporter: harmr | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Script Loader | Version: trunk
Severity: normal | Keywords:
Focuses: |
---------------------------+-----------------------------
Within my plugin I use the following code to enqueue scripts only on
specific pages:
{{{
[...]
$page3 = add_submenu_page('leafletmapsmarker_markers', $menu_name . ' - '
. __('add/edit marker', 'lmm'), '<img src="' . LEAFLET_PLUGIN_URL_ENC .
'inc/img/icon-menu-add' . $mp6_icon . '.png"> ' . __('Add new marker',
'lmm'), $lmm_options[ 'capabilities_edit' ], 'leafletmapsmarker_marker',
array(&$this, 'lmm_marker') );
[...]
add_action('admin_print_scripts-'.$page3, array(&$this,
'lmm_admin_enqueue_scripts_jquerydatepicker'));
[...]
function lmm_admin_enqueue_scripts_jquerydatepicker() {
$plugin_version = get_option('leafletmapsmarker_version_pro');
wp_enqueue_script( array ( 'jquery', 'jquery-ui-tabs','jquery-ui-
datepicker','jquery-ui-slider' ) );
wp_enqueue_script( 'jquery-ui-timepicker-addon',
LEAFLET_PLUGIN_URL_ENC . 'inc/js/jquery-ui-timepicker-addon.js',
array('jquery', 'jquery-ui-tabs','jquery-ui-datepicker'),
$plugin_version);
}
[...]
}}}
Since 4.2 I am getting the following PHP warning when accessing $page3
(=create new marker page):
{{{
WARNING: wp-includes/functions.wp-scripts.php:227 - explode() expects
parameter 2 to be string, array given
require_once('wp-admin/admin-header.php'), do_action('admin_print_scripts-
maps-marker-pro_page_leafletmapsmarker_marker'), call_user_func_array,
l4->lmm_admin_enqueue_scripts_jquerydatepicker, wp_enqueue_script, explode
}}}
I looked into the changed function.wp-scripts.php file to find out whats
wrong, but did not succeed:
{{{
function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver =
false, $in_footer = false ) {
$wp_scripts = wp_scripts();
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
$_handle = explode( '?', $handle );
if ( $src ) {
$wp_scripts->add( $_handle[0], $src, $deps, $ver );
}
if ( $in_footer ) {
$wp_scripts->add_data( $_handle[0], 'group', 1 );
}
$wp_scripts->enqueue( $handle );
}
}}}
The line
{{{
$_handle = explode( '?', $handle );
}}}
is responsible for creating this PHP warning.
Unfortunately I do not have an idea how to prevent this within my code.
Could a solution be to change that code into
{{{
$_handle = !is_array($_handle) : explode( '?', $handle ) ? $handle;
}}}
As I try not to generate any php error log entries with my plugin, any
help here would be really appreciated!
--
Ticket URL: <https://core.trac.wordpress.org/ticket/31636>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list