Vaping Laws around the World

As we all know, the world of vaping is ever changing. Like with many other laws on many other topics, there is very little consensus on the topic of vaping and whether or not it should be allowed. This can make things more than a little difficult for travelling vapers – where in one country you can vape freely, you might be given a substantial fine in the next. Here’s the most important rules and regulations you need to know from around the globe.

The EU

EU wide regulation introduced in 2014 outlaws advertising for e-cigarettes, sets a limit on the amount of nicotine in e-liquids, and requires sellers to package products in child and tamper-proof packaging amongst a whole load of other complicated rules and regulations. Despite the arrival of these rules, there are still discrepancies from country to country. In France, for instance, e-liquids are considered medical products – something that is not generally in place in other member states – and, in the United Kingdom, advertising of e-cigarette paraphernalia has been allowed since 2014.

North America

I’m sure we’re all familiar with the ever-changing regulations in the United States, but what about Canada? If you’re planning a trip across the border, there’s good news – vaping is largely unregulated in Canada. While the technicalities of Canadian law mean that selling e-cigarettes is illegal, the reality of the situation is that this is rarely enforced properly. When it comes to actually vaping, several cities have enforced different rules – in Toronto, for example, it’s against the rules to vape in the workplace and Vancouver has extended their smoking ban in public places to vaping.

Central and South America

After a ban on tobacco products was overturned in 2015, e-cigarettes are now legal again in Mexico. However, in places like Uruguay and Argentina vaping is completely banned. In addition, Brazilian law completely forbids ‘the sale, importation, and advertising’ of any electronic cigarettes. This is because Brazil’s health and sanitation federal agency, known as Anvisa, found the current health and safety assessments about e-cigarettes unsatisfactory to allow them in the country.

Australia and New Zealand

As vaping remains a relatively new phenomenon, Australia is still in the midst of developing their vaping regulations. Often the rules from state to state vary (and, in some cases, they actually conflict – which is nice and confusing for travellers!). But, on the whole, there is no regulation completely outlawing e-cigarettes.

In New Zealand, things are a little more straightforward. As long as your e-cigarettes don’t contain nicotine, sale is permitted to people over the age of 18. If you want e-juices containing nicotine, they must be imported from overseas and can only be used for personal use. Advertising of e-cigarettes is not allowed, however, which can cause trouble for manufacturers.

Asia

Japan took the decision to ban e-cigarettes containing nicotine in 2010, but there’s currently no regulation for e-cigarettes and vaping devices that don’t contain nicotine – so both adults and minors can vape those to their heart’s content. Similarly, in the Philippines, e-cigarettes remain completely unregulated, which means anyone of any age can buy them. However, the Philippine Medical Association is recommending that the ban on cigarettes in public places be extended to vaping.

In the modern-day home of vaping, China, the import and export, sale, and use of e-cigarettes is completely legal – but new rules are being imposed in certain places. In Shanghai, for example, the use of e-cigarettes is banned in no smoking areas.

The Middle East

Many countries in the Middle East take an even harder line against vaping. The UAE, Qatar, and Jordan have all completely banned vaping devices. Brunei goes one step further in their vaping rules, slapping anyone found vaping in a non-smoking zone with a $500 fine, and selling or importing e-cigarettes could cost you $10,000. If you’re planning to visit any time soon, we’d recommend you follow the rules!

It’s important to remember that vaping regulations are always changing. Public opinion on vaping is always evolving, as are the thoughts of people in power. If you’re an avid vaper planning to travel over the next few weeks, we’d definitely recommend that you check up on the regulations in your destination – after all, it’s better to give up your e-cigs for a little while then end up with a hefty fine (or jail time!).

Using the_posts_pagination for custom page template WordPress

If you look my sitemap, you’ll see the list of my post with pagination. That page was created under custom page template, the custom WP_Query of post’s list build under main loop of page, and function the_posts_pagination to display pagination.

Here the sample PHP code that you can accomplish if you need create custom page template with pagination. Just add after your main query loop.

// Define page_id
$page_ID = get_the_ID();

// Define paginated posts
$page    = get_query_var( 'page' );

// Define custom query parameters
$args    = array(
	'post_type'      => array( 'post', 'book', 'movie' ), // post types
	'posts_per_page' => 5,
	'paged'          => ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1
);

// If is_front_page "paged" parameters as $page number
if ( is_front_page() )
	$args['paged'] = $page;

// Instantiate custom query
$custom_query = new WP_Query( $args );

// Custom loop
if ( $custom_query->have_posts() ) :
    while ( $custom_query->have_posts() ) :
        $custom_query->the_post();

		/**
		 * Displaying content
		 *
		 * the_title(), the_permalink(), the_content() etc
		 * Or see Twentysixteen theme page.php
		 * get_template_part( 'template-parts/content', 'page' );
		 *
		 */
    endwhile;

		/**
		 * Pagination parameters of the_posts_pagination() since: 4.1.0
		 *
		 * @see the_posts_pagination
		 * https://codex.wordpress.org/Function_Reference/the_posts_pagination
		 *
		 */
		$pagination_args = array(
			'prev_text'          => __( 'Previous page', 'theme-domain' ),
			'next_text'          => __( 'Next page', 'theme-domain' ),
			'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'theme-domain' ) . ' </span>'
		);

		/**
		 * Fix pagination link base
		 *
		 * If in paginated posts w/o multiple loop
		 *
		 */

		if ( ! is_front_page() && 0 < intval( $page ) )
			$pagination_args['base'] = user_trailingslashit(
				untrailingslashit( get_page_link( $page_ID ) ) . '/page/%#%'
			);
		/**
		 * Fix Pagination with $GLOBALS['wp_query'] = {custom_query}
		 *
		 * @see get_the_posts_pagination use $GLOBALS['wp_query']
		 * https://developer.wordpress.org/reference/functions/get_the_posts_pagination/#source-code
		 *
		 */
		$GLOBALS['wp_query'] = $custom_query;
		the_posts_pagination( $pagination_args );
else :
	/**
	 * Empty Post
	 *
	 * Run your stuff here if posts empty
	 * Or see Twentysixteen theme page.php
	 * get_template_part( 'template-parts/content', 'none' );
	 */
endif;
wp_reset_query(); // Restore the $wp_query and global post data to the original main query.

We using get_page_link on paging arguments code instead of get_pagenum_link function, it just to making work with main loop if using post page ( wp_link_pages ~ <--nextpage--> ) for your content. I think there are better clean approach than this, but.. ah, let’s go ready to rumble.

UPDATE: April 08, 2016

  • Fix pagination if set in front page

Menampilkan editor TinyMCE di front-end tanpa wp_editor

Dengan function wp_editor Anda akan dengan mudah untuk menampilkan editor yang sama dengan editor postingan admin. Bagaimana jika kita ingin menampilkan hal yang sama dengan memanfaatkan langsung fitur TinyMCE yang digunakan oleh wp_editor?

Cara ini sudah saya terapkan di beberapa plugin private dan sudah saya share di WPSE.

Kode HTML sederhana textarea

Kode ini bisa Anda tempatkan di page situs Anda.

<textarea id="textarea_id_element"></textarea>

Kode PHP dan settingan TinyMCE

Dengan menggunakan function jv_editor_tinymce kita akan menempatkan kode js settingan tinyMCE di bagian footer theme. Pastikan Anda mengubah id name textrea dimana Anda akan menempatkan tinyMCE editor.

add_action( 'wp_footer', 'jv_editor_tinymce' );
function jv_editor_tinymce()
{ ?>
<script type="text/javascript">
if ( undefined !== window.jQuery ) {
	jQuery( document ).ready( function( $ ) {
		tinymce.init( {
			mode : 'exact',
			elements : 'textarea_id_element', //your id name textarea element
			theme: 'modern',
			skin: 'lightgray',
			menubar : false,
			statusbar : false,
			toolbar: [
				'bold italic | alignleft aligncenter alignright | bullist numlist outdent indent | undo redo'
			],
			plugins :'paste',
			paste_auto_cleanup_on_paste : true,
			paste_postprocess : function( pl, o ) {
				o.node.innerHTML = o.node.innerHTML.replace( /&nbsp;+/ig, ' ' );
			}
		} );
	} );
}
</script>
<?php
}

Kode JS TinyMCE WordPress

add_action( 'wp_enqueue_scripts', 'jv_enqueue_scripts' );
function jv_enqueue_scripts() {
	wp_enqueue_script( 'tinymce_js', includes_url( 'js/tinymce/' ) . 'wp-tinymce.php', array( 'jquery' ), false, true );
}
Tampilan editor TinyMCE
Tampilan editor TinyMCE dengan menggunakan theme TwentySixteen.

Tutorial ini hanya sekedar dasar untuk menampilkan editor tinyMCE, untuk menggunakannya dalam hal mengirimkan data layaknya postingan, Anda membutuhkan form, tombol submit dan function untuk mengevaluasi data yang dikirim. Semoga bermanfaat.

Mendapatkan jumlah dan membatasi kata dalam postingan WordPress

Jika Anda menggunakan Shortcode dalam postingan, terkadang untuk medapatkan jumlah dan membatasi kata dalam postingan WordPress dengan tepat, kita agak kesulitan. Berikut ini adalah function yang bisa Anda tambahkan dalam file functions.php theme Anda, dalam kode sudah diberikan penjelasan dan cara penggunaan.

add_filter( 'wp_trim_words', 'jv_trim_words', 10, 4 );
/* Trims text to a certain number of words.
 *
 * Kepp shortcode if exist in text.
 * Combination function of strip_shortcodes and wp_trim_words
 * Default $num_words = 55
 *
 ** USAGE
 ** Using directly
 ** jv_trim_words( $text, 56 )
 ** jv_trim_words( $text, 56, null, false, false, true ) &#8211; return array
 ** Shortcode hidden if $num_words is not set or if set with value = 55 with 4 arguments
 **
 ** Use wp_trim_words
 ** wp_trim_words( $text, $num_words = 56 )
 ** Fire wp_trim_words
 ** Shortcode hidden if $num_words is not set or $num_words = 55
 ** Position always in bottom
 ** add_filter( 'wp_trim_words', 'jv_trim_words', 10, 4 );
 *
 * @param  string  $text             Text to trim.
 * @param  int     $num_words        The number of words to trim the text to. Default 5.
 * @param  string  $more             An optional string to append to the end of the trimmed text, e.g. &hellip;.
 * @param  string  $original_content The text before it was trimmed.
 * @param  string  $pos              Shortcode Position. You can set 'top' value if using directly
 * @param  boolean $count            Get word count
 * @return string  The text after the filter witch $num_words
 * @return array   If using directly and parameter $count set to true
 */
function jv_trim_words( $text, $num_words = 55, $more = null, $original_content = false, $pos = false, $count = false ) {
	if ( null === $more)
		$more = ' ' . '[&hellip;]';

	$shortcode = $strip_shortcode = true;

	if ( ! $original_content )
		$original_content = $text;

	$text = $original_content;

	/* Check existing shortcode
	 *
	 */
	if ( false === strpos( $text, '[' ) )
		$strip_shortcode = false;

	global $shortcode_tags;

	if ( empty( $shortcode_tags ) || ! is_array( $shortcode_tags ) )
		$strip_shortcode = false;

	/* Strip content from shortcode
	 *
	 */
	if ( $strip_shortcode ) {
		preg_match_all( '@\[([^<>&/\[\]\x00-\x20=]++)@', $text, $matches );
		$tagnames = array_intersect( array_keys( $shortcode_tags ), $matches[1] );

		if ( ! empty( $tagnames ) ) {
			$text = do_shortcodes_in_html_tags( $text, true, $tagnames );
			$pattern = get_shortcode_regex( $tagnames );
			preg_match_all( "/$pattern/", $text, $match );

			if ( ! empty( $match[0] ) && is_array( $match[0] ) ) {
				$shortcode = '';
				$length    = count( $match[0] );
				for ( $i = 0 ; $i < $length; $i++ )
					$shortcode .= do_shortcode( $match[0][ $i ] ); //match shortcode
			}

			$text = preg_replace_callback( "/$pattern/", 'strip_shortcode_tag', $text );
			$text = unescape_invalid_shortcodes( $text );
		}
	}

	/* Hide shortcode
	 * Base on count function arguments
	 *
	 */
	if ( func_num_args() == 1 || ( func_num_args() == 4 && 55 == $num_words ) )
		 $shortcode = '';

	/* Split content into array words
	 *
	 */
	$text = wp_strip_all_tags( $text );

	/*
	 * translators: If your word count is based on single characters (e.g. East Asian characters),
	 * enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'.
	 * Do not translate into your own language.
	 */
	if ( strpos( _x( 'words', 'Word count type. Do not translate!' ), 'characters' ) === 0 && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) {
		$text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' );
		preg_match_all( '/./u', $text, $words_array );
		$limit_words_array = array_slice( $words_array[0], 0, $num_words + 1 );
		$full_words_array  = $words_array[0];
		$sep = '';
	} else	{
		$limit_words_array = preg_split( "/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY );
		$full_words_array  = explode( ' ', preg_replace( "/[\n\r\t ]+/", ' ', $text ) );
		$sep = ' ';
	}

	/* Check word count base on $num_words
	 *
	 */
	$word_count = count( $full_words_array );
	if ( $word_count >= $num_words ) {
		array_pop( $limit_words_array );
		$text  = implode( $sep, $limit_words_array );
		$text .= $more;

		/* keep shortcode if exists and set position ( top or bottom text )
		 *
		 */
		switch( $pos )	{
			case 'top' :
				$text = $shortcode . $text;
				break;

			default :
				$text .= $shortcode;
				break;
		}
	} else {
		$text = apply_filters( 'the_content', $original_content );
	}

	if ( $count )
		return array(
			'text'  => $text,
			'count' => $word_count
		);

	return $text; //output
}

Cara kerja function ini sama dengan function the_excerpt atau get_the_excerpt, hanya saja kita tetap menampilkan shortcode ketika postingan melebihi batas kata yang kita tentukan. Kode shortcode dan kode html tidak dihitung.

Kode ini juga di sini Trim content and limit with certain count word.

Modifikasi Kolom Komentar WordPress Menjadi WYSIWYG Editor

Tanpa harus menggunakan plugin, Anda bisa memodifikasi sendiri kolom pesan atau komentar untuk blog WordPress Anda menjadi bentuk WYSIWYG Editor.

Modifikasi ini memanfaatkan function wp_editor dan menggunakan filter comment_form_defaults untuk menimpa kolom komentar yang lama. Berikut kode PHP yang harus Anda tambahkan di file functions.php theme Anda.

add_filter( 'comment_form_defaults','jv_comment_form');
function jv_comment_form( $args ) {
	$editor_id = 'comment'; // element id of textarea comment field

	$settings  = array(
		'editor_height'    => 50, //column height
		'media_buttons'    => false,
		'textarea_name'    => $editor_id,
		'teeny'            => true,
		'tinymce'          => array(
			'resize'                => true,
			'wordpress_adv_hidden'  => true,
			'add_unload_trigger'    => true,
			'statusbar'             => true,
			'autoresize_min_height' => 50,
			'wp_autoresize_on'      => true,
			'toolbar1'              => 'bold,italic,bullist,numlist'
		),
		'quicktags' => array( 'buttons' => 'strong, em, link, block, del, ins, img, ul, ol, li, code, more, close' )
	);

	if ( function_exists( 'wp_editor' ) )	{
		ob_start();
		wp_editor( '', $editor_id, $settings );
		$args['comment_field'] = ob_get_clean();

		return $args;
	}
}

Hasilnya seperti gambar berikut:

WP Editor Kolom Komentar
WP Editor Kolom Komentar