diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..930aa14 --- /dev/null +++ b/composer.json @@ -0,0 +1,18 @@ +{ + "name": "wpackagist-plugin/multisite-post-duplicator", + "authors": [ + { + "name": "King & Partners", + "email": "technology@kingandpartners.com" + } + ], + "require": { + "composer/installers": "~1.0 || ~2.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.6", + "brain/monkey": "1.*", + "squizlabs/php_codesniffer": "~2.0 || ~3.0" + }, + "type": "wordpress-plugin" +} diff --git a/inc/mpd-functions.php b/inc/mpd-functions.php index 8b4b138..4d19449 100644 --- a/inc/mpd-functions.php +++ b/inc/mpd-functions.php @@ -29,7 +29,7 @@ function mpd_get_post_types_to_ignore(){ 'revision', 'nav_menu_item', //'attachment', - + ) ); @@ -53,7 +53,7 @@ function mpd_information_icon($c){ $u = uniqid(); ?> slug] = (object) $new_term; do_action( 'mpd_after_insert_term', $new_term, $post_term, $source_blog_id ); - + return $new_term['term_id']; } } /** - * + * * This function performs the action of setting the taxonomies of the source post and * to the destination post. * Works with mpd_get_post_taxonomy_terms(); @@ -1215,7 +1216,7 @@ function mpd_add_term_recursively( $post_term, &$orig_all_terms_by_id, &$all_ter * @since 0.9 * @param $post_id The ID of the newly created post * @param $source_taxonomy_terms_object An array of term objects used in the source post - * + * * @return array An array of term objects used in the post * */ @@ -1254,49 +1255,49 @@ function mpd_set_post_taxonomy_terms( $post_id, $source_taxonomy_terms_object, $ } /** - * + * * This function filters out post meta keys from the post meta as requested in the 'keys to ignore' mpd settings page. * * @since 0.9 * @param $post_meta_array The source post post_meta - * + * * @return array A filtered array without the keys as specified in 'keys to ignore' in mpd settings * */ function mpd_ignore_custom_meta_keys($post_meta_array){ - + $options = get_option( 'mdp_settings' ); - + $meta_to_ignore_raw = str_replace(' ', '', $options['mdp_ignore_custom_meta']); $meta_to_ignore = explode(',', $meta_to_ignore_raw); $new_post_meta = array(); - + foreach($post_meta_array as $meta_key => $meta_value){ - + if(!in_array($meta_key, $meta_to_ignore)){ $new_post_meta[$meta_key] = $meta_value; - + } - + } - + return $new_post_meta; - + } add_filter('mpd_filter_post_meta', 'mpd_ignore_custom_meta_keys'); add_filter('mpd_filter_persist_post_meta', 'mpd_ignore_custom_meta_keys'); /** - * + * * This function gets An 'edit url' for a post. * * @since 1.0 * @param $blog_id The blog_id where the post is * @param $post_id The post_id you want to link to - * + * * @return string An edit url for a post * */ @@ -1316,13 +1317,13 @@ function mpd_get_version(){ } /** - * + * * If the user chooses to, this function will collect the post date to of the source post to be used later * in mpd_set_published_date() to assign the published date to be the same as the destination. * * @since 0.9.4 * @param $mpd_process_info Array of the source post information - * + * * @return array A filtered array of source post information * */ @@ -1333,7 +1334,7 @@ function mpd_get_published_date($mpd_process_info){ if(isset($options['mdp_retain_published_date'])){ $mpd_process_info['post_date'] = get_post_field('post_date', $mpd_process_info['source_post_id']); } - + return $mpd_process_info; } @@ -1341,13 +1342,13 @@ function mpd_get_published_date($mpd_process_info){ add_filter('mpd_source_data', 'mpd_get_published_date'); /** - * + * * If the user chooses to, this function will set the post date to of the source post to the destination post. Note we have to set the post_status to publish for this activity as no published date would be assigned otherwise. * * @since 0.9.4 * @param $mdp_post Array of the destination post info prior to post being created in database * @param $mpd_process_info Array of the source post information - * + * * @return array A filtered array of destination post information prior to post being saved in database * */ @@ -1361,7 +1362,7 @@ function mpd_set_published_date($mdp_post, $mpd_process_info){ $mdp_post['post_status'] = 'publish'; } - + return $mdp_post; } @@ -1387,14 +1388,14 @@ function mpd_update_published_date($mpd_post, $persist_post) { } return $mpd_post; - + } add_filter('mpd_setup_persist_destination_data', 'mpd_update_published_date', 10, 2); /** - * + * * Do the markup for a link to MDP setting page * * @since 1.0 @@ -1407,7 +1408,7 @@ function mpd_do_settings_link(){ Settings - +

base_prefix . $siteid . $table; return $tablename; } /** - * + * * UI Function which provides a button to select all checkboxes in the MPD post metabox * * @since 1.5 - * + * * @return null * */ function mpd_select_all_checkboxes(){ if(apply_filters('mpd_show_select_all_checkboxes', true)) :?> - + '){ + + if(jQuery(this).html() == ''){ jQuery('#mpd_blogschecklist input:checkbox:not(.mpd-current-site)').prop('checked', 'checked'); jQuery(this).html(''); }else{ jQuery(this).html(''); jQuery('#mpd_blogschecklist input:checkbox').removeProp('checked'); } - - jQuery('#mpd_blogschecklist .mpd-site-checkbox input').trigger('change'); + + jQuery('#mpd_blogschecklist .mpd-site-checkbox input').trigger('change'); }); }); - get_current_blog_id(), @@ -1619,7 +1620,7 @@ function mpd_process_persist( $post_id, $destination_id, $created_post = false){ 'destination_post_id' => $created_post['id'] ); - + mpd_add_persist($args); } @@ -1630,9 +1631,9 @@ function mpd_process_persist( $post_id, $destination_id, $created_post = false){ function mpd_skip_standard_duplication($choice){ if(get_option('skip_standard_dup')){ - + delete_option('skip_standard_dup' ); - + return $choice = false; } @@ -1644,7 +1645,7 @@ function mpd_skip_standard_duplication($choice){ add_filter('mpd_do_single_metabox_duplication', 'mpd_skip_standard_duplication', 20); //Note priority higher than mpd_copy_acf_field_group() /** - * + * * Hooks into mpd_enter_the_loop funciton and set the conditions in which the multisite * post duplication processes can be accessed * @@ -1652,13 +1653,13 @@ function mpd_skip_standard_duplication($choice){ * @param boolean $choice The initial state if we are allowed into the loop * @param array $post_global the global post object on the form submit * @param int $post_id the ID of the post being saved - * + * * @return boolean The desision to continue or not * */ function mpd_enter_the_loop($choice, $post_global, $post_id){ - if(( isset($post_global["post_status"] ) ) + if(( isset($post_global["post_status"] ) ) && ( $post_global["post_status"] != "auto-draft" ) && ( isset($post_global['mpd_blogs'] ) ) && ( count( $post_global['mpd_blogs'] ) ) @@ -1673,13 +1674,13 @@ function mpd_enter_the_loop($choice, $post_global, $post_id){ add_filter('mpd_enter_the_loop', 'mpd_enter_the_loop', 10, 3); /** - * + * * Get media URL on any sub site by ID * * @since 1.6.5 * @param int $ID The ID of the media we want the URL of * @param int $source_blog The blog id this media file resides. - * + * * @return string The URL of the media file * */ @@ -1694,14 +1695,14 @@ function mpd_wp_get_attachment_url($ID, $source_blog){ } /** - * + * * Log the duplication of a media file by creating two meta files * * @since 1.6.6 * @param int $attach_id The ID of the media we want to log * @param int $source_id The blog id this media file resides. * @param int $source_attachment_id The original ID of the image on the source site - * + * * @return null * */ @@ -1720,7 +1721,7 @@ function mpd_log_media_file($attach_id, $source_id, $source_attachment_id){ add_action('mpd_media_image_added', 'mpd_log_media_file', 10, 3); /** - * + * * Check if a copy of a media file exists on another blog * Uses the logging structure as set in mpd_log_media_file(); * @@ -1728,7 +1729,7 @@ function mpd_log_media_file($attach_id, $source_id, $source_attachment_id){ * @param int $source_file_id The ID of the media we want to check * @param int $source_id The blog id this media file resides. * @param int $destination_id The blog id to check if there is a copy on - * + * * @return booleon True if it does exist and false if it doesn't * */ @@ -1773,9 +1774,9 @@ function mpd_does_file_exist($source_file_id, $source_id, $destination_id){ }else{ return false; - } + } } - + } return false; @@ -1809,4 +1810,4 @@ function mpd_process_meta( $post_id, $meta_values ) { } } } -} \ No newline at end of file +}