[ Index ]

MailPress 7.2

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


Generated: Tue May 19 15:55:14 2020 Cross-referenced by PHPXref 0.7.1