Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter gyroscopic

    (@gyroscopic)

    Well I checked out the plugin code to see how it works and from that it seems there is no (current) way to add classes to the wrapper div.

    So I added my own code to facilitate this.

    It works the same way the ‘add class to form tag’ code works for the html_class shortcode attribute.

    I had to add a new attribute to the list in both classes.php and controller.php and then add a test for extra classes in the classes.php file…

    public function form_html( $atts = array() ) {
    		$atts = wp_parse_args( $atts, array(
    			'html_id' => '',
    			'html_name' => '',
    			'html_class' => '',
    			'div_class' => '' // Wrapper - Allow classes to be added to wrapper div...
    			 ) );
    
    		$this->unit_tag = self::get_unit_tag( $this->id );
    
    		/**
    		 * Start - Allow classes to be added to wrapper div...
    		 * ---------------------------------------------------
    		 */
    		// ORIG: $html = '<div class="wpcf7" id="' . $this->unit_tag . '">' . "\n";
    		$wrapper_class = 'wpcf7';
    		if ( $atts['div_class'] ) {
    			$wrapper_class .= ' ' . $atts['div_class'];
    		}
    		$html = '<div class="' . $wrapper_class . '" id="' . $this->unit_tag . '">' . "\n";
    		/**
    		 * END - Allow classes to be added to wrapper div...
    		 * ---------------------------------------------------
    		 */

    All you have to do is then call the shortcode with the extra attribute and class eg

    [contact-form-7 id="222" div_class="container"]

    the new attribute is div_class

    Maybe the plugin Author can include this in a future update?

    Thread Starter gyroscopic

    (@gyroscopic)

    Fixed

    Thread Starter gyroscopic

    (@gyroscopic)

    Since v3.9 the above fix needs some changes as shown below;

    Now in contact-form.php (classes.php has been removed in v3.9)

    /**
    		 * Start - Allow classes to be added to wrapper div...
    		 * ---------------------------------------------------
    		 */
    		/* ORIG: $html = sprintf( '<div %s>', wpcf7_format_atts( array(
    			'class' => 'wpcf7',
    			'id' => $this->unit_tag,
    			( get_option( 'html_type' ) == 'text/html' ) ? 'lang' : 'xml:lang'
    				=> str_replace( '_', '-', $this->locale ),
    			'dir' => wpcf7_is_rtl( $this->locale ) ? 'rtl' : 'ltr' ) ) ) . "\n";
    		*/
    		$wrapper_class = 'wpcf7';
    		if ( $atts['div_class'] ) {
    			$wrapper_class .= ' ' . $atts['div_class'];
    		}
    
    		$html = sprintf( '<div %s>', wpcf7_format_atts( array(
    			'class' => $wrapper_class,
    			'id' => $this->unit_tag,
    			( get_option( 'html_type' ) == 'text/html' ) ? 'lang' : 'xml:lang'
    				=> str_replace( '_', '-', $this->locale ),
    			'dir' => wpcf7_is_rtl( $this->locale ) ? 'rtl' : 'ltr' ) ) ) . "\n";
    		/**
    		 * END - Allow classes to be added to wrapper div...
    		 * ---------------------------------------------------
    		 */

    Place the above code around line 261 (it replaces the line in ORIG: above)

    ANY CHANCE THE AUTHOR CAN ADD THIS TO THE PLUGIN?????
    He obviously forgot last time!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Add bs3 classes to div wrapper’ is closed to new replies.