Skip to content

Instantly share code, notes, and snippets.

@bogordesaincom
Last active March 7, 2023 07:09
Show Gist options
  • Save bogordesaincom/e949aae3440cbf68ad4bc263b8e96af4 to your computer and use it in GitHub Desktop.
Save bogordesaincom/e949aae3440cbf68ad4bc263b8e96af4 to your computer and use it in GitHub Desktop.
Helper theme
<?php
// Add custom Theme Functions here
// $myrows = $wpdb->get_results( "SELECT ID, post_name FROM {$wpdb->prefix}posts" );
// $results = $wpdb->get_results( "SELECT id FROM {$wpdb->prefix}frm_items", OBJECT );
// $latestID = $wpdb->get_var( 'SELECT id FROM ' . $wpdb->prefix . 'frm_items' . ' ORDER BY id DESC LIMIT 1');
// print_r((int)$latestID);
function custom_css() {
$parent_style = 'parent-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'fishlogsena-child-style', get_stylesheet_directory_uri() . '/style.css');
// wp_enqueue_style( 'fishlogsena-child-custom', get_stylesheet_directory_uri() . '/css/custom.css');
wp_enqueue_style( 'fishlogsena-child-font', get_stylesheet_directory_uri() . '/css/fonts.css');
}
add_action( 'wp_enqueue_scripts', 'custom_css' );
add_filter('frm_pre_create_entry', 'adjust_my_field');
function adjust_my_field($values){
if ($values['form_id'] == 2 ) { //change 5 to your form id
$current_value = $values['item_meta'][15]; // change 25 to to id of your field
if ( strpos( $current_value, '0816-' ) === false ) { // check if the value is already included
global $wpdb;
$latestID = $wpdb->get_var( 'SELECT id FROM ' . $wpdb->prefix . 'frm_items' . ' ORDER BY id DESC LIMIT 1');
$latest_number = str_pad((int)$latestID ? (int)$latestID + 1 : 1, 3, '0', STR_PAD_LEFT);
$values['item_meta'][15] = '0816-'.$latest_number;
print_r($values);
}
}
return $values;
}
add_action('frm_after_create_entry', 'frm_add_entry_id', 42, 2);
function frm_add_entry_id($entry_id, $form_id){
if ( $form_id == 2 ) { //change 221 to the ID of your form
$latest_number = str_pad($entry_id, 3, '0', STR_PAD_LEFT);
FrmEntryMeta::add_entry_meta( $entry_id, 15, "", '0816-'.$latest_number);//change 1819 to the ID of the field in which you want to store the entry ID
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment