Guests comment form – prevent duplicate email addresses

function preprocess_mycomment($commentdata) { $existing_comments = get_comments( array(‘post_id’ => 31691) ); // I run the code for one specific page only foreach ($existing_comments as $comment) { $previous_comments = $comment->comment_author_email; // email address send by the current poster if ( $previous_comments == $commentdata[‘comment_author_email’] ) { // comparing the current email address with the previous ones in database. … Read more

theme.json is altering Group block HTML

I was able to prevent the unwanted altering of HTML by using the render_block_core/group filter, and a copy of wp_restore_group_inner_container, without the JSON support check. public static function my_add_block_group_inner( $block_content, $block ) { $tag_name = isset( $block[‘attrs’][‘tagName’] ) ? $block[‘attrs’][‘tagName’] : ‘div’; $group_with_inner_container_regex = sprintf( ‘/(^\s*<%1$s\b[^>]*wp-block-group(\s|”)[^>]*>)(\s*<div\b[^>]*wp-block-group__inner-container(\s|”)[^>]*>)((.|\S|\s)*)/U’, preg_quote( $tag_name, “https://wordpress.stackexchange.com/” ) ); $replace_regex = sprintf( ‘/(^\s*<%1$s\b[^>]*wp-block-group[^>]*>)(.*)(<\/%1$s>\s*$)/ms’, … Read more

is_user_logged_in() undefined at shutdown in plugin context

Edit 1 – Does not work // Catch is_user_logged_in() value before shutdown function is_user_logged_in_init() { $is_user_logged_in_init = is_user_logged_in() ?? false; } add_action(‘init’, ‘is_user_logged_in_init’); Leaving this here for my reference. Ref Edit 2 – Works I found two ways to solve this: Option 1 – Not recommended Ref include_once ABSPATH.’wp-includes/pluggable.php’; Option 2 – Rewrite the script, … Read more

Creating my own “recent blog posts” static Gutenberg block, can’t use react hooks in the frontend

That’s not how blocks work, the save component generates static HTML, so you can’t use interactive hooks or state. The important part is that the save component only runs inside the editor on your browser. It does not run in the database, or on the client. You can’t save a react component to the database … Read more