GithubHelp home page GithubHelp logo

Comments (4)

fabiankaegy avatar fabiankaegy commented on June 30, 2024

This is a fundamental limitation with what the render.php file is. The file, or rather whatever file you include via the render key in block.json gets used as the render_callback of a block. This render callback will be called multiple times during a WordPress render cycle.

Because of this this file may not contain any function definitions. Or if it does contain them they need to be guarded with the functions_exist check before defining it.

A better option is moving the function definition into another file in the theme or plugin and then only calling it from within the render file

from gutenberg.

cb911nr avatar cb911nr commented on June 30, 2024

Thanks for that @fabiankaegy

Hate to bother but considering my ignorance in this, how would I place that function somewhere to be used inside render.php correctly?

Right now it's a plugin, structure is the typical create-block structure with, so there's on main php file for the plugin that register_block_type everything, but when I put the function in here, render.php doesn't see it?

Assume placing it inside functions.php at the theme level would solve it but rather keep it at the plugin level.

from gutenberg.

fabiankaegy avatar fabiankaegy commented on June 30, 2024

The create block cli creates a main PHP file named after the project slug in the root of the plugin folder. This file contains the plugin header metadata and the {{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init function.

If you define your custom function there that should make it accessible in your render.php

from gutenberg.

cb911nr avatar cb911nr commented on June 30, 2024

Ah thank you that worked, I guess I had to enable / disable the plugin or something funky.

from gutenberg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.