-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwordpress-content-helper.php
80 lines (66 loc) · 2.41 KB
/
wordpress-content-helper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/*
Plugin Name: WordPress Content Helper
Plugin URI: https://github.com/chrisbergr/Wordpress-Content-Helper
Description: WordPress Content Helper adds some helper functionality to the contents of a WordPress page.
Version: 0.9.1
Text Domain: wordpress-content-helper
Author: Christian Hockenberger
Author URI: https://christian.hockenberger.us
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Copyright 2019 Christian Hockenberger ([email protected])
WordPress Content Helper is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
any later version.
WordPress Content Helper is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with WordPress Content Helper. If not, see http://www.gnu.org/licenses/gpl-2.0.html.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Returns string with ASCII convertet characters
*
* @since 0.9.1
* @access public
*
* @param string $str
* @return string
*/
function wpch_convert_to_ascii( $str ) {
$pieces = str_split( trim( $str ) );
$new_str = '';
foreach( $pieces as $val ) {
$new_str .= '&#' . ord( $val ) . ';';
}
return $new_str;
}
/**
* Convert email addresses into ASCII strings to optimistically protect them from spambots
*
* Output:
* <a href="mailto:mail@example.com">Linktitle</a>
*
* @since 0.9.1
* @access public
*
* @param string $content Content from the WordPress filter
* @return string
*/
function wpch_process_email( $content ) {
$pattern = '/(mailto\:)?[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i';
preg_match_all( $pattern, $content, $matches );
foreach ( $matches[0] as $key => $replacement ) {
$content = preg_replace( $pattern, wpch_convert_to_ascii( $replacement ), $content, 1 );
}
return $content;
}
add_filter( 'the_content', 'wpch_process_email' );
add_filter( 'the_excerpt', 'wpch_process_email' );
add_filter( 'widget_text', 'wpch_process_email' );