All pastes #812803 Raw Edit

Something

public text v1 · immutable
·published 2007-12-12 00:56 UTC
rendered paste body
<?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();
}

?>