|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Admin Page Framework |
|
4
|
|
|
* |
|
5
|
|
|
* http://en.michaeluno.jp/admin-page-framework/ |
|
6
|
|
|
* Copyright (c) 2013-2015 Michael Uno; Licensed MIT |
|
7
|
|
|
* |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Provides an abstract base to create an automatic script insertion class. |
|
12
|
|
|
* |
|
13
|
|
|
* @since 3.3.0 |
|
14
|
|
|
* @since 3.5.3 Extends `AdminPageFramework_WPUtility`. |
|
15
|
|
|
* @since DEVVER Ranamed from `AdminPageFramework_Script_Base`. |
|
16
|
|
|
* @package AdminPageFramework |
|
17
|
|
|
* @subpackage JavaScript |
|
18
|
|
|
* @internal |
|
19
|
|
|
* @extends AdminPageFramework_WPUtility |
|
20
|
|
|
*/ |
|
21
|
|
|
abstract class AdminPageFramework_Factory___Script_Base extends AdminPageFramework_WPUtility { |
|
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Stores the enqueued script class names. |
|
25
|
|
|
* |
|
26
|
|
|
* @since 3.3.0 |
|
27
|
|
|
*/ |
|
28
|
|
|
static public $_aEnqueued = array(); |
|
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
public $oMsg; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Sets up hooks and properties. |
|
34
|
|
|
* |
|
35
|
|
|
* It will enqueue the scrip in the footer. |
|
36
|
|
|
* |
|
37
|
|
|
* @since 3.3.0 |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct( $oMsg=null ) { |
|
40
|
|
|
|
|
41
|
|
|
$_sClassName = get_class( $this ); |
|
42
|
|
|
if ( in_array( $_sClassName, self::$_aEnqueued ) ) { |
|
43
|
|
|
return; |
|
44
|
|
|
} |
|
45
|
|
|
self::$_aEnqueued[ $_sClassName ] = $_sClassName; |
|
46
|
|
|
$this->oMsg = $oMsg ? $oMsg : AdminPageFramework_Message::getInstance(); |
|
47
|
|
|
|
|
48
|
|
|
// add_action( 'customize_controls_print_footer_scripts', array( $this, '_replyToPrintScript' ) ); |
|
|
|
|
|
|
49
|
|
|
$this->registerAction( |
|
50
|
|
|
'customize_controls_print_footer_scripts', |
|
51
|
|
|
array( $this, '_replyToPrintScript' ) |
|
52
|
|
|
); |
|
53
|
|
|
|
|
54
|
|
|
$this->registerAction( |
|
55
|
|
|
'admin_footer', |
|
56
|
|
|
array( $this, '_replyToPrintScript' ) |
|
57
|
|
|
); |
|
58
|
|
|
|
|
59
|
|
|
$this->construct(); |
|
60
|
|
|
|
|
61
|
|
|
$this->registerAction( 'wp_enqueue_scripts', array( $this, 'load' ) ); |
|
62
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* The user constructor. |
|
67
|
|
|
* |
|
68
|
|
|
* Enqueue dependencies with this method. |
|
69
|
|
|
* |
|
70
|
|
|
* @remark This should be overridden in extended classes. |
|
71
|
|
|
* @since 3.3.0 |
|
72
|
|
|
* @since DEVVER Changed the visibility scope from protected. |
|
73
|
|
|
* @return void |
|
74
|
|
|
*/ |
|
75
|
|
|
public function construct() {} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @callback wp_enqueue_script |
|
79
|
|
|
* @since DEVVER |
|
80
|
|
|
*/ |
|
81
|
|
|
public function load() {} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Prints the script. |
|
85
|
|
|
* |
|
86
|
|
|
* @since 3.3.0 |
|
87
|
|
|
* @internal |
|
88
|
|
|
* @return string The generated HTML script tag. |
|
89
|
|
|
* @callback action admin_footer |
|
90
|
|
|
* @callback action customize_controls_print_footer_scripts |
|
91
|
|
|
*/ |
|
92
|
|
|
public function _replyToPrintScript() { |
|
|
|
|
|
|
93
|
|
|
$_sScript = $this->getScript( $this->oMsg ); |
|
94
|
|
|
if ( ! $_sScript ) { |
|
95
|
|
|
return; |
|
96
|
|
|
} |
|
97
|
|
|
echo "<script type='text/javascript' class='" . strtolower( get_class( $this ) ) . "'>" |
|
98
|
|
|
. '/* <![CDATA[ */' |
|
99
|
|
|
. $_sScript |
|
100
|
|
|
. '/* ]]> */' |
|
101
|
|
|
. "</script>"; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Returns an inline JavaScript script. |
|
106
|
|
|
* |
|
107
|
|
|
* @remark Extended classes just override this method and return the script. |
|
108
|
|
|
* @since 3.3.0 |
|
109
|
|
|
* @param $oMsg object The message object. |
|
110
|
|
|
* @return string The inline JavaScript script. |
|
111
|
|
|
*/ |
|
112
|
|
|
static public function getScript( /* $oMsg */ ) { |
|
|
|
|
|
|
113
|
|
|
$_aParams = func_get_args() + array( null ); |
|
114
|
|
|
$_oMsg = $_aParams[ 0 ]; |
|
|
|
|
|
|
115
|
|
|
return ""; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
} |
|
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.