admin管理员组文章数量:1277273
new here and to wordpress plugins development, go easy on me :D
Anyway, I am trying to create a new plugin and I am getting a 500 error.
I changed WP_DEBUG
in config.php to true in order to see what is causing the 500 error and got this message:
Fatal error: Uncaught Error: Call to undefined function is_woocommerce() in...
This is my code currently:
<?php
/**
* Plugin Name:
* Plugin URI:
* Description:
* Author:
* Author URI:
* Version: 1.0
* Text Domain:
*
* Copyright: (c) 2018
*
* License:
* License URI:
*
* @author
* @copyright Copyright (c) 2018
* @license
*
*/
//
defined( 'ABSPATH' ) or exit;
if (function_exists(is_woocommerce())) {
echo "test: ".is_woocommerce();
} else {
echo "test: Function does not exists!";
}
If you need any more information, tell me and I'll edit the question. Help will be appreciated, thanks!
new here and to wordpress plugins development, go easy on me :D
Anyway, I am trying to create a new plugin and I am getting a 500 error.
I changed WP_DEBUG
in config.php to true in order to see what is causing the 500 error and got this message:
Fatal error: Uncaught Error: Call to undefined function is_woocommerce() in...
This is my code currently:
<?php
/**
* Plugin Name:
* Plugin URI:
* Description:
* Author:
* Author URI:
* Version: 1.0
* Text Domain:
*
* Copyright: (c) 2018
*
* License:
* License URI:
*
* @author
* @copyright Copyright (c) 2018
* @license
*
*/
//
defined( 'ABSPATH' ) or exit;
if (function_exists(is_woocommerce())) {
echo "test: ".is_woocommerce();
} else {
echo "test: Function does not exists!";
}
If you need any more information, tell me and I'll edit the question. Help will be appreciated, thanks!
Share Improve this question asked Jul 22, 2018 at 11:58 OmerOmer 1491 gold badge4 silver badges14 bronze badges 6 | Show 1 more comment2 Answers
Reset to default 3If you want to check one Plugin's Function / Class etc. from another Plugin, then it's best to use a hook like plugins_loaded
.
Based on this, your Plugin CODE will look like:
<?php
/*
Plugin Name: YOUR PLUGIN NAME
*/
defined( 'ABSPATH' ) or exit;
add_action( 'plugins_loaded', 'plugin_prefix_woocommerce_check' );
function plugin_prefix_woocommerce_check() {
if( function_exists( 'is_woocommerce' ) ) {
add_action( "wp_footer", "wpse_woocommerce_exists" );
}
else {
add_action( "wp_footer", "wpse_woocommerce_doesnt_exist" );
}
}
function wpse_woocommerce_exists() {
echo "<h1>WooCommerce Exists!</h1>";
}
function wpse_woocommerce_doesnt_exist() {
echo "<h1>WooCommerce Doesn't Exists!</h1>";
}
Directly checking other plugin functions will often lead to error, since WordPress may not be done loading other plugins by the time your CODE executes. However, when WordPress is done, it'll fire the plugins_loaded
hook.
Check Plugin Development Guide for more information on how to develop a WordPress Plugin.
This may or may not be a relevant answer.
However, I was receiving a very similar error after updating the Divi theme.
Uncaught Error: Call to undefined function et_is_woocommerce_plugin_active()
I deleted the old Divi directory in the theme directory and replaced with the new Divi directory.
I tend to also delete the directory /wp-content/et-cache
as well, when updating Divi.
Anyways, long story short, I ran this WP CLI command after updating the Divi theme.
wp transient delete --all --skip-packages --skip-themes --skip-plugins
The error was immediately resolved, and the updated Divi theme was functioning as expected once again.
本文标签: pluginsWooCommerceCall to undefined function iswoocommerce()
版权声明:本文标题:plugins - WooCommerce - Call to undefined function is_woocommerce() 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741293768a2370699.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
function_exists
correctly secure.php/function_exists – mmm Commented Jul 22, 2018 at 12:26function_exists
but I am getting false onif (function_exists('is_woocommerce'))
– Omer Commented Jul 22, 2018 at 13:44