Php 在wordpress插件类中将钩子从构造函数更改为init-不再工作
在WordPress的早期版本(>5)中,插件工作正常。当我将它转移到更新的WordPress(v5.xx)网站时 它给了我一个错误“visaBooking类没有init方法” 我将钩子初始化从_construct()更改为init()。现在错误消失了,但是短代码不再工作了Php 在wordpress插件类中将钩子从构造函数更改为init-不再工作,php,wordpress,class,oop,init,Php,Wordpress,Class,Oop,Init,在WordPress的早期版本(>5)中,插件工作正常。当我将它转移到更新的WordPress(v5.xx)网站时 它给了我一个错误“visaBooking类没有init方法” 我将钩子初始化从_construct()更改为init()。现在错误消失了,但是短代码不再工作了 function visaBooking() { return visaBooking::instance(); } add_action( 'plugins_loaded', 'visaBooking' );
function visaBooking() {
return visaBooking::instance();
}
add_action( 'plugins_loaded', 'visaBooking' );
class visaBooking{
private static $_instance = null;
private $categories = array();
private $pricing = array();
private $discount = array();
private $insurance = array();
private $pricingDetails = array();
public static function instance() {
if ( is_null( self::$_instance ) )
self::$_instance = new self();
return self::$_instance;
} // End instance()
public function __construct(){
# Read countries json file
$countriesFile = plugin_dir_url( __FILE__ ).'countries.json';
$countriesFileResponse = wp_remote_get( $countriesFile );
$countriesFileBody = json_decode( $countriesFileResponse['body'] , true );
if( $this->isJson( $countriesFileResponse['body'] ) ){
$categories = json_decode( $countriesFileResponse['body'] , true );
if( !empty( $categories ) ){
foreach( $categories as $category ){
switch( $category['Price Type'] ){
case 'Medium':
$newCategory['medium'][] = $category['Country Codes'];
break;
case 'Expensive':
$newCategory['expensive'][] = $category['Country Codes'];
break;
case 'Cheaper':
$newCategory['cheaper'][] = $category['Country Codes'];
break;
}
}
$this->categories = $newCategory;
}
}
# Read services json file
$file = plugin_dir_url( __FILE__ ).'config.json';
$response = wp_remote_get( $file );
#$body = json_decode( $response['body'] , true );
if( $this->isJson( $response['body'] ) ){
$this->pricing = json_decode( $response['body'] , true );
}
}
public function init () {
add_action( 'template_redirect', array( $this, 'initialization' ) );
# Get price shortcode
add_shortcode( 'visa-booking-price' , array( $this, 'visaBookingPrice' ) );
# Get form shortcode
add_shortcode( 'visa-booking-form' , array( $this, 'visaBookingForm' ) );
add_filter( 'gform_pre_render', array( $this, 'modifyPricing' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'enqueueScript') );
add_action('wp_head', array( $this, 'enqueueJs') );
add_filter( 'gform_enable_field_label_visibility_settings', '__return_true' );
add_filter('gform_replace_merge_tags', array( $this, 'replace_merge_tag_code' ), 10, 7);
add_action( 'gform_admin_pre_render', array( $this, 'add_merge_tags' ) );
add_filter( 'gform_shortcode_conditional', array( $this, 'gform_shortcode_conditional_custom' ), 10, 3 );
add_shortcode('page_number', function(){
return $_POST['page_number'];
});
add_filter( 'gform_confirmation', array( $this, 'hide_boxed' ), 10, 4 );
add_shortcode('template_header', function($args){
ob_start();
include( plugin_dir_path( __FILE__ )."email-templates/header.php");
$text = ob_get_clean();
return do_shortcode($text);
});
add_shortcode('order_details', function($args){
$temp = array(
'form_id' => 1,
'entry_id' => 1,
'isadmin' => 'false'
);
$args = array_merge( $temp, $args );
ob_start();
switch($args['type']){
case 'flight';
include( plugin_dir_path( __FILE__ )."email-templates/flight-order-details.php");
break;
case 'hotel';
include( plugin_dir_path( __FILE__ )."email-templates/hotel-order-details.php");
break;
case 'flight-hotel';
include( plugin_dir_path( __FILE__ )."email-templates/flight-hotel-order-details.php");
break;
case 'flight-hotel-insurance';
include( plugin_dir_path( __FILE__ )."email-templates/flight-hotel-insurance-order-details.php");
break;
case 'insurance';
include( plugin_dir_path( __FILE__ )."email-templates/insurance-order-details.php");
break;
}
$entry = GFAPI::get_entry( $args['entry_id'] );
$form = GFAPI::get_form( $args['form_id'] );
$text = ob_get_clean();
$text = GFCommon::replace_variables( $text, $form, $entry, false, false, false, 'html' );
return do_shortcode($text);
});
add_shortcode('template_footer', function($args){
ob_start();
include( plugin_dir_path( __FILE__ )."email-templates/footer.php");
$text = ob_get_clean();
return do_shortcode($text);
});
}
我原以为它现在可以顺利运行,但如上所述,现在短代码不起作用。您在类中引用的这个方法是否确实存在?是的,由于不必要的代码,我没有复制它们