WordPress.org

Ready to get started?Download WordPress

Forums

Signature plugin - sanity check (3 posts)

  1. abatishko
    Member
    Posted 6 years ago #

    I finished my first plugin, and I was wondering if someone with some experience could give it a quick eyeball to make sure that I'm not doing anything stupid before I upload it somewhere. Thanks in advance for the help!

    <?php
    /*
    Plugin Name: PerUserSigs
    Description: Provides per-user signatures on posts and comments.
    Version: 1.0
    */
    
    /*  snip the GPL text */
    
    if (!class_exists('PerUserSig')) {
      class PerUserSig {
        function PerUserSig() {
          add_action('show_user_profile', array(&$this, 'output_signature_settings'));
          add_action('edit_user_profile', array(&$this, 'output_signature_settings'));
          add_action('profile_update', array(&$this, 'update_signature_settings'));
          add_filter('the_content', array(&$this, 'post_content_intercept'));
          add_filter('comment_text', array(&$this, 'comment_intercept'));
          add_filter('set_post_signature', 'wp_filter_post_kses');
          add_filter('set_comment_signature', 'wp_filter_kses');
        }
    
        function output_signature_settings() {
          global $userdata;
    
          $canPost = current_user_can('edit_posts');
    
          echo '<fieldset><legend>';
          if ($canPost) echo 'Signatures';
          else echo 'Signature';
          echo '</legend>';
    
          if ($canPost) {
            echo '<label>Post Signature:';
            echo '<textarea name="post_sig" id="post_sig" rows="5" cols="30">';
            echo get_usermeta($userdata->ID, 'post_sig');
            echo '</textarea>';
            echo '</label><p />';
          }
    
          echo '<label>Comment Signature:';
          echo '<textarea name="comment_sig" id="comment_sig" rows="5" cols="30">';
          echo get_usermeta($userdata->ID, 'comment_sig');
          echo '</textarea>';
          echo '</label>';
    
          echo '</fieldset>';
        }
    
        function update_signature_settings($user_ID) {
          if ( isset( $_POST['post_sig'] )) {
            $post_sig = apply_filters('set_post_signature', trim($_POST['post_sig']));
            update_usermeta($user_ID, 'post_sig', $post_sig);
          }
          if ( isset( $_POST['comment_sig'] )) {
            $comment_sig = apply_filters('set_comment_signature', trim($_POST['comment_sig']));
            update_usermeta($user_ID, 'comment_sig', $comment_sig);
          }
        }
    
        function post_content_intercept($content) {
          global $post;
    
          if ($post->post_type != 'post') {
            return $content;
          }
    
          $sig = get_usermeta($post->post_author, 'post_sig');
          if ( !empty( $sig )) {
            $content .= $sig;
          }
          return $content;
        }
    
        function comment_intercept($content) {
          global $comment;
    
          $sig = get_usermeta($comment->user_id, 'comment_sig');
          if ( !empty( $sig )) {
            $content .= "----------------------------------------
    ".$sig;
          }
          return $content;
        }
    
      }
    }
    
    //instantiate the class
    if (class_exists('PerUserSig')) {
      $PerUserSig = new PerUserSig();
    }
    
    ?>
  2. Adam Brown
    Member
    Posted 6 years ago #

    Post long pieces of code into http://wordpress.pastebin.ca/ instead of pasting them here--they're hard to read here.

    It's here now: http://wordpress.pastebin.ca/812803

    I don't see any obvious problems. One comment, though. You may want to put this (note that I commented out two lines):

    //instantiate the class
    // if (class_exists('PerUserSig')) {
      $PerUserSig = new PerUserSig();
    // }

    inside of this condition:

    if (!class_exists('PerUserSig')) {

    On the offchance that the 'PerUserSig' class already exists, you don't want to instantiate the other class. You only want to instantiate it if it's YOUR class.

  3. abatishko
    Member
    Posted 6 years ago #

    adamrbrown, thanks for information about the pastebin, and good point about the instantiation. Thanks for looking it over.

Topic Closed

This topic has been closed to new replies.

About this Topic