我有一个我无法弄清楚的问题。
http://www.realcommissionadvance.com/sign-up-form/
如果一个WP页面/帖子模板上有两个重力表单,则会显示错误。
警告:substr_count():第176行/home/joenygren/public_html/wp-content/plugins/commission-rates-calculator0423/commission_rates_calculator.php中的空子字符串
有什么想法吗?
<?php
/**
* Plugin Name: Commission Rates Calculator
* Plugin URI: http://ellaking.net
* Description: Commission Rates Calculator
* Version: 1.0.1
* Author: ellaking
* Author URI: http://ellaking.net
**/
class Commission_Rates_Calculator{
private $fdate;
function commission_rates_calculator(){
add_action( 'crc_init', array( &$this, 'crc_enqueue_scripts') );
add_filter('widget_text', 'do_shortcode');
//add_filter('gform_field_value_fdate', array( &$this, 'populate_fdate') );
//add_filter('gform_pre_submission', array( &$this, 'add_fdate') );
add_filter("gform_pre_render", array( &$this, "populate_dropdown"));
//Note: when changing drop down values, we also need to use the gform_admin_pre_render so that the right values are displayed when editing the entry.
//add_filter("gform_admin_pre_render", array( &$this, "populate_dropdown"));
//Note: this will allow for the labels to be used during the submission process in case values are enabled
add_filter('gform_pre_submission_filter', array( &$this, 'populate_dropdown'));
if(is_admin()){
add_action( 'admin_menu', array( &$this, 'crc_settings_page') );
}
add_shortcode('commission_rates_calculator', array( &$this, 'crc_show_calculator') );
}
function crc_settings_page() {
add_options_page('Commission Rates Calculator', 'Commission Rates Calculator', 'manage_options', 'crc_settings', array( &$this, 'crc_settings'));
}
function crc_settings(){
if ( isset( $_POST['save_crc'] ) ) {
$new_crc_rate = $old_crc_rate = get_option('crc_rate');
$new_crc_rate = $_POST['crc_rate'];
$new_crc_anticipated_time = $old_crc_anticipated_time = get_option('crc_anticipated_time');
$new_crc_anticipated_time = $_POST['crc_anticipated_time'];
if ( $old_crc_rate != $new_crc_rate ) {
update_option( 'crc_rate', $new_crc_rate );
}
if ( $old_crc_anticipated_time != $new_crc_anticipated_time ) {
update_option( 'crc_anticipated_time', $new_crc_anticipated_time );
}
}
$crc_rate = get_option('crc_rate');
$crc_anticipated_time = get_option('crc_anticipated_time');
if(empty($crc_rate)){
$crc_rate = 0.00075;
}
if(empty($crc_anticipated_time)){
$crc_anticipated_time = 10;
}
?>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("#crc_form").submit(function(){
var csc_rate = jQuery("#crc_rate_text").val();
var crc_anticipated_time = jQuery("#crc_anticipated_time_text").val();
if(isNaN(csc_rate)){
alert("Please enter a decimal such as 0.00075");
jQuery("#crc_rate_text").val('');
jQuery("#crc_rate_text").focus();
return false;
}
if(isNaN(crc_anticipated_time)){
alert("Please enter a anticipated time such as 10");
jQuery("#crc_anticipated_time_text").val('');
jQuery("#crc_anticipated_time_text").focus();
return false;
}
});
});
</script>
<div class="wrap">
<h2>Commission Rates Calculator Settings</h2>
<table class="form-table">
<tbody>
<form method="post" id="crc_form" >
<tr valign="top">
<th scope="row">Commission Rate</th>
<td>
<label for="crc_rate">Please enter a decimal such as 0.00075:</label><br /><br />
<input type="text" name="crc_rate" id="crc_rate_text" value="<?php echo $crc_rate;?>" />
</td>
</tr>
<tr valign="top">
<th scope="row">Anticipated Time</th>
<td>
<p>
<label for="crc_anticipated_time">Please enter a anticipated time such as 10:</label><br /><br />
<input type="text" name="crc_anticipated_time" id="crc_anticipated_time_text" value="<?php echo $crc_anticipated_time;?>" /> days
</p>
</td>
</tr>
<tr valign="top">
<td>
<p>
<input type="hidden" name="save_crc" value="1" />
<input type="submit" name="Submit" class="button-primary autowidth" value="Save" />
</p>
</td>
</tr>
</form>
</tbody>
</table>
</div>
<?php
}
function crc_enqueue_scripts(){
$crc_rate = get_option('crc_rate');
$crc_anticipated_time = get_option('crc_anticipated_time');
if(empty($crc_rate)){
$crc_rate = 0.00075;
}
if(empty($crc_anticipated_time)){
$crc_anticipated_time = 10;
}
wp_enqueue_style( 'crc-style', plugin_dir_url( __FILE__ ) . 'css/crc_style.css' );
wp_enqueue_style( 'crc-jquery-ui-css', plugin_dir_url( __FILE__ ) . 'css/ui-lightness/jquery-ui-datepicker.css' );
wp_enqueue_script( 'crc-jquery-ui', plugin_dir_url( __FILE__ ) . 'js/jquery-ui-datepicker.min.js', array( 'jquery' ) );
wp_enqueue_script( 'crc-script', plugin_dir_url( __FILE__ ) . 'crc_script.js', array( 'jquery' ) );
wp_localize_script('crc-script', 'crc_script_options', array('crc_rate' => $crc_rate, 'crc_anticipated_time' => $crc_anticipated_time));
}
function crc_show_calculator(){
do_action( 'crc_init' );
$mytime = time().rand();
$script = '<script type="text/javascript">';
$script .= file_get_contents(plugin_dir_path( __FILE__ ).'crc_script.js');
$script .= '</script>';
$html = file_get_contents(plugin_dir_path( __FILE__ ).'template.php');
$html=str_replace('[plugin_dir_url]',plugin_dir_url( __FILE__ ),$html);
$output = $script.$html;
$output = str_replace('crc_advance_date','crc_advance_date_'.$mytime,$output);
$output = str_replace('crc_closed_date','crc_closed_date_'.$mytime,$output);
$output = str_replace('crc_amount','crc_amount_'.$mytime,$output);
$output = str_replace('crc_pay','crc_pay_'.$mytime,$output);
$output = str_replace('crc_get_pay','crc_get_pay_'.$mytime,$output);
$output = str_replace('crc_datediff','crc_datediff_'.$mytime,$output);
return $output;
}
function populate_dropdown($form){
$have_crc = false;
if($form['fields']){
foreach($form['fields'] as $field){
if(substr_count('[commission_rates_calculator]',$field['content']) > 0){
$have_crc = true;
break;
}
}
if($have_crc){
$output = '<script type="text/javascript">';
foreach($form['fields'] as $field){
if($field['label'] == 'crc_advance_date'){
$output .= 'var crc__advance_date_gform_id = "input_'.$form['id'].'_'.$field['id'].'";'."\n";
}
if($field['label'] == 'crc_closed_date'){
$output .= 'var crc__closed_date_gform_id = "input_'.$form['id'].'_'.$field['id'].'";'."\n";
}
if($field['label'] == 'crc_amount'){
$output .= 'var crc__amount_gform_id = "input_'.$form['id'].'_'.$field['id'].'";'."\n";
}
if($field['label'] == 'crc_pay'){
$output .= 'var crc__pay_gform_id = "input_'.$form['id'].'_'.$field['id'].'";'."\n";
}
}
$output .= '</script>';
echo $output;
}
}
//print_r($form);
return $form;
}
}
$commission_rates_calculator = new Commission_Rates_Calculator();
?>