Changes Tainacan Blocks logc from OO to procedural due to error on render_callback. We may improve this but for now is necessary to do what is planned on #185.

This commit is contained in:
Mateus Machado Luna 2019-02-05 11:15:09 -02:00
parent 3b7ac2aba2
commit 965654f2a4
2 changed files with 94 additions and 107 deletions

View File

@ -157,7 +157,6 @@ require_once(__DIR__ . '/../theme-helper/template-tags.php');
$Tainacan_Theme_Helper = \Tainacan\Theme_Helper::get_instance(); $Tainacan_Theme_Helper = \Tainacan\Theme_Helper::get_instance();
require_once(__DIR__ . '/../gutenberg-blocks/class-tainacan-gutenberg-block.php'); require_once(__DIR__ . '/../gutenberg-blocks/class-tainacan-gutenberg-block.php');
$Tainacan_Gutenberg_Block = \Tainacan\GutenbergBlock::get_instance();
$Tainacan_Search_Engine = new \Tainacan\Search_Engine(); $Tainacan_Search_Engine = new \Tainacan\Search_Engine();
$Tainacan_Elastic_press = new \Tainacan\Elastic_Press(); $Tainacan_Elastic_press = new \Tainacan\Elastic_Press();

View File

@ -1,39 +1,28 @@
<?php <?php
namespace Tainacan;
include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
class GutenbergBlock { tainacan_blocks_initialize();
private static $instance = null; function tainacan_blocks_initialize() {
function __construct() {
global $wp_version; global $wp_version;
if(is_plugin_active('gutenberg/gutenberg.php') || $wp_version >= '5') { if(is_plugin_active('gutenberg/gutenberg.php') || $wp_version >= '5') {
$this->add_gutenberg_blocks_actions(); tainacan_blocks_add_gutenberg_blocks_actions();
} }
} }
public static function get_instance() { function tainacan_blocks_add_gutenberg_blocks_actions() {
if ( ! isset( self::$instance ) ) { //add_action('init', 'tainacan_blocks_register_tainacan_collections_carousel');
self::$instance = new self(); add_action('init', 'tainacan_blocks_register_tainacan_items_grid');
add_action('init', 'tainacan_blocks_add_plugin_settings');
//add_action('wp_enqueue_scripts', 'tainacan_blocks_enqueue_on_theme');
add_filter('block_categories', 'tainacan_blocks_register_tainacan_block_categories', 10, 2);
} }
return self::$instance; function tainacan_blocks_register_tainacan_block_categories($categories, $post){
}
private function add_gutenberg_blocks_actions() {
//add_action('init', array($this, 'register_tainacan_collections_carousel'));
add_action('init', array($this, 'register_tainacan_items_grid'));
add_action('init', array($this, 'add_plugin_settings'));
//add_action('wp_enqueue_scripts', array($this, 'enqueue_on_theme'));
add_filter('block_categories', array($this, 'register_tainacan_block_categories'), 10, 2);
}
public function register_tainacan_block_categories($categories, $post){
if ( $post->post_type !== 'post' ) { if ( $post->post_type !== 'post' ) {
return $categories; return $categories;
} }
@ -49,7 +38,7 @@ class GutenbergBlock {
); );
} }
public function enqueue_on_theme(){ function tainacan_blocks_enqueue_on_theme(){
global $TAINACAN_BASE_URL; global $TAINACAN_BASE_URL;
wp_enqueue_script( wp_enqueue_script(
@ -58,7 +47,7 @@ class GutenbergBlock {
); );
} }
public function register_tainacan_items_grid(){ function tainacan_blocks_register_tainacan_items_grid(){
global $TAINACAN_BASE_URL; global $TAINACAN_BASE_URL;
wp_register_script( wp_register_script(
@ -81,7 +70,7 @@ class GutenbergBlock {
} }
} }
public function register_tainacan_collections_carousel(){ function tainacan_blocks_register_tainacan_collections_carousel(){
global $TAINACAN_BASE_URL; global $TAINACAN_BASE_URL;
wp_register_script( wp_register_script(
@ -104,7 +93,7 @@ class GutenbergBlock {
} }
} }
public function get_plugin_js_settings(){ function tainacan_blocks_get_plugin_js_settings(){
global $TAINACAN_BASE_URL; global $TAINACAN_BASE_URL;
$settings = [ $settings = [
@ -116,11 +105,10 @@ class GutenbergBlock {
return $settings; return $settings;
} }
function add_plugin_settings() { function tainacan_blocks_add_plugin_settings() {
$settings = $this->get_plugin_js_settings(); $settings = tainacan_blocks_get_plugin_js_settings();
//wp_localize_script( 'collections-carousel', 'tainacan_plugin', $settings ); //wp_localize_script( 'collections-carousel', 'tainacan_plugin', $settings );
wp_localize_script( 'items-grid', 'tainacan_plugin', $settings ); wp_localize_script( 'items-grid', 'tainacan_plugin', $settings );
} }
}