| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: B Blocks |
| 4 |
* Description: Gutenberg Blocks Collection and Page Builder. |
| 5 |
* Version: 1.3 |
| 6 |
* Author: bPlugins LLC |
| 7 |
* Author URI: http://bplugins.com |
| 8 |
* License: GPLv3 |
| 9 |
* License URI: https://www.gnu.org/licenses/gpl-2.0.txt |
| 10 |
* Text Domain: b-blocks |
| 11 |
*/ |
| 12 |
|
| 13 |
// ABS PATH |
| 14 |
if ( !defined( 'ABSPATH' ) ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
// Constant |
| 19 |
define( 'B_BLOCKS_PLUGIN_VERSION', '1.3' ); |
| 20 |
define( "B_BLOCKS_ASSETS_DIR", plugin_dir_url( __FILE__ ) . 'assets/' ); |
| 21 |
|
| 22 |
// Register Block Category |
| 23 |
function b_blocks_block_categories( $categories ) { |
| 24 |
return array_merge( |
| 25 |
array( |
| 26 |
array( |
| 27 |
'slug' => 'bBlocks', |
| 28 |
'title' => __( 'B Blocks', 'b-blocks' ), |
| 29 |
), |
| 30 |
), |
| 31 |
$categories |
| 32 |
); |
| 33 |
} |
| 34 |
add_filter( 'block_categories', 'b_blocks_block_categories' ); |
| 35 |
|
| 36 |
// Register Blocks |
| 37 |
function b_blocks_wp_register_script( $block, $options = array() ) { |
| 38 |
register_block_type( |
| 39 |
'b-blocks/' . $block, |
| 40 |
array_merge( |
| 41 |
array( |
| 42 |
'editor_script' => 'b_blocks_editor_script', |
| 43 |
'editor_style' => 'b_blocks_editor_style', |
| 44 |
'script' => 'b_blocks_script', |
| 45 |
'style' => 'b_blocks_style', |
| 46 |
), |
| 47 |
$options |
| 48 |
) |
| 49 |
); |
| 50 |
} |
| 51 |
|
| 52 |
// Enqueue assets |
| 53 |
function b_blocks_enqueue_block_assets() { |
| 54 |
wp_enqueue_style( 'bootstrap', B_BLOCKS_ASSETS_DIR . 'css/bootstrap.min.css', '', '4.6.0', 'all' ); |
| 55 |
|
| 56 |
wp_enqueue_script( 'bootstrap', B_BLOCKS_ASSETS_DIR . 'js/bootstrap.bundle.min.js', array( 'jquery' ), '4.6.0', true ); |
| 57 |
wp_enqueue_script( 'mailtoui', B_BLOCKS_ASSETS_DIR . 'js/mailtoui-min.js', array(), B_BLOCKS_PLUGIN_VERSION, true ); |
| 58 |
} |
| 59 |
add_action( 'enqueue_block_assets', 'b_blocks_enqueue_block_assets' ); |
| 60 |
|
| 61 |
function b_blocks_enqueue_assets() { |
| 62 |
wp_enqueue_style( 'fancybox', B_BLOCKS_ASSETS_DIR . 'css/fancybox.min.css', '', '3.5.6', 'all' ); |
| 63 |
|
| 64 |
wp_enqueue_script( 'fancybox', B_BLOCKS_ASSETS_DIR . 'js/fancybox.min.js', array( 'jquery' ), '3.5.6', true ); |
| 65 |
} |
| 66 |
add_action( 'wp_enqueue_scripts', 'b_blocks_enqueue_assets' ); |
| 67 |
|
| 68 |
function b_blocks_register() { |
| 69 |
// Resister script in editor |
| 70 |
wp_register_script( 'b_blocks_editor_script', plugins_url( 'dist/editor.js', __FILE__ ), array( 'wp-blocks', 'wp-element', 'wp-data', 'wp-i18n', 'wp-editor', 'wp-components', 'wp-blob', 'wp-html-entities', 'wp-compose', 'wp-rich-text' ), null, false ); |
| 71 |
// Register style in editor |
| 72 |
wp_register_style( 'b_blocks_editor_style', plugins_url( 'dist/editor.css', __FILE__ ), array( 'wp-edit-blocks' ), null ); |
| 73 |
|
| 74 |
// Register script in frontend |
| 75 |
wp_register_script( 'b_blocks_script', plugins_url( 'dist/script.js', __FILE__ ), array( 'jquery' ), null, true ); |
| 76 |
// Register style in frontend |
| 77 |
wp_register_style( 'b_blocks_style', plugins_url( 'dist/style.css', __FILE__ ), array( 'wp-editor' ), null ); |
| 78 |
|
| 79 |
// Register Blocks |
| 80 |
b_blocks_wp_register_script( 'posts', array( |
| 81 |
'render_callback' => 'render_b_blocks_posts', |
| 82 |
// 'attributes' => array( |
| 83 |
// 'postsPerPage' => array( 'type' => 'number', 'default' => 5 ), |
| 84 |
// ), |
| 85 |
) ); |
| 86 |
b_blocks_wp_register_script( 'slider' ); |
| 87 |
b_blocks_wp_register_script( 'section' ); |
| 88 |
b_blocks_wp_register_script( 'section-heading' ); |
| 89 |
b_blocks_wp_register_script( 'image-gallery' ); |
| 90 |
b_blocks_wp_register_script( 'price-lists' ); |
| 91 |
b_blocks_wp_register_script( 'price-list' ); |
| 92 |
b_blocks_wp_register_script( 'feature-boxes' ); |
| 93 |
b_blocks_wp_register_script( 'feature-box' ); |
| 94 |
b_blocks_wp_register_script( 'info-box' ); |
| 95 |
b_blocks_wp_register_script( 'button-group' ); |
| 96 |
b_blocks_wp_register_script( 'countdown' ); |
| 97 |
b_blocks_wp_register_script( 'card' ); |
| 98 |
b_blocks_wp_register_script( 'mailto' ); |
| 99 |
b_blocks_wp_register_script( 'modal' ); |
| 100 |
b_blocks_wp_register_script( 'tabs' ); |
| 101 |
b_blocks_wp_register_script( 'accordion' ); |
| 102 |
b_blocks_wp_register_script( 'note' ); |
| 103 |
b_blocks_wp_register_script( 'gif' ); |
| 104 |
b_blocks_wp_register_script( 'qr-code' ); |
| 105 |
b_blocks_wp_register_script( 'highlight-text' ); |
| 106 |
b_blocks_wp_register_script( 'progress-bar' ); |
| 107 |
b_blocks_wp_register_script( 'spacer' ); |
| 108 |
b_blocks_wp_register_script( 'selection' ); |
| 109 |
b_blocks_wp_register_script( 'divider' ); |
| 110 |
b_blocks_wp_register_script( 'to-top' ); |
| 111 |
|
| 112 |
// WP Localized globals. |
| 113 |
wp_localize_script( |
| 114 |
'b_blocks_editor_script', |
| 115 |
'bBlocksAdmin', // Array containing dynamic data for a JS Global. |
| 116 |
array( |
| 117 |
'pluginDirPath' => plugin_dir_path( __DIR__ ), |
| 118 |
'pluginDirUrl' => plugin_dir_url( __DIR__ ), |
| 119 |
'siteUrl' => get_site_url(), |
| 120 |
) |
| 121 |
); |
| 122 |
} |
| 123 |
add_action( 'init', 'b_blocks_register' ); |
| 124 |
|
| 125 |
// After Setup Theme |
| 126 |
function b_blocks_after_setup_theme() { |
| 127 |
add_theme_support( 'align-wide' ); |
| 128 |
} |
| 129 |
add_action( 'after_setup_theme', 'b_blocks_after_setup_theme' ); |
| 130 |
|
| 131 |
// Block Initializer. |
| 132 |
require_once plugin_dir_path( __FILE__ ) . 'inc/posts.php'; |