Comments (4)
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.
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.
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.
Ah thank you that worked, I guess I had to enable / disable the plugin or something funky.
from gutenberg.
Related Issues (20)
- Site editor responsiveness
- [Flaky Test] The PHP version is rendered if the legacy attribute is true HOT 1
- A PHP warning is thrown whenever a plugin calls `register_setting` without the `show_in_rest` argument
- LinkControl: LInk preview buttons are off-view when the link text is a very long url
- Clarify the 'Play inline' setting for videos HOT 1
- Editing synced patterns does not use browser history HOT 1
- Non-synced patterns missing focus outline in pattern category inserter HOT 1
- [Flaky Test] should use `item` as the defaul item name in the context HOT 1
- Site Editor: Empty header while in distraction-free mode HOT 9
- Header nav menus covered by overlay in following block HOT 4
- Allow html in pagination labels HOT 2
- Click-to-expand images could prefetch full-resolution image to speed up display HOT 4
- Customization Options for Editor Interface HOT 3
- Data views grid layout: Make aspect ratio consumer configurable
- LinkControl: refine the display of the link preview title and url HOT 1
- LinkControl: Improve the link preview and Copy link aria labels HOT 3
- Components: Replace `reducedMotion()` usage with media queries
- Video block: Add aspect ratio control
- Font collections: search or filter fonts by supported script
- Extra Space need to remove in class-wp-block-bindings-registry.php file HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gutenberg.