Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

How to show Points with Author Meta?

2.1 stable, Bootstrap 2.2.1

I want it to show below user avatar if possible.

Thanks guys!

«13

Comments

  • Options
    hgtonighthgtonight ∞ · New Moderator

    The points are stored in the User table, so you can just hook into the user meta handler and spit out the markup you need. I can't give you any example code since I am mobile.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options

    @hgtonight said:
    The points are stored in the User table, so you can just hook into the user meta handler and spit out the markup you need. I can't give you any example code since I am mobile.

    Didn't manage to do it by myself. I'd appreciate further instructions, whenever you have the time. Thanks a lot!

  • Options
    hgtonighthgtonight ∞ · New Moderator
    public function DiscussionController_AuthorInfo_Handler($Sender) {
      $Author = $Sender->EventArguments['Author'];
      echo Wrap($Author->Points,'span', array('class' => 'Points Count'));
    }
    

    Sorry it took me so long to get back to you.

    Thanks for trying my addon!

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options

    @hgtonight‌ thanks! Now, the noob question remains.. where should I insert this markup? I don't want to mess anything up.

  • Options
    hgtonighthgtonight ∞ · New Moderator

    Put it in your own plugin or theme hooks file.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options
    r0obertr0obert
    edited May 2014

    @hgtonight said:
    Put it in your own plugin or theme hooks file.

    I tried creating my first ever plugin, but I get an error message when I try to enable the plugin in the dashboard:
    "There was an error getting the class methods."

    I'm sure I've done something wrong/ or forgot to add some simple line of code.

    class.myplugin.php only has these lines of code:

    <? 
    if(!defined('APPLICATION')) { exit(); }
    public function DiscussionController_AuthorInfo_Handler($Sender) {
      $Author = $Sender->EventArguments['Author'];
      echo Wrap($Author->Points,'span', array('class' => 'Points Count'));
    }
    ?>
    
  • Options
    peregrineperegrine MVP
    edited May 2014

    take the time to look at an actual plugin.

    e.g. this http://vanillaforums.org/addon/alwaysedit-plugin

    if you can follow the same basic idea. this link below has some flaws, but it might give you an understanding.

    http://vanillaforums.org/discussion/20359/annotated-plugin-how-to-write-a-plugin-for-how-to-set-guest-to-view-title-only-and-not-content

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options

    I managed to do it by pasting the code in the class.hooks.php, it works!

    Thanks @hgtonight‌ & @peregrine (again) for the assistance. I will also try to get the plugin to work by looking at an actual plugin, I'm just curious. Also, for future reference - how do I hook up in the user meta handler to get the markup?

  • Options

    I followed an example plugin and this is the code I came up with:

        <? 
        if(!defined('APPLICATION')) { exit(); 
    
        class MyYagaPointsPlugin extends Gdn_Plugin {
    
        public function DiscussionController_AuthorInfo_Handler($Sender) {
          $Author = $Sender->EventArguments['Author'];
          echo Wrap($Author->Points,'span', array('class' => 'Points Count'));
        }
    
        public function Setup() {
    
           } 
    
        ?>
    

    Still not working.

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited May 2014

    You did not look at a plugin example close enough...don't know if this will work but it has the missing parts

     <?php if(!defined('APPLICATION')) { exit();
    
    //define plugin
    $PluginInfo['nameofplugin'] = array(
    'Name' => 'nameofplugin',   
    'Version' => '1.0',
    'Description' => "A plugin for etc etc.",
    'Author' => "you",
    'AuthorEmail' => 'contact@you.com',
     'AuthorUrl' => 'you.com'
    );
    
    class MyYagaPointsPlugin extends Gdn_Plugin {
    
     public function DiscussionController_AuthorInfo_Handler($Sender) {
          $Author = $Sender->EventArguments['Author'];
          echo Wrap($Author->Points,'span', array('class' => 'Points Count'));
        }
        public function Setup() {
           } 
        }
    
  • Options
    r0obertr0obert
    edited May 2014

    @vrijvlinder‌ actuall I did, but I included the first part of the code in default.php. Should I just get all code together in class.myyagapoints.php instead?

    $PluginInfo['MyYagaPoints'] = array(
       'Description' => 'Display Yaga Points with Author Meta.',
       'Version' => '1.0',
       'Author' => "r0obert",
       'AuthorUrl' => 'http://vanillaforums.org'
    
    );
    
  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    Yes it all goes in one file. What else is in the default.php ?

  • Options
    peregrineperegrine MVP
    edited May 2014

    put it all in default.php OR all in class.myyagapoints.php it will do the same thing (for your plugin)

    either one will work.

    you have two things that are not good

    start with

    <?php if(!defined('APPLICATION')) { exit();

    NOT

    <? if(!defined('APPLICATION')) { exit();

    it is better form to use the standard also remove the closing ?> at the bottom of plugin it can wreck feeds off of you site it you close it it with a ?> and have blank lines.

    I recommend once again to look at this plugin, and follow the format.

    it can't get any simpler than that.

    http://vanillaforums.org/addon/alwaysedit-plugin

    @r0obert

    themehooks works as well. A plugin you can enable quickly and disable and will will work across all themes.
    with themehooks it will only work in themes with that set of themehooks.

    either will work. one is more generalized.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options

    @vrijvlinder said:
    Yes it all goes in one file. What else is in the default.php ?

    <?
    if(!defined('APPLICATION')) { exit(); }
    
    $PluginInfo['MyYagaPoints'] = array(
       'Description' => 'Display Yaga Points with Author Meta.',
       'Version' => '1.0',
       'Author' => "r0obert",
       'AuthorUrl' => 'http://vanillaforums.org'
    
    );
    
  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited May 2014

    No you need to use one file, either call it default, or class.MyYagaPointsPlugin.php
    it makes no dif which.

    Just as I posted above without the closing php tag and add the missing bracket in the end
    like I posted it. The only thing different is that and the plugin definition.

    You had two files one was being ignored and the other empty

  • Options

    see my comment again and read it, please.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options

    **Update: Working! **

    Thanks @peregrine @vrijvlinder‌ !

    I simply put all code in a single file, removed the ending ?> and added the <?php and that's about it.

    <?php
    if(!defined('APPLICATION')) { exit(); }
    
    $PluginInfo['MyYagaPoints'] = array(
       'Description' => 'Display Yaga Points with Author Meta.',
       'Version' => '1.0',
       'Author' => "r0obert",
       'AuthorUrl' => 'http://vanillaforums.org'
    
    );
    
    class MyYagaPointsPlugin extends Gdn_Plugin {
    
    public function DiscussionController_AuthorInfo_Handler($Sender) {
      $Author = $Sender->EventArguments['Author'];
      echo Wrap($Author->Points,'span', array('class' => 'Points Count'));
    }
    
    public function Setup() {
    
       } 
    }
    

    Hurrah, my 1st ever plugin lol!

  • Options

    now you can upload it if you want.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    @peregrine said:
    now you can upload it if you want.

    @r0obert

    And Don't forget to make an icon for it or I will!!

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    yes this plugin has been blessed by hgtonight and peregrine so it is Practically Approved !!

Sign In or Register to comment.