PluginProbe
Content Slider Block – bring your content to life with slides / trunk
Content Slider Block – bring your content to life with slides vtrunk
3.2.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 2.0.0 2.0.1 2.0.2 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 All 30 releases
content-slider-block / plugin.php

plugin.php in Content Slider Block – bring your content to life with slides trunk, at plugin.php

182 lines 6.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Content Slider Block
4 * Description: Display your goal to your visitor in bountiful way with content slider block.
5 * Version: 3.2.1
6 * Author: bPlugins
7 * Author URI: https://bplugins.com
8 * Plugin URI: https://bplugins.com/products/content-slider-block
9 * License: GPLv3
10 * License URI: https://www.gnu.org/licenses/gpl-3.0.txt
11 * Text Domain: content-slider-block
12 * Requires at least: 6.5
13 * Tested up to: 7.1
14 * Requires PHP: 7.4
15 * @fs_premium_only /vendor/freemius, /includes/fs.php, /includes/admin/CPT.php, includes/LicenseActivation.php, /build/admin/post.asset.php, /build/admin/post.css, /build/admin/post.js
16 * @fs_free_only /vendor/freemius-lite, /includes/fs-lite.php, /includes/admin/SubMenu.php
17 */
18
19 // ABS PATH
20 if ( !defined( 'ABSPATH' ) ) { exit; }
21
22 if ( function_exists( 'csb_fs' ) ) {
23 csb_fs()->set_basename( true, __FILE__ );
24 }else{
25 // Constant
26 define( 'CSB_VERSION', ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? time() : '3.2.1' );
27 define( 'CSB_DIR_URL', plugin_dir_url( __FILE__ ) );
28 define( 'CSB_DIR_PATH', plugin_dir_path( __FILE__ ) );
29
30 require_once CSB_DIR_PATH . 'includes/fs-lite.php';
31 require_once CSB_DIR_PATH . 'includes/admin/SubMenu.php';
32
33 if( !class_exists( 'CSBPlugin' ) ){
34 /**
35 * Class CSBPlugin
36 *
37 * Main initialization class for the Content Slider Block plugin.
38 *
39 * @since 1.0.0
40 */
41 class CSBPlugin{
42 /**
43 * CSBPlugin constructor.
44 *
45 * Registers plugin hooks, filters, and scripts.
46 *
47 * @since 1.0.0
48 */
49 function __construct(){
50 add_action( 'init', [ $this, 'onInit' ] );
51 add_filter( 'block_categories_all', [$this, 'blockCategories'] );
52 add_action( 'admin_enqueue_scripts', [ $this, 'adminEnqueueScripts' ] );
53 add_action( 'enqueue_block_editor_assets', [$this, 'enqueueBlockEditorAssets'] );
54
55 add_filter( 'plugin_action_links', [$this, 'pluginActionLinks'], 10, 2 );
56 add_filter( 'default_title', [$this, 'defaultTitle'], 10, 2 );
57 add_filter( 'default_content', [$this, 'defaultContent'], 10, 2 );
58 }
59
60 /**
61 * Filters the default post title when creating a new page from the dashboard link.
62 *
63 * @since 1.0.0
64 * @param string $title The default post title.
65 * @param WP_Post $post The post object.
66 * @return string The filtered post title.
67 */
68 function defaultTitle( $title, $post ) {
69 if ( 'page' === $post->post_type && isset( $_GET['title'] ) ) {
70 $nonce = isset( $_GET['nonce'] ) ? sanitize_text_field( wp_unslash( $_GET['nonce'] ) ) : '';
71
72 if ( wp_verify_nonce( $nonce, 'csbCreatePage' ) ) {
73 return sanitize_text_field( wp_unslash( $_GET['title'] ) );
74 }
75 }
76 return $title;
77 }
78
79 /**
80 * Filters the default post content when creating a new page from the dashboard link.
81 *
82 * @since 1.0.0
83 * @param string $content The default post content.
84 * @param WP_Post $post The post object.
85 * @return string The filtered post content.
86 */
87 function defaultContent( $content, $post ) {
88 if ( 'page' === $post->post_type && isset( $_GET['content'] ) ) {
89 $nonce = isset( $_GET['nonce'] ) ? sanitize_text_field( wp_unslash( $_GET['nonce'] ) ) : '';
90
91 if ( wp_verify_nonce( $nonce, 'csbCreatePage' ) ) {
92 return wp_kses_post( wp_unslash( $_GET['content'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
93 }
94 }
95 return $content;
96 }
97
98 /**
99 * Adds action links to the plugin listing in the admin area.
100 *
101 * @since 1.0.0
102 * @param array $links An array of plugin action links.
103 * @param string $file Path to the plugin file relative to the plugins directory.
104 * @return array The filtered array of plugin action links.
105 */
106 function pluginActionLinks( $links, $file ) {
107 if( plugin_basename( __FILE__ ) === $file ) {
108 $helpDemosLink = admin_url( 'tools.php?page=content-slider-block#/welcome' );
109
110 $links['help-and-demos'] = sprintf( '<a href="%s" style="%s">%s</a>', $helpDemosLink, 'color:#FF7A00;font-weight:bold', __( 'Help & Demos', 'content-slider-block' ) );
111 }
112
113 return $links;
114 }
115
116 /**
117 * Initializes the plugin by registering block types.
118 *
119 * @since 1.0.0
120 */
121 function onInit(){
122 register_block_type( __DIR__ . '/build' );
123 }
124
125 /**
126 * Adds a custom block category for Content Slider blocks.
127 *
128 * @since 1.0.0
129 * @param array $categories Array of block categories.
130 * @return array The filtered block categories.
131 */
132 function blockCategories( $categories ){
133 return array_merge( [[
134 'slug' => 'CSBlock',
135 'title' => 'Content Slider Block',
136 ] ], $categories );
137 } // Categories
138
139 /**
140 * Enqueues CSS and JavaScript for the admin dashboard.
141 *
142 * @since 1.0.0
143 * @param string $hook The current admin page hook.
144 */
145 function adminEnqueueScripts( $hook ) {
146 if( strpos( $hook, 'content-slider-block' ) ){
147 wp_enqueue_style( 'csb-admin-dashboard', CSB_DIR_URL . 'build/admin/dashboard.css', [], CSB_VERSION );
148
149 $asset_file = include CSB_DIR_PATH . 'build/admin/dashboard.asset.php';
150 wp_enqueue_script( 'csb-admin-dashboard', CSB_DIR_URL . 'build/admin/dashboard.js', array_merge( $asset_file['dependencies'], [ 'wp-util' ] ), CSB_VERSION, true );
151 wp_set_script_translations( 'csb-admin-dashboard', 'content-slider-block', CSB_DIR_PATH . 'languages' );
152 }
153 }
154
155 /**
156 * Enqueues inline scripts with licensing information for the block editor.
157 *
158 * @since 1.0.0
159 */
160 function enqueueBlockEditorAssets(){
161 wp_add_inline_script( 'csb-content-slider-block-editor-script', 'const csbpricingurl = "'. admin_url( 'tools.php?page=content-slider-block#/pricing' ) .'";', 'before' );
162 }
163
164 /**
165 * Renders the dashboard HTML element where the React application mounts.
166 *
167 * @since 1.0.0
168 */
169 static function renderDashboard(){ ?>
170 <div
171 id='csbDashboard'
172 data-info='<?php echo esc_attr( wp_json_encode( [
173 'version' => CSB_VERSION,
174 'adminUrl' => admin_url(),
175 'startUrl' => admin_url( 'post-new.php?post_type=page&title=' . rawurlencode( 'Content Slider Block' ) . '&content=' . rawurlencode( '<!-- wp:csb/content-slider-block /-->' ) . '&nonce=' . wp_create_nonce( 'csbCreatePage' ) )
176 ] ) ); ?>'
177 ></div>
178 <?php }
179 }
180 new CSBPlugin;
181 }
182 }