-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
496 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,75 @@ | ||
<?php | ||
/** | ||
* WordPress blacklist checker | ||
* Helpful helpers loaded before helpful classes. | ||
* | ||
* @param string $content the content to be checked. | ||
* | ||
* @return bool | ||
* @package Helpful | ||
* @author Pixelbart <[email protected]> | ||
*/ | ||
function helpful_backlist_check( $content ) { | ||
$mod_keys = trim( get_option( 'blacklist_keys' ) ); | ||
|
||
if ( '' == $mod_keys ) { | ||
return false; | ||
} | ||
if ( ! function_exists( 'helpful_backlist_check' ) ) { | ||
/** | ||
* WordPress blacklist checker | ||
* | ||
* @param string $content the content to be checked. | ||
* | ||
* @return bool | ||
*/ | ||
function helpful_backlist_check( $content ) { | ||
$mod_keys = trim( get_option( 'blacklist_keys' ) ); | ||
|
||
if ( '' === $mod_keys ) { | ||
return false; | ||
} | ||
|
||
$without_html = wp_strip_all_tags( $content ); | ||
$words = explode( "\n", $mod_keys ); | ||
$without_html = wp_strip_all_tags( $content ); | ||
$words = explode( "\n", $mod_keys ); | ||
|
||
foreach ( (array) $words as $word ) : | ||
$word = trim( $word ); | ||
foreach ( (array) $words as $word ) : | ||
$word = trim( $word ); | ||
|
||
if ( empty( $word ) ) { | ||
continue; | ||
} | ||
if ( empty( $word ) ) { | ||
continue; | ||
} | ||
|
||
$word = preg_quote( $word, '#' ); | ||
$pattern = "#$word#i"; | ||
$word = preg_quote( $word, '#' ); | ||
$pattern = "#$word#i"; | ||
|
||
if ( preg_match( $pattern, $content ) || preg_match( $pattern, $without_html ) ) { | ||
return true; | ||
} | ||
endforeach; | ||
if ( preg_match( $pattern, $content ) || preg_match( $pattern, $without_html ) ) { | ||
return true; | ||
} | ||
endforeach; | ||
|
||
return false; | ||
} | ||
} | ||
|
||
if ( ! function_exists( 'helpful_trim_all' ) ) { | ||
/** | ||
* Trim all whitespaces. | ||
* | ||
* @param string $string string to trim. | ||
* @return string | ||
*/ | ||
function helpful_trim_all( $string ) { | ||
return preg_replace( '/\s+/', '', $string ); | ||
} | ||
} | ||
|
||
return false; | ||
if ( ! function_exists( 'helpful_error_log' ) ) { | ||
/** | ||
* This allows custom error messages to be placed in the error_logs. | ||
* WP_DEBUG and WP_DEBUG_LOG must be set to true. | ||
* | ||
* @source https://wordpress.org/support/article/debugging-in-wordpress/ | ||
* @param string $message error message. | ||
*/ | ||
function helpful_error_log( $message ) { | ||
if ( true === WP_DEBUG ) { | ||
if ( is_array( $message ) || is_object( $message ) ) { | ||
error_log( print_r( $message, true ) ); | ||
} else { | ||
error_log( $message ); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.