12 public $icon =
'dashicons-admin-settings';
24 $this->widget_description = __(
'Allow users to modify the number of results shown per page.',
'gk-gravityview' );
26 $default_values = array(
34 add_action(
'gravityview/view/get', array( $this,
'override_view_page_size' ) );
37 parent::__construct( __(
'Page Size',
'gk-gravityview' ), $this->widget_id, $default_values,
$settings );
52 $default_size = (int) $context->view->settings->get(
'page_size' );
55 $sizes = array( 10, 25, $default_size, 50, 100 );
57 $sizes = array_unique( array_filter( $sizes ) );
61 $page_sizes = array();
62 foreach ( $sizes as $size ) {
63 $page_sizes [] = array(
74 $page_sizes = apply_filters(
'gravityview/widget/page_size/page_sizes', $page_sizes, $context );
92 $page_size = (int) \
GV\
Utils::_GET(
'page_size', $context->view->settings->get(
'page_size' ) );
95 'label' => __(
'Page Size',
'gk-gravityview' ),
96 'choices' => self::get_page_sizes( $context ),
97 'default_choice_text' => __(
'Results Per Page',
'gk-gravityview' ),
98 ), $widget_args,
'gravityview_widget_page_size' );
105 $settings = apply_filters(
'gravityview/widget/page_size/settings',
$settings, $context );
108 <div
class=
"gv-widget-page-size">
109 <form method=
"get" action=
"<?php echo esc_url( add_query_arg( array() ) ); ?>" onchange=
"this.submit();">
111 <?php
if( ! empty(
$settings[
'label'] ) ) { ?>
112 <label
for=
"gv-page_size"><?php echo esc_html(
$settings[
'label'] ); ?></label>
114 <select name=
"page_size" id=
"gv-page_size">
115 <option value=
""><?php echo esc_html(
$settings[
'default_choice_text'] ); ?></option>
117 foreach (
$settings[
'choices'] as $choice ) { ?>
118 <option value=
'<?php echo esc_attr( $choice['value
'] ); ?>'<?php
gv_selected( esc_attr( $choice[
'value'] ), esc_attr( $page_size ),
true ); ?>><?php echo esc_html( $choice[
'text'] ); ?></option>
121 <input type=
"submit" value=
"Submit" style=
"visibility: hidden; position: absolute;" /><?php
122 if( ! empty( $_GET ) ) {
124 unset( $get[
'page_size'] );
125 foreach ( $get as $key =>
$value ) {
126 if ( is_array(
$value ) ) {
127 foreach (
$value as $_key => $_value ) {
128 printf(
'<input type="hidden" name="%s[%s]" value="%s" />', esc_attr( $key ), esc_attr( $_key ), esc_attr( $_value ) );
131 printf(
'<input type="hidden" name="%s" value="%s" />', esc_attr( $key ), esc_attr(
$value ) );
152 if ( ! $view->widgets->by_id(
'page_size' )->count() ) {
158 if ( empty( $page_size ) ) {
163 if ( (
int) $page_size === (
int) $view->settings->get(
'page_size' ) ) {
171 if ( ! in_array( (
int) $page_size, wp_list_pluck( self::get_page_sizes( $context ),
'value' ),
true ) ) {
172 gravityview()->log->warning(
'The passed page size is not allowed: {page_size}. Not modifying result.', array(
'page_size' => $page_size ) );
176 $view->settings->update( array(
'page_size' => $page_size ) );
static _GET( $name, $default=null)
Grab a value from the _GET superglobal or default.
If this file is called directly, abort.
static get_page_sizes( $context)
Get an array of page sizes.
if(empty( $field_settings['content'])) $content
override_view_page_size(&$view)
Override the View settings and inject the needed page size.
static from_template( $template, $data=array())
Create a context from a Template.
gravityview()
The main GravityView wrapper function.
gv_selected( $value, $current, $echo=true, $type='selected')
Similar to the WordPress selected(), checked(), and disabled() functions, except it allows arrays to ...
render_frontend( $widget_args, $content='', $context=null)
Render the page size widget.
Widget to display page size.