Last active
October 2, 2015 19:34
-
-
Save JeppeSigaard/1a439d2af6d4615c41c8 to your computer and use it in GitHub Desktop.
Toms escaping test just got bad asser
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
<?php | |
/* | |
Plugin Name: Toms Escaping test | |
Plugin URI: http://tomjn.com | |
Description: Provides a tomjn_esc_test shortcode that lets you test values with escaping | |
Author: Tom J Nowell | |
Version: 1.0 | |
Author URI: http://www.tomjn.com/escaping | |
License: GPLv2 or later | |
License URI: http://www.gnu.org/licenses/gpl-2.0.html | |
This program 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 | |
(at your option) any later version. | |
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. | |
*/ | |
function tomjn_escaping_tests(){ | |
$value = (!empty( $_POST['tomjn_esc_value'] ) ) ? $_POST['tomjn_esc_value'] : false; | |
if($value){ | |
global $wpdb; | |
$esc_array = array( | |
'esc_html' => esc_html($value), | |
'esc_attr' => esc_attr($value), | |
'esc_js' => esc_js($value), | |
'esc_textarea' => esc_html( esc_textarea( $value ) ), | |
'esc_url' => esc_url($value), | |
'esc_url_raw' => esc_url_raw($value), | |
'esc_sql' => esc_html( esc_sql( $value ) ), | |
'wp_json_encode' => esc_html(wp_json_encode($value)), | |
'wp_kses( , array(), array())' => esc_html(wp_kses( $value, array(), array())), | |
'esc_kses_post' => esc_html( wp_kses_post( $value ) ), | |
'wp_strip_all_tags' => wp_strip_all_tags($value), | |
'strip_tags' => strip_tags($value), | |
'htmlentities' => htmlentities($value), | |
'urlencode' => urlencode($value), | |
'rawurlencode' => rawurlencode($value), | |
'sanitize_email' => sanitize_email($value), | |
'sanitize_file_name' => sanitize_file_name($value), | |
'sanitize_html_class' => sanitize_html_class($value), | |
'sanitize_key' => sanitize_key($value), | |
'sanitize_meta' => sanitize_meta($value), | |
'sanitize_mime_type' => sanitize_mime_type($value), | |
'sanitize_option' => sanitize_option($value), | |
'sanitize_post' => sanitize_post($value), | |
'sanitize_sql_orderby' => sanitize_sql_orderby($value), | |
'sanitize_term' => sanitize_term($value), | |
'sanitize_term_field' => sanitize_term_field($value), | |
'sanitize_text_field' => sanitize_text_field($value), | |
'sanitize_title' => sanitize_title($value), | |
'sanitize_title_for_query' => sanitize_title_for_query($value), | |
'sanitize_title_with_dashes' => sanitize_title_with_dashes($value), | |
'sanitize_user' => sanitize_user($value), | |
'balanceTags' => balanceTags($value), | |
'tag_escape' => tag_escape($value), | |
'addslashes' => addslashes($value), | |
'$wpdb->esc_like' => $wpdb->esc_like($value), | |
'$wpdb->prepare' => $wpdb->prepare($value), | |
); | |
} | |
ob_start(); ?> | |
<form action="" method="post"> | |
<textarea name="tomjn_esc_value"> | |
<?php if ($value) { echo $esc_array['esc_textarea']; } ?> | |
</textarea> | |
<p><small>Refresh rather than re-submit if you\'re having problems with expanding quote escaping</small></p> | |
<p><input type="submit" value="escape"></p> | |
</form> | |
<?php if ($value) : ?> | |
<dl> | |
<?php foreach($esc_array as $key => $val) : ?> | |
<dt><?php echo $key; ?></dt> | |
<dd><pre><?php echo $val; ?></pre></dd> | |
<?php endforeach; ?> | |
</dl> | |
<?php endif; return ob_get_clean(); | |
} | |
add_shortcode( 'tomjn_esc_test', 'tomjn_escaping_tests' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment