Categories
Big Commerce

Big Commerce Stencil

Install

https://developer.bigcommerce.com/stencil-docs/installing-stencil-cli/installing-stencil

Don’t forget to switch to Node V12 in order to access stencil

Setup theme

  1. Download theme and cd theme
  2. stencil init
  3. npm i
  4. stencil start
Categories
Svelte

Svelte Snippets

Remove protected comments from svelte build.

production && terser({ output: { comments: false } }),

Embed svelte bundle.js in html tag via php

$script = file_get_contents( 'public/build/bundle.js' );
// fixes svelte dev build '</script>' breaking the inline embed.
$script = str_replace( '</script>', '</fix>', $script );
$script = "<script>$script</script>";
echo $script;
Categories
vscode WordPress

WordPress Coding Standards in VS-Code

Install Composer and php codesniffer

scoop install composer

composer global require "squizlabs/php_codesniffer=*"

Clone WPCS in a global utils directory e.g. C:\utils\
Set phpcs config to wpcs

git clone -b master https://github.com/WordPress/WordPress-Coding-Standards.git wpcs

C:\Users\sunny\scoop\persist\composer\home\vendor\bin\phpcs --config-set installed_paths C:\utils\wpcs

Check to ensure WPCS is added

C:\Users\sunny\scoop\persist\composer\home\vendor\bin\phpcs -i

Install VS Code extensions: phpcs and phpcbf.
phpcs extension enables linting for all “PHP files in our editor.
phpcbf will try to beautify and fix our code according to the chosen coding standard.

Update settings

"phpcs.enable": true,
"phpcs.executablePath": "C:\\Users\\sunny\\scoop\\persist\\composer\\home\\vendor\\bin\\phpcs.bat",
"phpcs.standard": "WordPress",
"phpcbf.enable": true,
"phpcbf.documentFormattingProvider": true,
"phpcbf.onsave": true,
"phpcbf.executablePath": "C:\\Users\\sunny\\scoop\\persist\\composer\\home\\vendor\\bin\\phpcbf.bat",
"phpcbf.standard": "WordPress",
Categories
npm

NPM Tips

List globally installed npm packages

npm list -g --depth 0
Categories
Design

Design Resources

Bitmap

unsplashhttps://unsplash.com/
reshothttps://www.reshot.com/
pexelshttps://www.pexels.com/
thenounprojecthttps://thenounproject.com/

Vector

undrawhttps://undraw.co/
vectorstockhttps://www.vectorstock.com/free-vectors
icomoonhttps://icomoon.io/app/#/select

Inspire

designspiration https://www.designspiration.com/
dribbble https://dribbble.com/
awwwards https://www.awwwards.com/

Categories
wp-cli

Allow Root from wp-cli 2.5

In the past on order to run wp commands from the root user we would amend `–allow-root` to the wp command. With the release of wp-cli 2.5 we may now set the new environment variable: WP_CLI_ALLOW_ROOT just once.

 export WP_CLI_ALLOW_ROOT=true

More info here https://make.wordpress.org/cli/

Categories
Affiliates Domain Names

Domain Name Registrar Affiliates

Name.com and Google Domains are my preferred domain name registrars.

Purchase a domain at Name.com via this link and save $5.00 on your first purchase.

Categories
Affiliates

Affiliates

Transferwise

Receive a discount on your first transfer.
https://transferwise.com/u/sunnym11

AirBnB

I like AirBnB – Click here and get $40 off your first adventure!
https://www.airbnb.com/c/sunnym163?currency=USD

Hosting Providers

https://sunnymorgan.com/hosting-affiliates/

Domain Name Registrars

https://sunnymorgan.com/domain-name-affiliates/

Categories
Affiliates Hosting

Hosting Provider Affiliates

Digital Ocean

My preferred cloud services. Get $100 in credit over 60 days. Once they’ve spent $25.
https://m.do.co/c/8c4241ce3f7f

SiteGround

WordPress.org recommended WordPress hosting.
https://www.siteground.com/index.htm?afcode=6c144e937017630bd78e23953919cbe7

Flywheel

Super simple managed WordPress hosting for low traffic websites.
https://share.getf.ly/u92b4g

Kinsta

Kinsta is a managed WordPress hosting provider that I recommend for high traffic WordPress hosting.
https://kinsta.com/plans/?kaid=CBXZUMYDQAOB

 Gridpane

https://portal.gridpane.com/aff.php?aff=11

Cloudways

https://www.cloudways.com/en/?id=737926

Categories
SEO

Schema Types

Schema.org – Structured website metadata for search engines. Helps create Rich Snippets (google.com widgets).

  • JSON-LD – Metadata using JSON. Google’s prefered markup.1
  • Microdata – Part of the HTML Standard
  • RDFa – W3C Recommendation for adding metadata to HTML and other XML based documents
  • OpenGraph – Metadata for social media (twitter and facebook, etc..)

  1. https://jsonld.com/google-loves-json-ld-seo/ []
Categories
WordPress wp-cli

Migrate a WordPress Website with UpdraftPlus for Free (without Migrator or UpdraftClone)

How to Move a WordPress Site to a New Host

We often need to move a WordPress website to a new server or set up locally. I will usually use Wordmove and SSH to do this. But sometimes the client does not have SSH access to the server. In this case I will usually use Duplicator. Recently the client website had UpdraftPlus installed on the existing website.

  1. Install the free UpdraftPlus plugin on the old and new website.
  2. Backup your old website (db, plugins, theme, uploads, etc…) using the plugin.
  3. Transfer the backup files from the old site to the new site’s updraft directory http://newsite.com/wp-content/updraft/
  4. And add the following lines in the new site’s wp-config.php file: define(‘WP_SITEURL’, ‘http://newsite.com’);
    define(‘WP_HOME’, WP_SITEURL);
  5. Login to the new site and restore the backup files via the UpdraftPlus plugin. 
  6. Once restored, you will need to update the new website’s database with the new url. You can either use wp-cli or install a database Search and Replace plugin.
Categories
wp-cli

Search and Replace with wp-cli

wp search-replace oldsite.com newsite.com

Categories
Ubuntu Wordmove WordPress

WordPress directory and file ownership and permissions

Is WordPress failing to upload, install, or update your plugins, themes, or media files? It’s possible that your directory and file permissions are not set correctly.

chown

The chown command allows you to change user and group ownership for files and directories.

Recursively change user and group ownership of all directories and files to www-data:www-data, from the current directory.

sudo chown -R www-data:www-data . 

chmod

The chmod command changes the access permissions for files and directories.

Recursively change all directory and file permissions from the current directory.

sudo . -type d -exec chmod 755 {} \;  
sudo . -type f -exec chmod 644 {} \; 

wordmove

If you are updating WordPress via wordmove, you may wish to update all directory and file permissions automatically by setting rsync_options in your movefile.yml

 ssh:
    host: YOUR_HOST
    rsync_options: '-og --chown=www-data:www-data --no-perms --chmod=ugo=rwX'
Categories
WordPress wp-cli

Regenerate image sizes in WordPress

Regenerate your site’s images.

wp media regenerate --yes
Categories
Ubuntu WordPress wp-cli

Delete image sizes from WordPress

Easily delete images sizes from the command line.
This is permanent!

 find wp-content/uploads/*  -iname '*-2000x750.*' -exec rm {} \;
Categories
AMP

Testing AMP Pages

Add #development=1 to the URL of a page you wish to validate.

Add #log=1 to the URL of a page to view logged errors.

Logged messages appear in the browser’s console.

Categories
WordPress

Compile custom WordPress style.min.css from scss source files

It may be beneficial to dequeue the default WordPress Gutenberg block styles.min.css and compile your own from the source scss files.

The WordPress blocks css files is located here,
wp-includes/css/dist/block-library/style.min.css

The WordPress blocks source files are located here,
https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library

npm install the source files,
npm install @wordpress/base-styles --save-dev
npm install @wordpress/block-library --save-dev

Remove Gutenberg Block Library CSS from loading on the frontend. Add to function.php

//Remove Gutenberg Block Library CSS from loading on the frontend
function sd_remove_wp_block_library_css(){
    wp_dequeue_style( 'wp-block-library' );

} 
add_action( 'wp_enqueue_scripts', 'sd_remove_wp_block_library_css', 100 );

@import scss files

// mixins, vars, etc..
@import "~@wordpress/base-styles/_mixins.scss";

@import "~@wordpress/base-styles/breakpoints";

@import "~@wordpress/base-styles/variables";

// style src
@import "~@wordpress/block-library/src/style";

You may need to replace ~ with path to scss files. e.g. ../../node_modules/@wordpress/base-styles/
Comment out the imports within @wordpress/block-library/src/_style.scss that are not required.

Categories
Wordops

Install WordPress with wordops

Install WordPress

This will install WordPress with nginx fastcgi_cache, php 7.4, and Let’s encrypt. Replace site.com with your website URL.

wo site create --wpfc --php74 -le --force site.com 

Reinstall let’s encrypt security certificate

If the let’s encrypt SSL certificate fails you can attempt to reinstall the security certificate with

wo site update -le --force site.com 

Logs

Logs are available, wo log show --debug

Clear Cache

Clear the cache via WordPress, “Purge Cache” or cli, wo clean
Cleanes NGINX FastCGI cache, Opcache, Redis Cache and restart Nginx. You can also manually delete the nginx cache rm -rf /var/run/nginx-cache/*

Categories
Wordops

Maintaining Wordops

Upgrade Wordops to latest version

Maintaining Wordops stack

  • wo maintenance
    Update server packages (After SSH the message may appear, “…updates can be installed immediately”).
    This command is equivalent to:apt update
    • apt dist-upgrade
    • apt autoremove –purge
    • apt autoclean
  • wo stack upgrade
    Upgrade stack safely. Sites may be down for few seconds if upgrading Nginx, PHP-FPM, MariaDB or Redis
  • wo clean
    leans NGINX FastCGI cache, Opcache, Redis Cache

Helpful commands for maintaining Wordops

  • wo stack restart
  • wo stack restart --php
  • wo stack reload
  • wo stack status

Categories
Wordops

Setup wordops

#Install

  • wget -qO wo wops.cc && sudo bash wo
  • source /etc/bash_completion.d/wo_auto.rc # bash_completion

#Alias for sudo wo

  • echo -e "alias wo='sudo -E wo'" >> $HOME/.bashrc
  • source $HOME/.bashrc
Categories
Ubuntu

Users

List all users
getent passwd {1000..60000}

Categories
Ubuntu

Ubuntu update

apt update && apt upgrade -y && apt dist-upgrade -y && apt autoremove -y

Categories
Ubuntu

System restart

lists the packages that requested the reboot
cat /var/run/reboot-required.pkgs

Restart server. Takes 10 seconds or more.
sudo reboot

Categories
Ubuntu

Ubuntu bin directories

~/bin 				# you
/usr/local/bin			# you and other local users
/usr/local/sbin			# root only
/bin				# system
Categories
wp-cli

Creating a new WordPress user from the command line with wp-cli

wp user create sunny sunny@sunnymorgan.com --role=administrator --user_pass=PASSWORD

It may be simpler to update an existing user. e.g.

wp user update 1 --display_name=Admin --user_pass=PASS
Categories
wp-cli

Change post type

wp db query "UPDATE  `wp_posts` SET  `post_type` =  'new-cpt-post' WHERE  `post_type` = 'old-cpt-post';"
Categories
WordPress wp-cli

Optimize WordPress images

Easily optimize images using wp-cli, https://github.com/TypistTech/image-optimize-command

wp package install typisttech/image-optimize-command:@stable
# optimize specific attachments
$ wp image-optimize attachment 123 223 323

# optimize certain number of attachments
$ wp image-optimize batch --limit=20

# restore the full sized images of specific attachments
$ wp image-optimize restore 123 223 323
$ wp media regenerate 123 223 323

# restore all full sized images and drop all meta flags
$ wp image-optimize reset
$ wp media regenerate

# Find and optimize images under a given directory **without backup**
$ wp image-optimize find /path/to/my/directory --extensions=gif,jpeg,jpg,png,svg,webp

# shortcusts for `wp image-optimize find` **without backup**
$ wp image-optimize mu-plugins
$ wp image-optimize plugins
$ wp image-optimize themes
$ wp image-optimize wp-admin
$ wp image-optimize wp-includes

# learn more
$ wp help image-optimize
$ wp help image-optimize <subcommand>
Categories
wp-cli

wp import backup.sql.gz

Import a gzip compressed database

gunzip < backup.sql.gz | wp db import -
Categories
wp-cli

Settings up a new WordPress install with wp-cli

#Settings

wp core update --allow-root; 
wp option update timezone_string "America/New_York" --allow-root; 
wp option update posts_per_page 9 --allow-root; 
wp rewrite structure '/%category%/%postname%/' --allow-root;
wp user update 1 --display_name=Admin --user_pass=PASS--allow-root;
wp option update admin_email sunny@sunnymorgan.com --allow-root;

#Plugins

wp plugin delete hello --allow-root;
wp plugin install query-monitor --activate --allow-root;
wp plugin install nginx-helper --activate --allow-root;
wp plugin install "http://connect.advancedcustomfields.com/index.php?p=pro&a=download&k=REPLACE_WITH_KEY" --activate --allow-root;

Hello world!

Welcome to WordPress. This is your first post. Edit or delete it, then start writing!