Plugin Directory

Changeset 780430


Ignore:
Timestamp:
09/30/2013 04:33:11 PM (12 years ago)
Author:
globalis
Message:

tagging version 0.9.1

Location:
prepare-new-version/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • prepare-new-version/trunk/include/admin.php

    r778230 r780430  
    3939     */
    4040    public static function handle_action() {
    41         if( !isset( $_GET[PNV_ACTION_NAME] ) || !isset( $_GET['ID'] ) || !check_admin_referer( PNV_ACTION_NONCE ) )
    42             return;
    43 
    44         $source = get_post( $_GET['ID'] );
     41        if( !isset( $_GET[PNV_ACTION_NAME] ) || !isset( $_GET['post'] ) || !check_admin_referer( PNV_ACTION_NONCE . '_' . $_GET[PNV_ACTION_NAME] . '_' . $_GET['post'] ) )
     42            return;
     43
     44        $source = get_post( $_GET['post'] );
    4545        $post_types = PNV_Option::get_post_types();
    4646
    4747        // Check post type
    4848        if( !in_array( $source->post_type, $post_types ) )
     49            return;
     50
     51        $post_type_object = get_post_type_object( $source->post_type );
     52
     53        // Check user rights on that post
     54        if( !current_user_can( $post_type_object->cap->edit_post, $source->ID ) )
    4955            return;
    5056
     
    5965                break;
    6066            case PNV_ERASE_ACTION:
    61                 $destination = get_post( PNV::get_original( $_GET['ID'] ) );
     67                $destination = get_post( PNV::get_original( $_GET['post'] ) );
    6268                $post_id = PNV::erase_content( $source, $destination, $_GET[PNV_ACTION_NAME] );
    6369                break;
     
    96102        // If we are on a duplicata, remove default submit meta box and replace it with our box
    97103        if( PNV::is_duplicata( $post->ID ) ) {
    98             remove_meta_box( 'submitdiv', $current_screen->post_type, 'side' );
    99             add_meta_box( 'pnv_submit_meta_box', PNV_STR_PUBLISH_META_BOX_TITLE, array( __CLASS__, 'submit_meta_box' ), $current_screen->post_type, 'side', 'core' );
     104            remove_meta_box( 'submitdiv', $current_post_type, 'side' );
     105            add_meta_box( 'pnv_submit_meta_box', PNV_STR_PUBLISH_META_BOX_TITLE, array( __CLASS__, 'submit_meta_box' ), $current_post_type, 'side', 'core' );
    100106
    101107            // Replace "duplicates" meta box title
     
    112118        $post = get_post();
    113119        $original = PNV::get_original();
    114         $action_url = PNV::get_action_url( $post );
    115120
    116121        require PNV_COMPLETE_PATH . '/template/duplicata_meta_box.php';
     
    123128        $post = get_post();
    124129        $original = PNV::get_original();
    125         $action_url = PNV::get_action_url( $post );
    126130
    127131        require PNV_COMPLETE_PATH . '/template/submit_meta_box.php';
     
    357361                continue;
    358362
    359             $index = count( $messages[$post_type] );
     363            $index = !empty( $messages[$post_type] ) ? count( $messages[$post_type] ) : 0;
    360364            $messages[$post_type][$index] = PNV_STR_MESSAGE_DUPLICATE . ' <a href="' . esc_url( add_query_arg( array( 'post' => $original, 'action' => 'edit' ), admin_url( 'post.php' ) ) ) . '">' . get_the_title( $original ) . '</a>';
    361365
  • prepare-new-version/trunk/prepare_new_version.php

    r778368 r780430  
    77 * Author URI:          http://www.globalis-ms.com
    88 *
    9  * Version:             0.9
     9 * Version:             0.9.1
    1010 * Requires at least:   3.6.0
    1111 * Tested up to:        3.6
     
    4343            add_action( 'init', array( __CLASS__, 'init' ) );
    4444            add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
     45            add_filter( 'post_type_link', array( __CLASS__, 'post_type_link' ), 10, 4 );
     46            add_filter( 'post_link', array( __CLASS__, 'post_link' ), 10, 3 );
     47            add_filter( 'page_link', array( __CLASS__, 'page_link' ), 10, 3 );
    4548        }
    4649
     
    216219            }
    217220
    218             $destination = apply_filters( 'PNV_erase_content_destination', $destination, $source, $duplicate );
     221            $destination = apply_filters( 'pnv_erase_content_destination', $destination, $source, $action );
    219222
    220223            $post_id = wp_insert_post( $destination );
     
    279282         * Return URL where actions have to be sent
    280283         */
    281         public static function get_action_url( $post ) {
    282             $action_url = add_query_arg( array( 'ID' => $post->ID, 'action' => 'edit', 'post' => $post->ID ), admin_url( '/post.php' ) );
    283             $action_url = wp_nonce_url( $action_url, PNV_ACTION_NONCE );
     284        public static function get_action_url( $post, $action = PNV_DUPLICATE_ACTION ) {
     285            $action_url = add_query_arg( array( 'action' => 'edit', 'post' => $post->ID ), admin_url( '/post.php' ) );
     286            $action_url = wp_nonce_url( $action_url, PNV_ACTION_NONCE . '_' . $action . '_' . $post->ID );
    284287
    285288            return $action_url;
     289        }
     290
     291        /**
     292         * Filter Custom Post Types permalinks
     293         */
     294        public static function post_type_link( $permalink, $post, $leavename, $sample ) {
     295            return self::_post_link( $permalink, $post );
     296        }
     297
     298        /**
     299         * Filter 'post' type permalinks
     300         */
     301        public static function post_link( $permalink, $post, $leavename ) {
     302            return self::_post_link( $permalink, $post );
     303        }
     304
     305        /**
     306         * Filter 'page' type permalinks
     307         */
     308        public static function page_link( $permalink, $post_id, $sample ) {
     309            return self::_post_link( $permalink, get_post( $post_id ) );
     310        }
     311
     312        /**
     313         * Filter a permalink and always return a shortlink for a 'duplicata' status:
     314         *  - we don't need a permalink for that status
     315         *  - a shortlink won't work since WordPress will redirect to permalink because this status is not draft or pending
     316         *  - we need a shortlink for the preview
     317         */
     318        protected static function _post_link( $permalink, $post ) {
     319            if( PNV::is_duplicata( $post ) && in_array( $post->post_type, PNV_Option::get_post_types() ) ) {
     320                switch( $post->post_type ) {
     321                    case 'page':
     322                        $permalink = add_query_arg( array( 'page_id' => $post->ID ), '' );
     323                        break;
     324                    default:
     325                        $permalink = add_query_arg( array( 'post_type' => $post->post_type, 'p' => $post->ID ), '' );
     326                }
     327                $permalink = home_url( $permalink );
     328            }
     329
     330            return $permalink;
    286331        }
    287332    }
  • prepare-new-version/trunk/readme.txt

    r778239 r780430  
    44Requires at least: 3.5
    55Tested up to: 3.6.1
    6 Stable tag: 0.9
     6Stable tag: 0.9.1
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
  • prepare-new-version/trunk/template/duplicata_meta_box.php

    r778230 r780430  
    1818</ul>
    1919<p id="prepare-actions">
    20     <a href="<?php echo add_query_arg( PNV_ACTION_NAME, PNV_DUPLICATE_ACTION, $action_url ); ?>" id="duplicate" class="button <?php echo !empty( $original ) ? '' : 'button-primary button-large'; ?>"><?php echo PNV_STR_DUPLICATE_BUTTON; ?></a><br/>
     20    <a href="<?php echo add_query_arg( PNV_ACTION_NAME, PNV_DUPLICATE_ACTION, PNV::get_action_url( $post ) ); ?>" id="duplicate" class="button <?php echo !empty( $original ) ? '' : 'button-primary button-large'; ?>"><?php echo PNV_STR_DUPLICATE_BUTTON; ?></a><br/>
    2121
    2222    <?php
     
    3030    }
    3131    ?>
    32     <a href="<?php echo add_query_arg( PNV_ACTION_NAME, PNV_COPY_ACTION , $action_url ); ?>" id="copy"<?php echo $class; ?>><?php echo $title; ?></a>
     32    <a href="<?php echo add_query_arg( PNV_ACTION_NAME, PNV_COPY_ACTION , PNV::get_action_url( $post, PNV_COPY_ACTION ) ); ?>" id="copy"<?php echo $class; ?>><?php echo $title; ?></a>
    3333</p>
  • prepare-new-version/trunk/template/submit_meta_box.php

    r778230 r780430  
    1919        <div id="publishing-action">
    2020            <span class="spinner"></span>
    21             <a href="<?php echo add_query_arg( PNV_ACTION_NAME, PNV_ERASE_ACTION, $action_url ); ?>" id="erase" class="button button-primary button-large"><?php echo PNV_STR_ERASE_BUTTON; ?></a>
     21            <a href="<?php echo add_query_arg( PNV_ACTION_NAME, PNV_ERASE_ACTION, PNV::get_action_url( $post, PNV_ERASE_ACTION ) ); ?>" id="erase" class="button button-primary button-large"><?php echo PNV_STR_ERASE_BUTTON; ?></a>
    2222        </div>
    2323        <div class="clear"></div>
Note: See TracChangeset for help on using the changeset viewer.