| 1 |
<?php |
| 2 |
/** |
| 3 |
* |
| 4 |
* Plugin Name: ThemeZee Widget Bundle |
| 5 |
* Plugin URI: https://themezee.com/plugins/widget-bundle/ |
| 6 |
* Description: A collection of our most popular widgets, neatly bundled into a single plugin. The Plugin includes advanced widgets for Recent Posts, Recent Comments, Tabbed Content, Social Icons and more. |
| 7 |
* Author: ThemeZee |
| 8 |
* Author URI: https://themezee.com/ |
| 9 |
* Version: 1.7 |
| 10 |
* Text Domain: themezee-widget-bundle |
| 11 |
* Domain Path: /languages/ |
| 12 |
* License: GNU General Public License v2 or later |
| 13 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html |
| 14 |
* |
| 15 |
* @package ThemeZee Widget Bundle |
| 16 |
* Copyright(C) 2025, ThemeZee.com - support@themezee.com |
| 17 |
*/ |
| 18 |
|
| 19 |
// Exit if accessed directly. |
| 20 |
if ( ! defined( 'ABSPATH' ) ) { |
| 21 |
exit; |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Main ThemeZee_Widget_Bundle Class |
| 26 |
* |
| 27 |
* @package ThemeZee Widget Bundle |
| 28 |
*/ |
| 29 |
class ThemeZee_Widget_Bundle { |
| 30 |
|
| 31 |
/** |
| 32 |
* Call all Functions to setup the Plugin |
| 33 |
* |
| 34 |
* @uses ThemeZee_Widget_Bundle::constants() Setup the constants needed |
| 35 |
* @uses ThemeZee_Widget_Bundle::includes() Include the required files |
| 36 |
* @uses ThemeZee_Widget_Bundle::setup_actions() Setup the hooks and actions |
| 37 |
* @return void |
| 38 |
*/ |
| 39 |
static function setup() { |
| 40 |
|
| 41 |
// Setup Constants. |
| 42 |
self::constants(); |
| 43 |
|
| 44 |
// Setup Translation. |
| 45 |
add_action( 'plugins_loaded', array( __CLASS__, 'translation' ) ); |
| 46 |
|
| 47 |
// Include Files. |
| 48 |
self::includes(); |
| 49 |
|
| 50 |
// Setup Action Hooks. |
| 51 |
self::setup_actions(); |
| 52 |
|
| 53 |
// Disables the block editor from managing widgets in the Gutenberg plugin. |
| 54 |
add_filter( 'gutenberg_use_widgets_block_editor', '__return_false' ); |
| 55 |
|
| 56 |
// Disables the block editor from managing widgets. |
| 57 |
add_filter( 'use_widgets_block_editor', '__return_false' ); |
| 58 |
|
| 59 |
// Add Admin Notice on widgets screen. |
| 60 |
add_action( 'admin_notices', array( __CLASS__, 'widgets_admin_notice' ) ); |
| 61 |
|
| 62 |
// Dismiss Notice. |
| 63 |
add_action( 'init', array( __CLASS__, 'dismiss_notice' ) ); |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Setup plugin constants |
| 68 |
* |
| 69 |
* @return void |
| 70 |
*/ |
| 71 |
static function constants() { |
| 72 |
|
| 73 |
// Define Plugin Name. |
| 74 |
define( 'TZWB_NAME', 'ThemeZee Widget Bundle' ); |
| 75 |
|
| 76 |
// Define Version Number. |
| 77 |
define( 'TZWB_VERSION', '1.7' ); |
| 78 |
|
| 79 |
// Plugin Folder Path. |
| 80 |
define( 'TZWB_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
| 81 |
|
| 82 |
// Plugin Folder URL. |
| 83 |
define( 'TZWB_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); |
| 84 |
|
| 85 |
// Plugin Root File. |
| 86 |
define( 'TZWB_PLUGIN_FILE', __FILE__ ); |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* Load Translation File |
| 91 |
* |
| 92 |
* @return void |
| 93 |
*/ |
| 94 |
static function translation() { |
| 95 |
|
| 96 |
load_plugin_textdomain( 'themezee-widget-bundle', false, dirname( plugin_basename( TZWB_PLUGIN_FILE ) ) . '/languages/' ); |
| 97 |
|
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* Include required files |
| 102 |
* |
| 103 |
* @return void |
| 104 |
*/ |
| 105 |
static function includes() { |
| 106 |
|
| 107 |
// Include Admin Classes. |
| 108 |
require_once TZWB_PLUGIN_DIR . '/includes/admin/class-themezee-plugins-page.php'; |
| 109 |
|
| 110 |
// Include Settings Classes. |
| 111 |
require_once TZWB_PLUGIN_DIR . '/includes/settings/class-tzwb-settings.php'; |
| 112 |
require_once TZWB_PLUGIN_DIR . '/includes/settings/class-tzwb-settings-page.php'; |
| 113 |
|
| 114 |
// Include Widget Classes. |
| 115 |
require_once TZWB_PLUGIN_DIR . '/includes/widgets/widget-recent-comments.php'; |
| 116 |
require_once TZWB_PLUGIN_DIR . '/includes/widgets/widget-recent-posts.php'; |
| 117 |
require_once TZWB_PLUGIN_DIR . '/includes/widgets/widget-social-icons.php'; |
| 118 |
require_once TZWB_PLUGIN_DIR . '/includes/widgets/widget-tabbed-content.php'; |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* Setup Action Hooks |
| 123 |
* |
| 124 |
* @see https://codex.wordpress.org/Function_Reference/add_action WordPress Codex |
| 125 |
* @return void |
| 126 |
*/ |
| 127 |
static function setup_actions() { |
| 128 |
|
| 129 |
// Include active modules |
| 130 |
add_action( 'init', array( __CLASS__, 'modules' ), 12 ); |
| 131 |
|
| 132 |
// Register all widgets. |
| 133 |
add_action( 'widgets_init', array( __CLASS__, 'register_widgets' ) ); |
| 134 |
|
| 135 |
// Enqueue Frontend Widget Styles. |
| 136 |
add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_styles' ) ); |
| 137 |
|
| 138 |
// Enqueue Scripts and Styles on widgets admin screen. |
| 139 |
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_admin_scripts' ) ); |
| 140 |
|
| 141 |
// Register Image Sizes. |
| 142 |
add_action( 'init', array( __CLASS__, 'add_image_size' ) ); |
| 143 |
|
| 144 |
// Add Settings link to Plugin actions. |
| 145 |
add_filter( 'plugin_action_links_' . plugin_basename( TZWB_PLUGIN_FILE ), array( __CLASS__, 'plugin_action_links' ) ); |
| 146 |
|
| 147 |
// Add Widget Bundle Box to Plugin Overview Page. |
| 148 |
add_action( 'themezee_plugins_overview_page', array( __CLASS__, 'plugin_overview_page' ) ); |
| 149 |
} |
| 150 |
|
| 151 |
/** |
| 152 |
* Include active Modules |
| 153 |
* |
| 154 |
* @return void |
| 155 |
*/ |
| 156 |
static function modules() { |
| 157 |
|
| 158 |
// Get Plugin Options |
| 159 |
$options = TZWB_Settings::instance(); |
| 160 |
|
| 161 |
// Include Widget Visibility class unless it is already activated with Jetpack or Toolkit plugin. |
| 162 |
if ( true === $options->get( 'widget_visibility' ) and ! class_exists( 'Jetpack_Widget_Conditions' ) and ! class_exists( 'TZTK_Widget_Visibility' ) ) : |
| 163 |
|
| 164 |
require TZWB_PLUGIN_DIR . '/includes/modules/class-tzwb-widget-visibility.php'; |
| 165 |
|
| 166 |
endif; |
| 167 |
} |
| 168 |
|
| 169 |
/** |
| 170 |
* Register Widgets |
| 171 |
* |
| 172 |
* @return void |
| 173 |
*/ |
| 174 |
static function register_widgets() { |
| 175 |
|
| 176 |
// Get Settings. |
| 177 |
$instance = TZWB_Settings::instance(); |
| 178 |
$options = $instance->get_all(); |
| 179 |
|
| 180 |
// Register Widgets if enabled. |
| 181 |
if ( true == $options['recent_comments'] ) : |
| 182 |
register_widget( 'TZWB_Recent_Comments_Widget' ); |
| 183 |
endif; |
| 184 |
|
| 185 |
if ( true == $options['recent_posts'] ) : |
| 186 |
register_widget( 'TZWB_Recent_Posts_Widget' ); |
| 187 |
endif; |
| 188 |
|
| 189 |
if ( true == $options['social_icons'] ) : |
| 190 |
register_widget( 'TZWB_Social_Icons_Widget' ); |
| 191 |
endif; |
| 192 |
|
| 193 |
if ( true == $options['tabbed_content'] ) : |
| 194 |
register_widget( 'TZWB_Tabbed_Content_Widget' ); |
| 195 |
endif; |
| 196 |
} |
| 197 |
|
| 198 |
/** |
| 199 |
* Enqueue Widget Styles |
| 200 |
* |
| 201 |
* @return void |
| 202 |
*/ |
| 203 |
static function enqueue_styles() { |
| 204 |
|
| 205 |
// Return early if theme handles styling. |
| 206 |
if ( current_theme_supports( 'themezee-widget-bundle' ) ) : |
| 207 |
return; |
| 208 |
endif; |
| 209 |
|
| 210 |
// Load stylesheet only if widgets are active. |
| 211 |
if ( is_active_widget( 'TZWB_Recent_Comments_Widget', false, 'tzwb-recent-comments' ) |
| 212 |
or is_active_widget( 'TZWB_Recent_Posts_Widget', false, 'tzwb-recent-posts' ) |
| 213 |
or is_active_widget( 'TZWB_Social_Icons_Widget', false, 'tzwb-social-icons' ) |
| 214 |
or is_active_widget( 'TZWB_Tabbed_Content_Widget', false, 'tzwb-tabbed-content' ) |
| 215 |
) : |
| 216 |
|
| 217 |
// Enqueue Plugin Stylesheet. |
| 218 |
wp_enqueue_style( 'themezee-widget-bundle', TZWB_PLUGIN_URL . 'assets/css/themezee-widget-bundle.css', array(), TZWB_VERSION ); |
| 219 |
|
| 220 |
endif; |
| 221 |
} |
| 222 |
|
| 223 |
/** |
| 224 |
* Enqueue Admin Styles |
| 225 |
* |
| 226 |
* @param string $hook Hook suffix for the current admin page. |
| 227 |
* @return void |
| 228 |
*/ |
| 229 |
static function enqueue_admin_scripts( $hook ) { |
| 230 |
|
| 231 |
// Embed Widget Highlight only on widget page. |
| 232 |
if ( 'widgets.php' != $hook ) : |
| 233 |
return; |
| 234 |
endif; |
| 235 |
|
| 236 |
wp_enqueue_style( 'tzwb-widget-bgcolor', TZWB_PLUGIN_URL . 'assets/css/tzwb-widget-bgcolor.css', array(), TZWB_VERSION ); |
| 237 |
} |
| 238 |
|
| 239 |
/** |
| 240 |
* Add custom image size for post thumbnails in widgets |
| 241 |
* |
| 242 |
* @return void |
| 243 |
*/ |
| 244 |
static function add_image_size() { |
| 245 |
|
| 246 |
// Check if theme defines custom image size. |
| 247 |
if ( current_theme_supports( 'themezee-widget-bundle' ) ) : |
| 248 |
|
| 249 |
$theme_support = get_theme_support( 'themezee-widget-bundle' ); |
| 250 |
|
| 251 |
// Set custom image size. |
| 252 |
if ( isset( $theme_support[0]['thumbnail_size'] ) && is_array( $theme_support[0]['thumbnail_size'] ) ) : |
| 253 |
|
| 254 |
$thumbnail_size = $theme_support[0]['thumbnail_size']; |
| 255 |
add_image_size( 'tzwb-thumbnail', $thumbnail_size[0], $thumbnail_size[1], true ); |
| 256 |
|
| 257 |
endif; |
| 258 |
|
| 259 |
else : |
| 260 |
|
| 261 |
// Set default image size. |
| 262 |
add_image_size( 'tzwb-thumbnail', 80, 80, true ); |
| 263 |
|
| 264 |
endif; |
| 265 |
} |
| 266 |
|
| 267 |
/** |
| 268 |
* Add Settings link to the plugin actions |
| 269 |
* |
| 270 |
* @param array $actions Array of all plugin action links. |
| 271 |
* @return array $actions Plugin action links |
| 272 |
*/ |
| 273 |
static function plugin_action_links( $actions ) { |
| 274 |
|
| 275 |
$settings_link = array( 'settings' => sprintf( '<a href="%s">%s</a>', admin_url( 'options-general.php?page=themezee-plugins&tab=widgets' ), esc_html__( 'Settings', 'themezee-widget-bundle' ) ) ); |
| 276 |
|
| 277 |
return array_merge( $settings_link, $actions ); |
| 278 |
} |
| 279 |
|
| 280 |
/** |
| 281 |
* Add widget bundle box to plugin overview admin page |
| 282 |
* |
| 283 |
* @return void |
| 284 |
*/ |
| 285 |
static function plugin_overview_page() { |
| 286 |
|
| 287 |
$plugin_data = get_plugin_data( __FILE__ ); |
| 288 |
?> |
| 289 |
|
| 290 |
<dl> |
| 291 |
<dt> |
| 292 |
<h4><?php echo esc_html( $plugin_data['Name'] ); ?></h4> |
| 293 |
<span><?php printf( esc_html__( 'Version %s', 'themezee-widget-bundle' ), esc_html( $plugin_data['Version'] ) ); ?></span> |
| 294 |
</dt> |
| 295 |
<dd> |
| 296 |
<p><?php echo wp_kses_post( $plugin_data['Description'] ); ?><br/></p> |
| 297 |
<a href="<?php echo admin_url( 'options-general.php?page=themezee-plugins&tab=widgets' ); ?>" class="button button-primary"><?php esc_html_e( 'Plugin Settings', 'themezee-widget-bundle' ); ?></a> |
| 298 |
<a href="<?php echo esc_url( 'https://themezee.com/docs/widget-bundle-documentation/?utm_source=plugin-overview&utm_medium=button&utm_campaign=widget-bundle&utm_content=documentation' ); ?>" class="button button-secondary" target="_blank"><?php esc_html_e( 'View Documentation', 'themezee-widget-bundle' ); ?></a> |
| 299 |
</dd> |
| 300 |
</dl> |
| 301 |
|
| 302 |
<?php |
| 303 |
} |
| 304 |
|
| 305 |
/** |
| 306 |
* Display admin notice on widgets screen. |
| 307 |
* |
| 308 |
* @return void |
| 309 |
*/ |
| 310 |
static function widgets_admin_notice() { |
| 311 |
global $pagenow; |
| 312 |
|
| 313 |
if ( in_array( $pagenow, array( 'widgets.php' ) ) && ! isset( $_GET['page'] ) && ! get_transient( 'tzwb_admin_notice_dismissed' ) && current_user_can( 'manage_options' ) ) : ?> |
| 314 |
|
| 315 |
<div class="notice notice-info"> |
| 316 |
<p> |
| 317 |
<?php esc_html_e( 'ThemeZee Widget Bundle is not compatible with Blocks and therefore shows the Classic Widgets Editor screen.', 'themezee-widget-bundle' ); ?> |
| 318 |
<a href="<?php echo wp_nonce_url( add_query_arg( array( 'tzwb_admin_notice_action' => 'dismiss_notice', 'tzwb_admin_notice_transient' => 'dismissed' ) ), 'tzwb_admin_notice_dismiss', 'tzwb_admin_notice_dismiss_nonce' ); ?>"><?php _e( 'Dismiss Notice', 'themezee-widget-bundle' ); ?></a> |
| 319 |
</p> |
| 320 |
</div> |
| 321 |
|
| 322 |
<?php |
| 323 |
endif; |
| 324 |
} |
| 325 |
|
| 326 |
/** |
| 327 |
* Dismiss admin notices when Dismiss links are clicked |
| 328 |
* |
| 329 |
* @return void |
| 330 |
*/ |
| 331 |
static function dismiss_notice() { |
| 332 |
|
| 333 |
// Return early if tzwb_admin_notice_action was not fired. |
| 334 |
if ( ! isset( $_REQUEST['tzwb_admin_notice_action'] ) ) { |
| 335 |
return; |
| 336 |
} |
| 337 |
|
| 338 |
if ( ! isset( $_GET['tzwb_admin_notice_dismiss_nonce'] ) || ! wp_verify_nonce( $_GET['tzwb_admin_notice_dismiss_nonce'], 'tzwb_admin_notice_dismiss' ) ) { |
| 339 |
wp_die( __( 'Security check failed', 'themezee-widget-bundle' ), __( 'Error', 'themezee-widget-bundle' ), array( 'response' => 403 ) ); |
| 340 |
} |
| 341 |
|
| 342 |
if ( isset( $_GET['tzwb_admin_notice_transient'] ) ) { |
| 343 |
set_transient( 'tzwb_admin_notice_' . $_GET['tzwb_admin_notice_transient'], 1, DAY_IN_SECONDS * 90 ); |
| 344 |
wp_redirect( remove_query_arg( array( 'tzwb_admin_notice_action', 'tzwb_admin_notice_transient', 'tzwb_admin_notice_dismiss_nonce' ) ) ); |
| 345 |
exit; |
| 346 |
} |
| 347 |
} |
| 348 |
} |
| 349 |
|
| 350 |
// Run Plugin. |
| 351 |
ThemeZee_Widget_Bundle::setup(); |
| 352 |
|