Forum Replies Created

Viewing 6 replies - 16 through 21 (of 21 total)
  • Thread Starter jroakes

    (@jroakes)

    I was following the lead of mashable.com in that they have the various resources coming from http://9.mshcdn.com, http://8.mshcdn.com, http://7.mshcdn.com, etc. We do a lot more diverse sites than Mashable so I thought that if I segmented the types of files on each site (css, files, images, scripts) and created a “key” directory on each subdomain (i.e. css.domainCDN.com/sitename/ script.domainCDN.com/sitename and files.domainCDN.com/sitename/) that matched up to the site name then we could use your plugin (which rocks btw) to load the the resources in parallel to each site from our servers. These are currently on 1 server and the thought is that as we grow our wp sites these individual subdomains could move out to their own server if needed.
    We are trying out VPS.net as well and might just use them but we like the thought of managing our own files.

    Ok. So here is a modified version that fixes a bug that was making the form not work with other required fields.

    <?php
    /**
    ** A base module for [text*], and [email*]
    **/
    
    /* Validation filter for either or fields
    	use or_field:tag
    	use or_label:field label
    
    */
    
    add_filter( 'wpcf7_validate_text*', 'wpcf7_textor_validation_filter', 20, 2 );
    add_filter( 'wpcf7_validate_email*', 'wpcf7_textor_validation_filter', 20, 2 );
    
    function wpcf7_textor_validation_filter( $result, $tag ) {
    	$type = $tag['type'];
    	$name = $tag['name'];
    	$options = (array) $tag['options'];
    
    	foreach ( $options as $option ) {
    
    		if ( preg_match( '%^or_field:([-0-9a-zA-Z_]+)$%', $option, $matches ) ) {
    		$match = $matches[1];
    		$match = trim((string)$match);
    		}
    
    		if ( preg_match( '%^or_label:([-0-9a-zA-Z_]+)$%', $option, $matches ) ) {
    		$lmatch = $matches[1];
    		$lmatch = trim((string)$lmatch);
    		$lmatch = str_replace('_', ' ',$lmatch);
    		}
    
    	}
    
    	$_POST[$match] = trim( strtr( (string) $_POST[$match], "\n", " " ) );
    	$_POST[$name] = trim( strtr( (string) $_POST[$name], "\n", " " ) );
    
    	$custom_response = 'This field or the '. $lmatch .'  field are required';
    
    	if ( 'text*' == $type ) {
    		if ( '' == $_POST[$name] && '' == $_POST[$match] && $match) {
    			$result['valid'] = false;
    
    			$result['reason'][$name] = $custom_response;
    		} elseif ($match) {
    
    			$result['valid'] = true;
    
    		}
    	}
    
    	if ( 'email*' == $type ) {
    
    		if ( '' == $_POST[$name] &&  '' == $_POST[$match] && $match) {
    			$result['valid'] = false;
    			$result['reason'][$name] = $custom_response;
    		} elseif ( '' != $_POST[$name] && ! is_email( $_POST[$name] && $match) ) {
    			$result['valid'] = false;
    			$result['reason'][$name] = wpcf7_get_message( 'invalid_email' );
    		} elseif($match) {
    
    			$result['valid'] = true;
    
    		}
    	}
    
    	return $result;
    
    }
    
    /* Tag generator */
    
    add_action( 'admin_init', 'wpcf7_add_tag_generator_textor_and_emailor', 1 );
    
    function wpcf7_add_tag_generator_textor_and_emailor() {
    	wpcf7_add_tag_generator( 'text', __( 'Text field', 'wpcf7' ),
    		'wpcf7-tg-pane-text', 'wpcf7_tg_pane_textor' );
    
    	wpcf7_add_tag_generator( 'email', __( 'Email field', 'wpcf7' ),
    		'wpcf7-tg-pane-email', 'wpcf7_tg_pane_emailor' );
    }
    
    function wpcf7_tg_pane_textor( &$contact_form ) {
    	wpcf7_tg_pane_textor_and_emailor( 'text' );
    }
    
    function wpcf7_tg_pane_emailor( &$contact_form ) {
    	wpcf7_tg_pane_textor_and_emailor( 'email' );
    }
    
    function wpcf7_tg_pane_textor_and_emailor( $type = 'text' ) {
    	if ( 'email' != $type )
    		$type = 'text';
    
    ?>
    <div id="wpcf7-tg-pane-<?php echo $type; ?>" class="hidden">
    <form action="">
    <table>
    <tr><td><input type="checkbox" name="required" />&nbsp;<?php echo esc_html( __( 'Required field?', 'wpcf7' ) ); ?></td></tr>
    <tr><td><?php echo esc_html( __( 'Name', 'wpcf7' ) ); ?><br /><input type="text" name="name" class="tg-name oneline" /></td><td></td></tr>
    </table>
    
    <table>
    <tr>
    <td><code>id</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
    <input type="text" name="id" class="idvalue oneline option" /></td>
    
    <td><code>class</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
    <input type="text" name="class" class="classvalue oneline option" /></td>
    </tr>
    
    <tr>
    <td><code>size</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
    <input type="text" name="size" class="numeric oneline option" /></td>
    
    <td><code>maxlength</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
    <input type="text" name="maxlength" class="numeric oneline option" /></td>
    </tr>
    
    <tr>
    <td><code>or_field</code> <br />(<?php echo esc_html( __( 'match field tag name', 'wpcf7' ) ); ?>)<br />
    <input type="text" name="or_field" class="or_field oneline option" /></td>
    
    <td><code>or_label</code> <br />(<?php echo esc_html( __( 'match field pretty name (use _ for spaces', 'wpcf7' ) ); ?>)<br />
    <input type="text" name="or_label" class="or_label oneline option" /></td>
    </tr>
    
    <tr>
    <td colspan="2"><p> The fields above are useful only when the field you are adding is a required field.  These will make the current field and another field an either/or field. (ie.  <strong>email</strong> or <strong>phone number</strong> are required.  <br /> The format is <strong>[email* or_field:phone or_label:Phone_Number]</strong>  if phone is the other field tag name. </p></td>
    </tr>
    
    <tr>
    <td colspan="2"><?php echo esc_html( __( 'Akismet', 'wpcf7' ) ); ?> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
    <?php if ( 'text' == $type ) : ?>
    <input type="checkbox" name="akismet:author" class="exclusive option" />&nbsp;<?php echo esc_html( __( "This field requires author's name", 'wpcf7' ) ); ?><br />
    <input type="checkbox" name="akismet:author_url" class="exclusive option" />&nbsp;<?php echo esc_html( __( "This field requires author's URL", 'wpcf7' ) ); ?>
    <?php else : ?>
    <input type="checkbox" name="akismet:author_email" class="option" />&nbsp;<?php echo esc_html( __( "This field requires author's email address", 'wpcf7' ) ); ?>
    <?php endif; ?>
    </td>
    </tr>
    
    <tr>
    <td><?php echo esc_html( __( 'Default value', 'wpcf7' ) ); ?> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br /><input type="text" name="values" class="oneline" /></td>
    
    <td>
    <br /><input type="checkbox" name="watermark" class="option" />&nbsp;<?php echo esc_html( __( 'Use this text as watermark?', 'wpcf7' ) ); ?>
    </td>
    </tr>
    </table>
    
    <div class="tg-tag"><?php echo esc_html( __( "Copy this code and paste it into the form left.", 'wpcf7' ) ); ?><br /><input type="text" name="<?php echo $type; ?>" class="tag" readonly="readonly" onfocus="this.select()" /></div>
    
    <div class="tg-mail-tag"><?php echo esc_html( __( "And, put this code into the Mail fields below.", 'wpcf7' ) ); ?><br /><span class="arrow">⬇</span>&nbsp;<input type="text" class="mail-tag" readonly="readonly" onfocus="this.select()" /></div>
    </form>
    </div>
    <?php
    }
    
    ?>

    You got it!

    Put the following code into a file called text_or.php and put the file in your contact-form-7/modules/ folder. This plugin is VERY extendable with the modules area. The developer is awesome!

    <?php
    /**
    ** A base module for [text*], and [email*]
    **/
    
    /* Validation filter for either or fields
    use or_field:tag
    use or_label:field label
    
    */
    
    add_filter( 'wpcf7_validate_text*', 'wpcf7_textor_validation_filter', 20, 2 );
    add_filter( 'wpcf7_validate_email*', 'wpcf7_textor_validation_filter', 20, 2 );
    
    function wpcf7_textor_validation_filter( $result, $tag ) {
    $type = $tag['type'];
    $name = $tag['name'];
    $options = (array) $tag['options'];
    
    foreach ( $options as $option ) {
    
    if ( preg_match( '%^or_field:([-0-9a-zA-Z_]+)$%', $option, $matches ) ) {
    $match = $matches[1];
    $match = trim((string)$match);
    }
    
    if ( preg_match( '%^or_label:([-0-9a-zA-Z_]+)$%', $option, $matches ) ) {
    $lmatch = $matches[1];
    $lmatch = trim((string)$lmatch);
    $lmatch = str_replace('_', ' ',$lmatch);
    }
    
    }
    
    $_POST[$match] = trim( strtr( (string) $_POST[$match], "\n", " " ) );
    $_POST[$name] = trim( strtr( (string) $_POST[$name], "\n", " " ) );
    
    $custom_response = 'This field or the '. $lmatch .' field are required';
    
    if ( 'text*' == $type ) {
    if ( '' == $_POST[$name] && '' == $_POST[$match] ) {
    $result['valid'] = false;
    
    $result['reason'][$name] = $custom_response;
    } else {
    
    $result['valid'] = true;
    
    }
    }
    
    if ( 'email*' == $type ) {
    
    if ( '' == $_POST[$name] && '' == $_POST[$match] ) {
    $result['valid'] = false;
    $result['reason'][$name] = $custom_response;
    } elseif ( '' != $_POST[$name] && ! is_email( $_POST[$name] ) ) {
    $result['valid'] = false;
    $result['reason'][$name] = wpcf7_get_message( 'invalid_email' );
    } else {
    
    $result['valid'] = true;
    
    }
    }
    
    return $result;
    }
    
    /* Tag generator */
    
    add_action( 'admin_init', 'wpcf7_add_tag_generator_textor_and_emailor', 1 );
    
    function wpcf7_add_tag_generator_textor_and_emailor() {
    wpcf7_add_tag_generator( 'text', __( 'Text field', 'wpcf7' ),
    'wpcf7-tg-pane-text', 'wpcf7_tg_pane_textor' );
    
    wpcf7_add_tag_generator( 'email', __( 'Email field', 'wpcf7' ),
    'wpcf7-tg-pane-email', 'wpcf7_tg_pane_emailor' );
    }
    
    function wpcf7_tg_pane_textor( &$contact_form ) {
    wpcf7_tg_pane_textor_and_emailor( 'text' );
    }
    
    function wpcf7_tg_pane_emailor( &$contact_form ) {
    wpcf7_tg_pane_textor_and_emailor( 'email' );
    }
    
    function wpcf7_tg_pane_textor_and_emailor( $type = 'text' ) {
    if ( 'email' != $type )
    $type = 'text';
    
    ?>
    <div id="wpcf7-tg-pane-<?php echo $type; ?>" class="hidden">
    <form action="">
    <table>
    <tr><td><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field?', 'wpcf7' ) ); ?></td></tr>
    <tr><td><?php echo esc_html( __( 'Name', 'wpcf7' ) ); ?>
    <input type="text" name="name" class="tg-name oneline" /></td><td></td></tr>
    </table>
    
    <table>
    <tr>
    <td>id (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)
    <input type="text" name="id" class="idvalue oneline option" /></td>
    
    <td>class (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)
    <input type="text" name="class" class="classvalue oneline option" /></td>
    </tr>
    
    <tr>
    <td>size (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)
    <input type="text" name="size" class="numeric oneline option" /></td>
    
    <td>maxlength (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)
    <input type="text" name="maxlength" class="numeric oneline option" /></td>
    </tr>
    
    <tr>
    <td>or_field
    (<?php echo esc_html( __( 'match field tag name', 'wpcf7' ) ); ?>)
    <input type="text" name="or_field" class="or_field oneline option" /></td>
    
    <td>or_label
    (<?php echo esc_html( __( 'match field pretty name (use _ for spaces', 'wpcf7' ) ); ?>)
    <input type="text" name="or_label" class="or_label oneline option" /></td>
    </tr>
    
    <tr>
    <td colspan="2"><p> The fields above are useful only when the field you are adding is a required field. These will make the current field and another field an either/or field. (ie. email or phone number are required.
    The format is [email* or_field:phone or_label:Phone_Number] if phone is the other field tag name. </p></td>
    </tr>
    
    <tr>
    <td colspan="2"><?php echo esc_html( __( 'Akismet', 'wpcf7' ) ); ?> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)
    <?php if ( 'text' == $type ) : ?>
    <input type="checkbox" name="akismet:author" class="exclusive option" /> <?php echo esc_html( __( "This field requires author's name", 'wpcf7' ) ); ?>
    <input type="checkbox" name="akismet:author_url" class="exclusive option" /> <?php echo esc_html( __( "This field requires author's URL", 'wpcf7' ) ); ?>
    <?php else : ?>
    <input type="checkbox" name="akismet:author_email" class="option" /> <?php echo esc_html( __( "This field requires author's email address", 'wpcf7' ) ); ?>
    <?php endif; ?>
    </td>
    </tr>
    
    <tr>
    <td><?php echo esc_html( __( 'Default value', 'wpcf7' ) ); ?> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)
    <input type="text" name="values" class="oneline" /></td>
    
    <td>
    
    <input type="checkbox" name="watermark" class="option" /> <?php echo esc_html( __( 'Use this text as watermark?', 'wpcf7' ) ); ?>
    </td>
    </tr>
    </table>
    
    <div class="tg-tag"><?php echo esc_html( __( "Copy this code and paste it into the form left.", 'wpcf7' ) ); ?>
    <input type="text" name="<?php echo $type; ?>" class="tag" readonly="readonly" onfocus="this.select()" /></div>
    
    <div class="tg-mail-tag"><?php echo esc_html( __( "And, put this code into the Mail fields below.", 'wpcf7' ) ); ?>
    <span class="arrow">⬇</span> <input type="text" class="mail-tag" readonly="readonly" onfocus="this.select()" /></div>
    </form>
    </div>
    <?php
    }
    
    ?>

    So now that we know that multiple post types can share a taxonomy, how would you craft a url to know which post type to display when you select a certain taxonomy tag?

    Here is a very easy way of doing this:

    Just follow the instructions at the top of the script.

    <?php
    /**
    ** A base module for [hidden customfield]
    **
    **--Instructions--
    ** Put this script as a file (hidden_custom.php) into the plugins/contact-form-7/modules/ folder.
    ** "Hidden Custom Field" should now be an option in the "Generate Tag" dropdown of your contact form.
    ** Type the name of your custom field in the "The Custom Field name goes here" field.
    ** Put the 2 generated into the form and email as indicated.
    **
    **/
    
    // Shortcode handler
    
    wpcf7_add_shortcode( hidden, 'wpcf7_hidden_shortcode_handler', true );
    
    function wpcf7_hidden_shortcode_handler( $tag ) {
    	if ( ! is_array( $tag ) )
    		return '';
    
    	$name = $tag['name'];
    
    	$options = (array) $tag['options'];
    	$values = (array) $tag['values'];
    
    	$atts = '';
    	$id_att = '';
    
    	$class_att .= ' wpcf7-hidden';
    
    	foreach ( $options as $option ) {
    		if ( preg_match( '%^id:([-0-9a-zA-Z_]+)$%', $option, $matches ) ) {
    			$id_att = $matches[1];
    		}
    	}
    
    	if ( $id_att )
    		$atts .= ' id="' . trim( $id_att ) . '"';
    
    	global $wp_query;
    
    	$postid = $wp_query->post->ID;
    
    	$theCustomValue = get_post_meta($postid, $name , true);
    
    	$value = $theCustomValue;
    
    	$html = '<input name="'.$name.'" type="hidden" value="' . esc_attr( $value ) . '"' . $atts . ' />';
    
    	return $html;
    }
    
    // Tag generator
    
    add_action( 'admin_init', 'wpcf7_add_tag_generator_hidden', 50 );
    
    function wpcf7_add_tag_generator_hidden() {
    	wpcf7_add_tag_generator( 'hidden', __( 'Hidden Custom Field', 'wpcf7' ),
    		'wpcf7-tg-pane-hidden', 'wpcf7_tg_pane_hidden' );
    }
    
    function wpcf7_tg_pane_hidden( &$contact_form ) {
    ?>
    <div id="wpcf7-tg-pane-hidden" class="hidden">
    <form action="">
    <table>
    <tr><td><?php echo esc_html( __( 'The Custom Field name goes here', 'wpcf7' ) ); ?><br /><input type="text" name="name" class="tg-name oneline" /></td><td></td></tr>
    </table>
    <!-- I am killing these because they are not needed.  I am leaving them in case someone wants to modify this code.
    <table>
    
    <tr>
    
    <td><code>id</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
    <input type="text" name="id" class="idvalue oneline option" /></td>
    
    <td><code>class</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
    <input type="text" name="class" class="classvalue oneline option" /></td>
    </tr>
    
    </table>
    -->
    <div class="tg-tag"><?php echo esc_html( __( "Copy this code and paste it into the form left.", 'wpcf7' ) ); ?><br /><input type="text" name="hidden" class="tag" readonly="readonly" onfocus="this.select()" /></div>
    
    <div class="tg-mail-tag"><?php echo esc_html( __( "And, put this code anywhere in the emails below.", 'wpcf7' ) ); ?><br /><span class="arrow" style="font-size:20px;">&rarr;</span>&nbsp;<input type="text" class="mail-tag" readonly="readonly" onfocus="this.select()" /></div>
    </form>
    </div>
    <?php
    }
    
    ?>
Viewing 6 replies - 16 through 21 (of 21 total)