• Resolved tweakben

    (@tweakben)


    Hi David,

    You have probably created the most configurable plugin I’ve ever seen in WordPress history. The amount of options you have are insane. And that’s great. ?? I’m hoping you can help me figure out what I’m doing wrong.

    I use a plugin called rtMedia Pro which allows wordpress users to upload videos and pictures. It allows them to set attributes as they call them, which is essentially a media taxonomy.

    What it doesnt allow you to do, is view media by the taxonomy, which is where my problem comes in and I’m looking to your plugin to resolve.

    There is a main attribute and then the sub-attributes. When you click “Library” in wp-admin, you’ll see “Houses” as a taxonomy on the menu. If you click it, it shows the available sub-taxonomy such as “Mobile Homes”, “Mansions”, etc… The URL shows the main taxonomy name is “rt_houses” and each of the sub-taxonomys have a “tag_ID=XXX” associated with them.

    How do I make a shortcode that would show media in the Houses taxonomy, with the sub-taxonomy of “Mobile Homes” and only show pictures or only show videos? (There will be a separate page for pictures, a separate page for videos)

    I’m so lost and confused. If you can help steer me in a general direction to get them working it would be greatly appreciated.

    Regards,

    Ben

    https://www.ads-software.com/plugins/media-library-assistant/

Viewing 6 replies - 16 through 21 (of 21 total)
  • Plugin Author David Lingren

    (@dglingren)

    Thanks for confirming your use of BuddyPress. I will try setting up a test site to see if I can replicate your URL issues.

    The Support Forum moderator has removed your Skype Username from your post, to conform to the privacy policies of the forum. You can give me your e-mail address and other contact information by visiting the Contact Us page at our web site:

    Fair Trade Judaica/Contact Us

    I will keep you posted on my progress. Thanks for your patience.

    Plugin Author David Lingren

    (@dglingren)

    I have set up a BuddyPress/rtMedia Pro test site and made quite a bit of investigative progress.

    The URLs assigned to the [mla_gallery] items are generated by WordPress using its permalink conventions for “attachment pages”. You can see the same URL in the “Permalink:” entry just below the Title field in the Media/Edit Media admin screen for any of the items you upload through rtMedia.

    There is no Theme support for displaying these attachment pages, so you get a “Not Found” page when you use the Permalink to access them. You can get this result of you click “View Attachment Page” on the Media/Edit Media admin screen.

    The rtMedia plugins use the WordPress Media Library, but do not store media items in the “normal” WordPress upload directories. Instead, rtMedia creates its own directory, /wp-content/uploads/rtmedia/, and sub-directories within it organized by BuddyPress user, year and month. You can see this in the “File URL:” field in the Save meta box on the Media/Edit Media admin screen.

    The rtMedia plugins also use their own database structures to organize media items into albums and and access their “rtMedia Attachment Page”. Your https://www.DOMAIN.com/members/alexa/media/4/ example shows this “rtMedia Permalink” structure. In your example, the “4” element is the id value in the rt_rtm_rtmedia database table, and “alexa” is the WordPress user_nicename of the item’s member/owner/author. In the rt_rtm_rtmedia table you can find the media_id column, which contains the WordPress attachment ID value and the media_author column, which contains the ID value in the WordPress users table.

    To generate the “rtMedia Permalink” URLs requires an SQL query that links the WordPress attachment ID to the rtMedia “id” value and the author information. The query can be added to the “MLA Gallery Filters and Actions (Hooks)” in the example plugin you can find in the Settings/Media Library Assistant Documentation tab. Once that’s done it is easy to substitute the rtMedia Permalink for the WordPress Permalink and get the results you want.

    If you are willing to add the example plugin and the additional code to your site, let me know. I can complete the required work and send it to you once I have your contact information. I will also post it here so everyone can benefit from it.

    The solution to your needs is similar to another rtMedia support request in this recent Support Forum Topic:

    help with OR query

    Let me know how you want to proceed. Thanks for hanging in there while I completed my investigations.

    Thread Starter tweakben

    (@tweakben)

    Thanks David! I just sent you a contact request from the website.

    Ben

    Plugin Author David Lingren

    (@dglingren)

    Ben,

    Thanks for getting in touch and working with me to complete an example plugin that generates the URLs you need and the video thumbnail images. I am adding a new example plugin, /examples/buddypress-hooks-example.php.txt, to my next MLA version. I hope you received the final copy of the plugin I sent by e-mail.

    Here is the new code for the filters that implement the two new features:

    public static function mla_gallery_wp_query_object_action( $query_arguments ) {
        //error_log( 'MLABuddyPressHooksExample::mla_gallery_wp_query_object_action $query_arguments = ' . var_export( $query_arguments, true ), 0 );
    
        self::$wp_query_properties = array();
        self::$wp_query_properties ['post_count'] = MLAShortcodes::$mla_gallery_wp_query_object->post_count;
    
        if ( empty( self::$shortcode_attributes['buddypress_urls'] ) ) {
            return; // Don't need custom URLs
        }
    
        if ( 0 == self::$wp_query_properties ['post_count'] ) {
            return; // Empty gallery - nothing to do
        }
    
        global $wpdb;
    
        // Assemble the WordPress attachment IDs
        $post_info = array();
        foreach( MLAShortcodes::$mla_gallery_wp_query_object->posts as $value ) {
            $post_info[ $value->ID ] = $value->ID;
        }
    
        // Build an array of SQL clauses, then run the query
        $query = array();
        $query_parameters = array();
    
        $query[] = "SELECT rtm.id, rtm.media_id, rtm.media_author, rtm.cover_art, u.user_nicename FROM {$wpdb->prefix}rt_rtm_media AS rtm";
        $query[] = "LEFT JOIN {$wpdb->users} as u";
        $query[] = "ON (rtm.media_author = u.ID)";
    
        $placeholders = array();
        foreach ( $post_info as $value ) {
            $placeholders[] = '%s';
            $query_parameters[] = $value;
        }
        $query[] = 'WHERE ( rtm.media_id IN (' . join( ',', $placeholders ) . ') )';
    
        $query =  join(' ', $query);
        $results = $wpdb->get_results( $wpdb->prepare( $query, $query_parameters ) );
    
        // Save the values, indexed by WordPress attachment ID, for use in the item filter
        $post_info = array();
        if ( is_array( $results ) ) {
            foreach ( $results as $value ) {
                $post_info[ $value->media_id ] = $value;
            }
        }
    
        self::$wp_query_properties ['post_info'] = $post_info;
    
        /*
         * Unlike Filters, Actions never return anything
         */
        return;
    } // mla_gallery_wp_query_object_action
    /**
     * MLA Gallery Item Values
     *
     * @since 1.00
     *
     * @param    array    parameter_name => parameter_value pairs
     *
     * @return    array    updated substitution parameter name => value pairs
     */
    public static function mla_gallery_item_values_filter( $item_values ) {
        //error_log( 'MLABuddyPressHooksExample::mla_gallery_item_values_filter $item_values = ' . var_export( $item_values, true ), 0 );
    
        /*
         * We use a shortcode parameter of our own to apply our filters on a gallery-by-gallery basis,
         * leaving other [mla_gallery] instances untouched. If the "my_filter" parameter is not present,
         * we have nothing to do.
         */
        if ( ! isset( self::$shortcode_attributes['buddypress_urls'] ) ) {
            return $item_values; // leave them unchanged
        }
    
        $use_cover_art = 'cover' == strtolower( trim( self::$shortcode_attributes['buddypress_urls'] ) );
    
        if ( isset( self::$wp_query_properties ['post_info'][ $item_values['attachment_ID'] ] ) ) {
            $post_info = self::$wp_query_properties ['post_info'][ $item_values['attachment_ID'] ];
        } else {
            return $item_values; // no matching rtMedia item
        }
    
        $new_url = $item_values['site_url'] . '/members/' . $post_info->user_nicename . '/media/' . $post_info->id . '/';
        $new_link = str_replace( $item_values['link_url'], $new_url, $item_values['link'] );
    
        // Add the "media thumbnail", if desired and present. Note that the size is fixed at 150x150 pixels.
        if ( $use_cover_art && ! empty( $post_info->cover_art ) ) {
            $new_thumbnail = '<img width="150" height="150" src="' . $post_info->cover_art . '" class="attachment-thumbnail" alt="' . $item_values['thumbnail_content'] . '" />';
            $new_link = str_replace( $item_values['thumbnail_content'] . '</a>', $new_thumbnail . '</a>', $new_link );
    
            $item_values['thumbnail_content'] = $new_thumbnail;
            $item_values['thumbnail_width'] = '150';
            $item_values['thumbnail_height'] = '150';
            $item_values['thumbnail_url'] = $post_info->cover_art;
        }
    
        $item_values['link_url'] = $new_url;
        $item_values['link'] = $new_link;
    
        return $item_values;
    } // mla_gallery_item_values_filter

    Please let me know if you have any problems or further questions about the work. Thanks for an interesting question and for working with me on a solution.

    Thanks especially for the donation you made in support of Fair Trade Judaica’s work!

    Plugin Author David Lingren

    (@dglingren)

    I have released MLA v1.90, which includes the new example plugin, /examples/buddypress-hooks-example.php.txt.

    Thanks again for your help and donation!

    Thread Starter tweakben

    (@tweakben)

    Best plugin support ever. Thank you David.

Viewing 6 replies - 16 through 21 (of 21 total)
  • The topic ‘Overwhelmed. Help my shortcode out? :)’ is closed to new replies.