Tag Info

Hot answers tagged

12

< and > are encoded as +ADw- and +AD4- in UTF-7. Now imagine the following: Someone sends +ADw-script+AD4-alert(+ACI-Hello+ACI-)+ADw-/script+AD4- as comment text. It will pass all validation unescaped. The database expects and treats all incoming data as UTF-8. Since all UTF-7 streams are valid UTF-8 too, this will never result in a SQL error, and ...


3

first add this function to your functions.php file function max_title_length($title){ $max = 20; return substr( $title, 0, $max ). " &hellip;"; } then before the loop of the code you linked add this line to hook the above function: add_filter( 'the_title', 'max_title_length'); and after the loop remove this filter: remove_filter( ...


2

i used this code in one of my last projects: function ng_get_excerpt($count){ $permalink = get_permalink($post->ID); $excerpt = get_the_content(); $excerpt = strip_tags($excerpt); $excerpt = substr($excerpt, 0, $count); $excerpt = substr($excerpt, 0, strripos($excerpt, " ")); $excerpt = rtrim($excerpt,",.;:- _!$&#"); $excerpt = ...


2

In the form you have posted this is more of PHP question - you could use strlen() functions to determine length of original title and apply ellipsis conditionally. However in WP context you should consider using wp_trim_words() since trimming based on words looks tidier and it will take care of appending string of your choice whet cutting.


2

Figured it out, hooking into content_save_pre: function remove_empty_lines( $content ){ // replace empty lines $content = preg_replace("/&nbsp;/", "", $content); return $content; } add_action('content_save_pre', 'remove_empty_lines');


2

You have to either 1) take all the whitespace out of the script so WordPress does not add <p> tags and then the JS will work, or 2) disable autop in the post editor for all posts/pages (see http://codex.wordpress.org/Function_Reference/wpautop ) so WP doesn't add paragraph breaks, or 3) do the following, which leaves autop enabled globally, but lets ...


2

Three dots are converted to the typographically correct ellipsis … in wptexturize(). You can disable it in many cases, see my plugin Disable Wptexturize.


2

That conversion - among others - is caused by the wptexturize() filter being applied to the_content(). The sledge-hammer approach to preventing wp_texturize() being applied to the_content() is simply to remove the filter, like so: <?php remove_filter( 'the_content', 'wptexturize' ); ?>


2

According to this page, you can use the tiny_mce_before_init filter, make sure the entity encoding is set to named, and then add whichever special characters you want to the entities array.


1

Thanks, fdsa! For posterity, here's the actual code I used. It adds copyright, registered, trademark, service mark and euro to the array of allowed entities. I'm confused as to why some of these aren't in there by default, as they're really common. But in any case, this works: // Custom configuration for TinyMCE function wpsx_54398_configure_tiny_mce( ...


1

Quick and dirty, put this before your get_header() in your search.php <?php // Get the query string $query = get_search_query(); // if the first & last char is space, rip them $query = trim($query); // if there are more than one space, rip to one space $query = preg_replace('/\s\s+/', ' ',$query); // if chars count is less than 3, redirect them to ...


1

It appears that the site is still using the Unicode character set from the page header, but the database may have been corrupted. Ask Linode for a backup restore and/or if they changed anything with their MySQL servers. If you don't run your own regular database backups, you should. Try WordPress › WP-DB-Backup « WordPress Plugins. You can also use ...


1

I know toscho doesn't like this very much, but anyway: Converted the input args to an array: function utf8_truncate( $args = array( 'string' => null, 'max_chars' => 200, 'append' => "\xC2\xA0…" ) ) { $args['string'] = strip_tags( $args['string'] ); $args['string'] = html_entity_decode( $args['string'], ENT_QUOTES, 'utf-8' ); // \xC2\xA0 ...


1

When one creates a WordPress site by default, or via the Fantastico tool in cPanel, it may create a blog with the Latin1 charset in the MySQL database. This causes Chinese characters (and other Unicode characters) to be switched into one or more ? question mark symbols, instead. The fix is to connect to your cPanel, connect to phpMyAdmin, find the WordPress ...


1

You could use regex to only allow alphanumeric characters. $string = preg_replace("/[^A-Za-z0-9 ]/", '', $string);


1

It's Wordpress. You could hack into wp-includes/formatting.php and comment out the contents of the sanitize_user() function. However, I don't think that's a good idea - it may compromize your site's security, and special characters can always cause trouble... And it's never a good idea to hack into the core (maybe you can do it also with remove_action() - ...


1

If you run a wp_kses() on the_excerpt() (through a filter) you can whitelist specific HTML tags and such. In your case, the code would probably look something like this: if( is_page( 'your_page' ) ) { add_filter( 'the_excerpt', 'wpse44363_filter_the_excerpt' ); } function wpse44363_filter_the_excerpt( $excerpt ) { // this allows no html, you can ...


1

You cannot change that value. The database schema is limited to 20 Bytes. See wp-admin/includes/schema.php: TABLE $wpdb->posts ( ID bigint(20) unsigned NOT NULL auto_increment, post_author bigint(20) unsigned NOT NULL default '0', post_date datetime NOT NULL default '0000-00-00 00:00:00', post_date_gmt datetime NOT NULL default '0000-00-00 ...


1

get_the_content() return what's in the editor, but wpautop filters and such are attached to the_content (which you don't need inside your split function - just apply it later manually with apply_filters( 'the_content', $output ); at the end. You should as well use strip_shortcodes( get_the_content() ); before splitting it up: $output = ...


1

so I really appreciate all the feedback and the answer that @kaiser and @t31os contributed. I am shaky with PHP so it was hard to put together a working block of code with kasier & t31os's answer. That's my fault for not being a very talented coder :-( But, I wanted to post the solution that I came up with by doing my own research on PHP.net and asking ...


1

Per a request from user2655393 I have written a version of his/her code that does not use output buffering, but uses string concatenation instead. $content = get_the_content(); $strings = wordwrap($content, 500, "<!--break-->"); //insert this every 500 chars, but preserve whole words. $chunks = explode("<!--break-->", $strings); create a new ...


1

@Ravs... got it with this: $title = sanitize_title($title); Thank you for your help!


1

Use this regular expression /^[a-z0-9]{3,16}$/ (3,16) used for limit the characters


1

Using the regex posted by Moaz (and adding capitals), we will need to hook into the registration_errors filter: // Restrict username registration to alphanumerics add_filter('registration_errors', 'limit_username_alphanumerics', 10, 3); function limit_username_alphanumerics ($errors, $name) { if ( ! preg_match('/^[A-Za-z0-9]{3,16}$/', $name) ){ ...


1

Just do this with your string: $yourString = preg_replace ( '/å/' , 'a' , $yourString ) $yourString = preg_replace ( '/ä/' , 'a' , $yourString ) $yourString = preg_replace ( '/ö/' , 'o' , $yourString ) If you just want to do it with an SQL sentence, then you can try this : REPLACE(REPLACE(REPLACE(StringColumn, 'å', 'a') , 'ä', 'a') , 'ö', 'o') And you ...


1

Use the Multibyte String functions, in this case mb_strtoupper(). This is a general rule: in WordPress, output is usually encoded in UTF-8. Avoid single-byte functions like strlen(), substr() and others when there is a better mb_* function.


1

To limit characters add this to your textarea: maxlength="200" changing "200" to whatever you want the character limit to be. <textarea id="description" maxlength="200" tabindex="3" name="description2" cols="50" rows="6"></textarea> For a character counter you will need some basic Javascript, something like this: counter = function() { ...


1

The $tag is used as a key in an array, so it is converted to either a string or an integer. There is no maximum size for strings, the available memory is the only real restriction. The size of an integer depends on the platform: The size of an integer is platform-dependent, although a maximum value of about two billion is the usual value (that's 32 bits ...


1

I always thought that the memory size was the limit for the string length, but according to the PHP documentation: string can be as large as up to 2GB (2147483647 bytes maximum) There is also the maximum allowed memory size (memory_limit) for the PHP script, to consider. Testing: Do not perform this on a production server: You could always use the ...


1

Drop in add_filter( 'the_content', 'widont' ); (and the same for the_excerpt if required). This'll apply the function to the post content in addition to the title (the_title).



Only top voted, non community-wiki answers of a minimum length are eligible