Skip to content

Instantly share code, notes, and snippets.

@imath
Created March 14, 2016 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imath/672f3b81009a0f30c7b5 to your computer and use it in GitHub Desktop.
Save imath/672f3b81009a0f30c7b5 to your computer and use it in GitHub Desktop.
Snippet for imathi.eu/2014/09/30/wp-idea-stream-2-0/
<?php
/**
* Add links to share ideas on Twitter or by email
*/
function wpis_custom_sharing_services() {
// Only show sharing links on single templates
if ( ! wp_idea_stream_is_single_idea() ) {
return;
}
$share = array();
/** Twitter *******************************************************************/
// Change with your twitter account
$twitter_account = 'imath';
$twitter_args = array(
'original_referer' => urlencode( wp_idea_stream_ideas_get_permalink() ),
'source' => 'tweetbutton',
'text' => urlencode( wp_idea_stream_ideas_get_title() ),
'url' => urlencode( wp_idea_stream_ideas_get_permalink() ),
'via' => $twitter_account,
);
$tweet_url = esc_url( add_query_arg( $twitter_args, 'https://twitter.com/intent/tweet' ), null, 'display' );
$share['twitter'] = '<a href="' . $tweet_url . '" title="Share on Twitter" target="_blank" style="text-decoration:none"><span class="dashicons dashicons-twitter"></span> Share on Twitter</a>';
/** Email *******************************************************************/
$email_args = array(
'subject' => rawurlencode( wp_idea_stream_ideas_get_title() ),
'body' => wp_idea_stream_ideas_get_permalink(),
);
$email_url = esc_url( add_query_arg( $email_args, 'mailto:' ), null, 'display' );
$share['email'] = '<a href="' . $email_url . '" title="Share by Email" style="text-decoration:none"><span class="dashicons dashicons-email-alt"></span> Share by Email</a>';
echo join( '&nbsp;', $share );
}
add_action( 'wp_idea_stream_after_idea_footer', 'wpis_custom_sharing_services' );
/**
* Neutralize the built-in rating system
*/
add_filter( 'wp_idea_stream_is_rating_disabled', '__return_true' );
/**
* Register a new idea custom field
*/
function wpis_custom_register_metas() {
// A very simple way to add a custom field (for text field only)
wp_idea_stream_ideas_register_meta( 'simple_text', array( 'label' => 'Simple text' ) );
}
add_action( 'wp_idea_stream_init', 'wpis_custom_register_metas' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment