Skip to content

Instantly share code, notes, and snippets.

@davidallenlewis
Last active September 16, 2024 19:39
Show Gist options
  • Save davidallenlewis/a75c6cbd2056b9db060a93343e0fda9d to your computer and use it in GitHub Desktop.
Save davidallenlewis/a75c6cbd2056b9db060a93343e0fda9d to your computer and use it in GitHub Desktop.
Patches for WP Display Files Plugin version Version 4.0.8 from WePlugins
<?php
// @PATCH for /inc/listing/class-wpdf-downloader.php starting on line 52
// Allows shortcode files to download properly when a user has multiple roles or one role that is not zero-indexed
$current_user_info = wp_get_current_user();
$user_roles = $current_user_info->roles;
$user_id = $current_user_info->data->ID;
if( ! empty( $permissions['wpdf_user_names'] ) && ! empty($permissions['wpdf_user_roles'] ) ) {
if ( ! in_array( $user_id, $permissions['wpdf_user_names'] ) && ! array_intersect( $user_roles, $permissions['wpdf_user_roles'] ) ) {
wp_die( $msg );
}
} else if( ! empty( $permissions['wpdf_user_names'] ) ) {
if ( ! in_array( $user_id, $permissions['wpdf_user_names'] ) ) {
wp_die( $msg );
}
} else if( ! empty( $permissions['wpdf_user_roles'] ) ) {
if ( ! array_intersect( $user_roles, $permissions['wpdf_user_roles'] ) ) {
wp_die( $msg );
}
}
// @PATCH for /modules/display/modal.display.php starting on line 194
// Allows shortcode files to show properly if more than one user name is assigned (and no role)
$wpdf_user_names = explode(',', $this->shortcode->wpdf_permissions_setting['wpdf_user_names'][0]);
//if ( ! in_array( $user_id, $this->shortcode->wpdf_permissions_setting['wpdf_user_names'] ) ) {
if ( ! in_array( $user_id, $wpdf_user_names ) ) {
$this->display_content = false;
}
// @PATCH for /modules/display/modal.display.php starting on line 201
// Allows shortcode files to show properly when a user has multiple roles or one role that is not zero-indexed
} else if ( ! empty( $this->shortcode->wpdf_permissions_setting['wpdf_user_roles'] ) && $this->shortcode->wpdf_permissions_setting['wpdf_user_roles'][0] != 'all' ) {
$user_roles = $current_user_info->roles;
if( ! empty( $this->shortcode->wpdf_permissions_setting['wpdf_user_names'] ) ) {
$user_id = $current_user_info->data->ID;
if ( ! in_array( $user_id, $this->shortcode->wpdf_permissions_setting['wpdf_user_names'] ) && empty( array_intersect( $user_roles, $this->shortcode->wpdf_permissions_setting['wpdf_user_roles']) ) ) {
$this->display_content = false;
}
}else{
if ( empty( array_intersect( $user_roles, $this->shortcode->wpdf_permissions_setting['wpdf_user_roles'] ) ) ) {
$this->display_content = false;
}
}
}
// @PATCH for /inc/listing/class-wpdf-frontend-listing.php starting on line 1298
// Comment this line to prevent file size calculation PHP warnings that slow page down when logged is enabled
@array_walk_recursive($array, array($this,'wpdf_check_file_size') );
// @PATCH for /wp-content/plugins/pdf-viewer-for-wpdf/assets/js/wpdf-pdf-viewer.js on line 16
// Allows PDFs to render in higher resolution so they are not too blurry to read
//scale = 1,
scale = 3,
// @PATCH for /wp-content/plugins/pdf-viewer-for-wpdf/pdf-viewer-for-wpdf.php
// @HACK by David Lewis - add timestamp to URLs to prevent browser caching of same-named files
// Line 77
//<li><a href="javascript:void(0);" class="display_pdf_file" data-pdf-url = '.$download_url.' ></a></li>
<li><a href="javascript:void(0);" class="display_pdf_file" data-pdf-url="'.$download_url. $url.'&time='.time().'"></a></li>
// Line 196
// @HACK by David Lewis - add timestamp to URLs to prevent browser caching of same-named files
/*
$action_html.= '<div class="action_list_b">
<a href="javascript:void(0);" class="render_pdf_btn" data-file-name="'. $shortcode->current_file_name.'" data-pdf-url ="'. $url.'"> </a>
</div>
';
*/
$action_html.= '<div class="action_list_b"><a href="javascript:void(0);" class="render_pdf_btn" data-file-name="'. $shortcode->current_file_name.'" data-pdf-url="'. $url.'&time='.time().'"></a></div>';
@davidallenlewis
Copy link
Author

The original code uses $current_user_info->roles[0]; which will break functionality (permission checkes) if a user account has multiple roles or one role that is not zero-indexed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment