Skip to content

Instantly share code, notes, and snippets.

@svenl77
svenl77 / buddyforms_process_submission_end.php
Created May 28, 2018 10:04
BuddyForms -> Auto login user after registration
<?php
add_action( 'buddyforms_process_submission_end', 'my_buddyforms_process_submission_end', 10, 1 );
function my_buddyforms_process_submission_end($args){
if( ! isset( $args['user_id'] ) ){
return;
}
$user_id = $args['user_id'];
@svenl77
svenl77 / buddyforms_wp_insert_user_activation_mail.php
Created May 28, 2018 09:44
buddyforms_wp_insert_user_activation_mail
<?php
add_filter( 'buddyforms_wp_insert_user_activation_mail', 'my_buddyforms_wp_insert_user_activation_mail', $sent, $user_id );
function my_buddyforms_wp_insert_user_activation_mail(){
//
// use the $user_id to perform any custom action
//
@svenl77
svenl77 / buddyforms_the_loop_li_last.php
Last active September 4, 2017 12:40
Add a new div to the listing insite the "li"
<?php
// Add a new div to the listing insite the "li"
add_action('buddyforms_the_loop_li_last', 'my_buddyforms_the_loop_li_last', 10, 2);
function my_buddyforms_the_loop_li_last($post_id, $form_slug){
// Check if this is the correct form.
// Change "FORM_SLUG" to your form
if($form_slug != 'posts'){
return;
@svenl77
svenl77 / add-new-table-column.php
Last active September 4, 2017 12:44
BuddyForms: Add a new table column to the posts list table to display Form elements saved as post meta ( Custom Fields )
<?php
// Hook into the the-loop.php template and add an new table head
add_action('buddyforms_the_thead_tr_inner_last', 'my_buddyforms_the_thead_tr_inner_last', 10, 2);
function my_buddyforms_the_thead_tr_inner_last($post_id, $form_slug){
// Check if this is the correct form.
// Change "FORM_SLUG" to your form
if($form_slug != 'FORM_SLUG'){
return;
@svenl77
svenl77 / buddyforms_list_posts_hook.php
Last active September 4, 2017 12:35
Hook Form Elements saved as Post Meta ( Custom Fields ) under the title of the listing or the excerpt
<?php
// Hook Post Meta ( Custom Fields ) under the title of the listing
add_action('buddyforms_the_loop_item_title_after', 'my_buddyforms_the_loop_item_last', 10, 1);
// Hook Post Meta ( Custom Fields ) under the excerpt of the listing
// This hook only exists in the the-loop.php template
add_action('buddyforms_the_loop_item_excerpt_after', 'my_buddyforms_the_loop_item_last', 10, 1);
// Example function for the title and the excerpt after hooks
<?php
$field_wp_type = isset( $customfield['field_wp_type'] ) ? $customfield['field_wp_type'] : false;
$form_fields['general']['field_wp_type'] = new Element_Select( '<b>' . __( 'Save field as ', 'buddyforms' ) . '</b>', "buddyforms_options[form_fields][" . $field_id . "][field_wp_type]",
array(
'user_meta' => 'User Meta',
'post_meta' => 'Post Meta Custom Field',
'user_meta' => 'User Meta',
), array(
'value' => $field_wp_type,
<?php
add_action( 'pre_get_posts', 'jim_filter_cpt_listing_by_author' );
function buddyforms_filter_cpt_listing_by_author( $wp_query_obj ) {
// First let us check if this is a page. We not want to restrict pages
if( !isset( $wp_query_obj->query ) || isset( $wp_query_obj->query['page'] ) || 'page' == $wp_query_obj->query['post_type'] ){
return $wp_query_obj;
}
// Check if the user is logged in and display a page to logged off users
@svenl77
svenl77 / buddyforms_custom_gallery_shortcode.php
Last active August 28, 2017 11:34
Create WordPress Gallery from BuddyForms File Form Element to use in a ShortCode
@svenl77
svenl77 / buddyforms_user_can_edit.php
Created August 23, 2017 13:24
Filter to set permissions in BuddyForms
<?php
/**
* In this example we generally allow all to create and edit posts. This would be really dangerous and only should be used in closed intranets.
* In most situation you will use the filter to only fire in some situations. Please see the Groups Extension for a more complex example
* Link to the Groups Extension Example: https://github.com/BuddyForms/BuddyForms-Attach-Post-with-Group/blob/7d7d1b9c475cdfb076ef34963aeb94952a2e9545/includes/group-extension.php#L47
*/
add_filter( 'buddyforms_user_can_edit', 'buddyforms_user_can_edit' , 10, 3 );
function buddyforms_user_can_edit( $found ) {
return true;
<?php
add_action( 'pre_get_posts', 'buddyforms_filter_cpt_listing_by_author' );
function buddyforms_filter_cpt_listing_by_author( $wp_query_obj ) {
// First let us check if this is a page. We not want to restrict pages
if( !isset( $wp_query_obj->query ) || isset( $wp_query_obj->query['page'] ) || 'page' == $wp_query_obj->query['post_type'] ){
return $wp_query_obj;
}
// Check if the user is logged in and display a page to logged off users