PodsWidgetField.php
4 months ago
PodsWidgetForm.php
4 months ago
PodsWidgetList.php
4 months ago
PodsWidgetSingle.php
4 months ago
PodsWidgetView.php
4 months ago
PodsWidgetField.php
85 lines
| 1 | <?php |
| 2 | |
| 3 | // Don't load directly. |
| 4 | if ( ! defined( 'ABSPATH' ) ) { |
| 5 | die( '-1' ); |
| 6 | } |
| 7 | |
| 8 | /** |
| 9 | * @package Pods\Widgets |
| 10 | */ |
| 11 | class PodsWidgetField extends WP_Widget { |
| 12 | |
| 13 | /** |
| 14 | * {@inheritdoc} |
| 15 | */ |
| 16 | public function __construct( $id_base = '', $name = '', $widget_options = [], $control_options = [] ) { |
| 17 | parent::__construct( 'pods_widget_field', __( 'Pods - Field Value', 'pods' ), [ |
| 18 | 'classname' => 'pods_widget_field', |
| 19 | 'description' => __( "Display a single Pod item's field value", 'pods' ), |
| 20 | ], [ 'width' => 200 ] ); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * {@inheritdoc} |
| 25 | */ |
| 26 | public function widget( $args, $instance ) { |
| 27 | // Setup basic widget parameters. |
| 28 | $before_widget = pods_v( 'before_widget', $args ); |
| 29 | $after_widget = pods_v( 'after_widget', $args ); |
| 30 | $before_title = pods_v( 'before_title', $args ); |
| 31 | $title = apply_filters( 'widget_title', pods_v( 'title', $instance ) ); |
| 32 | $after_title = pods_v( 'after_title', $args ); |
| 33 | $before_content = pods_v( 'before_content', $instance ); |
| 34 | $after_content = pods_v( 'after_content', $instance ); |
| 35 | |
| 36 | $args = [ |
| 37 | 'name' => trim( (string) pods_v( 'pod_type', $instance, '' ) ), |
| 38 | 'slug' => trim( (string) pods_v( 'slug', $instance, '' ) ), |
| 39 | 'use_current' => trim( (string) pods_v( 'use_current', $instance, '' ) ), |
| 40 | 'field' => trim( (string) pods_v( 'field', $instance, '' ) ), |
| 41 | ]; |
| 42 | |
| 43 | if ( |
| 44 | ( |
| 45 | ( |
| 46 | 0 < strlen( $args['name'] ) |
| 47 | && 0 < strlen( $args['slug'] ) |
| 48 | ) |
| 49 | || 0 < strlen( $args['use_current'] ) |
| 50 | ) |
| 51 | && 0 < strlen( $args['field'] ) |
| 52 | ) { |
| 53 | require PODS_DIR . 'ui/front/widgets.php'; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * {@inheritdoc} |
| 59 | */ |
| 60 | public function update( $new_instance, $old_instance ) { |
| 61 | $instance = $old_instance; |
| 62 | |
| 63 | $instance['title'] = pods_v( 'title', $new_instance, '' ); |
| 64 | $instance['pod_type'] = pods_v( 'pod_type', $new_instance, '' ); |
| 65 | $instance['slug'] = pods_v( 'slug', $new_instance, '' ); |
| 66 | $instance['use_current'] = pods_v( 'use_current', $new_instance, '' ); |
| 67 | $instance['field'] = pods_v( 'field', $new_instance, '' ); |
| 68 | |
| 69 | return $instance; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * {@inheritdoc} |
| 74 | */ |
| 75 | public function form( $instance ) { |
| 76 | $title = pods_v( 'title', $instance, '' ); |
| 77 | $pod_type = pods_v( 'pod_type', $instance, '' ); |
| 78 | $slug = pods_v( 'slug', $instance, '' ); |
| 79 | $use_current = pods_v( 'use_current', $instance, '' ); |
| 80 | $field = pods_v( 'field', $instance, '' ); |
| 81 | |
| 82 | require PODS_DIR . 'ui/admin/widgets/field.php'; |
| 83 | } |
| 84 | } |
| 85 |