WP Customizer: checkbox value unreachable with get_option - wordpress

this is my code:
function vds_customize_register( $wp_customize ) {
$wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
$wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
$wp_customize->add_section( 'blog_settings' , array(
'title' => __( 'Blog settings', 'vds' ),
'priority' => 30
) );
$wp_customize->add_setting( 'vds[blog_show_commentslink_in_overview]', array(
'default' => '1',
'type' => 'option'
) );
$wp_customize->add_control( 'blog_show_commentslink_in_overview', array(
'label' => __( 'Show comments link in blog overview?' ),
'section' => 'blog_settings',
'settings' => 'vds[blog_show_commentslink_in_overview]',
'type' => 'checkbox',
'std' => '1'
) );
}
add_action( 'customize_register', 'vds_customize_register' );
I tried the following code to get the value in the templates:
get_option( 'vds[blog_show_commentslink_in_overview]' );
get_option( 'blog_show_commentslink_in_overview' );
get_theme_mod( 'vds[blog_show_commentslink_in_overview]' );
get_theme_mod( 'blog_show_commentslink_in_overview' );
none of them worked :/ Why is that? The actual value is stored I guess because if I deactivate the checkbox in the customizer and reload the customizer, the checkbox is unchecked so it shouldve saved that.

$variable = get_theme_mod( 'vds[blog_show_commentslink_in_overview]' ) == '1' ? '// what to run' : '';
echo $variable;
This is what i use.

Related

Can't add a section to a Woocommerce Custom Setting Tab [duplicate]

I'm trying to add a custom settings tab to the WooCommerce settings screen. Basically I want to achieve a similar thing to the Products settings tab, with the subsections/subtabs:
I haven't been able to find any decent documentation on how to do this but I've been able to add a custom tab using this snippet:
class WC_Settings_Tab_Demo {
public static function init() {
add_filter( 'woocommerce_settings_tabs_array', __CLASS__ . '::add_settings_tab', 50 );
}
public static function add_settings_tab( $settings_tabs ) {
$settings_tabs['test'] = __( 'Settings Demo Tab', 'woocommerce-settings-tab-demo' );
return $settings_tabs;
}
}
WC_Settings_Tab_Demo::init();
Based on what I've dug up from various threads/tutorials, I've been trying to add the sections/subtabs to the new settings tab something like this:
// creating a new sub tab in API settings
add_filter( 'woocommerce_get_sections_test','add_subtab' );
function add_subtab( $sections ) {
$sections['custom_settings'] = __( 'Custom Settings', 'woocommerce-custom-settings-tab' );
$sections['more_settings'] = __( 'More Settings', 'woocommerce-custom-settings-tab' );
return $sections;
}
// adding settings (HTML Form)
add_filter( 'woocommerce_get_settings_test', 'add_subtab_settings', 10, 2 );
function add_subtab_settings( $settings, $current_section ) {
// $current_section = (isset($_GET['section']) && !empty($_GET['section']))? $_GET['section']:'';
if ( $current_section == 'custom_settings' ) {
$custom_settings = array();
$custom_settings[] = array( 'name' => __( 'Custom Settings', 'text-domain' ),
'type' => 'title',
'desc' => __( 'The following options are used to ...', 'text-domain' ),
'id' => 'custom_settings'
);
$custom_settings[] = array(
'name' => __( 'Field 1', 'text-domain' ),
'id' => 'field_one',
'type' => 'text',
'default' => get_option('field_one'),
);
$custom_settings[] = array( 'type' => 'sectionend', 'id' => 'test-options' );
return $custom_settings;
} else {
// If not, return the standard settings
return $settings;
}
}
I've been able to add new subsections to the Products tab using similar code to the above, but it isn't working for my new custom tab. Where am I going wrong here?
1) To add a setting tab with sections, you can firstly use the woocommerce_settings_tabs_array filter hook:
// Add the tab to the tabs array
function filter_woocommerce_settings_tabs_array( $settings_tabs ) {
$settings_tabs['my-custom-tab'] = __( 'My custom tab', 'woocommerce' );
return $settings_tabs;
}
add_filter( 'woocommerce_settings_tabs_array', 'filter_woocommerce_settings_tabs_array', 99 );
2) To add new sections to the page, you can use the woocommerce_sections_{$current_tab} composite hook where {$current_tab} need to be replaced by the key slug that is set in the first function:
// Add new sections to the page
function action_woocommerce_sections_my_custom_tab() {
global $current_section;
$tab_id = 'my-custom-tab';
// Must contain more than one section to display the links
// Make first element's key empty ('')
$sections = array(
'' => __( 'Overview', 'woocommerce' ),
'my-section-1' => __( 'My section 1', 'woocommerce' ),
'my-section-2' => __( 'My section 2', 'woocommerce' )
);
echo '<ul class="subsubsub">';
$array_keys = array_keys( $sections );
foreach ( $sections as $id => $label ) {
echo '<li>' . $label . ' ' . ( end( $array_keys ) == $id ? '' : '|' ) . ' </li>';
}
echo '</ul><br class="clear" />';
}
add_action( 'woocommerce_sections_my-custom-tab', 'action_woocommerce_sections_my_custom_tab', 10 );
3) For adding the settings, as well as for processing/saving, we will use a custom function, which we will then call:
// Settings function
function get_custom_settings() {
global $current_section;
$settings = array();
if ( $current_section == 'my-section-1' ) {
// My section 1
$settings = array(
// Title
array(
'title' => __( 'Your title 1', 'woocommerce' ),
'type' => 'title',
'id' => 'custom_settings_1'
),
// Text
array(
'title' => __( 'Your title 1.1', 'text-domain' ),
'type' => 'text',
'desc' => __( 'Your description 1.1', 'woocommerce' ),
'desc_tip' => true,
'id' => 'custom_settings_1_text',
'css' => 'min-width:300px;'
),
// Select
array(
'title' => __( 'Your title 1.2', 'woocommerce' ),
'desc' => __( 'Your description 1.2', 'woocommerce' ),
'id' => 'custom_settings_1_select',
'class' => 'wc-enhanced-select',
'css' => 'min-width:300px;',
'default' => 'aa',
'type' => 'select',
'options' => array(
'aa' => __( 'aa', 'woocommerce' ),
'bb' => __( 'bb', 'woocommerce' ),
'cc' => __( 'cc', 'woocommerce' ),
'dd' => __( 'dd', 'woocommerce' ),
),
'desc_tip' => true,
),
// Section end
array(
'type' => 'sectionend',
'id' => 'custom_settings_1'
),
);
} elseif ( $current_section == 'my-section-2' ) {
// My section 2
$settings = array(
// Title
array(
'title' => __( 'Your title 2', 'woocommerce' ),
'type' => 'title',
'id' => 'custom_settings_2'
),
// Text
array(
'title' => __( 'Your title 2.2', 'text-domain' ),
'type' => 'text',
'desc' => __( 'Your description 2.1', 'woocommerce' ),
'desc_tip' => true,
'id' => 'custom_settings_2_text',
'css' => 'min-width:300px;'
),
// Section end
array(
'type' => 'sectionend',
'id' => 'custom_settings_2'
),
);
} else {
// Overview
$settings = array(
// Title
array(
'title' => __( 'Overview', 'woocommerce' ),
'type' => 'title',
'id' => 'custom_settings_overview'
),
// Section end
array(
'type' => 'sectionend',
'id' => 'custom_settings_overview'
),
);
}
return $settings;
}
3.1) Add settings, via the woocommerce_settings_{$current_tab} composite hook:
// Add settings
function action_woocommerce_settings_my_custom_tab() {
// Call settings function
$settings = get_custom_settings();
WC_Admin_Settings::output_fields( $settings );
}
add_action( 'woocommerce_settings_my-custom-tab', 'action_woocommerce_settings_my_custom_tab', 10 );
3.2) Process/save the settings, via the woocommerce_settings_save_{$current_tab} composite hook:
// Process/save the settings
function action_woocommerce_settings_save_my_custom_tab() {
global $current_section;
$tab_id = 'my-custom-tab';
// Call settings function
$settings = get_custom_settings();
WC_Admin_Settings::save_fields( $settings );
if ( $current_section ) {
do_action( 'woocommerce_update_options_' . $tab_id . '_' . $current_section );
}
}
add_action( 'woocommerce_settings_save_my-custom-tab', 'action_woocommerce_settings_save_my_custom_tab', 10 );
Result:
Based on:
Implement a custom WooCommerce settings page, including page sections
woocommerce/includes/admin/settings/

Custom Checkout Field for Woocommerce with dynamic options

I want to have dynamic options for my checkout dropdown field. The options must be users of specific roles that are in WordPress users. How can I achieve it? Below is the code that I am working with. In the first function, we can get all administrator users. I want users to be in options of the dropdown in the select field of checkout.
**User Roles**
function get_users_by_role($role, $orderby, $order) {
$args = array(
'role' => 'administrator',
'orderby' => 'user_nicename',
'order' => 'ASC'
);
$users = get_users( $args );
return $users;
}
**Dropdown Field**
function everest_custom_dropdown_fields( $fields ) {
$fields['everestmerchant_extra_dropdown_fields']['dropdown'] = array(
'label' => __('Leader Name', 'woocommerce'),
'placeholder' => _x('Leader Name', 'placeholder', 'woocommerce'),
'required' => true,
'class' => array( 'wps-drop' ),
'clear' => true,
'type' => 'select',
'options' => array(
'option 1' => __('option 1', 'woocommerce' ),
'option 2' => __('option 2', 'woocommerce'
)//end of options
);
return $fields;
}
add_filter( 'woocommerce_checkout_fields', 'everest_custom_dropdown_fields' );
Get All Leaders
function get_leaders($role) {
$args = array(
'role' => $role,
'orderby' => 'user_nicename',
'order' => 'ASC'
);
$leaders = ['' => 'Please Select'];
$users = get_users( $args );
if($users){
foreach($users as $user){
$leaders[$user->data->ID] = $user->data->display_name;
}
}
return $leaders;
}
Add Leader field in checkout page
function leader_name_select_field( $checkout ){
woocommerce_form_field( 'leader_name', array(
'type' => 'select',
'required' => true,
'class' => array('form-row-wide'),
'label' => 'Leader Name',
'options' => get_leaders('administrator')
), $checkout->get_value( 'leader_name' ) );
}
add_action( 'woocommerce_after_checkout_billing_form', 'leader_name_select_field' );
Save Selected field in database.
function save_leader_name_of_order( $order_id ){
if( !empty( $_POST['leader_name'] ) )
update_post_meta( $order_id, 'leader_name', sanitize_text_field( $_POST['leader_name'] ) );
}
add_action( 'woocommerce_checkout_update_order_meta', 'save_leader_name_of_order' );
Show saved field in order page in dashboard
function leader_name_show_on_order_detail_page($order){
$leader_id = get_post_meta($order->get_id(), 'leader_name', true );
$leader = get_user_by( 'ID', $leader_id );
if($leader_id && $leader){
echo '<p class="form-field form-field-wide">';
echo '<label>Leader Name</label>';
echo '<p> ' . $leader->data->display_name . '</p>';
echo '</p>';
}
}
add_action( 'woocommerce_admin_order_data_after_order_details', 'leader_name_show_on_order_detail_page', 10, 1 );

Selective refresh in the customizer css value does not work

I'm experiencing difficulties with a theme I developed.
I'm using Envato, where I cannot enter CSS anywhere other than wp_add_inline_style(); or enqueue style.
I use preview customization directly and add partial refresh.
I have a settings menu with the following options:
choice of layout A or B
choice of layout background color
The problem is that the layout changes when the background color is changed.
Does anyone have a solution?
Code snippet: customizer.php
function customizer_nav( $wp_customize ) {
// Section
$wp_customize->add_section( 'navigasi_sett',
array(
'title' => __( 'Navigasi Primary', 'mocita' ),
'priority' => 100,
'panel' => 'primary_panel',
)
);
// Background
$wp_customize->add_setting( 'nav_background',
array(
'default' => '#0663cc',
'transport' => 'postMessage',
'sanitize_callback' => 'sanitize_hex_color',
)
);
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'nav_background',
array(
'label' => __( 'Background Menus', 'mocita' ),
'section' => 'navigasi_sett',
'settings' => 'nav_background',
)
));
// Navigasi layout
$wp_customize->add_setting( 'nav_layout',
array(
'default' => 'tes1',
'transport' => 'postMessage',
'sanitize_callback' => 'mocita_sanitize_radio_img',
)
);
$wp_customize->add_control( new Mocita_Image_Radio( $wp_customize, 'nav_layout',
array(
'label' => __( 'Navigasi Layout', 'mocita' ),
'section' => 'navigasi_sett',
'choices' => array(
'tes1' => array(
'image' => trailingslashit( get_template_directory_uri() ) . 'images/navigasi/tes1.png',
'name' => __( 'tes1', 'mocita' )
),
'tes2' => array(
'image' => trailingslashit( get_template_directory_uri() ) . 'images/navigasi/tes2.png',
'name' => __( 'tes2', 'mocita' )
)
)
)
));
}
// selevtive_refresh
if ( isset( $wp_customize->selective_refresh ) ) {
// Navigasi Layout
$wp_customize->selective_refresh->add_partial( 'nav_layout',
array(
'selector' => '#primary',
'container_inclusive' => false,
'render_callback' => 'nav_layout',
)
);
}
// callback nav_layout
function nav_layout() {
$layout = get_theme_mod( 'nav_layout', 'nav1' );
if ( $layout === 'nav1' ) {
get_template_part( 'template-parts/navigasi/navigasi', 'primary1' );
} elseif ( $layout === 'nav2' ) {
get_template_part( 'template-parts/navigasi/navigasi', 'primary2' );
}
}
?>
customize-preview.js
(function( $ ) {
// ( Navigasi ) Background
wp.customize( 'nav_background', function( value ) {
value.bind( function( to ) {
$( '#menu' ).css( 'background', to );
});
});
} )( jQuery );

WordPress login form: rename label submit field

I have created login form for a shortcode. I could rename the label for the username and the submit field. But I would also like to rename the submit field. Any suggestions?
Php:
add_action( 'init', 'my_add_shortcodes' );
function my_add_shortcodes() {
add_shortcode( 'my-login-form', 'my_login_form_shortcode' );
}
function my_login_form_shortcode( $attr ) {
if ( is_user_logged_in() )
return 'you0re already logged in';
$defaults = array(
'label_username' => 'num dutilisader',
'label_password' => 'plaid clav'
);
$attr = shortcode_atts( $defaults, $attr );
$attr['echo'] = false;
return wp_login_form( $attr );
}
Shortcode:
[my-login-form label_username="num d'utilisader" label_password="plaid clav" label_submit="s'annunziar"]
You can try the attribute label_log_in for the submit text
you can see the available parameters in the following code
`function wpfa_login_form( $args ) {
$defaults = shortcode_atts( array(
'echo' => false,
'redirect' => site_url( '/wp-admin/' ),
'form_id' => 'loginform',
'label_username' => __( 'Username', 'wpfa-textdomain' ),
'label_password' => __( 'Password', 'wpfa-textdomain' ),
'label_remember' => __( 'Remember Me', 'wpfa-textdomain' ),
'label_log_in' => __( 'Log In', 'wpfa-textdomain' ),
'id_username' => 'user_login',
'id_password' => 'user_pass',
'id_remember' => 'rememberme',
'id_submit' => 'wp-submit',
'remember' => true,
'value_username' => NULL,
'value_remember' => false
), $args, 'wpfa_login' );
$login_args = wp_parse_args( $args, $defaults );
return wp_login_form( $login_args );
} add_shortcode( 'wpfa_login', 'wpfa_login_form' );`
Here you can create a shortcode: [wpfa_login label_log_in="Show Me The Way"].
You can try altering your code based on this

My Wordpress Plugin is giving me the WSOD

I followed this tutorial,http://wp.tutsplus.com/tutorials/plugins/a-guide-to-wordpress-custom-post-types-creation-display-and-meta-boxes/, I thought very closely but when I finished it, my plugin works but it gives every other page on the site the WSOD! Once I deactivate the plugin, my other pages work again. I am running this on my mac using MAMP if that helps at all. I wanted to get it all finished before I upload and test online even though my site isn't live.
Below is my code. Any ideas on what the heck I did wrong? Thank you so much for any help you can give me.
<?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
)
);
}
?>
I took out some parts but narrowed it down to this section below that was causing the problem.
// 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;
}
I deleted add_filter( 'template_include','include_template_function', 1 ); and it seems to work fine now.
Below is my code all together that works and has been edited to get rid of a few things that I didn't really want anyway.
<?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
)
);
}
?>
Thanks for your help!
There is no 'column_ordering' function defined, though it is necessary for «add_filter( 'request', 'column_ordering' );»
Kill this filter out from code and hapiness will come!

Resources