Fix Magento 2 – php cli error on cpanel or other hostings

On cPanel servers, the php command you get over SSH isn’t always the command-line version of PHP. Magento 2’s bin/magento refuses to run under anything else, so every Magento command fails before it starts. The fix is to point php at the right binary for your user. The problem: On a fresh install of Magento 2 on cPanel-based hosting, you receive the following error while running any command over SSH: ...

September 10, 2018 · 3 min · Harshvardhan Malpani

WordPress Hierarchy – Important Files and Directories

When you move a WordPress site, fix a broken one or work on it over FTP or a file manager, it helps to know which files, folders and database tables matter. This is my short map of the ones I look at most often. Files wp-config.php file contains all information about your database connection and some salts which are used for password generation. It holds the database name, user, password and host, and the table prefix ($table_prefix). Strictly speaking, the keys and salts are used to secure login cookies and nonces rather than to hash the passwords themselves, which is why changing them logs every user out. Never share this file, and keep a copy when you move the site. index.php handles all the requests on your WordPress blog. It’s a tiny file that loads WordPress, which then works out which post or page was asked for. On Apache, the permalink rules in .htaccess send every address that isn’t a real file or folder to it. yourblog.com/wp-login.php or yourblog.com/wp-admin/ can be used for logging into the WordPress backend. Folders wp-content/themes contains all the themes installed in your blog. wp-content/plugins contains all the plugins installed in your blog. wp-content/uploads contains all your file uploads, including all the images in the media library. They are usually organised in folders by year and month, like 2018/08, 2018/09 and so on. That’s controlled by the “Organize my uploads into month- and year-based folders” option under Settings > Media. Together with the database, wp-content is what makes your site yours. The wp-admin and wp-includes folders are WordPress core and are replaced on every update, so never edit anything in them. ...

September 8, 2018 · 3 min · Harshvardhan Malpani

How to add colon separated hours in PHP using explode function twice?

Problem Statement Tracked hours for multiple days are available in HH:MM:SS format, separated by tabs. Add all the times to show the total hours worked/tracked. This is the format you get when you copy a row of time values out of a spreadsheet or a time-tracking report: the cells are pasted as one line with a tab between them. The values can’t be added as ordinary numbers, because 60 seconds make a minute and 60 minutes make an hour. The script below splits the string twice with explode(), first into days and then each day into hours, minutes and seconds, adds each part up separately and carries the overflow at the end. ...

September 6, 2018 · 3 min · Harshvardhan Malpani

A list of few productivity plugins and useful websites for web developers

Browser Extensions To know the platform and background details of any website – use Wappalyzer (chrome extension) https://chrome.google.com/webstore/detail/wappalyzer/gppongmhjkpfnbhagpmjfkannfbllamg?hl=en To protect privacy over internet, use privacy badger (chrome extension) https://chrome.google.com/webstore/detail/privacy-badger/pkehgijcmpdhfbdbbnkijodmdjhbjlgp To get away with distractions, use stayfocusd (chrome extension) https://chrome.google.com/webstore/detail/stayfocusd/laankejkbhbdhmipfmgcngdelahlfoji You hate CORS warnings in console, to get rid of them, use Allow-Control-Allow-Origin plugin for chrome https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi Developers and sys admins keep playing with DNS all the time, but browsers use cache and are lazy in updating the record. Use DNS Flusher https://chrome.google.com/webstore/detail/dns-flusher/nbomnjapnclaocillijpceooehonajnk Sometimes, you just want to check the website before actually moving the DNS or IP record, use Virtual Hosts (chrome extension) you can set IP of any domain name to anything https://chrome.google.com/webstore/detail/virtual-hosts/aiehidpclglccialeifedhajckcpedom JSONView – use this extension to view any json with indentation https://chrome.google.com/webstore/detail/jsonview/chklaanhfefbnpoihckbnefhakgolnmc For sharing screenshots very quick, you can use two plugins Nimbus screenshot and Lightshot https://chrome.google.com/webstore/detail/lightshot-screenshot-tool/mbniclmhobmnbdlbpiphghaielnnpgdp?hl=en ...

September 4, 2018 · 3 min · Harshvardhan Malpani

How to get all attributes with all available labels/options in Magento2?

Sometimes you need every dropdown and multi-select product attribute in a Magento 2 store together with all of its options in one place: to audit a messy catalogue, to plan a migration, or to prepare values for a CSV import. The admin only shows the options one attribute at a time, under Stores > Attributes > Product. I did a lot of research but could not find a solution for that. So I gathered some info and created this code: (it is not the best way to do it, but it works – you can use it at least one time for quick results) the values need to be transformed if you want to see them properly in csv ...

August 31, 2018 · 3 min · Harshvardhan Malpani

WordPress Dashboard – Introduction by newbie

Dashboard Panel When you will log into the administration area of your blog, you’ll see the WordPress Dashboard which will display the overview of the whole website. You can customize your needs by using some quick links such as writing quick draft, replying to latest comment, etc. Dashboard Menu The WordPress Dashboard provides a navigation menu that contains some menu options such as posts, media library, pages, comments, appearance options, plugins, users, tools and settings on the left side. ...

August 29, 2018 · 2 min · Harshvardhan Malpani

Extracting names from given list of URLs (using regex)

I use this when I have a list of URLs and only need one part of each, here a person’s name that comes after ?= at the end of the URL. Instead of copying the names out one at a time, a regular expression in Notepad++ pulls them all out in one go. The same trick works for any list where the value you want follows a fixed marker. Let us extract the name from the URL https://www.google.com/name?=rajiv The name we want here is rajiv. ...

August 9, 2018 · 3 min · Harshvardhan Malpani

How to install a new theme in WordPress using a compressed theme file

The usual way to add a theme you’ve downloaded or bought is the dashboard: Appearance > Themes > Add New > Upload Theme. That uploader only takes .zip files, though, and it can fail when the file is bigger than the upload limit your host allows. In those cases you can put the theme in place yourself with your hosting control panel’s file manager (cPanel’s File Manager in the screenshots below) and then activate it from the dashboard as normal. ...

August 9, 2018 · 3 min · Harshvardhan Malpani

How to remove links of a learndash course which has not started yet? without code changes

LearnDash can drip-feed a course, so each lesson only opens a set number of days after a student enrols, or on a fixed date. On the course page, the lessons that haven’t opened yet are still listed as links, and so are their topics. Students click them anyway, and until the lesson opens that doesn’t get them anywhere useful. I wanted those links to stop being clickable without editing LearnDash’s templates or plugin files. LearnDash already marks the unavailable lesson links with a notavailable class, so a few lines of jQuery can remove the links in the browser. ...

August 9, 2018 · 3 min · Harshvardhan Malpani

Simple joining of data from two different tables on basis of a common key

These are queries for combining data from two tables that share a key. My examples come from WordPress databases. WordPress keeps each user’s login details in the users table and extra profile fields, such as a phone number added by a plugin, in the usermeta table. The common key is the user ID: usermeta.user_id matches users.ID. The first two queries come from a site that used the table prefix e_ instead of the usual wp_; the third uses wp_. ...

August 7, 2018 · 3 min · Harshvardhan Malpani