Actions and Filters

Here are the main actions and filters for Highlight and Share. They are documented in the code, but for now, here are some main ones, which will be fleshed out later.

//Example filter usage for highlight and share
//https://github.com/ronalfy/highlight-and-share

/* The following filters take and return booleans (true, false)*/
/* Call WordPress functions __return_false or __return_true */
add_filter( 'has_show_facebook', '__return_true' ); //Disable or enable facebook sharing
add_filter( 'has_show_twitter', '__return_true' ); //Disable or enable twitter sharing
add_filter( 'has_load_css', '__return_true' ); //Disable or enable plugin's CSS - Use your own
add_filter( 'has_enable_content', '__return_true' ); //Disable or enable main post content
add_filter( 'has_enable_excerpt', '__return_true' ); //Disable or enable excerpt content
add_filter( 'has_enable_mobile', '__return_true' ); //Disable or enable on mobile devices

/* Override the Facebook share text (default is Share) */
add_filter( 'has_facebook_text', 'has_override_facebook_text' );
function has_override_facebook_text( $default ) {
	return 'Facebook';
}

/* Override the Twitter share text (default is Tweet) */
add_filter( 'has_twitter_text', 'has_override_twitter_text' );
function has_override_twitter_text( $default ) {
	return 'Twitter';
}

/* Override the JavaScript classes (assuming jQuery class format with no periods) */
add_filter( 'has_js_classes', 'has_override_js_classes' );
function has_override_js_classes( $content ) {
	return 'entry-content,type-page,type-post';
}

/* Add JS IDs */
add_filter( 'has_js_ids', 'has_override_js_ids' );
function has_override_js_ids( $content = array() ) {
	if ( !is_array( $content ) ) $content = array();
	$new_arr = array( 'content', 'comments' );
	$content = array_merge( $content, $new_arr );
	return $content;
}

/* Add JS elements */
add_filter( 'has_js_elements', 'has_override_js_elements' );
function has_override_js_elements( $content = array() ) {
	if ( !is_array( $content ) ) $content = array();
	$new_arr = array( 'blockquote' );
	$content = array_merge( $content, $new_arr );
	return $content;
}

/* Override the Twitter username (no @ symbol needed) */
add_filter( 'has_twitter_username', 'has_override_twitter_username' );
function has_override_twitter_username( $username ) {
	return 'wordpress';
}

Disable on Front Page

add_action( 'wp', function() {
	if ( is_front_page() ) {
		add_filter( 'has_show_facebook', '__return_false' );
		add_filter( 'has_show_twitter', '__return_false' );
	}
} );

Modify the Content URL

add_filter( 'has_content_url', function( $url, $post_id ) {
	return 'https://wordpress.org';
}, 10, 2 );

Modifying jQuery Selectors

//Demonstrates how to select paragraph text only

add_filter( 'has_js_selectors', 'hs_custom_selectors', 10, 5 );
function hs_custom_selectors( $selectors, $content = array(), $classes = array(), $ids = array(), $elements = array() ) {
	//With $content, $classes, $ids, $elements, you can build your own selectors
	//Or just override $selectors (a string) with your own custom ones
	return '.has-content-area p, .has-excerpt-area p';
}

Last updated