Users running a non-download version of Vanilla (pulled from github), on branch release/2019.016 or master from the last 2 weeks should upgrade to release/2019.017 or latest master for security reasons. Downloaded official open sources releases are not affected.

Plugin not working with 2.5+ (addon.json) format [RESOLVED]

JasonBarnabeJasonBarnabe Cynical Salamander ✭✭

Vanilla 2.6.4

I'm trying to develop a new addon in the 2.5+ format. I've previously created plugins for 2.4 and earlier. I'm having trouble getting things working - the plugin I created with an example from the tutorial doesn't seem to do anything.

Directory is /www/vanilla/plugins/stupidspammers. It contains:

addon.json

{
    "type": "addon",
    "key": "stupidspammers",
    "name": "StupidSpammers",
    "description": "Outsmart stupid spammers with an easy question.",
    "version": "0.1",
    "mobileFriendly": true,
    "authors": [
        {
            "name": "Jason Barnabe",
            "email": "[email protected]"
        }
    ],
    "require": {
        "vanilla": ">=2.5"
    }
}

class.stupidspammersplugin.php

class StupidspammersPlugin extends Gdn_Plugin {
    /* (Copied from tutorial - https://docs.vanillaforums.com/developer/addons/events-and-handlers/#add-the-views-and-comments-counts-to-a-discussion-page) */
    /**
     * Adds Views and Comments count to Discussion Page
     *
     * @param DiscussionController $sender
     * @param array $args
     */
    public function DiscussionController_AfterDiscussionTitle_handler($sender, $args) {
        echo '<span class="Discussion-CountViews">';
        echo t("Views").": ";
        echo $args['Discussion']->CountViews;
        echo '</span>';

        echo '<span class="Discussion-CountComments">';
        echo t("Reply").": ";
        echo $args['Discussion']->CountComments;
        echo '</span>';
    }
}

The plugin is listed as enabled in the dashboard. I have cleared /www/vanilla/cache/addon.php. When it regenerates, it contains:

  'stupidspammers' => 
  Vanilla\Addon::__set_state(array(
     'info' => 
    array (
      'type' => 'addon',
      'key' => 'stupidspammers',
      'name' => 'StupidSpammers',
      'description' => 'Outsmart stupid spammers with an easy question.',
      'version' => '0.1',
      'mobileFriendly' => true,
      'authors' => 
      array (
        0 => 
        array (
          'name' => 'Jason Barnabe',
          'email' => '[email protected]',
        ),
      ),
      'require' => 
      array (
        'vanilla' => '>=2.5',
      ),
      'oldType' => 'plugin',
      'Issues' => 
      array (
      ),
      'priority' => 100,
    ),
     'classes' => 
    array (
    ),
     'subdir' => '/plugins/stupidspammers',
     'translations' => 
    array (
    ),
     'special' => 
    array (
    ),
  )),

I note classes is an empty array.

I have enabled debug mode and see nothing related to this plugin. Any thoughts?

Comments

  • ShadowdareShadowdare Moderator

    Make sure your class.stupidspammersplugin.php file starts with <?php on the first line. After adding this, clear/delete your /www/vanilla/cache/addon.php file again.

    Add Pages to Vanilla with the Basic Pages app

    LincJasonBarnabe
  • JasonBarnabeJasonBarnabe Cynical Salamander ✭✭

    Ah, stupid mistake by a part-time PHP programmer. That did it. Thanks.

Sign In or Register to comment.