LLMS_Admin_Media_Protection_Attachment_Settings::attachment_fields_to_edit( array $form_fields, object $post )

Add the media protection settings to the attachment edit screen


Parameters Parameters

$form_fields

(array) (Required) Array of form fields

$post

(object) (Required) WP_Post object


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/admin/class-llms-admin-media-protection-attachment-settings.php

	public function attachment_fields_to_edit( $form_fields, $post ) {

		$selected_product_html = $protection_warning_html = '';
		$selected_product_id   = get_post_meta( $post->ID, '_llms_media_protection_product_id', true );
		if ( $selected_product_id && ( $selected_product      = get_post( $selected_product_id ) ) ) {
			$selected_product_html = sprintf( '<option value="%d" selected="selected">%s</option>', $selected_product->ID, $selected_product->post_title );
		}

		$protector = new LLMS_Media_Protector();
		if ( ! $protector->is_media_protected( $post->ID ) ) {
			// translators: %s is a link to the LifterLMS documentation.
			$protection_warning_html = '<div class="llms-media-protection-warning">' . sprintf( __( 'This media is not protected. If you select a product here, the media will be moved to the protected uploads directory and existing links to the media will no longer work. %1$sLearn More%2$s', 'lifterlms' ), '<a target="_blank" href="https://lifterlms.com/docs/how-protected-media-files-work/?utm_source=LifterLMS%20Plugin&utm_medium=Media&utm_campaign=Backend%20Help%20Page">', '</a>' ) . '</div>';
		}

		$form_fields['llms_media_protection_post'] = array(
			'label' => __( 'LifterLMS Media Protection:', 'lifterlms' ),
			'input' => 'html',
			// TODO: Add selected course/membership to the select2 dropdown if known for this attachment post.
			'html'  => "$protection_warning_html<select id='attachments-" . $post->ID . "-llms_media_protection_post' class='llms-posts-select2' data-no-view-button='true' data-allow_clear='false' data-post-type='course,llms_membership' name='attachments[" . $post->ID . "][llms_media_protection_post]'>$selected_product_html</select>",
			'helps' => $protector->is_media_protected( $post->ID ) ? sprintf( __( 'Access is restricted to the selected course/membership. %1$sLearn More%2$s', 'lifterlms' ), '<a target="_blank" href="https://lifterlms.com/docs/how-protected-media-files-work/?utm_source=LifterLMS%20Plugin&utm_medium=Media&utm_campaign=Backend%20Help%20Page">', '</a>' ) : '',
		);

		/**
		 * Filter the LifterLMS media protection attachment field.
		 *
		 * @since 10.0.0
		 *
		 * @param array                $field     Attachment field definition.
		 * @param WP_Post              $post      Attachment post object.
		 * @param LLMS_Media_Protector $protector Media protector instance.
		 */
		$form_fields['llms_media_protection_post'] = apply_filters( 'llms_media_protection_attachment_field', $form_fields['llms_media_protection_post'], $post, $protector );

		return $form_fields;
	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.