__( 'Next Step Widgets', 'cartflows' ) ) ); } /** * Creating widget front-end * * @param array $args arguments array. * @param array $instance widget instance. */ function widget( $args, $instance ) { $title = apply_filters( 'widget_title', $instance['title'] ); $step_id = intval( $instance['step_id'] ); $flow_id = intval( $instance['flow_id'] ); if ( ! $step_id || ! $flow_id ) { global $post; if ( $post && CARTFLOWS_STEP_POST_TYPE === $post->post_type ) { $step_id = intval( $post->ID ); $flow_id = intval( get_post_meta( $step_id, 'wcf-flow-id', true ) ); } } $output = 'No Data'; if ( $flow_id ) { $navigation = false; $steps = get_post_meta( $flow_id, 'wcf-steps', true ); if ( is_array( $steps ) && ! empty( $steps ) ) { foreach ( $steps as $i => $step ) { if ( intval( $step['id'] ) === $step_id ) { $next_i = $i + 1; if ( isset( $steps[ $next_i ] ) ) { $navigation = $steps[ $next_i ]; } break; } } if ( $navigation && is_array( $navigation ) ) { $output = '
'; } } } // before and after widget arguments are defined by themes. echo $args['before_widget']; if ( ! empty( $title ) ) { echo $args['before_title'] . $title . $args['after_title']; } // This is where you run the code and display the output. echo $output; echo $args['after_widget']; } /** * Creating widget back-end * * @param array $instance widget instance. */ function form( $instance ) { if ( isset( $instance['title'] ) ) { $title = $instance['title']; } else { $title = __( 'New title', 'cartflows' ); } if ( isset( $instance['flow_id'] ) ) { $flow_id = $instance['flow_id']; } else { $flow_id = ''; } if ( isset( $instance['step_id'] ) ) { $step_id = $instance['step_id']; } else { $step_id = ''; } // Widget admin form. ?>