How to release product versions tags on Github?

# View Tags

$ git tag
v0.1
v1.3

# Create a tag for product version release.

$ git tag

# Push the tags.

git push origin --tags

# Get the list of only 1.5.* releases.

$ git tag -l "v1.2*"
v1.2
v1.2-1
v1.2-2
v1.2.3

More more details visit https://git-scm.com/book/en/v2/Git-Basics-Tagging

WordPress Sensitization & Escaping Quick Examples

What is Sensitization?

Get secure user inputs.

What is Escaping?

Print / echo the secure output.


# Sanitize: Secure Input:

sanitize_email()
sanitize_file_name()
sanitize_html_class()
sanitize_key()
sanitize_meta()
sanitize_mime_type()
sanitize_option()
sanitize_sql_orderby()
sanitize_text_field()
sanitize_title()
sanitize_title_for_query()
sanitize_title_with_dashes()
sanitize_user()
esc_url_raw()
wp_filter_post_kses()
wp_filter_nohtml_kses()

# Escaping: Securing Output:

esc_html()
esc_url()
esc_js()
esc_attr() 
esc_textarea()

( with Localization )
esc_html__()
esc_html_e()
esc_html_x()
esc_attr__()
esc_attr_e()
esc_attr_x()


Examples ( Sanitize: Secure Input ):

sanitize_email()

$sanitized_email = sanitize_email('     admin@example.com!     ');
echo $sanitized_email; // It trim whitespace and special character and will output: 'admin@example.com'

sanitize_file_name()

echo sanitize_file_name("_profile pic--1_.png"); //Output "profile-pic-1_.png"

sanitize_html_class()

// If you want to explicitly style a post, you can use the sanitized version of the post title as a class
$post_class = sanitize_html_class( $post->post_title );
echo $post_class;
sanitize_key()
echo sanitize_key("https://WordPress.org"); //Output "httpswordpressorg"

sanitize_meta()

$clean_value = sanitize_meta( 'birth-year', $user_input, 'user' );

sanitize_mime_type()

sanitize_mime_type( $mime_type );

sanitize_option()

sanitize_option( 'admin_email', 'admin@example.com!' );

sanitize_sql_orderby()
Ensures a string is a valid SQL ‘order by’ clause.

$attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );

sanitize_text_field()

$title = sanitize_text_field( $_POST['title'] );
update_post_meta( $post->ID, 'title', $title );

sanitize_title()

echo sanitize_title("Sanitizing, in WordPress"); //Output "sanitizing-in-wordpress"

sanitize_title_for_query()

$query['name'] = sanitize_title_for_query( $query['name'] );

sanitize_title_with_dashes()

echo sanitize_title_with_dashes("I'm in LOVE with WordPress!!!1"); // this will print: im-in-love-with-wordpress1

sanitize_user()
Only keep alphanumeric, _, space, ., -, @

$user = sanitize_user( $user );

esc_url_raw()
Use esc_url_raw() if you want to store a URL in a database or use in URL redirecting.
Else use esc_url()

$url = esc_url_raw( 'https://wordpress.org/' );

wp_filter_post_kses()
Sanitize content for allowed HTML tags for post content.

$content = wp_filter_post_kses( 'This tag is <p> working</p>.' );

wp_filter_nohtml_kses()
Strips all of the HTML in the content.

$content = wp_filter_nohtml_kses('This tag is <p> working</p>.' );

Examples ( Escaping: Securing Output ):

esc_html()

echo esc_html( '<strong>text</strong> <b>bold</b>' );

esc_url()

<img src="<?php echo esc_url( 'https://wordpress.org/logo.png' ); ?>" data-wpmedia-src="<?php echo esc_url( 'https://wordpress.org/logo.png' ); ?>" />

esc_js()

var value = '<?php echo esc_js( $value ); ?>';

esc_attr()
Encodes the , &, ” and ‘ characters.

<?php $fname = ( isset( $_POST['fname'] ) ) ? $_POST['fname'] : ''; ?>
<input type="text" name="fname" value="<?php echo esc_attr( $fname ); ?>">

esc_textarea()
Use esc_textarea() instead of esc_html() while displays text in textarea. Because esc_textarea() can double encode entities.

<textarea><?php echo esc_textarea( 'Content goes here.' ); ?></textarea>

( with Localization )

esc_html__()

echo esc_html__('Text to translate', 'text-domain');

esc_html_e()

esc_html_e('Text to translate', 'text-domain')

esc_html_e()

esc_html_x('Date translate', 'post date', 'text-domain')

esc_attr__()

echo esc_attr__('Text to translate', 'text-domain');

esc_attr_e()

esc_attr_e('Text to translate', 'text-domain');

esc_attr_x()

esc_attr_x('Date translate', 'post date', 'text-domain')

$clean_value = sanitize_meta( 'birth-year', $user_input, 'user' );

sanitize_mime_type()

sanitize_mime_type( $mime_type );

sanitize_option()

sanitize_option( 'admin_email', 'admin@example.com!' );

sanitize_sql_orderby()

Ensures a string is a valid SQL ‘order by’ clause.

$attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );

sanitize_text_field()

$title = sanitize_text_field( $_POST['title'] );
update_post_meta( $post->ID, 'title', $title );

Examples ( Escaping: Securing Output ):

esc_html()

echo esc_html( '<strong>text</strong> <b>bold</b>' );

WordPress Translation Ready Reference Guide

Quick Reference:

e is for echo
x is for context
n is for plurals

# Translate Strings:

__()Retrieve a translated string.
_e()Display a translated string.
_x()Retrieve a translated string with context.
_ex()Display a translated string with context.
_n()Retrieve a plural or singular form based on amount.
_nx() – Hybrid of _n() and _x(). Supports context and plurals.


# Examples:

__()

Retrieve a translated string.
echo __( 'Hello.', 'text-domain' );

_e()

Display a translated string.
_e( 'Hello.', 'text-domain' );

_x()

Retrieve a translated string with context.
echo_x( 'post link', 'A link to the post', 'text-domain' );

_ex()

Display a translated string with context.
_ex( 'post link', 'A link to the post', 'text-domain' );

_n()

Retrieve a plural or singular form based on amount.
echo _n( 'There is a comment', 'There are comments', get_comments_number(), 'text-domain');

_nx()

() – Hybrid of _n() and _x(). Supports context and plurals.
_nx( '%s Comment', '%s Comments', get_comments_number(), 'comments title', 'text-domain' )


#  Using sprintf & printf:

Using sprintf
echo sprintf( __( 'You have chosen the %s theme.' ) , $color )

Using printf
printf( __( 'You have chosen the %s theme.' ) , $color );


# Only Register Strings:

Only register strings for Translation don’t translate them.

_n_noop() – Register plural strings in POT file. But, don’t translate them.
_nx_noop() – Register plural strings with context in POT file. But, don’t translate them.

translate_nooped_plural() – Translate the result of _n_noop() or _nx_noop().


More Details @see https://codex.wordpress.org/I18n_for_WordPress_Developers

Profiling with Blackfire for WordPress

Setup Blackfire profiling tool on your local machine ( I’m installing it on Windows ). Profiling help developer to analyse there coding performance. Find unwanted calls / memory issues and helps to optimize all the possible issues.

# Setup Blackfire Environment

Follow below 10 steps to setup Blackfire on Windows system. For other system setup goto https://blackfire.io/


Step 1) Download Binary Files

Download 32 Bit Binary file
Download 64 Bit Binary file

For latest binary files goto – Blackfire Installation


Step 2) Create Blackfire directory in your system.

I’m creating it like C:\Program Files\Blackfire.


Step 3) Set Windows PATH environment variable.

You can set it though Command Prompt ( CMD ) OR though windows Edit System Environment.
I’m using command prompt.

So, I follow below steps:

- Add though 'Command Prompt ( CMD )'
- Open Command Prompt by pressing `( Windows + R )` key. Or Goto start menu and search `command prompt`.
- Add command set PATH=%PATH%;C:\Program Files\Blackfire - NOTE: Add location where you extract the Blackfire binary files.

Add below command and confirm the system path is perfectly set.

echo %path%

Step 4) Create ‘agent.ini’ like ‘C:\Program Files\Blackfire\agent.ini’. And add below code.

Note: Please add your MY_SERVER_ID & MY_SERVER_TOKEN which you get it after login / register to http://blackfire.io

Or

Avoid below step. Goto Blackfire Configure

Here, Blackfire auto generate your agent.ini with your MY_SERVER_ID & MY_SERVER_TOKEN.

[blackfire]
;
; setting: ca-cert
; desc   : Sets the PEM encoded certificates
; default:
ca-cert=

;
; setting: collector
; desc   : Sets the URL of Blackfire's data collector
; default: https://blackfire.io
collector=https://blackfire.io/

;
; setting: log-file
; desc   : Sets the path of the log file. Use stderr to log to stderr
; default: stderr
log-file=stderr

;
; setting: log-level
; desc   : log verbosity level (4: debug, 3: info, 2: warning, 1: error)
; default: 1
log-level=1

;
; setting: server-id
; desc   : Sets the server id used to authenticate with Blackfire API
; default:
server-id=[MY_SERVER_ID]

;
; setting: server-token
; desc   : Sets the server token used to authenticate with Blackfire API. It is unsafe to set this from the command line
; default:
server-token=[MY_SERVER_TOKEN]

;
; setting: socket
; desc   : Sets the socket the agent should read traces from. Possible value can be a unix socket or a TCP address
; default: unix:///var/run/blackfire/agent.sock on Linux, unix:///usr/local/var/run/blackfire-agent.sock on MacOSX, and tcp://127.0.0.1:8307 on Windows.
socket=unix:///var/run/blackfire/agent.sock

;
; setting: spec
; desc   : Sets the path to the json specifications file
; default:
spec=

Step 5) Goto ‘Command Prompt’ and add below commands:

cd C:
cd C:\Program Files\Blackfire\
blackfire-agent -register

Add your Server Id & Server Token which you get from http://blackfire.io

blackfire config

Add your Server Id & Server Token which you get from http://blackfire.io


Step 6) Download PHP ‘.dll’ file for blackfire and rename with ‘php_blackfire.dll’.
You can download it by your system & PHP version.

E.g.
Download 32 Bit & PHP 7
Download 32 Bit & PHP 7

Or

Download appropriate PHP ‘.dll’ from Blackfire Get Dll


Step 7) Goto PHP extensions directory. I have it in ‘C:\xampp\php\ext\’. And move downloaded ‘php_blackfire.dll’ within it.


Step 8) Open ‘php.ini’ file and add below code:

Note: If you have ‘XDebug’ or ‘XHProf’ then disable these.

[blackfire]
extension=blackfire.so
; On Windows use the following configuration:
extension=php_blackfire.dll


; Sets the socket where the agent is listening.
; Possible value can be a unix socket or a TCP address.
; Defaults to unix:///var/run/blackfire/agent.sock on Linux,
; unix:///usr/local/var/run/blackfire-agent.sock on MacOSX,
; and to tcp://127.0.0.1:8307 on Windows.
;blackfire.agent_socket = unix:///var/run/blackfire/agent.sock

blackfire.agent_timeout = 0.25

; Log verbosity level (4: debug, 3: info, 2: warning, 1: error)
;blackfire.log_level = 1

; Log file (STDERR by default)
;blackfire.log_file = /tmp/blackfire.log

;blackfire.server_id =

;blackfire.server_token =

Step 9) Open ‘.htaccess’ file in which local site you want to test the blackfire and add below code:

Note: Add your Server ID & Server Token.

    php_admin_value blackfire.server_id "[MY_SERVER_ID]"
    php_admin_value blackfire.server_token "[MY_SERVER_TOKEN]"

Step 10) Download blackfire chrome extension from Download Blackfire Chrome


Step 11) Goto – ‘C:\Program Files\Blackfire’ and execute blackfire-agent.exe.

It open the black window. KEEP THIS WINDOW AS IT IS. Minimize it. ( DON’T CLOSE IT ).

Its done. Lets test it.

  • Goto the local website in which ‘.htaccess’ you added blackfire.

  • I have http://localhost/dev.themes/ – Click on installed chrome extension icon from top right. – And click on ‘Profile’ button.


# Analyse Profiling Result

Goto your Blackfire dashboard and analyse your blackfire profiling result. Click here for depth analyzing profiles

E.g.

 

 

Slack /remind command to create a reminder

# Information:

/remind is a slash command (a special type of message that is treated differently from a regular message) that tells Slackbot to create a reminder.

# Syntax

/remind <who> <to do what> <when>

# Examples

/remind me to take a walk in 10 mins
/remind @john to fill in the survey form in 10 mins
/remind #dev-team to fill in the survey form in 10 mins
/remind me to take a walk in 10 mins
/remind me to take a break in 2 hours
/remind me to take a walk at 1:30pm
/remind me to take a walk tomorrow at 10am
/remind me to take a walk at 1:30pm on 22nd September
/remind me to take a walk at 1:30pm on 22/09/2016
/remind me to get lunch at 1pm everyday
/remind me to get lunch at 1pm every weekday
/remind me to leave work at 5pm every Friday
/remind me to pay my credit card bill on the 5th of every month
/remind me to 'book tickets for the movie' tomorrow
/remind me to email the report at 10.20am at 10.10am
/remind me to book tickets for the movie tomorrow at 2pm
/remind me to 'email the report at 10.20am' at 10.10am
/remind me to 'book tickets for the movie tomorrow' at 2pm
/remind list

@source https://chatbotnewsdaily.com/how-to-set-reminders-in-slackbot-1e979d24b9b#.szupxs19b

add_editor_style() does not seem to be implemented properly.

While developing WordPress theme you see the message:

RECOMMENDED: add_editor_style() does not seem to be implemented properly.

The reason is your themes style.css load ONLY ON front end.
So, While writing article end user not have an idea how it looks on front end.


# Why editor style is recommended?

The reason is end user does not

The reason of editor style is to Show the post design / look in post editor window!


# How it editor style works?

Check below example to know how editor style works.

E.g. If your single post design is look like below screenshot:

frontend


With editor style support:

with-editor-style

Without editor style support:

without-editor-style


# Add editor style support?

/**
 * Added Editor Style
 */
function _theme_slug_setup() {
     add_editor_style( 'editor-style.css' );
}
add_action( 'after_setup_theme', '_theme_slug_setup' );

# Add RTL Support for Editor Style

For editor style RTL support! Save the file with FILE_NAME-rtl.css

E.g. editor-style.css then editor-style-rtl.css
E.g. assets/inc/editor-style.css then assets/inc/editor-style-rtl.css

WordPress 4.7 Introduces Twenty Seventeen Default Theme and WP REST API Content Endpoints — WordPress Tavern

https://videopress.com/embed/AHz0Ca46?hd=0

photo credit: Wikimedia CommonsWordPress 4.7 “Vaughan” was released today, named in honor of American jazz vocalist Sarah “Sassy” Vaughan. This release makes significant improvements to the new theme setup experience, inspiring the tagline: “Your site, your way.” Twenty Seventeen is making its debut in 4.7 as the first default theme designed for business websites. It…

via WordPress 4.7 Introduces Twenty Seventeen Default Theme and WP REST API Content Endpoints — WordPress Tavern