WPtouch 3 Pro WordPress Taxonomy Support

Last update : July 20, 2013
I use the WPtouch 3 Pro plugin for my WordPress Family Blog, together with the User Access Manager (UAM) plugin, created by Alexander Schneider. I noticed that the taxonomy support of WPtouch 3 Pro does not work as expected. All categories and tags are displayed on the mobile without respecting the restrictions defined by the UAM plugin. The reason is that WPtouch retrieves the taxonomy informations directly from the database with an SQL request, instead of using the wordpress functions get_categories() and get_tags(). For categories WordPress even offers the function wp_list_categories() with formatting support.

Usually I don’t like to modify the core code of WordPress themes and plugins, but in this case the only feasible solution to solve this problem was to change the two functions wptouch_fdn_ordered_cat_list() and wptouch_fdn_ordered_tag_list() in the WPtouch 3 Pro theme foundation file plugins/wptouch-pro-3/themes/foundation/root-functions.php.

function wptouch_fdn_ordered_tag_list( $num, $include_count = true )

I changed the following code :

echo '<ul>';
$sql = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}term_taxonomy INNER JOIN {$wpdb->prefix}terms ON {$wpdb->prefix}term_taxonomy.term_id = {$wpdb->prefix}terms.term_id WHERE taxonomy = 'category' AND {$wpdb->prefix}term_taxonomy.term_id NOT IN ($excluded_cats) AND count >= 1 ORDER BY count DESC LIMIT 0, $num");
if ( $sql ) {
foreach ( $sql as $result ) {
if ( $result ) {
echo "<li><a href=\"" . get_category_link( $result->term_id ) . "\">" . $result->name;
if ( $include_count ) {
echo " <span>(" . $result->count . ")</span></a>";
}
echo '</a>';
echo '</li>';
}
}
}
echo '</ul>';

by the new code :

$args = array (
'orderby' => 'count',
'order' => 'DESC',
'exclude' => $excluded_cats,
'number' => $num );
$categories = get_categories($args);
echo '<ul>';
foreach ($categories as $category) {
echo '<li><a href="' .get_category_link($category -> term_id). '">' .$category -> name. '';
if ($include_count) {
echo '<span> (' .$category -> count. ')</span>';}
echo '</a></li>';}
echo '</ul>';

function wptouch_fdn_ordered_cat_list( $num )

I changed the following code :

echo '<ul>';
$sql = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}term_taxonomy INNER JOIN {$wpdb->prefix}terms ON {$wpdb->prefix}term_taxonomy.term_id = {$wpdb->prefix}terms.term_id WHERE taxonomy = 'post_tag' AND {$wpdb->prefix}term_taxonomy.term_id NOT IN ($excluded_tags) AND count >= 1 ORDER BY count DESC LIMIT 0, $num");
if ( $sql ) {
foreach ( $sql as $result ) {
if ( $result ) {
echo "<li><a href=\"" . get_tag_link( $result->term_id ) . "\">" . $result->name . " <span>(" . $result->count . ")</span></a></li>";
}
}
}
echo '</ul>';

by the new code :

$args = array (
'orderby' => 'count',
'order' => 'DESC',
'exclude' => $excluded_tags,
'number' => $num );
$tags = get_tags($args);
echo '<ul>';
foreach ($tags as $tag) {
echo '<li><a href="' .get_tag_link($tag -> term_id). '">' .$tag -> name. '<span> (' .$tag -> count. ')</span></a></li>';}
echo '</ul>';

The new code provides the same WPtouch features and functionalities as the old one and is fully compatible with the UAM plugin.

One disadvantage of core changes in a plugin is the need to replace the modified files when an automatic update of the plugin is done. This was the case in July  2013 when the new versions 3.0.5 and 3.0.6 were loaded.