admin管理员组文章数量:1130349
I am developing a Woocommerce dependent plugin which works, and a settings page which behaves funky and throws a Class 'WC_Settings_Page' not found Fatal Error
if ( !defined( 'ABSPATH' ) ) {exit;}
if ( !class_exists( 'WooCommerce_Chilexpress_Tags_Settings' ) ) {
class WooCommerce_Chilexpress_Tags_Settings extends WC_Settings_Page{
...
}
function my_plugin_add_settings() {
return new WooCommerce_Chilexpress_Tags_Settings();
}
}
add_filter( 'woocommerce_get_settings_pages', 'my_plugin_add_settings', 15 );
this code is in a includes/mysettings.php which is loaded during the plugin init, which alphabetically is woocommerce-chilexpress-etiquetas, so it should be loaded after woocommerce
For a reason I don't understand yet, my plugin settings are loaded always before WooCommerce Settings though throwing me a PHP Fatal Error:
PHP Fatal error: Class 'WC_Settings_Page' not found
The obvious dirty fix was to insert the WC_Settings_Page code into my own settings. I am trying now to clean this up but somehow it won't work...
So the (yes I know very broad) question is: What could I miss?
I am developing a Woocommerce dependent plugin which works, and a settings page which behaves funky and throws a Class 'WC_Settings_Page' not found Fatal Error
if ( !defined( 'ABSPATH' ) ) {exit;}
if ( !class_exists( 'WooCommerce_Chilexpress_Tags_Settings' ) ) {
class WooCommerce_Chilexpress_Tags_Settings extends WC_Settings_Page{
...
}
function my_plugin_add_settings() {
return new WooCommerce_Chilexpress_Tags_Settings();
}
}
add_filter( 'woocommerce_get_settings_pages', 'my_plugin_add_settings', 15 );
this code is in a includes/mysettings.php which is loaded during the plugin init, which alphabetically is woocommerce-chilexpress-etiquetas, so it should be loaded after woocommerce
For a reason I don't understand yet, my plugin settings are loaded always before WooCommerce Settings though throwing me a PHP Fatal Error:
PHP Fatal error: Class 'WC_Settings_Page' not found
The obvious dirty fix was to insert the WC_Settings_Page code into my own settings. I am trying now to clean this up but somehow it won't work...
So the (yes I know very broad) question is: What could I miss?
Share Improve this question edited Nov 20, 2018 at 18:15 Canelo Digital asked Nov 20, 2018 at 18:01 Canelo DigitalCanelo Digital 1414 bronze badges 2 |2 Answers
Reset to default 6The problem is, by the time your WooCommerce_Chilexpress_Tags_Settings is defined, WC_Settings_Page has indeed not yet loaded; hence you got the fatal error.
And if you want to do it the same way that WooCommerce does it, place the WooCommerce_Chilexpress_Tags_Settings in a separate PHP file, e.g. includes/class-woocommerce-chilexpress-tags-tettings.php, and initialize the class from that file — i.e. return an instance of WooCommerce_Chilexpress_Tags_Settings like so:
<?php
// class-woocommerce-chilexpress-tags-tettings.php
defined( 'ABSPATH' ) || exit;
class WooCommerce_Chilexpress_Tags_Settings extends WC_Settings_Page {
...
}
return new WooCommerce_Chilexpress_Tags_Settings();
and include it from my_plugin_add_settings():
function my_plugin_add_settings( $settings ) {
$settings[] = include 'path/to/includes/class-woocommerce-chilexpress-tags-tettings.php';
return $settings;
}
add_filter( 'woocommerce_get_settings_pages', 'my_plugin_add_settings' );
And if you noticed, you need to return the $settings from my_plugin_add_settings().
See working example: https://gist.github/bekarice/34aaeda2d4729ef87ad7
You should do something like this:
// If this file is called directly, abort.
defined('ABSPATH') or exit();
if ( !class_exists( 'WooCommerce_Chilexpress_Tags_Settings' ) ) {
function my_plugin_add_settings() {
class WooCommerce_Chilexpress_Tags_Settings extends WC_Settings_Page {
// Your class and your code / logic
}
return new WooCommerce_Chilexpress_Tags_Settings();
}
add_filter( 'woocommerce_get_settings_pages', 'my_plugin_add_settings', 15 );
}
I am developing a Woocommerce dependent plugin which works, and a settings page which behaves funky and throws a Class 'WC_Settings_Page' not found Fatal Error
if ( !defined( 'ABSPATH' ) ) {exit;}
if ( !class_exists( 'WooCommerce_Chilexpress_Tags_Settings' ) ) {
class WooCommerce_Chilexpress_Tags_Settings extends WC_Settings_Page{
...
}
function my_plugin_add_settings() {
return new WooCommerce_Chilexpress_Tags_Settings();
}
}
add_filter( 'woocommerce_get_settings_pages', 'my_plugin_add_settings', 15 );
this code is in a includes/mysettings.php which is loaded during the plugin init, which alphabetically is woocommerce-chilexpress-etiquetas, so it should be loaded after woocommerce
For a reason I don't understand yet, my plugin settings are loaded always before WooCommerce Settings though throwing me a PHP Fatal Error:
PHP Fatal error: Class 'WC_Settings_Page' not found
The obvious dirty fix was to insert the WC_Settings_Page code into my own settings. I am trying now to clean this up but somehow it won't work...
So the (yes I know very broad) question is: What could I miss?
I am developing a Woocommerce dependent plugin which works, and a settings page which behaves funky and throws a Class 'WC_Settings_Page' not found Fatal Error
if ( !defined( 'ABSPATH' ) ) {exit;}
if ( !class_exists( 'WooCommerce_Chilexpress_Tags_Settings' ) ) {
class WooCommerce_Chilexpress_Tags_Settings extends WC_Settings_Page{
...
}
function my_plugin_add_settings() {
return new WooCommerce_Chilexpress_Tags_Settings();
}
}
add_filter( 'woocommerce_get_settings_pages', 'my_plugin_add_settings', 15 );
this code is in a includes/mysettings.php which is loaded during the plugin init, which alphabetically is woocommerce-chilexpress-etiquetas, so it should be loaded after woocommerce
For a reason I don't understand yet, my plugin settings are loaded always before WooCommerce Settings though throwing me a PHP Fatal Error:
PHP Fatal error: Class 'WC_Settings_Page' not found
The obvious dirty fix was to insert the WC_Settings_Page code into my own settings. I am trying now to clean this up but somehow it won't work...
So the (yes I know very broad) question is: What could I miss?
Share Improve this question edited Nov 20, 2018 at 18:15 Canelo Digital asked Nov 20, 2018 at 18:01 Canelo DigitalCanelo Digital 1414 bronze badges 2-
I think you need to wrap your entire class declaration (or the file inclusion) in your
my_plugin_add_settings()function: – karpstrucking Commented Nov 20, 2018 at 18:34 - produces unfortunately a PHP Fatal error: Uncaught Error: Class 'WooCommerce_Chilexpress_Tags_Settings' not found – Canelo Digital Commented Nov 20, 2018 at 19:08
2 Answers
Reset to default 6The problem is, by the time your WooCommerce_Chilexpress_Tags_Settings is defined, WC_Settings_Page has indeed not yet loaded; hence you got the fatal error.
And if you want to do it the same way that WooCommerce does it, place the WooCommerce_Chilexpress_Tags_Settings in a separate PHP file, e.g. includes/class-woocommerce-chilexpress-tags-tettings.php, and initialize the class from that file — i.e. return an instance of WooCommerce_Chilexpress_Tags_Settings like so:
<?php
// class-woocommerce-chilexpress-tags-tettings.php
defined( 'ABSPATH' ) || exit;
class WooCommerce_Chilexpress_Tags_Settings extends WC_Settings_Page {
...
}
return new WooCommerce_Chilexpress_Tags_Settings();
and include it from my_plugin_add_settings():
function my_plugin_add_settings( $settings ) {
$settings[] = include 'path/to/includes/class-woocommerce-chilexpress-tags-tettings.php';
return $settings;
}
add_filter( 'woocommerce_get_settings_pages', 'my_plugin_add_settings' );
And if you noticed, you need to return the $settings from my_plugin_add_settings().
See working example: https://gist.github/bekarice/34aaeda2d4729ef87ad7
You should do something like this:
// If this file is called directly, abort.
defined('ABSPATH') or exit();
if ( !class_exists( 'WooCommerce_Chilexpress_Tags_Settings' ) ) {
function my_plugin_add_settings() {
class WooCommerce_Chilexpress_Tags_Settings extends WC_Settings_Page {
// Your class and your code / logic
}
return new WooCommerce_Chilexpress_Tags_Settings();
}
add_filter( 'woocommerce_get_settings_pages', 'my_plugin_add_settings', 15 );
}
本文标签: Plugin vs Settings load order (woocommerce dependency)
版权声明:本文标题:Plugin vs Settings load order (woocommerce dependency) 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749164738a2325984.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


my_plugin_add_settings()function: – karpstrucking Commented Nov 20, 2018 at 18:34