Broken Plugin

  • Unknown's avatar

    my site is conedccmh.wpcomstaging.com

    I have created my own custom plugin called RedirectPlugin

    I uploaded it and activated it. Noticed I needed to add a ! in an if statement and my site completely blew up after activating it again.

    The plugin code is as follows:

    <?php
    /**
    * Plugin Name: Redirect Logged-In Users
    * Description: If a user is already logged in, redirect them to platform
    * Version: 1.0
    * Author: Daniel Steinberg
    */

    class RedirectPlugin {

    public static function initialize() {
    add_action( 'init', self::redirectHandler() );
    }

    public static function redirectHandler() {
    if ( is_user_logged_in() ) {
    if ( !current_user_can( 'edit_posts' ) ) {
    if ( wp_redirect( 'https://www.conedccmh.com/' ) ) {
    exit;
    }
    }
    }
    }
    }

    RedirectPlugin::initialize();
    ?>

    the only change I had made was this line
    if ( current_user_can( 'edit_posts' ) ) {
    to
    if ( !current_user_can( 'edit_posts' ) ) {

    notice the ! added

    I am not sure why this caused catastrophic problems to my site. the error according to the chat agent was

    Call to Undefined function is_user_logged_in() thrown on line 19 which I think is the exit; line

    any help would be appreciated

    The blog I need help with is: (visible only to logged in users)

  • Unknown's avatar

    Hi there FWIW I am able to access your above site.

    As a Business plan user, you are eligible for direct support via Live Chat and email when you post at https://wordpress.com/help/contact rather than needing to post to these public forums. I’ve also gone ahead and tagged this thread for Staff attention and further direction.

  • Hi there,

    Please contact live chat support at the link @justjennifer provided above so we can help with this – fixing this will likely require manually deactivating or manually deleting and reinstalling the plugin on your site, and that’s better done in real time, and with our live chat team who are experienced in fixing issues like this.

  • Unknown's avatar

    I had already contacted them to fix the site back up, which they did. They then directed me here to get help with the plugin itself and to why it is breaking the connection with jetpack. If this is not the right place to get that help can you direct me?

  • This forum is for WordPress.com, where your site is hosted, but for end-users of our free sites. Free sites can’t use plugins at all, so we’re not really able to provide any plugin-related help here, and definitely not development help like what you’re looking for.

    It looks like the chat operator referred you to https://wordpress.org/support/ – that’s the support for the open source WordPress software, and the best place to ask for advice about developing plugins.

    In fact, the advanced subforum is probably best for this, considering this is your own plugin:

    https://wordpress.org/support/forum/wp-advanced/

    You can also try https://wordpress.stackexchange.com/ for developer-related questions.

  • The topic ‘Broken Plugin’ is closed to new replies.