Forum Replies Created

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Taeo

    (@taeo)

    Making it an option sounds like a good approach! I figure there may be some users who take the same path I did and look for a replacement to the built in lightbox functionality in 6.4. The UX for enabling it in the editor is very good IMO but the lack of zoom really kills it.

    I ended up dropping your plugin and adding the PhotoSwipe JS to my theme manually so I could have more direct control over the options but I hope my code fragments can save you some time. It took me a bit to find the right hooks to use.

    Thread Starter Taeo

    (@taeo)

    I went ahead and implemented this on my own but wanted to share in case it is helpful! There might be a better way to do this but this was quick and relatively easy to implement on a custom theme.

    /**
     * Overrides render callback for core image block.
     * 
     * @param array $args An array of block parameters
     * @param name  $name The name of the block including namespace
     * @return array
     */
    function override_core_image_block_render_callback( $args, $name ) {
    	if ( 'core/image' === $name ) {
    		unset( $args['viewScript'] );
    		unset( $args['view_script_handles'] );
    		$args['render_callback'] = 'render_image_lightbox';
    	}
    	return $args;
    }
    add_filter( 'register_block_type_args', 'override_core_image_block_render_callback', 10, 2 );
    
    /**
     * Wrap images in links to trigger the PhotoSwipe plugin.
     *
     * @param array  $attributes An array of block attributes
     * @param string $content The HTML content of the block
     * @param object $block The block object
     * @return bool|array
     */
    function render_image_lightbox( $attributes, $content, $block ) {
    	if ( false === stripos( $content, '<img' ) ) {
    		return '';
    	}
    
    	$link_destination  = isset( $attributes['linkDestination'] ) ? $attributes['linkDestination'] : 'none';
    	$lightbox_settings = block_core_image_get_lightbox_settings( $block->parsed_block );
    
    	/*
    	 * If the lightbox is enabled and the image is not linked, wrap the image in a link to trigger the PhotoSwipe Lightbox plugin.
    	 */
    	if (
    		isset( $lightbox_settings ) &&
    		'none' === $link_destination &&
    		isset( $lightbox_settings['enabled'] ) &&
    		true === $lightbox_settings['enabled']
    	) {
    		$img_src  = wp_get_attachment_url( $attributes['id'] );
    		$img_meta = wp_get_attachment_metadata( $attributes['id'] );
    
    		if ( $img_src && $img_meta ) {
    			$pattern     = '/<img.*?>/';
    			$replacement = sprintf( '<a class="lightbox" href="%s" data-pswp-width="%d" data-pswp-height="%d">$0</a>', esc_url( $img_src ), esc_attr( $img_meta['width'] ), esc_attr( $img_meta['height'] ) );
    			$content     = preg_replace( $pattern, $replacement, $content );
    		}
    	}
    
    	return $content;
    }
    
    Thread Starter Taeo

    (@taeo)

    Thank you! This worked out well.

    Just FYI – the issue I was trying to overcome was the fact that after a successful registration the register form shortcode would display a success message and the login form. There are two issues with this…

    1) Since we’re still on the registration page the content on that page ( I have an h1 before it and some policy information/links after it ) might confuse the user. Minor concern but still something to consider.

    2) If you make a mistake or typo when using this login form the page refreshes and displays the registration form again – no error messages or anything.

    I fixed this by using the wpmem_register_redirect_filter to redirect the user to the standard login page with a query string to trigger a success message.

    Thread Starter Taeo

    (@taeo)

    Unfortunately I wasn’t able to solve things with Rackspace.

    As best we can tell it’s the Varnish VCL configuration that is breaking the plugin. Inspecting resources shows that the “bid_1_password_protected_auth” cookie is not set after filling out the login form. I know that Varnish will disregard cookies when individual static files are served to cut down on overhead but I don’t know how that affects your plugin.

    Unfortunately we can’t turn off Varnish completely because it is what keeps WordPress in sync when load balanced across multiple servers. I’m sure this is the same reason WP Engine does not work.

    I will try looking into it a bit more myself but if you have any ideas or recommendations on places to look I’d appreciate it. I’ll gladly share any solutions I find.

    Thread Starter Taeo

    (@taeo)

    Gotcha. I think the setup uses Varnish for caching which I believe is what WP Engine uses as well. Having Rackspace look into it – will report my findings.

    Forum: Fixing WordPress
    In reply to: Not reading CSS

    I believe you are using @import incorrectly. Try replacing:

    <style type=”text/css” media=”screen”>
    @import url( https://www.evolutionbusinessservices.co.uk/charlene/blog3/wp-content/themes/SAM WPv0.1/style.css );
    </style>

    with

    <link rel=”stylesheet” href=”<?php bloginfo(‘stylesheet_url’); ?>” type=”text/css” media=”screen” />

Viewing 6 replies - 1 through 6 (of 6 total)