} //save the option array update_option("taxonomy_" . $term_id . "_pg_redirect", $tax_pc_red); } else { delete_option("taxonomy_" . $term_id . "_pg_redirect"); } } // clean database after term deletion function pc_delete_term_clean_db($term_id) { delete_option('taxonomy_' . $term_id . '_pg_redirect'); } add_action('deleted_term_taxonomy', 'pc_delete_term_clean_db'); ///////////////////////////////////////////////////////////////////////// // manage category taxonomy table foreach (pc_affected_tax() as $tax) { add_filter('manage_edit-' . $tax . '_columns', 'pc_category_column_headers', 10, 1); add_filter('manage_' . $tax . '_custom_column', 'pc_category_column_row', 10, 3); } // ALLOW CONTENT - add the table column // REDIRECT CONTENTS - add the table column function pc_category_column_headers($columns) { $columns_local = array(); if (!isset($columns_local['pc_hide'])) { $columns_local['pc_hide'] = __("PC Hide", 'pc_ml'); } if (!isset($columns_local['pc_redirect'])) { $columns_local['pc_redirect'] = __("PC Redirect", 'pc_ml'); } return array_merge($columns, $columns_local);
function pc_query_filter_cat_array() { $exclude_array = array(); $args = array('hide_empty' => 0); $categories = get_terms(pc_affected_tax(), $args); foreach ($categories as $category) { if (!pc_redirect_check('category', $category)) { $exclude_array[] = '-' . $category->term_id; } } return $exclude_array; }
function pc_redirect_meta_setup() { include_once PC_DIR . '/functions.php'; global $post, $pc_users; $user_categories = get_terms('pg_user_categories', 'orderby=name&hide_empty=0'); $pc_redirect = (array) get_post_meta($post->ID, 'pg_redirect', true); $pc_unlogged_redirect = get_post_meta($post->ID, 'pg_unlogged_redirect', true); ?> <p style="margin-bottom: 7px;"><?php _e('Which user categories can see the page?', 'pc_ml'); ?> </p> <div class="pc_tax_cat_list"> <select name="pg_redirect[]" multiple="multiple" class="lcweb-chosen pc_pag_restr" data-placeholder="<?php _e('Select categories', 'pc_ml'); ?> .." autocomplete="off"> <option value="all" class="pc_all_field" <?php if (isset($pc_redirect[0]) && $pc_redirect[0] == 'all') { echo 'selected="selected"'; } ?> ><?php _e('All', 'pc_ml'); ?> </option> <option value="unlogged" class="pc_unl_field" <?php if (isset($pc_redirect[0]) && $pc_redirect[0] == 'unlogged') { echo 'selected="selected"'; } ?> ><?php _e('Unlogged Users', 'pc_ml'); ?> </option> <?php foreach ($user_categories as $ucat) { $selected = isset($pc_redirect[0]) && in_array($ucat->term_id, $pc_redirect) ? 'selected="selected"' : ''; echo '<option value="' . $ucat->term_id . '" ' . $selected . '>' . $ucat->name . '</option>'; } ?> </select> <div id="pc_unl_redir_wrap" <?php if (!in_array('unlogged', $pc_redirect)) { echo 'style="display: none;"'; } ?> > <p style="margin-bottom: 7px;"><?php _e('Where to move logged users?', 'pc_ml'); ?> </p> <select name="pg_unlogged_redirect" class="lcweb-chosen" data-placeholder="<?php _e('Select an option', 'pc_ml'); ?> .." style="width: 254px;" autocomplete="off"> <option value=""><?php _e('Use main redirect target', 'pc_ml'); ?> </option> <?php foreach (get_pages() as $pag) { if ($pag->ID == $post->ID) { continue; } // avoid loops $selected = $pc_unlogged_redirect == $pag->ID ? 'selected="selected"' : ''; echo '<option value="' . $pag->ID . '" ' . $selected . '>' . $pag->post_title . '</option>'; } ?> </select> </div> </div> <?php //// check parent restrictions and print an helper global $current_screen; $restr = array(); // post types if ($current_screen->id == 'post') { // search in every involved taxonomy foreach (pc_affected_tax() as $tax) { $terms = wp_get_post_terms($post->ID, $tax); if (is_array($terms)) { foreach ($terms as $term) { $response = pc_restrictions_helper('post', $term->term_id, $tax); if ($response) { $restr = array_merge($restr, $response); } } } } $sing_plur = count($restr) == 1 ? __('this category', 'pc_ml') : __('these categories', 'pc_ml'); } else { $response = pc_restrictions_helper('page', $post); if ($response) { $restr = array_merge($restr, $response); } $sing_plur = count($restr) == 1 ? __('this parent', 'pc_ml') : __('these parents', 'pc_ml'); } // print helper if (is_array($restr) && count($restr) > 0) { echo '<div id="pc_page_rest_helper"> <strong>' . __('Page already restricted by', 'pc_ml') . ' ' . $sing_plur . ':</strong> <dl>'; foreach ($restr as $index => $rs) { echo '<dt>' . $index . '</dt> <dd><em>' . __('visible by', 'pc_ml') . ' ' . $rs . '</em></dd>'; } echo '</dl></div>'; } ?> <?php // comments block restriction if ($pc_users->wp_user_sync) { $pc_hide_comments = (array) get_post_meta($post->ID, 'pg_hide_comments', true); $pc_hc_warn = get_post_meta($post->ID, 'pg_hc_use_warning', true); ?> <hr style="margin-top: 18px;"/> <p style="margin-bottom: 7px; font-size: 99.2%;"><?php _e('Which user categories can see comments?', 'pc_ml'); ?> </p> <div class="pc_tax_cat_list"> <select name="pg_hide_comments[]" multiple="multiple" class="lcweb-chosen pc_pag_restr" data-placeholder="<?php _e('Select categories', 'pc_ml'); ?> .." autocomplete="off"> <option value="all" class="pc_all_field" <?php if (isset($pc_hide_comments[0]) && $pc_hide_comments[0] == 'all') { echo 'selected="selected"'; } ?> ><?php _e('All', 'pc_ml'); ?> </option> <?php foreach ($user_categories as $ucat) { $selected = isset($pc_hide_comments[0]) && in_array($ucat->term_id, $pc_hide_comments) ? 'selected="selected"' : ''; echo '<option value="' . $ucat->term_id . '" ' . $selected . '>' . $ucat->name . '</option>'; } ?> </select> <div id="pc_hc_use_warning" <?php if (empty($pc_hide_comments)) { echo 'style="display: none;"'; } ?> > <p style="margin-bottom: 7px;"><?php _e('Display warning box?', 'pc_ml'); ?> </p> <select name="pg_hc_use_warning" class="lcweb-chosen" data-placeholder="<?php _e('Select an option', 'pc_ml'); ?> .." style="width: 254px;" autocomplete="off"> <option value="default" <?php selected($pc_hc_warn, 'default'); ?> ><?php _e('as default', 'pc_ml'); ?> </option> <option value="yes" <?php selected($pc_hc_warn, 'yes'); ?> ><?php _e('yes', 'pc_ml'); ?> </option> <option value="no" <?php selected($pc_hc_warn, 'no'); ?> ><?php _e('no', 'pc_ml'); ?> </option> </select> </div> </div> <?php } ?> <?php // create a custom nonce for submit verification later echo '<input type="hidden" name="pc_redirect_noncename" value="' . wp_create_nonce(__FILE__) . '" />'; ?> <script src="<?php echo PC_URL; ?> /js/chosen/chosen.jquery.min.js" type="text/javascript"></script> <script type="text/javascript" charset="utf8"> jQuery(document).ready(function($) { // all/unlogged toggles jQuery('body').delegate('.pc_tax_cat_list select', 'change', function() { var pc_sel = jQuery(this).val(); if(!pc_sel) {pc_sel = jQuery.makeArray();} // if ALL is selected, discard the rest if(jQuery.inArray("all", pc_sel) >= 0) { jQuery(this).children('option').prop('selected', false); jQuery(this).children('.pc_all_field').prop('selected', true); jQuery(this).trigger("chosen:updated"); } // if UNLOGGED is selected, discard the rest else if(jQuery.inArray("unlogged", pc_sel) >= 0) { jQuery(this).children('option').prop('selected', false); jQuery(this).children('.pc_unl_field').prop('selected', true); jQuery(this).trigger("chosen:updated"); var unlogged_chosen = true; } // unloggged redirect toggle if(jQuery(this).attr('name') == 'pg_redirect[]') { if(typeof(unlogged_chosen) != 'undefined') { jQuery('#pc_unl_redir_wrap').slideDown(); } else { jQuery('#pc_unl_redir_wrap').slideUp(); } } // hidden comments warning if(jQuery(this).attr('name') == 'pg_hide_comments[]') { if(typeof(pc_sel[0]) != 'undefined') { jQuery('#pc_hc_use_warning').slideDown(); } else { jQuery('#pc_hc_use_warning').slideUp(); } } }); // chosen jQuery('.lcweb-chosen').each(function() { var w = jQuery(this).css('width'); jQuery(this).chosen({width: w}); }); jQuery(".lcweb-chosen-deselect").chosen({allow_single_deselect:true}); }); </script> <?php }