| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Advanced Post Block |
| 4 |
* Description: Enhance your WordPress posts with customizable layouts, responsive design, and feature-rich elements. |
| 5 |
* Version: 2.5.0 |
| 6 |
* Author: bPlugins |
| 7 |
* Author URI: https://bplugins.com |
| 8 |
* Plugin URI: https://bplugins.com/products/advanced-post-block |
| 9 |
* License: GPLv3 |
| 10 |
* License URI: https://www.gnu.org/licenses/gpl-3.0.txt |
| 11 |
* Text Domain: advanced-post-block |
| 12 |
* Requires at least: 6.5 |
| 13 |
* Tested up to: 7.1 |
| 14 |
* Requires PHP: 7.4 |
| 15 |
*/ |
| 16 |
|
| 17 |
// ABS PATH |
| 18 |
if ( !defined( 'ABSPATH' ) ) { exit; } |
| 19 |
|
| 20 |
if ( function_exists( 'apb_fs' ) ) { |
| 21 |
apb_fs()->set_basename( true, __FILE__ ); |
| 22 |
}else{ |
| 23 |
define( 'APB_VERSION', ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? time() : '2.5.0' ); |
| 24 |
define( 'APB_DIR_URL', plugin_dir_url( __FILE__ ) ); |
| 25 |
define( 'APB_DIR_PATH', plugin_dir_path( __FILE__ ) ); |
| 26 |
define( 'APB_OPTIONS_KEY', 'apb_options' ); |
| 27 |
|
| 28 |
require_once APB_DIR_PATH . 'includes/fs-lite.php'; |
| 29 |
require_once APB_DIR_PATH . 'includes/admin/CPT.php'; |
| 30 |
require_once APB_DIR_PATH . 'includes/Posts.php'; |
| 31 |
require_once APB_DIR_PATH . 'includes/Tracker.php'; |
| 32 |
require_once APB_DIR_PATH . 'includes/Ajax.php'; |
| 33 |
require_once APB_DIR_PATH . 'includes/Options.php'; |
| 34 |
require_once APB_DIR_PATH . 'includes/Templates/Templates.php'; |
| 35 |
|
| 36 |
if( !class_exists( 'APBPlugin' ) ){ |
| 37 |
/** |
| 38 |
* APBPlugin class |
| 39 |
* Main plugin class responsible for initialization, enqueuing assets, and registering block types. |
| 40 |
* |
| 41 |
* @package APB |
| 42 |
*/ |
| 43 |
class APBPlugin{ |
| 44 |
/** |
| 45 |
* Constructor. |
| 46 |
* Registers hooks for plugin initialization and asset enqueuing. |
| 47 |
*/ |
| 48 |
public function __construct(){ |
| 49 |
add_action( 'init', [$this, 'onInit'] ); |
| 50 |
add_filter( 'block_categories_all', [$this, 'blockCategories'] ); |
| 51 |
add_action( 'admin_enqueue_scripts', [$this, 'adminEnqueueScripts'] ); |
| 52 |
add_action( 'enqueue_block_editor_assets', [$this, 'enqueueBlockEditorAssets'] ); |
| 53 |
add_action( 'enqueue_block_assets', [$this, 'enqueueBlockAssets'] ); |
| 54 |
|
| 55 |
add_filter( 'plugin_action_links', [$this, 'pluginActionLinks'], 10, 2 ); |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Adds custom action links to the plugin entry on the plugins page. |
| 60 |
* |
| 61 |
* @param array $links The existing action links. |
| 62 |
* @param string $file The plugin file name. |
| 63 |
* @return array Modified action links. |
| 64 |
*/ |
| 65 |
public function pluginActionLinks( $links, $file ) { |
| 66 |
if( plugin_basename( __FILE__ ) === $file ) { |
| 67 |
$helpDemosLink = admin_url( 'edit.php?post_type=apb&page=advanced-post-block#/welcome' ); |
| 68 |
|
| 69 |
$links['help-and-demos'] = sprintf( '<a href="%s" style="%s">%s</a>', $helpDemosLink, 'color:#FF7A00;font-weight:bold', __( 'Help & Demos', 'advanced-post-block' ) ); |
| 70 |
} |
| 71 |
|
| 72 |
return $links; |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Initializes the plugin by registering the block type. |
| 77 |
* |
| 78 |
* @return void |
| 79 |
*/ |
| 80 |
public function onInit(){ |
| 81 |
register_block_type( __DIR__ . '/build' ); |
| 82 |
|
| 83 |
// Core registers the block.json script translations without a path, which |
| 84 |
// only resolves against WP_LANG_DIR — point them at the bundled JSON files. |
| 85 |
wp_set_script_translations( 'ap-block-posts-editor-script', 'advanced-post-block', APB_DIR_PATH . 'languages' ); |
| 86 |
wp_set_script_translations( 'ap-block-posts-view-script', 'advanced-post-block', APB_DIR_PATH . 'languages' ); |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* Registers custom block categories. |
| 91 |
* |
| 92 |
* @param array $categories The existing block categories. |
| 93 |
* @return array Modified block categories. |
| 94 |
*/ |
| 95 |
public function blockCategories( $categories ){ |
| 96 |
return array_merge( [ [ |
| 97 |
'slug' => 'APBlock', |
| 98 |
'title' => 'Advanced Post Block' |
| 99 |
] ], $categories ); |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Enqueues scripts and styles for the admin dashboard. |
| 104 |
* |
| 105 |
* @param string $hook The current admin page hook. |
| 106 |
* @return void |
| 107 |
*/ |
| 108 |
public function adminEnqueueScripts( $hook ) { |
| 109 |
if( strpos( $hook, 'advanced-post-block' ) ){ |
| 110 |
wp_enqueue_style( 'apb-admin-dashboard', APB_DIR_URL . 'build/admin/dashboard.css', [], APB_VERSION ); |
| 111 |
|
| 112 |
$asset_file = include APB_DIR_PATH . 'build/admin/dashboard.asset.php'; |
| 113 |
wp_enqueue_script( 'apb-admin-dashboard', APB_DIR_URL . 'build/admin/dashboard.js', array_merge( $asset_file['dependencies'], [ 'wp-util' ] ), APB_VERSION, true ); |
| 114 |
wp_set_script_translations( 'apb-admin-dashboard', 'advanced-post-block', APB_DIR_PATH . 'languages' ); |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* Enqueues assets for the block editor. |
| 120 |
* |
| 121 |
* @return void |
| 122 |
*/ |
| 123 |
public function enqueueBlockEditorAssets(){ |
| 124 |
wp_add_inline_script( 'ap-block-posts-editor-script', sprintf( |
| 125 |
'const apbpricingurl = %s;', |
| 126 |
wp_json_encode( admin_url( 'edit.php?post_type=apb&page=advanced-post-block#/pricing' ) ) |
| 127 |
), 'before' ); |
| 128 |
|
| 129 |
wp_enqueue_script( 'apb-template-library-script', APB_DIR_URL . 'build/template-library.js', [ 'wp-api', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-dom-ready', 'wp-i18n', 'wp-util', 'react', 'react-dom' ], APB_VERSION, false ); |
| 130 |
wp_set_script_translations( 'apb-template-library-script', 'advanced-post-block', APB_DIR_PATH . 'languages' ); |
| 131 |
|
| 132 |
wp_enqueue_style( 'apb-template-library-style', APB_DIR_URL . 'build/template-library.css', [], APB_VERSION ); |
| 133 |
|
| 134 |
wp_add_inline_script('apb-template-library-script', 'const apbtemplatenonce = "' . wp_create_nonce( 'apb_template' ) . '";', 'before' ); |
| 135 |
} |
| 136 |
|
| 137 |
/** |
| 138 |
* Enqueues assets shared by the editor and frontend. |
| 139 |
* |
| 140 |
* @return void |
| 141 |
*/ |
| 142 |
public function enqueueBlockAssets(){ |
| 143 |
wp_register_script( 'easyTicker', APB_DIR_URL . 'public/js/easy-ticker.min.js', [ 'jquery' ], '3.2.1', true ); |
| 144 |
wp_set_script_translations( 'easyTicker', 'advanced-post-block', APB_DIR_PATH . 'languages' ); |
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* Renders the dashboard container for the React app. |
| 149 |
* |
| 150 |
* @return void |
| 151 |
*/ |
| 152 |
public static function renderDashboard(){ ?> |
| 153 |
<div |
| 154 |
id='apbDashboard' |
| 155 |
data-info='<?php echo esc_attr( wp_json_encode( [ |
| 156 |
'version' => APB_VERSION, |
| 157 |
'deleteDataOnUninstall' => (bool) \APB\Options::getOptions()['delete_data_on_uninstall'], |
| 158 |
'uninstallNonce' => wp_create_nonce( 'apbSaveUninstallOption' ), |
| 159 |
] ) ); ?>' |
| 160 |
></div> |
| 161 |
<?php } |
| 162 |
} |
| 163 |
new APBPlugin(); |
| 164 |
} |
| 165 |
} |