15 $name = __(
'GravityView Recent Entries',
'gk-gravityview');
17 $widget_options = array(
18 'description' => __(
'Display the most recent entries for a View',
'gk-gravityview' ),
21 parent::__construct(
'gv_recent_entries',
$name, $widget_options );
28 add_action(
'admin_enqueue_scripts', array( $this,
'admin_enqueue_scripts') );
30 add_action(
'wp_ajax_gv_get_view_merge_tag_data', array( $this,
'ajax_get_view_merge_tag_data' ) );
41 if ( ! isset( $_POST[
'nonce'] ) || ! wp_verify_nonce( $_POST[
'nonce'],
'gravityview_ajax_widget' ) ) {
52 'title' =>
$form[
'title'],
53 'fields' =>
$form[
'fields'],
55 'mergeTags' => GFCommon::get_merge_tags(
$form[
'fields'],
'',
false ),
71 if( $pagenow ===
'widgets.php' ) {
73 $script_debug = (defined(
'SCRIPT_DEBUG') && SCRIPT_DEBUG) ?
'' :
'.min';
75 wp_enqueue_script(
'gravityview_widgets', plugins_url(
'assets/js/admin-widgets'.$script_debug.
'.js',
GRAVITYVIEW_FILE), array(
'jquery',
'gform_gravityforms' ),
GV_PLUGIN_VERSION );
77 wp_localize_script(
'gravityview_widgets',
'GVWidgets', array(
78 'nonce' => wp_create_nonce(
'gravityview_ajax_widget' )
96 if( empty( $instance[
'view_id'] ) ) {
100 if ( defined(
'REST_REQUEST' ) && REST_REQUEST ) {
104 $args[
'id'] = ( isset(
$args[
'id'] ) ) ?
$args[
'id'] :
'gv_recent_entries';
105 $instance[
'title'] = ( isset( $instance[
'title'] ) ) ? $instance[
'title'] :
'';
107 $title = apply_filters(
'widget_title', $instance[
'title' ], $instance,
$args[
'id'] );
109 echo
$args[
'before_widget'];
112 echo $args[
'before_title'] .
$title . $args[
'after_title'];
120 do_action(
'gravityview/widget/recent-entries/before_widget', $args, $instance );
123 echo $this->get_output( $instance );
130 do_action(
'gravityview/widget/recent-entries/after_widget', $args, $instance );
132 echo $args[
'after_widget'];
144 private function get_output( $instance ) {
156 $entry_link_post_id = ( empty( $instance[
'error_post_id'] ) && !empty( $instance[
'post_id'] ) ) ? $instance[
'post_id'] : $instance[
'view_id'];
162 $List =
new GravityView_Entry_List(
$entries, $entry_link_post_id,
$form, $instance[
'link_format'], $instance[
'after_link'],
'recent-entries-widget', null, $instance[
'view_id'] );
171 $output = apply_filters(
'gravityview/widget/recent-entries/output',
$output, $instance );
189 $limit = isset( $instance[
'limit'] ) ? $instance[
'limit'] : 10;
191 $view->settings->set(
'page_size', $limit );
207 public function update( $new_instance, $old_instance ) {
209 $instance = $new_instance;
212 $instance[
'limit'] = empty( $instance[
'limit'] ) ? 10 : absint( $instance[
'limit'] );
214 $instance[
'view_id'] = intval( $instance[
'view_id'] );
216 $instance[
'link_format'] = trim( rtrim( $instance[
'link_format'] ) );
218 $instance[
'link_format'] = empty( $instance[
'link_format'] ) ? $old_instance[
'link_format'] : $instance[
'link_format'];
220 $instance[
'post_id'] = empty( $instance[
'post_id'] ) ?
'' : intval( $instance[
'post_id'] );
225 $instance[
'error_post_id'] = is_wp_error( $is_valid_embed_id ) ? $is_valid_embed_id->get_error_message() : NULL;
228 $instance[
'updated'] = 1;
237 $instance = apply_filters(
'gravityview/widget/update', $instance, $new_instance, $old_instance );
246 public function form( $instance ) {
250 'title' => __(
'Recent Entries',
'gk-gravityview'),
254 'link_format' => __(
'Entry #{entry_id}',
'gk-gravityview'),
258 $instance = wp_parse_args( (array) $instance, $defaults );
264 <label
for=
"<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e(
'Title:',
'gk-gravityview' ) ?></label>
265 <input
class=
"widefat" id=
"<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name=
"<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type=
"text" value=
"<?php echo esc_attr( $instance['title'] ); ?>" />
271 'post_type' =>
'gravityview',
272 'posts_per_page' => -1,
273 'post_status' =>
'publish',
275 $views = get_posts( $args );
278 if( empty( $views ) ) {
290 if( isset( $instance[
'updated'] ) && empty( $instance[
'view_id'] ) ) {
292 <div
class=
"error inline hide-on-view-change">
293 <p><?php esc_html_e(
'Please select a View to search.',
'gk-gravityview'); ?></p>
301 <label
for=
"<?php echo esc_attr( $this->get_field_id( 'view_id' ) ); ?>"><?php esc_html_e(
'Select a View',
'gk-gravityview'); ?></label>
302 <select
class=
"widefat gv-recent-entries-select-view" name=
"<?php echo esc_attr( $this->get_field_name( 'view_id' ) ); ?>" id=
"<?php echo esc_attr( $this->get_field_id( 'view_id' ) ); ?>">
303 <option value=
""><?php esc_html_e(
'— Select a View as Entries Source —',
'gk-gravityview' ); ?></option>
306 foreach( $views as $view ) {
307 $title = empty( $view->post_title ) ? __(
'(no title)',
'gk-gravityview') : $view->post_title;
308 echo
'<option value="'. $view->ID .
'"'.selected( absint( $instance[
'view_id'] ), $view->ID ).
'>'. esc_html( sprintf(
'%s #%d',
$title, $view->ID ) ) .
'</option>';
320 if( !empty( $instance[
'error_post_id'] ) ) {
322 <div
class=
"error inline">
323 <p><?php echo $instance[
'error_post_id']; ?></p>
331 <label
for=
"<?php echo $this->get_field_id('post_id'); ?>"><?php esc_html_e(
'If Embedded, Page ID:',
'gk-gravityview' ); ?></label>
332 <input
class=
"code" size=
"3" id=
"<?php echo $this->get_field_id('post_id'); ?>" name=
"<?php echo $this->get_field_name('post_id'); ?>" type=
"text" value=
"<?php echo esc_attr( $instance['post_id'] ); ?>" />
333 <span
class=
"howto gv-howto"><?php
334 esc_html_e(
'To have a search performed on an embedded View, enter the ID of the post or page where the View is embedded.',
'gk-gravityview' );
335 echo
' '.gravityview_get_link(
'https://docs.gravityview.co/article/222-the-search-widget', __(
'Learn more…',
'gk-gravityview' ),
'target=_blank' );
340 <label
for=
"<?php echo $this->get_field_id( 'limit' ); ?>">
341 <span><?php _e(
'Number of entries to show:',
'gk-gravityview' ); ?></span>
343 <input
class=
"code" id=
"<?php echo $this->get_field_id( 'limit' ); ?>" name=
"<?php echo $this->get_field_name( 'limit' ); ?>" type=
"number" value=
"<?php echo intval( $instance['limit'] ); ?>" size=
"3" />
347 <label
for=
"<?php echo $this->get_field_id( 'link_format' ); ?>">
348 <span><?php _e(
'Entry link text (required)',
'gk-gravityview' ); ?></span>
350 <input
id=
"<?php echo $this->get_field_id( 'link_format' ); ?>" name=
"<?php echo $this->get_field_name( 'link_format' ); ?>" type=
"text" value=
"<?php echo esc_attr( $instance['link_format'] ); ?>" class=
"widefat merge-tag-support mt-position-right mt-hide_all_fields" />
354 <label
for=
"<?php echo $this->get_field_id( 'after_link' ); ?>">
355 <span><?php _e(
'Text or HTML to display after the link (optional)',
'gk-gravityview' ); ?></span>
357 <textarea
id=
"<?php echo $this->get_field_id( 'after_link' ); ?>" name=
"<?php echo $this->get_field_name( 'after_link' ); ?>" rows=
"5" class=
"widefat code merge-tag-support mt-position-right mt-hide_all_fields"><?php echo esc_textarea( $instance[
'after_link'] ); ?></textarea>
367 do_action(
'gravityview_recent_entries_widget_form' , $this, $instance );
374 jQuery(
'#<?php echo $this->get_field_id( 'view_id
' ); ?>').trigger(
'change' );
const GV_PLUGIN_VERSION(! GravityKit\GravityView\Foundation\meets_min_php_version_requirement(__FILE__, '7.2.0'))
Constants.
If this file is called directly, abort.
gravityview_get_form( $form_id)
Returns the form object for a given Form ID.
static is_valid_embed_id( $post_id='', $view_id='', $empty_is_valid=false)
Checks if the passed post id has the passed View id embedded.
if(gravityview() ->plugin->is_GF_25()) $form
static no_views_text()
Get text for no views found.
static by_id( $post_id)
Construct a instance from a post ID.
gravityview_get_form_id( $view_id)
Get the connected form ID from a View ID.
const GRAVITYVIEW_FILE
Full path to the GravityView file "GRAVITYVIEW_FILE" "./gravityview.php".
if(empty( $created_by)) $form_id