Monday, 9 January 2017

How to Create Custom Registration Plugin?

Plugin Download Now


/*
Plugin Name: My Plugin
Plugin URI: https://developer.wordpress.org/
Description: A brief description of my plugin
Version: 1.0
Author: Ankit Shah
Author URI: http://itnewcode.blogspot.in/
License: GPLv2
*/

/*** Plugin Activation Code ***/
function aks_activate_plugin(){
                /* Create Table */
                global $wpdb;
                $charset_collate = $wpdb->get_charset_collate();
                $table_name = $wpdb->prefix . 'new_register_test';

                $sql = "CREATE TABLE $table_name (
                                id mediumint(9) NOT NULL AUTO_INCREMENT,
                                name varchar(30) NOT NULL,
                                email varchar(30) NOT NULL,
                                gender varchar(6) NOT NULL,
                                regtime datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
                                views smallint(5) NOT NULL,
                                clicks smallint(5) NOT NULL,
                                UNIQUE KEY id (id)
                ) $charset_collate;";

                require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
                dbDelta( $sql );
}
register_activation_hook( __FILE__, 'aks_activate_plugin' );


/*** Add wordpress Menu ***/
add_action('admin_menu', 'aks_reg_menu_page');
function aks_reg_menu_page() {
                /*
                add_menu_page() function arguments:
                                1. Page title – used in the title tag of the page (shown in the browser bar) when it is displayed.
                                2. Menu title – used in the menu on the left.
                                3. Capability – the user level allowed to access the page.
                                4. Menu slug – the slug used for the page in the URL.
                                5. Function – the name of the function you will be using to output the content of the page.
                                6. Icon – A url to an image or a Dashicons string.
                                7. Position – The position of your item within the whole menu.
                */
                add_menu_page('Register Plugin Settings', 'Register Settings', 'administrator', __FILE__, 'aks_reg_form' , plugins_url('/images/icon.png', __FILE__) );
}

function aks_reg_form(){
                $empty_error = $success_msg = " ";
                if(isset($_POST['aks-register'])){
                               
                                if(empty($_POST['aks_name_field']) || empty($_POST['aks_email_field']) || empty($_POST['aks_gender_field'])){
                                                $empty_error = "Please fill all fields";
                                }
                                else
                                {
                                                $aks_name_field=$_POST['aks_name_field'];
                                                $aks_email_field=$_POST['aks_email_field'];
                                                $aks_gender_field=$_POST['aks_gender_field'];
                                               
                                                /* Insert Query */
                                                global $wpdb;
                                                $charset_collate = $wpdb->get_charset_collate();
                                                $table_name = $wpdb->prefix . 'new_register_test';
                                               
                                                $insertsql="INSERT INTO `$table_name`(`id`, `name`, `email`, `gender`) VALUES (' ', '$aks_name_field', '$aks_email_field', '$aks_gender_field')";

                                                require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
                                                dbDelta( $insertsql );
                                                                $success_msg="Succesfully Registed";                                 
                                }
                }
               
                ?>
               

Register here,


Name
Email
Gender Male Female
  

/*** Plugin Uninstall Code ***/
function aks_uninstall_plugin(){
                /* Delete Query */
                global $wpdb;
                $charset_collate = $wpdb->get_charset_collate();
                $table_name = $wpdb->prefix . 'new_register_test';

                $deletesql = "DROP TABLE IF EXISTS '$table_name';";

                require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
                dbDelta( $deletesql );   
}

register_uninstall_hook(__FILE__, 'aks_uninstall_plugin');

?>


For more Interesting, Useful Article & codes visit IT New Code.

Wednesday, 28 December 2016

How To Display Author Bio in WordPress

After login in WordPress login panel.


Add Social Media Profile Box To User Profile:-
Copy the below into your "functions.php" file to add input boxes for the user social media profiles.

/*=====================================================================    * Add Author Links
 * ====================================================================*/
function add_to_author_profile( $contactmethods ) {

$contactmethods['rss_url'] = 'RSS URL';
$contactmethods['google_profile'] = 'Google Profile URL';
$contactmethods['twitter_profile'] = 'Twitter Profile URL';
$contactmethods['facebook_profile'] = 'Facebook Profile URL';
$contactmethods['linkedin_profile'] = 'Linkedin Profile URL';

return $contactmethods;
}
add_filter( 'user_contactmethods', 'add_to_author_profile', 10, 1);

Then Go to Users -> Your Profile & manage information.


View Author Bio:-
Copy & paste Following code where you want so see.






Written by



Website:

    $rss_url = get_the_author_meta( 'rss_url' );
    if ( $rss_url && $rss_url != '' ) {
    echo '
  • ';
    }

    $google_profile = get_the_author_meta( 'google_profile' );
    if ( $google_profile && $google_profile != '' ) {
    echo '
  • ';
    }

    $twitter_profile = get_the_author_meta( 'twitter_profile' );
    if ( $twitter_profile && $twitter_profile != '' ) {
    echo ' ';
    }

    $facebook_profile = get_the_author_meta( 'facebook_profile' );
    if ( $facebook_profile && $facebook_profile != '' ) {
    echo ' ';
    }

    $linkedin_profile = get_the_author_meta( 'linkedin_profile' );
    if ( $linkedin_profile && $linkedin_profile != '' ) {
    echo '
  • ';
    }
    ?>




    Contact form 7 Email body HTML Structure code

    Style 1:-



    Enquiry from Website






    Name:
    [your-name]


    Email:
    [your-email]



    Contact No:
    [tel-no]



    Message:
    [your-message]







    This email sent from "#".



    BbPress links shortcode in WordPress

    Below given shortcode for
    Profile  => [BUDDYUSER-PROFILE text='Edit Profile']
    Friends  => [BUDDYUSER-FRIENDS text='My Friends']
    Activity => [BUDDYUSER-ACTIVITY text='My Activity']
    Add following code in your theme "functions.php" file.


    /** bbpress profile link shortdode "[BUDDYUSER-PROFILE text='Edit Profile']" **/
    add_shortcode( 'BUDDYUSER-PROFILE', 'cuser_profile_shortocode_handler' );
    function cuser_profile_shortocode_handler( $atts ){
    $atts = shortcode_atts( array(
    'text' => 'my profile',
    ), $atts );

    if( !is_user_logged_in() )
    return '';

    $link = home_url( '/members/' . bp_core_get_username( get_current_user_id() ) . '/profile/' );
    return "" . $atts['text'] . "";
    }


    /** bbpress friends link shortdode "[BUDDYUSER-FRIENDS text='My Friends']" **/
    add_shortcode( 'BUDDYUSER-FRIENDS', 'cuser_friends_shortocode_handler' );
    function cuser_friends_shortocode_handler( $atts_friends ){
    $atts_friends = shortcode_atts( array(
    'text' => 'my friends',
    ), $atts_friends );

    if( !is_user_logged_in() )
    return '';

    $link = home_url( '/members/' . bp_core_get_username( get_current_user_id() ) . '/friends/' );
    return "" . $atts_friends['text'] . "";
    }


    /** bbpress activity link shortdode "[BUDDYUSER-ACTIVITY text='My Activity']" **/
    add_shortcode( 'BUDDYUSER-ACTIVITY', 'cuser_activity_shortocode_handler' );
    function cuser_activity_shortocode_handler( $atts_activity ){
    $atts_activity = shortcode_atts( array(
    'text' => 'my activity',
    ), $atts_activity );

    if( !is_user_logged_in() )
    return '';

    $link = home_url( '/members/' . bp_core_get_username( get_current_user_id() ) . '/' );
    return "" . $atts_activity['text'] . "";
    }

    Any defined user role redirect to homepage after login in Wordpress

    Paste this function into your themes "functions.php" to redirect every specific user role from the admin back to your homepage:

    add_action('admin_init', function() {
       
        $wp_user = wp_get_current_user();
       
        if(isset($wp_user->caps['subscriber']) && $wp_user->caps['subscriber']){
            wp_redirect(get_site_url());
            exit;
        }
       
    });


    Here, "subscriber" is user role slug change this as your user role.
    it can be author, contributor, editor,

    Create custom user roles in WordPress

    Methode 1:-

    Add following code in "functions.php" file


    // Add a custom user role

    $result = add_role( 'client', __('Client' ),
    array(
    'read' => true, // true allows this capability
    'edit_posts' => true, // Allows user to edit their own posts
    'edit_pages' => true, // Allows user to edit pages
    'edit_others_posts' => true, // Allows user to edit others posts not just their own
    'create_posts' => true, // Allows user to create new posts
    'manage_categories' => true, // Allows user to manage post categories
    'publish_posts' => true, // Allows the user to publish, otherwise posts stays in draft mode
    'edit_themes' => false, // false denies this capability. User can’t edit your theme
    'install_plugins' => false, // User cant add new plugins
    'update_plugin' => false, // User can’t update any plugins
    'update_core' => false // user cant perform core updates
    )
    );


    Methode 2:-

    Install "User Role Editor" plugin from "https://wordpress.org/plugins/user-role-editor/"

     

    Copyright @ 2016 IT New Code | Developing Code | Designing Code.

    Designed by: Ankit Shah