Last active
February 6, 2024 09:39
-
-
Save svenl77/4eb09ef14177d4ebccd4ed240edfef80 to your computer and use it in GitHub Desktop.
BuddyForms VS Event List Integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( !defined( 'ABSPATH' ) ) { | |
exit; | |
} | |
/* | |
* Plugin Name: BuddyForms VS Event List | |
* Description: BuddyForms VS Event List Integration | |
* Version: 0.1 | |
* Author: ThemeKraft | |
* Author URI: https://themekraft.com/buddyforms/ | |
* Licence: GPLv3 | |
* Network: false | |
* Text Domain: buddyforms | |
***************************************************************************** | |
* | |
* This script is free software; you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation; either version 2 of the License, or | |
* (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* You should have received a copy of the GNU General Public License | |
* along with this program; if not, write to the Free Software | |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
* | |
**************************************************************************** | |
*/ | |
// Save the form element after submit | |
add_filter( 'buddyforms_before_update_post_meta', 'events_buddyforms_before_update_post_meta', 10, 4 ); | |
function events_buddyforms_before_update_post_meta($field_value, $customfield, $post_id, $form_slug ){ | |
// Check if it's the correct form elment type | |
if( $customfield['type'] != 'date' ) | |
return; | |
// check if the form element exists | |
if( !isset($_POST[$customfield['slug']]) && $customfield['slug'] == 'event-start-date' ) | |
return; | |
// Get the value form the $_POST | |
$date = $_POST[$customfield['slug']]; | |
// Create the timestemp from the date string | |
$field_value = strtotime($date); | |
// Return the timestring | |
return $field_value; | |
} | |
// Display the correct format in the edit screen. | |
add_filter('buddyforms_edit_custom_field_value', 'events_buddyforms_edit_custom_field_value', 10, 4); | |
function events_buddyforms_edit_custom_field_value($customfield_val, $customfield, $post_id, $slug){ | |
if( $customfield['slug'] == 'event-start-date' ){ | |
$customfield_val = gmdate("D, d M Y H:i:s", get_post_meta( $post_id, $slug, true ) ); | |
} | |
return $customfield_val; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment