secret

Proof of concept for patch.

  • Download Gist
gistfile1.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
<?php
/**
* Media class for Soliloquy.
*
* @since 1.0.0
*
* @package Soliloquy
* @author Thomas Griffin
*/
class Tgmsp_Media {
 
/**
* Holds a copy of the object for easy reference.
*
* @since 1.0.0
*
* @var object
*/
private static $instance;
 
/**
* Constructor. Hooks all interactions to initialize the class.
*
* @since 1.0.0
*/
public function __construct() {
self::$instance = $this;
add_filter( 'media_view_strings', array( $this, 'media_strings' ) );
add_action( 'print_media_templates', array( $this, 'print_media_templates' ) );
add_filter( 'wp_prepare_attachment_for_js', array( $this, 'prepare_slides' ), 10, 3 );
add_action( 'wp_ajax_save_attachment', array( $this, 'save_attachment_fields' ), 10, 2 );
}
/**
* Modify WordPress media workflow strings to fit Soliloquy.
*
* @since 1.5.0
*
* @param array $strings Default strings
* @return array $strings Amended media strings
*/
public function media_strings( $strings ) {
if ( ! Tgmsp::is_soliloquy_add_edit_screen() )
return $strings;
// Modify existing strings.
$strings['insertMediaTitle'] = Tgmsp_Strings::get_instance()->strings['media_title'];
$strings['insertIntoPost'] = Tgmsp_Strings::get_instance()->strings['media_insert'];
$strings['uploadedToThisPost'] = Tgmsp_Strings::get_instance()->strings['media_uploaded'];
$strings['uploadFilesTitle'] = Tgmsp_Strings::get_instance()->strings['media_upload'];
// Remove unnecessary existing strings.
unset( $strings['createGalleryTitle'] );
unset( $strings['insertFromUrlTitle'] );
// Return the modified strings.
return $strings;
}
/**
* Output the custom media workflow templates for our custom slide types.
*
* @since 1.5.0
*/
public function print_media_templates() {
if ( ! Tgmsp::is_soliloquy_add_edit_screen() )
return;
// Custom template for attachment fields. ?>
<script type="text/html" id="tmpl-soliloquy-attachment-fields">
<label class="setting" data-setting="soliloquy_link">
<span><?php echo Tgmsp_Strings::get_instance()->strings['image_link']; ?></span>
<input type="text" value="{{ data.soliloquy_link }}" />
</label>
</script>
<?php
}
/**
* Filter the attachment response to include custom attachment metadata fields
* for Soliloquy slides.
*
* @since 1.5.0
*
* @param array $response Array of response data about the attachment
* @param object $$attachment The attachment object
* @param array $meta Array of attachment metadata
* @return array $response Amended $response array with our custom data
*/
public function prepare_slides( $response, $attachment, $meta ) {
// Return early if not on a Soliloquy post type.
$parent = get_post( $attachment->post_parent );
if ( $parent )
if ( 'soliloquy' !== $parent->post_type )
return $response;
// Add our custom metadata fields to the response array.
$response['soliloquy_link'] = get_post_meta( $attachment->ID, '_soliloquy_image_link', true );
// Return our amended response array.
return $response;
}
/**
* Saves custom attachment metadata when WordPress runs the update via Backbone.
*
* @since 1.5.0
*
* @param array $attachment Array of attachment data
* @param array $changes Changes that have been sent from the server
*/
public function save_attachment_fields( $attachment, $changes ) {
if ( ! empty( $changes['soliloquy_link'] ) )
update_post_meta( $attachment['ID'], '_soliloquy_image_link', esc_url( $changes['soliloquy_link'] ) );
}
/**
* Getter method for retrieving the object instance.
*
* @since 1.0.0
*/
public static function get_instance() {
return self::$instance;
}
 
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.