### Install Node.js Dependencies Source: https://github.com/rtcamp/rtmedia/wiki/Guidelines-for-Contribution Install Node.js dependencies required for development. Run these commands in your project's root directory. ```bash npm install npm install --dev ``` -------------------------------- ### Start Selenium Server Source: https://github.com/rtcamp/rtmedia/blob/develop/tests/codeception/README.md Launch the standalone Selenium server. This is required for WebDriver to function. ```bash java -jar selenium-server-standalone-3.4.0.jar ``` -------------------------------- ### Start BrowserStack Local Source: https://github.com/rtcamp/rtmedia/blob/develop/tests/codeception/README.md Enable local testing with BrowserStack by running the BrowserStackLocal binary. Replace 'yourkey' with your actual BrowserStack access key. ```bash ./BrowserStackLocal --key yourkey ``` -------------------------------- ### PHP Function Documentation Example Source: https://github.com/rtcamp/rtmedia/wiki/Guidelines-for-Contribution Example of a PHP function with proper PHPDoc comments, including parameter and return type hints. Adheres to WordPress coding standards. ```php /** * Example function with proper documentation. * * @since n.e.x.t * @param string $param1 Description of parameter. * @param int $param2 Description of parameter. * @return bool Description of return value. * */ public function example_function( string $param1, int $param2 ): bool { // Implementation } ``` -------------------------------- ### Translatable String Example Source: https://github.com/rtcamp/rtmedia/wiki/Guidelines-for-Contribution Example of a translatable string in PHP using the __() function and sprintf for dynamic content. Includes a translator comment for context and specifies the 'buddypress-media' text domain. ```php /* translators: %s: Image title */ $message = sprintf( __( 'Image "%s" uploaded successfully', 'buddypress-media' ), $title ); ``` -------------------------------- ### JavaScript React Component Example Source: https://github.com/rtcamp/rtmedia/wiki/Guidelines-for-Contribution Example of a React component written in JavaScript, using JSDoc for type hinting and documentation. Follows WordPress JavaScript coding standards. ```javascript /** * Example React component. * * @param {Object} props - Component props. * @param {string} props.title - The title to display. * @return {JSX.Element} The component JSX. */ const ExampleComponent = ( { title } ) => { return

{ title }

; }; ``` -------------------------------- ### Get Array of Enabled Upload Type Names Source: https://context7.com/rtcamp/rtmedia/llms.txt Get a simple array containing the names of media types that are currently enabled for upload. ```php $type_names = rtmedia_get_allowed_upload_types_array(); // ['photo','video','music'] ``` -------------------------------- ### Conventional Commits Example Source: https://github.com/rtcamp/rtmedia/wiki/Guidelines-for-Contribution Follow the Conventional Commits specification for commit messages. This standardizes the commit history, making it easier to understand changes and automate changelog generation. ```bash feat(media): add 4k media support fix(video): resolve timeout issues docs(readme): update installation guide style(php): fix indentation refactor(api): improve error handling perf(media): optimize thumbnail generation test(unit): add media migration tests chore(deps): update action-scheduler ``` -------------------------------- ### Get All Registered Media Types Source: https://context7.com/rtcamp/rtmedia/llms.txt Retrieve an array of all media types configured in rtMedia, including their extensions, thumbnail settings, and labels. ```php $all_types = rtmedia_get_allowed_types(); /* [ 'photo' => ['name'=>'photo','extn'=>['jpg','jpeg','png','gif'],'thumbnail'=>'...','plural_label'=>'Photos'], 'video' => ['name'=>'video','extn'=>['mp4','mov','avi',...],'thumbnail'=>'...','plural_label'=>'Videos'], 'music' => ['name'=>'music','extn'=>['mp3','ogg','wav',...],'thumbnail'=>'...','plural_label'=>'Music'], ... ] */ ``` -------------------------------- ### Custom Media Delete Permission Override Source: https://context7.com/rtcamp/rtmedia/llms.txt Override the default media delete permission using a filter. This example allows users with 'moderate_comments' capability to delete any media. ```php add_filter( 'rtmedia_media_delete_priv', function( $allowed ) { if ( current_user_can( 'moderate_comments' ) ) { return true; // allow moderators to delete any media } return $allowed; }); ``` -------------------------------- ### Run Codeception Tests (Vendor Path) Source: https://github.com/rtcamp/rtmedia/blob/develop/tests/codeception/README.md Execute acceptance tests when the vendor/bin directory is not in the system's PATH. This explicitly calls the wpcept executable. ```bash vendor/bin/wpcept run acceptance exampleCept.php ``` -------------------------------- ### Run Codeception Tests Source: https://github.com/rtcamp/rtmedia/blob/develop/tests/codeception/README.md Execute acceptance tests using the wpcept command. Ensure you are in the codeception directory. ```bash wpcept run acceptance exampleCept.php ``` -------------------------------- ### Add wp-plugin-dev-lib using Git Subtree Source: https://github.com/rtcamp/rtmedia/blob/develop/bin/readme.md Use this command to add the library to your project's bin directory via Git subtree. ```bash git subtree add --prefix bin \ git@github.com:x-team/wp-plugin-dev-lib.git master --squash ``` -------------------------------- ### Symlink .travis.yml and .jshintrc Source: https://github.com/rtcamp/rtmedia/blob/develop/bin/readme.md Symlink configuration files from the library's bin directory to your project's root. Remember to add them to Git. ```bash ln -s bin/.travis.yml . && git add .travis.yml ln -s bin/.jshintrc . && git add .jshintrc ``` -------------------------------- ### Run Development Scripts Source: https://github.com/rtcamp/rtmedia/wiki/Guidelines-for-Contribution Execute development scripts using npx and grunt. Use 'watch' for continuous development, 'grunt' for development builds, and 'grunt build' for production builds. Generate translation files with 'wp i18n make-pot'. ```bash npx grunt watch ``` ```bash npx grunt ``` ```bash npx grunt build ``` ```bash wp i18n make-pot . languages/buddpress-media.pot ``` -------------------------------- ### Control Gallery Shortcode Rendering Source: https://context7.com/rtcamp/rtmedia/llms.txt The 'before_rtmedia_gallery_display' filter can be used to conditionally prevent the gallery shortcode from rendering. This example hides the gallery from logged-out users. ```php add_filter( 'before_rtmedia_gallery_display', function( $flag ) { return is_user_logged_in() ? $flag : false; // hide from logged-out users }); ``` -------------------------------- ### Get Enabled Upload Media Types Source: https://context7.com/rtcamp/rtmedia/llms.txt Retrieve an array of media types that are currently enabled for uploads. This is useful for dynamically configuring upload interfaces. ```php $upload_types = rtmedia_get_allowed_upload_types(); ``` -------------------------------- ### Modify SQL WHERE Clause in Media Queries Source: https://context7.com/rtcamp/rtmedia/llms.txt Customize the SQL WHERE clause for media queries using the 'rtmedia-model-where-query' filter. This example restricts results to only public media. ```php add_filter( 'rtmedia-model-where-query', function( $where, $table_name, $join ) { $where .= " AND {$table_name}.privacy = 0 "; // show only public media return $where; }, 10, 3 ); ``` -------------------------------- ### Push Changes to wp-plugin-dev-lib using Git Subtree Source: https://github.com/rtcamp/rtmedia/blob/develop/bin/readme.md Use this command to push your local changes back to the library's repository. ```bash git subtree push --prefix bin \ git@github.com:x-team/wp-plugin-dev-lib.git master ``` -------------------------------- ### Clone rtMedia Repository Source: https://github.com/rtcamp/rtmedia/wiki/Guidelines-for-Contribution Clone the rtMedia repository to your local machine. This command should be run in your terminal. ```bash git clone https://github.com/rtCamp/rtmedia.git buddypress-media cd buddypress-media ``` -------------------------------- ### Override Media Delete Permission Source: https://context7.com/rtcamp/rtmedia/llms.txt Control delete permissions for media using the 'rtmedia_media_delete_priv' filter. This example allows users with 'edit_others_posts' capability to delete media. ```php add_filter( 'rtmedia_media_delete_priv', function( $allowed ) { return $allowed || current_user_can( 'edit_others_posts' ); }); ``` -------------------------------- ### Get rtMedia Privacy Symbol Source: https://context7.com/rtcamp/rtmedia/llms.txt Retrieves the HTML icon for a media item's privacy level. Ensure privacy is enabled site-wide before using privacy-related functions. ```php // Privacy levels: // 0 = Public (anyone) // 20 = All Members (logged-in users) // 40 = Friends only (BuddyPress friends) // 60 = Only me (private) // 80 = Blocked (temporarily hidden) // Get the HTML icon for a media item's privacy: $privacy_icon = get_rtmedia_privacy_symbol( 42 ); echo wp_kses( $privacy_icon, [ 'i' => [ 'class' => [], 'title' => [] ] ] ); // Outputs: ``` ```php // Check if privacy is enabled site-wide: if ( is_rtmedia_privacy_enable() ) { // Render the privacy selector UI for editing: $privacymodel = new RTMediaPrivacy( false ); $select_html = $privacymodel->select_privacy_ui( false ); echo wp_kses( $select_html, RTMedia::expanded_allowed_tags() ); } ``` ```php // Get the site-wide default privacy level: $default_privacy = get_rtmedia_default_privacy(); // returns 0, 20, 40, or 60 ``` ```php // Check if current user can override privacy on a per-item basis: if ( is_rtmedia_privacy_user_overide() ) { echo rtmedia_edit_media_privacy_ui(); // renders dropdown for edit page } ``` -------------------------------- ### Update wp-plugin-dev-lib using Git Subtree Source: https://github.com/rtcamp/rtmedia/blob/develop/bin/readme.md Use this command to pull the latest changes from the library into your project. ```bash git subtree pull --prefix bin \ git@github.com:x-team/wp-plugin-dev-lib.git master --squash ``` -------------------------------- ### Query Media with RTMediaModel::get() Source: https://context7.com/rtcamp/rtmedia/llms.txt Use RTMediaModel::get() to fetch media records from the database. Supports filtering by various criteria, meta queries, pagination, ordering, and count mode. Ensure RTMediaModel is instantiated. ```php $model = new RTMediaModel(); // Fetch all photos by a specific user, newest first: $photos = $model->get( [ 'media_author' => 8, 'media_type' => 'photo', 'context' => 'profile', 'context_id' => 8, ], 0, // offset 20, // per_page 'media_id desc' ); foreach ( $photos as $photo ) { echo $photo->id; // rtMedia ID echo $photo->media_id; // WordPress attachment post ID echo $photo->media_title; echo $photo->privacy; // 0, 20, 40, 60, or 80 $url = wp_get_attachment_url( $photo->media_id ); } // Get media with meta query: $tagged = $model->get([ 'media_author' => 8, 'meta_query' => [ [ 'key' => 'custom_source', 'value' => 'my_integration', 'compare' => '=', ], ], ]); // Count all videos in a BuddyPress group: $count = $model->get( [ 'context' => 'group', 'context_id' => 3, 'media_type' => 'video' ], false, false, 'media_id desc', true // count_flag = true ); echo "Total videos: $count"; ``` -------------------------------- ### Get Comma-Separated Upload Type Extensions Source: https://context7.com/rtcamp/rtmedia/llms.txt Obtain a comma-separated string of file extensions for all enabled upload types. This format is commonly used for client-side file upload filters like Plupload. ```php $exts = get_rtmedia_allowed_upload_type(); // 'jpg,jpeg,png,gif,mp4,...' ``` -------------------------------- ### Dynamically Add or Remove Allowed Media Types Source: https://context7.com/rtcamp/rtmedia/llms.txt Use the 'rtmedia_allowed_types' filter to dynamically manage which media types are permitted for upload. For example, to disable music uploads, unset the 'music' key. ```php add_filter( 'rtmedia_allowed_types', function( $types ) { unset( $types['music'] ); // disable music uploads return $types; }); ``` -------------------------------- ### Run Code Before/After Template Load Source: https://context7.com/rtcamp/rtmedia/llms.txt The 'rtmedia_before_template_load' and 'rtmedia_after_template_load' action hooks can be used to inject content, such as headers or footers, before or after the template is loaded. ```php add_action( 'rtmedia_before_template_load', function() { /* inject header */ }); ``` ```php add_action( 'rtmedia_after_template_load', function() { /* inject footer */ }); ``` -------------------------------- ### Run Code After Single Media Render Source: https://context7.com/rtcamp/rtmedia/llms.txt The 'rtmedia_after_photo' action hook executes code after a single media item is rendered, allowing for the injection of elements like share buttons. ```php add_action( 'rtmedia_after_photo', function( $media_id ) { echo '
'; }); ``` -------------------------------- ### Display rtMedia Uploader Shortcode Source: https://github.com/rtcamp/rtmedia/blob/develop/readme.txt Use the `[rtmedia_uploader]` shortcode to display a drag-and-drop uploader in any WordPress area, including posts, pages, and custom post types. Ensure the rtMedia plugin is installed and activated. ```shortcode [rtmedia_uploader] ``` -------------------------------- ### rtmedia_gallery() / have_rtmedia() / rtmedia() Source: https://context7.com/rtcamp/rtmedia/llms.txt Template loop functions for iterating over media items within a template, similar to the WordPress loop. ```APIDOC ## Template Loop API ### Description The WordPress-loop-style API for iterating over media items within a template. Used inside custom templates to display gallery thumbnails, titles, links, and metadata. ### Functions - `have_rtmedia()`: Checks if there are more media items in the loop. - `rtmedia()`: Advances the media loop pointer and sets the global `$rtmedia_media` object. - `rtmedia_gallery()`: Initializes the media loop (often called implicitly or before `have_rtmedia`). ### Usage These functions are designed to be used within a WordPress template file. ### Request Example ```php // In a custom template or theme file, render a media loop: if ( have_rtmedia() ) : while ( have_rtmedia() ) : rtmedia(); // advances the pointer, sets $rtmedia_media global ?>
<?php rtmedia_image_alt(); ?>

By:

Album:

No media found.

'; endif; ``` ### Response This API primarily affects the template output by providing access to media item data within the loop. ``` -------------------------------- ### Get Media Identity Information Source: https://context7.com/rtcamp/rtmedia/llms.txt Use rtmedia_id(), rtmedia_media_id(), and rtmedia_type() to retrieve the rtMedia ID, WordPress attachment ID, and media type respectively. These functions can be used within the media loop or with an explicit ID. ```php // Within the media loop or on a single-media page: $rtm_id = rtmedia_id(); // rtMedia table row ID (e.g., 42) $post_id = rtmedia_media_id(); // WP attachment post ID (e.g., 189) $type = rtmedia_type(); // 'photo', 'video', 'music', 'album' // By explicit rtMedia ID: $post_id = rtmedia_media_id( 42 ); $type = rtmedia_type( 42 ); $ext = rtmedia_media_ext( 42 ); // 'jpg', 'mp4', 'mp3', etc. // Convert WP attachment ID to rtMedia ID: $rtm_id = rtmedia_id( 189 ); // Get the full permalink to a specific media item: $url = get_rtmedia_permalink( 42 ); echo esc_url( $url ); // e.g. https://example.com/members/john/media/42/ // Get activity ID associated with media: $activity_id = rtmedia_activity_id( 42 ); ``` -------------------------------- ### rtmedia_add_media() Function Source: https://context7.com/rtcamp/rtmedia/llms.txt Programmatically uploads a media file and inserts it into the rtMedia database. Accepts an array of upload parameters equivalent to a POST submission. Returns the new rtMedia ID on success or `false` on failure. ```APIDOC ## rtmedia_add_media() — Programmatically upload and add media Uploads a media file and inserts it into the rtMedia database. Accepts an array of upload parameters equivalent to a POST submission. Returns the new rtMedia ID on success or `false` on failure. ### Parameters: `$upload_params` (array) - An associative array of upload parameters. - `media_author` (int) - WordPress user ID of the media author. - `album_id` (int) - rtMedia album ID to associate the media with. - `context` (string) - The context for the media (e.g., 'profile', 'group'). - `context_id` (int) - The ID related to the context (e.g., user ID for 'profile', group ID for 'group'). - `privacy` (int) - Privacy level for the media (0=public, 20=members, 40=friends, 60=private). - `media_title` (string) - The title of the media. - `mode` (string) - The upload mode, typically 'file_upload'. ### Return Value: (int|false) - The new rtMedia ID on success, or `false` on failure. ### Example: ```php // Upload a media file programmatically (e.g., from a form handler): $upload_params = [ 'media_author' => 12, // WordPress user ID 'album_id' => 45, // rtMedia album ID 'context' => 'profile', 'context_id' => 12, 'privacy' => 0, // 0=public, 20=members, 40=friends, 60=private 'media_title' => 'My Photo', 'mode' => 'file_upload', ]; // $_FILES['rtmedia_file'] must be populated before calling $media_id = rtmedia_add_media( $upload_params ); if ( $media_id ) { $permalink = get_rtmedia_permalink( $media_id ); echo 'Uploaded! View at: ' . esc_url( $permalink ); // Add custom metadata to the new media item: add_rtmedia_meta( $media_id, 'custom_source', 'my_integration' ); } else { echo 'Upload failed.'; } ``` ``` -------------------------------- ### Media Type Configuration Source: https://context7.com/rtcamp/rtmedia/llms.txt Provides functions to retrieve the currently allowed media types and their configurations, including extensions, thumbnail settings, and labels. This is useful for custom upload interfaces and file validation. ```APIDOC ## `rtmedia_get_allowed_types()` / `rtmedia_get_allowed_upload_types()` — Media type configuration Functions for reading the current allowed media types and their settings (extensions, thumbnails, labels) from rtMedia options. Essential for building custom upload UIs or validating files before upload. ```php // Get all registered media types (photo, video, music, etc.): $all_types = rtmedia_get_allowed_types(); /* [ 'photo' => ['name'=>'photo','extn'=>['jpg','jpeg','png','gif'],'thumbnail'=>'...','plural_label'=>'Photos'], 'video' => ['name'=>'video','extn'=>['mp4','mov','avi',...],'thumbnail'=>'...','plural_label'=>'Videos'], 'music' => ['name'=>'music','extn'=>['mp3','ogg','wav',...],'thumbnail'=>'...','plural_label'=>'Music'], ... ] */ // Get only the types that are currently enabled for upload: $upload_types = rtmedia_get_allowed_upload_types(); // Get names array of enabled upload types: $type_names = rtmedia_get_allowed_upload_types_array(); // ['photo','video','music'] // Get comma-separated extension string for Plupload filter: $exts = get_rtmedia_allowed_upload_type(); // 'jpg,jpeg,png,gif,mp4,...' // Individual type checks: if ( is_rtmedia_upload_photo_enabled() ) { /* show photo tab */ } if ( is_rtmedia_upload_video_enabled() ) { /* show video tab */ } if ( is_rtmedia_upload_music_enabled() ) { /* show audio tab */ } if ( is_rtmedia_upload_document_enabled() ) { /* show document tab (Premium) */ } // Determine media type from a file extension: $type = rtmedia_get_media_type_from_extn( 'mp4' ); // returns 'video' $ext = rtmedia_get_extension( $media_post_id ); // returns 'jpg', 'mp3', etc. ``` ``` -------------------------------- ### Programmatically Upload Media with rtmedia_add_media() Source: https://context7.com/rtcamp/rtmedia/llms.txt Use rtmedia_add_media() to upload media files programmatically. Pass an array of parameters similar to a POST submission. The function returns the new rtMedia ID on success or false on failure. ```php $upload_params = [ 'media_author' => 12, 'album_id' => 45, 'context' => 'profile', 'context_id' => 12, 'privacy' => 0, 'media_title' => 'My Photo', 'mode' => 'file_upload', ]; $media_id = rtmedia_add_media( $upload_params ); if ( $media_id ) { $permalink = get_rtmedia_permalink( $media_id ); echo 'Uploaded! View at: ' . esc_url( $permalink ); add_rtmedia_meta( $media_id, 'custom_source', 'my_integration' ); } else { echo 'Upload failed.'; } ``` -------------------------------- ### RTMediaModel::get() Source: https://context7.com/rtcamp/rtmedia/llms.txt Queries media records from the database with support for filtering, meta queries, pagination, ordering, and count mode. Returns an array of media objects. ```APIDOC ## RTMediaModel::get() ### Description The core data-access method for retrieving media records from the `rt_rtm_media` table. Supports filtering by any column, meta queries, pagination, ordering, and count mode. Returns an array of media objects. ### Parameters - `array $params` (array) - Associative array of parameters for filtering media. - `int|bool $offset` - The number of records to skip (for pagination). - `int|bool $per_page` - The number of records to return per page. - `string $order_by` - The column to order the results by, followed by 'asc' or 'desc'. - `bool $count_flag` - If true, returns the total count of matching records instead of the records themselves. ### Request Example ```php $model = new RTMediaModel(); // Fetch all photos by a specific user, newest first: $photos = $model->get( [ 'media_author' => 8, 'media_type' => 'photo', 'context' => 'profile', 'context_id' => 8, ], 0, // offset 20, // per_page 'media_id desc' ); // Get media with meta query: $tagged = $model->get([ 'media_author' => 8, 'meta_query' => [ [ 'key' => 'custom_source', 'value' => 'my_integration', 'compare' => '=', ], ], ]); // Count all videos in a BuddyPress group: $count = $model->get( [ 'context' => 'group', 'context_id' => 3, 'media_type' => 'video' ], false, false, 'media_id desc', true // count_flag = true ); ``` ### Response - `array` - An array of media objects if `$count_flag` is false. - `int` - The total count of matching media records if `$count_flag` is true. ``` -------------------------------- ### Render Media Galleries with Template Loop API Source: https://context7.com/rtcamp/rtmedia/llms.txt Use rtmedia_gallery(), have_rtmedia(), and rtmedia() within WordPress templates to loop through and display media items. Ensure the loop functions are called within a conditional check for media availability. ```php // In a custom template or theme file, render a media loop: if ( have_rtmedia() ) : while ( have_rtmedia() ) : rtmedia(); // advances the pointer, sets $rtmedia_media global ?>
<?php rtmedia_image_alt(); ?>

By:

Album:

No media found.

'; endif; ``` -------------------------------- ### Conventional Commit Message Format Source: https://github.com/rtcamp/rtmedia/wiki/Guidelines-for-Contribution Illustrates the conventional commit message format, including type, optional scope, description, optional body, and optional footer(s). ```git [optional scope]: [optional body] [optional footer(s)] ``` -------------------------------- ### Export Shortcode (Direct) Uploads Source: https://context7.com/rtcamp/rtmedia/llms.txt Exports media uploads made directly via shortcodes for a specified user. ```APIDOC ## Export Shortcode Uploads ### Description Exports media uploads made directly via shortcodes for a specified user. ### Method PHP Function Call ### Function Signature `rtmedia_shortcode_upload_exporter( string $email, int $page = 1 ): array` ### Parameters #### Path Parameters - **email** (string) - Required - The email address of the user. - **page** (int) - Optional - The page number for pagination. Defaults to 1. ``` -------------------------------- ### Export User's rtMedia Activity Uploads Source: https://context7.com/rtcamp/rtmedia/llms.txt Exports a user's rtMedia activity uploads. The result is paginated and includes data and a 'done' flag. ```APIDOC ## Export rtMedia Activity Uploads ### Description Exports a user's rtMedia activity uploads. The result is paginated and includes data and a 'done' flag. ### Method PHP Function Call ### Function Signature `rtmedia_activity_exporter( string $email, int $page = 1 ): array` ### Parameters #### Path Parameters - **email** (string) - Required - The email address of the user whose data to export. - **page** (int) - Optional - The page number for pagination. Defaults to 1. ### Response #### Success Response - **data** (array) - An array of media data, where each item contains 'group_id', 'item_id', and 'data'. - **done** (bool) - Indicates if all data has been exported. ```