post_page = true;
}
}
// Display notice in Admin panel
function admin_notice() {
global $post;
$meta = '';
if ( $this->post_page && is_object( $post) ) {
$meta = get_post_meta($post->ID, 'WyPiekacz_msg', true);
}
if ('' != $meta ) {
// Display error message
echo '
', $meta,
'
', __('Post Status has been changed to Draft.', 'wypiekacz'), '
', "\n";
// Remove this message
delete_post_meta( $post->ID, 'WyPiekacz_msg' );
// Change WP message to 'Post saved'
if ( isset( $_GET['message'] ) ) {
if ( '6' == $_GET['message'] ) {
$_GET['message'] = '7';
}
}
}
}
// Change redirect URL used after post is saved (WP2.9+)
function redirect_post_location( $location ) {
if ( count( $this->errors ) > 0 ) {
$location = remove_query_arg( 'message', $location );
$location = add_query_arg( 'message', '10', $location );
}
return $location;
}
// Check submitted post data
function wp_insert_post( $data, $post_arr ) {
if (
// Check only for posts
( 'post' == $data['post_type'])
// Check only if status is Published or Pending Review
&& ( in_array( $data['post_status'], array( 'publish', 'pending', 'future' ) ) )
// Editors (and above) can have limits too
&& ( ( !get_option( 'wypiekacz_limit_for_all' ) && !current_user_can( 'edit_others_posts' ) )
|| get_option( 'wypiekacz_limit_for_all' ) )
) {
$ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
$autosave = defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE;
// Need to check this here, because save_post hook is called later
// Also need to handle AJAX calls - both quickedit and autosave
$skip_check = false;
if ( get_option( 'wypiekacz_allow_skip_rules' ) && current_user_can( 'edit_others_posts' ) ) {
if ( $ajax && !$autosave ) { // Quickedit
$skip_check = get_post_meta( $post_arr['ID'], '_wypiekacz_skip_check', true );
} elseif ( isset( $post_arr['wypiekacz_nonce'] ) &&
wp_verify_nonce( $post_arr['wypiekacz_nonce'], plugin_basename(__FILE__) ) &&
isset( $post_arr['wypiekacz_skip_check'] )
) {
$skip_check = true;
}
}
if ( !$skip_check ) {
$data = $this->enforce_rules( $data );
$result = $this->check_precel_post( $data['post_content'], $data['post_title'], $post_arr );
if ( true !== $result ) {
// Revert post status to Draft
$data['post_status'] = 'draft';
if ( !current_user_can( 'edit_others_posts' ) && isset( $post_arr['ID'] ) ) {
// Delete 'skip check' flag when normal user will spoil the post
delete_post_meta( $post_arr['ID'], '_wypiekacz_skip_check' );
}
// This is not supported in the core yet
// See https://core.trac.wordpress.org/ticket/10480
/*if ( $ajax ) {
$errors = $this->errors;
$this->errors = array();
return new WP_Error( 'edit_refused', implode( '; ', $errors ) );
}*/
}
}
}
return $data;
}
// Called after post is saved - save error messages too
function save_post( $post_ID ) {
// Check if 'Skip rule check' option was checked
// verify this came from the our screen and with proper authorisation,
// because save_post can be triggered at other times
if ( get_option( 'wypiekacz_allow_skip_rules' ) && isset( $_POST['wypiekacz_nonce'] ) &&
wp_verify_nonce( $_POST['wypiekacz_nonce'], plugin_basename(__FILE__) ) &&
( $_POST['post_type'] == 'post' ) && current_user_can( 'edit_post', $post_ID ) &&
current_user_can( 'edit_others_posts' )
) {
// OK, we're authenticated: do the work now
$skip_check = isset( $_POST['wypiekacz_skip_check'] ) ? trim( $_POST['wypiekacz_skip_check'] ) : '';
if ( !empty( $skip_check ) ) {
update_post_meta( $post_ID, '_wypiekacz_skip_check', 1 );
} else {
delete_post_meta( $post_ID, '_wypiekacz_skip_check' );
}
}
if ( count( $this->errors ) > 0 ) {
delete_post_meta( $post_ID, 'WyPiekacz_msg' );
add_post_meta( $post_ID, 'WyPiekacz_msg', implode( '
', $this->errors ), true );
}
}
// Add new column to the Edit Posts page
function manage_edit_columns( $columns ) {
if ( current_user_can( 'edit_others_posts' ) ) {
$columns['wypiekacz'] = __('WyPiekacz Status', 'wypiekacz');
}
return $columns;
}
// Print values in new column on the Edit Posts page
function manage_posts_custom_column( $column_name, $postID ) {
if ( current_user_can( 'edit_others_posts' ) && $column_name === 'wypiekacz' ) {
if ( get_option( 'wypiekacz_allow_skip_rules' ) &&
get_post_meta( $postID , '_wypiekacz_skip_check', true ) ) {
_e('[Skipped check]', 'wypiekacz');
} else {
$post = get_post( $postID );
if ( $this->check_precel_post( $post->post_content, $post->post_title, $post ) === true) {
_e('OK', 'wypiekacz');
} else {
echo '', implode( '
', $this->errors ), "\n";
$this->errors = array();
}
}
}
}
// Callback - remove extra links
function rx_remove_links( $matches ) {
++$this->link_counter;
if ( $this->link_counter > get_option( 'wypiekacz_max_links' ) ) {
return $matches[2];
} else {
return $matches[1].$matches[2].$matches[3];
}
}
// Return word count (Note: empty string = 0 words)
function count_words( $text ) {
$text2 = preg_replace( '/<.[^<>]*?>/', ' ', $text );
$text2 = preg_replace( '/ | /i', ' ', $text2 );
$text2 = preg_replace( '/[0-9.(),;:!?%#$¿\'"_+=\\/-]*/', '', $text2 );
$text2 = trim( $text2 );
if ( $text2 == '' ) {
$count = 0;
} else {
$count = preg_match_all( '/\S\s+/', $text2, $matches );
if ( $count !== false ) {
$count += 1;
} else {
$count = -1; // Error!
}
}
return $count;
}
// Enforce rules for posts
function enforce_rules( $data ) {
// Enforce max link count
if ( get_option( 'wypiekacz_enforce_links' ) ) {
$this->link_counter = 0;
$data['post_content'] = preg_replace_callback( '#(]*href\s*=\s*[^>]+[^>]*>)(.*?)()#',
array( &$this, 'rx_remove_links' ), $data['post_content'] );
}
$add_dots = get_option( 'wypiekacz_enforce_add_dots' );
// Enforce max title length
if ( get_option( 'wypiekacz_enforce_title' ) ) {
$need_dots = false;
// Enforce max length (in words)
$max_len = get_option( 'wypiekacz_max_title_len_words' );
$count = $this->count_words( $data['post_title'] );
if ( ( $max_len > 0 ) && ( $count > $max_len ) ) {
$title = trim( $data['post_title'] );
$words = preg_split( '/((?: | |\s)+)/i', $title, -1, PREG_SPLIT_DELIM_CAPTURE );
$data['post_title'] = implode( '', array_slice( $words, 0, $max_len * 2 - 1 ) );
$need_dots = true;
}
// Enforce max length (in chars)
$max_len = get_option( 'wypiekacz_max_title_len' );
$len = strlen( $data['post_title'] );
if ( ( $max_len > 0 ) && ( $len > $max_len ) ) {
if ( $add_dots ) {
$max_len -= 3; // Make room for three dots at the end
$need_dots = true;
}
if ( version_compare( PHP_VERSION, '5', '<' ) ) {
$data['post_title'] = substr( $data['post_title'], 0, $max_len + 1 );
$pos = strrpos( $data['post_title'], ' ' );
} else {
$pos = strrpos( $data['post_title'], ' ', $max_len - $len );
}
if ( $pos !== false ) {
$data['post_title'] = substr( $data['post_title'], 0, $pos );
} else {
// No spaces? Interesting...
$data['post_title'] = substr( $data['post_title'], 0, $max_len );
}
}
if ( $add_dots && $need_dots ) {
$data['post_title'] .= '...';
}
}
// TODO: Enforce max category count
// Not supported in WP core yet
/*if ( get_option( 'wypiekacz_enforce_cats' ) ) {
}*/
// TODO: Enforce max tag count
// Not supported in WP core yet
/*if ( get_option( 'wypiekacz_enforce_tags' ) ) {
}*/
return $data;
}
// Enforce rules for posts - modify $_POST array
function enforce_rules_POST() {
if ( isset( $_POST['post_category'] ) && is_array( $_POST['post_category'] ) ) {
// Remove non-existing categories from user's POST data
/*if ( true ) {
$blog_cats = get_all_category_ids();
$cats = array();
foreach ( $_POST['post_category'] as $category ) {
if ( in_array( $category, $blog_cats ) ) {
$cats[] = $category;
}
}
$_POST['post_category'] = $cats;
}*/
// Enforce max category count
if ( get_option( 'wypiekacz_enforce_cats' ) ) {
$max_cats = get_option( 'wypiekacz_max_cats' );
if ( count( $_POST['post_category'] ) > $max_cats ) {
// Try to remove default category first, if it is forbidden
if ( !get_option( 'wypiekacz_use_def_cat' ) ) {
$default_cat = get_option( 'default_category' );
$pos = array_search( $default_cat, $_POST['post_category'] );
if ( $pos !== false ) {
array_splice( $_POST['post_category'], $pos, 1 );
}
}
}
if ( count( $_POST['post_category'] ) > $max_cats ) {
// Remove extra categories if still there are too many
array_splice( $_POST['post_category'], $max_cats );
}
}
}
// Enforce max tag count
if ( get_option( 'wypiekacz_enforce_tags' ) ) {
$max_tags = get_option( 'wypiekacz_max_tags' );
$found_tags = 0;
// Simple Post Tags plugin uses this
if ( !empty( $_POST['adv-tags-input'] ) ) {
$tags = explode( ',', $_POST['adv-tags-input'] );
$cnt = 0;
foreach ($tags as $tag) {
if ( trim( $tag ) != '' ) {
++$cnt;
}
}
if ( $cnt > $max_tags ) {
$tags = array_slice( $tags, 0, $max_tags );
$_POST['adv-tags-input'] = implode( ',', $tags );
}
$found_tags += count( $tags );
}
// WordPress 2.8+ uses general taxonomy support for tags too
// Need to check this first, because $post_data['tags_input'] is set too
// Check default tag taxonomy
if ( !empty( $_POST['tax_input'] ) && is_array( $_POST['tax_input'] )
&& isset( $_POST['tax_input']['post_tag'] ) ) {
$tags = explode( ',', $_POST['tax_input']['post_tag'] );
if ( $found_tags + count( $tags ) > $max_tags ) {
if ( $found_tags >= $max_tags ) {
unset( $_POST['tax_input']['post_tag'] );
$tags = array();
} else {
$tags = array_slice( $tags, 0, $max_tags - $found_tags );
$_POST['tax_input']['post_tag'] = implode( ',', $tags );
}
}
$found_tags += count( $tags );
}
// Default WordPress field (up to 2.7.1)
// Note: For some reason WP2.8 puts here an array when updating post
if ( !empty( $_POST['tags_input'] ) ) {
/*if ( is_array( $post_data['tags_input'] ) ) {
$tags = $post_data['tags_input'];
} else {
$tags = explode( ',', $post_data['tags_input'] );
}*/
$tags = explode( ',', $_POST['tags_input'] );
if ( $found_tags + count( $tags ) > $max_tags ) {
if ( $found_tags >= $max_tags ) {
unset( $_POST['tags_input'] );
//$tags = array();
} else {
$tags = array_slice( $tags, 0, $max_tags - $found_tags );
$_POST['tags_input'] = implode( ',', $tags );
}
}
//$found_tags += count( $tags );
}
}
}
// Check for badwords
function check_badwords( $text ) {
$has_mb = function_exists( 'mb_convert_case' );
$words_found = array();
if ( $has_mb ) {
$text = mb_convert_case( $text, MB_CASE_LOWER );
$len = mb_strlen( $text );
} else {
$text = strtolower( $text );
$len = strlen( $text );
}
$badwords = get_option( 'wypiekacz_badwords', array() );
$goodwords = get_option( 'wypiekacz_goodwords', array() );
foreach ( $badwords as $badword ) {
$pos_bad = 0;
while ( $pos_bad < $len ) {
// Try to find badword in text
if ( $has_mb ) {
$pos_bad = mb_strpos( $text, $badword, $pos_bad );
} else {
$pos_bad = strpos( $text, $badword, $pos_bad );
}
// Found badword in text
if ( $pos_bad !== false ) {
$found_good = false;
foreach ( $goodwords as $goodword ) {
// Try to find badword in goodword
if ( $has_mb ) {
$pos_good = mb_strpos( $goodword, $badword );
} else {
$pos_good = strpos( $goodword, $badword );
}
// Found badword in goodword
if ( $pos_good !== false ) {
$good_start = $pos_bad - $pos_good;
if ( $has_mb ) {
$good_len = mb_strlen( $goodword );
$maybe_good = mb_substr( $text, $good_start, $good_len );
} else {
$good_len = strlen( $goodword );
$maybe_good = substr( $text, $good_start, $good_len );
}
// Check if word in text is good
if ( $maybe_good == $goodword ) {
$found_good = true;
break;
}
}
}
if ( !$found_good ) {
$words_found[] = $badword;
break; // exit $badwords loop
} else {
// This was a false hit - continue searching
if ( $has_mb ) {
$pos_bad += mb_strlen( $badword );
} else {
$pos_bad += strlen( $badword );
}
}
} else {
break; // exit loop - badword not found
}
}
}
return $words_found;
}
// Check if post obeys rules
function check_precel_post( $text, $title, $post_data ) {
// Check length (in characters)
$min_len = get_option( 'wypiekacz_min_len' );
$text2 = preg_replace( '/\s\s+/', ' ', trim( strip_tags( $text ) ) );
$len = strlen( $text2 );
if ( $len < $min_len ) {
$this->errors[] = sprintf( __('Post is too short (minimum is %1$s chars, your post has %2$s).', 'wypiekacz'),
$min_len, $len );
}
// Check length (in words)
$min_len = get_option( 'wypiekacz_min_len_words' );
$count = $this->count_words( $text );
if ( $count < $min_len ) {
$this->errors[] = sprintf( __('Post is too short (minimum is %1$s words, your post has %2$s).', 'wypiekacz'),
$min_len, $count );
}
// Check links
$max_links = get_option( 'wypiekacz_max_links' );
$cnt = preg_match_all( '/<\s*a\s/i', $text, $matches );
if ( $cnt > $max_links ) {
$this->errors[] = sprintf( __('Post contains too many links (maximum is %1$s, your post has %2$s).', 'wypiekacz'),
$max_links, $cnt );
}
// Check title length (in characters)
$min_len = get_option( 'wypiekacz_min_title_len' );
$max_len = get_option( 'wypiekacz_max_title_len' );
$text2 = trim( $title );
$len = strlen( $text2 );
if ( $len < $min_len ) {
$this->errors[] = sprintf( __('Post Title is too short (minimum is %1$s chars, your Title has %2$s).', 'wypiekacz'),
$min_len, $len );
}
elseif ( ( $max_len > 0 ) && ( $len > $max_len ) ) {
$this->errors[] = sprintf( __('Post Title is too long (maximum is %1$s chars, your Title has %2$s).', 'wypiekacz'),
$max_len, $len );
}
// Check title length (in words)
$min_len = get_option( 'wypiekacz_min_title_len_words' );
$max_len = get_option( 'wypiekacz_max_title_len_words' );
$count = $this->count_words( $title );
if ( $count < $min_len ) {
$this->errors[] = sprintf( __('Post Title is too short (minimum is %1$s words, your Title has %2$s).', 'wypiekacz'),
$min_len, $count );
}
elseif ( ( $max_len > 0 ) && ( $count > $max_len ) ) {
$this->errors[] = sprintf( __('Post Title is too long (maximum is %1$s words, your Title has %2$s).', 'wypiekacz'),
$max_len, $count );
}
if ( is_array( $post_data ) ) {
// Get categories from POST data
if ( empty( $post_data['post_category'] ) || ( 0 == count( $post_data['post_category'] ) )
|| !is_array( $post_data['post_category'] ) ) {
$post_cat_cnt = 0;
$categories = array();
} else {
$post_cat_cnt = count( $post_data['post_category'] );
$categories = $post_data['post_category'];
}
} else {
// Get categories from Post object
$categories = wp_get_post_categories( $post_data->ID );
$post_cat_cnt = count( $categories );
}
$has_default_cat = false;
$default_cat = get_option( 'default_category' );
foreach ( $categories as $category ) {
if ( $category == $default_cat ) {
$has_default_cat = true;
break;
}
}
// Check default category
$use_default_cat = get_option( 'wypiekacz_use_def_cat' );
if ( !$use_default_cat && $has_default_cat ) {
$this->errors[] = sprintf( __('Cannot add posts to the default category (%s).', 'wypiekacz'),
get_cat_name( $default_cat ) );
}
// When post doesn't have categories, default one will be used
if ( ( 0 == $post_cat_cnt ) && $use_default_cat ) {
$post_cat_cnt = 1;
}
// Check categories count
$min_cats = get_option( 'wypiekacz_min_cats' );
$max_cats = get_option( 'wypiekacz_max_cats' );
if ( $post_cat_cnt < $min_cats ) {
$this->errors[] = sprintf( __('Too few categories selected (minimum is %1$s, your post has %2$s).', 'wypiekacz'),
$min_cats, $post_cat_cnt );
} else if ( $post_cat_cnt > $max_cats ) {
$this->errors[] = sprintf( __('Too many categories selected (maximum is %1$s, your post has %2$s).', 'wypiekacz'),
$max_cats, $post_cat_cnt );
}
if ( is_array( $post_data ) ) {
//var_dump($post_data);die;
$post_tag_cnt = 0;
$tags = array();
// Get tags from POST data
if ( !empty( $post_data['adv-tags-input'] ) ) {
// Simple Post Tags plugin uses this
$tags = explode( ',', $post_data['adv-tags-input'] );
} else if ( !empty( $post_data['tax_input'] ) && is_array( $post_data['tax_input'] ) ) {
// WordPress 2.8+ uses general taxonomy support for tags too
// Need to check this first, because $post_data['tags_input'] is set too
// Check default tag taxonomy
if ( isset( $post_data['tax_input']['post_tag'] ) ) {
$tags = explode( ',', $post_data['tax_input']['post_tag'] );
}
} else if ( !empty( $post_data['tags_input'] ) ) {
// Default WordPress field (up to 2.7.1)
// Note: For some reason WP2.8 puts here an array when updating post
if ( is_array( $post_data['tags_input'] ) ) {
$tags = $post_data['tags_input'];
} else {
$tags = explode( ',', $post_data['tags_input'] );
}
}
foreach ($tags as $tag) {
if ( trim( $tag ) != '' ) {
++$post_tag_cnt;
}
}
} else {
// Get tags from Post object
$tags = wp_get_post_tags( $post_data->ID );
$post_tag_cnt = count( $tags );
}
// Check tag count
$min_tags = get_option( 'wypiekacz_min_tags' );
$max_tags = get_option( 'wypiekacz_max_tags' );
if ( $post_tag_cnt < $min_tags ) {
$this->errors[] = sprintf( __('Too few tags (minimum is %1$s, your post has %2$s).', 'wypiekacz'),
$min_tags, $post_tag_cnt );
} else if ($post_tag_cnt > $max_tags) {
$this->errors[] = sprintf( __('Too many tags (maximum is %1$s, your post has %2$s).', 'wypiekacz'),
$max_tags, $post_tag_cnt );
}
// Check forbidden words in title
if ( get_option( 'wypiekacz_check_badwords_title' ) ) {
$words_found = $this->check_badwords( $title );
if ( count( $words_found ) > 0 ) {
$this->errors[] = sprintf( __('Forbidden word(s) in title: %s', 'wypiekacz'),
implode( ', ', $words_found ) );
}
}
// Check forbidden words in content
if ( get_option( 'wypiekacz_check_badwords_content' ) ) {
$words_found = $this->check_badwords( $text );
if ( count( $words_found ) > 0 ) {
$this->errors[] = sprintf( __('Forbidden word(s) in content: %s', 'wypiekacz'),
implode( ', ', $words_found ) );
}
}
return count( $this->errors ) == 0;
}
// Set Title and Content using defined template
function submitpost_box() {
global $post;
// Title
if ( empty( $post->post_title ) || ( '' == $post->post_title ) ) {
$post->post_title = get_option( 'wypiekacz_def_title' );
}
// Text
if ( empty( $post->post_content ) || ( '' == $post->post_content ) ) {
$post->post_content = get_option( 'wypiekacz_def_text' );
}
}
// Show meta box on edit post page
function post_metabox( $post ) {
if ( !get_option( 'wypiekacz_allow_skip_rules' ) || !current_user_can( 'edit_others_posts' ) ) {
return;
}
$skip_check = get_post_meta( $post->ID , '_wypiekacz_skip_check', true );
?>
draft );
$text = _n( 'Draft', 'Drafts', $num_posts->draft, 'wypiekacz' );
$num = "$num";
$text = "$text";
echo '| ', $num, ' | ', $text,
' | |
';
}
if ( $can_publish ) {
// Pending Posts count
$num = number_format_i18n( $num_posts->pending );
$text = _n( 'Pending', 'Pending', $num_posts->pending, 'wypiekacz' );
$num = "$num";
$text = "$text";
echo '| ', $num, ' | ', $text,
' | |
';
}
}
// Handle options panel
function options_panel() {
?>
1 ) {
$value = 1;
}
}
return $value;
}
function sanitize_nonnegative( $value ) {
$value = (int)$value;
if ( $value < 0 ) {
$value = 0;
}
return $value;
}
function sanitize_stringlist( $value ) {
$value = explode( "\n", (string)$value );
$ret = array();
$has_mb = function_exists( 'mb_convert_case' );
$encoding = get_option( 'blog_charset' );
foreach ( $value as $val ) {
$val = trim( $val );
if ( $val != '' ) {
if ( $has_mb ) {
$val = mb_convert_case( $val, MB_CASE_LOWER, $encoding );
}
if ( !in_array( $val, $ret ) ) {
$ret[] = $val;
}
}
}
return $ret;
}
} // End Class
// Add options
add_option( 'wypiekacz_min_len', 1000 ); // Minimum post length (characters)
add_option( 'wypiekacz_min_len_words', 0 ); // Minimum post length (words)
add_option( 'wypiekacz_max_links', 3 ); // Maximum links per post
add_option( 'wypiekacz_min_title_len', 5 ); // Minimum title length (characters)
add_option( 'wypiekacz_min_title_len_words', 0 ); // Minimum title length (words)
add_option( 'wypiekacz_max_title_len', 80 ); // Maximum title length (characters); 0 = disable check
add_option( 'wypiekacz_max_title_len_words', 0 ); // Maximum title length (words); 0 = disable check
add_option( 'wypiekacz_use_def_cat', 1 ); // Posts can be added to the default category
add_option( 'wypiekacz_min_cats', 1 ); // Minimum category count
add_option( 'wypiekacz_max_cats', 3 ); // Maximum category count
add_option( 'wypiekacz_min_tags', 1 ); // Minimum tag count
add_option( 'wypiekacz_max_tags', 5 ); // Maximum tag count
add_option( 'wypiekacz_limit_for_all', 1 ); // Check ruled for Editors and Administrators
add_option( 'wypiekacz_def_title', '' ); // Default post title
add_option( 'wypiekacz_def_text', '' ); // Default post text
add_option( 'wypiekacz_new_login_email', 1 ); // Send notification of new login creation to admin
add_option( 'wypiekacz_pass_reset_email', 1 ); // Send notification of password resets to admin
add_option( 'wypiekacz_right_now_stats', 1 ); // Show number of Drafts and Pending Posts in Dashboard
add_option( 'wypiekacz_badwords', array() ); // List of forbidden words
add_option( 'wypiekacz_check_badwords_title', 0 ); // Check for forbidden words in title
add_option( 'wypiekacz_check_badwords_content', 0 ); // Check for forbidden words in content
add_option( 'wypiekacz_goodwords', array() ); // List of allowed words
add_option( 'wypiekacz_enforce_links', 0 ); // Enforce max link count
add_option( 'wypiekacz_enforce_title', 0 ); // Enforce max title length
add_option( 'wypiekacz_enforce_add_dots', 1 ); // Enforce max title length
add_option( 'wypiekacz_enforce_cats', 0 ); // Enforce max category count
add_option( 'wypiekacz_enforce_tags', 0 ); // Enforce max tag count
add_option( 'wypiekacz_allow_skip_rules', 1 ); // Allow Editors and Administrators to skip rule check
$wp_wypiekacz = new WyPiekacz();
$wp_wypiekacz->enforce_rules_POST();
// Redefine default WordPress functions in order to get control over sending extra emails to admin
if ( !get_option('wypiekacz_new_login_email') && !function_exists( 'wp_new_user_notification' ) ) {
// Notify user of his new username and password (skip admin)
function wp_new_user_notification( $user_id, $plaintext_pass = '' ) {
// Allow other plugins to override wp_new_user_notification() too
if ( !apply_filters( 'wypiekacz_send_email_to_new_user', true, $user_id, $plaintext_pass ) ) {
return;
}
if ( empty($plaintext_pass) )
return;
$user = new WP_User($user_id);
$user_login = stripslashes($user->user_login);
$user_email = stripslashes($user->user_email);
$message = sprintf(__('Username: %s'), $user_login) . "\r\n";
$message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";
$message .= wp_login_url() . "\r\n";
@wp_mail($user_email, sprintf(__('[%s] Your username and password'), get_option('blogname')), $message);
}
}
if ( !get_option('wypiekacz_pass_reset_email') && !function_exists( 'wp_password_change_notification' ) )
{
// Don't send password change notifications to admin
function wp_password_change_notification(&$user) {
}
}
} // END
?>