Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter ncvp

    (@ncvp)

    Adding apiVersion: 3 to the registerBlockType() call in editor.js made the deprecation warning go away.
    editor.js is now this:

    (function(blocks, element) {
    var el = element.createElement;
    blocks.registerBlockType('ncvp/header-menu', {
    apiVersion: 3,
    edit: function() {
    return el('div', {
    style: {
    padding: '20px',
    background: '#f0f0f0',
    border: '5px solid #0073aa',
    textAlign: 'center',
    borderRadius: '10px'
    }
    }, [
    el('strong', {
    style: {
    fontSize: '18px',
    display: 'block',
    marginBottom: '10px'
    }
    }, 'DON\'T PANIC'),
    el('span', {}, 'ncvp header menu derived from Twenty Seventeen')
    ]);
    },
    save: function() {
    return null; // Dynamic block, rendered by PHP
    }
    });
    })(window.wp.blocks, window.wp.element);

    Thanks very much for your help

    I’m unsure of the etiquette in these forums. Can I delete the copy GitHub repo I’ve linked to above, or should I leave it in case anyone else is interested?

    Thread Starter ncvp

    (@ncvp)

    As I understand it I’ve got to do 3 things:
    1) Register the custom block with WordPress
    2) Render the menu HTML so it can appear on the page
    3) Provide JS to display the custom block in the editor
    At the moment my code for 2) and 3) both do 1) as well, so WordPress gets confused.
    I tried adding “render”: “file:./t17m-menu.php” to block.json, but that alone is not sufficient. editor.js, which was originally written by ChatGPT, needs to be modified, I think, but I’ve no idea how to do that.
    I’m going to work through this video https://www.youtube.com/watch?v=UidNIrkqk-E to see if it offers any solutions.

    Thread Starter ncvp

    (@ncvp)

    I am calling register_block_type() as you suggest, at line 43 approximately of t17m/t17m.php. I have to do that, otherwise the callback which renders the menu html is not executed.
    Interestingly (?) if I don’t enqueue editor.js (line 60 of t17m/t17.php) I don’t get the console log warning, but the editor complains ‘Your site doesn’t include support for the “ncvp/header-menu” block. You can leave it as-is or remove it.’, which is rather off-putting.
    It may be that the block is being registered twice, but I do want to see a nice friendly label on my block in the editor.

    Thread Starter ncvp

    (@ncvp)

    Thanks for your interest. I have made a GitHub repo of the current state of the code https://github.com/ncvp/twenty25-test6-copy in case you have time to look at it.
    WordPress must be seeing my block.json, because if I change the description key value that is reflected in the WordPress editor.
    I am calling register_block_type(), but perhaps not in the right way. You can see all my PHP code in t17m/t17m.php. There’s only 70 lines of it.

    Thread Starter ncvp

    (@ncvp)

    Thank you very much, that fixed it.

    I had to create /apache/htdocs/wordpress/.htaccess with the single line you suggested, and I also had to change this section of the Apache httpd.conf:

    <Directory “C:/apache/htdocs”>

    AllowOverride All # was None

    </Directory>

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