Install WordPress via WP-CLI

If you are a bash lover I wish you will find WP-CLI is the best approach to install WordPress for your project. WP-CLI provides a command-line interface for many actions you might perform in the WordPress admin where doing those same thing via WP-Admin will cost you some extra time.

To install WP-CLI on your machine depending on your Operating System there are some requirements, please check for that here https://wp-cli.org/

Here I am going to show how to move forward with Linux with PHP version 7.0.

Installing WP-CLI

Open you terminal with CTRL + ALT + T and execute below commands one by one. If things go right I hope you are ready to test the power of WP-CLI.

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
php wp-cli.phar --info
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp --info

How to Install a fresh WordPress instance

To install a fresh WordPress instance move into your work directory and create a directory with your project name. For example phpfarmer.com in my case. Then change directory into it and run below commands one by one.

In the meantime I will create a database with below info:
Database name: phpfarmer
Database Username: juyal
Database User Password: 123456$$!

Also I am expecting my newly installed WordPress admin credentials will be:
Username: phpfarmer
Password: 123farmer$$
Email: juyal@phpfarmer.com

# Download and Configure WordPress   
wp core download   
wp core config --dbhost=localhost --dbname=phpfarmer --dbuser=juyal --dbpass=123456$$!   

# Configure wp-config.php   
chmod 644 wp-config.php   
wp core install --url=yourwebsite.com --title="Your Blog Title" --admin_name=phpfarmer --admin_password=123farmer$$ --admin_email=juyal@phpfarmer.com   

# Enable File Uploading   
cd wp-content   
mkdir uploads   
chgrp web uploads/   
chmod 775 uploads/   

If everything went right then that’s all! Isn’t it easy and fast enough? Let’s see it in action just visit – http://localhost/phpfarmer.com

Try some action with WP-CLI

May be all of them you can do via WP-Admin but clicking, page loading, navigation will wast your time for them. So here you are going to skip them to speed up your development.

wp plugin list
wp plugin update akismet
wp theme list
wp theme update twentyfifteen

Thanks for reading!

This is how I make my Development Environment Ready!

Each Time I start with a fresh Linux Ubuntu distro I faced a lot of software installation and configuration is repeating because you know we software engineers are preferred to use only those applications which is we are used to.

That’s why to get my machine fully armed from a fresh start for web application development I wrote a gist to expedite the process.. If you are a Linux Ubuntu lover I wish you will find it useful – https://gist.github.com/tojibon/6a67e8fce63e65971be2374fef2e8cfd

```
sudo apt-get install -y build-essential
sudo apt-get install curl -y
sudo apt-get install libpng-dev libjpeg-dev -y
sudo apt-get install pngquant -y
sudo apt-get install git -y
sudo apt-get install openssh-server -y
sudo apt-get install unrar -y
# Fix local issue: https://askubuntu.com/questions/162391/how-do-i-fix-my-locale-issue

# installing VIM
sudo apt-get update
sudo apt-get install vim -y

# installing zsh
sudo apt-get update
sudo apt-get install git-core zsh
zsh --version
chsh -s $(which zsh) ============OR=========== chsh -s /bin/zsh
wget --no-check-certificate http://install.ohmyz.sh -O - | sh
vim .zshrc
alias ll='ls -l --color=auto'
alias la='ls -la --color=auto'
ZSH_THEME=amuse
reboot

# installing SDKMAN - http://sdkman.io/install.html
curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk version
sdk install java
sdk current java
sdk install maven
sdk current maven

# installing Docker   
sudo ls   
curl https://gist.githubusercontent.com/tojibon/fadd13d9b1cc5a42f38112911c43b4d6/raw/0f369720ac0109885ffbdc2fc4840b0e50389909/install_docker.sh | bash   
docker -v
docker-compose -v   
   
# installing LAMP7 - https://www.storagecraft.com/blog/install-lamp-server-linux-mint-18-command/
sudo apt-get update && sudo apt-get dist-upgrade -y
sudo reboot
sudo apt-get install lamp-server^ -y
xdg-open http://localhost
sudo nano /var/www/html/info.php
sudo service apache2 restart
sudo apt-get install phpmyadmin -y
sudo service apache2 restart
xdg-open http://localhost/phpmyadmin
sudo apt-get install php-intl

#installing Composer
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer
composer -V
sudo composer self-update

# installing Spring-STS - https://gist.github.com/tojibon/9e521a276cf93ac79650c8a3f68e03fe

# installing Intellij IDEA - https://www.jetbrains.com/idea/download/download-thanks.html?platform=linux
# https://www.jetbrains.com/help/idea/2017.1/installing-and-launching.html
cd Downloads/
sudo tar xf ideaIU-2017.1.3.tar.gz -C /opt/
cd /opt/idea-IU-171.4424.56/bin
./idea.sh
# https://confluence.jetbrains.com/display/IDEADEV/Inotify+Watches+Limit

#installing nodejs - https://nodejs.org/en/download/package-manager/
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs

# installing yarn - https://yarnpkg.com/en/docs/install
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn

# installing JHipster- https://jhipster.github.io/
sudo npm install --global gulp-cli 
sudo npm install -g bower
sudo npm install -g yo
sudo yarn global add generator-jhipster
 
# Generating SSH Key
ssh-keygen
cat .ssh/id_rsa.pub

sudo apt-get install php-curl
sudo apt-get install poedit

# Installing Zeal
sudo add-apt-repository ppa:zeal-developers/ppa
sudo apt-get update
sudo apt-get install zeal

# Installing WP Cli http://wp-cli.org/#installing   
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp --info

# Installing PlayOnLinux https://askubuntu.com/questions/770687/how-to-install-playonlinux-on-ubuntu-16-04   
sudo add-apt-repository ppa:noobslab/apps   
sudo apt-get update   
sudo apt-get install playonlinux

sudo apt install gnome-clocks -y
```

After installing all of these here are some software to be installed from Ubuntu software:

```
1. Kazam 
2. Kdenlive
3. Skype 
4. Shutter
```

Become AWS Certified Developer – Associate Level

As a software engineer I’ve been working on Web Application development career for around 10+ years, so it’s been above a decade!!

On this long career I’ve been working with AWS platform for a lot of applications and also currently managing a couple of AWS root / non-root admin account as a developer.

I was never concerned about any certification related to my career but recently I’ve found it’s really imported to get certified from some internationally popular vendors like AWS, Google, Zend etc. and In the meantime I’ve found one of my peer Shudarshon Chaki who is very keen on getting certified like Linux, AWS etc. I was inspired from him and started studying for AWS Associate Level Developer certification from may be Mar / Apr, 2018 and finally got the badge on Nov, 2018.

It’s first time I’ve received a proof of my work knowledge on any platform, the feeling is really awesome, this actually boosted up my confidence level. Now a days I am planning to start for other certifications like Solution Architect, Docker, Scrum etc certification and Expecting to own at least on within 2019.

How you can get prepared for AWS certification?

If you want to get it I will advice you to have your own AWS account mostly the trial one for one year, read Whitepapers and FAQ of AWS services. And also follow depend on some video courses provided by LinuxAcademy or A Cloud Guru. While study for certification don’t move forward fast instead try to learn the concepts, advantages, disadvantages and limitations of a feature.

Make some notes of your learning, after a few days of your study take a break for at least one week and then start again, by this way you will find yourself efficient and continuous learning without any break will make you get boring and demotivated 🙁

Also another thing, focus on the syllabus – the subjects / topics of your certification. AWS is a really huge platform, otherwise you will lost yourself! After atleast 3/4 months of study I will advice you to purchase the invoice for exam and finish it within a week!

That’s it for now, If you have any specific query you can put a comment here, I will try to reply you best. Thanks for reading.

Become a Amazing Contributors of TitanFramework!

I’ve been working with WordPress a most popular free and open-source content management system based on PHP & MySQL since 2008. As a senior software engineer I find one this CMS is the best to build simple dynamic websites for my freelance and official small to medium scale projects.

From the beginning I started creating WordPress theme from scratch or building child theme and plugin for it. But then I moved to https://themeforest.net/user/codereactor like marketplaces to sell my developed premium WordPress theme and plugins I’ve found this TitanFramework is the most suitable starter framework for WordPress.

After a couple of theme and plugins development I become a fan of this Framework only for it’s simplicity of developer friendly API. Though that time it was still growing and I planned to contribute a couple of features. The first contribution was about image gallery input API and add more and drop and drop sorting. Also added some other commits. Finally somehow the core team approved my pull requested!

And this is second time my contribution was approved on open source community via Github. The feeling of code contribution pull request accepted is really amazing and on top of that published your photo on any well known website related to your career is something top of everything!!!

If you are WordPress developer I will expect you to try TitanFramework I hope you will fall in love with this!

Thanks for reading.

Auto Fill Input Fields for Unique Page Sidebars

When you are developing a website with WordPress and support for Unique Page Sidebars WordPress Plugins then you may noticed when add a sidebar all the widget parameters inputs are empty. Something like the below image

default-inputs

Here with this code example you can auto fill the widget parameters.

Step 1: include a javascript for WordPress admin interface.

wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'admin-custom-js', get_template_directory_uri() . '/resources/js/custom-admin.js', array( 'jquery' ), '1.2', true );

Step 2: Write below codes on your custom-admin.js

/*
---------------------------------------------------------------------------------------
Auto fill input values for WordPress Unique Page Sidebars when creating a synamic sidebar with default values
---------------------------------------------------------------------------------------
*/

jQuery(document).ready( function($) {

    //Finding all inputs from unique page sidebars when creating a sidebar
    $("input[id^=ups_sidebars]").each( function( k, v ) {

        //Finding current input fields id
        id = $( this ).attr( 'id' );

        //Check if it has a default value already
        if ( $( this ).val() == '' ) {

            //Matching if it is the before_title field
            before_title = id.match(/\bbefore_title/);
            if ( before_title ) {
            $( this ).val( '<h3 class="widget-title">' );
            }

            //Matching if it is the after_title field
            after_title = id.match(/\bafter_title/);
            if ( after_title ) {
            $( this ).val( '</h3>' );
            }

            //Matching if it is the before_widget field
            before_widget = id.match(/\bbefore_widget/);
            if ( before_widget ) {
            $( this ).val( '<div id="%1$s" class="widget %2$s">' );
            }

            //Matching if it is the after_widget field
            after_widget = id.match(/\bafter_widget/);
            if ( after_widget ) {
            $( this ).val( '</div>' );
            }

        }

    });

});

That’s all if everything goes fine you will see a interface as the below image shown when adding a sidebar.
input-pre-values

Note: Don’t forget to widget parameters as your need on javascript what you are using when registering a sidebar for your theme.

Removing WordPress menu div tag and keeping ul [Code Snippet]

When you are working with WordPress menu then sometimes you may noticed if no menu is defined it is putting a div wrapper just above the url tag. Here is how you can remove that div and keep ul as it as.

wp_nav_menu( 
    array( 
        'theme_location'  => '', //Just keep this as empty
        'container'       => '', //Keep this one also as empty
        'menu_class'      => 'menu',
        'menu_id'         => 'primary-menu',
        'depth' => '2',
    )
);

Checking if a menu published in WordPress

$has_enabled_main_menu = false; 
$menu_location = 'primary'; //Going to check if this menu location (primary) has a menu as defined
$menu_locations = get_nav_menu_locations();
$menu_object = ( isset( $menu_locations[ $menu_location ] ) ? wp_get_nav_menu_object( $menu_locations[ $menu_location ] ) : null );
if( $menu_object ) {
    $has_enabled_main_menu = true;
}

Finding all parent pages in WodPress [Code Snippet]

Sometimes we needs to find all parent pages of current page in WordPress. It is useful to create a breadcrumb. Here is a example code snippet to find all parent pages.

<ul class="page-breadcrumbs">
    <li><a href="<?php echo home_url(); ?>"><?php _e( 'Home', 'mondira' ) ?></a></li>
    <?php
    global $post;
    $parent_id = $post->post_parent;
    $breadcrumbs = array();
    while ( $parent_id ) {
        $page = get_page( $parent_id );
        $breadcrumbs[] = '<li><a href="' . get_permalink( $page->ID ) . '">' . get_the_title( $page->ID ) . '</a></li>';
        $parent_id = $page->post_parent;
    }
    $breadcrumbs = array_reverse( $breadcrumbs );
    foreach ( $breadcrumbs as $crumb ) echo $crumb;
    ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title();?></a></li>
</ul>

WordPress sidebars fetching on other cms with wordpress xml rpc

Recently I worked on a site which is using wordpress as it’s cms and creloaded as it’s web shop. So the wordpress was top of the shopping cart and then the shopping cart as webshop. So basically I had to develop the site using wordpress and then had to install that creloaded inside woordpress installation.

For main site wordpress has it’s header (with navigation), footer (with navigation and other contents), sidebar with widgets etc. So when I am visiting the web shop with creloaded I was required to show the same layouts and design. For that I had to use wp xmlrpc to fetch those common features into creloaded system.

XML-RPC functionality is turned on by default since WordPress 3.5. So anyone can use it who is using wp 3.5 or greater without activating xml-rpc via wordpress admin!

All of this can be done with below written 3 steps.
1. Writing XML Client Class
2. Using XML Client
3. Defining XML Server methods in wp functions.php

Note: Here all the things are not well documented, Because I am assuming you are enough expert on wp and did some google and finally here to see a code example of wp xml rpc implementations.
Read More

z-index of dropdown menu vs iframe (youtube) video issue

When you are using iframe to display any video, for example if you are using youtube iframe video and on your site it has a dropdown menu and your dropdown memu is showing behind the iframe video you can make it top of iframe video with below written jquery code.

(function ($) {
    $ = jQuery;
    $(function () {
        $video = $("#parentocontainer> iframe");
        $srcVal = $video.attr('src');
        appendedVal = $srcVal + "?wmode=opaque";
        //or
        //appendedVal = $srcVal + "&wmode=opaque";
        $video.attr('src',appendedVal);
    });
 })(jQuery);