Daily Archives: April 1, 2013

PHP

How to Get Remote IP Address in PHP?

For That I create one Function as below.

   function getRemoteIPAddress() 
   {
       $remote_ip = $_SERVER['REMOTE_ADDR'];
       return $remote_ip;
   }

First I have create above code it will not work in case your client is behind proxy server. In that case use below function to get real IP address of client.

  function getRealIPAddress()
  {
    if (!empty($_SERVER['HTTP_CLIENT_IP']))   //checked ip from share internet
    {
        $remote_ip =$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
    {
        $remote_ip =$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
        $remote_ip =$_SERVER['REMOTE_ADDR'];
    }
    return $remote_ip;
 }
Advertisements

Let’s Create a Custom Post Type Using Plugin.

Step 1 : Create WordPress Plugin Directory in plugin Folder.
Open your WordPress Plugin directory and create a new directory called CUSTOM POST TYPE NAME.

Step 2 :Create PHP File in your created folder.
Open the directory and create a PHP file named CUSTOM POST TYPE NAME.php.

Step 3 : Add Header in CUSTOM POST TYPE NAME.php

<?php
/*
    Plugin Name: Movie Reviews
    Plugin URI: https://shahkeyul.wordpress.com/
    Description: This is Test Plugin for Create Custom Post Type you have 
                  to give your plugin description as per your demand.
    Version: 1.0
    Author: Expert Developer
    Author URI: https://shahkeyul.wordpress.com/
*/
?>

Step 4 : Open your CUSTOM POST TYPE NAME.php file write down below code.

function create_CUSTOM_FUNTION_NAME() {
    register_post_type( 'CUSTOM POST TYPE NAME',
        array(
            'labels' => array(
                'name' => 'CUSTOM POST TYPE NAME',
                'singular_name' => 'CUSTOM POST TYPE NAME',
                'add_new' => 'Add New',
                'add_new_item' => 'Add New CUSTOM POST TYPE NAME',
                'edit' => 'Edit',
                'edit_item' => 'Edit CUSTOM POST TYPE NAME',
                'new_item' => 'New CUSTOM POST TYPE NAME',
                'view' => 'View',
                'view_item' => 'View CUSTOM POST TYPE NAME',
                'search_items' => 'Search CUSTOM POST TYPE NAME',
                'not_found' => 'No CUSTOM POST TYPE NAME found',
                'not_found_in_trash' => 'No CUSTOM POST TYPE NAME found in Trash',
                'parent' => 'Parent CUSTOM POST TYPE NAME'
            ),
 
            'public' => true,
            'menu_position' => 15,
            'supports' => array( 'title', 'editor', 'comments', 'thumbnail', 'custom-fields' ),
            'taxonomies' => array( '' ),
            'menu_icon' => plugins_url( 'images/image.png', __FILE__ ),
            'has_archive' => true
        )
    );
}

NOTE: CUSTOM POST TYPE NAME Replace With your Custom Post type Name.

Step 5 :
Where

  • ‘public’ => true determines the visibility of the custom post type both in the admin panel and front end.
  • ‘menu_position’ => 15 determines the menu position of the custom post type.
  • ‘supports’ => array( ‘title’, ‘editor’, ‘comments’, ‘thumbnail’, ‘custom-fields’ ) determines the features of the custom post type which is to be displayed.
  • ‘taxonomies’ => array( ” ) creates custom taxonomies. Here it’s not defined.
  • ‘menu_icon’ => plugins_url( ‘images/image.png’, __FILE__ ) displays the admin menu icon.
  • ‘has_archive’ => true enables archiving of the custom post type.
  • Step 3 : Register Custom Function

     add_action( 'init', 'create_CUSTOM_FUNTION_NAME' );
    

    In Second parameter we have to pass our Custom function Name.

    Step 6 : Define your Icon For custom post type.
    save your images in plugin folder/images/YOUR IMG FILE NAME.

    Step 7 : Activate your Plugin.
    For That you have go in admin panel –> Plugins –> Activate your plugin.

    Step 8 : you can see the new custom post type at admin side. Now add the Custom Post .

    Word Press

    How do I create a custom post type Using Function.php?

    Step 1 : Open your function.php file write down below code.

    function create_CUSTOM_FUNTION_NAME() {
        register_post_type( 'CUSTOM POST TYPE NAME',
            array(
                'labels' => array(
                    'name' => 'CUSTOM POST TYPE NAME',
                    'singular_name' => 'CUSTOM POST TYPE NAME',
                    'add_new' => 'Add New',
                    'add_new_item' => 'Add New CUSTOM POST TYPE NAME',
                    'edit' => 'Edit',
                    'edit_item' => 'Edit CUSTOM POST TYPE NAME',
                    'new_item' => 'New CUSTOM POST TYPE NAME',
                    'view' => 'View',
                    'view_item' => 'View CUSTOM POST TYPE NAME',
                    'search_items' => 'Search CUSTOM POST TYPE NAME',
                    'not_found' => 'No CUSTOM POST TYPE NAME found',
                    'not_found_in_trash' => 'No CUSTOM POST TYPE NAME found in Trash',
                    'parent' => 'Parent CUSTOM POST TYPE NAME'
                ),
     
                'public' => true,
                'menu_position' => 15,
                'supports' => array( 'title', 'editor', 'comments', 'thumbnail', 'custom-fields' ),
                'taxonomies' => array( '' ),
                'menu_icon' => plugins_url( 'images/image.png', __FILE__ ),
                'has_archive' => true
            )
        );
    }
    

    NOTE: CUSTOM POST TYPE NAME Replace With your Custom Post type Name.

    Step 2 :
    Where

  • ‘public’ => true determines the visibility of the custom post type both in the admin panel and front end.
  • ‘menu_position’ => 15 determines the menu position of the custom post type.
  • ‘supports’ => array( ‘title’, ‘editor’, ‘comments’, ‘thumbnail’, ‘custom-fields’ ) determines the features of the custom post type which is to be displayed.
  • ‘taxonomies’ => array( ” ) creates custom taxonomies. Here it’s not defined.
  • ‘menu_icon’ => plugins_url( ‘images/image.png’, __FILE__ ) displays the admin menu icon.
  • ‘has_archive’ => true enables archiving of the custom post type.
  • Step 3 : Register Custom Function

     add_action( 'init', 'create_CUSTOM_FUNTION_NAME' );
    

    In Second parameter we have to pass our Custom function Name.
    Step 4 : you can see the new custom post type at admin side.