'', 1 => __( 'Form saved.', 'iwacontact' ), 2 => __( 'Custom field saved.', 'iwacontact' ), 3 => __( 'Custom field deleted.', 'iwacontact' ), 4 => __( 'Form saved.', 'iwacontact' ), 5 => false, 6 => __( 'Form saved.', 'iwacontact' ), 7 => __( 'Form saved.', 'iwacontact' ), 8 => __( 'Form saved.', 'iwacontact' ), 9 => __( 'Form saved.', 'iwacontact' ), 10 => __( 'Form saved.', 'iwacontact' ) ); return $messages; } /** * Echo the content for the submission email body metabox * * @since 2.0.0 **/ function iwacontact_submission_email_body() { global $ajaxcontact; $fields = get_post_custom(); echo nl2br( $fields['_email_body'][0] ); } /** * Echo the content for the anti-spam metabox * * @since 2.0.0 **/ function iwacontact_antispam_box() { global $ajaxcontact; $fields = get_post_custom(); $use_captcha_default = 'yes' == $ajaxcontact->get( 'use_captcha' ) ? true : false; $use_captcha = ( key_exists( '_use_captcha', $fields ) ) ? $fields['_use_captcha'][0] == '1' : $use_captcha_default; $captcha_type = ( key_exists( '_captcha_type', $fields ) ) ? $fields['_captcha_type'][0] : $ajaxcontact->get( 'captcha_type' ); $use_captcha_checked = ( $use_captcha ) ? 'checked="checked"' : ''; $captcha_type_disabled = ( !$use_captcha ) ? 'disabled="disabled"' : ''; echo '

' . " " . '' . '

'; echo '

' . '' . "' . '

'; } /** * Echo the content for the email editor metabox * * @since 2.0.0 **/ function iwacontact_email_box() { global $ajaxcontact; $fields = get_post_custom(); $custom_email = key_exists( '_use_custom_body', $fields ) && $fields['_use_custom_body'][0] == '1'; $custom_email_body = ( key_exists( '_custom_body', $fields ) ) ? $fields['_custom_body'][0] : ''; $checked = ( $custom_email ) ? 'checked="checked"' : ''; echo '

' . __( 'You can specify a custom body for email notifications sent using this form.', 'iwacontact' ) . '

'; echo '

' . " " . '' . '

'; ?>

Field ID in double percentage symbols. E.g. to include the submitted value for a field with a Field ID of "your_name" you would use %%your_name%%', 'iwacontact' ); ?>

get( 'default_to' ); $iwacf_subject = ( key_exists( 'iwacontact_subject', $fields ) ) ? $fields['iwacontact_subject'][0] : $ajaxcontact->get( 'default_subject' ); $iwacf_from = ( key_exists( 'iwacontact_from', $fields ) ) ? $fields['iwacontact_from'][0] : $ajaxcontact->get( 'default_from' ); $iwacf_submit_value = ( key_exists( 'iwacontact_submit_value', $fields ) ) ? $fields['iwacontact_submit_value'][0] : $ajaxcontact->get( 'default_submit_value' ); $iwacf_redirect = ( key_exists( 'iwacontact_redirect', $fields ) ) ? $fields['iwacontact_redirect'][0] : $ajaxcontact->get( 'default_redirect' ); ?>

'iwacontactsubmission', 'post_status' => 'publish', 'meta_key' => '_form_id', 'meta_value' => $post->ID, 'limit' => 5 ) ); if ( count( $submissions ) < 1 ) { echo '

' . '' . __( 'No submissions have been made using this form yet.', 'iwacontact' ) . '' . '

'; return; } echo ''; } /** * Echo the content for the edit form metabox * * @since 1.0.0 **/ function iwacontact_box() { global $ajaxcontact; $fields = get_post_custom(); if ( key_exists( '_iwacontact_data', $fields ) ) $fields['iwacontact_data'] = $fields['_iwacontact_data']; $iwacontact_data = ( key_exists( 'iwacontact_data', $fields ) ) ? $fields['iwacontact_data'][0] : ''; ?>
' . '

' . __( 'Form Fields', 'iwacontact' ) . '' . '

'; if ( preg_match( '/\;\;/', $iwacontact_data ) ) { $form_fields = preg_split( '/\;\;/', $iwacontact_data ); $ordered_fields = array(); foreach ( $form_fields as $field ) { $field_attrs = preg_split( '/\:\:/', $field ); array_push( $ordered_fields, $field_attrs ); } usort( $ordered_fields, "iwacontact_sort_fields" ); $count = 0; $form_fields_html = ''; $field_display_html = ''; foreach ( $ordered_fields as $field ) { $new_field_attrs = array( 'fieldid' => $field[0], 'displayorder' => $field[1], 'fieldtype' => $field[2], 'fieldname' => $field[3], 'fieldoptions' => $field[4], 'fieldrequired' => $field[5], 'fieldvalidation' => $field[6] ); if ( key_exists( 7, $field ) ) $new_field_attrs = array_merge( $new_field_attrs, array( 'fieldlabel' => $field[7] ) ); $form_fields_html .= iwacontact_get_new_contact_field( $count, $new_field_attrs ); $field_display_html .= iwacontact_get_new_contact_display( $count, $new_field_attrs ); $count++; } echo '' . '
' . $form_fields_html; } else { echo '' . '' . iwacontact_get_new_contact_field( '0', array( 'displayorder' => 1 ) ); } ?>

// // < ? php // } /** * Echo the content for the submission details metabox * * @since 2.0.0 */ function iwacontact_submission_details() { global $ajaxcontact, $post; $fields = get_post_custom(); if ( key_exists( 'markas', $_GET ) && 'unread' == $_GET['markas'] ) update_post_meta( $post->ID, '_read_before', '0' ); else update_post_meta( $post->ID, '_read_before', '1' ); $form_data = unserialize( unserialize( $fields['_form_data'][0] ) ); $form = get_post( $fields['_form_id'][0] ); $form_edit_url = admin_url( 'post.php?post=' . $form->ID . '&action=edit' ); $form_title = $form->post_title; ?>
ID ); ?> at ID ); ?>
( | )
'; foreach ( $form_data as $field ) { $fname = $field['fieldname']; $fval = ( $field['fieldtype'] != 'textarea' ) ? $field['submittedvalue'] : nl2br( $field['submittedvalue'] ); print "" . "$fname" . "$fval" . ""; } print ''; } /** * Remove contact submission publish metabox * * @since 2.0.0 */ function remove_iwacontact_submission_publish() { remove_meta_box( 'submitdiv', 'iwacontactsubmission', 'side' ); } /** * Hide contact form publishing actions * * @since 2.0.0 */ function hide_iwacontact_form_publishing_actions() { global $post; if ( 'iwacontactform' == $post->post_type ) { echo ' '; } } /** * Save the iwacontact meta box data on save_post action * * @param integer $post_id The post ID * @since 1.0.0 **/ function iwacontact_save_meta( $post_id ) { if ( !key_exists( 'iwajax_contact', $_POST ) ) return $post_id; if ( !wp_verify_nonce( $_POST['iwajax_contact'], plugin_basename(__FILE__) ) ) return $post_id; if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id; if ( 'page' == $_POST['post_type'] ) { if ( !current_user_can( 'edit_page', $post_id ) ) return $post_id; } $form_fields = array(); // Form fields associative array $field_names = array(); // Field names array foreach ( $_POST as $key => $value ) { if ( preg_match( '/^iwacf\_[a-z]+\_[0-9]+$/', $key ) ) { $attrs = preg_split( '/\_/', $key ); $field_no = $attrs[2]; if ( $attrs[1] == 'fieldname' ) array_push( $field_names, $value ); $array_item = array( $attrs[1] => $value ); if ( !key_exists( $field_no, $form_fields ) || !is_array( $form_fields[$field_no] ) ) $form_fields[$field_no] = array(); $form_fields[$field_no] = array_merge( $form_fields[$field_no], $array_item ); } } $iwacontact_data = array(); $iwacontact_data_str = ''; $count = 0; foreach ( $form_fields as $field ) { $count++; $safe_field_name = iwacontact_get_field_id( $field['fieldname'] ); $displayorder = ( key_exists( 'displayorder', $field ) ) ? $field['displayorder'] : $count; $fieldoptions = ( key_exists( 'fieldoptions', $field ) ) ? $field['fieldoptions'] : ''; $fieldrequired = ( key_exists( 'fieldrequired', $field ) ) ? $field['fieldrequired'] : ''; $field_data = array( $safe_field_name, $displayorder, $field['fieldtype'], $field['fieldname'], $fieldoptions, $fieldrequired, $field['fieldvalidation'], $field['fieldlabel'] ); $field = join( '::', $field_data ); array_push( $iwacontact_data, $field ); } $iwacontact_data_str = join( ';;', $iwacontact_data ); update_post_meta( $post_id, 'iwacontact_data', $iwacontact_data_str ); update_post_meta( $post_id, 'iwacontact_sendto', trim( $_POST['iwacf_sendto'] ) ); update_post_meta( $post_id, 'iwacontact_subject', trim( $_POST['iwacf_subject'] ) ); update_post_meta( $post_id, 'iwacontact_from', trim( $_POST['iwacf_from'] ) ); update_post_meta( $post_id, 'iwacontact_submit_value', trim( $_POST['iwacf_submit_value'] ) ); update_post_meta( $post_id, 'iwacontact_redirect', trim( $_POST['iwacf_redirect'] ) ); update_post_meta( $post_id, '_use_custom_body', ( key_exists( 'iwacf_use_custom_body', $_POST ) && '1' == $_POST['iwacf_use_custom_body'] ) ? '1' : '' ); update_post_meta( $post_id, '_custom_body', trim( $_POST['iwacf_custom_body'] ) ); update_post_meta( $post_id, '_use_captcha', ( key_exists( 'iwacf_use_captcha', $_POST ) && '1' == $_POST['iwacf_use_captcha'] ) ? '1' : '' ); update_post_meta( $post_id, '_captcha_type', trim( $_POST['iwacf_captcha_type'] ) ); } /** * Return a new field in the admin edit contact form box * * @param integer $sequence The sequential number for this contact field * @param array $data The data to pre-populate this field with (if any) * @since 1.0.0 **/ function iwacontact_get_new_contact_display( $sequence, $data = array() ) { $fieldname = ( key_exists( 'fieldname', $data ) ) ? $data['fieldname'] : __( 'New Field', 'iwacontact' ); $fieldtype = ( key_exists( 'fieldtype', $data ) ) ? $data['fieldtype'] : 'input'; $required = ( key_exists( 'fieldrequired', $data ) && '1' == $data['fieldrequired'] ) ? 'required' : ''; return "
  • " . "$fieldname" . '' . __( 'Required', 'iwacontact' ) . '' . '
  • '; } /** * Return a new *hidden* field editor dialog in the admin edit contact form box * * @param integer $sequence The sequential number for this contact field * @param array $data The data to pre-populate this field with (if any) * @since 1.0.0 **/ function iwacontact_get_new_contact_field( $sequence, $data = array() ) { global $iwacontactv; $fieldname = ( key_exists( 'fieldname', $data ) ) ? $data['fieldname'] : __( 'New Field', 'iwacontact' ); $fieldid = ( key_exists( 'fieldid', $data ) ) ? $data['fieldid'] : 'new_field'; $fieldtype = ( key_exists( 'fieldtype', $data ) ) ? $data['fieldtype'] : 'input'; $fieldoptions = ( key_exists( 'fieldoptions', $data ) ) ? $data['fieldoptions'] : ''; $displayorder = ( key_exists( 'displayorder', $data ) ) ? $data['displayorder'] : ''; $fieldrequired = ( key_exists( 'fieldrequired', $data ) ) ? $data['fieldrequired'] : ''; $fieldvalidation = ( key_exists( 'fieldvalidation', $data ) ) ? $data['fieldvalidation'] : 'none'; $fieldlabel = ( key_exists( 'fieldlabel', $data ) ) ? $data['fieldlabel'] : '1'; $default_label_label = __( 'Default Value ', 'iwacontact' ); switch ( $field_type ) { case 'input': //break; case 'password': //break; case 'textarea': //break; case 'hidden': //break; case 'readonly': $default_label_label = __( 'Default Value ', 'iwacontact' ); break; case 'radio': //break; case 'selectbox': //break; case 'multiselect': $default_label_label = __( 'Options (1 per line) ', 'iwacontact' ); break; case 'checkbox': //break; case 'sendcopy': //break; case 'h1': //break; case 'h2': //break; case 'h3': //break; case 'h4': default: $default_label_label = __( 'Default Value ', 'iwacontact' ); break; } return "
    " . '

    ' . __( 'Field Editor', 'iwacontact' ) . '

    ' . '

    ' . "" . "" . '

    ' . '

    ' . "" . "" . '

    ' . '

    ' . "" . "' . '

    ' . '

    ' . "" . "" . '

    ' . '

    ' . "" . "" . '

    ' . '

    ' . "" . "' . '

    ' . '

    ' . "' . "" . '

    ' . '

    ' . "' . "" . '

    ' . '

    ' . "" // . '' . '

    ' . '
    '; } /** * Return field type select options * * @param string $selected_option The selected option * @return string Select options html * @since 2.0.0 */ function iwacontact_fieldtype_options( $selected_option ) { global $iwacontactv; $field_type_groups = array( __( 'Normal Fields', 'iwacontact' ) => array( 'input' => array( __( 'Text Input', 'iwacontact' ), true ), 'password' => array( __( 'Text Input (Password)', 'iwacontact' ), true ), 'textarea' => array( __( 'Text Input (Multi-Line)', 'iwacontact' ), true ), 'readonly' => array( __( 'Text Input (Read-Only)', 'iwacontact' ), true ), 'selectbox' => array( __( 'Select Box', 'iwacontact' ), true ), 'multiselect' => array( __( 'Select Box (Multiple)', 'iwacontact' ), true ), 'checkbox' => array( __( 'Check Box', 'iwacontact' ), true ), 'radio' => array( __( 'Radio Buttons', 'iwacontact' ), true ), 'hidden' => array( __( 'Hidden Field', 'iwacontact' ), true ), 'file' => array( __( 'File Upload', 'iwacontact' ), false ) ), // 'Special Fields' => array( // 'firstname' => array( __( 'First Name', 'iwacontact' ), false ), // 'lastname' => array( __( 'Last Name', 'iwacontact' ), false ), // 'fullname' => array( __( 'Full Name', 'iwacontact' ), false ), // 'emailaddr' => array( __( 'Email Address', 'iwacontact' ), false ), // 'sendcopy' => array( __( 'Send Copy Checkbox', 'iwacontact' ), false ) // ), __( 'Headings', 'iwacontact' ) => array( 'h1' => array( __( 'Heading 1', 'iwacontact' ), true ), 'h2' => array( __( 'Heading 2', 'iwacontact' ), true ), 'h3' => array( __( 'Heading 3', 'iwacontact' ), true ), 'h4' => array( __( 'Heading 4', 'iwacontact' ), true ) ) ); $result = ''; foreach ( $field_type_groups as $group_name => $fields ) { $result .= ""; foreach ( $fields as $option => $attrs ) { $selected = ( $option == $selected_option ) ? 'selected="selected"' : ''; $disabled = ( !$attrs[1] ) ? 'disabled="disabled"' : ''; $result .= ''; } $result .= ''; } return $result; } /** * Add Settings link to plugins page * * @since 2.0.0 */ function iwacontact_add_settings_link( $links, $file ) { static $this_plugin; if ( !$this_plugin ) $this_plugin = dirname( plugin_basename(__FILE__) ) . '/ajax-contact.php'; if ( $file == $this_plugin ) { $settings_link = 'Settings'; array_unshift( $links, $settings_link ); } return $links; } /** * Add contact form edit post columns * * @param array $columns The columns * @return array The new columns * @since 1.6.0 */ function iwacontact_columns( $columns ) { $columns['submissions'] = __( 'Submissions', 'iwacontact' ); $columns['fields'] = __( 'Fields', 'iwacontact' ); $columns['shortcode'] = __( 'Short code', 'iwacontact' ); return $columns; } /** * Echo the values for our contact form edit post columns * * @param string $column The column to echo output for * @since 1.6.0 */ function iwacontact_custom_columns( $column ) { global $post; switch ( $column ) { case 'shortcode': echo '[insert_ajaxcontact id=' . $post->ID . ']'; break; case 'fields': echo iwacontact_get_field_count( $post->ID ); break; case 'submissions': echo iwacontact_get_submission_count( $post->ID ); break; } } /** * Filter for contact form and submission edit post row actions * * @param array $actions The post row actions * @return array The new actions * @since 2.0.0 */ function iwacontact_row_actions( $actions ) { global $post; if ( in_array( get_post_type(), array( 'iwacontactform', 'iwacontactsubmission' ) ) ) { unset( $actions['view'] ); unset( $actions['inline hide-if-no-js'] ); } if ( 'iwacontactform' == get_post_type() ) { $submissions_text = sprintf( __( 'View Submissions (%1$d)', 'iwacontact' ), iwacontact_get_submission_count( $post->ID ) ); $actions['submissions'] = '' . $submissions_text . ''; } return $actions; } /** * Add form_id filter parameter to form submissions list * * @param object $query The WP_Query object * @since 2.0.0 */ function iwacontact_admin_posts_filter( $query ) { global $pagenow; if ( is_admin() && 'edit.php' == $pagenow && key_exists( 'form_id', $_GET ) && '' != trim( $_GET['form_id'] ) ) { $query->query_vars['meta_key'] = '_form_id'; $query->query_vars['meta_value'] = $_GET['form_id']; } } /** * Add submissions link to contact form admin menu item * * @since 2.0.0 */ function iwacontact_admin_menu() { add_submenu_page( 'edit.php?post_type=iwacontactform', __( 'Submissions', 'iwacontact' ), __( 'Submissions', 'iwacontact' ), 'manage_options', 'edit.php?post_type=iwacontactsubmission' ); }