Browse files

allow to remove jQuery from the admin panel if you already have jQuery

  • Loading branch information...
1 parent 76705ff commit 6d42819b699bde4b43d1bf426d0d4235d0c43656 @t1gr0u committed Mar 14, 2013
Showing with 24 additions and 2 deletions.
  1. +24 −2 wpsocialite.php
View
26 wpsocialite.php
@@ -73,8 +73,14 @@ public function init() {
load_plugin_textdomain('wpsocialite', false, dirname( plugin_basename(__FILE__) ).'/lang/');
if( WPSOCIALITE_LOADSCRIPTS && !is_admin() ) {
+ // do we need jQuery ?
+ $dependencyLib = array('jquery');
+ if ( get_option( 'wpsocialite_jquery' ) == true ) {
+ // no need of jquery
+ $dependencyLib = array();
+ }
- wp_enqueue_script('socialite-lib', plugin_dir_url(__FILE__).'Socialite/socialite.min.js', array('jquery'), '2.0', true);
+ wp_enqueue_script('socialite-lib', plugin_dir_url(__FILE__).'Socialite/socialite.min.js', $dependencyLib, '2.0', true);
wp_enqueue_script('wpsocialite', plugin_dir_url(__FILE__).'wpsocialite.js', array('socialite-lib'), '1.0', true);
$scripts = self::wpsocialite_list_network_options(null, null, null, null);
@@ -83,7 +89,7 @@ public function init() {
foreach ($scripts as $script){
if( isset($value[$script['slug']]) && $script['external_file'] !== false )
- wp_enqueue_script('socialite-'.$script['slug'].'', plugin_dir_url(__FILE__).'Socialite/extensions/'.$script['external_file'].'', array('jquery'), '1.0', true);
+ wp_enqueue_script('socialite-'.$script['slug'].'', plugin_dir_url(__FILE__).'Socialite/extensions/'.$script['external_file'].'', $dependencyLib, '1.0', true);
}
}
@@ -258,6 +264,22 @@ public function admin_init() {
register_setting( $option_group = 'discussion', $option_name = 'wpsocialite_mode' );
add_settings_field(
+ $id = 'wpsocialite_jquery',
+ $title = __('Remove jQuery','wpsocialite'),
+ $callback = array( $this, 'wpsocialite_checkbox' ),
+ $page = 'discussion',
+ $section = 'wpsocialite',
+ $args = array(
+ 'name' => 'wpsocialite_jquery',
+ 'description' => '',
+ 'options' => array(
+ '1' => _('Remove jQuery dependency from Socialite (it will confict, if you already have jQuery in your pages)'),
+ ),
+ )
+ );
+ register_setting( $option_group = 'discussion', $option_name = 'wpsocialite_jquery' );
+
+ add_settings_field(
$id = 'wpsocialite_excerpt',
$title = __('Apply to Excerpt','wpsocialite'),
$callback = array( $this, 'wpsocialite_checkbox' ),

4 comments on commit 6d42819

@tmort

Can you provide the code you are using to add jQuery in your other page? For example, is it located in the functions.php of your theme? I'm interested in what is causing the conflict.

@t1gr0u
Owner

Basically, one of our developers had hardcoded jQuery in the header of the template and pulled 1.8.2.
But your code was including a dependency with "wp_enqueue_script" which was pulling 1.7.4, so we had 2 versions, and all the jQuery plugins were installed on one version and not to be seen on the other.

@tmort

So the jQuery library that you had originally was hardcoded? The reason I ask is because Wordpress should only include one version of jQuery when the wp_enqueue_script function is used.

I'm concerned about adding an option to disable jQuery in the administration panel because it could directly break WPSocialite's functionality if someone where to accidentally enable it. Trying to make things as easy for the end user and avoid unnecessary support tickets.

What if you used the WPSOCIALITE_LOADSCRIPTS, setting it to false? You could then just load socialite.min.js and wpsocialite.js separately.

Another option would be to load the original jQuery library in question using the themes functions.php and the wp_enqueue_script function. Let me know your thoughts.

@t1gr0u
Owner

By default jQuery will be included, so it won't change how it works, until you tick the box, then it will include jQuery.
I do agree, it's hard to make things simple and easy to use as well as complicated.

I was also thinking to move WPSOCIALITE_LOADSCRIPTS and WPSOCIALITE_LOADSTYLES into the admin panel.

For me, a plugin should be all setup in the admin panel, no code changes, plug and play, but this is my view :)

Please sign in to comment.