尽管添加了“构造(),我还是得到了错误-”;在PHP的未来版本中,与类同名的方法将不会是构造函数;
尽管添加了_construct(),但我还是发现了一个不推荐使用的错误:在PHP的未来版本中,与类同名的方法将不会成为构造函数 这是一个wordpress插件[代码-尽管添加了“构造(),我还是得到了错误-”;在PHP的未来版本中,与类同名的方法将不会是构造函数;,php,wordpress,Php,Wordpress,尽管添加了_construct(),但我还是发现了一个不推荐使用的错误:在PHP的未来版本中,与类同名的方法将不会成为构造函数 这是一个wordpress插件[代码- jQuery(文档).ready(函数(){ if(jQuery('#timestampdiv').length>0){ jQuery('#timestampdiv')。find('div')) .append(“”) .append(jQuery(“”) .attr('class','now button') .append(
jQuery(文档).ready(函数(){
if(jQuery('#timestampdiv').length>0){
jQuery('#timestampdiv')。find('div'))
.append(“”)
.append(jQuery(“”)
.attr('class','now button')
.append(“”)
);
}
if(jQuery('.inline edit date')。长度>0){
jQuery('.inline edit date').find('div'))
.append(“”)
.append(jQuery(“”)
.attr('class','now button')
.append(“”)
);
}
jQuery('.now.button').bind('click',function(){
如果(jQuery('select[name=“mm”]').length>0)jQuery('select[name=“mm”]').val('');
if(jQuery('input[name=“jj”]').length>0)jQuery('input[name=“jj”]').val(“”);
if(jQuery('input[name=“aa”]')).length>0)jQuery('input[name=“aa”]')).val(“”);
if(jQuery('input[name=“hh”]').length>0)jQuery('input[name=“hh”]').val(“”);
if(jQuery('input[name=“mn”]').length>0)jQuery('input[name=“mn”]').val('');
});
});
您可以将方法名称更改为\uuuu-construct()
。请尝试像公共函数\uuuu-construct()
一样声明方法的可见性(对于其他方法也是如此)
jQuery(文档).ready(函数(){
if(jQuery('#timestampdiv').length>0){
jQuery('#timestampdiv')。find('div'))
.append(“”)
.append(jQuery(“”)
.attr('class','now button')
.append(“”)
);
}
if(jQuery('.inline edit date')。长度>0){
jQuery('.inline edit date').find('div'))
.append(“”)
.append(jQuery(“”)
.attr('class','now button')
.append(“”)
);
}
jQuery('.now.button').bind('click',function(){
如果(jQuery('select[name=“mm”]').length>0)jQuery('select[name=“mm”]').val('');
if(jQuery('input[name=“jj”]').length>0)jQuery('input[name=“jj”]').val(“”);
if(jQuery('input[name=“aa”]')).length>0)jQuery('input[name=“aa”]')).val(“”);
if(jQuery('input[name=“hh”]').length>0)jQuery('input[name=“hh”]').val(“”);
if(jQuery('input[name=“mn”]').length>0)jQuery('input[name=“mn”]').val('');
});
});
谢谢你,安迪。很抱歉迟了回复。你认为wordpress插件esp添加公共函数构造()
,安全性方面这段代码可以吗?我认为从安全角度来看这很好。\u构造
可能不应该用于添加操作,我用$class->run()编辑了我的答案
取而代之-但这只是一个最佳做法。安全建议:添加esc\u html\u e
而不是\u e
。这只是防止通过翻译文件进行XSS攻击。(例如
)。如果需要,您可以排队并本地化脚本(),但这不是安全问题。
<?php
/*
Author: radiok
Plugin Name: Date/Time Now Button
Author URI: http://radiok.info/
Plugin URI: http://radiok.info/blog/category/datetime-now-button/
Description: Adds a Now button to the right of date and time fields.
Version: 0.2.2
Text Domain: datetime-now-button
Domain Path: /languages
*/
if ( !class_exists( 'DateTimeNowButtonPlugin' ) ) {
class DateTimeNowButtonPlugin {
function DateTimeNowButtonPlugin() {
add_action( 'init', array( $this, 'InitI18n' ), 10, 1 );
add_action( 'admin_head', array($this, 'AddNowButton' ), 10, 1 );
}
function InitI18n() {
// Place your language file in the languages subfolder and name it "datetime-now-button-{language}.mo" replace {language} with your language value from wp-config.php
load_plugin_textdomain( 'datetime-now-button', FALSE, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
function AddNowButton() {
?>
<script type="text/javascript">
jQuery(document).ready(function() {
if (jQuery('#timestampdiv').length > 0) {
jQuery('#timestampdiv').find('div')
.append(' ')
.append(jQuery('<a>')
.attr('class', 'now button')
.append('<?php _e( 'Now', 'datetime-now-button' ); ?>')
);
}
if (jQuery('.inline-edit-date').length > 0) {
jQuery('.inline-edit-date').find('div')
.append(' ')
.append(jQuery('<a>')
.attr('class', 'now button')
.append('<?php _e( 'Now', 'datetime-now-button' ); ?>')
);
}
jQuery('.now.button').bind('click', function() {
<?php
$time_adj = current_time('timestamp');
$cur_mm = gmdate( 'm', $time_adj );
$cur_jj = gmdate( 'd', $time_adj );
$cur_aa = gmdate( 'Y', $time_adj );
$cur_hh = gmdate( 'H', $time_adj );
$cur_mn = gmdate( 'i', $time_adj );
?>
if (jQuery('select[name="mm"]').length > 0) jQuery('select[name="mm"]').val('<?php echo $cur_mm; ?>');
if (jQuery('input[name="jj"]').length > 0) jQuery('input[name="jj"]').val('<?php echo $cur_jj; ?>');
if (jQuery('input[name="aa"]').length > 0) jQuery('input[name="aa"]').val('<?php echo $cur_aa; ?>');
if (jQuery('input[name="hh"]').length > 0) jQuery('input[name="hh"]').val('<?php echo $cur_hh; ?>');
if (jQuery('input[name="mn"]').length > 0) jQuery('input[name="mn"]').val('<?php echo $cur_mn; ?>');
});
});
</script>
<?php
}
}
}
if ( class_exists( 'DateTimeNowButtonPlugin' ) ) $date_time_now_button = new DateTimeNowButtonPlugin();
<?php
/*
Author: radiok
Plugin Name: Date/Time Now Button
Author URI: http://radiok.info/
Plugin URI: http://radiok.info/blog/category/datetime-now-button/
Description: Adds a Now button to the right of date and time fields.
Version: 0.2.2
Text Domain: datetime-now-button
Domain Path: /languages
*/
if ( !class_exists( 'DateTimeNowButtonPlugin' ) ) {
class DateTimeNowButtonPlugin {
public function run() {
add_action( 'init', array( $this, 'InitI18n' ), 10, 1 );
add_action( 'admin_head', array($this, 'AddNowButton' ), 10, 1 );
}
public function InitI18n() {
// Place your language file in the languages subfolder and name it "datetime-now-button-{language}.mo" replace {language} with your language value from wp-config.php
load_plugin_textdomain( 'datetime-now-button', FALSE, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
public function AddNowButton() {
?>
<script type="text/javascript">
jQuery(document).ready(function() {
if (jQuery('#timestampdiv').length > 0) {
jQuery('#timestampdiv').find('div')
.append(' ')
.append(jQuery('<a>')
.attr('class', 'now button')
.append('<?php _e( 'Now', 'datetime-now-button' ); ?>')
);
}
if (jQuery('.inline-edit-date').length > 0) {
jQuery('.inline-edit-date').find('div')
.append(' ')
.append(jQuery('<a>')
.attr('class', 'now button')
.append('<?php _e( 'Now', 'datetime-now-button' ); ?>')
);
}
jQuery('.now.button').bind('click', function() {
<?php
$time_adj = current_time('timestamp');
$cur_mm = gmdate( 'm', $time_adj );
$cur_jj = gmdate( 'd', $time_adj );
$cur_aa = gmdate( 'Y', $time_adj );
$cur_hh = gmdate( 'H', $time_adj );
$cur_mn = gmdate( 'i', $time_adj );
?>
if (jQuery('select[name="mm"]').length > 0) jQuery('select[name="mm"]').val('<?php echo $cur_mm; ?>');
if (jQuery('input[name="jj"]').length > 0) jQuery('input[name="jj"]').val('<?php echo $cur_jj; ?>');
if (jQuery('input[name="aa"]').length > 0) jQuery('input[name="aa"]').val('<?php echo $cur_aa; ?>');
if (jQuery('input[name="hh"]').length > 0) jQuery('input[name="hh"]').val('<?php echo $cur_hh; ?>');
if (jQuery('input[name="mn"]').length > 0) jQuery('input[name="mn"]').val('<?php echo $cur_mn; ?>');
});
});
</script>
<?php
}
}
}
if ( class_exists( 'DateTimeNowButtonPlugin' ) ) {
$date_time_now_button = new DateTimeNowButtonPlugin();
$date_time_now_button->run();
}