Changeset 3313636
- Timestamp:
- 06/18/2025 06:35:31 AM (10 months ago)
- Location:
- duplicate-publish-multisite
- Files:
-
- 10 edited
- 1 copied
-
tags/1.7.5 (copied) (copied from duplicate-publish-multisite/trunk)
-
tags/1.7.5/includes/assets/category-publish.js (modified) (2 diffs)
-
tags/1.7.5/includes/class-admin-publishmu.php (modified) (3 diffs)
-
tags/1.7.5/includes/class-pubmult-settings.php (modified) (4 diffs)
-
tags/1.7.5/publish-multisite.php (modified) (2 diffs)
-
tags/1.7.5/readme.txt (modified) (1 diff)
-
trunk/includes/assets/category-publish.js (modified) (2 diffs)
-
trunk/includes/class-admin-publishmu.php (modified) (3 diffs)
-
trunk/includes/class-pubmult-settings.php (modified) (4 diffs)
-
trunk/publish-multisite.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
duplicate-publish-multisite/tags/1.7.5/includes/assets/category-publish.js
r3284609 r3313636 10 10 site_id = $(this).closest('.publishmu').find('.site-publish').val(); 11 11 strindex = $(this).closest('.publishmu').find('.category-publish').attr('for').replaceAll('][',',').replace('[','').replace(']','').split(','); 12 //let nonce = $( this ).closest('.publishmu').find('#nonce').val();13 let nonce = ajaxAction.nonce;14 12 15 13 $.ajax({ 16 14 type: 'POST', 17 url: ajaxAction.url,15 url: pubmult_ajaxAction.url, 18 16 data: { 19 17 action: 'category_publish', … … 23 21 taxonomy: taxpub.val(), 24 22 index: strindex[1], 25 nonce: nonce23 nonce: pubmult_ajaxAction.nonce 26 24 }, 27 25 beforeSend: function() { $(".category-publish-action .spinner").addClass("is-active"); }, -
duplicate-publish-multisite/tags/1.7.5/includes/class-admin-publishmu.php
r3157312 r3313636 151 151 // Get image data. 152 152 $post_thumbnail_id = get_post_thumbnail_id( $source_post_id ); 153 $image_url = wp_get_attachment_image_src( $post_thumbnail_id, 'full' ); 154 $uploads = wp_upload_dir(); 155 $source_image_path = str_replace( $uploads['baseurl'], $uploads['basedir'], $image_url[0] ); 156 153 154 if ( ! $post_thumbnail_id || ! wp_attachment_is_image( $post_thumbnail_id ) ) { 155 $is_image_changed = false; 156 } 157 158 $image_url = null; 159 $source_image_path = null; 160 161 if ($is_image_changed && $post_thumbnail_id) { 162 $image_url = wp_get_attachment_image_src($post_thumbnail_id, 'full'); 163 164 if ($image_url && is_array($image_url)) { 165 $uploads = wp_upload_dir(); 166 167 $source_image_path = get_attached_file( $post_thumbnail_id ); 168 169 if ( ! $source_image_path || ! file_exists( $source_image_path ) ) { 170 $source_image_path = str_replace( $uploads['baseurl'], $uploads['basedir'], $image_url[0] ); 171 $source_image_path = preg_replace( '/\?.*/', '', $source_image_path ); 172 error_log('Duplicate Publish Multisite - Source image not found directly. Using alternative path: ' . $source_image_path); 173 } 174 175 if ( ! file_exists( $source_image_path ) ) { 176 $is_image_changed = false; 177 error_log('Duplicate Publish Multisite - Source image file not found at: ' . $source_image_path); 178 } 179 } else { 180 $is_image_changed = false; 181 error_log('Duplicate Publish Multisite - Cannot get image URL for thumbnail ID: ' . $post_thumbnail_id); 182 } 183 } 157 184 // Copy data. 158 185 switch_to_blog( $target_site ); … … 227 254 * ## Thumbnail 228 255 * --------------------------- */ 229 if ( $is_image_changed ) {256 if ( $is_image_changed && $source_image_path && file_exists( $source_image_path ) ) { 230 257 // Add Featured Image to Post. 231 258 $upload_dir = wp_upload_dir(); 232 if ( is_array( $image_url ) ) { 233 $image_url = $image_url[0]; 234 $filename = basename( $image_url ); 235 236 // Check folder permission and define file location. 237 if ( wp_mkdir_p( $upload_dir['path'] ) ) { 238 $target_image_path = $upload_dir['path'] . '/' . $filename; 239 } else { 240 $target_image_path = $upload_dir['basedir'] . '/' . $filename; 241 } 242 243 // Copies to target folder. 244 copy( $source_image_path, $target_image_path ); 245 259 $source_image_path_clean = preg_replace('/\?.*/', '', $source_image_path); 260 $filename = basename($source_image_path_clean); 261 262 $target_dir = $upload_dir['path']; 263 if ( ! file_exists( $target_dir ) ) { 264 wp_mkdir_p( $target_dir ); 265 } 266 267 $target_image_path = $upload_dir['path'] . '/' . $filename; 268 269 $copy_success = false; 270 271 if( copy( $source_image_path, $target_image_path ) ) { 272 $copy_success = true; 273 } else { 274 error_log('Duplicate Publish Multisite - Direct copy failed. Trying file_get_contents/file_put_contents'); 275 276 $file_content = @file_get_contents($source_image_path); 277 if ($file_content !== false) { 278 if (file_put_contents($target_image_path, $file_content) !== false) { 279 $copy_success = true; 280 } 281 } 282 } 283 284 if ( $copy_success ) { 246 285 // Check image file type. 247 286 $wp_filetype = wp_check_filetype( $filename, null ); … … 269 308 // And finally assign featured image to post. 270 309 set_post_thumbnail( $target_post_id, $attach_id ); 310 } else { 311 error_log('Failed to copy image from ' . $source_image_path . ' to ' . $target_image_path); 271 312 } 272 313 } -
duplicate-publish-multisite/tags/1.7.5/includes/class-pubmult-settings.php
r3158731 r3313636 80 80 wp_localize_script( 81 81 'category-publish', 82 ' ajaxAction',82 'pubmult_ajaxAction', 83 83 array( 84 84 'url' => admin_url( 'admin-ajax.php' ), … … 219 219 $term = isset( $_POST['taxonomy'] ) ? sanitize_key( $_POST['taxonomy'] ) : ''; 220 220 221 if ( check_ajax_referer( 'category_publish_nonce', 'nonce' ) ) { 222 $html_tax = ''; 223 $taxonomies = HELPER::get_taxonomies( $post_type ); 224 foreach ( $taxonomies as $key => $value ) { 225 $html_tax .= '<option value="' . esc_html( $key ) . '"'; 226 if ( $key === $taxonomy_parent ) { 227 $html_tax .= ' selected'; 228 } 229 $html_tax .= '>' . esc_html( $value ) . '</option>'; 221 $valid_nonce = false; 222 if (isset($_POST['nonce'])) { 223 $valid_nonce = wp_verify_nonce($_POST['nonce'], 'category_publish_nonce'); 224 } 225 if (!$valid_nonce) { 226 wp_send_json_error(array('error' => 'Invalid nonce')); 227 return; 228 } 229 230 $html_tax = ''; 231 $taxonomies = HELPER::get_taxonomies( $post_type ); 232 foreach ( $taxonomies as $key => $value ) { 233 $html_tax .= '<option value="' . esc_html( $key ) . '"'; 234 if ( $key === $taxonomy_parent ) { 235 $html_tax .= ' selected'; 230 236 } 231 232 // Options Source Terms.233 $html_source_term = ''; 234 $source_site_id = get_current_blog_id();235 foreach ( HELPER::get_terms_from( $source_site_id, $taxonomy_parent, $post_type ) as $key => $value ) {236 $html_source_term .= '<option value="' . esc_html( $key ) . '"';237 if ( $key === $term) {238 $html_source_term .= ' selected';239 }240 $html_source_term .= ' >' . esc_html( $value ) . '</option>';237 $html_tax .= '>' . esc_html( $value ) . '</option>'; 238 } 239 240 // Options Source Terms. 241 $html_source_term = ''; 242 $source_site_id = get_current_blog_id(); 243 foreach ( HELPER::get_terms_from( $source_site_id, $taxonomy_parent, $post_type ) as $key => $value ) { 244 $html_source_term .= '<option value="' . esc_html( $key ) . '"'; 245 if ( $key === $term ) { 246 $html_source_term .= ' selected'; 241 247 } 242 243 // Options Target Terms.244 $html_target_term = ''; 245 foreach ( HELPER::get_terms_from( $site_id, $taxonomy_parent, $post_type ) as $key => $value ) {246 $html_target_term .= '<p><input type="checkbox"';247 $html_target_term .= ' name="publish_mu_setttings[musite][' . esc_html( $index ) . '][target_cat_' . esc_html( $key ) . ']" id="' . esc_html( $key ) . '"';248 $html_target_term .= ' value="' . esc_html( $key ) . '"';249 $html_target_term .= '/><label for="' . esc_html( $key ) . '">' . esc_html( $value ) . '</label></p>';250 }251 252 // Options Target author.253 $html_auth = ''; 254 foreach ( HELPER::get_authors_from( $site_id ) as $key => $value ) {255 $html_auth .= '<option value="' . esc_html( $key ) . '">' . esc_html( $value ) . '</option>';256 }257 error_log( 'return: ' . print_r( array( $html_tax, $html_source_term, $html_target_term, $html_auth ) , true ) );258 wp_send_json_success( array( $html_tax, $html_source_term, $html_target_term, $html_auth ) );259 } else {260 wp_send_json_error( array( 'error' => 'Error') );261 } 248 $html_source_term .= '>' . esc_html( $value ) . '</option>'; 249 } 250 251 // Options Target Terms. 252 $html_target_term = ''; 253 foreach ( HELPER::get_terms_from( $site_id, $taxonomy_parent, $post_type ) as $key => $value ) { 254 $html_target_term .= '<p><input type="checkbox"'; 255 $html_target_term .= ' name="publish_mu_setttings[musite][' . esc_html( $index ) . '][target_cat_' . esc_html( $key ) . ']" id="' . esc_html( $key ) . '"'; 256 $html_target_term .= ' value="' . esc_html( $key ) . '"'; 257 $html_target_term .= '/><label for="' . esc_html( $key ) . '">' . esc_html( $value ) . '</label></p>'; 258 } 259 260 // Options Target author. 261 $html_auth = ''; 262 foreach ( HELPER::get_authors_from( $site_id ) as $key => $value ) { 263 $html_auth .= '<option value="' . esc_html( $key ) . '">' . esc_html( $value ) . '</option>'; 264 } 265 error_log( 'return: ' . print_r( array( $html_tax, $html_source_term, $html_target_term, $html_auth ) , true ) ); 266 wp_send_json_success( array( $html_tax, $html_source_term, $html_target_term, $html_auth ) ); 267 262 268 } 263 269 … … 277 283 ?> 278 284 <div class="publishmu repeating" style="border: 1px solid #ccc; padding: 10px; margin-bottom: 10px;"> 279 <div class="save-item">280 <?php wp_nonce_field( 'category_publish_nonce', 'nonce' ); ?>281 </div>282 285 <div class="save-item"> 283 286 <p><strong><?php esc_html_e( 'Post type', 'duplicate-publish-multisite' ); ?></strong></p> … … 452 455 } 453 456 } 454 455 457 if ( is_admin() ) { 456 458 new PUBMULT_Settings(); -
duplicate-publish-multisite/tags/1.7.5/publish-multisite.php
r3284609 r3313636 4 4 * Plugin URI: duplicate-publish-multisite 5 5 * Description: Publish duplicated post to multisite based on category. 6 * Version: 1.7. 26 * Version: 1.7.5 7 7 * Author: Closemarketing 8 8 * Author URI: https://close.marketing … … 24 24 defined( 'ABSPATH' ) || die( 'No script kiddies please!' ); 25 25 26 define( 'PUBLISHMU_VERSION', '1.7. 2' );26 define( 'PUBLISHMU_VERSION', '1.7.5' ); 27 27 define( 'PUBLISHMU_PLUGIN', __FILE__ ); 28 28 define( 'PUBLISHMU_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); -
duplicate-publish-multisite/tags/1.7.5/readme.txt
r3284609 r3313636 29 29 30 30 == Changelog = 31 = 1.7.5 = 32 * Fix: Files path. 33 34 = 1.7.4 = 35 * Fix: Thumbnail copy. 36 37 = 1.7.3 = 38 * Fix: Post categories load. 39 31 40 = 1.7.2 = 32 41 * Fix: Empty nonce when duplicating elements. -
duplicate-publish-multisite/trunk/includes/assets/category-publish.js
r3284609 r3313636 10 10 site_id = $(this).closest('.publishmu').find('.site-publish').val(); 11 11 strindex = $(this).closest('.publishmu').find('.category-publish').attr('for').replaceAll('][',',').replace('[','').replace(']','').split(','); 12 //let nonce = $( this ).closest('.publishmu').find('#nonce').val();13 let nonce = ajaxAction.nonce;14 12 15 13 $.ajax({ 16 14 type: 'POST', 17 url: ajaxAction.url,15 url: pubmult_ajaxAction.url, 18 16 data: { 19 17 action: 'category_publish', … … 23 21 taxonomy: taxpub.val(), 24 22 index: strindex[1], 25 nonce: nonce23 nonce: pubmult_ajaxAction.nonce 26 24 }, 27 25 beforeSend: function() { $(".category-publish-action .spinner").addClass("is-active"); }, -
duplicate-publish-multisite/trunk/includes/class-admin-publishmu.php
r3157312 r3313636 151 151 // Get image data. 152 152 $post_thumbnail_id = get_post_thumbnail_id( $source_post_id ); 153 $image_url = wp_get_attachment_image_src( $post_thumbnail_id, 'full' ); 154 $uploads = wp_upload_dir(); 155 $source_image_path = str_replace( $uploads['baseurl'], $uploads['basedir'], $image_url[0] ); 156 153 154 if ( ! $post_thumbnail_id || ! wp_attachment_is_image( $post_thumbnail_id ) ) { 155 $is_image_changed = false; 156 } 157 158 $image_url = null; 159 $source_image_path = null; 160 161 if ($is_image_changed && $post_thumbnail_id) { 162 $image_url = wp_get_attachment_image_src($post_thumbnail_id, 'full'); 163 164 if ($image_url && is_array($image_url)) { 165 $uploads = wp_upload_dir(); 166 167 $source_image_path = get_attached_file( $post_thumbnail_id ); 168 169 if ( ! $source_image_path || ! file_exists( $source_image_path ) ) { 170 $source_image_path = str_replace( $uploads['baseurl'], $uploads['basedir'], $image_url[0] ); 171 $source_image_path = preg_replace( '/\?.*/', '', $source_image_path ); 172 error_log('Duplicate Publish Multisite - Source image not found directly. Using alternative path: ' . $source_image_path); 173 } 174 175 if ( ! file_exists( $source_image_path ) ) { 176 $is_image_changed = false; 177 error_log('Duplicate Publish Multisite - Source image file not found at: ' . $source_image_path); 178 } 179 } else { 180 $is_image_changed = false; 181 error_log('Duplicate Publish Multisite - Cannot get image URL for thumbnail ID: ' . $post_thumbnail_id); 182 } 183 } 157 184 // Copy data. 158 185 switch_to_blog( $target_site ); … … 227 254 * ## Thumbnail 228 255 * --------------------------- */ 229 if ( $is_image_changed ) {256 if ( $is_image_changed && $source_image_path && file_exists( $source_image_path ) ) { 230 257 // Add Featured Image to Post. 231 258 $upload_dir = wp_upload_dir(); 232 if ( is_array( $image_url ) ) { 233 $image_url = $image_url[0]; 234 $filename = basename( $image_url ); 235 236 // Check folder permission and define file location. 237 if ( wp_mkdir_p( $upload_dir['path'] ) ) { 238 $target_image_path = $upload_dir['path'] . '/' . $filename; 239 } else { 240 $target_image_path = $upload_dir['basedir'] . '/' . $filename; 241 } 242 243 // Copies to target folder. 244 copy( $source_image_path, $target_image_path ); 245 259 $source_image_path_clean = preg_replace('/\?.*/', '', $source_image_path); 260 $filename = basename($source_image_path_clean); 261 262 $target_dir = $upload_dir['path']; 263 if ( ! file_exists( $target_dir ) ) { 264 wp_mkdir_p( $target_dir ); 265 } 266 267 $target_image_path = $upload_dir['path'] . '/' . $filename; 268 269 $copy_success = false; 270 271 if( copy( $source_image_path, $target_image_path ) ) { 272 $copy_success = true; 273 } else { 274 error_log('Duplicate Publish Multisite - Direct copy failed. Trying file_get_contents/file_put_contents'); 275 276 $file_content = @file_get_contents($source_image_path); 277 if ($file_content !== false) { 278 if (file_put_contents($target_image_path, $file_content) !== false) { 279 $copy_success = true; 280 } 281 } 282 } 283 284 if ( $copy_success ) { 246 285 // Check image file type. 247 286 $wp_filetype = wp_check_filetype( $filename, null ); … … 269 308 // And finally assign featured image to post. 270 309 set_post_thumbnail( $target_post_id, $attach_id ); 310 } else { 311 error_log('Failed to copy image from ' . $source_image_path . ' to ' . $target_image_path); 271 312 } 272 313 } -
duplicate-publish-multisite/trunk/includes/class-pubmult-settings.php
r3158731 r3313636 80 80 wp_localize_script( 81 81 'category-publish', 82 ' ajaxAction',82 'pubmult_ajaxAction', 83 83 array( 84 84 'url' => admin_url( 'admin-ajax.php' ), … … 219 219 $term = isset( $_POST['taxonomy'] ) ? sanitize_key( $_POST['taxonomy'] ) : ''; 220 220 221 if ( check_ajax_referer( 'category_publish_nonce', 'nonce' ) ) { 222 $html_tax = ''; 223 $taxonomies = HELPER::get_taxonomies( $post_type ); 224 foreach ( $taxonomies as $key => $value ) { 225 $html_tax .= '<option value="' . esc_html( $key ) . '"'; 226 if ( $key === $taxonomy_parent ) { 227 $html_tax .= ' selected'; 228 } 229 $html_tax .= '>' . esc_html( $value ) . '</option>'; 221 $valid_nonce = false; 222 if (isset($_POST['nonce'])) { 223 $valid_nonce = wp_verify_nonce($_POST['nonce'], 'category_publish_nonce'); 224 } 225 if (!$valid_nonce) { 226 wp_send_json_error(array('error' => 'Invalid nonce')); 227 return; 228 } 229 230 $html_tax = ''; 231 $taxonomies = HELPER::get_taxonomies( $post_type ); 232 foreach ( $taxonomies as $key => $value ) { 233 $html_tax .= '<option value="' . esc_html( $key ) . '"'; 234 if ( $key === $taxonomy_parent ) { 235 $html_tax .= ' selected'; 230 236 } 231 232 // Options Source Terms.233 $html_source_term = ''; 234 $source_site_id = get_current_blog_id();235 foreach ( HELPER::get_terms_from( $source_site_id, $taxonomy_parent, $post_type ) as $key => $value ) {236 $html_source_term .= '<option value="' . esc_html( $key ) . '"';237 if ( $key === $term) {238 $html_source_term .= ' selected';239 }240 $html_source_term .= ' >' . esc_html( $value ) . '</option>';237 $html_tax .= '>' . esc_html( $value ) . '</option>'; 238 } 239 240 // Options Source Terms. 241 $html_source_term = ''; 242 $source_site_id = get_current_blog_id(); 243 foreach ( HELPER::get_terms_from( $source_site_id, $taxonomy_parent, $post_type ) as $key => $value ) { 244 $html_source_term .= '<option value="' . esc_html( $key ) . '"'; 245 if ( $key === $term ) { 246 $html_source_term .= ' selected'; 241 247 } 242 243 // Options Target Terms.244 $html_target_term = ''; 245 foreach ( HELPER::get_terms_from( $site_id, $taxonomy_parent, $post_type ) as $key => $value ) {246 $html_target_term .= '<p><input type="checkbox"';247 $html_target_term .= ' name="publish_mu_setttings[musite][' . esc_html( $index ) . '][target_cat_' . esc_html( $key ) . ']" id="' . esc_html( $key ) . '"';248 $html_target_term .= ' value="' . esc_html( $key ) . '"';249 $html_target_term .= '/><label for="' . esc_html( $key ) . '">' . esc_html( $value ) . '</label></p>';250 }251 252 // Options Target author.253 $html_auth = ''; 254 foreach ( HELPER::get_authors_from( $site_id ) as $key => $value ) {255 $html_auth .= '<option value="' . esc_html( $key ) . '">' . esc_html( $value ) . '</option>';256 }257 error_log( 'return: ' . print_r( array( $html_tax, $html_source_term, $html_target_term, $html_auth ) , true ) );258 wp_send_json_success( array( $html_tax, $html_source_term, $html_target_term, $html_auth ) );259 } else {260 wp_send_json_error( array( 'error' => 'Error') );261 } 248 $html_source_term .= '>' . esc_html( $value ) . '</option>'; 249 } 250 251 // Options Target Terms. 252 $html_target_term = ''; 253 foreach ( HELPER::get_terms_from( $site_id, $taxonomy_parent, $post_type ) as $key => $value ) { 254 $html_target_term .= '<p><input type="checkbox"'; 255 $html_target_term .= ' name="publish_mu_setttings[musite][' . esc_html( $index ) . '][target_cat_' . esc_html( $key ) . ']" id="' . esc_html( $key ) . '"'; 256 $html_target_term .= ' value="' . esc_html( $key ) . '"'; 257 $html_target_term .= '/><label for="' . esc_html( $key ) . '">' . esc_html( $value ) . '</label></p>'; 258 } 259 260 // Options Target author. 261 $html_auth = ''; 262 foreach ( HELPER::get_authors_from( $site_id ) as $key => $value ) { 263 $html_auth .= '<option value="' . esc_html( $key ) . '">' . esc_html( $value ) . '</option>'; 264 } 265 error_log( 'return: ' . print_r( array( $html_tax, $html_source_term, $html_target_term, $html_auth ) , true ) ); 266 wp_send_json_success( array( $html_tax, $html_source_term, $html_target_term, $html_auth ) ); 267 262 268 } 263 269 … … 277 283 ?> 278 284 <div class="publishmu repeating" style="border: 1px solid #ccc; padding: 10px; margin-bottom: 10px;"> 279 <div class="save-item">280 <?php wp_nonce_field( 'category_publish_nonce', 'nonce' ); ?>281 </div>282 285 <div class="save-item"> 283 286 <p><strong><?php esc_html_e( 'Post type', 'duplicate-publish-multisite' ); ?></strong></p> … … 452 455 } 453 456 } 454 455 457 if ( is_admin() ) { 456 458 new PUBMULT_Settings(); -
duplicate-publish-multisite/trunk/publish-multisite.php
r3284609 r3313636 4 4 * Plugin URI: duplicate-publish-multisite 5 5 * Description: Publish duplicated post to multisite based on category. 6 * Version: 1.7. 26 * Version: 1.7.5 7 7 * Author: Closemarketing 8 8 * Author URI: https://close.marketing … … 24 24 defined( 'ABSPATH' ) || die( 'No script kiddies please!' ); 25 25 26 define( 'PUBLISHMU_VERSION', '1.7. 2' );26 define( 'PUBLISHMU_VERSION', '1.7.5' ); 27 27 define( 'PUBLISHMU_PLUGIN', __FILE__ ); 28 28 define( 'PUBLISHMU_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); -
duplicate-publish-multisite/trunk/readme.txt
r3284609 r3313636 29 29 30 30 == Changelog = 31 = 1.7.5 = 32 * Fix: Files path. 33 34 = 1.7.4 = 35 * Fix: Thumbnail copy. 36 37 = 1.7.3 = 38 * Fix: Post categories load. 39 31 40 = 1.7.2 = 32 41 * Fix: Empty nonce when duplicating elements.
Note: See TracChangeset
for help on using the changeset viewer.