1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Black Studio TinyMCE Widget - Compatibility with WP Page Widget plugin |
4
|
|
|
* |
5
|
|
|
* @package Black_Studio_TinyMCE_Widget |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Black_Studio_TinyMCE_Widget\Compatibility\Plugin; |
9
|
|
|
|
10
|
|
|
// Exit if accessed directly. |
11
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
12
|
|
|
exit; |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
if ( ! class_exists( 'Black_Studio_TinyMCE_Widget\\Compatibility\\Plugin\\Wp_Page_Widget', false ) ) { |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class that provides compatibility code for WP Page Widget plugin |
19
|
|
|
* |
20
|
|
|
* @package Black_Studio_TinyMCE_Widget |
21
|
|
|
* @since 3.0.0 |
22
|
|
|
*/ |
23
|
|
|
final class Wp_Page_Widget { |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The single instance of the class |
27
|
|
|
* |
28
|
|
|
* @var object |
29
|
|
|
* @since 3.0.0 |
30
|
|
|
*/ |
31
|
|
|
protected static $_instance = null; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Return the single class instance |
35
|
|
|
* |
36
|
|
|
* @return object |
37
|
|
|
* @since 3.0.0 |
38
|
|
|
*/ |
39
|
|
|
public static function instance() { |
40
|
|
|
if ( is_null( self::$_instance ) ) { |
41
|
|
|
self::$_instance = new self(); |
42
|
|
|
} |
43
|
|
|
return self::$_instance; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Class constructor |
48
|
|
|
* |
49
|
|
|
* @uses is_admin() |
50
|
|
|
* @uses add_action() |
51
|
|
|
* |
52
|
|
|
* @since 3.0.0 |
53
|
|
|
*/ |
54
|
|
|
protected function __construct() { |
55
|
|
|
if ( is_admin() ) { |
56
|
|
|
add_action( 'admin_init', array( $this, 'admin_init' ) ); |
57
|
|
|
} |
58
|
|
|
if ( ! function_exists( 'is_plugin_active' ) ) { |
59
|
|
|
include_once ABSPATH . 'wp-admin/includes/plugin.php'; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Prevent the class from being cloned |
65
|
|
|
* |
66
|
|
|
* @return void |
67
|
|
|
* @since 3.0.0 |
68
|
|
|
*/ |
69
|
|
|
protected function __clone() { |
70
|
|
|
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ uh?' ), '3.0' ); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Initialize compatibility for WP Page Widget plugin (only for WordPress 3.3+) |
75
|
|
|
* |
76
|
|
|
* @uses add_filter() |
77
|
|
|
* @uses add_action() |
78
|
|
|
* @uses is_plugin_active() |
79
|
|
|
* @uses get_bloginfo() |
80
|
|
|
* |
81
|
|
|
* @return void |
82
|
|
|
* @since 3.0.0 |
83
|
|
|
*/ |
84
|
|
|
public function admin_init() { |
85
|
|
|
if ( is_plugin_active( 'wp-page-widget/wp-page-widgets.php' ) && version_compare( get_bloginfo( 'version' ), '3.3', '>=' ) ) { |
86
|
|
|
add_filter( 'black_studio_tinymce_enable_pages', array( $this, 'enable_pages' ) ); |
87
|
|
|
add_action( 'admin_print_scripts', array( $this, 'enqueue_script' ) ); |
88
|
|
|
add_filter( 'black_studio_tinymce_widget_update', array( $this, 'add_data' ), 10, 2 ); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Enable filter for WP Page Widget plugin |
94
|
|
|
* |
95
|
|
|
* @param string[] $pages Array of pages. |
96
|
|
|
* @return string[] |
97
|
|
|
* @since 3.0.0 |
98
|
|
|
*/ |
99
|
|
|
public function enable_pages( $pages ) { |
100
|
|
|
$action = filter_input( INPUT_GET, 'action' ); |
101
|
|
|
$page = filter_input( INPUT_GET, 'page' ); |
102
|
|
|
$pages[] = 'post-new.php'; |
103
|
|
|
$pages[] = 'post.php'; |
104
|
|
|
if ( 'edit' === $action ) { |
105
|
|
|
$pages[] = 'edit-tags.php'; |
106
|
|
|
} |
107
|
|
|
if ( in_array( $page, array( 'pw-front-page', 'pw-search-page' ), true ) ) { // Input var ok. |
108
|
|
|
$pages[] = 'admin.php'; |
109
|
|
|
} |
110
|
|
|
return $pages; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Add WP Page Widget marker |
115
|
|
|
* |
116
|
|
|
* @param mixed[] $instance Widget instance. |
117
|
|
|
* @param object $widget Widget object. |
118
|
|
|
* @return mixed[] |
119
|
|
|
* @since 3.0.0 |
120
|
|
|
*/ |
121
|
|
|
public function add_data( $instance, $widget ) { |
122
|
|
|
if ( bstw()->check_widget( $widget ) && ! empty( $instance ) ) { |
123
|
|
|
$action = filter_input( INPUT_POST, 'action' ); |
124
|
|
|
if ( 'pw-save-widget' === $action ) { |
125
|
|
|
$instance['wp_page_widget'] = true; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
return $instance; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Enqueue script for WP Page Widget plugin |
133
|
|
|
* |
134
|
|
|
* @uses apply_filters() |
135
|
|
|
* @uses wp_enqueue_script() |
136
|
|
|
* @uses plugins_url() |
137
|
|
|
* @uses SCRIPT_DEBUG |
138
|
|
|
* |
139
|
|
|
* @return void |
140
|
|
|
* @since 3.0.0 |
141
|
|
|
*/ |
142
|
|
|
public function enqueue_script() { |
143
|
|
|
$main_script = apply_filters( 'black_studio_tinymce_widget_script', 'black-studio-tinymce-widget' ); |
144
|
|
|
$compat_script = 'js/compatibility/plugin/wp-page-widget'; |
145
|
|
|
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.js' : '.min.js'; |
146
|
|
|
wp_enqueue_script( |
147
|
|
|
$compat_script, |
148
|
|
|
plugins_url( $compat_script . $suffix, dirname( dirname( dirname( __FILE__ ) ) ) ), |
149
|
|
|
array( 'jquery', 'editor', 'quicktags', $main_script ), |
150
|
|
|
bstw()->get_version(), |
151
|
|
|
true |
152
|
|
|
); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
} // END class |
156
|
|
|
|
157
|
|
|
} // END class_exists |
158
|
|
|
|