current user entry counter gravity forms display numbers - gravity-forms-plugin

how can i display numbers with shortcode of submitted from gravity form only from current logged in user
add_filter( 'gform_shortcode_entry_count', 'gwiz_entry_count_shortcode', 10, 2 );
function gwiz_entry_count_shortcode( $output, $atts ) {
extract( shortcode_atts( array(
'id' => false,
'status' => 'total', // accepts 'total', 'unread', 'starred', 'trash', 'spam'
'format' => false // should be 'comma', 'decimal'
), $atts ) );
$valid_statuses = array( 'total', 'unread', 'starred', 'trash', 'spam' );
if( ! $id || ! in_array( $status, $valid_statuses ) ) {
return current_user_can( 'update_core' ) ? __( 'Invalid "id" (the form ID) or "status" (i.e. "total", "trash", etc.) parameter passed.' ) : '';
}
$counts = GFFormsModel::get_form_counts( $id );
$output = rgar( $counts, $status );
if( $format ) {
$format = $format == 'decimal' ? '.' : ',';
$output = number_format( $output, 0, false, $format );
}
return $output;
}

Related

Custom FacetWP dropdown not showing posts

I have been able to render a dropdown facet in FacetWP front end with:
add_filter( 'facetwp_facet_html', function( $output, $params ) {
if ( 'today_or_month' == $params['facet']['name'] ) {
$selected = isset( $params['selected'] ) ? $params['selected'] : '';
$output = '<select class="facetwp-dropdown">';
$output .= '<option value="">Select date range</option>';
$output .= '<option value="today"' . ( 'today' == $selected ? ' selected' : '' ) . '>Today</option>';
$output .= '<option value="month"' . ( 'month' == $selected ? ' selected' : '' ) . '>This Month</option>';
$output .= '<option value="test"' . ( 'test' == $selected ? ' selected' : '' ) . '>Test</option>';
$output .= '</select>';
}
return $output;
}, 10, 2 );
All 'event' posts show under the Facet dropdown on page load but when I select an option from the dropdown the queries do not return any posts in the FacetWP template. When I select "Select date range" again all the posts show again.
The queries are as follows:
add_filter( 'facetwp_query_args', function( $args, $class ) {
if (!isset($class->http_params['get']['facetwp'])) return $args;
$selected = $class->http_params['get']['facetwp']['today_or_month'];
$current_month = date( 'Y-m' );
if ( 'today' == $selected ) {
$args['meta_query'][] = array(
'key' => 'event_date_start',
'value' => date( 'Y-m-d' ),
'compare' => '<=',
);
$args['meta_query'][] = array(
'key' => 'event_date_end',
'value' => date( 'Y-m-d' ),
'compare' => '>=',
);
}
elseif ( 'month' == $selected ) {
$args['meta_query'][] = array(
'key' => 'event_date_start',
'value' => date( 'Y-m-01' ),
'compare' => '>=',
);
$args['meta_query'][] = array(
'key' => 'event_date_end',
'value' => date( 'Y-m-t' ),
'compare' => '<=',
);
}
elseif ( 'test' == $selected ) {
$args['meta_query'][] = array(
'key' => 'event_date_start',
'value' => $current_month,
'compare' => 'LIKE',
);
}
$args['post_type'] = 'event';
return $args;
}, 10, 2 );
Does anybody know why the query is not returning any posts in the front end?
I thought maybe I need to convert to a timestamp from ACF custom fields first? Something like this:
$start_date = get_field( 'event_date_start', $params['post_id'] );
$end_date = get_field( 'event_date_end', $params['post_id'] );
$start_timestamp = strtotime( $start_date );
$end_timestamp = strtotime( $end_date );
And then use these variables as the key:
'key' => '$start_timestamp ',
Any help at all would be great. Been going over and over this! Thank you so much. I am begging.
I have tried to run the code as above, I expected some of the custom post types of event to show up in the FacetWP template area according to the dropdown selections. Instead no posts show at all (they should show as some of the posts have February dates).

Paragraph breaks missing from shortcode output

I created a shortcode in Wordpress to perform a query and display the content, but the content line breaks are being removed.
add_shortcode( 'resource' , 'Resource' );
function Resource($atts) {
$atts = shortcode_atts( array(
'category' => ''
), $atts );
$categories = explode(',' , $atts['category']);
$args = array(
'post_type' => 'resource',
'post_status' => 'publish',
'orderby' => 'title',
'order' => 'ASC',
'posts_per_page'=> -1,
'tax_query' => array( array(
'taxonomy' => 'category',
'field' => 'term_id',
'operator' => 'AND',
'terms' => $categories
) )
);
$string = '';
$query = new WP_Query( $args );
if( ! $query->have_posts() ) {
$string .= '<p>no listings at this time...</p>';
}
while( $query->have_posts() ){
$query->the_post();
$string .= '<div id="links"><div id="linksImage">' . get_the_post_thumbnail() . '</div>
<div id="linksDetails"><h1>'. get_the_title() .'</h1><p>' . get_the_content() . '</p>
<p>for more information CLICK HERE</div></div>';
}
wp_reset_postdata();
$output = '<div id="linksWrapper">' . $string . '</div>';
return $output;
}
Any suggestion on why this is happening and what to do to fix it. This is only happening on the shortcode output. On regular pages - the content displays correctly.
found a solution through more searches:
function get_the_content_with_formatting ($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return $content;
}
works perfect, so I thought I would share..

How to receive REMOTE POST response data and print to Gravity Forms confirmation page

I'm struggling with getting remote post response data to print on the Gravity Forms confirmation page. The data from the form is posted to the 3rd party site successfully and my logs show that the response data is received, however the received data is not printing to the confirmation page.
I have tried many variations such as;
$request = new WP_Http();
$data = json_decode( wp_remote_retrieve_body( $response ) );
$response = wp_remote_post( $post_url, array( 'body' => $body ) );
GFCommon::log_debug( 'gform_confirmation: response => ' . print_r( $response, true ) );
return $confirmation;
I submit the data via a plugin and have tried with the filters gform_confirmation, gform_after_submission, and gform_entry_post_save to no avail.
After many support tickets to Gravity Forms; I'm told that to do this requires additional scripting.
Thank you,
Richard
This is the code I have so far for the plugin.
add_filter( 'gform_confirmation_2', 'custom_confirmation', 10, 4 );
function custom_confirmation( $confirmation, $form, $entry, $ajax ) {
$post_url = 'my_post_url';
$body = array(
'VTC_ID' => rgar( $entry, '15' ),
'Member_ID' => rgar( $entry, '16' ),
'bname' => rgar( $entry, '3' ),
'baddress' => rgar( $entry, '4' ),
'bcity' => rgar( $entry, '5' ),
'bstate' => rgar( $entry, '6' ),
'bcountry' => rgar( $entry, '7' ),
'bzip' => rgar( $entry, '8' ),
'phone' => rgar( $entry, '9' ),
'email' => rgar( $entry, '17' ),
'password' => rgar( $entry, '11' ),
'isTrial' => rgar( $entry, '12' ),
'isActive' => rgar( $entry, '18' ),
'trialStart' => rgar( $entry, '13' ),
'trialEnd' => rgar( $entry, '14' ),
);
GFCommon::log_debug( 'gform_confirmation: body => ' . print_r( $body, true ) );
$request = new WP_Http();
$response = wp_remote_post( $post_url, $parameters );
$confirmation .= print_r( $response, true );
return $confirmation;
GFCommon::log_debug( 'gform_confirmation: response => ' . print_r( $response, true ) );
}
Assuming everything is part of the same submission process, you should be able to use the gform_confirmation hook instead of the gform_after_submission.
add_filter( 'gform_confirmation_123', 'custom_confirmation', 10, 4 );
function custom_confirmation( $confirmation, $form, $entry, $ajax ) {
$response = wp_remote_post( $post_url, $parameters );
$confirmation .= print_r( $response, true );
return $confirmation;
}
This assumes that:
Your confirmation is configured for text (not page or redirect)
You will need to:
Update the "123" in the filter name to your form ID
Update the wp_remote_post() to actually use the variables applicable to your request
Update the $confirmation to include the actual content from the response that you want
Starting with #dave-from-gravity-wiz answer, I used GET not POST with github API for simplicity when experimenting
add_filter( 'gform_confirmation_4', 'custom_confirmation', 10, 4 );
function custom_confirmation( $confirmation, $form, $entry, $ajax ) {
$response = wp_remote_get( 'https://api.github.com/users/someuser' );
if ( is_wp_error( $response ) ) {
echo 'An error happened';
} else {
$body = wp_remote_retrieve_body( $response );
$data = json_decode( $body );
}
$confirmation .= print_r( $data->id, true );
return $confirmation;
}
This takes the json table you can see on the url and only prints the 'id' number in the response on the form submission confirmation, or any key label you change it to. If you want to show more than one value I was told you can concatenate the print_r so this works in the above example:
$confirmation .= print_r( $data->id, true )." <br/> ".print_r($data->login, true);
return $confirmation;

tax_query to get posts with a field with empty value?

I defined a custom field, to be able to hide posts from home, like this:
/* Campo adicional que puede ocultar noticia de la home */
function mnd_get_custom_field( $value ) {
global $post;
$custom_field = get_post_meta( $post->ID, $value, true );
if ( !empty( $custom_field ) )
return is_array( $custom_field ) ? stripslashes_deep( $custom_field ) : stripslashes( wp_kses_decode_entities( $custom_field ) );
return false;
}
function mnd_add_custom_meta_box() {
add_meta_box( 'home-page', __( 'Home page', 'mnd' ), 'mnd_meta_box_output', 'post', 'normal', 'high' );
}
add_action( 'add_meta_boxes', 'mnd_add_custom_meta_box' );
function mnd_meta_box_output( $post ) {
wp_nonce_field( 'my_mnd_meta_box_nonce', 'mnd_meta_box_nonce' ); ?>
<p>
<label for="mnd_hide_homepage"><?php _e( 'Hide from homepage', 'mnd' ); ?>:</label>
<input type="checkbox" name="mnd_hide_homepage" id="mnd_hide_homepage" checked="<?php echo mnd_get_custom_field( 'mnd_hide_homepage' ) == 1 ? 'checked' : ''; ?>" value="1" size="50" />
</p>
<?php
}
function mnd_meta_box_save( $post_id ) {
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
if( !isset( $_POST['mnd_meta_box_nonce'] ) || !wp_verify_nonce( $_POST['mnd_meta_box_nonce'], 'my_mnd_meta_box_nonce' ) ) return;
if( !current_user_can( 'edit_post', get_the_id() ) ) return;
if( isset( $_POST['mnd_hide_homepage'] ) )
update_post_meta( $post_id, 'mnd_hide_homepage', esc_attr( $_POST['mnd_hide_homepage'] ) );
}
add_action( 'save_post', 'mnd_meta_box_save' );
and I'm trying like:
// The Query
$ppp = 12;
$page = $_GET['page'];
$args_count = array(
'post_type' => 'post',
'paged' => false,
'status' => 'publish'
);
$posts_home_count = new WP_Query( $args_count );
$manyPosts = $posts_home_count->found_posts;
$paginas = $manyPosts / $ppp;
wp_reset_postdata();
$meta_params = array(
array(
'key' => 'mnd_hide_homepage',
'value' => 1,
'compare' => '!=',
'type' => 'NUMERIC'
)
);
$args = array(
'post_type' => 'post',
'posts_per_page' => $ppp,
'paged' => $page,
'page' => $page,
'status' => 'publish'/*,
'meta_query' => $meta_params */
);
//print_r ( $args );
$posts_home = new WP_Query( $args );
And it won't return any posts,
But if I change to
'compare' => '=',
Then it returns all the checked posts
Any idea what I'm missing?
There are some problems with Meta Query sometimes and the problem is not always visible. Try the following:
var_dump the WP_Query object and check the SQL manually. Do you see the problem?
Did you try to remove 'type' => 'NUMERIC'?
The “hack” solution (untested):
global $wpdb;
$ids = $wpdb->get_results("
SELECT $wpdb->posts.id FROM $wpdb->posts
WHERE post_status=publish
INNER JOIN $wpdb->post_meta
ON $wpdb->post_meta.post_id = $wpdb->posts.id
AND $wpdb->post_meta.key = 'mnd_hide_homepage'
AND $wpdb->post_meta.value != '1'
");
// put the ids with post__in into the WP_Query arguments
Maybe this is the solution. If not, it may help to find it.
Try this:
array(
'key' => 'mnd_hide_homepage',
'value' => '1',
'compare' => '!=',
'type' => 'NUMERIC'
)
Or
array(
'key' => 'mnd_hide_homepage',
'value' => array('1'),
'compare' => 'NOT IN'
)

How to make an activity to everyone to see on Social Engine?

I am trying to make an activity published by an admin to be visible to every member of the network, not just their friends.
As far as I could make until now, is that the table stream is preventing my message to became public, it only make a profile message. Visible only in its feed.
Does anyone have any idea how to enforce this?
[EDIT]
My code below is picking tweets in my account, I am using some settings i created (like the screen_name from twitter and the user who is publishing the tweet at the feed).
The code is doing as follows:
-> Checking if there is settings for twitter user to read its messages.
-> Save it in a table
-> Authorizing (in theory) to everyone to read this messages, ether is friend of the publisher or not.
-> Adding the activity, that I also created.
$TwitterUser = Engine_Api::_ ()->getApi ( 'settings', 'core' )->getSetting ( 'core.twitter.screen_name' );
if ($TwitterUser != '') {
// Ultimo tweet postado
$TwitterUser = Engine_Api::_ ()->getApi ( 'settings', 'core' )->getSetting ( 'core.twitter.screen_name' );
$table = Engine_Api::_ ()->getDbtable ( 'tweets', 'user' );
$query = $table->select ()->order ( 'tweets_id desc')->limit(1);
$lastTweet = $table->fetchRow ( $query );
// Set the configuration parameters
$config = array ('adapter' => 'Zend_Http_Client_Adapter_Socket', 'ssltransport' => 'tls' );
// Instantiate a client object
if (is_null ( $lastTweet )) {
$client = new Zend_Http_Client ( "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=$TwitterUser&count=4&include_rts=1", $config );
} else {
$client = new Zend_Http_Client ( "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=$TwitterUser&include_rts=1&since_id=" . $lastTweet->real_id, $config );
}
// The following request will be sent over a TLS secure connection.
$response = $client->request ();
// Pegando a resposta
$body = json_decode ( $response->getBody () );
if (! empty ( $body )) {
$db = Engine_Api::_()->getDbtable('tweets', 'user')->getAdapter();
$db->beginTransaction();
try
{
$table = Engine_Api::_ ()->getDbtable ( 'users', 'user' );
$twitter_user = $table->fetchRow ( $table->select ()->where ( 'user_id = ?', Engine_Api::_ ()->getApi ( 'settings', 'core' )->getSetting ( 'core.twitter.user_id' ) ) );
$table = Engine_Api::_ ()->getDbtable ( 'tweets', 'user' );
$activityApi = Engine_Api::_ ()->getDbtable ( 'actions', 'activity' );
foreach ( array_reverse($body) as $tweet ) {
$data = explode ( ' ', $tweet->created_at );
$meses = array ('Jan' => '01', 'Fev' => '02', 'Mar' => '03', 'Apr' => '04', 'May' => '05', 'Jun' => '06', 'Jul' => '07', 'Aug' => '08', 'Sep' => '09', 'Oct' => '10', 'Nov' => '11', 'Dec' => '12' );
$tweet_date = $data ['5'] . "-" . $meses [$data [1]] . '-' . $data [2] . " " . $data [3];
$tweet_date = (date ( 'Y-m-d H:i:s', strtotime ( $tweet_date ) ));
$last_tweet = $table->createRow();
$last_tweet->setFromArray(array(
'real_id' => $tweet->id_str,
'user_id' => $tweet->user->id_str,
'screen_name' => $tweet->user->screen_name,
'body' => $tweet->text,
'retweeted' => $tweet->retweeted,
'created_at' => $tweet_date,
'profile_image_url' => $tweet->user->profile_image_url,
'coordinates' => $tweet->coordinates
));
$last_tweet->save();
// Authorizations
$auth = Engine_Api::_()->authorization()->context;
$auth->setAllowed($last_tweet, 'everyone', 'view', true);
$auth->setAllowed($last_tweet, 'everyone', 'comment', true);
$auth->setAllowed($last_tweet, 'everyone', 'likes', true);
$action = $activityApi->addActivity ($twitter_user,$last_tweet, 'post_twitter', $tweet->text);
if( $action ) {
$activityApi->attachActivity($action, $last_tweet);
}
}
// Commit
$db->commit();
} catch ( Exception $e ) {
$db->rollBack ();
throw $e;
}
}
}
No problems happens, but the tweet that I am tracking only could be red by the user I used to publish it.
You should create entries in stream table for this action_id.