Tuesday, November 8, 2016

Create a Linux VM on Azure using the Portal

In this section we are going to see how to “Create a Linux VM on Azure using the Portal”.  We assume that you have an Azure Portal with a valid subscription. Follow the following steps to quickly create a “Linux Virtual Machine”.



  • Login into your Azure Portal with your portal credentials.
  • After logging you will be redirected to “Dashboard” of the Portal.
  • In the upper left corner you will find an option “New”.
  • Click on the “New” option.


  • After clicking on New you will find many options.
  • Click on the “Virtual Machines” Option.
  • Select “Ubuntu Server” from the Featured Apps and Select “Resource Manager”  as deployment model.

  • Click on the “Create” button.
  • On the Page will be displayed next Enter the following things.
  • A name for your “Virtual Machine”.
  • Admin Username
  • Set the Authentication type to “SSH
  • Select Existing “Resource Name” or add new.
  • After Entering all the required data click on the “Ok” button to continue.

  • The next step will be to “Select a Size”.
  • There will be multiple sizes displayed on the screen.
  • You can have a look the “Recommended” sizes by Azure.
  • Select the “DS1” Size from the Options as it will Install “ubuntu” on Premium SSD.
  • You can select other options also.
  • Please see below screenshot for more details.


  • The next option after this is the “Settings”.
  • There is no need to change or set any “Setting”.
  • It is recommend to leave the “Settings” as it is.
  • Just click “Ok” and the summary of the settings will be visible for review.
  • If all things are fine the “Confirm” the “Settings” by clicking on the “Ok” button.
  • Now the next step is to get the “Public” IP of the VM that we have just created.
  • Go to “Dashboard” of your portal.
  • Click on the “Network Interfaces” option.
  • In the “Network Interfaces” you will see the name of the VM that you just created.
  • Click on the VM and you see the Public IP Address.
  • Copy the Public IP Address. (Suppose your Public IP is 11.12.11.12)
  • Now SSH into the public IP using your SSH public key using the following command.
  • ssh -i ~/.ssh/azure_id_rsa ubuntu@11.12.11.12

That's all and your Linux VM is ready for use!

Magento 2 Contact Page With Google Map

In Magento 2 contact page is present and it can be enabled from the Admin section from the configuration options. The contact page shows a form and captcha. By default map is not available on the contact page in Magento 2.

In many cases users need to also show the shop address on the contact page with the help of an Google map. For this purpose this extension can be used.

Important Features of the Extension are as follows:

(1) Extension is very easy to install
(2) Text area option to enter any address in Admin
(3) Option to manage map height.
(4) Option to upload custom images for marker .
(5) Option to customize the page layout.
(6) Text field Option to enter latitude and longitude for the map marker.
(7) User can easily enable and disable this module.

This extension can be downloaded from the Magento Marketplace.

Please refer the following URL:  https://marketplace.magento.com/clarion-contact.html

WordPress WePay Woocommerce addon

Woocommerce is used to convert a wordpress website into an shopping cart. Whenever a shopping cart website is built payment gateways are also needed to accept and process the payment online.

There are many payment gateways like paypal, authorize.net, stripe etc. Similarly WePay is also an payment and to integrate the payment system with WordPress Woocommerce this plugin is made.

This plugin is for WooCommerce to implement a payment gateway for accepting and processing Credit Cards Payments By merchants via the WePay Payment Gateway

You can download and install this plugin at WordPress plugin repository

URL: https://wordpress.org/plugins/woo-payment-addon/

WordPress Shortcodes In Widgets

In WordPress user can display output of a plugin or functionality on a page, template or post by using shortcode. shortcode can be pasted in an page or post or can be written in template with some programming knowledge.

In the widgets which are displayed in the sidebar cannot display shortcode output. But sometime we need to display shortcode output in sidebar with the help of the widget. In such scenario this plugin can be used.

Features of the plugin are as follows:

  • Option to add shortcode in an widget and output will be displayed in frontend of the website.

You can download and install this plugin at WordPress plugin repository

URL: https://wordpress.org/plugins/shortcodes-in-widgets/

WordPress Redirect After Comment To Custom Page

Every blog has a feature that uses to express their views regarding an article. That feature is no other than but the commenting system. Using the commenting system the users/visitors of the website can start a discussion regarding an article.

Sometimes in many scenarios it is needed to redirect the user to a different page after commenting to an article. For this purpose this plugin can be used.

Features of the plugin are as follows:

  • Redirect user to custom page after comment.
  • Option to set custom Page URL from the plugin settings screen in the Admin section.
  • URL can be set of an post, page or any other external URL.

You can download and install this plugin at WordPress plugin repository

URL: https://wordpress.org/plugins/wp-comment-redirect/

WordPress OutBoundLinks

In many cases we need the links of external website which are present in the content should open in new tab as the original website is not lost. Every time is not possible to add a target blank attribute to the external link while adding the content in the blog post.

Also it helps with the SEO of the website. This plugin automatically adds the target blank attribute to external links present in the content.

Features of the plugin are as follows:

  • It Works with all WordPress posts.
  • It Opens all external links of a post in a new tab.
  • It adds a query string parameter "?rel=outbound" to an hyper-link.
  • The Links which refer within the site are excluded.

You can download and install this plugin at WordPress plugin repository

URL: https://wordpress.org/plugins/outboundlinks/

WordPress Interactive SVG Map

This WordPress Plugin is based on Github JQV MAP.

URL: https://github.com/manifestinteractive/jqvmap

Many times we need map in SVG format as Google map does not fit for every requirement. We can have more control on SVG map than Google map. using this plugin you can create map with options as you wish.

You just need to place a shortcode for the plugin on any post or page and the map is loaded on that particular page or post.

Features of the plugin are as follows:

  • Map is displayed in SVG format. 
  • Options to configure Map from the admin section.
  • Options to customize the map output on front-end.
  • The following Maps are available supported by the plugin.
    •   World Map
    •   USA
    •   Europe
    •   Germany
    •   Africa
    •   Asia
    •   Australia
    •   Argentina
    •   Algeria
    •   Brazil
    •   Canada
    •   France
    •   Greece
    •   Iran
    •   Iraq
    •   North America
    •   Russia
    •   South America
    •   Tunisia
    •   Turkey
You can download and install this plugin at WordPress plugin repository

URL: https://wordpress.org/plugins/interactive-svg-map/

WordPress Hide Administrator Bar

This plugin allows the administrator of the website to hide the administrator bar on the front-end. This can be done for all users including administrator himself.

Features of the plugin are as follows:

  • Plugin Option to Hide Admin Bar for all Users in Frontend.
  • Plugin Option to Hide Admin Bar for Non Admin users in Frontend.
  • Plugin Option to Hide Admin Bar for Admin users in Frontend.
  • Plugin option settings to configure to which user will the administrator bar will be visible.

You can download and install this plugin at WordPress plugin repository

URL: https://wordpress.org/plugins/hide-administrator-bar/

WordPress Forbidden Author Words

When managing a multi-author blog there are users who have the rights to post blog post content on the website. Not every time it is possible to check the entire content. So, to avoid misuse of some offensive words or words which may not be quite right for your website can be restricted using this plugin.

Features of the plugin are as follows:

  • Add words in the plugin option that are to be restricted.
  • User can set the option to restrict the word in post title, content or both.
  • user can set the option to display the "Restricted words" as a notice in the entire Admin section and it can be activated or deactivated from Admin.

You can download and install this plugin at WordPress plugin repository

URL: https://wordpress.org/plugins/forbidden-author-words/

WordPress Empty Categories In Widgets

WordPress had a options to show categories list with post count as a widget in sidebar. But empty categories are excluded and only categories which have at-least one post assigned are shown.

Some times we need to show empty categories also in the sidebar. For this we can use this plugin.

Features of the plugin are as follows:

  • Shows Empty Categories In Sidebar as a Widget.


You can download and install this plugin at WordPress plugin repository

URL: https://wordpress.org/plugins/empty-categories-in-widgets/

WordPress Disable Plugin Deactivation

This plugin provides options to disable plugin deactivation, activation, deletion, and update. Many times when working on a project we need to create multiple accounts with administrator rights.

So in many of the cases other users with administrator rights can mess with the plugin settings by activating, deactivating, updating, deleting plugins. To avoid such a mess and scenario this plugin can be used.

Features of the plugin are as follows:

  • Disable plugin activation from the plugin screen in the Admin section.
  • Disable plugin deactivation from the plugin screen in the Admin section.
  • Disable plugin update option from the plugin screen in the Admin section.
  • Disable plugin delete option from the plugin screen in the Admin section.
  • Disable plugin edit link from the plugin screen in the Admin section.


You can download and install this plugin at WordPress plugin repository

URL: https://wordpress.org/plugins/disable-plugin-deactivation/

WordPress Disable Lost Password Email

Many times in WordPress spam users tries to reset password by clicking on the "forget password" link which sends a email to the email address of the user with the reset link. Doing it many times sends multiple emails and may blacklist the domain as spam email domain by the hosting companies and email service providers.

To avoid this many times we need to disable any email sending. To achieve this we can use this plugin. This plugin disables forgot password email for all the users including administrator of the website.

Features of the plugin are as follows:

  • It Disables lost email functionality for all users including the administrator.


You can download and install this plugin at WordPress plugin repository

URL: https://wordpress.org/plugins/disable-lost-password-email/

WordPress Bulk Edit Post Titles

Sometimes we need to edit multiple post titles at same time to give same titles. This feature is not provided by WordPress till now. To overcome this drawback there you can use this plugin which add this functionality.

Features of this plugin:

  • Bulk edit post titles at once.
  • User can select any number of posts.
  • This plugin can work with single as well as multiple post titles.


You can download this plugin at https://wordpress.org/plugins/bulk-edit-post-titles/

WordPress BuddyPress Registration Widget

Want to add BuddyPress Registration Widget in sidebar? You can use this plugin.

Using this plugin you can "Display BuddyPress Registration form as a Widget".

This plugin provides BuddyPress registration form as a widget.

Features of this plugin are as follows:

  • BuddyPress registration form as a widget in sidebar.
  • Disable BuddyPress cover image for all users.
  • Make Profile image mandatory excluding super Admin.


You can download this plugin at https://wordpress.org/plugins/buddy-registration-widget/

WordPress Automatically Empty Trash

This plugin can be used to Automatically Empty Trash after the n number of days the user wishes.

Using this plugin the user can set the number of days from which the trash should be automatically deleted in the plugin option from the Admin plugin section.

Features of the plugin are as follows:

  • Option to set number of days after which the trash should be automatically emptied.


This Plugin can be downloaded at  https://wordpress.org/plugins/automatically-empty-trash/

Tuesday, September 27, 2016

Delete all tables from database using command line

We can drop all tables of a database using an GUI Interface like PHPMYADMIN. But sometimes in some scenarios we do not have access to the GUI Interface like PHPMYADMIN but only tool like command line or command prompt.

In Such scenarios we can drop all the tables of a specific database using the command line. Following are the statements which can be used on the command line to drop all the database tables from the database with ease.

SET FOREIGN_KEY_CHECKS = 0; 

SET @tables = NULL;
SELECT GROUP_CONCAT(table_schema, '.', table_name) INTO @tables
  FROM information_schema.tables 
  WHERE table_schema = 'database_name'; -- specify DB name here.

SET @tables = CONCAT('DROP TABLE ', @tables);
PREPARE stmt FROM @tables;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET FOREIGN_KEY_CHECKS = 1;

That's it all tables from the database will be deleted.

Saturday, May 21, 2016

WordPress get recent posts

In WordPress we can get recently added posts.

To get recently added posts in WordPress user the following function.

<?php
$args = array( 'numberposts' => 6, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");
$posts_list = get_posts( $args );
echo '<ul>';
foreach ($posts_list as $post) :  setup_postdata($post); ?>
<li><strong><?php the_date(); ?></strong><br />
<a href="<?php the_permalink(); ?>" title="<?php the_title();?>"> <?php the_title(); ?></a>
</li>
        <?php endforeach; ?>
       </ul>

 The above code can be used anywhere in the website and in any template.

WordPress get current timezone

In WordPress timezone is already set during installation. To get the current timezone in WordPress use the following piece of code.

You can get 2 things.

 a) If you want to get the offset use the following code.

<?php echo get_option('gmt_offset'); ?>

 b) If you want to get timezone in string format use the following code.

<?php echo get_option('timezone_string'); ?>


WordPress get form post data

WordPress supports forms and there are many extension for forms available on the WordPress plugin repository. When form is submitted it is processed and submitted as defined in the plugin.

But sometimes we need the form data and for that we cannot customize the plugin as hacking the core of plugin is bad idea and an plugin update in the future will erase all our changes done.

So, to get the posted form data you can use the following code.

<?php
    foreach($_POST as $key=>$post_data){
        echo "You posted:" . $key . " = " . $post_data . "<br>";
    }
?>

using this you can get the form key and its value.

WordPress get first image from post

To display the first image from the post content use the following function given.

First open your active theme's functions.php file in a code editor. After opening the file in the code editor add the following function at the end of the file.

<?php
function get_first_image() {
 global $post, $posts;
 $first_img = '';
 ob_start();
 ob_end_clean();
 $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
 $first_img = $matches [1] [0];

 if(empty($first_img)){ //Defines a default image
$first_img = "/images/default.jpg";
 }
 return $first_img;
}
?>

Save the file and upload it back to the server.

The function can be called in the loop or anywhere to display the first image from the post.

<?php echo catch_that_image() ?>


WordPress get parent categories

WordPress supports Categories. A Post can be assigned to single or multiple categories in WordPress. Also categories can be single level or multi level (nested). To get only parent categories and exclude the child categories the following code can be used.

<?php
$args = array(
 'orderby' => 'name',
 'parent' => 0
);

$categories = get_categories($args);
?>

$categories contains all the parent level categories only.

WordPress get featured image by post id

In WordPress there is featured image for Post and Pages and Custom Post types.

To get the feature image of an post or page or custom post type use the following code.

<?php if (has_post_thumbnail( $post->ID ) ):
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
 endif;
?>

Now in $image you have all the feature image information. To display the image you can do it as follows:

<img src="<?php echo $image[0]; ?>" />

And you are done. Now feature image will be displayed.

WordPress get blog name

Wordpress is a blogging CMS. But now WordPress is used for many other purpose like shopping cart, gallery sites, portfolio site etc.

This all have been possible with the available plugins and themes and WordPress support community.

If you want to get the WordPress site name then you can get it in the following way.

<?php echo get_bloginfo( 'name' ); ?>

Using the above line any where in the file will give you the WordPress site/blog name.

WordPress get ajax full url

In Wordpress we can get the full Ajax url as follows:

In PHP we can get it in the following way.

<?php echo admin_url('admin-ajax.php'); ?>

If you want to use it in Javascript then you can use it in following way.

<script type="text/javascript">
    var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>";
</script>


WordPress get user data

In WordPress there are many users with different roles. A user may have a administrator role, author or any other roles from the standard roles defined by WordPress.

If you want to find out user role or user information such as name,ID etc you can use the following function.

<?php
 $user_info = get_userdata(1);
          echo 'Username: ' . $user_info->user_login . "\n";
          echo 'User roles: ' . implode(', ', $user_info->roles) . "\n";
          echo 'User ID: ' . $user_info->ID . "\n";
?>

The above will give you user's username, role and ID.

WordPress get admin email address

In WordPress there is a administrator who manages pages, posts and every content of the site.

He can also manage and provide roles to other users. If you want to the get the email address of the site administrator you can use the following function.

<?php
$admin_email = bloginfo('admin_email');
?>

$admin_email will give you the email address of the site administrator.

WordPress get active menu item

In WordPress menu are dynamically managed. User can set Primary Header and footer menu from admin section.

If you want to get the current Menu item name you can get it by using the following function.

Open your active theme's functions.php and add the following function at the bottom of the file.

<?php
function Get_menu_item_name( $loc ) {
global $post;
$locs = get_nav_menu_locations();
$menu = wp_get_nav_menu_object( $locs[$loc] );

if($menu) {
$items = wp_get_nav_menu_items($menu->term_id);

foreach ($items as $k => $v) {          
if ($items[$k]->object_id == $post->ID) {
$name = $items[$k]->title;
break;
}
}
}
return $name;
}
?>

The usage of the function is as follows:

<?php
$current_menu_name = Get_menu_item_name( 'primary' ); // here you enter another alias if your menu is not primary
echo $current_menu_name;
?>

$current_menu_name will contain the value of the current menu name.

WordPress get active plugin url

In WordPress to get the active plugin URL we can use the following code.

<?php $plugin_url = plugin_dir_url( $file ); ?>

$plugin_url will give you the current active plugin URL.

WordPress get current plugin directory path

While working with plugins sometimes we need the plugin directory path. WordPress provides a way to get the plugin current directory path.

use the following code which gives the plugin current directory path.

<?php $plugin_dir_path = dirname(__FILE__); ?>

$plugin_dir_path will give you the current plugin directory path.

WordPress get active theme directory

To get the full directory path of the active theme use the following piece of code.

<?php echo get_template_directory(); ?>

If you are using a child theme then it will return the path of the Parent theme only. To get the child theme directory path use the following code.

<?php echo get_stylesheet_directory(); ?>

This will give you the path of the child theme.

WordPress get active theme name

In Wordpress there can be multiple themes installed. But only one theme at a time can be active. If you want to get the name of the active theme in WordPress you can get it.

To get the active theme name use the following code is useful.

<?php
$active_theme_name = wp_get_theme();
?>

$active_theme_name will give you the active theme name.

WordPress get uploaded image path

To get the full path of an attachment use the following method.

<?php $path = get_attached_file( $attachment_id ); ?>


The above will give you full path of the file/attachment.

If you just want the filename and not path then use the following code.

<?php $filename_only = basename( get_attached_file( $attachment_id ) ); ?>

This will give you just the filename.

WordPress get Author info from post ID

If you want to get the Author information such as name, profile image and name from post ID then it can be retrieved in the following way.

<?php $author_id=$post->post_author; ?>

Now suppose you want to get the Author Avatar. The avatar is fetched in the following way.

<img src="<?php echo the_author_meta( 'avatar' , $author_id ); ?> " width="140" height="140" class="avatar" alt="<?php echo the_author_meta( 'display_name' , $author_id ); ?>" />

This will display the author avatar.

To display the author name use the following code.

<?php echo the_author_meta( 'user_nicename' , $author_id ); ?>


This will display the author name.

WordPress get current page number in Pagination

WordPress Supports pagination and has default functions which can be used to display pagination. For Example: In Blog page pagination is displayed by default. But sometimes you needs to add pagination to a custom template. In Some scenarios we needs to get the current page number in the pagination.

Current page number in Pagination can be retrived in the following way.

<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
?>


Here $paged will contain the page number.

WordPress get current page url

To get the current active page URL in WordPress use the following function.

<?php
$current_page_url = add_query_arg( $wp->query_string, '', home_url( $wp->request ) );
?>


Now you can use $current_page_url any where you like as it contains the current page URL of the active page.

WordPress get current category id

To the the Category ID on Current active page in WordPress use the following code.

<?php
$categories = get_the_category();
$category_id = $categories[0]->cat_ID;
echo category_id;
?>


Your Category ID will be present in category_id.

Total Post Count in WordPress

To Display total post count on any page in WordPress the following code will be helpful.

<?php
$total_posts = wp_count_posts();
echo number_format($total_posts->publish);
?>


This will display total posts in WordPress in number format.

Monday, May 16, 2016

Wordpress get current logged in user information

In WordPress we can get the logged in user information such as firstname, lastname, displayname and ID in the following way.

<?php
$current_logged_user = wp_get_current_user();
?>


Now you have all the user information in the $current_logged_user variable. You can access the information in the following way.

<?php
echo 'Username: ' . $current_logged_user->user_login . '<br />';
    echo 'User email: ' . $current_logged_user->user_email . '<br />';
    echo 'User first name: ' . $current_logged_user->user_firstname . '<br />';
    echo 'User last name: ' . $current_logged_user->user_lastname . '<br />';
    echo 'User display name: ' . $current_logged_user->display_name . '<br />';
    echo 'User ID: ' . $current_logged_user->ID . '<br />';
?>

Get Logged In user ID in WordPress

To get the currently logged in user ID in WordPress use the following code.

<?php
$current_user_id = get_current_user_id();

echo $current_user_id;
?>


$current_user_id will give you the ID of the currently logged in user.

Redirect to custom page after comment in WordPress

In WordPress when a user comments on an Article, post or page he is redirected to the same page after commenting.

But in some scenarios it is required that user should be redirected to some other URL after commenting. This can be done with a simple piece of code.

Open your active theme's functions.php file and add the following line at the end of the line.

function wp_comment_redirect_url($location) {    
        return "http://www.yourdomain.com";
    }

add_filter('comment_post_redirect', 'wp_comment_redirect_url');


Now user will be redirected to the URL to have set.

Disable Profile and Group Cover Image in BuddyPress

In BuddyPress most of the times Group and Profile cover images are not required. We can disable Profile and Group Cover images in the following way.

Open your theme's function.php and at the end of the file before ?> add the following 2 lines.

add_filter( 'bp_is_profile_cover_image_active', '__return_false' );
add_filter( 'bp_is_groups_cover_image_active', '__return_false' );


After adding the above two lines, save the file and upload the file back to the server.

Now, Profile and Group Cover image will be disabled and will not be visible in the front-end.

Update Wordpress without FTP

Sometimes when WordPress site is updated ftp details are asked while updating. We can surpass the FTP authentication and directly update WordPress, Plugins and Themes to latest version.
To do so open your wp-config.php file (file is present on the root of wordpress installation).

After opening the file in an editor find the following line

require_once(ABSPATH . 'wp-settings.php');


After you find the above line in the wp-config.php file place the following line below it.

define('FS_METHOD','direct');


So, your final file should look like below.

require_once(ABSPATH . 'wp-settings.php');
define('FS_METHOD','direct');


After this save you wp-config.php file and upload back to server. Now WordPress, Plugins, Themes can be updated to their latest version without the need to enter FTP details.

Disable lost password email in WordPress

In WordPress users can recover their passwords through the lost password feature available. But some times this options is used by users to spam your website by using the functionality which may result your domain to be blacklisted in Google or your hosting provider may suspend your domain for mass emailing.

 To Avoid this recover password functionality can be disabled. You add the following lines in your function.php file to stop any email from sending from your website.

  function wp_password_change_notification() 
   { 
      return false; 
   }

add_filter('allow_password_reset', 'wp_password_change_notification');

This will disable lost password email in WordPress

MS SQL : How to identify fragmentation in your indexes?

Almost all of us know what fragmentation in SQL indexes are and how it can affect the performance. For those who are new Index fragmentation...