Skip to content

Instantly share code, notes, and snippets.

@michael-cannon
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michael-cannon/eb99f4317bcae9be0fd0 to your computer and use it in GitHub Desktop.
Save michael-cannon/eb99f4317bcae9be0fd0 to your computer and use it in GitHub Desktop.
Sidebar settings for Custom Bulk/Quick Edit Premium
<?php
/**
* Plugin Name: Sidebar for Custom Bulk/Quick Edit Premium
* Plugin URI: http://aihr.us/downloads/custom-bulkquick-edit-premium-wordpress-plugin/
* Author: Michael Cannon <mc@aihr.us>
*/
if ( ! class_exists( 'Custom_Bulkquick_Edit_Settings' ) ) {
return;
}
add_filter( 'manage_page_posts_columns', 'chms_manage_post_posts_columns' );
add_filter( 'manage_post_posts_columns', 'chms_manage_post_posts_columns' );
function chms_manage_post_posts_columns( $columns ) {
$columns['sbg_selected_sidebar_replacement'] = esc_html__( 'Sidebar' );
return $columns;
}
// add_filter( 'cbqe_post_types_ignore', 'chms_cbqe_post_types_ignore' );
function chms_cbqe_post_types_ignore( $post_types ) {
foreach ( $post_types as $key => $value ) {
if ( 'page' == $value ) {
unset( $post_types[ $key ] );
}
}
return $post_types;
}
add_filter( 'cbqe_settings_as_types', 'chms_settings_as_types' );
function chms_settings_as_types( $as_types ) {
$as_types['sbg_selected_sidebar_replacement'] = esc_html__( 'As sidebar' );
return $as_types;
}
add_filter( 'cbqe_configuration_default', 'chms_configuration_default', 10, 3 );
/**
*
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
function chms_configuration_default( $default, $id, $type ) {
switch ( $type ) {
case 'sbg_selected_sidebar_replacement':
$default = array();
$default[] = '0|Default';
$sidebars = $GLOBALS['wp_registered_sidebars'];
if ( ! empty( $sidebars ) ) {
foreach ( $sidebars as $sidebar ) {
// $default[] = $sidebar['id'] . '|' . $sidebar['name'];
$default[] = $sidebar['name'] . '|' . $sidebar['name'];
}
}
$default = implode( "\n", $default );
break;
}
return $default;
}
add_filter( 'cbqe_quick_edit_custom_box_field', 'chms_quick_edit_custom_box_field', 10, 5 );
/**
*
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
function chms_quick_edit_custom_box_field( $input, $field_type, $field_name, $options, $bulk_mode ) {
$column_name = str_replace( Custom_Bulkquick_Edit::SLUG, '', $field_name );
$field_name_var = str_replace( '-', '_', $field_name );
$result = $input;
switch ( $field_type ) {
case 'sbg_selected_sidebar_replacement':
$result = Custom_Bulkquick_Edit::custom_box_select( $column_name, $field_name, $field_name_var, $options, $bulk_mode );
break;
}
return $result;
}
add_filter( 'cbqe_manage_posts_custom_column_field_type', 'chms_manage_posts_custom_column_field_type', 10, 4 );
/**
*
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
function chms_manage_posts_custom_column_field_type( $current, $field_type, $column, $post_id ) {
global $post;
$result = $current;
switch ( $field_type ) {
case 'sbg_selected_sidebar_replacement':
$details = Custom_Bulkquick_Edit::get_field_config( $post->post_type, $column );
$options = explode( "\n", $details );
$result = Custom_Bulkquick_Edit::column_select( $column, $current, $options, $field_type );
break;
}
return $result;
}
add_action( 'cbqe_save_post', 'chms_save_post', 20 );
function chms_save_post( $post_id ) {
$field = 'sbg_selected_sidebar_replacement';
$field2 = 'sbg_selected_sidebar';
if ( ! isset( $_POST[ Custom_Bulkquick_Edit::SLUG . $field ] ) ) {
return;
}
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return;
}
$old = get_post_meta( $post_id, $field, true );
$new = $_POST[ Custom_Bulkquick_Edit::SLUG . $field ];
if ( $new && $new != $old ) {
remove_action( 'edit_page_form', array( 'sidebar_generator', 'save_form' ) );
remove_action( 'edit_post', array( 'sidebar_generator', 'save_form' ) );
remove_action( 'publish_post', array( 'sidebar_generator', 'save_form' ) );
remove_action( 'save_post', array( 'sidebar_generator', 'save_form' ) );
delete_post_meta( $post_id, $field );
delete_post_meta( $post_id, $field2 );
if ( Custom_Bulkquick_Edit_Settings::RESET != $new ) {
$new = array( $new );
update_post_meta( $post_id, $field, $new );
$new2 = array( 0 );
update_post_meta( $post_id, $field2, $new2 );
}
unset( $_POST[ Custom_Bulkquick_Edit::SLUG . $field ] );
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment