Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Pilot Press integration for Custom Bulk/Quick Edit plugin
<?php
/**
* Pilot Press integration for Custom Bulk/Quick Edit plugin
*
* @author Michael Cannon <mc@aihr.us>
*/
add_filter( 'manage_post_posts_columns', 'rgp_manage_post_posts_columns' );
add_filter( 'manage_guitarlessons_posts_columns', 'rgp_manage_post_posts_columns' );
add_filter( 'manage_weeklylessons_posts_columns', 'rgp_manage_post_posts_columns' );
add_filter( 'manage_songlessons_posts_columns', 'rgp_manage_post_posts_columns' );
function rgp_manage_post_posts_columns( $columns ) {
$columns['_pilotpress_level'] = esc_html__( 'Pilot Press Level' );
$columns['_pilotpress_show_in_nav'] = esc_html__( 'Show in Navigation' );
$columns['_pilotpress_redirect_location'] = esc_html__( 'On Error' );
return $columns;
}
add_filter( 'cbqe_settings_as_types', 'rgp_settings_as_types' );
function rgp_settings_as_types( $as_types ) {
$as_types['pilot_press_levels'] = esc_html__( 'As Pilot Press Levels' );
$as_types['pilotpress_redirect_location'] = esc_html__( 'As Pilot Press Redirect Location' );
return $as_types;
}
add_filter( 'cbqe_configuration_default', 'rgp_configuration_default', 10, 3 );
/**
*
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
function rgp_configuration_default( $default, $id, $type ) {
switch ( $type ) {
case 'pilot_press_levels':
$default = array();
$default[] = 'Free';
$default[] = 'All Access Monthly Membership';
$default[] = 'All Access Lifetime Membership';
$default = implode( "\n", $default );
break;
case 'pilotpress_redirect_location':
global $pilotpress;
$pages = $pilotpress->get_routeable_pages();
$default = array();
foreach ( $pages as $key => $value ) {
$default[] = $key . '|' . $value;
}
$default = implode( "\n", $default );
break;
}
return $default;
}
add_filter( 'cbqe_quick_edit_custom_box_field', 'rgp_quick_edit_custom_box_field', 10, 5 );
/**
*
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
function rgp_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 'pilot_press_levels':
if ( ! $bulk_mode ) {
$result = Custom_Bulkquick_Edit::custom_box_checkbox( $column_name, $field_name, $field_name_var, $options );
} else {
$result = Custom_Bulkquick_Edit::custom_box_select_multiple( $column_name, $field_name, $field_name_var, $options, $bulk_mode );
}
break;
case 'pilotpress_redirect_location':
$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', 'rgp_manage_posts_custom_column_field_type', 10, 4 );
/**
*
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
function rgp_manage_posts_custom_column_field_type( $current, $field_type, $column, $post_id ) {
global $post;
$result = $current;
switch ( $field_type ) {
case 'pilot_press_levels':
$field = '_pilotpress_level';
$current = get_post_meta( $post_id, $field );
$details = Custom_Bulkquick_Edit::get_field_config( $post->post_type, $column );
$options = explode( "\n", $details );
$field_type = 'checkbox';
$result = Custom_Bulkquick_Edit::column_checkbox_radio( $column, $current, $options, $field_type );
break;
case 'pilotpress_redirect_location':
$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', 'rgp_save_post', 20 );
function rgp_save_post( $post_id ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return;
}
$post = get_post( $post_id );
$post_type = $post->post_type;
$field = '_pilotpress_level';
$field_type = Custom_Bulkquick_Edit::is_field_enabled( $post_type, $field );
if ( empty( $field_type ) ) {
return;
}
delete_post_meta( $post_id, $field );
if ( ! isset( $_POST[ Custom_Bulkquick_Edit::SLUG . $field ] ) ) {
return;
}
$new = $_POST[ Custom_Bulkquick_Edit::SLUG . $field ];
if ( empty( $new ) ) {
return;
}
if ( in_array( Custom_Bulkquick_Edit_Settings::RESET, $new ) ) {
return;
}
foreach ( $new as $value ) {
add_post_meta( $post_id, $field, $value );
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment