Fatal error with wp_register_block_type()

[ad_1]

Hello,

I created a plugin to add a gutenberg block (to displayed a post in another post).

Here my code :

<?php
/**
* Plugin Name: Post Displayer
* Description: Add a Gutenberg block to display another existing post.
* Version: 1.0
* Author: BizarreMood
* License: GPLv2 or later
* Text Domain: post-displayer
*/

if (!defined(‘ABSPATH’)) {
exit;
}

// Enregistrez le type de bloc.
function register_post_displayer_block() {
wp_register_block_type(
‘post-displayer/block’,
array(
‘editor_script’ => ‘post-displayer-block-script’,
‘editor_style’ => ‘post-displayer-block-style’,
)
);
}
add_action(‘init’, ‘register_post_displayer_block’);

// Enfilez les scripts et les styles de bloc.
function enqueue_post_displayer_block_assets() {
wp_enqueue_script(
‘post-displayer-block-script’,
plugins_url(‘block.js’, __FILE__),
array(‘wp-blocks’, ‘wp-element’, ‘wp-editor’),
filemtime(plugin_dir_path(__FILE__) . ‘block.js’)
);

wp_enqueue_style(
‘post-displayer-block-style’,
plugins_url(‘block.css’, __FILE__),
array(‘wp-edit-blocks’),
filemtime(plugin_dir_path(__FILE__) . ‘block.css’)
);
}
add_action(‘enqueue_block_editor_assets’, ‘enqueue_post_displayer_block_assets’);

Here the error :

&#x200B;

thrown in /home/u642246707/domains/manuturf.com/public\_html/wp-content/plugins/post-displayer/post-displayer.php on line 18

**\[22-Feb-2024 15:47:11 UTC\] PHP Fatal error: Uncaught Error: Call to undefined function wp\_register\_block\_type() in /home/u642246707/domains/manuturf.com/public\_html/wp-content/plugins/post-displayer/post-displayer.php:18**

Stack trace:

\#0 /home/u642246707/domains/manuturf.com/public\_html/wp-includes/class-wp-hook.php(324): register\_post\_displayer\_block()

\#1 /home/u642246707/domains/manuturf.com/public\_html/wp-includes/class-wp-hook.php(348): WP\_Hook->apply\_filters()

\#2 /home/u642246707/domains/manuturf.com/public\_html/wp-includes/plugin.php(517): WP\_Hook->do\_action()

\#3 /home/u642246707/domains/manuturf.com/public\_html/wp-settings.php(643): do\_action()

\#4 /home/u642246707/domains/manuturf.com/public\_html/wp-config.php(111): require\_once(‘/home/u64224670…’)

\#5 /home/u642246707/domains/manuturf.com/public\_html/wp-load.php(50): require\_once(‘/home/u64224670…’)

\#6 /home/u642246707/domains/manuturf.com/public\_html/wp-admin/admin.php(34): require\_once(‘/home/u64224670…’)

&#x200B;

Any idea ? I use the last wordpress version.

Lot of thanks in advance !

[ad_2]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer