Shortcodes Generator

Overview

Use this tool to create custom code for Shortcodes with add_shortcode() function.

Usage

  • Fill in the user-friendly form.
  • Click the “Update Code” button.
  • Copy the code to your project.
  • Or save it as a snippet and share with the community.
Shortcode tag in the content.
e.g. [tag]
The function used in the code.
Self-closing shortcode: [tag]
Enclosing shortcode: [tag]content[/tag]
Enable attributes such as
[tag foo="123" bar="456"].
Use "shortcode_atts_{$shortcode}" filter, to allow shortcode attributes filtering.
Set custom filter name.
Attribute name. Lowercase.
Default value.
e.g. [tag attr_name="default_value"]
Attribute name. Lowercase.
Default value.
Attribute name. Lowercase.
Default value.
Custom code to generate the output.
Should only "return" the text, never produce the output directly.
  Save Snippet
// Add Shortcode
function missionary_private_message_() {

	/**
	 * Get the User Id in the current context
	 * @param int $user_id
	 * @return int user_id
	 */
	function hibuddy_get_context_user_id($user_id=false){
	 
	if ( bp_is_my_profile() || !is_user_logged_in() )
	 return false;
	 if( !$user_id )
	 $user_id = bp_get_member_user_id();//for members loop
	 if( !$user_id && bp_is_user() ) //for user profile
	 $user_id = bp_displayed_user_id();
	 
	 return apply_filters( 'hibuddy_get_context_user_id', $user_id );
	}
	
	function hibuddy_get_send_private_message_url() {
	 
	$user_id = hibuddy_get_context_user_id();
	 
	if( !$user_id || $user_id == bp_loggedin_user_id() )
	 return;
	 
	 if ( bp_is_my_profile() || !is_user_logged_in() )
	 return false;
	 
	return apply_filters( 'hibuddy_get_send_private_message_url', wp_nonce_url( bp_loggedin_user_domain() . bp_get_messages_slug() . '/compose/?r=' . bp_core_get_username( $user_id ) ) );
	}
	
	function hibuddy_get_send_private_message_button() {
	 //get the user id to whom we are sending the message
	 $user_id = hibuddy_get_context_user_id();
	 
	 //don't show the button if the user id is not present or the user id is same as logged in user id
	 if( !$user_id || $user_id == bp_loggedin_user_id() )
	 return;
	$defaults = array(
	 'id' => 'private_message-'.$user_id,
	 'component' => 'messages',
	 'must_be_logged_in' => true,
	 'block_self' => true,
	 'wrapper_id' => 'send-private-message-'.$user_id,
	 'wrapper_class' =>'send-private-message',
	 'link_href' => hibuddy_get_send_private_message_url(),
	 'link_title' => __( 'Send a private message to this user.', 'buddypress' ),
	 'link_text' => __( 'Private Message', 'buddypress' ),
	 'link_class' => 'send-message',
	 );
	 
	 $btn = bp_get_button( $defaults );
	 
	 return apply_filters( 'hibuddy_get_send_private_message_button', $btn );
	}
	
	function hibuddy_send_private_message_button() {
	 echo hibuddy_get_send_private_message_button();
	}

}
add_shortcode( '', 'missionary_private_message_' );