Composer usage with premium version

We use Freemius as service to ship our premium plugins and license management. This service offers a way to retrieve and include the premium plugin version by composer.


Plugin Filters

This code can be inserted as it is in your theme's functions.php file on in your custom plugin.

Basic

Change the thumbnail size in tooltips

add_filter( 'glossary_tooltip_image_size', 'full' );

Disable the alert about missing localization on translate.wordpress.org.

add_filter( 'glossary_alert_localization', '__return_false' );

Remove Glossary Metaboxes

This will remove the Glossary auto-link settings metabox

function glossary_remove_metabox() {
    CMB2_Boxes::remove( 'glossary_metabox' );
}
add_action( 'cmb2_init_before_hookup', 'glossary_remove_metabox' );

This will remove the Glossary Post Override metabox

function glossary_remove_post_metabox() {
    CMB2_Boxes::remove( 'glossary_post_metabox' );
}
add_action( 'cmb2_init_before_hookup', 'glossary_remove_post_metabox' );

Custom Tooltips Themes

This two filters enable you to add a custom theme inside the Glossary settings. The first one enable you to set a theme name and show it in the native plugin's dashboard. The second one is the URL of the CSS file to enqueue on the front-end.

add_filter(
    'glossary_themes_dropdown',
    function( $themes ) {
        $themes['beautiful'] = 'My beautiful theme';
        return $themes;
    }
);
add_filter( 'glossary_themes_url', 
    function( $themes ) {
        $themes['beautiful'] = 'url to your css file to enqueue in the page';
        return $themes;
    }
);

Change the excerpt inside the tooltips

add_filter( 'glossary_excerpt', function( $excerpt, $post_id ) {
    return $excerpt
}, 10, 2 );

Disable the injection inside excerpt

add_filter( 'glossary_excerpt_support', '__return_false' );

Interact with the tooltip's HTML

/**
 * Filter the HTML generated
 *
 * string $tooltip The tooltip.
 * string $excerpt The excerpt.
 * string $photo   Photo.
 * string $post    The post object.
 * string $noreadmore The internal html link.
 * string $tooltip_html The tooltip's HTML content wrapper.
 *
 * @return string $html The tooltip filtered.
 */
add_filter( 'glossary_tooltip_html', function( $tooltip, $excerpt, $photo, $post_id, $noreadmore, $tooltip_html ) {
    return $tooltip;
}, 10, 5 );

Eg. How to print in a tooltip the price of a WooCommerce product.

add_filter( 'glossary_tooltip_html', function( $tooltip, $excerpt, $photo, $post_id, $noreadmore ) {
    if ( is_product( $post_id ) ) {
        $product = wc_get_product( $post_id );
        return $tooltip . $product->get_price() . '€';
    }
    return $tooltip;
}, 10, 5 );

Eg. How to print in a tooltip the term title.

add_filter( 'glossary_tooltip_html', function( $tooltip, $excerpt, $photo, $post_id, $noreadmore ) {
    return get_the_title( $post_id ) . $tooltip;
}, 10, 5 );

Change the regex used in the algorithm

add_filter( 'glossary_regex', function( $regex, $term ) {
    return $regex;
}, 10, 2 );

An example, the same regular expression generated by the plugin: without the check for the plugin span (it is an option) and added the symbol to the ones allowed useful for asiatic languages:

add_filter( 'glossary_regex', function( $regex, $term ) {
    return '/(?<![\w\—\-\.\/]|=")((?i)' . $term . '(?-i))(?=[\।\॥ \.\,\:\;\*\"\)\!\?\/\%\$\€\£\^\<\>\“\”])(?![^<]*(\/>|<h|<\/button|<\/h|<\/a|<\/pre|<\/figcaption|<\/code|\"))/u';
}, 10, 2 );

Attention

It will change just the regular expression used in the first part of the algorithm, not the resulting HTML

Enable glossary on not official supported plugins

This filter enables buddypress support. We didn't have an explicit option because we are not interested in supporting this officially.

add_filter( 'glossary_buddypress_support', '__return_true' );

This filter enables bbpress support. We didn't have an explicit option because we are not interested in supporting this officially.

add_filter( 'glossary_bbpress_support', '__return_true' );

Run Glossary auto-link in specific taxonomies, archives or post types

This example will allow the glossary execution only if the post is in the taxonomy book_author or it is a post type book.

add_filter( 'glossary_is_page_to_parse', 'inject_glossary_tax' , 9999 );

function inject_glossary_tax( $bool ) {
    if ( is_tax('book_author') || is_post_type_archive('book') ) {
        return true;
    }

    return $bool;
}

This one instead if the post has the category dictionary.

add_filter( 'glossary_is_page_to_parse', 'inject_glossary_tax' , 9999 );

function inject_glossary_tax( $bool ) {
    if ( has_category('dictionary') ) {
        return true;
    }

    return $bool;
}

So using one of those with the plugin settings to enable in specific post types can improve your automatic filtering about injecting the tooltips.

Change the HTML tag that wraps every letter in the Alphabetical Bar

<span> is the default HTML tag.

add_filter( 'glossary_a2z_letter_tag', function( $tag ) {
    return 'div';
}, 10, 1 );

Add your custom tooltip theme

Using this filter you can add your own custom tooltip theme directly in the settings dropdown.

add_filter( 'glossary_themes_url', 'add_glossary_url' );

function add_glossary_url( array $themes ) {
    $themes[ 'newtheme' ] = "https://urlofyourtooltiptheme.css";

    return $themes;
}

Create a new tooltip theme name

add_filter(' glossary_themes_dropdown', 'add_glossary_name' );
function add_glossary_name( $themes ) {
    $themes[ 'newtheme' ] = "New theme";

    return $themes;
}

Advanced

Add/Remove Glossary PHP classes on plugin loading.

Attention

Removing a Class through this filter requires a dedicated plugin. It will not work if placed in the theme's functions.php

add_filter( 'glossary_classes_to_execute', function( classes ) {
    return $classes;
}, 10, 1 );

Eg. How to remove Term_Content Class

add_filter( 'glossary_classes_to_execute', function($classes) {
    foreach ( $classes as $index => $class ) {
        if ( $class === 'Glossary\Frontend\Term_Content' ) {
            unset($classes[$index]);
            return $classes;
        }
    }
    return $classes;
}, 99999 );

Change priority for the_content filter execution

add_filter( 'glossary_content_priority', function() {
    return 10;
} );

Change the post types available in the Internal URL field picker

add_filter( 'glossary_posttype_picker', function() {
    return array('post','page');
} );

Enable the Glossary category taxonomy as hierarchical

add_filter( 'glossary_tax_hierarchical', function() {
    return true;
} );

Change settings with a filter

You can change the plugin options with a filter.
This example change the tooltip mode in a specific page with footnotes.

add_filter( 'glossary_settings', 'change_mode_on_page' );

function change_mode_on_page( $settings ) {
    if ( get_the_ID() === 100 ) {
        $settings['tooltip'] = 'footnote';
    } 

    return $settings;
}

Get/Change a Class instance (since Glossary 2.2.17)

It is possible to get the class instance using a filter that is generated using the plugin namespace.

$search_engine = \apply_filters( 'glossary_instance_Glossary\Frontend\Core\Search_Engine', '' );
add_action( 'plugins_loaded', 'glossary_init' );

function glossary_init() {
   add_filters( 'glossary_instance_Glossary\Frontend\Core\Search_Engine', 'Your_Instance' );
}

Change the default parameters for Term injections (since Glossary 2.2.24)

It is possible to change the parameters generated by the plugin before the plugin injection, in this way it is possible to alter the behavior and the option for a term.

add_filter( 'glossary_default_term_parameters', function( $parameters, $term_id ) {
    return $parameters;
}, 10, 2 );

Only for PRO users

Change the separator in the Alphabetical Index shortcode.

add_filter( 'glossary_list_excerpt_separator', function() {
    return ' > ';
} );

You can use this filter in order to add/remove meta keys before print them inside the content of an article.

add_filter( 'glossary_customizer_fields_list', function( $fields ) {
    return $fields;
}, 10, 1 );

Change the field type for the native custom fields

add_filter( 'glossary_custom_field_type', function( $type, $field_id ) {
    return 'wysiwyg';
}, 10, 2 );

You can use the various types available on CMB2.

WooCommerce

Add support in WooCommerce short descriptions

add_filter( 'woocommerce_short_description', function( $excerpt ) {
    $search_engine = new Glossary\Frontend\CoreCore\Search_Engine;        
    return $search_engine->auto_link( $excerpt );
}, 10, 1 );