Super simple WP Plugin (Widget)

Discussion in 'PHP' started by JWales, Jun 7, 2013.

  1. #1
    Hi,

    I need a WP Plugin created for a super simple widget that you just drag to where it needs to be. No settings can be configured, only drag and drop.

    On the front-end it should then display a linked image. That's all.

    I have messed a bit around and tried this:


    <?php
    /*
    Plugin Name: Img-widget
    Plugin URI: http://test.com
    Description: To automatically display sidebar img.
    Version: 1.0
    Author: test
    Author URI: http://test.com
    */
    error_reporting(E_ALL);
    add_action("widgets_init", array('Widget_name', 'register'));
    class Widget_name {
      function control(){
        echo 'I am a control panel';
      }
      function widget($args){
        echo $args['before_widget'];
        echo $args['before_title'] . 'Your widget title' . $args['after_title'];
        echo '<img src="https://tpc.googlesyndication.com/simgad/11090750883171998112">';
        echo $args['after_widget'];
      }
      function register(){
        register_sidebar_widget('Widget name', array('Widget_name', 'widget'));
        register_widget_control('Widget name', array('Widget_name', 'control'));
      }
    }
    ?>
    PHP:
    But it doesn't seem to work at all.

    Anyone who could give a point in the right direction.
     
    JWales, Jun 7, 2013 IP
  2. Marcel Preda

    Marcel Preda Member

    Messages:
    21
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    43
    #2
    Hi there,

    I've just tests it on my own site, WP version 3.5.1 and a custom theme.
    It is working perfect.

    You just have to be sure that you put your PHP file in plugins/ folder.
    Then you have to activate the plugin.
    Then go to "widgets" setting and you should find it as "Widget Name".
    Drag & Drop works and your plugin is visble in my sidebar.

    BR,
    Marcel
     
    Marcel Preda, Jun 7, 2013 IP
  3. JWales

    JWales Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    Hey Marcel,

    Yeah it did work actually, I messed up some settings on my test-server that caused everything to make errors :)

    Thanks for your reply though!
     
    JWales, Jun 11, 2013 IP