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/"

    Create an admin user by using database in WordPress

    1. To begin, log into your cPanel interface.

    2. From the main cPanel screen, find the Databases category and click on the icon entitled phpMyAdmin.

    3. Once the first screen appears, look to the left hand sidebar and click on the database for your specific WordPress installation. If you do not know which database is the correct one, you can find out by using these instructions.

    4. After the database information loads, you will need to find the tab named SQL and click on it.

    5. This leads you to an SQL editor where you will enter some code that will create a new admin account for you. Below is the code to create a new admin account named "newadmin" with the password "pass123". You may change any of the content in red to fit your needs, but leave all other data as is.


    INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`)
    VALUES ('newadmin', MD5('pass123'), 'firstname lastname', 'email@example.com', '0');

    INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
    VALUES (NULL, (Select max(id) FROM wp_users), 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');

    INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
    VALUES (NULL, (Select max(id) FROM wp_users), 'wp_user_level', '10');


    6. After replacing any data fields you need, click the Go button to perform the insertion.

    7. This should simply refresh the screen and you should see the messsage '1 row affected' after each of the three SQL statements. This means the insertion ran smoothly. From here, visit your wordpress admin login area as normal and use the new admin login information. You should get to the admin interface without issue.

    IF template name is this then do this in WordPress

    Just add following code where you need.


    if ( is_page_template('template_file_name.php') ) {
        // Returns true when 'template_file_name.php' is being used.
    } else {
        // Returns false when 'template_file_name.php' is not being used.
    }
    ?>

    Notice Undefined offset error Solution in WordPress

    Method 1:-

    Please deactivate the wp debug mode. Open up wp-config.php and replace:
    define( 'WP_DEBUG', true );
    with
    define( 'WP_DEBUG', false );



    Method 2:-

    Put following code in "functions.php" file.

    error_reporting(0);
    @ini_set(‘display_errors’, 0);

     

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

    Designed by: Ankit Shah