Skip to content

Instantly share code, notes, and snippets.

View rafaehlers's full-sized avatar

Rafael M. Ehlers rafaehlers

View GitHub Profile
@rafaehlers
rafaehlers / gv-dt-change-message.php
Created July 30, 2018 22:45
Change DataTables Ajax Messages
<?php
function gravityview_datatables_change_messages( $dt_config, $view_id, $post ) {
$dt_config['language']['processing'] = 'Wait!';
//$dt_config['language']['emptyTable'] = 'No entries here!';
return $dt_config;
}
add_filter( 'gravityview_datatables_js_options', 'gravityview_datatables_change_messages', 10, 3 );
@rafaehlers
rafaehlers / gv-rename-approved-entry-note-text.php
Last active June 29, 2019 00:01
Filter to rename the "Approved the Entry" message in an Entry note.
<?php // Make sure to remove this line before pasting it on your theme's functions.php
add_filter( 'gravityview/entry_notes/get_notes', 'gv_modify_notes', 10, 2 );
function gv_modify_notes( $notes, $entry_id ) {
foreach($notes as $key => $note){
if (strpos( $note->value, 'Approved') !== false){
$note->value = "Aprovada!";
}
if (strpos( $note->value, 'Unapproved') !== false){
$note->value = "Não Aprovada!";
@rafaehlers
rafaehlers / gw-copy-uid-to-other-field.php
Last active October 13, 2018 08:18
Copy the Unique ID to another field
<?php
/**
* Gravity Perks // GP Unique ID // Copy ID to Another Field
* http://gravitywiz.com
*/
// change the "999" to your form ID
add_filter( 'gform_entry_post_save_999', function( $entry ) {
// update "1" to your Unique ID field's field ID
$uid_field_id = 1;
@rafaehlers
rafaehlers / gv-rest-api-nonce.php
Created July 9, 2018 21:07
Code snippet for this: https://docs.gravityview.co/article/468-rest-api (Authentication section)
<?php
$entries_url = 'http://gv2.dev.codeseekah.com/wp-json/gravityview/v1/views/1696/entries.json';
$nonce = wp_create_nonce( 'wp_rest' );
?>
<script type="text/javascript">
jQuery.ajax( {
url: <?php echo json_encode( $entries_url ); ?>,
method: 'GET',
beforeSend: function ( xhr ) {
xhr.setRequestHeader( 'X-WP-Nonce', <?php echo json_encode( $nonce ); ?> );
@rafaehlers
rafaehlers / gv-ratings-reviews-form-stars.php
Last active April 8, 2020 22:31
Ratings and Reviews extension - Remove all fields from the review form, leaving only the thumbs/stars
<?php // DO NOT COPY THIS LINE
add_filter( 'comment_form_field_gv_review_title', '__return_empty_string' );
add_filter( 'gv_ratings_reviews_review_form_settings', 'gv_modify_review_form_labels',10,1);
function gv_modify_review_form_labels($defaults){
$defaults['author'] = '';
$defaults['email'] = '';
@rafaehlers
rafaehlers / gv_listify.php
Last active June 29, 2018 05:11
Shortcode that accepts a category field which is usually displayed as bullet points and turns into a comma separated values string
<?php
//usage [gv_listify field="{Field Merge Tag}"]
add_shortcode( 'gv_listify', 'gv_listify_shortcode' );
function gv_listify_shortcode( $atts ) {
extract( shortcode_atts(
array(
'field' => '',
), $atts )
);
<?php
function gv_change_edit_entry_title( $previous_text = 'Edit Entry' ) {
$view_id = GravityView_View::getInstance()->getViewId();
if($view_id == 105){
return 'Edit Profile';
}
if( ($view_id == 106) || ($view_id == 107)){
return 'Edit Entry';
}
}
<?php
add_action('gform_after_update_entry_115', 'gv_change_entry_creator', 10, 2);
function gv_change_entry_creator( $form, $entry_id ){
$entry = GFAPI::get_entry($entry_id);
$new_entry_creator = $entry[1]; // field ID where the dropdown with usernames are (this will be the new entry creator)
GFAPI::update_entry_property( $entry_id, 'created_by', $new_entry_creator );
}
@rafaehlers
rafaehlers / gv-remove-wpautop-custom-content.php
Last active April 14, 2020 06:52
Prevents the wpautop (BR and P tags) function from running on a custom content field.
<?php
/**
* Remove wpautop() when Gravity Forms is in the field content
*/
add_filter( 'gravityview/field_output/args', function( $args, $passed_args, $context = null ) {
if( $context && $context instanceof \GV\Template_Context ) {
$content = \GV\Utils::get( $args, 'value', '' );
if( has_shortcode( $content, 'gravityform') ) {
@rafaehlers
rafaehlers / gv-send-form-notification-entry-approval.php
Last active June 5, 2018 21:41
Send a form notification when an entry is approved/disapproved
<?php
add_action('gravityview/approve_entries/disapproved','gv_send_form_notification_approval');
add_action('gravityview/approve_entries/approved','gv_send_form_notification_approval');
function gv_send_form_notification_approval($entry_id){
$entry = GFAPI::get_entry( $entry_id );
if( ! $entry || is_wp_error( $entry ) ) {
return;
}
$form = GFAPI::get_form( $entry['form_id'] );
if( ! $form || is_wp_error( $form ) ) {