Plugin Directory

Changeset 3313636


Ignore:
Timestamp:
06/18/2025 06:35:31 AM (10 months ago)
Author:
closemarketing
Message:

Update to version 1.7.5 from GitHub

Location:
duplicate-publish-multisite
Files:
10 edited
1 copied

Legend:

Unmodified
Added
Removed
  • duplicate-publish-multisite/tags/1.7.5/includes/assets/category-publish.js

    r3284609 r3313636  
    1010        site_id = $(this).closest('.publishmu').find('.site-publish').val();
    1111        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;
    1412
    1513        $.ajax({
    1614            type: 'POST',
    17             url: ajaxAction.url,
     15            url: pubmult_ajaxAction.url,
    1816            data: {
    1917                action: 'category_publish',
     
    2321                taxonomy: taxpub.val(),
    2422                index: strindex[1],
    25                 nonce: nonce
     23                nonce: pubmult_ajaxAction.nonce
    2624            },
    2725            beforeSend: function() { $(".category-publish-action .spinner").addClass("is-active"); },
  • duplicate-publish-multisite/tags/1.7.5/includes/class-admin-publishmu.php

    r3157312 r3313636  
    151151        // Get image data.
    152152        $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        }
    157184        // Copy data.
    158185        switch_to_blog( $target_site );
     
    227254         * ## Thumbnail
    228255         * --------------------------- */
    229         if ( $is_image_changed ) {
     256        if ( $is_image_changed && $source_image_path && file_exists( $source_image_path ) ) {
    230257            // Add Featured Image to Post.
    231258            $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 ) {
    246285                // Check image file type.
    247286                $wp_filetype = wp_check_filetype( $filename, null );
     
    269308                // And finally assign featured image to post.
    270309                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);
    271312            }
    272313        }
  • duplicate-publish-multisite/tags/1.7.5/includes/class-pubmult-settings.php

    r3158731 r3313636  
    8080        wp_localize_script(
    8181            'category-publish',
    82             'ajaxAction',
     82            'pubmult_ajaxAction',
    8383            array(
    8484                'url'   => admin_url( 'admin-ajax.php' ),
     
    219219        $term            = isset( $_POST['taxonomy'] ) ? sanitize_key( $_POST['taxonomy'] ) : '';
    220220
    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';
    230236            }
    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';
    241247            }
    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
    262268    }
    263269
     
    277283            ?>
    278284            <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>
    282285                <div class="save-item">
    283286                    <p><strong><?php esc_html_e( 'Post type', 'duplicate-publish-multisite' ); ?></strong></p>
     
    452455    }
    453456}
    454 
    455457if ( is_admin() ) {
    456458    new PUBMULT_Settings();
  • duplicate-publish-multisite/tags/1.7.5/publish-multisite.php

    r3284609 r3313636  
    44 * Plugin URI:  duplicate-publish-multisite
    55 * Description: Publish duplicated post to multisite based on category.
    6  * Version:     1.7.2
     6 * Version:     1.7.5
    77 * Author:      Closemarketing
    88 * Author URI:  https://close.marketing
     
    2424defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
    2525
    26 define( 'PUBLISHMU_VERSION', '1.7.2' );
     26define( 'PUBLISHMU_VERSION', '1.7.5' );
    2727define( 'PUBLISHMU_PLUGIN', __FILE__ );
    2828define( 'PUBLISHMU_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
  • duplicate-publish-multisite/tags/1.7.5/readme.txt

    r3284609 r3313636  
    2929
    3030== 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
    3140= 1.7.2 =
    3241*   Fix: Empty nonce when duplicating elements.
  • duplicate-publish-multisite/trunk/includes/assets/category-publish.js

    r3284609 r3313636  
    1010        site_id = $(this).closest('.publishmu').find('.site-publish').val();
    1111        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;
    1412
    1513        $.ajax({
    1614            type: 'POST',
    17             url: ajaxAction.url,
     15            url: pubmult_ajaxAction.url,
    1816            data: {
    1917                action: 'category_publish',
     
    2321                taxonomy: taxpub.val(),
    2422                index: strindex[1],
    25                 nonce: nonce
     23                nonce: pubmult_ajaxAction.nonce
    2624            },
    2725            beforeSend: function() { $(".category-publish-action .spinner").addClass("is-active"); },
  • duplicate-publish-multisite/trunk/includes/class-admin-publishmu.php

    r3157312 r3313636  
    151151        // Get image data.
    152152        $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        }
    157184        // Copy data.
    158185        switch_to_blog( $target_site );
     
    227254         * ## Thumbnail
    228255         * --------------------------- */
    229         if ( $is_image_changed ) {
     256        if ( $is_image_changed && $source_image_path && file_exists( $source_image_path ) ) {
    230257            // Add Featured Image to Post.
    231258            $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 ) {
    246285                // Check image file type.
    247286                $wp_filetype = wp_check_filetype( $filename, null );
     
    269308                // And finally assign featured image to post.
    270309                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);
    271312            }
    272313        }
  • duplicate-publish-multisite/trunk/includes/class-pubmult-settings.php

    r3158731 r3313636  
    8080        wp_localize_script(
    8181            'category-publish',
    82             'ajaxAction',
     82            'pubmult_ajaxAction',
    8383            array(
    8484                'url'   => admin_url( 'admin-ajax.php' ),
     
    219219        $term            = isset( $_POST['taxonomy'] ) ? sanitize_key( $_POST['taxonomy'] ) : '';
    220220
    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';
    230236            }
    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';
    241247            }
    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
    262268    }
    263269
     
    277283            ?>
    278284            <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>
    282285                <div class="save-item">
    283286                    <p><strong><?php esc_html_e( 'Post type', 'duplicate-publish-multisite' ); ?></strong></p>
     
    452455    }
    453456}
    454 
    455457if ( is_admin() ) {
    456458    new PUBMULT_Settings();
  • duplicate-publish-multisite/trunk/publish-multisite.php

    r3284609 r3313636  
    44 * Plugin URI:  duplicate-publish-multisite
    55 * Description: Publish duplicated post to multisite based on category.
    6  * Version:     1.7.2
     6 * Version:     1.7.5
    77 * Author:      Closemarketing
    88 * Author URI:  https://close.marketing
     
    2424defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
    2525
    26 define( 'PUBLISHMU_VERSION', '1.7.2' );
     26define( 'PUBLISHMU_VERSION', '1.7.5' );
    2727define( 'PUBLISHMU_PLUGIN', __FILE__ );
    2828define( 'PUBLISHMU_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
  • duplicate-publish-multisite/trunk/readme.txt

    r3284609 r3313636  
    2929
    3030== 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
    3140= 1.7.2 =
    3241*   Fix: Empty nonce when duplicating elements.
Note: See TracChangeset for help on using the changeset viewer.