Composer usage with premium version

We use Freemius as service to ship our premium plugins and license management. This service offers a way to retrive 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

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 );

Interact with the tooltip 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.
 *
 * @return string $html The tooltip filtered.
 */
add_filter( 'glossary_tooltip_html', function( $tooltip, $excerpt, $photo, $post_id, $noreadmore ) {
    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

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;
}

Change the HTML tag that wraps every letter in the Alphabetical Bar (<span> is the default)

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

This filter changes the size of the featured image inside the tooltips

add_filter( 'glossary_tooltip_image', function( $size ) {
    return 'full';
}, 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 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;
}

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 );