Skip to content

Instantly share code, notes, and snippets.

@rahul3883
rahul3883 / functions.php
Last active May 26, 2017 07:30
Remove link from post title in member media page and group media page
<?php
/**
* Remove link from post title in member media page and group media page.
*/
function rtm_change_post_title_member_group_cb( $template, $new_rt_template ) {
global $wp_query, $post;
if ( ( 'bp_member' === $post->post_type || 'bp_group' === $post->post_type ) ) {
preg_match( '~>\K[^<>]*(?=<)~', $post->post_title, $matches );
if ( ! empty( $matches ) ) {
@rahul3883
rahul3883 / functions.php
Last active May 4, 2017 10:52
Remove 'All' tab from rtMedia's 'Media' tab and make 'Album' tab as a default tab
<?php
/**
* Change query var to fetch albums from database.
*
* @param array $query_vars Query vars.
* @return array Modified query vars.
*/
function rtm_change_query_var_cb( $query_vars ) {
global $wp_query;
if ( isset( $wp_query->query_vars['media'] ) && '' === $wp_query->query_vars['media'] ) {
@rahul3883
rahul3883 / functions.php
Last active April 17, 2017 07:04
Display album link on rtMedia's single media page
<?php
/**
* Display album name with permalink.
*
* @param $media_id Current media id for which we need to display the album link.
*/
function tmp_rtm_display_album_link( $media_id ) {
global $rt_ajax_request;
@rahul3883
rahul3883 / functions.php
Last active April 13, 2017 09:40
Sort media by rtMedia custom attributes
<?php
/**
* This code snippet enhances the sort functionality provided by rtMedia Sorting plugin by providing sorting using
* custom attributes that is created by rtMedia Custom Attributes plugin.
* Both rtMedia Custom Attributes and rtMedia Sorting plugins must be enabled for this code snippet to work.
*/
// Enter attribute slug here.
$rtm_attributes_slug = 'camera';
@rahul3883
rahul3883 / change-allowed-media-types-document.php
Created March 22, 2017 09:55
Allow only pdf documents on upload
<?php
/**
* Allow only pdf documents on upload.
*
* Only allow documents which has pdf extension.
*
* @param array $allowed_types Allowed types of media to upload.
*
* @return array Allowed types of media to upload
@rahul3883
rahul3883 / functions.php
Last active March 16, 2017 14:51
Display only particular media using `media_name` attribute of `rtmedia_gallery` shortcode
<?php
/**
* Magic begins from here
*/
function my_rtmedia_set_query_filters() {
add_filter( 'rtmedia_media_query', 'my_modify_media_query', 9, 3 );
}
add_action( 'rtmedia_set_query', 'my_rtmedia_set_query_filters', 99 );
/**
@rahul3883
rahul3883 / functions.php
Created March 15, 2017 12:11
Change order of media from descending to ascending
<?php
if ( ! function_exists( 'rtmedia_change_order_by_asc_callback' ) ) {
/**
* Change order of media from descending to ascending.
*
* This function changes the order by query string when
* media is uploaded from byssypress activity page or from uploader widget.
*
* @param string $qorderby order by query string
*