PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 1.1.14
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v1.1.14
3.3.0 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.1 trunk 1.0.4 1.1.0 1.1.0.1 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 All 162 releases
cartflows / modules / widgets / class-cartflows-next-step.php

class-cartflows-next-step.php in CartFlows – Funnel Builder & Checkout Plugin for WooCommerce 1.1.14, at modules/widgets/class-cartflows-next-step.php

156 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Next Step Widget
4 *
5 * @package CartFlows
6 */
7
8 /**
9 * Initial Setup
10 *
11 * @since 1.0.0
12 */
13 class Cartflows_Next_Step extends WP_Widget {
14
15 /**
16 * Constructor
17 */
18 function __construct() {
19
20 parent::__construct(
21
22 // Base ID of your widget.
23 'cartflows_next_step',
24 // Widget name will appear in UI.
25 __( 'CartFlows Next Step', 'cartflows' ),
26 // Widget description.
27 array( 'description' => __( 'Next Step Widgets', 'cartflows' ) )
28 );
29 }
30
31 /**
32 * Creating widget front-end
33 *
34 * @param array $args arguments array.
35 * @param array $instance widget instance.
36 */
37 function widget( $args, $instance ) {
38
39 $title = apply_filters( 'widget_title', $instance['title'] );
40
41 $step_id = intval( $instance['step_id'] );
42 $flow_id = intval( $instance['flow_id'] );
43
44 if ( ! $step_id || ! $flow_id ) {
45
46 global $post;
47
48 if ( $post && CARTFLOWS_STEP_POST_TYPE === $post->post_type ) {
49 $step_id = intval( $post->ID );
50 $flow_id = intval( get_post_meta( $step_id, 'wcf-flow-id', true ) );
51 }
52 }
53 $output = 'No Data';
54
55 if ( $flow_id ) {
56
57 $navigation = false;
58
59 $steps = get_post_meta( $flow_id, 'wcf-steps', true );
60
61 if ( is_array( $steps ) && ! empty( $steps ) ) {
62
63 foreach ( $steps as $i => $step ) {
64
65 if ( intval( $step['id'] ) === $step_id ) {
66
67 $next_i = $i + 1;
68
69 if ( isset( $steps[ $next_i ] ) ) {
70 $navigation = $steps[ $next_i ];
71 }
72
73 break;
74 }
75 }
76
77 if ( $navigation && is_array( $navigation ) ) {
78
79 $output = '<div class="wcf-step-navigation"><a class="button" target="_self" href="' . get_permalink( $navigation['id'] ) . '">' . __( 'Next Step', 'cartflows' ) . '</a></div>';
80 }
81 }
82 }
83
84 // before and after widget arguments are defined by themes.
85 echo $args['before_widget'];
86
87 if ( ! empty( $title ) ) {
88 echo $args['before_title'] . $title . $args['after_title'];
89 }
90
91 // This is where you run the code and display the output.
92 echo $output;
93
94 echo $args['after_widget'];
95 }
96
97 /**
98 * Creating widget back-end
99 *
100 * @param array $instance widget instance.
101 */
102 function form( $instance ) {
103
104 if ( isset( $instance['title'] ) ) {
105 $title = $instance['title'];
106 } else {
107 $title = __( 'New title', 'cartflows' );
108 }
109
110 if ( isset( $instance['flow_id'] ) ) {
111 $flow_id = $instance['flow_id'];
112 } else {
113 $flow_id = '';
114 }
115
116 if ( isset( $instance['step_id'] ) ) {
117 $step_id = $instance['step_id'];
118 } else {
119 $step_id = '';
120 }
121 // Widget admin form.
122 ?>
123 <p>
124 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'cartflows' ); ?></label>
125 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
126 </p>
127 <p>
128 <label for="<?php echo $this->get_field_id( 'flow_id' ); ?>"><?php _e( 'Flow ID:', 'cartflows' ); ?></label>
129 <input class="widefat" id="<?php echo $this->get_field_id( 'flow_id' ); ?>" name="<?php echo $this->get_field_name( 'flow_id' ); ?>" type="text" value="<?php echo esc_attr( $flow_id ); ?>" />
130 </p>
131 <p>
132 <label for="<?php echo $this->get_field_id( 'step_id' ); ?>"><?php _e( 'Step ID:', 'cartflows' ); ?></label>
133 <input class="widefat" id="<?php echo $this->get_field_id( 'step_id' ); ?>" name="<?php echo $this->get_field_name( 'step_id' ); ?>" type="text" value="<?php echo esc_attr( $step_id ); ?>" />
134 </p>
135 <?php
136 }
137
138 /**
139 * Updating widget replacing old instances with new
140 *
141 * @param array $new_instance new widget instance.
142 * @param array $old_instance old widget instance.
143 * @return array
144 */
145 function update( $new_instance, $old_instance ) {
146
147 $instance = array();
148
149 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
150 $instance['flow_id'] = ( ! empty( $new_instance['flow_id'] ) ) ? strip_tags( $new_instance['flow_id'] ) : '';
151 $instance['step_id'] = ( ! empty( $new_instance['step_id'] ) ) ? strip_tags( $new_instance['step_id'] ) : '';
152
153 return $instance;
154 }
155 }
156