WordPress.org

Plugin Directory

Changeset 664848


Ignore:
Timestamp:
02/07/13 17:07:16 (14 months ago)
Author:
chipbennett
Message:

Update stable tag to 2.2

Location:
cbnet-multi-author-comment-notification/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • cbnet-multi-author-comment-notification/trunk/cbnet-multi-author-comment-notification.php

    r643418 r664848  
    44 * Plugin URI:    http://www.chipbennett.net/wordpress/plugins/cbnet-multi-author-comment-notification/ 
    55 * Description:   Send comment notification emails to multiple users. Select users individually or by user role, or send emails to arbitrary email addresses. 
    6  * Version:       2.1.2 
     6 * Version:       2.2 
    77 * Author:        chipbennett 
    88 * Author URI:    http://www.chipbennett.net/ 
     
    105105} 
    106106 
     107/** 
     108 * Filter array of comment notificaiton email addresses 
     109 */ 
     110function cbnet_macn_filter_comment_notification_email_to( $email_to ) {  
     111    global $cbnet_macn_options; 
     112    if ( false == $cbnet_macn_options['notify_for_registered_users'] && is_user_logged_in() ) { 
     113        return $email_to; 
     114    } 
     115    return array_unique( array_merge( $email_to, cbnet_macn_get_notification_email_addresses() ) ); 
     116} 
     117add_filter( 'comment_notification_email_to', 'cbnet_macn_filter_comment_notification_email_to' ); 
     118 
     119/** 
     120 * Filter array of moderation notificaiton email addresses 
     121 */ 
     122function cbnet_macn_filter_comment_moderation_email_to( $email_to ) { 
     123    global $cbnet_macn_options; 
     124    if ( false == $cbnet_macn_options['notify_for_comment_moderation'] || ( true == $cbnet_macn_options['notify_for_registered_users'] && is_user_logged_in() ) ) { 
     125        return $email_to; 
     126    } 
     127    return array_unique( array_merge( $email_to, cbnet_macn_get_notification_email_addresses() ) ); 
     128} 
     129add_filter( 'comment_moderation_email_to', 'cbnet_macn_filter_comment_moderation_email_to' ); 
     130 
     131 
    107132?> 
  • cbnet-multi-author-comment-notification/trunk/custom-user-meta.php

    r643418 r664848  
     1<<<<<<< HEAD 
    12<?php 
    23/** 
     
    4243add_action( 'edit_user_profile_update', 'cbent_macn_save_user_meta_data' ); 
    4344 
     45======= 
     46<?php 
     47/** 
     48 * Plugin Custom User Meta 
     49 */ 
     50  
     51/** 
     52 * Create comment notification user meta field 
     53 */ 
     54 
     55function cbent_macn_add_user_meta_field( $user ) { ?> 
     56 
     57    <h3><?php _e( 'Comment Email Notification', 'cbnet_macn' ); ?></h3> 
     58 
     59    <table class="form-table"> 
     60 
     61        <tr> 
     62            <th><label for="comment_notify"><?php _e( 'Comment Email Notification', 'cbnet_macn' ); ?></label></th> 
     63 
     64            <td> 
     65                <input type="checkbox" name="cbnet_macn_comment_notify" value="true" <?php checked( true == get_the_author_meta( 'cbnet_macn_comment_notify', $user->ID ) ); ?>> 
     66                <span class="description"><?php _e( 'Receive email notification of comments to all posts, regardless of post author', 'cbnet_macn' ); ?></span> 
     67            </td> 
     68        </tr> 
     69 
     70    </table> 
     71<?php } 
     72add_action( 'show_user_profile', 'cbent_macn_add_user_meta_field' ); 
     73add_action( 'edit_user_profile', 'cbent_macn_add_user_meta_field' ); 
     74 
     75 
     76/** 
     77 * Save comment notification user meta data 
     78 */ 
     79function cbent_macn_save_user_meta_data( $user_id ) { 
     80 
     81    if ( !current_user_can( 'edit_user', $user_id ) ) 
     82        return false; 
     83 
     84    update_user_meta( $user_id, 'cbnet_macn_comment_notify', ( isset( $_POST['cbnet_macn_comment_notify'] ) ? true : false ) ); 
     85} 
     86add_action( 'personal_options_update', 'cbent_macn_save_user_meta_data' ); 
     87add_action( 'edit_user_profile_update', 'cbent_macn_save_user_meta_data' ); 
     88 
     89>>>>>>> b0050ec04ed4b3934a36b1d3afdf97f4152d733c 
    4490?> 
  • cbnet-multi-author-comment-notification/trunk/pluggable.php

    r643268 r664848  
     1<<<<<<< HEAD 
    12<?php 
    23/** 
     
    109110        $message_headers = apply_filters('comment_notification_headers', $message_headers, $comment_id); 
    110111         
     112        $email_to = apply_filters( 'comment_notification_email_to', array( $author->user_email ) ); 
     113         
     114        foreach ( $email_to as $email ) 
     115            @wp_mail($email, $subject, $notify_message, $message_headers); 
     116 
     117        return true; 
     118    } 
     119} 
     120 
     121if ( !function_exists('wp_notify_moderator') ) : 
     122/** 
     123 * Notifies the moderator of the blog about a new comment that is awaiting approval. 
     124 * 
     125 * @since 1.0 
     126 * @uses $wpdb 
     127 * 
     128 * @param int $comment_id Comment ID 
     129 * @return bool Always returns true 
     130 */ 
     131function wp_notify_moderator($comment_id) { 
     132    global $wpdb; 
     133 
     134    if ( 0 == get_option( 'moderation_notify' ) ) 
     135        return true; 
     136 
     137    $comment = get_comment($comment_id); 
     138    $post = get_post($comment->comment_post_ID); 
     139    $user = get_userdata( $post->post_author ); 
     140    // Send to the administration and to the post author if the author can modify the comment. 
     141    $email_to = array( get_option('admin_email') ); 
     142    if ( user_can($user->ID, 'edit_comment', $comment_id) && !empty($user->user_email) && ( get_option('admin_email') != $user->user_email) ) 
     143        $email_to[] = $user->user_email; 
     144     
     145    $email_to = apply_filters( 'comment_moderation_email_to', $email_to ); 
     146 
     147    $comment_author_domain = @gethostbyaddr($comment->comment_author_IP); 
     148    $comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'"); 
     149 
     150    // The blogname option is escaped with esc_html on the way into the database in sanitize_option 
     151    // we want to reverse this for the plain text arena of emails. 
     152    $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); 
     153 
     154    switch ($comment->comment_type) 
     155    { 
     156        case 'trackback': 
     157            $notify_message  = sprintf( __('A new trackback on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n"; 
     158            $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n"; 
     159            $notify_message .= sprintf( __('Website : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; 
     160            $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "\r\n"; 
     161            $notify_message .= __('Trackback excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; 
     162            break; 
     163        case 'pingback': 
     164            $notify_message  = sprintf( __('A new pingback on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n"; 
     165            $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n"; 
     166            $notify_message .= sprintf( __('Website : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; 
     167            $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "\r\n"; 
     168            $notify_message .= __('Pingback excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; 
     169            break; 
     170        default: //Comments 
     171            $notify_message  = sprintf( __('A new comment on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n"; 
     172            $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n"; 
     173            $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; 
     174            $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n"; 
     175            $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "\r\n"; 
     176            $notify_message .= sprintf( __('Whois  : http://whois.arin.net/rest/ip/%s'), $comment->comment_author_IP ) . "\r\n"; 
     177            $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; 
     178            break; 
     179    } 
     180 
     181    $notify_message .= sprintf( __('Approve it: %s'),  admin_url("comment.php?action=approve&c=$comment_id") ) . "\r\n"; 
     182    if ( EMPTY_TRASH_DAYS ) 
     183        $notify_message .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "\r\n"; 
     184    else 
     185        $notify_message .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "\r\n"; 
     186    $notify_message .= sprintf( __('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id") ) . "\r\n"; 
     187 
     188    $notify_message .= sprintf( _n('Currently %s comment is waiting for approval. Please visit the moderation panel:', 
     189        'Currently %s comments are waiting for approval. Please visit the moderation panel:', $comments_waiting), number_format_i18n($comments_waiting) ) . "\r\n"; 
     190    $notify_message .= admin_url("edit-comments.php?comment_status=moderated") . "\r\n"; 
     191 
     192    $subject = sprintf( __('[%1$s] Please moderate: "%2$s"'), $blogname, $post->post_title ); 
     193    $message_headers = ''; 
     194 
     195    $notify_message = apply_filters('comment_moderation_text', $notify_message, $comment_id); 
     196    $subject = apply_filters('comment_moderation_subject', $subject, $comment_id); 
     197    $message_headers = apply_filters('comment_moderation_headers', $message_headers); 
     198 
     199    foreach ( $email_to as $email ) 
     200        @wp_mail($email, $subject, $notify_message, $message_headers); 
     201 
     202    return true; 
     203} 
     204endif; 
     205 
     206======= 
     207<?php 
     208/** 
     209 * Plugin overrides of pluggable functions 
     210 */ 
     211 
     212/** 
     213 * Globalize Plugin options 
     214 */ 
     215global $cbnet_macn_options; 
     216$cbnet_macn_options = cbnet_macn_get_options(); 
     217 
     218if ( ! function_exists( 'wp_notify_postauthor' ) ) { 
     219     /** 
     220     * Notify an author of a comment/trackback/pingback to one of their posts. 
     221     * 
     222     * @since 1.0.0 
     223     * 
     224     * @param int $comment_id Comment ID 
     225     * @param string $comment_type Optional. The comment type either 'comment' (default), 'trackback', or 'pingback' 
     226     * @return bool False if user email does not exist. True on completion. 
     227     *  
     228     * Forked from Trunk 13Dec12 
     229     *  
     230     * @todo    submit trac ticket to make email addresses filterable 
     231     */ 
     232    function wp_notify_postauthor( $comment_id, $comment_type = '' ) { 
     233        $comment = get_comment( $comment_id ); 
     234        $post    = get_post( $comment->comment_post_ID ); 
     235        $author  = get_userdata( $post->post_author ); 
     236 
     237        // The comment was left by the author 
     238        if ( $comment->user_id == $post->post_author ) 
     239            return false; 
     240 
     241        // The author moderated a comment on his own post 
     242        if ( $post->post_author == get_current_user_id() ) 
     243            return false; 
     244 
     245        // If there's no email to send the comment to 
     246        if ( '' == $author->user_email ) 
     247            return false; 
     248 
     249        $comment_author_domain = @gethostbyaddr($comment->comment_author_IP); 
     250 
     251        // The blogname option is escaped with esc_html on the way into the database in sanitize_option 
     252        // we want to reverse this for the plain text arena of emails. 
     253        $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); 
     254 
     255        if ( empty( $comment_type ) ) $comment_type = 'comment'; 
     256 
     257        if ('comment' == $comment_type) { 
     258            $notify_message  = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "\r\n"; 
     259            /* translators: 1: comment author, 2: author IP, 3: author domain */ 
     260            $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; 
     261            $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n"; 
     262            $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "\r\n"; 
     263            $notify_message .= sprintf( __('Whois  : http://whois.arin.net/rest/ip/%s'), $comment->comment_author_IP ) . "\r\n"; 
     264            $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; 
     265            $notify_message .= __('You can see all comments on this post here: ') . "\r\n"; 
     266            /* translators: 1: blog name, 2: post title */ 
     267            $subject = sprintf( __('[%1$s] Comment: "%2$s"'), $blogname, $post->post_title ); 
     268        } elseif ('trackback' == $comment_type) { 
     269            $notify_message  = sprintf( __( 'New trackback on your post "%s"' ), $post->post_title ) . "\r\n"; 
     270            /* translators: 1: website name, 2: author IP, 3: author domain */ 
     271            $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; 
     272            $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "\r\n"; 
     273            $notify_message .= __('Excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; 
     274            $notify_message .= __('You can see all trackbacks on this post here: ') . "\r\n"; 
     275            /* translators: 1: blog name, 2: post title */ 
     276            $subject = sprintf( __('[%1$s] Trackback: "%2$s"'), $blogname, $post->post_title ); 
     277        } elseif ('pingback' == $comment_type) { 
     278            $notify_message  = sprintf( __( 'New pingback on your post "%s"' ), $post->post_title ) . "\r\n"; 
     279            /* translators: 1: comment author, 2: author IP, 3: author domain */ 
     280            $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; 
     281            $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "\r\n"; 
     282            $notify_message .= __('Excerpt: ') . "\r\n" . sprintf('[...] %s [...]', $comment->comment_content ) . "\r\n\r\n"; 
     283            $notify_message .= __('You can see all pingbacks on this post here: ') . "\r\n"; 
     284            /* translators: 1: blog name, 2: post title */ 
     285            $subject = sprintf( __('[%1$s] Pingback: "%2$s"'), $blogname, $post->post_title ); 
     286        } 
     287        $notify_message .= get_permalink($comment->comment_post_ID) . "#comments\r\n\r\n"; 
     288        $notify_message .= sprintf( __('Permalink: %s'), get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment_id ) . "\r\n"; 
     289        if ( EMPTY_TRASH_DAYS ) 
     290            $notify_message .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "\r\n"; 
     291        else 
     292            $notify_message .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "\r\n"; 
     293        $notify_message .= sprintf( __('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id") ) . "\r\n"; 
     294 
     295        $wp_email = 'wordpress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])); 
     296 
     297        if ( '' == $comment->comment_author ) { 
     298            $from = "From: \"$blogname\" <$wp_email>"; 
     299            if ( '' != $comment->comment_author_email ) 
     300                $reply_to = "Reply-To: $comment->comment_author_email"; 
     301        } else { 
     302            $from = "From: \"$comment->comment_author\" <$wp_email>"; 
     303            if ( '' != $comment->comment_author_email ) 
     304                $reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>"; 
     305        } 
     306 
     307        $message_headers = "$from\n" 
     308            . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; 
     309 
     310        if ( isset($reply_to) ) 
     311            $message_headers .= $reply_to . "\n"; 
     312 
     313        $notify_message = apply_filters('comment_notification_text', $notify_message, $comment_id); 
     314        $subject = apply_filters('comment_notification_subject', $subject, $comment_id); 
     315        $message_headers = apply_filters('comment_notification_headers', $message_headers, $comment_id); 
     316         
    111317        /* 
    112318         * Begin changes here 
     
    136342    } 
    137343} 
     344>>>>>>> b0050ec04ed4b3934a36b1d3afdf97f4152d733c 
    138345?> 
  • cbnet-multi-author-comment-notification/trunk/readme.txt

    r643418 r664848  
    44Tags: cbnet, multi, author, comment, comments, comment notification, notification, notify, admin, administrator, email, maxblogpress 
    55Requires at least: 3.0 
    6 Tested up to: 3.5 
    7 Stable tag: 2.1.2 
     6Tested up to: 3.5.1 
     7Stable tag: 2.2 
    88 
    9 Send comment notification emails to multiple users. Select users individually or by user role, or send emails to arbitrary email addresses. 
     9Send comment notification and comment moderation emails to multiple users. Select users individually or by user role, or send emails to arbitrary email addresses. 
    1010 
    1111== Description == 
     
    5454== Changelog == 
    5555 
     56= 2.2 = 
     57* Feature Release 
     58 * Added option to send comment moderation emails to multiple authors 
     59 * Added filters to support potential core patches to Pluggable functions 
    5660= 2.1.2 = 
    5761* Bugfix.  
     
    9296== Upgrade Notice == 
    9397 
     98= 2.2 = 
     99Feature release. Option to add comment moderation emails to multiple authors. New filters. 
    94100= 2.1.2 = 
    95101Bugfix. Fixed call to deprecated function update_usermeta(). 
  • cbnet-multi-author-comment-notification/trunk/settings.php

    r642413 r664848  
     1<<<<<<< HEAD 
    12<?php 
    23/** 
     
    2829        'all_subscribers' => false, 
    2930        'additional_emails' => false, 
    30         'notify_for_registered_users' => true 
     31        'notify_for_registered_users' => true, 
     32        'notify_for_comment_moderation' => false 
    3133    ); 
    3234    return apply_filters( 'cbnet_macn_option_defaults', $defaults ); 
     
    8991            'default' => $defaults['notify_for_registered_users'] 
    9092        ), 
     93        'notify_for_comment_moderation' => array( 
     94            'name' => 'notify_for_comment_moderation', 
     95            'title' => __( 'Moderated Comment Notification', 'cbnet_macn' ), 
     96            'description' => __( 'Send notification emails for comments held for moderation', 'cbnet_macn' ), 
     97            'type' => 'checkbox', 
     98            'default' => $defaults['notify_for_comment_moderation'] 
     99        ), 
    91100    ); 
    92101    return apply_filters( 'cbnet_macn_option_parameters', $parameters ); 
     
    195204            <input type="checkbox" name="plugin_cbnet_macn_options[notify_for_registered_users]" value="true" <?php checked( true == $cbnet_macn_options['notify_for_registered_users'] ); ?>> 
    196205            <?php echo $option_parameters['notify_for_registered_users']['description']; ?> 
     206        </p> 
     207        <p> 
     208            <input type="checkbox" name="plugin_cbnet_macn_options[notify_for_comment_moderation]" value="true" <?php checked( true == $cbnet_macn_options['notify_for_comment_moderation'] ); ?>> 
     209            <?php echo $option_parameters['notify_for_comment_moderation']['description']; ?> 
    197210        </p> 
    198211        <?php 
     
    305318 
    306319} 
     320======= 
     321<?php 
     322/** 
     323 * Plugin Settings API Implementation 
     324 */ 
     325 
     326/** 
     327 * Globalize Plugin options 
     328 */ 
     329global $cbnet_macn_options; 
     330$cbnet_macn_options = cbnet_macn_get_options(); 
     331 
     332/** 
     333 * Get Plugin options 
     334 */ 
     335function cbnet_macn_get_options() { 
     336    return wp_parse_args( get_option( 'plugin_cbnet_macn_options', array() ), cbnet_macn_get_option_defaults() ); 
     337} 
     338 
     339/** 
     340 * Get Plugin option defaults 
     341 */ 
     342function cbnet_macn_get_option_defaults() { 
     343    $defaults = array(   
     344        'all_administrators' => false, 
     345        'all_editors' => false, 
     346        'all_authors' => false, 
     347        'all_contributors' => false, 
     348        'all_subscribers' => false, 
     349        'additional_emails' => false, 
     350        'notify_for_registered_users' => true 
     351    ); 
     352    return apply_filters( 'cbnet_macn_option_defaults', $defaults ); 
     353} 
     354 
     355/** 
     356 * Get Plugin option parameters 
     357 */ 
     358function cbnet_macn_get_option_parameters() { 
     359    $defaults = cbnet_macn_get_option_defaults(); 
     360    $parameters = array( 
     361        'all_administrators' => array( 
     362            'name' => 'all_administrators', 
     363            'title' => __( 'All Administrators', 'cbnet_macn' ), 
     364            'description' => __( 'Send comment notification emails to all Administrators', 'cbnet_macn' ), 
     365            'type' => 'checkbox', 
     366            'default' => $defaults['all_administrators'] 
     367        ), 
     368        'all_editors' => array( 
     369            'name' => 'all_editors', 
     370            'title' => __( 'All Editors', 'cbnet_macn' ), 
     371            'description' => __( 'Send comment notification emails to all Editors', 'cbnet_macn' ), 
     372            'type' => 'checkbox', 
     373            'default' => $defaults['all_editors'] 
     374        ), 
     375        'all_authors' => array( 
     376            'name' => 'all_authors', 
     377            'title' => __( 'All Authors', 'cbnet_macn' ), 
     378            'description' => __( 'Send comment notification emails to all Authors', 'cbnet_macn' ), 
     379            'type' => 'checkbox', 
     380            'default' => $defaults['all_authors'] 
     381        ), 
     382        'all_contributors' => array( 
     383            'name' => 'all_contributors', 
     384            'title' => __( 'All Contributors', 'cbnet_macn' ), 
     385            'description' => __( 'Send comment notification emails to all Contributors', 'cbnet_macn' ), 
     386            'type' => 'checkbox', 
     387            'default' => $defaults['all_contributors'] 
     388        ), 
     389        'all_subscribers' => array( 
     390            'name' => 'all_subscribers', 
     391            'title' => __( 'All Subscribers', 'cbnet_macn' ), 
     392            'description' => __( 'Send comment notification emails to all Subscribers', 'cbnet_macn' ), 
     393            'type' => 'checkbox', 
     394            'default' => $defaults['all_subscribers'] 
     395        ), 
     396        'additional_emails' => array( 
     397            'name' => 'additional_emails', 
     398            'title' => __( 'Additional Email Addresses', 'cbnet_macn' ), 
     399            'description' => __( 'Send comment notification emails to these additional email addresses', 'cbnet_macn' ), 
     400            'type' => 'text', 
     401            'sanitize' => 'emailarray', 
     402            'default' => $defaults['additional_emails'] 
     403        ), 
     404        'notify_for_registered_users' => array( 
     405            'name' => 'notify_for_registered_users', 
     406            'title' => __( 'Registered-User Comments', 'cbnet_macn' ), 
     407            'description' => __( 'Send notification emails for comments from registered users', 'cbnet_macn' ), 
     408            'type' => 'checkbox', 
     409            'default' => $defaults['notify_for_registered_users'] 
     410        ), 
     411    ); 
     412    return apply_filters( 'cbnet_macn_option_parameters', $parameters ); 
     413} 
     414  
     415/** 
     416 * Register Plugin Settings 
     417 */ 
     418function cbnet_macn_register_settings() { 
     419 
     420    /** 
     421    * Register Favicon setting 
     422    *  
     423    * Registers Favicon setting as 
     424    * part of core General settings 
     425    */ 
     426    register_setting( 'discussion', 'plugin_cbnet_macn_options', 'cbnet_macn_validate_settings' ); 
     427 
     428    /** 
     429     * Add settings section to Settings -> Discussion 
     430     */ 
     431    add_settings_section( 'cbnet_macn', __( 'cbnet Multi-Author Comment Notification Settings', 'cbnet_macn' ), 'cbnet_macn_settings_section', 'discussion' );   
     432     
     433    /** 
     434     * Discussion settings section callback 
     435     */ 
     436    function cbnet_macn_settings_section() { 
     437        echo '<p>' . __( 'Configure cbnet Multi-Author Comment Notification settings here.', 'cbnet_macn' ) . '</p>'; 
     438    } 
     439 
     440    /** 
     441    * Add user roles setting field 
     442    *  
     443    * Adds setting fields to  
     444    * Settings -> Discussion 
     445    */ 
     446    add_settings_field( 'cbnet_macn_user_roles', '<label for="cbnet_macn_user_roles">' . __( 'User Roles' , 'cbnet_macn' ) . '</label>', 'cbnet_macn_settings_field_user_roles', 'discussion', 'cbnet_macn' ); 
     447     
     448    /** 
     449     * User roles setting fields callback 
     450     */ 
     451    function cbnet_macn_settings_field_user_roles() { 
     452        global $cbnet_macn_options; 
     453        $option_parameters = cbnet_macn_get_option_parameters(); 
     454        ?> 
     455        <p> 
     456            <input type="checkbox" name="plugin_cbnet_macn_options[all_administrators]" value="true" <?php checked( true == $cbnet_macn_options['all_administrators'] ); ?>> 
     457            <?php echo $option_parameters['all_administrators']['description']; ?> 
     458            <br /> 
     459            <input type="checkbox" name="plugin_cbnet_macn_options[all_editors]" value="true" <?php checked( true == $cbnet_macn_options['all_editors'] ); ?>> 
     460            <?php echo $option_parameters['all_editors']['description']; ?> 
     461            <br /> 
     462            <input type="checkbox" name="plugin_cbnet_macn_options[all_authors]" value="true" <?php checked( true == $cbnet_macn_options['all_authors'] ); ?>> 
     463            <?php echo $option_parameters['all_authors']['description']; ?> 
     464            <br /> 
     465            <input type="checkbox" name="plugin_cbnet_macn_options[all_contributors]" value="true" <?php checked( true == $cbnet_macn_options['all_contributors'] ); ?>> 
     466            <?php echo $option_parameters['all_contributors']['description']; ?> 
     467            <br /> 
     468            <input type="checkbox" name="plugin_cbnet_macn_options[all_subscribers]" value="true" <?php checked( true == $cbnet_macn_options['all_subscribers'] ); ?>> 
     469            <?php echo $option_parameters['all_subscribers']['description']; ?> 
     470            <br /> 
     471        </p> 
     472        <?php 
     473    } 
     474 
     475    /** 
     476    * Add additional emails setting field 
     477    *  
     478    * Adds setting field to  
     479    * Settings -> Discussion 
     480    */ 
     481    add_settings_field( 'cbnet_macn_additional_emails', '<label for="cbnet_macn_additional_emails">' . __( 'Additional Emails' , 'cbnet_macn' ) . '</label>', 'cbnet_macn_settings_field_additional_emails', 'discussion', 'cbnet_macn' ); 
     482     
     483    /** 
     484     * Additional emails setting fields callback 
     485     */ 
     486    function cbnet_macn_settings_field_additional_emails() { 
     487        global $cbnet_macn_options; 
     488        $option_parameters = cbnet_macn_get_option_parameters(); 
     489        $additional_emails = ( is_array( $cbnet_macn_options['additional_emails'] ) ? implode( $cbnet_macn_options['additional_emails'], ',' ) : '' ); 
     490        ?> 
     491        <p> 
     492            <input type="text" size="80" name="plugin_cbnet_macn_options[additional_emails]" value="<?php echo esc_attr( $additional_emails ); ?>" /> 
     493            <br /> 
     494            <?php echo $option_parameters['additional_emails']['description']; ?> 
     495        </p> 
     496        <?php 
     497    } 
     498 
     499    /** 
     500    * Add Miscellaneous setting field 
     501    *  
     502    * Adds setting field to  
     503    * Settings -> Discussion 
     504    */ 
     505    add_settings_field( 'cbnet_macn_misc', '<label for="cbnet_macn_misc">' . __( 'Miscellaneous' , 'cbnet_macn' ) . '</label>', 'cbnet_macn_settings_field_misc', 'discussion', 'cbnet_macn' ); 
     506     
     507    /** 
     508     * CAPTCHA image setting fields callback 
     509     */ 
     510    function cbnet_macn_settings_field_misc() { 
     511        global $cbnet_macn_options; 
     512        $option_parameters = cbnet_macn_get_option_parameters(); 
     513        ?> 
     514        <p> 
     515            <input type="checkbox" name="plugin_cbnet_macn_options[notify_for_registered_users]" value="true" <?php checked( true == $cbnet_macn_options['notify_for_registered_users'] ); ?>> 
     516            <?php echo $option_parameters['notify_for_registered_users']['description']; ?> 
     517        </p> 
     518        <?php 
     519    } 
     520} 
     521add_action( 'admin_init', 'cbnet_macn_register_settings' ); 
     522 
     523 
     524 
     525/** 
     526 * Plugin register_setting() sanitize callback 
     527 *  
     528 * Validate and whitelist user-input data before updating Plugin  
     529 * Options in the database. Only whitelisted options are passed 
     530 * back to the database, and user-input data for all whitelisted 
     531 * options are sanitized. 
     532 *  
     533 * @link    http://codex.wordpress.org/Data_Validation  Codex Reference: Data Validation 
     534 *  
     535 * @param   array   $input  Raw user-input data submitted via the Plugin Settings page 
     536 * @return  array   $input  Sanitized user-input data passed to the database 
     537 */ 
     538function cbnet_macn_validate_settings( $input ) { 
     539 
     540    // This is the "whitelist": current settings 
     541    global $cbnet_macn_options; 
     542    $valid_input = $cbnet_macn_options; 
     543    // Get the array of option parameters 
     544    $option_parameters = cbnet_macn_get_option_parameters(); 
     545    // Get the array of option defaults 
     546    $option_defaults = cbnet_macn_get_option_defaults(); 
     547     
     548    // Determine what type of submit was input 
     549    $submittype = ( ! empty( $input['reset'] ) ? 'reset' : 'submit' );   
     550     
     551    // Loop through each setting 
     552    foreach ( $option_defaults as $setting => $value ) { 
     553         
     554        // If submit, validate/sanitize $input 
     555        if ( 'submit' == $submittype ) { 
     556         
     557            // Get the setting details from the defaults array 
     558            $optiondetails = $option_parameters[$setting]; 
     559            // Get the array of valid options, if applicable 
     560            $valid_options = ( isset( $optiondetails['valid_options'] ) ? $optiondetails['valid_options'] : false ); 
     561             
     562            // Validate checkbox fields 
     563            if ( 'checkbox' == $optiondetails['type'] ) { 
     564                // If input value is set and is true, return true; otherwise return false 
     565                $valid_input[$setting] = ( ( isset( $input[$setting] ) && true == $input[$setting] ) ? true : false ); 
     566            } 
     567            // Validate radio button fields 
     568            else if ( 'radio' == $optiondetails['type'] ) { 
     569                // Only update setting if input value is in the list of valid options 
     570                $valid_input[$setting] = ( array_key_exists( $input[$setting], $valid_options ) ? $input[$setting] : $valid_input[$setting] ); 
     571            } 
     572            // Validate select fields 
     573            else if ( 'select' == $optiondetails['type'] ) { 
     574                // Only update setting if input value is in the list of valid options 
     575                $valid_input[$setting] = ( in_array( $input[$setting], $valid_options ) ? $input[$setting] : $valid_input[$setting] ); 
     576            } 
     577            // Validate text input and textarea fields 
     578            else if ( ( 'text' == $optiondetails['type'] || 'textarea' == $optiondetails['type'] ) ) { 
     579                // Validate no-HTML content 
     580                if ( 'nohtml' == $optiondetails['sanitize'] ) { 
     581                    // Pass input data through the wp_filter_nohtml_kses filter 
     582                    $valid_input[$setting] = wp_filter_nohtml_kses( $input[$setting] ); 
     583                } 
     584                // Validate HTML content 
     585                if ( 'html' == $optiondetails['sanitize'] ) { 
     586                    // Pass input data through the wp_filter_kses filter 
     587                    $valid_input[$setting] = wp_filter_kses( $input[$setting] ); 
     588                } 
     589                // Validate integer content 
     590                if ( 'integer' == $optiondetails['sanitize'] ) {  
     591                    // Verify value is an integer 
     592                    $valid_input[$setting] = ( is_int( (int) $input[$setting] ) ? $input[$setting] : $valid_input[$setting] ); 
     593                } 
     594                // Validate RGB content 
     595                if ( 'rgb' == $optiondetails['sanitize'] ) {  
     596                    // Verify value is an integer 
     597                    $valid_input[$setting] = ( ( is_int( (int) $input[$setting] ) && 0 <= (int) $input[$setting] && 255 >= (int) $input[$setting] ) ? $input[$setting] : $valid_input[$setting] ); 
     598                } 
     599                // Validate Email Array content 
     600                if ( 'emailarray' == $optiondetails['sanitize'] ) { 
     601                    // Create array 
     602                    if ( false == strpos( $input[$setting], ',' ) ) { 
     603                        $input_emails = array( $input[$setting] ); 
     604                    } else { 
     605                        $input_emails = ( '' != $input[$setting] ? explode( ',', $input[$setting] ) : false ); 
     606                    } 
     607                    // Verify values are valid email addresses 
     608                    if ( false != $input_emails ) { 
     609                        foreach ( $input_emails as $email ) { 
     610                            $email = trim( $email ); 
     611                            if ( ! is_email( $email ) ) { unset( $input_emails[$email] ); } 
     612                        } 
     613                    } 
     614                    $valid_input[$setting] = ( ! empty( $input_emails ) ? $input_emails : false ); 
     615                } 
     616            } 
     617        }  
     618        // If reset, reset defaults 
     619        elseif ( 'reset' == $submittype ) { 
     620            // Set $setting to the default value 
     621            $valid_input[$setting] = $option_defaults[$setting]; 
     622        } 
     623    } 
     624    return $valid_input;         
     625 
     626} 
     627>>>>>>> b0050ec04ed4b3934a36b1d3afdf97f4152d733c 
    307628?> 
Note: See TracChangeset for help on using the changeset viewer.