• I am working on a photography portfolio for a client and need to deactivate Simple-Lightbox for mobile screens. This is the site: http://www.dianashearwood.com/behind-the-mall/

    I was successful in deactivating a jquery tooltip script using the following code in my functions.php file:

    require_once (dirname(__FILE__) . '/library/js/Mobile-Detect-2.8.11/Mobile_Detect.php');
    $detect = new Mobile_Detect;
    if ( $detect->isMobile() ) {
    function wpdocs_dequeue_script() {
    wp_dequeue_script( 'jquery-tooltip' );
    }
    add_action( 'wp_enqueue_scripts', 'wpdocs_dequeue_script', 100 );
    }

    So, to explain, the lightweight PHP class Mobile_Detect.php (http://mobiledetect.net/) is used to detect if the user agent is a tablet. Then I use a dequeue function to deactivate the script. This is possible because I have registered and enqueued the tooltip script in functions.php using:

    function load_scripts() {
    wp_register_script('jquery-tooltip', get_stylesheet_directory_uri() . '/library/js/jquery-tooltip.js', array('tooltip'), '1.0', false);
    wp_enqueue_script('jquery-tooltip');
    }
    add_action('wp_enqueue_scripts', 'load_scripts');

    I have looked hard into the Simple-Lightbox code to see where it enqueues the six scripts it puts in the footer (i.e. lib.core.js, lib.view.js, client.js, tag.item.js, tag.ui.js and handler.image.js), but I am unable to identify the id used in enqueuing them.

    I figured that the lib.core.js script might be the one to dequeue so I tried the following but it does not work:

    function wpdocs_dequeue_lightbox() {
    wp_dequeue_script( 'core' );
    }
    add_action( 'enqueue_client_files', 'wpdocs_dequeue_lightbox', 100 );

    Here is the code from a few files that seems to be involved in the enqueue scripts. Any help is greatly appreciated!

    =====

    In controller.php:

    /**
    	 * Declare client files (scripts, styles)
    	 * @uses parent::_client_files()
    	 * @return void
    	 */
    	protected function _client_files($files = null) {
    		$js_path = 'client/js/';
    		$js_path .= ( SLB_DEV ) ? 'dev' : 'prod';
    		$files = array (
    			'scripts' => array (
    				'core'			=> array (
    					'file'		=> "$js_path/lib.core.js",
    					'deps'		=> 'jquery',
    					'enqueue'	=> false,
    					'in_footer'	=> true,
    				),
    				'view'			=> array (
    					'file'		=> "$js_path/lib.view.js",
    					'deps'		=> array('[core]'),
    					'context'	=> array( array('public', $this->m('is_request_valid')) ),
    					'in_footer'	=> true,
    				),
    			),
    			'styles' => array (
    				'core'			=> array (
    					'file'		=> 'client/css/app.css',
    					'context'	=> array('public'),
    				)
    			)
    		);
    		parent::_client_files($files);
    	}

    In class.component.php:

    /**
    	 * Enqueue files in client
    	 * @param string $type (optional) Type of file to load (singular) (Default: All client file types)
    	 */
    	public function enqueue_client_files($type = null) {
    		if ( empty($type) ) {
    			$type = array ( 'script', 'style');
    		}
    		if ( !is_array($type) ) {
    			$type = array ( $type );
    		}
    		foreach ( $type as $t ) {
    			$m = (object) array (
    				'get'		=> $this->m('get_' . $t . 's'),
    				'enqueue'	=> 'wp_enqueue_' . $t,
    			);
    			$v = $this->util->get_plugin_version();
    			$files = call_user_func($m->get);
    			$param_final = ( 'script' == $t ) ? true : 'all';
    			foreach ( $files as $f ) {
    				$f = (object) $f;
    				//Format handle
    				$handle = $this->get_handle($f->handle);
    
    				//Format dependencies
    				$deps = array();
    				foreach ( $f->deps as $dep ) {
    					if ( $this->util->has_wrapper($dep) ) {
    						$dep = $this->get_handle( $this->util->remove_wrapper($dep) );
    					}
    					$deps[] = $dep;
    				}
    				call_user_func($m->enqueue, $handle, $f->uri, $deps, $v, $param_final);
    			}
    			unset($files, $f, $param_final, $handle, $deps, $dep);
    		}
    	}
    
    	/**
    	 * Enqueue scripts
    	 */
    	public function enqueue_scripts() {
    		$this->enqueue_client_files('script');
    	}

    In class.content.handlers.php:

    /**
    	 * Build client output
    	 * Load handler files in client
    	 */
    	public function client_output() {
    		//Get handlers for current request
    		foreach ( $this->request_matches as $handler ) {
    			$handler->enqueue_scripts();
    		}
    	}

    And in class.base.php :

    /**
    	 * Enqueues files for client output (scripts/styles) based on context
    	 * @uses <code>admin_enqueue_scripts</code> Action hook depending on context
    	 * @uses <code>wp_enqueue_scripts</code> Action hook depending on context
    	 * @param bool $footer (optional) Whether to enqueue footer files (Default: No)
    	 * @return void
    	 */
    	function enqueue_client_files($footer = false) {
    		//Validate
    		if ( !is_bool($footer) ) {
    			$footer = false;
    		}
    		//Enqueue files
    		foreach ( $this->client_files as $type => $files ) {
    			$func = $this->get_client_files_handler($type, 'enqueue');
    			if ( !$func ) {
    				continue;
    			}
    			foreach ( $files as $fkey => $f ) {
    				//Skip previously-enqueued files and shadow files
    				if ( $f->enqueued || !$f->enqueue ) {
    					continue;
    				}
    				//Enqueue files only for current location (header/footer)
    				if ( isset($f->in_footer) ) {
    					if ( $f->in_footer != $footer ) {
    						continue;
    					}
    				} elseif ( $footer ) {
    					continue;
    				}
    				$load = true;
    				//Global Callback
    				if ( is_callable($f->callback) && !call_user_func($f->callback) ) {
    					$load = false;
    				}
    				//Context
    				if ( $load && !empty($f->context) ) {
    					//Reset $load before evaluating context
    					$load = false;
    					//Iterate through contexts
    					foreach ( $f->context as $ctx ) {
    						//Context + Callback
    						if ( is_array($ctx) ) {
    							//Stop checking context if callback is invalid
    							if ( !is_callable($ctx[1]) || !call_user_func($ctx[1]) )
    								continue;
    							$ctx = $ctx[0];
    						}
    						//Stop checking context if valid context found
    						if ( $this->util->is_context($ctx) ) {
    							$load = true;
    							break;
    						}
    					}
    				}
    				//Load valid file
    				if ( $load ) {
    					//Mark file as enqueued
    					$this->client_files[$type]->{$fkey}->enqueued = true;
    					$func($f->id);
    				}
    			}
    		}
    	}
    
    	/**
    	 * Enqueue client files in the footer
    	 */
    	public function enqueue_client_files_footer() {
    		$this->enqueue_client_files(true);
    	}

The topic ‘[Plugin: Simple-Lightbox] Dequeue or deactivate plugin for Mobile’ is closed to new replies.