我的Wordpress插件给了我WSOD

时间:2014-01-02 18:29:10

标签: wordpress-plugin wordpress custom-post-type wsod

我遵循了本教程http://wp.tutsplus.com/tutorials/plugins/a-guide-to-wordpress-custom-post-types-creation-display-and-meta-boxes/,我非常仔细地考虑过但是当我完成它时,我的插件可以工作,但它会给网站上的每个其他页面提供WSOD!一旦我停用插件,我的其他页面再次工作。我在使用MAMP的Mac上运行它,如果这有帮助的话。我希望在我上传和在线测试之前完成所有工作,即使我的网站不在线。

以下是我的代码。关于我做错了什么的任何想法?非常感谢你给我的任何帮助。

<?php
/*
Plugin Name: NM Portfolio
Plugin URI: http://work.nickmoyer.net
Description: Declares a plugin that will create a custom post type displaying movie reviews.
Version: 1.3
Author: Nick Moyer
Author URI: http://work.nickmoyer.net
License: GPLv2
*/

// Create a Custom Post Type

add_action( 'init', 'create_nm_portfolio' );

function create_nm_portfolio() {
    register_post_type( 'nm_portfolio',
        array(
            'labels' => array(
            'name' => 'NM Portfolio',
            'singular_name' => 'NM Portfolio',
            'add_new' => 'Add New',
            'add_new_item' => 'Add New Portfolio Project',
            'edit' => 'Edit',
            'edit_item' => 'Edit Portfolio Project',
            'new_item' => 'New Portfolio Project',
            'view' => 'View',
            'view_item' => 'View Portfolio Project',
            'search_items' => 'Search Portfolio Projects',
            'not_found' => 'No Portfolio Projects found',
            'not_found_in_trash' =>
            'No Portfolio Projects found in Trash',
            'parent' => 'Parent Portfolio Project'
        ),
            'public' => true,
            'menu_position' => 15,
            'supports' =>
            array( 'title', 'editor', 'thumbnail' ),
            'rewrite' => array('slug' => 'portfolio'),
            'taxonomies' => array( '' ),
            'has_archive' => true
        )
    );
}

// Creating Meta Box Fields for Custom Post Types

add_action( 'admin_init', 'my_admin' );

function my_admin() {
    add_meta_box( 'nm_portfolio_cleint_meta_box','Portfolio Project Client Info','display_nm_portfolio_client_meta_box','nm_portfolio', 'normal', 'high' );
}

function display_nm_portfolio_client_meta_box( $nm_portfolio ) {
    // Retrieve current name of the Director and Movie Rating based on review ID
    $nm_clients = esc_html( get_post_meta( $nm_portfolio->ID,'nm_clients', true ) );
    ?>
    <table>
        <tr>
            <td style="width: 100%">Client Name</td>
            <td>
                <input type="text" size="80" name="nm_portfolio_clients" value="<?php echo $nm_clients; ?>" />
            </td>
        </tr>
    </table>
<?php }

add_action( 'save_post','add_nm_portfolio_fields', 10, 2 );

function add_nm_portfolio_fields( $nm_portfolio_id,$nm_portfolio ) {
    // Check post type for movie reviews
    if ( $nm_portfolio->post_type == 'nm_portfolio' ) {
    // Store data in post meta table if present in post data
    if ( isset( $_POST['nm_portfolio_clients'] ) && $_POST['nm_portfolio_clients'] != '' ) {
        update_post_meta( $nm_portfolio_id, 'nm_clients', $_POST['nm_portfolio_clients'] );
    }
}

}
// Custom Template Dedicated to Custom Post Types

add_filter( 'template_include','include_template_function', 1 );

function include_template_function( $template_path ) {
    if ( get_post_type() == 'nm_portfolio' ) {
        if ( is_single() ) {
            // checks if the file exists in the theme first,
            // otherwise serve the file from the plugin
            if ( $theme_file = locate_template( array ( 'single-nm_portfolio.php' ) ) ) {
                $template_path = $theme_file;
            } else {
                $template_path = plugin_dir_path( __FILE__ ) . '/single-nm_portfolio.php';
            }
        }
            elseif ( is_archive() ) {
        if ( $theme_file = locate_template( array ( 'archive-nm_portfolio.php' ) ) ) {
            $template_path = $theme_file;
        } else { $template_path = plugin_dir_path( __FILE__ ) . '/archive-nm_portfolio.php';

        }
    }
    return $template_path;
}

// Displaying Additional Columns

add_filter( 'manage_edit-nm_portfolio_columns', 'my_columns' );

function my_columns( $columns ) {
    $columns['nm_portfolio_clients'] = 'Clients';
    unset( $columns['comments'] );
    return $columns;
}

add_action( 'manage_posts_custom_column', 'populate_columns' );

function populate_columns( $column ) {
    if ( 'nm_portfolio_clients' == $column ) {
        $nm_clients = esc_html( get_post_meta( get_the_ID(), 'nm_clients', true ) );
        echo $nm_clients;
    }
}

add_filter( 'manage_edit-nm_portfolio_sortable_columns', 'sort_me' );

function sort_me( $columns ) {
    $columns['nm_portfolio_clients'] = 'nm_portfolio_clients';
    return $columns;
}

add_filter( 'request', 'column_ordering' );

add_filter( 'request', 'column_orderby' );

function column_orderby ( $vars ) {
    if ( !is_admin() )
        return $vars;
    if ( isset( $vars['orderby'] ) && 'nm_portfolio_clients' == $vars['orderby'] ) {
        $vars = array_merge( $vars, array( 'meta_key' => 'nm_clients', 'orderby' => 'meta_value' ) );
    }
    return $vars;
}

//Creating Filters With Custom Taxonomy

add_action( 'restrict_manage_posts', 'my_filter_list' );

function my_filter_list() {
    $screen = get_current_screen();
    global $wp_query;
    if ( $screen->post_type == 'nm_portfolio' ) {
        wp_dropdown_categories( array(
            'show_option_all' => 'Show All Movie Genres',
            'taxonomy' => 'movie_reviews_movie_genre',
            'name' => 'movie_reviews_movie_genre',
            'orderby' => 'name',
            'selected' => ( isset( $wp_query->query['movie_reviews_movie_genre'] ) ? $wp_query->query['movie_reviews_movie_genre'] : '' ),
            'hierarchical' => false,
            'depth' => 3,
            'show_count' => false,
            'hide_empty' => true,
        ) );
    }
}

add_filter( 'parse_query','perform_filtering' );

function perform_filtering( $query ) {
    $qv = &$query->query_vars;
    if ( ( $qv['movie_reviews_movie_genre'] ) && is_numeric( $qv['movie_reviews_movie_genre'] ) ) {
        $term = get_term_by( 'id', $qv['movie_reviews_movie_genre'], 'movie_reviews_movie_genre' );
        $qv['movie_reviews_movie_genre'] = $term->slug;
    }
}
}

// Adding Taxonomies

add_action( 'init', 'create_my_taxonomies', 0 );

function create_my_taxonomies() {
    register_taxonomy(
        'nm_portfolio_service_type',
        'nm_portfolio',
        array(
            'labels' => array(
                'name' => 'Services Performed',
                'add_new_item' => 'Add New Service',
                'new_item_name' => "New Service Type"
            ),
            'show_ui' => true,
            'show_tagcloud' => false,
            'hierarchical' => true
        )
    );
    register_taxonomy(
        'nm_portfolio_programs_used',
        'nm_portfolio',
        array(
            'labels' => array(
                'name' => 'Programs Used',
                'add_new_item' => 'Add New Program',
                'new_item_name' => "New Program"
            ),
            'show_ui' => true,
            'show_tagcloud' => false,
            'hierarchical' => true
        )
    );
    register_taxonomy(
        'nm_portfolio_equipment_used',
        'nm_portfolio',
        array(
            'labels' => array(
                'name' => 'Equipment Used',
                'add_new_item' => 'Add New Equipment',
                'new_item_name' => "New Equipment"
            ),
            'show_ui' => true,
            'show_tagcloud' => false,
            'hierarchical' => true
        )
    );

}
?>

2 个答案:

答案 0 :(得分:0)

我拿出了一些部分,但将其缩小到下面导致问题的部分。

// Custom Template Dedicated to Custom Post Types

add_filter( 'template_include','include_template_function', 1 );

function include_template_function( $template_path ) {
    if ( get_post_type() == 'nm_portfolio' ) {
        if ( is_single() ) {
            // checks if the file exists in the theme first,
            // otherwise serve the file from the plugin
            if ( $theme_file = locate_template( array ( 'single-nm_portfolio.php' ) ) ) {
                $template_path = $theme_file;
            } else {
                $template_path = plugin_dir_path( __FILE__ ) . '/single-nm_portfolio.php';
            }
        }
            elseif ( is_archive() ) {
        if ( $theme_file = locate_template( array ( 'archive-nm_portfolio.php' ) ) ) {
            $template_path = $theme_file;
        } else { $template_path = plugin_dir_path( __FILE__ ) . '/archive-nm_portfolio.php';

        }
    }
    return $template_path;
}

我删除了add_filter( 'template_include','include_template_function', 1 );,现在似乎工作正常。

下面是我的代码,它们一起工作并且已经过编辑,以摆脱一些我不想要的东西。

<?php
/*
Plugin Name: NM Portfolio
Plugin URI: http://work.nickmoyer.net
Description: Declares a plugin that will create a custom post type displaying movie reviews.
Version: 1.3
Author: Nick Moyer
Author URI: http://work.nickmoyer.net
License: GPLv2
*/

// Create a Custom Post Type

add_action( 'init', 'create_nm_portfolio' );


function create_nm_portfolio() {
    register_post_type( 'nm_portfolio',
        array(
            'labels' => array(
            'name' => 'NM Portfolio',
            'singular_name' => 'NM Portfolio',
            'add_new' => 'Add New',
            'add_new_item' => 'Add New Portfolio Project',
            'edit' => 'Edit',
            'edit_item' => 'Edit Portfolio Project',
            'new_item' => 'New Portfolio Project',
            'view' => 'View',
            'view_item' => 'View Portfolio Project',
            'search_items' => 'Search Portfolio Projects',
            'not_found' => 'No Portfolio Projects found',
            'not_found_in_trash' =>
            'No Portfolio Projects found in Trash',
            'parent' => 'Parent Portfolio Project'
        ),
            'public' => true,
            'menu_position' => 15,
            'supports' =>
            array( 'title', 'editor', 'thumbnail' ),
            'rewrite' => array('slug' => 'portfolio'),
            'taxonomies' => array( '' ),
            'has_archive' => true
        )
    );
}

// Creating Meta Box Fields for Custom Post Types

add_action( 'admin_init', 'my_admin' );


function my_admin() {
    add_meta_box( 'nm_portfolio_cleint_meta_box','Portfolio Project Client Info','display_nm_portfolio_client_meta_box','nm_portfolio', 'normal', 'high' );
}

function display_nm_portfolio_client_meta_box( $nm_portfolio ) {
    // Retrieve current name of the Director and Movie Rating based on review ID
    $nm_clients = esc_html( get_post_meta( $nm_portfolio->ID,'nm_clients', true ) );
    ?>
    <table>
        <tr>
            <td style="width: 100%">Client Name</td>
            <td>
                <input type="text" size="80" name="nm_portfolio_clients" value="<?php echo $nm_clients; ?>" />
            </td>
        </tr>
    </table>
<?php }


add_action( 'save_post','add_nm_portfolio_fields', 10, 2 );


function add_nm_portfolio_fields( $nm_portfolio_id,$nm_portfolio ) {
    // Check post type for movie reviews
    if ( $nm_portfolio->post_type == 'nm_portfolio' ) {
    // Store data in post meta table if present in post data
    if ( isset( $_POST['nm_portfolio_clients'] ) && $_POST['nm_portfolio_clients'] != '' ) {
        update_post_meta( $nm_portfolio_id, 'nm_clients', $_POST['nm_portfolio_clients'] );
    }

}

}

// Custom Template Dedicated to Custom Post Types

function include_template_function( $template_path ) {
    if ( get_post_type() == 'nm_portfolio' ) {
        if ( is_single() ) {
            // checks if the file exists in the theme first,
            // otherwise serve the file from the plugin
            if ( $theme_file = locate_template( array ( 'single-nm_portfolio.php' ) ) ) {
                $template_path = $theme_file;
            } else {
                $template_path = plugin_dir_path( __FILE__ ) . '/single-nm_portfolio.php';
            }
        }
        elseif ( is_archive() ) {
            if ( $theme_file = locate_template( array ( 'archive-nm_portfolio.php' ) ) ) {
                $template_path = $theme_file;
            } else { $template_path = plugin_dir_path( __FILE__ ) . '/archive-nm_portfolio.php';

            }
        }
    }
    return $template_path;
}

// Adding Taxonomies

add_action( 'init', 'create_my_taxonomies', 0 );

function create_my_taxonomies() {
    register_taxonomy(
        'nm_portfolio_service_type',
        'nm_portfolio',
        array(
            'labels' => array(
                'name' => 'Services Performed',
                'add_new_item' => 'Add New Service',
                'new_item_name' => "New Service Type"
            ),
            'show_ui' => true,
            'show_tagcloud' => false,
            'hierarchical' => true
        )
    );
    register_taxonomy(
        'nm_portfolio_programs_used',
        'nm_portfolio',
        array(
            'labels' => array(
                'name' => 'Programs Used',
                'add_new_item' => 'Add New Program',
                'new_item_name' => "New Program"
            ),
            'show_ui' => true,
            'show_tagcloud' => false,
            'hierarchical' => true
        )
    );
    register_taxonomy(
        'nm_portfolio_equipment_used',
        'nm_portfolio',
        array(
            'labels' => array(
                'name' => 'Equipment Used',
                'add_new_item' => 'Add New Equipment',
                'new_item_name' => "New Equipment"
            ),
            'show_ui' => true,
            'show_tagcloud' => false,
            'hierarchical' => true
        )
    );

}

?>

感谢您的帮助!

答案 1 :(得分:0)

没有定义'column_ordering'函数,尽管«add_filter('request','column_ordering');» 从代码中删除这个过滤器,并且会出现烦恼!