$description ) ); } /** * Outputs the content of the widget. * * @param array $args * @param array $instance */ public function widget( $args, $instance ) { // Get the form that the Developer selected - if there is no form, then early exit. $form_id = !empty( $instance['form_id'] ) ? $instance['form_id'] : false; if ( !$form_id ) return; // This function acts on the selected form - get it. $query_args = array ( 'post__in' => array( $form_id ), 'post_type' => 'wpcf7_contact_form' ); $result = new \WP_Query( $query_args ); if ( !$result || ( count( $result->posts ) != 1 ) ) return; $form = $result->posts[0]; // Wrap start. echo $args['before_widget']; // The title comes from the Contact form, but can be overridden in the widget. $title = ( empty( $instance['title'] ) ) ? $form->post_title : $instance['title']; $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); if ( !empty( $title ) ) echo $args['before_title'].$title.$args['after_title']; // Making it here means that we can display the contact form - use the // shortcode provided by Contact Form 7. echo do_shortcode( '[contact-form-7 id="'.$form->ID.'"]' ); // Wrap end. echo $args['after_widget']; } /** * Outputs the options form on admin. * * @param array $instance The widget options */ public function form( $instance ) { $title = isset( $instance['title'] ) ? strip_tags( $instance['title'] ) : ''; $form_id = isset( $instance['form_id'] ) ? $instance['form_id'] : ''; // Display the title, similar to the WP-provided widgets. echo '
'.
''.
'
'.
''.
__( 'Leave blank to use the title from the form.', 'bpq' ).
''.
'
'. sprintf( __( 'Before you can use this widget, you must ensure that the Contact Form 7 '. 'plugin is installed and activated.' ), admin_url( 'themes.php?page=tgmpa-install-plugins' ) ). '
'; return; } // Get a list of the Contact Form 7 forms already defined. $args = array ( 'post_type' => 'wpcf7_contact_form', 'order_by' => 'title', 'order' => 'ASC' ); $result = new \WP_Query( $args ); // If there are no forms, direct the user to the Contact Form 7 interface. if ( !$result || !$result->posts ) { echo ''. sprintf( __( 'No Contact Form 7 forms have been created yet. Create some.'), admin_url( 'admin.php?page=wpcf7' ) ) . '
'; return; } // Making it here means that the list of forms can be displayed. echo ''.
''.
'
'.
''.
sprintf( __( 'You can create/delete Contact Form 7 forms here.', 'bpq' ), admin_url( 'admin.php?page=wpcf7' ) ).
''.
'