/** * Add more items based on installed plugins etc. */ function otw_sidebar_add_items() { global $wp_sbm_int_items; //wpml $active_plugins = get_option('active_plugins'); if (otw_installed_plugin('wpml')) { $wp_sbm_int_items['wpmllanguages'] = array(); $wp_sbm_int_items['wpmllanguages'][0] = array(); $wp_sbm_int_items['wpmllanguages'][1] = __('WPML plugin language', 'otw_sbm'); $wp_sbm_int_items['wpmllanguages'][2] = __('All WPML plugin languages', 'otw_sbm'); } if (otw_installed_plugin('bbpress')) { $wp_sbm_int_items['bbp_page'] = array(); $wp_sbm_int_items['bbp_page'][0] = array(); $wp_sbm_int_items['bbp_page'][1] = __('bbPress pages', 'otw_sbm'); $wp_sbm_int_items['bbp_page'][2] = __('All bbPress pages', 'otw_sbm'); } if (otw_installed_plugin('buddypress')) { $wp_sbm_int_items['buddypress_page'] = array(); $wp_sbm_int_items['buddypress_page'][0] = array(); $wp_sbm_int_items['buddypress_page'][1] = __('BuddyPress pages', 'otw_sbm'); $wp_sbm_int_items['buddypress_page'][2] = __('All BuddyPress pages', 'otw_sbm'); } }
function otw_get_strict_filters() { global $current_user; $filters = array(); //apply user roles if (function_exists('get_currentuserinfo')) { get_currentuserinfo(); } if (isset($current_user->ID) && intval($current_user->ID) && isset($current_user->roles) && is_array($current_user->roles) && count($current_user->roles)) { $filter_key = count($filters); $filters[$filter_key][0] = 'userroles'; $filters[$filter_key][1] = array(); foreach ($current_user->roles as $u_role) { $filters[$filter_key][1][] = $u_role; } $filters[$filter_key][2] = 'any'; } else { $filter_key = count($filters); $filters[$filter_key][0] = 'userroles'; $filters[$filter_key][1] = array(); $filters[$filter_key][1][] = 'notlogged'; $filters[$filter_key][2] = 'any'; } if (otw_installed_plugin('wpml') && defined('ICL_LANGUAGE_CODE')) { $filter_key = count($filters); $filters[$filter_key][0] = 'wpmllanguages'; $filters[$filter_key][1] = array(); $filters[$filter_key][1][] = ICL_LANGUAGE_CODE; $filters[$filter_key][2] = 'all'; } return $filters; }
/** init otw sidebars * */ function otw_sidebar_init() { global $wp_registered_sidebars, $otw_replaced_sidebars, $wp_sbm_int_items, $otw_sbm_plugin_url, $pagenow, $otw_sbm_grid_manager_component, $otw_sbm_shortcode_component, $otw_sbm_form_component, $otw_sbm_grid_manager_object, $otw_sbm_widget_settings, $otw_plugin_options; otw_sidebar_add_items(); $otw_registered_sidebars = get_option('otw_sidebars'); $otw_widget_settings = get_option('otw_widget_settings'); if (!is_array($otw_widget_settings)) { $otw_widget_settings = array(); update_option('otw_widget_settings', $otw_widget_settings); } if (is_array($otw_registered_sidebars) && count($otw_registered_sidebars)) { foreach ($otw_registered_sidebars as $otw_sidebar_id => $otw_sidebar) { $sidebar_params = array(); $sidebar_params['id'] = $otw_sidebar_id; $sidebar_params['name'] = $otw_sidebar['title']; $sidebar_params['description'] = $otw_sidebar['description']; $sidebar_params['replace'] = $otw_sidebar['replace']; $sidebar_params['status'] = $otw_sidebar['status']; if (isset($otw_sidebar['widget_alignment'])) { $sidebar_params['widget_alignment'] = $otw_sidebar['widget_alignment']; } $sidebar_params['validfor'] = $otw_sidebar['validfor']; if (isset($otw_sidebar['exclude_posts_for'])) { $sidebar_params['exclude_posts_for'] = $otw_sidebar['exclude_posts_for']; } //collect all replacements for faster search in font end if (strlen($sidebar_params['replace'])) { if (!isset($otw_replaced_sidebars[$sidebar_params['replace']])) { $otw_replaced_sidebars[$sidebar_params['replace']] = array(); } $otw_replaced_sidebars[$sidebar_params['replace']][$sidebar_params['id']] = $sidebar_params['id']; if (isset($wp_registered_sidebars[$sidebar_params['replace']])) { if (isset($wp_registered_sidebars[$sidebar_params['replace']]['class'])) { $sidebar_params['class'] = $wp_registered_sidebars[$sidebar_params['replace']]['class']; } if (isset($wp_registered_sidebars[$sidebar_params['replace']]['before_widget'])) { $sidebar_params['before_widget'] = $wp_registered_sidebars[$sidebar_params['replace']]['before_widget']; } if (isset($wp_registered_sidebars[$sidebar_params['replace']]['after_widget'])) { $sidebar_params['after_widget'] = $wp_registered_sidebars[$sidebar_params['replace']]['after_widget']; } if (isset($wp_registered_sidebars[$sidebar_params['replace']]['before_title'])) { $sidebar_params['before_title'] = $wp_registered_sidebars[$sidebar_params['replace']]['before_title']; } if (isset($wp_registered_sidebars[$sidebar_params['replace']]['after_title'])) { $sidebar_params['after_title'] = $wp_registered_sidebars[$sidebar_params['replace']]['after_title']; } } } else { foreach ($otw_sbm_widget_settings as $s_type => $s_data) { if (isset($otw_plugin_options['otw_sbm_' . $s_type])) { $sidebar_params[$s_type] = $otw_plugin_options['otw_sbm_' . $s_type]; } else { $sidebar_params[$s_type] = $s_data[1]; } } } register_sidebar($sidebar_params); } } //apply validfor settings to all sidebars if (is_array($wp_registered_sidebars) && count($wp_registered_sidebars)) { foreach ($wp_registered_sidebars as $wp_widget_key => $wo_widget_data) { if (array_key_exists($wp_widget_key, $otw_widget_settings)) { $wp_registered_sidebars[$wp_widget_key]['widgets_settings'] = $otw_widget_settings[$wp_widget_key]; } else { $wp_registered_sidebars[$wp_widget_key]['widgets_settings'] = array(); } } } $custom_post_types = get_post_types(array('public' => true, '_builtin' => false), 'object'); if (is_array($custom_post_types)) { foreach ($custom_post_types as $c_key => $c_cust) { if (otw_installed_plugin('bbpress') && $c_key == 'reply') { //skip reply they appear on same pages as topics } else { $wp_sbm_int_items['cpt_' . $c_cust->name] = array(array(), $c_cust->label, __('All ', 'otw_sbm') . $c_cust->labels->name); } } } $custom_taxonomies = get_taxonomies(array('public' => true, '_builtin' => false), 'object'); if (is_array($custom_taxonomies)) { foreach ($custom_taxonomies as $c_cust) { $wp_sbm_int_items['ctx_' . $c_cust->name] = array(array(), $c_cust->label . ' ' . __('archives', 'otw_sbm'), __('All ', 'otw_sbm') . $c_cust->label . ' ' . __('archives', 'otw_sbm')); foreach ($c_cust->object_type as $c_object) { if ($c_object_info = get_post_type_object($c_object)) { $wp_sbm_int_items[$c_object . '_in_ctx_' . $c_cust->name] = array(array(), __('All', 'otw_sbm') . ' ' . $c_object_info->labels->name . ' ' . __('from taxonomy', 'otw_sbm') . ' ' . $c_cust->label, __('All', 'otw_sbm') . ' ' . $c_object_info->labels->name . ' ' . __('from taxonomy', 'otw_sbm') . ' ' . $c_cust->label); } } } } //otw grid manager component $otw_sbm_grid_manager_component = otw_load_component('otw_grid_manager'); $otw_sbm_grid_manager_object = otw_get_component($otw_sbm_grid_manager_component); if (isset($otw_plugin_options['otw_gm_metabox_for'])) { $otw_sbm_grid_manager_object->show_metabox_for = $otw_plugin_options['otw_gm_metabox_for']; } include_once plugin_dir_path(__FILE__) . 'include/otw_labels/otw_sbm_grid_manager_object.labels.php'; $otw_sbm_grid_manager_object->init(); //shortcode component $otw_sbm_shortcode_component = otw_load_component('otw_shortcode'); $otw_sbm_shortcode_object = otw_get_component($otw_sbm_shortcode_component); $otw_sbm_shortcode_object->shortcodes['sidebars'] = array('title' => __('Sidebars', 'otw_sbm'), 'enabled' => true, 'children' => false, 'order' => 132, 'parent' => false, 'path' => dirname(__FILE__) . '/include/otw_components/otw_shortcode/', 'url' => $otw_sbm_plugin_url . '/include/otw_components/otw_shortcode/'); $otw_sbm_shortcode_object->shortcodes['sidebar'] = array('title' => __('OTW Sidebar', 'otw_sbm'), 'enabled' => false, 'children' => false, 'order' => 100000, 'path' => dirname(__FILE__) . '/include/otw_components/otw_shortcode/', 'url' => $otw_sbm_plugin_url . '/include/otw_components/otw_shortcode/'); include_once plugin_dir_path(__FILE__) . 'include/otw_labels/otw_sbm_shortcode_object.labels.php'; $otw_sbm_shortcode_object->init(); //form component $otw_sbm_form_component = otw_load_component('otw_form'); $otw_sbm_form_object = otw_get_component($otw_sbm_form_component); include_once plugin_dir_path(__FILE__) . 'include/otw_labels/otw_sbm_form_object.labels.php'; $otw_sbm_form_object->init(); $otw_sbm_content_sidebars_component = otw_load_component('otw_content_sidebars'); $otw_sbm_content_sidebars_object = otw_get_component($otw_sbm_content_sidebars_component); $otw_sbm_content_sidebars_object->meta_name = 'otw_content_sidebars_settings'; if (isset($otw_plugin_options['otw_cs_metabox_for'])) { $otw_sbm_content_sidebars_object->show_metabox_for = $otw_plugin_options['otw_cs_metabox_for']; } include_once plugin_dir_path(__FILE__) . 'include/otw_labels/otw_sbm_content_sidebars_object.labels.php'; $otw_sbm_content_sidebars_object->init(); if (is_admin()) { require_once plugin_dir_path(__FILE__) . '/include/otw_process_actions.php'; /* if( get_user_option('rich_editing') ){ add_filter('mce_external_plugins', 'add_otw_tinymce_plugin'); add_filter('mce_buttons', 'register_otw_tinymce_button'); }*/ add_action('add_meta_boxes', 'otw_sbm_meta_boxes'); add_action('save_post', 'otw_sbm_pcm_save'); } else { wp_register_style('otw_sbm.css', $otw_sbm_plugin_url . '/css/otw_sbm.css'); wp_enqueue_style('otw_sbm.css'); add_filter('the_content', 'otw_sbm_pcm_show'); } }