functions.php
<?php
register_post_type('contact', array('label' => 'contact','description' => '',
'public' => true, 'publicly_queryable' =>true, 'show_ui' => true,'show_in_menu' => true,'capability_type' => 'post',
'hierarchical' => true, 'rewrite' => array( 'slug' => 'contact', 'with_front' => false),'query_var' => true,'exclude_from_search' => false,
'has_archive' => true,'supports' => array('title','editor','thumbnail','author','comments'),'labels' => array (
'name' => 'List of Contacts',
'singular_name' => 'contact',
'menu_name' => 'Contacts',
//'add_new' => 'Add Users Conference',
//'add_new_item' => 'Add Users Conference',
'edit' => 'Edit Contacts',
'edit_item' => 'Edit Contacts',
'new_item' => 'New Contacts',
'view' => 'View Contacts',
'view_item' => 'View Contacts',
'search_items' => 'Search Contacts',
'not_found' => 'No Users Found',
'not_found_in_trash' => 'No Users Found in trash',
'parent' => 'Contacts',
),) );
/* Meta box for userconfrence*/
add_action("admin_init", "contact_enquerires_meta_box");
function contact_enquerires_meta_box(){
add_meta_box("contact-meta", "Contact Details", "contact_enquerires_meta_options", "contact", "normal", "high");
}
function contact_enquerires_meta_options(){
global $post;
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id;
$custom2 = get_post_custom($post->ID);
$cname = $custom2["contact_name"][0];
$cemail = $custom2["contact_email"][0];
$cphone = $custom2["contact_phone"][0];
$message = $custom2["contact_comments"][0];
?>
<div class="my_custom">
<style>
.register_formadmin div.field {
position:relative;
width:100%;
}
#userconfregadmin label{
display:block;
font-weight:bold;
width:140px;
margin-top:7px;
}
</style>
<div class="register_formadmin" id="userconfregadmin">
<table>
<tr>
<td>Name: </td>
<td><input type="text" name="cname" id="cname" value="<?php echo $cname; ?>"></td>
</tr>
<tr>
<td>Email: </td>
<td><input type="text" name="cemail" id="cemail" value="<?php echo $cemail; ?>"></td>
</tr>
<tr>
<td>Phone: </td>
<td><input type="text" name="cphone" id="cphone" value="<?php echo $cphone; ?>"></td>
</tr>
<tr>
<td>Message: </td>
<td><textarea name="message" id="message"><?php echo $message; ?></textarea></td>
</tr>
</table>
<input type="hidden" name="trash_metafield" id="trash_metafield" value="<?php echo wp_create_nonce(plugin_basename(__FILE__).$post->ID); ?>" />
</div>
<?php
}
add_action('save_post', 'save_contacts');
function save_contacts(){
global $post;
if (!wp_verify_nonce($_POST['trash_metafield'], plugin_basename(__FILE__).$post->ID)) {
return $post->ID;
}
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ){
return $post_id;
} else {
update_post_meta($post->ID, "contact_name", $_POST["cname"]);
update_post_meta($post->ID, "contact_email", $_POST["cemail"]);
update_post_meta($post->ID, "contact_phone", $_POST["cphone"]);
update_post_meta($post->ID, "contact_comments", $_POST["message"]);
}
}
add_filter( 'manage_edit-contact_columns', 'my_edit_contact_columns' ) ;
function my_edit_contact_columns( $columns ) {
$columns = array(
'title' => __( 'Email' ),
'ContactName' => __( 'Contact Name' ),
'Phone' => __( 'Phone' ),
'date' => __( 'Date' )
);
return $columns;
}
add_action( 'manage_contact_posts_custom_column', 'my_manage_contact_columns', 10, 1 );
function my_manage_contact_columns( $column, $post_id ) {
global $post;
switch( $column ) {
/* If displaying the 'duration' column. */
case 'ContactName' :
/* Get the post meta. */
$userstatus = get_post_meta($post->ID, 'contact_name', true );
/* If no duration is found, output a default message. */
echo ( ucwords($userstatus));
break;
case 'Phone' :
/* Get the post meta. */
$userstatus = get_post_meta($post->ID, 'contact_phone', true );
/* If no duration is found, output a default message. */
echo ( ucwords($userstatus));
break;
/* Just break out of the switch statement for everything else. */
default :
break;
}
}
/* add post price */
add_action( 'admin_menu', 'register_my_custom_menu_page' );
function register_my_custom_menu_page(){
//add_menu_page( 'custom menu title', 'Premium Posts Settings', '', 'premium_post', 'my_custom_premium_post_menu_page', get_template_directory_uri().'/images/admint_settings.png');
add_submenu_page( 'options-general.php', 'My Settings', 'My Settings', 'manage_options', 'premium_post', 'my_custom_premium_post_menu_page');
}
function my_custom_premium_post_menu_page(){
include TEMPLATEPATH .'/price-settings.php';
}
/* end post price */
?>
page-contact.php:
<?php
/**
* The template for displaying all pages
*
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages
* and that other 'pages' on your WordPress site will use a
* different template.
*
* @package WordPress
* @subpackage Twenty_Twelve
* @since Twenty Twelve 1.0
*/
get_header();
if(isset($_POST['submit'])){
$cname=$_POST['cname'];
$cemail=$_POST['cemail'];
$cphone=$_POST['cphone'];
$message=$_POST['message'];
$post_title = $cemail;
global $wpdb;
/* Checking email exists or not */
$query = $wpdb->prepare(
"SELECT ID FROM $wpdb->posts
WHERE post_title = '$post_title'
AND post_type = 'contact'
AND post_status='Publish'"
);
$wpdb->query( $query );
if ( $wpdb->num_rows ) {
} else{
/*inserting values in to database */
$post_information = array(
'post_title' => $post_title,
'post_type' => 'contact',
'post_status' => 'Publish'
);
$post_id = wp_insert_post( $post_information, $wp_error );
update_post_meta($post_id,'contact_name',$cname);
update_post_meta($post_id,'contact_email',$cemail);
update_post_meta($post_id,'contact_phone',$cphone);
update_post_meta($post_id,'contact_comments',$message);
echo'<script> window.location="http://www.google.com";</script>';
}
}
?>
<script src="<?php echo get_template_directory_uri()?>/js/jquery.min.js"></script>
<script src="<?php echo get_template_directory_uri()?>/js/jquery.validate.js"></script>
<script type='text/javascript'>
var $$_ = jQuery;
$$_(document).ready(function(){
var regxalpha = /^[A-Za-z .-0"']+$/;
var regxalphacaptch = /^[A-Za-z]+$/;
var regxalpha1 = /^[A-Za-z _.-123456789"'@&-/]+$/;
var regnum=/^[-0123456789"'-/]+$/;
var regemail = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
$$_.validator.addMethod("vendornamevalidate", function(value, element) {
var cname = jQuery('#cname').val();
if (regxalpha.test(cname)) {
return cname;
}
}, 'Invalid Name');
$$_.validator.addMethod("emailvalidate", function(value, element) {
var cemail = jQuery('#cemail').val();
if (regemail.test(cemail)) {
return cemail;
}
}, 'Invalid Email');
$$_.validator.addMethod("vendorphone", function(value, element) {
var cphone = jQuery('#cphone').val();
if (regnum.test(cphone)) {
return cphone;
}
}, 'Invalid Phone');
$$_('#contact_form').validate({// initialize the plugin
rules: {
cname: {
required: true,
vendornamevalidate: true
},
cemail: {
required: true,
email: true,
emailvalidate: true
},
cphone: {
required: true,
number: true,
vendorphone: true
},
},
messages: {
cname: {
required: "Please specify a First Name"
},
cemail: {
required: "Please specify your Email",
email: "Invalid Email",
},
cphone: {
required: "Please specify your Phone",
number: "Enter numbers only",
},
}
});
});
</script>
<div id="primary" class="site-content">
<div id="content" role="main">
<form name="contacts" id="contact_form" action="" method="post">
<table>
<tr>
<td>Name: </td>
<td><input type="text" name="cname" id="cname"></td>
</tr>
<tr>
<td>Email: </td>
<td><input type="text" name="cemail" id="cemail"></td>
</tr>
<tr>
<td>Phone: </td>
<td><input type="text" name="cphone" id="cphone"></td>
</tr>
<tr>
<td>Message: </td>
<td><textarea name="message" id="message"></textarea></td>
</tr>
<tr>
<td clospan="2"><input type="submit" value="Submit" name="submit" id="submit"></td>
</tr>
</table>
</form>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
page-contact-list.php
<?php
/**
* The template for displaying all pages
*
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages
* and that other 'pages' on your WordPress site will use a
* different template.
*
* @package WordPress
* @subpackage Twenty_Twelve
* @since Twenty Twelve 1.0
*/
get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$pr=array(
'post_type'=>'contact',
'posts_per_page' => 3,
'paged' => $paged,
'post_status'=>'publish'
);
$obj=new WP_Query($pr);
if($obj ->have_posts() )
{
?>
<table style="width:500px;" cellpadding="1" cellspacing="1">
<tr>
<td>Name</td>
<td>Email</td>
<td>Phone</td>
<tr>
<?php
while($obj ->have_posts())
{
$obj->the_post();
$post_id=$post->ID;
$page_data =get_page($id);
$title = $page_data->post_title;
//$desc=$page_data->post_content;
$name=get_post_meta($post_id,'contact_name')[0];
$phone=get_post_meta($post_id,'contact_phone')[0];
?>
<tr>
<td><?php echo $name?></td>
<td><?php echo $title?></td>
<td><?php echo $phone?></td>
<tr>
<?php
}
?>
</table>
<?php
}
?>
<!-- pagination -->
<?php next_posts_link(); ?>
<?php previous_posts_link(); ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Price-settings.php
<?php
global $wpdb, $PasswordHash, $current_user, $user_ID;
$registeration_cost = get_option( 'registeration_cost', 'default_value' );
$guest_cost = get_option( 'guest_cost', 'default_value' );
$paypal_emailid = get_option( 'paypal_emailid', 'default_value' );
if($_POST['submit']){
$registeration_cost = trim($_POST['registeration_cost']);
$paypal_emailid = trim($_POST['paypal_emailid']);
$guest_cost = trim($_POST['guest_cost']);
update_option( 'registeration_cost', $registeration_cost);
update_option( 'guest_cost', $guest_cost);
update_option( 'paypal_emailid', $paypal_emailid);
}
?>
<style>
div.field {
float:left;
position:relative;
width:100%;
}
label{
display:block;
font-weight:bold;
text-align:right;
width:140px;
margin-top:7px;
float:left;
}
.settings_submit {
padding-left: 142px;
}
</style>
<section class="main_cont">
<!-- middle block starts here-->
<section class="mid_block">
<script src="<?php echo get_template_directory_uri(); ?>/js/jquery.validate.js"></script>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<div class="entry-content">
<div id="container">
<div id="content">
<p>
<?php
if($error)
echo $error;
if($success)
echo $success;
?>
</p>
<?php //the_title(); ?>
<div id="user-registration" class="main">
<div id="pwdReset" class="registrationArea">
<form name="postsettings" class="regForm" id="postsettings" method="post">
<dl>
<div class="divider">
<div class="content">
<div class="field">
<label>Registration Fee <span>*</span>
</label>
<input type="text" name="registeration_cost" id="registeration_cost" value="<?php echo $registeration_cost; ?>" class="text-input" size="20" required="required">
(USD)
</div>
<div class="field">
<label>Guest Fee <span>*</span>
</label>
<input type="text" name="guest_cost" id="guest_cost" value="<?php echo $guest_cost; ?>" class="text-input" size="20" required="required">
(USD)
</div>
<div class="field">
<label>Paypal Emailid<span>*</span>
</label>
<input type="text" name="paypal_emailid" id="paypal_emailid" value="<?php echo $paypal_emailid; ?>" class="text-input" size="20" required="required">
</p>
</div>
<div class="settings_submit"><input type="submit" name="submit" id="pass_submit" value="UDATE" class="button button-primary button-large"></div>
<table style="margin-left:153px">
<tr>
<td>
</td>
</tr>
</table>
</div>
<div class="clear"></div>
</div>
</dl>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- .entry-content -->
</div>
<!-- #content -->
</div>
<!-- #primary -->
</section>
<!-- middle block ends here-->
</section>
<?php //} ?>