Plugin Directory

Changeset 1696624


Ignore:
Timestamp:
07/15/2017 06:30:17 AM (9 years ago)
Author:
webbilicious
Message:

Tag 1.3

Location:
listolicious/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • listolicious/trunk/listolicious.php

    r1586081 r1696624  
    33Plugin Name: Listolicious
    44Description: The shortcode displays a movie list in the style of Mubi
    5 Version:     1.2.1
     5Version:     1.3
    66Author:      Daniel Hånberg Alonso
    77Author URI:  http://webbilicious.se
     
    5757        if ( is_admin() ) {
    5858
    59             add_action( 'save_post', array( $this, 'save_details')  );
    6059            add_filter( 'manage_edit-movies_columns', array( $this, 'edit_columns' ) );
     60            add_filter( 'manage_edit-movies_sortable_columns', array( $this, 'sortable_columns' ) );
     61            add_action( 'pre_get_posts', array( $this, 'sort_posts' ), 1 );
    6162            add_action( 'manage_posts_custom_column', array( $this, 'add_columns' ) );
    6263            add_action( 'quick_edit_custom_box', array( $this, 'quickedit' ), 10, 2 );
    6364            add_action( 'admin_enqueue_scripts', array( $this, 'quickedit_script' ), 10,  1 );
    64 
     65            add_action( 'save_post', array( $this, 'save_details'), 10, 1 );
    6566        }
    6667    }
     
    193194        global $post;
    194195
     196        wp_nonce_field('save_listolicious', 'movie_edit_nonce');
     197
    195198        $custom = get_post_custom($post->ID);
    196199        $listo_director = isset( $custom["listo_director"][0] ) ? $custom["listo_director"][0] : '';
     
    198201        $listo_url = isset( $custom["listo_url"][0] ) ? $custom["listo_url"][0] : '';
    199202
    200         wp_nonce_field( 'save_listolicious', 'movie_edit_nonce' );
    201203        ?>
    202204        <p><label><?php _e('Director', 'listolicious'); ?>:</label><br />
     
    214216     * @since 1.0
    215217     */
    216     function save_details(){
     218    function save_details($post_id){
    217219        global $post;
    218220
    219         if ( ! empty( $_POST ) && check_admin_referer( 'save_listolicious', 'movie_edit_nonce' ) ) {
    220 
    221             $id = ( isset( $post->ID ) ? get_the_ID() : NULL );
     221        if ( ! empty( $_POST ) ) {
     222
     223            //check nonce set
     224            if(!isset($_POST['movie_edit_nonce'])){
     225                return false;
     226            }
     227
     228            //verify nonce
     229            if(!wp_verify_nonce($_POST['movie_edit_nonce'], 'save_listolicious')){
     230                return false;
     231            }
     232           
    222233            $listo_director = isset( $_POST['listo_director'] ) ? sanitize_text_field( $_POST['listo_director'] ) : '';
    223234            $listo_year = isset( $_POST['listo_year'] ) ? sanitize_text_field( $_POST['listo_year'] ) : '';
    224235            $listo_url = isset( $_POST['listo_url'] ) ? sanitize_text_field( $_POST['listo_url'] ) : '';
    225236
    226             update_post_meta( $id, "listo_director", $listo_director );
    227             update_post_meta( $id, "listo_year", $listo_year );
    228             update_post_meta( $id, "listo_url", $listo_url );
     237            update_post_meta( $post_id, "listo_director", $listo_director );
     238            update_post_meta( $post_id, "listo_year", $listo_year );
     239            update_post_meta( $post_id, "listo_url", $listo_url );
     240
    229241        }
    230242    }
     
    348360     * @since 1.0
    349361     */
    350     function add_columns($column){
     362    function add_columns($columns){
    351363        global $post;
    352364   
    353         switch ($column) {
     365        switch ($columns) {
    354366        case "director":
    355367            $custom = get_post_custom();
     
    367379
    368380    /**
     381     * The following filter makes the custom columns sortable.
     382     *
     383     * @since 1.3
     384     */
     385    function sortable_columns( $sortable_columns ) {
     386
     387        $sortable_columns[ 'director' ] = 'director';
     388        $sortable_columns[ 'year' ] = 'year';
     389
     390        return $sortable_columns;
     391    }
     392
     393    /**
     394     * The following action makes the custom columns sortable.
     395     *
     396     * @since 1.3
     397     */
     398    function sort_posts( $query ) {
     399
     400        /**
     401         * We only want our code to run in the main WP query
     402         * AND if an orderby query variable is designated.
     403         */
     404        if ( $query->is_main_query() && ( $orderby = $query->get( 'orderby' ) ) ) {
     405
     406            switch( $orderby ) {
     407
     408                case 'director':
     409
     410                    $query->set( 'meta_key', 'listo_director' );
     411                    $query->set( 'orderby', 'meta_value' );
     412
     413                    break;
     414
     415                case 'year':
     416
     417                    $query->set( 'meta_key', 'listo_year' );
     418                    $query->set( 'orderby', 'meta_value' );
     419
     420                    break;                 
     421
     422            }
     423        }
     424    }
     425
     426
     427    /**
    369428     * Adds quickedit button for editing in list view
    370429     *
     
    372431     */
    373432    function quickedit($column_name, $post_type) { 
    374         static $printNonce = TRUE;
    375         if ( $printNonce ) {
    376             $printNonce = FALSE;
    377             wp_nonce_field( plugin_basename( __FILE__ ), 'movie_edit_nonce' );
    378         }
     433       
     434        wp_nonce_field( 'save_listolicious', 'movie_edit_nonce' );
    379435
    380436        ?>
  • listolicious/trunk/readme.txt

    r1586081 r1696624  
    44Tags: shortcode, custom post type, list, movie
    55Requires at least: 4.5.3
    6 Tested up to: 4.7.2
    7 Stable tag: 1.2.1
     6Tested up to: 4.8
     7Stable tag: 1.3
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset for help on using the changeset viewer.