Custom blocks via plugin and API

Posted in: Newspaper
Post count: 3

Hey!
Trying to create a custom block via API and the plugin I’ve made for it but get Fatal errors.. Please advise:

Here’s the error (it occurs twice):
[20-Jan-2020 10:44:25 UTC] PHP Fatal error: Uncaught Error: Class ‘elab_block_01’ not found in /–/wp-content/plugins/td-composer/legacy/common/wp_booster/td_global_blocks.php:33
Stack trace:
#0 /–/wp-content/plugins/td-composer/legacy/common/wp_booster/td_global_blocks.php(27): td_global_blocks::get_instance(‘elab_block_01’)
#1 /–/wp-includes/shortcodes.php(325): td_global_blocks::proxy_function(”, ”, ‘elab_block_01’)
#2 [internal function]: do_shortcode_tag(Array)
#3 /–/wp-includes/shortcodes.php(199): preg_replace_callback(‘/\\[(\\[?)(elab_b…’, ‘do_shortcode_ta…’, ‘[elab_block_01]’)
#4 /–/wp-content/plugins/td-composer/includes/tdc_ajax.php(246): do_shortcode(‘[elab_block_01]’)
#5 /–/wp-includes/rest-api/class-wp-rest-server.php(946): tdc_ajax::on_ajax_render_shortcode(Object(WP_REST_Request))
#6 /–/wp-includes/rest-api/class-wp-re in /–/wp-content/plugins/td-composer/legacy/common/wp_booster/td_global_blocks.php on line 33

And here’s my plugin:
class elab_td_api_plugin {
var $plugin_url = ”;
var $plugin_path = ”;

function __construct() {
$this->plugin_url = plugins_url(”, __DIR__); // path used for elements like images, css, etc which are available on end user
$this->plugin_path = dirname(__DIR__); // used for internal (server side) files

add_action(‘td_global_after’, array($this, ‘elab_td_global_after’)); // hook used to add or modify items via Api
add_action(‘admin_enqueue_scripts’, array(‘elab_td_api_plugin’, ‘elab_td_plugin_wpadmin_css’)); // hook used to add custom css for wp-admin area
add_action(‘wp_enqueue_scripts’, array(‘elab_td_api_plugin’, ‘elab_td_plugin_frontend_css’)); // hook used to add custom css used on frontend area
}

static function elab_td_plugin_wpadmin_css() {
wp_enqueue_style(‘elab-td-plugin-framework’, plugins_url(”, __DIR__) . ‘/admin/style.css’); // backend css (admin_enqueue_scripts)
}

static function elab_td_plugin_frontend_css() {
wp_enqueue_style(‘elab-td-plugin-framework’, plugins_url(”, __DIR__) . ‘/css/style.css’); // frontend css (wp_enqueue_scripts)
}

function elab_td_global_after() {
td_api_thumb::add(‘elab_320x480’,
array(
‘name’ => ‘elab_320x480’,
‘width’ => 320,
‘height’ => 480,
‘crop’ => array(‘center’, ‘center’),
‘post_format_icon_size’ => ‘small’,
‘used_on’ => array(
‘Inimesed’
)
)
);
td_api_thumb::add(‘elab_80x120’,
array(
‘name’ => ‘elab_80x120’,
‘width’ => 80,
‘height’ => 120,
‘crop’ => array(‘center’, ‘center’),
‘post_format_icon_size’ => ‘small’,
‘used_on’ => array(
‘Loetelud’
)
)
);
td_api_module::add(‘elab_module_01’,
array(
‘file’ => $this->plugin_path . “/modules/elab_module_01.php”,
‘text’ => ‘ELAB Module 01’,
‘img’ => $this->plugin_url . ‘/images/modules/elab_module_01.png’,
‘used_on_blocks’ => array(‘elab_block_01’),
‘excerpt_title’ => 12,
‘excerpt_content’ => 25,
‘enabled_on_more_articles_box’ => true,
‘enabled_on_loops’ => true,
‘uses_columns’ => true, // if the module uses columns on the page template + loop
‘category_label’ => true,
‘class’ => ‘td_module_wrap td-animation-stack’,
)
);
td_api_block::add(‘elab_block_01’,
array(
‘map_in_visual_composer’ => false,
‘map_in_td_composer’ => true,
“name” => ‘ELAB Block 01’,
“base” => ‘elab_block_01’,
“class” => ‘elab_block_01’,
“controls” => “full”,
“category” => ‘Blocks’,
‘tdc_category’ => ‘Blocks’,
‘icon’ => ‘icon-pagebuilder-elab_block_01’,
‘file’ => $this->plugin_path . ‘/shortcodes/elab_block_01.php’,
“params” => array_merge(
td_config::get_map_block_general_array(),
td_config::get_map_filter_array(),
td_config::get_map_block_ajax_filter_array(),
td_config::get_map_block_pagination_array()
)
)
);
}

}
new elab_td_api_plugin();

Thanks in advance!

Post count: 3

Any ideas?

Post count: 3

Nevermind.. didn’t see the “td” string prepend requirement… all is good now.

Viewing 3 posts - 1 through 3 (of 3 total)
The forum ‘Newspaper’ is closed to new topics and replies.