WordPress.org

Forums

Advanced Post Manager
Plugin causes JS error which breaks admin pages (5 posts)

  1. tsdexter
    Member
    Posted 1 year ago #

    When I activate the plugin and the demo content I get a JavaScript error that causes me to not be able to switch between text/visual modes on the editor for pages as well the JS error causes other plugins admin JS files to not load since they're included afterwards which breaks other unrelated functionality (specifically, visual composer doesn't work).

    I've deactivated visual composer entirely and the advanced post manager still causes the issue and I can't switch between text/visual modes because of the js error and presumably other js components won't work as well but that's the only thing I've tried thus far.

    Seems like it has something to do with jquery - can you point me in the right direction to patch the plugin?

    Here is the error:

    Uncaught TypeError: Cannot read property 'length' of undefined load-scripts.php?c=0&load%5B%5D=jquery,utils,plupload,plupload-html5,plupload-flash,plupload-silverlight,plupload-html4,json2&ver=3.5.2:2
    v.extend.each load-scripts.php?c=0&load%5B%5D=jquery,utils,plupload,plupload-html5,plupload-flash,plupload-silverlight,plupload-html4,json2&ver=3.5.2:2
    e.widget load-scripts.php?c=0&load%5B%5D=admin-bar,hoverIntent,common,schedule,wp-aj…wplink,wpdialogs-popup,wp-fullscreen,medi&load%5B%5D=a-upload&ver=3.5.2:69
    (anonymous function) load-scripts.php?c=0&load%5B%5D=admin-bar,hoverIntent,common,schedule,wp-aj…wplink,wpdialogs-popup,wp-fullscreen,medi&load%5B%5D=a-upload&ver=3.5.2:74
    (anonymous function) load-scripts.php?c=0&load%5B%5D=admin-bar,hoverIntent,common,schedule,wp-aj…wplink,wpdialogs-popup,wp-fullscreen,medi&load%5B%5D=a-upload&ver=3.5.2:74

    http://wordpress.org/plugins/advanced-post-manager/

  2. tsdexter
    Member
    Posted 1 year ago #

    I've found the reason. You are calling in WP default jQuery UI (version v1.9.2 in WP 3.5) but you are using jQuery UI code that is deprecated in 1.9+

    I've modified core files from Advanced Post Manager in order to rectify this. Can you please update the plugin and upload a new version so I don't have to run a version with modified core files? (or provide me with another fix that doesn't require modifying core).

    I've modified:

    ./lib/tribe-filters.class.php - starting at line 407

    from:

    public function enqueue() {
    		global $current_screen;
    		$resources_url = apply_filters( 'tribe_apm_resources_url', $this->url . 'resources' );
    		$resources_url = trailingslashit($resources_url);
    		if ( $current_screen->id == 'edit-' . $this->filtered_post_type ) {
    			wp_enqueue_style('tribe-jquery-ui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/themes/base/jquery-ui.css');
    			wp_enqueue_script('tribe-jquery-ui-datepicker', $resources_url . 'jquery-ui-datepicker.js', array('jquery-ui-core'), null, true );
    			wp_enqueue_script('tribe-filters', $resources_url . 'tribe-filters.js', array('jquery-ui-sortable', 'tribe-jquery-ui-datepicker'), null, true );
    		}
    	}

    To:

    public function enqueue() {
    		global $current_screen;
    		$resources_url = apply_filters( 'tribe_apm_resources_url', $this->url . 'resources' );
    		$resources_url = trailingslashit($resources_url);
    		if ( $current_screen->id == 'edit-' . $this->filtered_post_type ) {
    			wp_enqueue_style('tribe-jquery-ui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/themes/base/jquery-ui.css');
    			//georgiancode
    			wp_enqueue_script('old-jquery-ui', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/jquery-ui.min.js', array('jquery'), true);
    			//wp_enqueue_script('tribe-jquery-ui-datepicker', $resources_url . 'jquery-ui-datepicker.js', array('jquery-ui-core'), null, true );
    			wp_enqueue_script('tribe-jquery-ui-datepicker', $resources_url . 'jquery-ui-datepicker.js', array('old-jquery-ui'), null, true );
    			wp_enqueue_script('tribe-filters', $resources_url . 'tribe-filters.js', array('jquery-ui-sortable', 'tribe-jquery-ui-datepicker'), null, true );
    		}
    	}

    ./lib/tribe-meta-box.php - starting at Line 58

    from:

    function register_scripts_and_styles() {
    		// change '\' to '/' in case using Windows
    		$content_dir = str_replace('\\', '/', WP_CONTENT_DIR);
    		$script_dir = str_replace('\\', '/', dirname(__FILE__));
    
    		// get URL of the directory of current file, this works in both theme or plugin
    		$base_url = trailingslashit( str_replace($content_dir, WP_CONTENT_URL, $script_dir) );
    		$resources_url = apply_filters( 'tribe_apm_resources_url', $base_url . 'resources' );
    		$resources_url = trailingslashit($resources_url);
    
    		wp_register_style( 'tribe-meta-box', $resources_url . 'meta-box.css');
    		wp_register_script('tribe-meta-box', $resources_url . 'meta-box.js', array('jquery'), null, true);
    
    		wp_register_style('tribe-jquery-ui-css', 'http://ajax.googleapis.com/ajax/libs/jqueryui/' . self::get_jqueryui_ver() . '/themes/base/jquery-ui.css');
    		wp_register_script('tribe-jquery-ui', 'https://ajax.googleapis.com/ajax/libs/jqueryui/' . self::get_jqueryui_ver() . '/jquery-ui.min.js', array('jquery'));
    		wp_register_script('tribe-timepicker', 'https://github.com/trentrichardson/jQuery-Timepicker-Addon/raw/master/jquery-ui-timepicker-addon.js', array('tribe-jquery-ui'));
    	}

    to:

    function register_scripts_and_styles() {
    		// change '\' to '/' in case using Windows
    		$content_dir = str_replace('\\', '/', WP_CONTENT_DIR);
    		$script_dir = str_replace('\\', '/', dirname(__FILE__));
    
    		// get URL of the directory of current file, this works in both theme or plugin
    		$base_url = trailingslashit( str_replace($content_dir, WP_CONTENT_URL, $script_dir) );
    		$resources_url = apply_filters( 'tribe_apm_resources_url', $base_url . 'resources' );
    		$resources_url = trailingslashit($resources_url);
    
    		wp_register_style( 'tribe-meta-box', $resources_url . 'meta-box.css');
    		wp_register_script('tribe-meta-box', $resources_url . 'meta-box.js', array('jquery'), null, true);
    
    		wp_register_style('tribe-jquery-ui-css', 'http://ajax.googleapis.com/ajax/libs/jqueryui/' . self::get_jqueryui_ver() . '/themes/base/jquery-ui.css');
    		//georgiancode
    		//wp_register_script('tribe-jquery-ui', 'https://ajax.googleapis.com/ajax/libs/jqueryui/' . self::get_jqueryui_ver() . '/jquery-ui.min.js', array('jquery'));
    		wp_register_script('tribe-old-jquery-ui', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/jquery-ui.min.js', array('jquery'));
    		wp_register_script('tribe-timepicker', 'https://github.com/trentrichardson/jQuery-Timepicker-Addon/raw/master/jquery-ui-timepicker-addon.js', array('tribe-jquery-ui'));
    	}

    Let me know.

    Thanks,
    Thomas

  3. tsdexter
    Member
    Posted 1 year ago #

    This fix has broken the datepicker. Investigating a better solution.

  4. tsdexter
    Member
    Posted 1 year ago #

    OK, here is the proper fix that should likely be included in the plugin. The issue was that the plugin includes the wrong jquery-ui version.

    The proper fix would be to change the function get_jqueryui_ver(){...}

    From:

    // Get proper jQuery UI version to not conflict with WP admin scripts
    	static function get_jqueryui_ver() {
    		global $wp_version;
    		if (version_compare($wp_version, '3.1', '>=')) {
    			return '1.8.10';
    		} 
    
    		return '1.7.3';
    	}

    To:

    // Get proper jQuery UI version to not conflict with WP admin scripts
    	static function get_jqueryui_ver() {
    		global $wp_version;
    
    		if (version_compare($wp_version, '3.5', '>=')) {
    			return '1.9.2';
    		}
    
    		if (version_compare($wp_version, '3.1', '>=')) {
    			return '1.8.10';
    		} 
    
    		return '1.7.3';
    	}

    It looks like wordpress 3.5 increased the jquery-ui version to 1.9.2 and you guys forgot to make that change in the plugin.

    Thanks,
    Thomas

  5. leahkoerper
    Modern Tribe Support Rep
    Posted 1 year ago #

    Hey there,

    I just wanted to let you know that a fix for this issue is included in our upcoming version 3.3. Keep an eye out on your WordPress Plugins page for an update. Thanks for your patience while we worked on this!

    Cheers,
    Leah

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Advanced Post Manager
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic