Mu-plugin causes entire site to crash

Closed. This question is off-topic. It is not currently accepting answers.Questions that are too localized (such as synt

Closed. This question is off-topic. It is not currently accepting answers.

Questions that are too localized (such as syntax errors, code with restricted access, hacked sites, hosting or support issues) are not in scope. See how do I ask a good question?

Closed 5 years ago.

Improve this question

I think i'm probably doing something daft here. Every time i try to include this as a mu-plugin it takes down the test site though.

<?php
if( is_plugin_active( '/public_html/wp-content/plugins/wordfence.php' ) ) {
    require_once('wp-load.php');
    $to = ‘[email protected]’;
    $subject = ‘Wordfence is down’;
    $message = ‘Wordfence is not active’;
    $headers = array('Content-Type: text/html; charset=UTF-8');
    wp_mail( $to, $subject, $message, $headers );
}

Any ideas where i'm going wrong would be very much appreciated :)

Closed. This question is off-topic. It is not currently accepting answers.

Questions that are too localized (such as syntax errors, code with restricted access, hacked sites, hosting or support issues) are not in scope. See how do I ask a good question?

Closed 5 years ago.

Improve this question

I think i'm probably doing something daft here. Every time i try to include this as a mu-plugin it takes down the test site though.

<?php
if( is_plugin_active( '/public_html/wp-content/plugins/wordfence.php' ) ) {
    require_once('wp-load.php');
    $to = ‘[email protected]’;
    $subject = ‘Wordfence is down’;
    $message = ‘Wordfence is not active’;
    $headers = array('Content-Type: text/html; charset=UTF-8');
    wp_mail( $to, $subject, $message, $headers );
}

Any ideas where i'm going wrong would be very much appreciated :)

Share Improve this question asked May 20, 2019 at 12:39 Peter KirwanPeter Kirwan 31 bronze badge 2
  • Debugging always needs to be done you. Try to accomplish this systematically. Delete line by line of your snippet until you get the line that's causing the problem. Then check the official docs of the function that's causing the problem and fix it. You might also check/search the WordPress core for similar usages. – norman.lol Commented May 20, 2019 at 13:18
  • Cough curly quotes cough. :) – rudtek Commented May 21, 2019 at 14:28
Add a comment  | 

2 Answers 2

Reset to default 1

is_plugin_active isn't available for mu-plugins to use. The codex says:

NOTE: defined in wp-admin/includes/plugin.php, so this is only available from within the admin pages, and any references to this function must be hooked to admin_init or a later action. If you want to use this function from within a template or a must-use plugin, you will need to manually require plugin.php, an example is below.

And I think there must be better ways to solve this anyway: your code will try and send you an email for every non-static HTTP request to the site, and you probably meant !is_plugin_active or is_plugin_inactive, and in any case these accept relative paths to the plugin files not absolute paths.

It's best to turn on WP_DEBUG to see exactly what problem you're facing. The code above includes fancy quotes like and and doesn't include the full path to wp-load.php.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745480156a4629522.html

相关推荐

  • Mu-plugin causes entire site to crash

    Closed. This question is off-topic. It is not currently accepting answers.Questions that are too localized (such as synt

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信