首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我的Wordpress插件给了我WSOD

我的Wordpress插件给了我WSOD
EN

Stack Overflow用户
提问于 2014-01-02 18:29:10
回答 2查看 95关注 0票数 0

我遵循这个教程,http://wp.tutsplus.com/tutorials/plugins/a-guide-to-wordpress-custom-post-types-creation-display-and-meta-boxes/,我想得很仔细,但当我完成它,我的插件工作,但它提供了网站上的每一个其他页面的世界超级氧化物歧化酶!一旦我关闭插件,我的其他页面再次工作。我正在使用MAMP在我的mac上运行这个,如果这有帮助的话。我想在上传和在线测试之前完成所有的工作,即使我的网站不在现场。

下面是我的密码。我到底做错了什么?非常感谢你能帮我的忙。

代码语言:javascript
复制
<?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
        )
    );

}
?>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-01-03 12:10:26

我拿出了一些零件,但把范围缩小到下面这个部分,这是造成问题的原因。

代码语言:javascript
复制
// 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 );,现在它似乎运行良好。

下面是我所有的代码一起工作,并已被编辑,以摆脱一些事情,我并不是真正想要的。

代码语言:javascript
复制
<?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
        )
    );

}

?>

谢谢你的帮忙!

票数 0
EN

Stack Overflow用户

发布于 2015-02-24 09:03:32

没有定义“column_ordering”函数,尽管对«add_filter(‘请求’,'column_ordering‘)是必要的;如果从代码中删除这个过滤器,那么就会带来快乐!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20889383

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档