[ Index ]

MailPress 7.1

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-content/add-ons/ -> MailPress_comment.php (source)

   1  <?php
   2  if ( class_exists( 'MailPress' ) && !class_exists( 'MailPress_comment' ) )
   3  {
   4  /*
   5  Plugin Name: MailPress_comment
   6  Plugin URI: http://blog.mailpress.org/tutorials/add-ons/comment/
   7  Description: Subscribe to comments
   8  Version: 7.1
   9  */
  10  
  11  class MailPress_comment
  12  {
  13      const meta_key = '_MailPress_subscribe_to_comments_';
  14      const option   = 'MailPress_comment';
  15  
  16  	function __construct()
  17      {
  18  // for wordpress hooks
  19  // for comment
  20          add_action( 'comment_form',                     array( __CLASS__, 'comment_form' ) );
  21          //add_filter( 'comment_form_default_fields',         array( __CLASS__, 'comment_form_default_fields' ), 8, 1 );
  22          add_action( 'comment_post',                     array( __CLASS__, 'comment_post' ), 8, 1 );
  23          add_action( 'wp_set_comment_status',                 array( __CLASS__, 'approve_comment' ) );
  24  // for post
  25          add_action( 'delete_post',                     array( __CLASS__, 'delete_post' ) );
  26  
  27  // for sending mails
  28          add_filter( 'MailPress_mailinglists_optgroup',         array( __CLASS__, 'mailinglists_optgroup' ), 5, 2 );
  29          add_filter( 'MailPress_mailinglists',             array( __CLASS__, 'mailinglists' ), 5, 1 );
  30          add_filter( 'MailPress_query_mailinglist',         array( __CLASS__, 'query_mailinglist' ), 5, 2 );
  31  
  32  // for mp_user
  33          add_action( 'MailPress_activate_user',             array( __CLASS__, 'activate_user' ), 8, 1 );
  34          add_action( 'MailPress_deactivate_user',             array( __CLASS__, 'deactivate_user' ), 8, 1 );
  35          add_action( 'MailPress_unsubscribe_user',             array( __CLASS__, 'delete_user' ), 8, 1 );
  36          add_action( 'MailPress_delete_user',                 array( __CLASS__, 'delete_user' ), 8, 1 );    
  37  
  38  // for autoresponder
  39          add_action( 'MailPress_load_Autoresponder_events',    array( __CLASS__, 'load_Autoresponder_events' ) );
  40  
  41  // for sync wordpress user
  42          add_filter( 'MailPress_has_subscriptions',         array( __CLASS__, 'has_subscriptions' ), 8, 2 );
  43          add_action( 'MailPress_sync_subscriptions',        array( __CLASS__, 'sync_subscriptions' ), 8, 2 );    
  44  
  45  // for wp admin
  46          if ( is_admin() )
  47          {
  48          // for link on plugin page
  49              add_filter( 'plugin_action_links',             array( __CLASS__, 'plugin_action_links' ), 10, 2 );
  50          // for role & capabilities
  51              add_filter( 'MailPress_capabilities',         array( __CLASS__, 'capabilities' ), 1, 1 );
  52          // for settings
  53              add_filter( 'MailPress_settings_tab',         array( __CLASS__, 'settings_tab' ), 8, 10 );
  54          // for settings subscriptions
  55              add_filter( 'MailPress_settings_subscriptions_help',        array( __CLASS__, 'settings_subscriptions_help' ), 40, 1 );
  56              add_action( 'MailPress_settings_subscriptions_form',        array( __CLASS__, 'settings_subscriptions_form' ), 40 );
  57  
  58          // for meta box in user page
  59              if ( current_user_can( 'MailPress_manage_comments' ) )
  60              {
  61                  add_action( 'MailPress_add_help_tab_user',        array( __CLASS__, 'add_help_tab_user' ), 10 );
  62                  add_action( 'MailPress_update_meta_boxes_user',    array( __CLASS__, 'update_meta_boxes_user' ) );
  63                  add_action( 'MailPress_add_meta_boxes_user',     array( __CLASS__, 'add_meta_boxes_user' ), 10, 2 );
  64              }
  65          // for dashboard
  66              add_action( 'MailPress_load_Dashboard_widgets',     array( __CLASS__, 'load_Dashboard_widgets' ) );
  67          }
  68  
  69  // for mp_users list
  70          add_filter( 'MailPress_users_columns',             array( __CLASS__, 'users_columns' ), 30, 1 );
  71          add_filter( 'MailPress_users_get_row',             array( __CLASS__, 'users_get_row' ), 30, 4 );
  72  
  73  // for posts list
  74          add_filter( 'manage_edit_columns',                array( __CLASS__, 'manage_edit_columns' ), 10, 1 );
  75          add_action( 'manage_posts_custom_column',            array( __CLASS__, 'manage_posts_custom_column' ), 10, 2 );
  76  
  77  // for comments list
  78          add_filter( 'manage_edit-comments_columns',        array( __CLASS__, 'manage_edit_comments_columns' ), 10, 1 );
  79          add_action( 'manage_comments_custom_column',        array( __CLASS__, 'manage_comments_custom_column' ), 10, 2 );
  80      }
  81  
  82  //// Subscriptions ////
  83  
  84  	public static function get_checklist( $mp_user_id = false, $args = '' ) 
  85      {
  86          $checklist = '';
  87          $defaults = array (     'htmlname'     => 'keep_comment_sub', 
  88                          'echo'        => 1, 
  89                          'type'        => 'checkbox', 
  90                          'htmlstart'    => '', 
  91                          'htmlmiddle'    => '&#160;&#160;', 
  92                          'htmlend'        => "<br />\n"
  93                       );
  94          $r = wp_parse_args( $args, $defaults );
  95          extract( $r );
  96  
  97          $comment_subs = self::get_subscriptions( $mp_user_id );
  98          foreach ( $comment_subs as $comment_sub )
  99          {
 100              $typ2         = 'checkbox';
 101              $k         = $comment_sub->meta_id;
 102              $v         = apply_filters( 'the_title', $comment_sub->post_title );
 103  
 104              $tag          = '<input type="' . $typ2 . '" name="' . $htmlname . '[' . $k . ']" id="' . $htmlname . '_' . $k . '" checked="checked" />';
 105              $htmlstart2  = str_replace( '{{id}}', "{$htmlname}_{$k}", $htmlstart );
 106              $htmlmiddle2 = $htmlmiddle . str_replace( '&#160;', '', $v );
 107              $htmlend2    = $htmlend;
 108  
 109              $checklist .= "$htmlstart2$tag$htmlmiddle2$htmlend2";
 110          }
 111          return $checklist;
 112      }
 113  
 114  	public static function update_checklist( $mp_user_id )
 115      {
 116          $comment_subs = self::get_subscriptions( $mp_user_id );
 117  
 118          $post_ = filter_input_array( INPUT_POST );
 119  
 120          foreach ( $comment_subs as $comment_sub )
 121          {
 122              if ( isset( $post_['keep_comment_sub'][$comment_sub->meta_id] ) ) continue;
 123              delete_post_meta( $comment_sub->post_id, self::meta_key, $mp_user_id );
 124              new MP_Stat( 'c', $comment_sub->post_id, -1 );
 125          }
 126      }
 127  
 128  	public static function get_subscriptions( $id ) 
 129      {
 130          global $wpdb;
 131          return $wpdb->get_results( $wpdb->prepare( "SELECT a.meta_id, a.post_id, b.post_title FROM $wpdb->postmeta a, $wpdb->posts b WHERE a.meta_key = %s AND a.meta_value = %s AND a.post_id = b.ID;", self::meta_key, $id ) );
 132      }
 133  
 134  ////    Plugin  ////
 135  
 136  	public static function comment_form( $post_id ) 
 137      {
 138          $out = '';
 139  
 140          $txtsubcomment = __( "Notify me of follow-up comments via email.", 'MailPress' );
 141  
 142          $email = MP_WP_User::get_email();
 143  
 144          if ( is_email( $email ) )
 145          {
 146              $i = MP_User::get_id_by_email( $email );
 147              if ( $i )
 148              {
 149                  $is_subscriber = self::is_subscriber( $post_id, $i );
 150                  if ( $is_subscriber )
 151                  {
 152                         $url = MP_User::get_unsubscribe_url( MP_User::get_key_by_email( $email ) );
 153  
 154                      $out .= '<!-- start of code generated by MailPress -->' . "\r\n";
 155                      $out .= '<div class="MailPressCommentform" style="clear:both;">' . "\r\n";
 156                      $out .= '<span>' . sprintf( __( 'You are subscribed to this entry. %1$s.', 'MailPress' ), sprintf( '<a href="%1$s">%2$s</a>', $url, __( 'Manage your subscriptions', 'MailPress' ) ) ) . '</span>' . "\r\n";
 157                      $out .= '</div>' . "\r\n";
 158                      $out .= '<!-- end of code generated by MailPress -->' . "\r\n";
 159  
 160                      echo $out;
 161                      return;
 162                  }
 163              }
 164          }
 165  
 166          $out .= '<!-- start of code generated by MailPress -->' . "\r\n";
 167          $out .= '<div class="MailPressCommentform" style="clear:both;">' . "\r\n";
 168          $out .= '<input type="hidden" name="MailPress[subscribe_to_comments_on]" value="on" />' . "\r\n";
 169          $out .= '<label for="MailPress_subscribe_to_comments">' . "\r\n";
 170          $out .= '<input name="MailPress[subscribe_to_comments]" id="MailPress_subscribe_to_comments" type="checkbox" class="MailPressCommentformCheckbox" style="margin:0;padding:0;width:auto;"' . checked( get_option( self::option ), true, false ) . ' />' . "\r\n";
 171          $out .= '<span>' . $txtsubcomment . '</span>' . "\r\n";
 172          $out .= '</label>' . "\r\n";
 173          $out .= '</div>' . "\r\n";
 174          $out .= '<!-- end of code generated by MailPress -->' . "\r\n";
 175  
 176          echo $out;
 177      }
 178  
 179  	public static function comment_form_default_fields( $fields ) 
 180      {
 181          $txtsubcomment = __( 'Notify me of follow-up comments via email.', 'MailPress' );
 182  
 183          $post_id = get_the_ID();
 184  
 185          $email = MP_WP_User::get_email();
 186  
 187          if ( MailPress::is_email( $email ) )
 188          {
 189              $i = MP_User::get_id_by_email( $email );
 190              if ( $i )
 191              {
 192                  $is_subscriber = self::is_subscriber( $post_id, $i );
 193                  if ( $is_subscriber )
 194                  {
 195                             $url = MP_User::get_unsubscribe_url( MP_User::get_key_by_email( $email ) );
 196  
 197                          $fields['mailpress-comment']  = '<!-- start of code generated by MailPress -->' . "\n";
 198                          $fields['mailpress-comment'] .= '<p class="comment-form-mailpress"><span>' . sprintf( __( 'You are subscribed to this entry. %1$s.', 'MailPress' ), sprintf( '<a href="%1$s">%2$s</a>', $url, __( 'Manage your subscriptions', 'MailPress' ) ) ) . '</span></p>';
 199                          $fields['mailpress-comment'] .= "\n" . '<!-- end of code generated by MailPress -->' . "\n";
 200                          return $fields;
 201                  }
 202              }
 203          }
 204  
 205          $fields['mailpress-comment']  = '<!-- start of code generated by MailPress -->' . "\n";
 206          $fields['mailpress-comment'] .= '<p class="comment-form-cookies-consent comment-form-mailpress"><input name="MailPress[subscribe_to_comments]" id="MailPress_subscribe_to_comments" type="checkbox" class="MailPressCommentformCheckbox"' . checked( get_option( self::option ), true, false ) . ' />' . 
 207                                  '<label for="MailPress_subscribe_to_comments">' .  __( 'Notify me of follow-up comments via email.', 'MailPress' ) . '</label>' .
 208                                  '<input type="hidden" name="MailPress[subscribe_to_comments_on]" value="on" /></p>' . "\n";
 209          $fields['mailpress-comment'] .= '<!-- end of code generated by MailPress -->' . "\n";
 210          return $fields;
 211      }
 212  
 213  	public static function comment_post( $id ) 
 214      {
 215          global $wpdb, $comment;
 216  
 217          $comment     = $wpdb->get_row( "SELECT * FROM $wpdb->comments WHERE comment_ID = $id LIMIT 1" );
 218          if ( 'spam' == $comment->comment_approved ) return;
 219  
 220          $post_id     = $comment->comment_post_ID;
 221  
 222          $email     = MP_WP_User::get_email();
 223          $name     = $comment->comment_author;
 224  
 225          $post_ = filter_input_array( INPUT_POST );
 226  
 227          if ( MailPress::is_email( $email ) )
 228          {
 229              $mp_user_id = MP_User::get_id_by_email( $email );
 230              if ( !$mp_user_id ) $mp_user_id = apply_filters( 'MailPress_user_already_inserted', false );
 231  
 232              if ( $mp_user_id )
 233              {
 234                  if ( isset( $post_['MailPress']['subscribe_to_comments'] ) && !self::is_subscriber( $post_id, $mp_user_id ) ) 
 235                  {
 236                      add_post_meta( $post_id, self::meta_key, $mp_user_id );
 237                      new MP_Stat( 'c', $post_id, 1 );
 238                  }
 239              }
 240              else
 241              {
 242                  if ( isset( $post_['MailPress']['subscribe_to_comments'] ) )
 243                  {
 244                      $mp_user_id = MP_User::insert( $email, $name );
 245                      if ( $mp_user_id )
 246                      {
 247                          add_post_meta( $post_id, self::meta_key, $mp_user_id );
 248                          new MP_Stat( 'c', $post_id, 1 );
 249                          new MP_Stat( 'u', 'comment', 1 );
 250                          do_action( 'MailPress_new commenter', $mp_user_id, 'MailPress_new commenter' );
 251                      }
 252                  }
 253              }
 254          }
 255          if ( '1' == $comment->comment_approved ) self::approve_comment( $id );
 256      }
 257  
 258  	public static function approve_comment( $id ) 
 259      {
 260          global $wpdb, $comment;
 261  
 262          $comment    = $wpdb->get_row( "SELECT * FROM $wpdb->comments WHERE comment_ID = $id LIMIT 1" );
 263  
 264          if ( !$comment ) return false;
 265          
 266          if ( '1' != $comment->comment_approved ) return true;
 267  
 268          $post = &get_post( $comment->comment_post_ID );
 269  
 270          $mail = new stdClass();
 271  
 272          $mail->Template    = 'comments';
 273  
 274          $mail->recipients_query = "SELECT c.id, c.email, c.name, c.status, c.confkey from $wpdb->comments a, $wpdb->postmeta b, $wpdb->mp_users c WHERE a.comment_ID = $id AND a.comment_post_ID  = b.post_id AND b.meta_value = c.id AND b.meta_key = '" . self::meta_key . "' AND a.comment_author_email <> c.email AND c.status IN ( 'waiting', 'active' ) ;";
 275  
 276          $mail->the_title    = apply_filters( 'the_title', $post->post_title );
 277  
 278          $mail->subject    = sprintf( __( '[%1$s] New Comment (%2$s)', 'MailPress' ), get_bloginfo( 'name' ), $mail->the_title );
 279  
 280          $mail->content    = apply_filters( 'comment_text', get_comment_text() );
 281  
 282              $mail->advanced = new stdClass();
 283              $mail->advanced->comment = $comment;
 284              $mail->advanced->post    = $post;
 285  
 286          /* deprecated */
 287              $mail->p = new stdClass();
 288              $mail->p->id    = $comment->comment_post_ID;
 289              $mail->c = new stdClass();
 290              $mail->c->id       = $id;
 291          /* deprecated */
 292  
 293          return MailPress::mail( $mail );
 294      }
 295  
 296  ////  Post ////
 297  
 298  	public static function delete_post( $id )
 299      {
 300          global $wpdb;
 301          new MP_Stat( 'c', $id, ( -1 * $wpdb->get_var( "SELECT sum( scount ) FROM $wpdb->mp_stats WHERE stype = 'c' AND slib = '$id';" ) ) );
 302      }
 303  
 304  //// Sending Mails ////
 305  
 306  	public static function mailinglists_optgroup( $label, $optgroup ) 
 307      {
 308          if ( __CLASS__ == $optgroup ) return __( 'Comments', 'MailPress' );
 309          return $label;
 310      }
 311  
 312  	public static function mailinglists( $draft_dest = array() ) 
 313      {
 314          $draft_dest['2'] = __( 'to comments', 'MailPress' );
 315          $draft_dest['3'] = __( 'to blog & comments', 'MailPress' );
 316          return $draft_dest;
 317      }
 318  
 319  	public static function query_mailinglist( $query, $draft_toemail ) 
 320      {
 321          if ( $query ) return $query;
 322  
 323          global $wpdb;
 324  
 325          switch ( $draft_toemail )
 326          {
 327              case '2' :
 328                  return $wpdb->prepare( "SELECT DISTINCT id, email, name, status, confkey FROM $wpdb->mp_users a, $wpdb->postmeta b WHERE a.id = b.meta_value AND a.status in ( 'waiting', 'active' ) AND b.meta_key = %s ;",  self::meta_key );
 329              break;
 330              case '3' :
 331                  return $wpdb->prepare( "SELECT id, email, name, status, confkey FROM $wpdb->mp_users WHERE status = 'active' UNION SELECT DISTINCT id, email, name, status, confkey FROM $wpdb->mp_users a, $wpdb->postmeta b WHERE a.id = b.meta_value AND a.status = 'waiting' AND b.meta_key = %s ;", self::meta_key );
 332              break;
 333          }
 334          return $query;
 335      }
 336  
 337  //// post & mp_user ////
 338  
 339  	public static function is_subscriber( $post_id, $mp_user_id ) 
 340      {
 341          global $wpdb;
 342          return $wpdb->get_var( $wpdb->prepare( "SELECT count( * ) FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s AND meta_value = %s;", $post_id, self::meta_key, $mp_user_id ) );
 343      }
 344  
 345  //// post ////
 346  
 347  	public static function has_subscribers( $post_id ) 
 348      {
 349          global $wpdb;
 350          return $wpdb->get_var( $wpdb->prepare( "SELECT count( * ) FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s;", $post_id, self::meta_key ) );
 351      }
 352  
 353  //// mp_user ////
 354  
 355  	public static function has_subscribed( $mp_user_id ) 
 356      {
 357          global $wpdb;
 358          return $wpdb->get_var( $wpdb->prepare( "SELECT count( * ) FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s;", self::meta_key, $mp_user_id ) );
 359      }
 360  
 361  	public static function unsubscribe( $mp_user_id ) 
 362      {
 363          global $wpdb;
 364          return $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s;", self::meta_key, $mp_user_id ) );
 365      }
 366  
 367  	public static function activate_user( $mp_user_id ) 
 368      {
 369          if ( self::has_subscribed( $mp_user_id ) ) new MP_Stat( 'u', 'comment', -1 );
 370      }
 371  
 372  	public static function deactivate_user( $mp_user_id ) 
 373      {
 374          if ( self::has_subscribed( $mp_user_id ) ) new MP_Stat( 'u', 'comment', 1 );
 375      }
 376  
 377  	public static function delete_user( $mp_user_id ) 
 378      {
 379          if ( self::has_subscribed( $mp_user_id ) ) new MP_Stat( 'u', 'comment', ( -1 * self::unsubscribe( $mp_user_id ) ) );
 380      }
 381  
 382  //// Autoresponders ////
 383  
 384  	public static function load_Autoresponder_events()
 385      {
 386          new MP_Autoresponder_events_comment();
 387      }
 388  
 389  // Sync wordpress user
 390  
 391  	public static function has_subscriptions( $has, $mp_user_id )
 392      {
 393          $x = self::has_subscribed( $mp_user_id );
 394  
 395          if ( !$x ) return $has;
 396          return true;
 397      }
 398  
 399  	public static function sync_subscriptions( $oldid, $newid )
 400      {
 401          if ( !self::has_subscriptions( false, $oldid ) ) return;
 402          global $wpdb;
 403          return $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->postmeta SET meta_value = %s WHERE meta_key = %s AND meta_value = %s ;", $newid, self::meta_key, $oldid ) );
 404      }
 405  
 406  ////  ADMIN  ////
 407  ////  ADMIN  ////
 408  ////  ADMIN  ////
 409  ////  ADMIN  ////
 410  
 411  // for link on plugin page
 412  	public static function plugin_action_links( $links, $file )
 413      {
 414          return MailPress::plugin_links( $links, $file, plugin_basename( __FILE__ ), 'subscriptions' );
 415      }
 416  
 417  // for role & capabilities
 418  	public static function capabilities( $capabilities ) 
 419      {
 420          $capabilities['MailPress_manage_comments'] = array(     'name'  => __( 'Comments', 'MailPress' ), 
 421                                                  'group' => 'users'
 422                                           );
 423          return $capabilities;
 424      }
 425  
 426  // for settings
 427  	public static function settings_tab( $tabs )
 428      {
 429          $tabs['subscriptions'] = __( 'Subscriptions', 'MailPress' );
 430          return $tabs;
 431      }
 432  
 433  // // for settings subscriptions
 434  	public static function settings_subscriptions_help( $content )
 435      {
 436          include  ( MP_ABSPATH . 'mp-admin/includes/settings/subscriptions/comment/help.php' );
 437          return $content;
 438      }
 439  
 440  	public static function settings_subscriptions_form()
 441      {
 442          include  ( MP_ABSPATH . 'mp-admin/includes/settings/subscriptions/comment/form.php' );
 443      }
 444  
 445  // for meta box in user page
 446  	public static function add_help_tab_user()
 447      {
 448          $post_ = filter_input_array( INPUT_POST );
 449  
 450          if ( !isset( $post_['id'] ) ) return;
 451          if ( !self::has_subscribers( $post_['id'] ) ) return;
 452  
 453          global $current_screen;
 454  
 455          $content = '';
 456          $content .= '<p><strong>' . __( 'Comments :', 'MailPress' ) . '</strong></p>';
 457          $content .= '<p>' . __( 'You can create, modify comments subscriptions for a mp user.', 'MailPress' ) . '</p>';
 458  
 459          $current_screen->add_help_tab( array(     'id'        => 'comments',
 460                                          'title'    => __( 'Comments', 'MailPress' ),
 461                                          'content'    => $content )
 462          );
 463      }
 464  
 465  	public static function update_meta_boxes_user() 
 466      {
 467          $post_ = filter_input_array( INPUT_POST );
 468  
 469          if ( !isset( $post_['id'] ) ) return;
 470          if ( !self::has_subscribers( $post_['id'] ) ) return;
 471  
 472          if ( !isset( $post_['keep_comment_sub'] ) ) $post_['keep_comment_sub'] = array();
 473  
 474          self::update_checklist( $post_['id'] );
 475      }
 476  
 477  	public static function add_meta_boxes_user( $mp_user_id, $screen )
 478      {
 479          if ( !self::has_subscribed( $mp_user_id ) ) return;
 480  
 481          add_meta_box( 'commentdiv', __( 'Comments', 'MailPress' ), array( __CLASS__, 'meta_box' ), $screen, 'normal', 'core' );
 482      }
 483  
 484  	public static function meta_box( $mp_user )
 485      { 
 486          $check_comments = self::get_checklist( $mp_user->id );
 487          if ( $check_comments ) echo $check_comments;
 488      }
 489  
 490  // for dashboard
 491  	public static function load_Dashboard_widgets() 
 492      {
 493          new MP_WP_Dashboard_widgets_comment();
 494      }
 495  
 496  // for mp_users list
 497  	public static function users_columns( $x )
 498      {
 499          $date = array_pop( $x );
 500          $x['comments']=  __( 'Comments', 'MailPress' );
 501          $x['date']        = $date;
 502          return $x;
 503      }
 504  
 505  	public static function users_get_row( $out, $column_name, $mp_user, $url_parms )
 506      {
 507          if ( 'comments' == $column_name )
 508          {
 509              $o = array();
 510  
 511              global $wpdb;
 512              $posts = $wpdb->get_results( $wpdb->prepare( "SELECT post_id as id FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s ;", self::meta_key, $mp_user->id ) );
 513  
 514              if ( !empty( $posts ) )
 515              { 
 516                  foreach ( $posts as $post )
 517                  {
 518                      $post = get_post( $post->id );
 519                      $o[] = $post->post_title;
 520                  }
 521                  $out .= join( ', ', $o );
 522              }
 523          }
 524          return $out;
 525      }
 526  
 527  // for posts list
 528  	public static function manage_edit_columns( $x )
 529      {
 530          $x['mp_users']=  __( 'Subscribers', 'MailPress' );
 531          return $x;
 532      }
 533  
 534  	public static function manage_posts_custom_column( $column_name, $post_id )
 535      {
 536          if ( 'mp_users' != $column_name ) return;
 537  
 538          global $wpdb;
 539          $count = self::has_subscribers( $post_id );
 540          if ( $count ) echo $count;
 541      }
 542  
 543  // for comments list
 544  	public static function manage_edit_comments_columns( $x )
 545      {
 546          $x['mp_subscribed']=  __( 'Subscriber', 'MailPress' );
 547          return $x;
 548      }
 549  
 550  	public static function manage_comments_custom_column( $column_name, $comment_id )
 551      {
 552          if ( 'mp_subscribed' != $column_name ) return;
 553  
 554          $comment = get_comment( $comment_id );
 555          if ( !empty( $comment->comment_post_ID ) )
 556          {
 557              $post_id = $comment->comment_post_ID;
 558              $mp_user_id = MP_User::get_id_by_email( $comment->comment_author_email );
 559              if ( $mp_user_id )
 560              {
 561                  global $wpdb;
 562                  $is_subscriber = self::is_subscriber( $post_id, $mp_user_id );
 563                  if ( $is_subscriber )
 564                  {
 565                      _e( 'yes', 'MailPress' );
 566                      return;
 567                  }
 568              }
 569          }
 570          _e( 'no', 'MailPress' );
 571      }
 572  }
 573  new MailPress_comment();
 574  }


Generated: Mon Mar 11 18:33:33 2019 Cross-referenced by PHPXref 0.7.1