| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Plugin Name: Button Block |
| 5 |
* Description: Implement multi-functional button |
| 6 |
* Version: 1.1.8 |
| 7 |
* Author: bPlugins |
| 8 |
* Author URI: http://bplugins.com |
| 9 |
* License: GPLv3 |
| 10 |
* License URI: https://www.gnu.org/licenses/gpl-3.0.txt |
| 11 |
* Text Domain: button-block |
| 12 |
*/ |
| 13 |
// ABS PATH |
| 14 |
if ( !defined( 'ABSPATH' ) ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
if ( function_exists( 'btn_fs' ) ) { |
| 18 |
register_activation_hook( __FILE__, function () { |
| 19 |
if ( is_plugin_active( 'button-block/index.php' ) ) { |
| 20 |
deactivate_plugins( 'button-block/index.php' ); |
| 21 |
} |
| 22 |
if ( is_plugin_active( 'button-block-pro/index.php' ) ) { |
| 23 |
deactivate_plugins( 'button-block-pro/index.php' ); |
| 24 |
} |
| 25 |
} ); |
| 26 |
} else { |
| 27 |
// Constant |
| 28 |
define( 'BTN_VERSION', ( isset( $_SERVER['HTTP_HOST'] ) && 'localhost' === $_SERVER['HTTP_HOST'] ? time() : '1.1.8' ) ); |
| 29 |
define( 'BTN_DIR_URL', plugin_dir_url( __FILE__ ) ); |
| 30 |
define( 'BTN_DIR_PATH', plugin_dir_path( __FILE__ ) ); |
| 31 |
define( 'BTN_HAS_FREE', 'button-block/index.php' === plugin_basename( __FILE__ ) ); |
| 32 |
define( 'BTN_HAS_PRO', 'button-block-pro/index.php' === plugin_basename( __FILE__ ) ); |
| 33 |
if ( !function_exists( 'btn_fs' ) ) { |
| 34 |
function btn_fs() { |
| 35 |
global $btn_fs; |
| 36 |
if ( !isset( $btn_fs ) ) { |
| 37 |
$fsStartPath = dirname( __FILE__ ) . '/freemius/start.php'; |
| 38 |
$bSDKInitPath = dirname( __FILE__ ) . '/bplugins_sdk/init.php'; |
| 39 |
if ( file_exists( $fsStartPath ) ) { |
| 40 |
require_once $fsStartPath; |
| 41 |
} else { |
| 42 |
if ( file_exists( $bSDKInitPath ) ) { |
| 43 |
require_once $bSDKInitPath; |
| 44 |
} |
| 45 |
} |
| 46 |
$btnConfig = [ |
| 47 |
'id' => '13491', |
| 48 |
'slug' => 'button-block', |
| 49 |
'premium_slug' => 'button-block-pro', |
| 50 |
'type' => 'plugin', |
| 51 |
'public_key' => 'pk_8fb5be7805414bb29e5b06c24566a', |
| 52 |
'is_premium' => false, |
| 53 |
'premium_suffix' => 'Pro', |
| 54 |
'has_premium_version' => true, |
| 55 |
'has_addons' => false, |
| 56 |
'has_paid_plans' => true, |
| 57 |
'trial' => [ |
| 58 |
'days' => 7, |
| 59 |
'is_require_payment' => true, |
| 60 |
], |
| 61 |
'has_affiliation' => 'all', |
| 62 |
'menu' => [ |
| 63 |
'slug' => 'edit.php?post_type=button-block', |
| 64 |
'contact' => false, |
| 65 |
'support' => false, |
| 66 |
], |
| 67 |
]; |
| 68 |
$btn_fs = ( file_exists( $fsStartPath ) ? fs_dynamic_init( $btnConfig ) : fs_lite_dynamic_init( $btnConfig ) ); |
| 69 |
} |
| 70 |
return $btn_fs; |
| 71 |
} |
| 72 |
|
| 73 |
btn_fs(); |
| 74 |
do_action( 'btn_fs_loaded' ); |
| 75 |
} |
| 76 |
require_once BTN_DIR_PATH . 'includes/AdminMenu.php'; |
| 77 |
require_once BTN_DIR_PATH . 'includes/CustomPost.php'; |
| 78 |
if ( BTN_HAS_PRO ) { |
| 79 |
require_once BTN_DIR_PATH . 'includes/EmailLead.php'; |
| 80 |
} |
| 81 |
function btnIsPremium() { |
| 82 |
return ( BTN_HAS_PRO ? btn_fs()->can_use_premium_code() : false ); |
| 83 |
} |
| 84 |
|
| 85 |
// Button Block |
| 86 |
if ( !class_exists( 'BTNPlugin' ) ) { |
| 87 |
class BTNPlugin { |
| 88 |
function __construct() { |
| 89 |
add_action( 'enqueue_block_assets', [$this, 'enqueueBlockAssets'] ); |
| 90 |
add_action( 'init', [$this, 'onInit'] ); |
| 91 |
add_action( 'wp_ajax_btnPipeChecker', [$this, 'btnPipeChecker'] ); |
| 92 |
add_action( 'wp_ajax_nopriv_btnPipeChecker', [$this, 'btnPipeChecker'] ); |
| 93 |
add_action( 'admin_init', [$this, 'registerSettings'] ); |
| 94 |
add_action( 'rest_api_init', [$this, 'registerSettings'] ); |
| 95 |
add_action( 'wp_ajax_btnUserRoles', [$this, 'userRoles'] ); |
| 96 |
add_action( 'wp_ajax_nopriv_btnUserRoles', [$this, 'userRoles'] ); |
| 97 |
} |
| 98 |
|
| 99 |
function enqueueBlockAssets() { |
| 100 |
wp_register_style( |
| 101 |
'fontAwesome', |
| 102 |
BTN_DIR_URL . 'public/css/font-awesome.min.css', |
| 103 |
[], |
| 104 |
'6.4.2' |
| 105 |
); |
| 106 |
wp_register_style( |
| 107 |
'aos', |
| 108 |
BTN_DIR_URL . 'public/css/aos.css', |
| 109 |
[], |
| 110 |
'3.0.0' |
| 111 |
); |
| 112 |
wp_register_script( |
| 113 |
'aos', |
| 114 |
BTN_DIR_URL . 'public/js/aos.js', |
| 115 |
[], |
| 116 |
'3.0.0', |
| 117 |
true |
| 118 |
); |
| 119 |
} |
| 120 |
|
| 121 |
function onInit() { |
| 122 |
register_block_type( __DIR__ . '/build' ); |
| 123 |
} |
| 124 |
|
| 125 |
function btnPipeChecker() { |
| 126 |
$nonce = $_POST['_wpnonce']; |
| 127 |
if ( !wp_verify_nonce( $nonce, 'wp_ajax' ) ) { |
| 128 |
wp_send_json_error( 'Invalid Request' ); |
| 129 |
} |
| 130 |
wp_send_json_success( [ |
| 131 |
'isPipe' => btnIsPremium(), |
| 132 |
] ); |
| 133 |
} |
| 134 |
|
| 135 |
function registerSettings() { |
| 136 |
register_setting( 'btnUtils', 'btnUtils', [ |
| 137 |
'show_in_rest' => [ |
| 138 |
'name' => 'btnUtils', |
| 139 |
'schema' => [ |
| 140 |
'type' => 'string', |
| 141 |
], |
| 142 |
], |
| 143 |
'type' => 'string', |
| 144 |
'default' => wp_json_encode( [ |
| 145 |
'nonce' => wp_create_nonce( 'wp_ajax' ), |
| 146 |
] ), |
| 147 |
'sanitize_callback' => 'sanitize_text_field', |
| 148 |
] ); |
| 149 |
} |
| 150 |
|
| 151 |
function userRoles() { |
| 152 |
$nonce = $_POST['_wpnonce'] ?? null; |
| 153 |
if ( !wp_verify_nonce( $nonce, 'wp_ajax' ) ) { |
| 154 |
wp_send_json_error( 'Invalid Request' ); |
| 155 |
} |
| 156 |
global $wp_roles; |
| 157 |
wp_send_json_success( $wp_roles->get_names() ); |
| 158 |
} |
| 159 |
|
| 160 |
} |
| 161 |
|
| 162 |
new BTNPlugin(); |
| 163 |
} |
| 164 |
} |