| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Button Block |
| 4 |
* Description: Implement multi-functional button |
| 5 |
* Version: 1.0.3 |
| 6 |
* Author: bPlugins LLC |
| 7 |
* Author URI: http://bplugins.com |
| 8 |
* License: GPLv3 |
| 9 |
* License URI: https://www.gnu.org/licenses/gpl-3.0.txt |
| 10 |
* Text Domain: button-block |
| 11 |
*/ |
| 12 |
|
| 13 |
// ABS PATH |
| 14 |
if ( !defined( 'ABSPATH' ) ) { exit; } |
| 15 |
|
| 16 |
// Constant |
| 17 |
define( 'BTN_PLUGIN_VERSION', isset( $_SERVER['HTTP_HOST'] ) && 'localhost' === $_SERVER['HTTP_HOST'] ? time() : '1.0.3' ); |
| 18 |
define( 'BTN_ASSETS_DIR', plugin_dir_url( __FILE__ ) . 'assets/' ); |
| 19 |
|
| 20 |
// Button Block |
| 21 |
class BTNButtonBlock{ |
| 22 |
function __construct(){ |
| 23 |
add_action( 'init', [$this, 'onInit'] ); |
| 24 |
add_action( 'enqueue_block_assets', [$this, 'enqueueBlockAssets'] ); |
| 25 |
} |
| 26 |
|
| 27 |
function enqueueBlockAssets(){ |
| 28 |
wp_enqueue_style( 'fontAwesome', BTN_ASSETS_DIR . 'css/fontAwesome.min.css', [], '5.15.4' ); |
| 29 |
wp_enqueue_style( 'aos', BTN_ASSETS_DIR . 'css/aos.css', [], '3.0.0' ); |
| 30 |
|
| 31 |
wp_enqueue_script( 'aos', BTN_ASSETS_DIR . 'js/aos.js', [], '3.0.0', true ); |
| 32 |
} |
| 33 |
|
| 34 |
function onInit() { |
| 35 |
wp_register_style( 'btn-button-editor-style', plugins_url( 'dist/editor.css', __FILE__ ), [ 'wp-edit-blocks' ], BTN_PLUGIN_VERSION ); // Backend Style |
| 36 |
wp_register_style( 'btn-button-style', plugins_url( 'dist/style.css', __FILE__ ), [], BTN_PLUGIN_VERSION ); // Frontend Style |
| 37 |
|
| 38 |
register_block_type( __DIR__, [ |
| 39 |
'editor_style' => 'btn-button-editor-style', |
| 40 |
'style' => 'btn-button-style', |
| 41 |
'render_callback' => [$this, 'render'] |
| 42 |
] ); // Register Block |
| 43 |
|
| 44 |
wp_set_script_translations( 'btn-button-editor-script', 'button-block', plugin_dir_path( __FILE__ ) . 'languages' ); // Translate |
| 45 |
} |
| 46 |
|
| 47 |
function render( $attributes ){ |
| 48 |
extract( $attributes ); |
| 49 |
|
| 50 |
$className = $className ?? ''; |
| 51 |
$btnBlockClassName = 'wp-block-btn-button ' . $className . ' align' . $align; |
| 52 |
|
| 53 |
ob_start(); ?> |
| 54 |
<div class='<?php echo esc_attr( $btnBlockClassName ); ?>' id='btnButton-<?php echo esc_attr( $cId ) ?>' data-attributes='<?php echo esc_attr( wp_json_encode( $attributes ) ); ?>'></div> |
| 55 |
|
| 56 |
<?php return ob_get_clean(); |
| 57 |
} // Render |
| 58 |
} |
| 59 |
new BTNButtonBlock; |