Archives: Snippets
MemberPress: Exclude Protected Posts from Search Results
function maybe_exclude_protected_posts($query) { if(!$query->is_admin && $query->is_search && $query->is_main_query()) { $posts_to_exclude = array(); $posts = get_posts(array( ‘post_type’ => get_post_types(), ‘numberposts’ => -1 )); foreach($posts as $post) { if(MeprRule::is_locked($post)) { $posts_to_exclude[] = $post->ID; } } if(!empty($posts_to_exclude)) { $query->set(‘post__not_in’, $posts_to_exclude); } } }…Continue reading
Amit choudhary blogs
WPForms: add BCC email header to notification emails
add_filter( ‘wpforms_email_headers’, function ( $headers, $emails ) { // APPLY THE BCC TO THIS FORM ID ONLY. // CHANGE THE ID TO THE FORM YOU NEED. OR REMOVE THE WHOLE IF BLOCK IF NEEDED FOR ALL FORMS. if ( 42…Continue reading
WPForms: swap price and option value for payment fields
add_filter( ‘wpforms_html_field_value’, function ( $value, $field, $form_data, $context ) { if ( ’email-html’ !== $context ) { return $value; } $form_id = (int) $form_data[‘id’]; // For a specific form. // REMOVE IF NEEDED FOR ALL FORMS. if ( 1 !==…Continue reading
WP Mail SMTP: when using SMTP mailer – disable SSL verification
add_filter(‘wp_mail_smtp_custom_options’, function( $phpmailer ) { $phpmailer->SMTPOptions = array( ‘ssl’ => array( ‘verify_peer’ => false, ‘verify_peer_name’ => false, ‘allow_self_signed’ => true ) ); return $phpmailer; } );Continue reading
WP Mail SMTP: specify an exact AuthType to connect to a Server.
add_filter( ‘wp_mail_smtp_custom_options’, function( $phpmailer ) { $phpmailer->AuthType = ‘LOGIN’; return $phpmailer; } );Continue reading
WPForms: add several new smart tags for newly submitted CPT: ID, title and URL.
function wpf_dev_register_smarttag( $tags ) { // Key is the tag, value is the tag name. $tags[‘submitted_cpt_id’] = ‘Submitted Post Type ID’; $tags[‘submitted_cpt_url’] = ‘Submitted Post Type URL’; $tags[‘submitted_cpt_title’] = ‘Submitted Post Type Title’; return $tags; } add_filter( ‘wpforms_smart_tags’, ‘wpf_dev_register_smarttag’ );…Continue reading
Calendly Calendar for Demo
WPForms: add field description in notification HTML and plain text emails
// HTML Email. add_filter( ‘wpforms_html_field_value’, static function ( $field_val, $field, $form_data, $context ) { if ( $context !== ’email-html’ ) { return $field_val; } if ( empty( $form_data[‘fields’][ $field[‘id’] ] ) ) { return $field_val; } $field_data = $form_data[‘fields’][ $field[‘id’]…Continue reading