Skip to content
This repository has been archived by the owner on Oct 31, 2022. It is now read-only.

Commit

Permalink
Merge pull request #9 from jaredcobb/1.0.3
Browse files Browse the repository at this point in the history
Delete featured images when posts are deleted, add post meta to images
  • Loading branch information
jaredcobb authored Feb 9, 2018
2 parents 7cd7c6d + a803641 commit 0867d8b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
9 changes: 7 additions & 2 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Contributors: jaredcobb
Tags: ccb, church, api, chms
Requires at least: 4.6.0
Tested up to: 4.9.2
Stable tag: 1.0.2
Tested up to: 4.9.4
Stable tag: 1.0.3
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -61,6 +61,11 @@ You'll need to ensure your [group settings](https://churchcommunitybuilder.force

== Changelog ==

= 1.0.3 =
* Featured images associated with synchronized posts now also get deleted when the post is deleted
* A new filter `ccb_core_synchronizer_delete_attachment` has been created to optionally overwrite the default behavior of deleting attachments when posts are deleted
* Any images that are synchronized automatically get a post meta key of `ccb_core` with a value of `true` (in case you need to programatically query for CCB images in the future)

= 1.0.2 =
* Fixed a bug to allow subdomains with dashes
* Remove PHP 5.4 array syntax from the main plugin file (prevent crashes on PHP < 5.4)
Expand Down
4 changes: 2 additions & 2 deletions ccb-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Plugin Name: Church Community Builder Core API
* Plugin URI: https://www.wpccb.com
* Description: A plugin to provide a core integration of the Church Community Builder API into WordPress custom post types
* Version: 1.0.2
* Version: 1.0.3
* Author: Jared Cobb
* Author URI: https://www.jaredcobb.com/
* License: GPL-2.0+
Expand All @@ -27,7 +27,7 @@
define( 'CCB_CORE_PATH', plugin_dir_path( __FILE__ ) );
define( 'CCB_CORE_URL', plugin_dir_url( __FILE__ ) );
define( 'CCB_CORE_BASENAME', plugin_basename( __FILE__ ) );
define( 'CCB_CORE_VERSION', '1.0.2' );
define( 'CCB_CORE_VERSION', '1.0.3' );

// Check minimum requirements before proceeding.
require_once CCB_CORE_PATH . 'includes/class-ccb-core-requirements.php';
Expand Down
14 changes: 10 additions & 4 deletions includes/class-ccb-core-helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,22 @@ public function download_image( $image_url, $filename = '', $post_id = 0 ) {
$media_id = media_handle_sideload( $file_array, $post_id );
remove_filter( 'upload_dir', [ $this, 'custom_uploads_directory' ] );

if ( $post_id ) {
set_post_thumbnail( $post_id, $media_id );
}

// phpcs:ignore
@unlink( $temp_file );

if ( ! is_wp_error( $media_id ) ) {
// Also attach the media to the post if a post id exists.
if ( $post_id ) {
set_post_thumbnail( $post_id, $media_id );
}

// Set post meta on the image to allow anyone to
// query for ccb specific images in the future.
update_post_meta( $media_id, 'ccb_core', true );

return $media_id;
}

}

return false;
Expand Down
18 changes: 18 additions & 0 deletions includes/class-ccb-core-synchronizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -711,13 +711,31 @@ public function delete_posts( $post_ids ) {
];

foreach ( $post_ids as $post_id ) {

/**
* Filters whether or not the attachment for this post should
* also be deleted.
*
* @since 1.0.3
*
* @param bool $delete Whether or not the attachment should be deleted.
* @param int $post_id The post id.
*/
if ( apply_filters( 'ccb_core_synchronizer_delete_attachment', true, $post_id ) ) {
$attachment_id = get_post_thumbnail_id( $post_id );
if ( $attachment_id ) {
wp_delete_attachment( $attachment_id, true );
}
}

$deleted = wp_delete_post( $post_id, true );
if ( ! $deleted ) {
$result['success'] = false;
$result['message'] = esc_html__( 'There was an error while attempting to delete orhpaned posts', 'ccb-core' );
return $result;
}
$result['processed'] += 1;

}
return $result;
}
Expand Down

0 comments on commit 0867d8b

Please sign in to comment.