Support » Plugin: BuddyPress Docs » Conflict with Smart Slider 3

  • Resolved Nextendweb

    (@nextendweb)


    Hi @boonebgorges,
    I’m the developer of Smart Slider 3 and one of our user reported an issue between BuddyPress Docs and Smart Slider 3. The bad news, I was not able to reproduce the issue in our test environment, so maybe another plugin involved in the conflict, but the good news is that I have access to the website.

    The error happens when we go to edit a post, click on the set featured image and the images are not loading. The console tells an XHR call to admin-ajax.php which fails with error 500.

    Stacktrace of the error:

    [18-Oct-2018 05:55:23 UTC] PHP Fatal error:  Uncaught Error: Call to a member function wp_rewrite_rules() on null in */wp-includes/rewrite.php:518
    Stack trace:
    #0 */wp-content/plugins/buddypress-docs/includes/attachments.php(367): url_to_postid('http://***')
    #1 */wp-content/plugins/buddypress-docs/includes/attachments.php(318): BP_Docs_Attachments::get_doc_id_from_url('http://***')
    #2 */wp-content/plugins/buddypress-docs/includes/attachments.php(130): BP_Docs_Attachments->get_doc_id()
    #3 */wp-includes/class-wp-hook.php(286): BP_Docs_Attachments->filter_upload_dir(Array)
    #4 */wp-includes/plugin.php(203): WP_Hook->apply_filters(Array, Array)
    #5 */wp-includes/functions.php(1901): apply_filters('upload_dir', Array)
    #6 */wp-cont in */wp-includes/rewrite.php on line 518

    I narrowed down the issue and Smart Slider acquires the upload directory from WordPress on plugins_loaded action. If you open /wp-settings.php, you will see that plugins_loaded action happens before the $GLOBALS['wp_rewrite'] set.

    Back to the backtrace:
    url_to_postid wants to use the $wp_rewrite global, which is not available at that point in time. url_to_postid called from the BP_Docs_Attachments->filter_upload_dir call trace.

    One solution would be to check if the $wp_rewrite initialized before calling that function:

    public static function get_doc_id_from_url( $url ) {
    	$doc_id = null;
    	$url = untrailingslashit( $url );
    	$edit_location = strrpos( $url, BP_DOCS_EDIT_SLUG );
    	if ( false !== $edit_location && BP_DOCS_EDIT_SLUG == substr( $url, $edit_location ) ) {
    		global $wp_rewrite;
    		if($wp_rewrite){
    			$doc_id = url_to_postid( substr( $url, 0, $edit_location - 1 ) );
    		}		
    	}
    	return $doc_id;
    }

    Another solution is to delay the hook to the upload_dir filter unti the $wp_rewrite ready:

    add_action('setup_theme' function(){
        add_filter( 'upload_dir', array( $this, 'filter_upload_dir' ) );
    });
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Conflict with Smart Slider 3’ is closed to new replies.