Forum Replies Created

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter Zephyrinus Rodrigues

    (@zephyrr)

    Hi @jordesign,

    Thank you very much for your reply. You have confirmed what I suspected. The php template solution does use cookies to remember if you already visited the site. Looks like I will have to learn how to use and develop with the Gutenburg plugin. I think I will run with a Front Page as a splash page for the moment in order to move forward. I want to keep the number of plugins I use to a minimum.

    Wish you a Very Happy 2024!

    Thread Starter Zephyrinus Rodrigues

    (@zephyrr)

    Just to confirm @glendaviesnz your code for displaying a block based on only if a user is logged in using the Class Name works 100%. I tested it on my PHP 7.4 dev box with both the twenty twenty-one and the twenty twenty three themes on WordPress 6.1.1 and it worked as expected. Thank you very much!

    // display block for logged in user only
    add_filter( 'render_block', 'logged_in_only_block', 10, 2 );
    function logged_in_only_block( $block_content, $block ) {
    	if ( strpos( $block['attrs']['className'], 'members-intro') ) {
      	    if ( is_user_logged_in() === true )  {
          	        return $block_content;
        	    } else {
          	        return '';
    	    }
    	}
      	return $block_content;
    }

    I am now hoping someone will be able to tell me how I can access the Class Names from the block attributes via php for testing/development purposes. Thank you.

    Thread Starter Zephyrinus Rodrigues

    (@zephyrr)

    Hi Glen!

    Thanks for your reply and suggestion to try.

    Firstly, I managed to get the ‘members-intro’ class conditional to work as it should with just the ‘members-intro’ in the Additional CSS Class(es) in the Block Editor. I am not sure what it was. I decided to test in a different block theme ans used 2023 WordPress block theme. I created a functions.php here. I also had an orphaned block in the 2021 WordPress theme where the Block Editor said something like the block is unavailable or has been moved. After switching themes this orphaned block disappeared. But I don’t think it was the orphaned block as I had the same issue on another system running PHP 7.4 . I haven’t had the chance as yet to test on this setup.

    I am afraid echo var_dump( $block[‘attrs’][‘className’] ); does not work. If enabled in functions.php I get the “There has been a critical error on this website.” and if put in the page template php file nothing outputs and no other code runs after it.

    Thread Starter Zephyrinus Rodrigues

    (@zephyrr)

    Hi Glen,

    Thanks very much for your reply and code. And the add filter reference link.

    Initially I did not have much joy with your code as all blocks get rendered irrespective if the user is logged in or not. I think the problem lies with the additional class name. The filter is not picking it up.

    I used this code to test

    add_filter( 'render_block', 'logged_in_only_block', 10, 2 );  function logged_in_only_block( $block_content, $block ) {	if ( strpos( $block['attrs']['className'], 'members-intro') ) {  	          	        
    return $block_content;    	    
    }    	    
    else {      	        
    return '';	    	
    }  	
    return $block_content;  
    }    

    With this, none of the image blocks got rendered irrespective of the stipulated ‘members-intro’. I tried it on two different machines just to be sure it wasn’t a bug/or theme files corruption.

    By trial and error, I managed to get it to work by adding ‘is-style-default’ to Additional CSS Class(es) in the Block Editor. So I have ‘is-style-default members-intro’ for the image block I want to display to logged in users.

    Is there a way to output on the screen all Class Names from $block[‘attrs’][‘className’] via php?

    Thank you very much once again for your help with this.

    Thread Starter Zephyrinus Rodrigues

    (@zephyrr)

    Hi glendaviesnz!

    Thank you very much for your reply. I am using WordPress 6.1.1 and PHP 8.1.2-1ubuntu2.11

    I am trying to use the render_block filter to display an image via the image block depending on a condition. At the moment I am trying to get a block to display only if a user is logged in. Hence the additional class.

    In this particular image block for additional CSS Class(ed) I have “is-style-default members-intro”
    members-intro is the class I have added to this particular image block. This is my code.

    // display block for logged in user only
    add_filter( 'render_block', 'logged_in_only_block', 10, 2 );
    function logged_in_only_block( $block_content, $block ) {
      if ( strpos( $block['attrs']['className'], 'members-intro') && 
      ( is_user_logged_in() === true ) ) {
          return $block_content;
        } else {
          return '';
        }
      return $block_content;
    }
    
    // end display block for logged in user only 

    It is certainly picking up the additional class and rendering the image block when the user is logged in. However it it not displaying my other image blocks like a reusable image block I have. I need some time to test further as I have an Apache web server permission issue uploading new image content. Please give me a couple of days to resolve this. Can you please tell me if the last statement ” return $block_content; ” is necessary?

    A question regarding the render_block filter. Can you please tell me what the “10, 2” parameters signify?

    Thank you.

    The free version of Better Search and Replace is not useful and even harmful as you cannot see what changes have been made. Have you tried the “Search & Replace” plugin by Inpsyde GmbH? It is not supported anymore but works in WordPress 6.1.1

    Thread Starter Zephyrinus Rodrigues

    (@zephyrr)

    Hi Manfred,
    Besides the CSS code for styling the button, the rest of the code is well tested and works. From what you describe it would seem the javascript is not working. Check that you have implemented the code correctly.

    Thank you.

    Thread Starter Zephyrinus Rodrigues

    (@zephyrr)

    Styling the Menu button with some CSS.
    I only couldn’t get the margin to work to displace the button down a little bit. I will have a play later but if anyone knows why margin-top does not work please let me know. Thank you. site: bright-work.co.uk

    button.menu-toggle{	
    	font-size: 16px;
    	font-weight: bold;
    	border-width: 5px;
        border-style: solid;
    	border-color: MediumVioletRed;
    	padding-left: 20px;
    	padding-right: 20px; 
    	padding-top: 2px;
    	padding-bottom: 2px:
    	/*margin-top: 40px;*/
    					}

    Hi chaps!

    I finally found the button using the FireFox Inspector in Tools–> Web Developer –>Inspector.

    It’s a great too! Thanks to the Developers at Mozilla FireFox!

    The button is an h3.menu-toggle element. You can apply CSS to this in your style.css preferably in your child theme to change this.

    e.g

    h3.menu-toggle{
    	border-width: 5px;
        border-style: solid;
    	border-color: silver;
    	padding: 2px;
    }

    I noticed the padding does not appear .It’s probably something to do with size. I will have a play later. ??

    Great work guys!

    Could someone please tell me where to find the code that actually creates the Menu button in mobile view so that I can change the look of this button via CSS? Here is what it looks like :

    I am running the 2012 v3.0 theme
    Thank you.

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