How to allow data:image attribute in src tag during post insert?

I'm inserting a post using wp_post_insert(). And my post's content looks like this: <img src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAN4AAAB6CA { ... } but on the insert process, Wordpress removes the data attribute. So above code becomes this: <img src="image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAN4AAAB6CA { ... } I've tried something like this but no luck: function my_filter_allowed_html($allowed, $context){ if (is_array($context)) { return $allowed; } if ($context === 'post') { $allowed['img']['data'] = true; $allowed['src']['data'] = true; } return $allowed; } add_filter('wp_kses_allowed_html', 'my_filter_allowed_html', 10, 2); How can I avoid …
Category: Web

Change allowed HTML tags for comments

I've set up a HTML editor for WordPress comments, and I want to change the allowed HTML tags for comments accordingly. Some of the HTML tags also have inline styling, or classes added. I only want to allow the styling and classes that I'm expecting, but I cannot get it to work. I want to allow only these custom classes and styles. <span class="spoiler">This is spoilered text</span> <span style="text-decoration: line-through;">This text has strikethrough</span> Non-working code: function custom_allowed_tags_comment() { global $allowedtags; …
Category: Web

Could you please correct the code is_admin()

I have this code in my function.php: add_action( 'init', 'blockusers_init' ); function blockusers_init() { if ( is_admin() && ! current_user_can( 'administrator' ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { wp_redirect( 'http://madeeasy-online.com/zhile-2/dobavit-obyavlenie/', 302); exit; } } But I want 'moderator' to reach the admin-panel. What should I add to the code? Thank in advance, Sv
Category: Web

Allow all attributes in $allowedposttags tags

I would like to use $allowedposttags to allow extra HTML tags during entry submission. Can I allow all attributes for a specific tag using $allowedposttags? For example, the code below will allow iframe tags and the src, height, and width attributes in the iframe tags: $allowedposttags['iframe'] = array( 'src' => array(), 'height' => array(), 'width' => array() ); How can I allow all attributes in this example, not just src, height, and width?
Category: Web

Adding target and _blank as it's value to the allowedtags

I know that WordPress uses KSES to parse HTML and strip invalid XHTML so I took control of $allowedtags in my themes functions.php file inside a function then added 'target' keyed to an array which contains '_blank' keyed to an empty array. I thought this would work but my link still seems to not contain the target attribute? I have tried re saving the HTML also. Here is my code: function add_required_html_tags() { global $allowedtags; //tap into wordpress global array …
Category: Web

Filtering the Comment Form Allowed Tags

How can I remove some of the allowed HTML tags in comments/posts? For whatever reason, the following code, placed in my theme's functions.php, didn't work: add_action('init', 'my_html_tags_code', 10); function my_html_tags_code() { define('CUSTOM_TAGS', true); global $allowedposttags, $allowedtags; $allowedposttags = array( 'strong' => array(), 'em' => array(), 'pre' => array(), 'code' => array(), 'a' => array( 'href' => array (), 'title' => array ()) ); $allowedtags = array( 'strong' => array(), 'em' => array(), 'a' => array( 'href' => array (), 'title' …
Category: Web

Allow tags and attributes in post and pages content

I am trying to allow the "onclick" attribute on links as well as some html tags such as iframe to the content displayed in posts and pages. In my theme's functions.php file, I tried removing filters such as wpautop function rm_wpautop($content) { global $post; // Get the keys and values of the custom fields: $rmwpautop = get_post_meta($post->ID, 'wpautop', true); // Remove the filter remove_filter('the_content', 'wpautop'); if ('false' === $rmwpautop) { } else { add_filter('the_content', 'wpautop'); } return $content; } // …
Category: Web

Disable html in custom post types

My webstie have custom post type created, and now I want to disable usage of any html tag in content editor, so only plain text is saved in database (and to remove content editor and html editor if possible). I found functions to remove (rich) content editor: add_filter('user_can_richedit' , create_function('' , 'return false;') , 50); And HTML editor remained. But even if I maange to remove HTML editor (this: http://prntscr.com/26uj6u ), users will be able to just type html tags …
Category: Web

preg_replace and comment_form_defaults

this was kinda of a joke at the beginning but now I'm wondering if it's possible to use regex with the hook comment_form_defaults. Here is what I'm looking for : function remove_default_allowed_tags( $defaults) { $defaults = preg_replace('/<p class="form-allowed-tags">(.*?)<\/p>/','', $defaults); return $defaults; } add_filter('comment_form_defaults', 'remove_default_allowed_tags', 2); I know it can be easily done with something like this : $defaults['comment_notes_after'] = ''; return $defaults; But I just want to know if I can use my regex in this context and if not, …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.