Skip to content

Instantly share code, notes, and snippets.

View kipmyk's full-sized avatar
🏠
Working from home

Mike Kipruto kipmyk

🏠
Working from home
View GitHub Profile
@kipmyk
kipmyk / All_images_attached_to_the_post.php
Created July 2, 2023 07:33
This code will help show all images attached to the post
<ul>
<?php
// Check if there are posts
if ( have_posts() ) : while ( have_posts() ) : the_post();
// Get attachments for the current post
$attachments = get_posts( array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
@kipmyk
kipmyk / formating_wpforms_phone_field.php
Created May 17, 2023 06:25
Formating the WPForms phone number by removing leading 0 or + using wpforms_process_filter
<?php
/**
* The wpforms_process_filter hook is used to modify the form submission data.
* @link https://wpforms.com/developers/wpforms_process_filter/
**/
add_filter( 'wpforms_process_filter', function ( $fields, $entry, $form_data ) {
foreach ( $fields as &$field ) {
// If field type is phone
if ( $field['type'] == 'phone' ) {
// Grabing the field value
@kipmyk
kipmyk / wpforms_email_summaries_cron_unschedule.php
Last active April 17, 2023 12:04
Wordpress cron: Unschedule the wpforms_email_summaries_cron events when WPForms is deactivated
<?php
/**
* Wordpress cron: Unschedule the wpforms_email_summaries_cron events when WPForms is deactivated
* @link https://developer.wordpress.org/reference/functions/wp_unschedule_event/
* @link https://developer.wordpress.org/reference/functions/wp_next_scheduled/
* @link https://wpforms.com/docs/how-to-use-email-summaries/
* @link https://developer.wordpress.org/reference/functions/get_option/
* */
$crons = get_option( 'cron' );
@kipmyk
kipmyk / wpforms_field_label_on_url.php
Created March 2, 2023 18:37
The following code snippet will include all the WPForms form fields in the confirmation URL plus the field label and the corresponding field ID.
<?php
add_filter( 'wpforms_process_redirect_url', function( $url, $form_id, $fields ) {
$args = array();
foreach( $fields as $field ) {
if( !empty( $field['value'] ) )
$args[$field['name'] .'_'. $field['id']] = $field['value'];
}
return esc_url_raw( add_query_arg( $args, $url ) );
}, 10, 3 );
<?php
/**
Wordpress login url change using login_url @link https://developer.wordpress.org/reference/hooks/login_url/
*/
add_filter( 'login_url', function( $login_url, $redirect, $force_reauth ){
// Change here your login page url
$login_url = 'yoursite_login_url';
if ( ! empty( $redirect ) ) {
$login_url = add_query_arg( 'redirect_to', urlencode( $redirect ), $login_url );
}
<?php
/**
* How to exclude certain fields from saving to database,
* */
add_filter( 'wpforms_entry_save_data', static function( $fields, $entry, $form_data ) {
//where 11 is the Form ID @link: https://wpforms.com/developers/how-to-locate-form-id-and-field-id/#form-id
if ( '11' !== $form_data['id'] ) {
return $fields;
}
//where 1, and 7 are the Field IDs @link: https://wpforms.com/developers/how-to-locate-form-id-and-field-id/#field-id
@kipmyk
kipmyk / mk_wpforms_after_password_reset.php
Created February 11, 2023 09:51
WPForms redirecf after password reset
<?php
/**
* @link https://developer.wordpress.org/reference/hooks/after_password_reset/
* @link https://wpforms.com/how-to-create-a-custom-login-form-for-improved-site-branding/#Step_4_Add_a_Forgot_Password_Link_to_Your_Custom_Login_Form
*/
add_action( 'after_password_reset', function( $user_id ){
exit( wp_redirect( home_url('/login/') ) );
}, 8, 1 );
@kipmyk
kipmyk / wpforms_date_picker_year_display_issue.css
Created January 31, 2023 07:23
WPForms Datepicker year select display issue
.flatpickr-current-month .flatpickr-monthDropdown-months {
width: auto !important;
display: inline-block !important;
padding: 0 0 0 .5ch !important;
margin: 0px !important;
}
.flatpickr-current-month input.cur-year {
padding: 0 0 0 .5ch !important;
margin: 0px !important;
@kipmyk
kipmyk / dynamic_choice_orderby_menu_order.php
Created January 12, 2023 15:01
How Can to change the order of items from: Using Multiple Choice Dynamic Choices.
<?php
add_filter( 'wpforms_dynamic_choice_post_type_args', function( $args, $field, $form_id ) {
$args = [
'post_type' => $field['dynamic_post_type'],
'orderby' => 'menu_order',
'order' => 'asc',
];
return $args;
}, 10, 3 );
@kipmyk
kipmyk / display_wpforms.md
Created January 12, 2023 13:05
wpforms_display( $form_id=562, $title=true, $desc=true); Where 512 is the form ID, $title - form title and $desc - description.

wpforms_display( $form_id=562, $title=true, $desc=true);

Where 512 is the form ID, $title - form title and $desc - description.