Skip to content

Commit 81a9b1f

Browse files
authored
Merge pull request #126 from Patreon/1_8_1_release
1 8 1 release
2 parents 4d509c4 + c707103 commit 81a9b1f

File tree

5 files changed

+80
-11
lines changed

5 files changed

+80
-11
lines changed

classes/patreon_options.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ function patreon_plugin_setup_page(){
286286
<th scope="row">
287287
<strong>Enable image locking features</strong>
288288
<br>
289-
<div class="patreon-options-info">If on, you will be able to lock your images and provide patron only images anywhere in your posts like webcomics or visual content. If you aren't using image locking or having complications due to your web host infrastructure, you can keep this feature off. Whenever you turn this feature on or off, you should visit 'Permalinks' settings in your WordPress site and save your permalinks just once by clicking 'Save'. Otherwise your images may appear broken.</div>
289+
<div class="patreon-options-info">If on, you will be able to lock your images and provide patron only images anywhere in your posts like webcomics or visual content. This may use noticeable server resources at your web host. If you aren't using image locking or having complications due to your web host infrastructure, you turn this feature off. Whenever you turn this feature on or off, you should visit 'Permalinks' settings in your WordPress site and save your permalinks just once by clicking 'Save'. Otherwise your images may appear broken.</div>
290290
</th>
291291
<td>
292292
<input type="checkbox" name="patreon-enable-file-locking" value="1"<?php checked( get_option( 'patreon-enable-file-locking', false ) ); ?> />

classes/patreon_protect.php

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ public static function servePatronOnlyImage( $image=false ) {
196196

197197
// Check if image exists in media library
198198

199-
$attachment_id = attachment_url_to_postid( $image );
199+
$attachment_id = Patreon_Protect::get_attachment_id_from_url( $image );
200200

201-
// attachment_url_to_postid returns 0 if it cant find the attachment post id
201+
// The above returns 0 if it cant find the attachment post id
202202

203203
if ( $attachment_id == 0 ) {
204204

@@ -731,9 +731,9 @@ public function makeAttachmentPledgeEditor( $attachment_id = false ) {
731731
}
732732
// Get attachment from attachment url.
733733

734-
$attachment_id = attachment_url_to_postid( $attachment_url );
734+
$attachment_id = Patreon_Wordpress::get_attachment_id_from_url( $attachment_url );
735735

736-
// attachment_url_to_postid returns 0 if it cant find the attachment post id
736+
// The above returns 0 if it cant find the attachment post id
737737

738738
if ( $attachment_id == 0 ) {
739739

@@ -836,9 +836,9 @@ public function ParseContentForProtectedImages( $content ) {
836836

837837
foreach ( $images as $key => $value ) {
838838

839-
$attachment_id = attachment_url_to_postid( $images[$key] );
839+
$attachment_id = Patreon_Protect::get_attachment_id_from_url( $images[$key] );
840840

841-
// attachment_url_to_postid returns 0 if it cant find the attachment post id
841+
// The above returns 0 if it cant find the attachment post id
842842

843843
if ( $attachment_id == 0 ) {
844844

@@ -940,5 +940,64 @@ public static function checkPatronPledgeForImage( $attachment_id, $user = false
940940
return 0;
941941

942942
}
943+
// Taken and modified from https://wordpress.stackexchange.com/questions/6645/turn-a-url-into-an-attachment-post-id/7094#7094
944+
// wp attachment_url_to_postid fails for intermediate size images at the time of this commit - this is a replacement
945+
public static function get_attachment_id_from_url( $url ) {
946+
947+
$dir = wp_upload_dir();
948+
949+
// baseurl never has a trailing slash
950+
if ( false === strpos( $url, $dir['baseurl'] . '/' ) ) {
951+
// URL points to a place outside of upload directory
952+
return 0;
953+
}
954+
955+
$file = basename( $url );
956+
$query = array(
957+
'post_type' => 'attachment',
958+
'fields' => 'ids',
959+
'meta_query' => array(
960+
array(
961+
'key' => '_wp_attached_file',
962+
'value' => $file,
963+
'compare' => 'LIKE',
964+
),
965+
)
966+
);
967+
968+
// query attachments
969+
$ids = get_posts( $query );
970+
971+
if ( ! empty( $ids ) ) {
972+
973+
foreach ( $ids as $id ) {
974+
975+
// first entry of returned array is the URL
976+
if ( $url === array_shift( wp_get_attachment_image_src( $id, 'full' ) ) )
977+
return $id;
978+
}
979+
}
980+
981+
$query['meta_query'][0]['key'] = '_wp_attachment_metadata';
982+
983+
// query attachments again
984+
$ids = get_posts( $query );
985+
986+
if ( empty( $ids) )
987+
return 0;
988+
989+
foreach ( $ids as $id ) {
990+
991+
$meta = wp_get_attachment_metadata( $id );
992+
993+
foreach ( $meta['sizes'] as $size => $values ) {
994+
995+
if ( $values['file'] === $file && $url === array_shift( wp_get_attachment_image_src( $id, $size ) ) )
996+
return $id;
997+
}
998+
}
999+
1000+
return 0;
1001+
}
9431002

9441003
}

classes/patreon_wordpress.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ public static function AdminMessages() {
951951

952952
// The addon upsell must be admin wide, permanently dismissable, and must not appear in plugin manager page in admin
953953

954-
if( !$pcm_addon_upsell_shown AND !self::check_plugin_exists('patron-content-manager') AND $current_screen->id != 'plugins' AND ( (self::check_days_after_last_non_system_notice( 7 ) AND self::calculate_days_after_first_activation( 30 ) ) OR $existing_install ) AND !$already_showed_non_system_notice AND !isset($GLOBALS['patron_content_manager_pitch_being_shown']) ) {
954+
if( !$pcm_addon_upsell_shown AND !self::check_plugin_exists('patron-content-manager') AND $current_screen->id != 'plugins' AND ( (self::check_days_after_last_non_system_notice( 7 ) AND self::calculate_days_after_first_activation( 30 ) ) OR $existing_install ) AND !$already_showed_non_system_notice AND !isset($GLOBALS['patron_content_manager_pitch_being_shown']) AND !is_plugin_active( 'patron-plugin-pro/index.php' )) {
955955

956956
?>
957957
<div class="notice notice-success is-dismissible patreon-wordpress" id="patron_content_manager_pitch_shown"><p><div style="display: flex; flex-wrap: wrap; flex-direction: row;"><a href="https://codebard.com/patron-content-manager?utm_source=<?php urlencode( site_url() ) ?>&utm_medium=patreon_wordpress&utm_campaign=&utm_content=patreon_wordpress_addon_upsell_notice_patron_content_manager&utm_term=" target="_blank"><img class="addon_upsell" src="<?php echo PATREON_PLUGIN_ASSETS ?>/img/Easily-manage-gated-posts.jpg" style="width:200px; height:106px;margin: 10px; border: 1px solid #000000; margin-right: 20px;" alt="Patron Content Manager" /></a><div style="max-width: 700px; width: 100%;"><div style="max-width:500px; width: auto; float:left; display:inline-box"><h2 style="margin-top: 0px; font-size: 150%; font-weight: bold;">Easily manage your patron only content with Patron Content Manager</h2></div><div style="width:100%; font-size: 125% !important;clear:both; ">Get new <a href="https://codebard.com/patron-content-manager?utm_source=<?php urlencode( site_url() ) ?>&utm_medium=patreon_wordpress&utm_campaign=&utm_content=patreon_wordpress_addon_upsell_notice_patron_content_manager&utm_term=" target="_blank">Patron Content Manager</a> plugin for Patreon and easily re-gate content, gate old content, use detailed locking options, use content locking wizard to manage your patron only content & increase your patrons and pledges.<br /><br /><a href="https://codebard.com/patron-content-manager?utm_source=<?php urlencode( site_url() ) ?>&utm_medium=patreon_wordpress&utm_campaign=&utm_content=patreon_wordpress_addon_upsell_notice_patron_content_manager&utm_term=" target="_blank">Check out all features here</a></div></div></div></p>

patreon.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Plugin Name: Patreon Wordpress
55
Plugin URI: https://www.patreon.com/apps/wordpress
66
Description: Patron-only content, directly on your website.
7-
Version: 1.8.0
7+
Version: 1.8.1
88
Author: Patreon <[email protected]>
99
Author URI: https://patreon.com
1010
*/
@@ -68,7 +68,7 @@
6868
define( "PATREON_CREATOR_BYPASSES_FILTER_MESSAGE", 'This content is for Patrons only, it\'s not locked for you because you are logged in as the Patreon creator' );
6969
define( "PATREON_NO_LOCKING_LEVEL_SET_FOR_THIS_POST", 'Post is already public. If you would like to lock this post, please set a pledge level for it' );
7070
define( "PATREON_NO_POST_ID_TO_UNLOCK_POST", 'Sorry - could not get the post id for this locked post' );
71-
define( "PATREON_WORDPRESS_VERSION", '1.8.0' );
71+
define( "PATREON_WORDPRESS_VERSION", '1.8.1' );
7272
define( "PATREON_WORDPRESS_BETA_STRING", '' );
7373
define( "PATREON_WORDPRESS_PLUGIN_SLUG", plugin_basename( __FILE__ ) );
7474
define( "PATREON_PRIVACY_POLICY_ADDENDUM", '<h2>Patreon features in this website</h2>In order to enable you to use this website with Patreon services, we save certain functionally important Patreon information about you in this website if you log in with Patreon.

readme.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Tags: patreon, membership, members
44
Requires at least: 4.0
55
Requires PHP: 5.4
66
Tested up to: 5.8.1
7-
Stable tag: 1.8.0
7+
Stable tag: 1.8.1
88
License: GPLv2 or later
99
License URI: https://www.gnu.org/licenses/gpl-2.0.html
1010

@@ -79,6 +79,11 @@ It is difficult to protect videos due the intensive bandwidth requirements of h
7979

8080
== Upgrade Notice ==
8181

82+
= 1.8.1 =
83+
84+
* Enhanced post id detection from attachment url. This will address various issues those who are using image locking were having with smaller size thumbnails of locked images, or non locked images of smaller attachment sizes.
85+
* Hid the PCM addon upsell notification when PP addon is active
86+
8287
= 1.8.0 =
8388

8489
* Made the post syncer not overwrite $ level if an existing post has it. This will prevent overriding of already set post tier values with.
@@ -438,6 +443,11 @@ Nothing will be changed at your site - the plugin will just connect your site to
438443

439444
== Changelog ==
440445

446+
= 1.8.1 =
447+
448+
* Enhanced post id detection from attachment url. This will address various issues those who are using image locking were having with smaller size thumbnails of locked images, or non locked images of smaller attachment sizes.
449+
* Hid the PCM addon upsell notification when PP addon is active
450+
441451
= 1.8.0 =
442452

443453
* Made the post syncer not overwrite $ level if an existing post has it. This will prevent overriding of already set post tier values with.

0 commit comments

Comments
 (0)