Skip to content

Commit

Permalink
Merge pull request #139 from NeilWJames/master
Browse files Browse the repository at this point in the history
Media Library URL’s change after plugin update
  • Loading branch information
benbalter authored Jan 14, 2019
2 parents 2d09397 + 85fd98f commit bdc1f30
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 22 deletions.
12 changes: 6 additions & 6 deletions includes/class-wp-document-revisions.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class WP_Document_Revisions {
*
* @var String $version
*/
public $version = '3.2.0';
public $version = '3.2.1';

/**
* The WP default directory cache
Expand All @@ -64,7 +64,7 @@ class WP_Document_Revisions {
*
* @since 3.2
*/
public static $doc_image = false;
public static $doc_image = true;

/**
* Identify if processing document or image directory
Expand Down Expand Up @@ -268,7 +268,7 @@ public function register_cpt() {
}

// Set Global for Document Image from Cookie doc_image (may be updated later)
self::$doc_image = ( isset( $_COOKIE['doc_image'] ) ? 'true' === $_COOKIE['doc_image'] : false );
self::$doc_image = ( isset( $_COOKIE['doc_image'] ) ? 'true' === $_COOKIE['doc_image'] : true );

}

Expand Down Expand Up @@ -1201,7 +1201,7 @@ public function document_upload_dir_filter( $dir ) {

if ( ! $this->verify_post_type() ) {
// Ensure cookie variable is set correctly - if needed elsewhere
self::$doc_image = false;
self::$doc_image = true;
return $dir;
}

Expand Down Expand Up @@ -1279,7 +1279,7 @@ public function filename_rewrite( $file ) {
// verify this is a document
// @codingStandardsIgnoreLine WordPress.Security.NonceVerification.NoNonceVerification
if ( ! isset( $_POST['post_id'] ) || ! $this->verify_post_type( $_POST['post_id'] ) ) {
self::$doc_image = false;
self::$doc_image = true;
return $file;
}

Expand Down Expand Up @@ -1330,7 +1330,7 @@ public function rewrite_file_url( $file ) {
// verify that this is a document
// @codingStandardsIgnoreLine WordPress.Security.NonceVerification.NoNonceVerification
if ( ! isset( $_POST['post_id'] ) || ! $this->verify_post_type( $_POST['post_id'] ) ) {
self::$doc_image = false;
self::$doc_image = true;
return $file;
}

Expand Down
17 changes: 12 additions & 5 deletions js/wp-document-revisions.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ class WPDocumentRevisions
@$('#misc-publishing-actions a').click @enableSubmit #if post status is changed, enable the submit button so the change can be saved
@$('input, select').on 'change', @enableSubmit #if any metabox is changed, allow submission
@$('input[type=text], textarea').on 'keyup', @enableSubmit #if any metabox is changed, allow submission
@$('#content-add_media').click @cookieFalse #click outside featured image area
@$('#poststuff').click @cookieFalse #set cookie false so load from document library
@$('#document').click @cookieFalse #ditto
@$('#postimagediv .inside').click @cookieTrue #click from within Featured Image metabox, set librry to image library
@$('#content-add_media').click @cookieFalse #click on upload document
@$('#postimagediv .inside').click @cookieTrue #click within Featured Image metabox, set library to image library
@$('#submitdiv .inside').click @cookieDelete #click within Submit metabox, remove cookie for non-WPDR functions
@$('#adminmenumain').click @cookieDelete #click menu, remove cookie for non-WPDR functions as going elsewhere
@$('#wpadminbar').click @cookieDelete #click bar, remove cookie for non-WPDR functions as going elsewhere

@$('#document').show() #present the user with the docment upload box
@$('#revision-log').show() #present the user with the revision log box
@$('#revision-summary').hide() #initially hide the revision summary box
@bindPostDocumentUploadCB()
@hijackAutosave()
@cookieFalse() #start with cookie false, ie document not image
setInterval @updateTimestamps, 60000 #automatically refresh all timestamps every minute with actual human time diff

#monkey patch global autosave to our autosave
Expand All @@ -42,6 +43,7 @@ class WPDocumentRevisions

#enable submit buttons
enableSubmit: =>
@$('#revision-summary').show() #change made so show the summary for comment
@$(':button, :submit', '#submitpost').removeAttr 'disabled'

#notify user of success by adding the post upload notice before the #post div
Expand Down Expand Up @@ -172,6 +174,11 @@ class WPDocumentRevisions
@$(':button, :submit', '#submitpost').removeAttr 'disabled'
# Propagation will be stopped in postimagediv to stop document event setting cookie false.

cookieDelete = =>
secure = 'https:' == window.location.protocol
wpCookies.set 'doc_image', 'true', -1, false, false, secure
@$(':button, :submit', '#submitpost').removeAttr 'disabled'
# Propagation will be stopped in postimagediv to stop document event setting cookie false.

#loop through all timestamps and update
updateTimestamps: =>
Expand Down
16 changes: 12 additions & 4 deletions js/wp-document-revisions.coffee2
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@hijackAutosave = bind(@hijackAutosave, this)
@cookieFalse = bind(@cookieFalse, this)
@cookieTrue = bind(@cookieTrue, this)
@cookieDelete = bind(@cookieDelete, this)
@$ = $
@$('.revision').click @restoreRevision
@$('#override_link').click @overrideLock
Expand All @@ -30,14 +31,15 @@
@$('input, select').on 'change', @enableSubmit
@$('input[type=text], textarea').on 'keyup', @enableSubmit
@$('#content-add_media').click @cookieFalse
@$('#poststuff').click @cookieFalse
@$('#document').click @cookieFalse
@$('#postimagediv .inside').click @cookieTrue
@$('#submitdiv .inside').click @cookieDelete
@$('#adminmenumain').click @cookieDelete
@$('#wpadminbar').click @cookieDelete
@$('#document').show()
@$('#revision-log').show()
@$('#revision-summary').hide()
@bindPostDocumentUploadCB()
@hijackAutosave()
@cookieFalse()
setInterval @updateTimestamps, 60000
return

Expand All @@ -55,6 +57,7 @@
return

WPDocumentRevisions::enableSubmit = ->
@$('#revision-summary').show()
@$(':button, :submit', '#submitpost').removeAttr 'disabled'
@window.jQuery('#lock_override').prev().fadeIn()

Expand Down Expand Up @@ -161,6 +164,11 @@
# Propagation will be stopped in postimagediv to stop document event setting cookie false.
return

WPDocumentRevisions::cookieDelete = ->
secure = 'https:' == window.location.protocol
wpCookies.set 'doc_image', 'true', -1, false, false, secure
return

WPDocumentRevisions::updateTimestamps = ->
@$('.timestamp').each ((_this) ->
->
Expand Down Expand Up @@ -194,4 +202,4 @@
).call this

# ---
# generated by js2coffee 2.2.0
# generated by js2coffee 2.2.0
14 changes: 11 additions & 3 deletions js/wp-document-revisions.dev.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/wp-document-revisions.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bdc1f30

Please sign in to comment.