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

Advertisements

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 <strong>set PATH=%PATH%;C:\Program Files\Blackfire</strong> - <strong>NOTE:</strong> 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.

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 Rollback WordPress.org Plugins and Themes

In development lots of times, We need to check the old version of current plugin/theme. Use WordPress plugins & themes WP Rollback.

[https://wordpress.org/plugins/wp-rollback/]

Translation Ready

Github Repo.

Support and Documentation

We answer all support requests on the WordPress.org support forum.

One Page Navigator for Visual Composer

Hey Guys,

Just wanted to let you know that “One Page Navigator for Visual Composer” WordPress plugin is live on Codecanyon. You can buy it officially here – http://codecanyon.net/item/one-page-navigator-for-visual-composer/10766943

PREVIEW:

One Page Navigator for Visual Composer
One Page Navigator for Visual Composer

Steve Bruner and Kevin Miller: Building Powerful Websites and Web Applications with Piklist

Introducing MG Parallax Slider

MG Parallax Slider by Mahesh Waghmare [mwaghmare7@gmail.com][http://mgwebthemes.com]

Create parallax slider for your website. It provide ultimate admin panel for slide customization.

Visit http://wordpress.org/plugins/mg-parallax-slider/

How to Use

You can create slides using two ways.

  1. Use Framework Unlimited Slides: Goto MGPS Options -> Slides -> Add Slides and use shortcode [mgps-slider]
  2. OR
  3. Use MG Slider: Goto MG Slider -> Add New and use shortcode [mgps-slider-post]
  4. Use MG Options for styling slider background, title, content etc.

Features:

  • Ultimate admin panel
  • 2 Shortcodes [mgps-slider] and [mgps-slider-post]
  • Unlimited Slides
  • Unlimited Colors
  • 19 Background Patterns
  • 600+ Google Fonts
  • Import/Export

Review:

Reply your Reviews, Suggestions to make it more useful…

Admin Panel of MG Parallax Slider by Mahesh Waghmare (mwaghmare7@gmail.com)[http://mgwebthemes.com]