| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly. |
| 4 |
} |
| 5 |
|
| 6 |
// Blocks |
| 7 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'blocks/inc/block-product-field/block-product-field.php'; |
| 8 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'blocks/inc/block-share/block-share.php'; |
| 9 |
|
| 10 |
function wdk_block_category($categories, $post) { |
| 11 |
return array_merge( |
| 12 |
array( |
| 13 |
array( |
| 14 |
'slug' => 'wdk-blocks', |
| 15 |
'title' => __('WDK Blocks', 'text-domain'), |
| 16 |
'icon' => 'dashicons-heart', |
| 17 |
), |
| 18 |
), |
| 19 |
$categories |
| 20 |
); |
| 21 |
} |
| 22 |
|
| 23 |
add_filter('block_categories_all', 'wdk_block_category', 10, 2); |
| 24 |
|
| 25 |
function wdk_block_view($view_file = '', $element = '', $print = false) |
| 26 |
{ |
| 27 |
if(empty($view_file)) return false; |
| 28 |
$file = false; |
| 29 |
if(is_child_theme() && file_exists(get_stylesheet_directory().'/wpdirectorykit/blocks/inc/'.$view_file)) |
| 30 |
{ |
| 31 |
$file = get_stylesheet_directory().'/wpdirectorykit/blocks/inc/'.$view_file; |
| 32 |
} |
| 33 |
elseif(file_exists(get_template_directory().'/wpdirectorykit/blocks/inc/'.$view_file)) |
| 34 |
{ |
| 35 |
$file = get_template_directory().'/wpdirectorykit/blocks/inc/'.$view_file; |
| 36 |
} |
| 37 |
elseif(file_exists(WPDIRECTORYKIT_PATH.'blocks/inc/'.$view_file)) |
| 38 |
{ |
| 39 |
$file = WPDIRECTORYKIT_PATH.'blocks/inc/'.$view_file; |
| 40 |
} |
| 41 |
|
| 42 |
if($file) |
| 43 |
{ |
| 44 |
extract($element); |
| 45 |
if($print) { |
| 46 |
include $file; |
| 47 |
} else { |
| 48 |
ob_start(); |
| 49 |
include $file; |
| 50 |
return ob_get_clean(); |
| 51 |
} |
| 52 |
} |
| 53 |
else |
| 54 |
{ |
| 55 |
if($print) { |
| 56 |
echo 'View file not found in: '.esc_html($file); |
| 57 |
} else { |
| 58 |
return 'View file not found in: '.$file; |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
?> |