Pages

Wednesday, January 6, 2016

How to block or prevent spam registrations/spam bots on phpmotion web site?


I have done lots of research and tried many possible ways. Finally I found a solution like to use google recaptcha on the website. To do this we need to follow below steps.

1. Register in Google for captcha using the link https://www.google.com/recaptcha/admin#list.
2. After register you will get site key and secrete key.

Sunday, April 12, 2015

Wordpress custom pages creation?

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&nbsp;<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&nbsp;<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 //} ?>

Tuesday, January 27, 2015

Why User login stopped working or not working properly using active directory integration? and how to solve?

Sometimes user login won't work properly or stop working because of configurations issue. To solve this.. 1. Login at admin side. 2. Goto active directory integration settings. 3. Uncheck the "Use TLS" and save the settings. 4. Clear the cache and try to login.

Tuesday, August 26, 2014

How to disable hyper links in comments section of Wordpress?

To disable hyper links in comment section of Wordpress need to follow below two steps.

1. Open functions.php in the theme which you are using.
2. Place the below code in functions.php and save it.

add_filter('comment_text', 'wp_filter_nohtml_kses');
add_filter('comment_text_rss', 'wp_filter_nohtml_kses');
add_filter('comment_excerpt', 'wp_filter_nohtml_kses');

Monday, July 7, 2014

How to add a Custom Widget in Wordpress?

To add a custom widget just create a plugin by following below steps.

1. Create a folder in plugins folder.
2. Add a php file with folder name(Suppose if folder name is abc the file in folder should abc.php).
3. Add below code in that file.

<?php
/*
Plugin Name: Widget Plugin Name
Plugin URI: Author Link
Description: A simple plugin that adds a calendar of events at rights side
Version: 1.0
Author: Author Name
Author URI: Author Link
License: GPL2
*/
class wp_my_plugin extends WP_Widget {

// constructor
    function wp_my_plugin() {
        parent::WP_Widget(false, $name = __('My Widget', 'wp_widget_plugin') );
    }
    // widget form creation
function form($instance) {

// Check values
if( $instance) {
     $title = esc_attr($instance['title']);
 } else {
     $title = '';
  }
?>

<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Widget Title', 'wp_widget_plugin'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
</p>


 <?php
}

// update widget
function update($new_instance, $old_instance) {
      $instance = $old_instance;
      // Fields
      $instance['title'] = strip_tags($new_instance['title']);
      $instance['text'] = strip_tags($new_instance['text']);
      $instance['textarea'] = strip_tags($new_instance['textarea']);
     return $instance;
}
// display widget
function widget($args, $instance) {
   extract( $args );
   // these are the widget options
   $title = apply_filters('widget_title', $instance['title']);
   $text = $instance['text'];
   $textarea = $instance['textarea'];
   echo $before_widget;
   // Display the widget
   echo '<div class="widget-text wp_widget_plugin_box">';

   // Check if title is set
   if ( $title ) {
      echo $before_title . $title . $after_title;
   }

//add functionality you want add here..
   echo '</div>';
   echo $after_widget;
}
}

// register widget
add_action('widgets_init', create_function('', 'return register_widget("wp_my_plugin");'));
?>

Wednesday, May 14, 2014

How to solve the permalinks issue of /index.php/%postname% but not with just %postname% in IIS?

When we deploy the wordpress in ISS servers or Amazon windows servers .htaccess won't work untill we install httpd.conf and enable the htaccess there. Because of this we will get the issue of url with index.php/%postname% .

To solve this issue go to web.config file in IIS add below code in between of <rewrite><.rewrite>.

<rules>
<rule name="WordPress Rule" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?page_id={R:0}" />
</rule>
</rules>




Tuesday, April 22, 2014

How to Solve White Screen Death problem in wordpress?

To solve the issue we need to first find out where is the problem. For this add the below code in wp-config.php file.

error_reporting(E_ALL);
ini_set('display_errors', 1);

By this you will easily find where is the code error and do the necessary changes and problem maximum get resolves.