Category Archives: How to

Some infos how to use this example theme

xilitidy new logo

xili-tidy-tags version 1.8.6 released with a new template tag !

With new version of WP this summer (3.6 oscar), now new version of xili-tidy-tags plugin:

As example, the source now contains a new template tag – xili_tidy_tags_dropdown – to display a tag cloud as a dropdown list as expected by some users.
In my opinion, dropdown html tag is a little strange way and a flowed solution combining html and a little javascript (requiring jQuery) to redirect to the link associated with the tag (like in a cloud).

The example code is at (around) line 1009 in file of the plugin. The syntax is very easy like another plugin tag for cloud with a param (id_dropdown) to set the unique ID to a unique value for jQuery.

Soon more explanations…

M.

Case of main filters/actions during initialisation of WP [reserved for developers]

[note: example with jetpack was based on version 2.3. now recent jetpack 2.4 have changed initialization according better rules explained here]

What you need to know before adding filters in plugin or theme’s file functions.php ?

The case of main filters/actions during initialisation of WP.

The time line is very visible if your read the wp-settings.php file line by line.

Launching (do_action) of plugins_loaded (#211) preceeds that of init (#306). And both occur after plugin files including loop. (#196)

196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// Load active plugins.
foreach ( wp_get_active_and_valid_plugins() as $plugin )
	include_once( $plugin );
unset( $plugin );
 
// Load pluggable functions.
require( ABSPATH . WPINC . '/pluggable.php' );
require( ABSPATH . WPINC . '/pluggable-deprecated.php' );
 
// Set internal encoding.
wp_set_internal_encoding();
 
// Run wp_cache_postload() if object cache is enabled and the function exists.
if ( WP_CACHE && function_exists( 'wp_cache_postload' ) )
	wp_cache_postload();
 
do_action( 'plugins_loaded' );

Why it is important to understand filter priority during enqueuing ?

The things – including files, instancing classes, adding filter (action) – need to be done one after the other. They must give (allow) place to be modified by another plugin. Doing one of these things inside the step where plugin files are being included is not efficient and the order is only related to name of plugins and it difficult or impossible for another plugin to modify installed filters by the previous plugin. Because adding a specific filter for a specific plugin is uneasy to maintain, it is far better to follow time line and standard filter (action).

What can we learn from the launch of jetpack plugin – latest lines of jetpack.php ?

580
581
582
583
584
585
// line 4580 and...
add_action( 'init', array( 'Jetpack', 'init' ) );
add_action( 'plugins_loaded', array( 'Jetpack', 'load_modules' ), 100 );
add_filter( 'jetpack_static_url', array( 'Jetpack', 'staticize_subdomain' ) );
 
Jetpack_Sync::sync_options( __FILE__, 'widget_twitter' );

We find two main filters (action), init and plugins_loaded… And what happen in wp-settings.php

Launching (do_action) of plugins_loaded (#209) preceeds that of init (#306).

At end of jetpack.php a function calling Twitter is fired when including plugin file (#194) ( Jetpack_Sync::sync_options( FILE, ‘widget_twitter’ ); ). This function instanciates at this time the jetpack class. So the (previous) init filter seems to be redundant and explains some difficultes with load_plugin_textdomain step. So jetpack plugin architecture need cleaning works !

About functions and objects added in functions.php of current theme.

286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
$GLOBALS['wp_locale'] = new WP_Locale();
 
// Load the functions for the active theme, for both parent and child theme if applicable.
if ( ! defined( 'WP_INSTALLING' ) || 'wp-activate.php' === $pagenow ) {
	if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists( STYLESHEETPATH . '/functions.php' ) )
		include( STYLESHEETPATH . '/functions.php' );
	if ( file_exists( TEMPLATEPATH . '/functions.php' ) )
		include( TEMPLATEPATH . '/functions.php' );
}
 
do_action( 'after_setup_theme' );
 
// Set up current user.
$wp->init();
 
/**
 * Most of WP is loaded at this stage, and the user is authenticated. WP continues
 * to load on the init hook that follows (e.g. widgets), and many plugins instantiate
 * themselves on it for all sorts of reasons (e.g. they need a user, a taxonomy, etc.).
 *
 * If you wish to plug an action once WP is loaded, use the wp_loaded hook below.
 */
do_action( 'init' );
 
// Check site status
if ( is_multisite() ) {
	if ( true !== ( $file = ms_site_check() ) ) {
		require( $file );
		die();
	}
	unset($file);
}

This file is included after plugins file and roles defined. The file of the child theme is inserted after that of the parent theme. (# 287), and then launching ( (do_action) after_setup_theme (#294) preceeding init (#306). It is therefore possible to modify plugin behaviour or filters inserted by plugins. All here will only activate if this theme is the current. When reading wp-settings.php, we see that only filters (present in wp-settings) like ‘init’ can be used or modified (associated function changed or his priority…). Note that in case of child theme, the priority of after_setup_theme must set to 11. So the functions fired by the ‘child’ filter will be executed ‘after’ those of parent.

Authoring options for help during translation

This 2013 child theme uses an improved class including features to help authors during translation.

Today, by default, if you create a french post as translation from an english, all the categories are copied to the new post ready to receive the translation.

According content rules, it is sometimes possible to copy also the post-format and more. The seven options are:

  1. Post Format: here, it is a copy but with a filter, the developer can change the rules
  2. Page template
  3. Comment Status
  4. Ping Status
  5. Post Parent: In this case, you must be sure that the current post has a parent AND the parent has his own translation because it will the ID of this translated parent that will be copied… CMS design requires 😉 !!!
  6. Order: reserved for hierarchical post as page,
  7. Featured image: Linked translated post will have the same featured image, (try to find the translated media).

These new options are visible since Appareance/Xili-Options/ menu, screenshot below:

Authoring Options
Authoring Options