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();
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_Elastic_press = new \Tainacan\Elastic_Press();

View File

@ -1,39 +1,28 @@
<?php
namespace Tainacan;
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
class GutenbergBlock {
tainacan_blocks_initialize();
private static $instance = null;
function __construct() {
function tainacan_blocks_initialize() {
global $wp_version;
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() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self();
function tainacan_blocks_add_gutenberg_blocks_actions() {
//add_action('init', 'tainacan_blocks_register_tainacan_collections_carousel');
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;
}
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){
function tainacan_blocks_register_tainacan_block_categories($categories, $post){
if ( $post->post_type !== 'post' ) {
return $categories;
}
@ -49,7 +38,7 @@ class GutenbergBlock {
);
}
public function enqueue_on_theme(){
function tainacan_blocks_enqueue_on_theme(){
global $TAINACAN_BASE_URL;
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;
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;
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;
$settings = [
@ -116,11 +105,10 @@ class GutenbergBlock {
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( 'items-grid', 'tainacan_plugin', $settings );
}
}