Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //-------------------------------------------------------------------
- // rating taxonomy with custom urls
- //-------------------------------------------------------------------
- add_action('init', 'my_rating_init');
- //--------------------------------
- function my_rating_init() {
- //--------------------------------
- if (!is_taxonomy('rating')) {
- register_taxonomy( 'rating', 'post',
- array( 'hierarchical' => FALSE, 'label' => __('Rating'),
- 'public' => TRUE, 'show_ui' => TRUE,
- 'query_var' => 'rating',
- 'rewrite' => true ) );
- }
- }
- //--------------------------------
- add_filter('post_link', 'rating_permalink', 10, 3);
- add_filter('post_type_link', 'rating_permalink', 10, 3);
- //----------------------------------
- // creating urls on pages
- //----------------------------------
- function rating_permalink(
- //--------------------------------
- $permalink,
- $post_id,
- $leavename) {
- //--------------------------------
- if (strpos($permalink, '%rating%') === FALSE) return $permalink;
- // Get post
- //---------------------------
- $post = get_post($post_id);
- if (!$post) return $permalink;
- // Get taxonomy terms
- $terms = wp_get_object_terms($post->ID, 'rating');
- if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0]))
- $taxonomy_slug = $terms[0]->slug;
- else
- $taxonomy_slug = 'not-rated';
- return str_replace('%rating%', $taxonomy_slug, $permalink);
- }
- ?>
- <?php
- //-------------------------------------------------------------------
- // output rewrite rules
- //-------------------------------------------------------------------
- global $wp_rewrite;
- $wp_rewrite->flush_rules();
- ?>
- 'rewrite' => array('slug' => 'shiba-gallery', 'with_front' => FALSE)
- <?php
- //-------------------------------------------------------------------
- // post type with custom sef urls
- //-------------------------------------------------------------------
- $args = array(
- 'publicly_queryable' => true,
- 'query_var' => true,
- 'rewrite' => false,
- ...
- );
- //----------------------------------
- register_post_type('gallery',$args);
- // add to our plugin init function
- //----------------------------------
- global $wp_rewrite;
- $gallery_structure = '/galleries/%year%/%monthnum%/%gallery%';
- $wp_rewrite->add_rewrite_tag("%gallery%", '([^/]+)', "gallery=");
- $wp_rewrite->add_permastruct('gallery', $gallery_structure, false);
- // Add filter to plugin init function
- //-------------------------------------
- add_filter('post_type_link', 'gallery_permalink', 10, 3);
- // Adapted from get_permalink function in wp-includes/link-template.php
- //----------------------------------
- // creating urls
- //----------------------------------
- function gallery_permalink(
- $permalink,
- $post_id,
- $leavename) {
- //----------------------------------
- $post = get_post($post_id);
- $rewritecode = array(
- '%year%',
- '%monthnum%',
- '%day%',
- '%hour%',
- '%minute%',
- '%second%',
- $leavename? '' : '%postname%',
- '%post_id%',
- '%category%',
- '%author%',
- $leavename? '' : '%pagename%',
- );
- if ( '' != $permalink &&
- !in_array($post->post_status, array('draft', 'pending', 'auto-draft')) ) {
- $unixtime = strtotime($post->post_date);
- $category = '';
- if ( strpos($permalink, '%category%') !== false ) {
- $cats = get_the_category($post->ID);
- if ( $cats ) {
- usort($cats, '_usort_terms_by_ID'); // order by ID
- $category = $cats[0]->slug;
- if ( $parent = $cats[0]->parent )
- $category = get_category_parents($parent, false, '/', true) . $category;
- }
- // show default category in permalinks, without
- // having to assign it explicitly
- if ( empty($category) ) {
- $default_category = get_category( get_option( 'default_category' ) );
- $category = is_wp_error( $default_category ) ? '' : $default_category->slug;
- }
- }
- $author = '';
- if ( strpos($permalink, '%author%') !== false ) {
- $authordata = get_userdata($post->post_author);
- $author = $authordata->user_nicename;
- }
- $date = explode(" ",date('Y m d H i s', $unixtime));
- $rewritereplace =
- array(
- $date[0],
- $date[1],
- $date[2],
- $date[3],
- $date[4],
- $date[5],
- $post->post_name,
- $post->ID,
- $category,
- $author,
- $post->post_name,
- );
- $permalink = str_replace($rewritecode, $rewritereplace, $permalink);
- } else { // if they're not using the fancy permalink option
- }
- return $permalink;
- }
- ?>
- <?php
- //-------------------------------------------------------------------
- // create and manage custom post type
- //-------------------------------------------------------------------
- $labels = array(
- 'name' => _x('Galleries', 'post type general name'),
- 'singular_name' => _x('Gallery', 'post type singular name'),
- 'add_new' => _x('Add New', 'gallery'),
- 'add_new_item' => __("Add New Gallery"),
- 'edit_item' => __("Edit Gallery"),
- 'new_item' => __("New Gallery"),
- 'view_item' => __("View Gallery"),
- 'search_items' => __("Search Gallery"),
- 'not_found' => __('No galleries found'),
- 'not_found_in_trash' => __('No galleries found in Trash'),
- 'parent_item_colon' => ''
- );
- $args = array(
- 'labels' => $labels,
- 'public' => true,
- 'publicly_queryable' => true,
- 'show_ui' => true,
- 'query_var' => true,
- 'rewrite' => true,
- 'capability_type' => 'post',
- 'hierarchical' => false,
- 'menu_position' => null,
- 'supports' => array('title','thumbnail','excerpt')
- );
- register_post_type('gallery',$args);
- //----------------------------------------------------
- add_filter('manage_edit-gallery_columns',
- 'add_new_gallery_columns');
- //----------------------------------------------------
- function add_new_gallery_columns($gallery_columns) {
- //----------------------------------------------------
- $new_columns['cb'] = '<input type="checkbox" />';
- $new_columns['id'] = __('ID');
- $new_columns['title'] = _x('Gallery Name', 'column name');
- $new_columns['images'] = __('Images');
- $new_columns['author'] = __('Author');
- $new_columns['categories'] = __('Categories');
- $new_columns['tags'] = __('Tags');
- $new_columns['date'] = _x('Date', 'column name');
- return $new_columns;
- }
- //----------------------------------------------------
- // Add to admin_init function
- add_action('manage_gallery_posts_custom_column',
- 'manage_gallery_columns', 10, 2);
- //----------------------------------------------------
- function manage_gallery_columns(
- $column_name, $id) {
- //----------------------------------------------------
- global $wpdb;
- switch ($column_name) {
- case 'id':
- echo $id;
- break;
- case 'images':
- // Get number of images in gallery
- $num_images = $wpdb->get_var($wpdb->prepare(
- "SELECT COUNT(*) FROM $wpdb->posts WHERE post_parent = {$id};"));
- echo $num_images;
- break;
- default:
- break;
- }
- }
- ?>
- <?php
- //-------------------------------------------------------------------
- // add categories and tags to pages
- //-------------------------------------------------------------------
- //------------------------------------
- function add_page_cats_and_tags() {
- //------------------------------------
- register_taxonomy_for_object_type('post_tag', 'page');
- register_taxonomy_for_object_type('category', 'page');
- }
- //------------------------------------
- add_action( 'admin_init', 'add_page_cats_and_tags' );
- //------------------------------------
- function my_expanded_request($q) {
- //------------------------------------
- if (isset($q['tag']) || isset($q['category_name'])) {
- $q['post_type'] = array('post', 'page');
- }
- return $q;
- }
- //------------------------------------
- add_filter('request', 'my_expanded_request');
- ?>
- <?php
- //-------------------------------------------------------------------
- // pagination
- //-------------------------------------------------------------------
- if (isset($_GET['paged']))
- $cur_page = absint($_GET['paged']);
- else
- $cur_page = 1;
- //--------------------------------
- $args = array(
- 'post_type' => 'attachment',
- 'posts_per_page' => 5,
- 'paged'=> $cur_page
- );
- //--------------------------------
- query_posts($args);
- //--------------------------------
- global $wp_query;
- $page_links_total = $wp_query->max_num_pages;
- $page_links = paginate_links(
- array(
- 'base' => add_query_arg( 'paged', '%#%' ),
- 'format' => '',
- 'prev_text' => __('«'),
- 'next_text' => __('»'),
- 'total' => $page_links_total,
- 'current' => $cur_page
- ));
- //--------------------------------
- if ( $page_links ) :
- ?>
- <div class="tablenav-pages">
- <?php
- //--------------------------
- $page_links_text =
- //--------------------------
- sprintf( '<span class="displaying-num">' .
- __( 'Displaying %s–%s of %s' ) .
- '</span>%s',
- //--------------------------
- number_format_i18n( ( $cur_page - 1 ) * $wp_query->query_vars['posts_per_page'] + 1 ),
- //--------------------------
- number_format_i18n(
- min(
- $cur_page * $wp_query->query_vars['posts_per_page'],
- $wp_query->found_posts )
- ),
- //--------------------------
- number_format_i18n( $wp_query->found_posts ),
- //--------------------------
- $page_links);
- echo $page_links_text;?>
- </div>
- <?php
- endif;
- ?>
- <?php
- //-------------------------------------------------------------------
- // add the admin options page (settings API)
- //-------------------------------------------------------------------
- add_action('admin_menu',
- 'plugin_admin_add_page');
- //------------------------------------
- function plugin_admin_add_page() {
- //------------------------------------
- add_options_page( 'Custom Plugin Page',
- 'Custom Plugin Menu',
- 'manage_options', /* capabilities */
- 'plugin' /* page-id */,
- //---------------------------
- 'plugin_options_page'
- //---------------------------
- );
- }
- //------------------------------------
- function plugin_options_page() {
- //------------------------------------
- ?>
- <div>
- <h2>My custom plugin</h2>
- Options relating to the Custom Plugin.
- <form action="options.php" method="post">
- <?php
- settings_fields('plugin_options');
- ?>
- <?php
- do_settings_sections('plugin');
- ?>
- <input name="Submit" type="submit" value="<?php
- esc_attr_e('Save Changes');
- ?>" />
- </form>
- </div>
- <?php
- }
- // add the admin settings and such
- //-----------------------------------------
- add_action('admin_init',
- 'plugin_admin_init');
- //-----------------------------------------
- function plugin_admin_init(){
- //-----------------------------------------
- register_setting( 'plugin_options' /* options group */,
- 'plugin_options' /* option name */,
- //--------------------------
- 'plugin_options_validate'
- //--------------------------
- );
- //----------------------------------
- add_settings_section('plugin_main' /* section-id */,
- 'Main Settings',
- //-----------------------
- 'plugin_section_text',
- //-----------------------
- 'plugin' /* page-id */);
- //----------------------------------
- add_settings_field('ztext_string' /* option-id */,
- 'Plugin Text Input',
- //-------------------------
- 'plugin_setting_string',
- //-------------------------
- 'plugin' /* page-id */,
- 'plugin_main' /* section-id */);
- }
- //---------------------------------------
- function plugin_section_text() {
- //---------------------------------------
- echo '<p>Main description of this section here.</p>';
- }
- //---------------------------------------
- function plugin_setting_string() {
- //---------------------------------------
- $options = get_option('plugin_options');
- echo "<input id='plugin_text_string'
- name='plugin_options[ztext_string]'
- size='40' type='text'
- value='{$options['ztext_string']}' />";
- }
- //---------------------------------------
- function plugin_options_validate($input) {
- //---------------------------------------
- $newinput['ztext_string'] = trim($input['ztext_string']);
- if(!preg_match('/^[a-z0-9]{32}$/i', $newinput['ztext_string'])) {
- $newinput['ztext_string'] = '';
- }
- return $newinput;
- }
- ?>
- <?php
- //-------------------------------------------------------------------
- // Settings API
- //-------------------------------------------------------------------
- function eg_settings_api_init() {
- //-------------------------------------
- add_settings_section(
- //-------------------------------------
- 'eg_setting_section' /* section-id */,
- 'Example settings section in reading',
- //------------------------
- 'eg_setting_section_callback_function'
- //------------------------,
- 'reading' /* page-id */);
- //-------------------------------------
- add_settings_field(
- //-------------------------------------
- 'eg_setting_name' /* option-id */,
- 'Example setting Name',
- //---------------------------
- 'eg_setting_callback_function',
- //----------------------------
- 'reading', /* page-id */
- 'eg_setting_section' /* section-id */ );
- //-------------------------------------
- register_setting(
- //-------------------------------------
- 'reading' /* settings-group */,
- 'eg_setting_name' /* option-id */);
- }
- add_action('admin_init', 'eg_settings_api_init');
- //------------------------------------------
- function eg_setting_section_callback_function() {
- echo '<p>Intro text for our settings section</p>';
- }
- //------------------------------------------
- function eg_setting_callback_function() {
- echo '<input name=
- //-----------------------
- "eg_setting_name"
- //-----------------------
- id="gv_thumbnails_insert_into_excerpt" type="checkbox" value="1" class="code" ' .
- checked( 1,
- //---------------------------------
- get_option('eg_setting_name'),
- //---------------------------------
- false ) . ' /> Explanation text';
- }
- ?>
- <?php
- //-------------------------------------------------------------------
- // custom settings output handlers
- //-------------------------------------------------------------------
- //-----------------------------------------------
- function custom_do_settings_sections($page) {
- //-----------------------------------------------
- global $wp_settings_sections, $wp_settings_fields;
- if ( !isset($wp_settings_sections) || !isset($wp_settings_sections[$page]) )
- return;
- //----------------------------------
- foreach( (array) $wp_settings_sections[$page] as $section ) {
- echo "<h3>{$section['title']}</h3>\n";
- call_user_func($section['callback'], $section);
- if ( !isset($wp_settings_fields) ||
- !isset($wp_settings_fields[$page]) ||
- !isset($wp_settings_fields[$page][$section['id']]) )
- continue;
- echo '<div class="settings-form-wrapper">';
- //-----------------------------
- custom_do_settings_fields($page, $section['id']);
- //-----------------------------
- echo '</div>';
- }
- }
- //-----------------------------------------------
- function custom_do_settings_fields(
- $page, $section) {
- //-----------------------------------------------
- global $wp_settings_fields;
- if ( !isset($wp_settings_fields) ||
- !isset($wp_settings_fields[$page]) ||
- !isset($wp_settings_fields[$page][$section]) )
- return;
- //--------------------------------
- foreach ( (array) $wp_settings_fields[$page][$section] as $field ) {
- echo '<div class="settings-form-row">';
- if ( !empty($field['args']['label_for']) )
- echo '<p><label for="' . $field['args']['label_for'] . '">' .
- $field['title'] . '</label><br />';
- else
- echo '<p>' . $field['title'] . '<br />';
- //---------------------------------
- call_user_func($field['callback'], $field['args']);
- echo '</p></div>';
- }
- }
- ?>
- <?php
- //-------------------------------------------------------------------
- // custom post types
- //-------------------------------------------------------------------
- $labels = array(
- 'name' => _x('Galleries', 'post type general name'),
- 'singular_name' => _x('Gallery', 'post type singular name'),
- 'add_new' => _x('Add New', 'gallery'),
- 'add_new_item' => __("Add New Gallery"),
- 'edit_item' => __("Edit Gallery"),
- 'new_item' => __("New Gallery"),
- 'view_item' => __("View Gallery"),
- 'search_items' => __("Search Gallery"),
- 'not_found' => __('No galleries found'),
- 'not_found_in_trash' => __('No galleries found in Trash'),
- 'parent_item_colon' => ''
- );
- //---------------------------
- $args = array(
- 'labels' => $labels,
- 'public' => true,
- 'publicly_queryable' => true,
- 'show_ui' => true,
- 'query_var' => true,
- 'rewrite' => true,
- 'capability_type' => 'post',
- 'hierarchical' => false,
- 'menu_position' => null,
- 'supports' => array('title','thumbnail','excerpt')
- );
- //----------------------------
- register_post_type('gallery',$args);
- //------------------------------------------
- // add post type supports after creation
- //------------------------------------------
- add_post_type_support('gallery', 'title');
- add_post_type_support('gallery', array('title', 'thumbnail', 'excerpt') );
- //------------------------------------------
- // taxonomies linked to post type
- //------------------------------------------
- $args = array(
- 'labels' => $labels,
- ...
- 'taxonomies' => array('category', 'post_tag')
- );
- register_post_type('gallery',$args);
- //--------------------------------------
- // Add meta box
- // goes into our admin_init function
- //--------------------------------------
- add_meta_box( 'gallery-type-div', __('Gallery Type'),
- 'gallery_type_metabox',
- 'gallery',
- 'normal', 'low');
- //-------------------------------------
- function gallery_type_metabox($post) {
- //-------------------------------------
- $gallery_type = get_post_meta($post->ID, '_gallery_type', TRUE);
- if (!$gallery_type) $gallery_type = 'attachment';
- ?>
- <input type="hidden" name="gallery_type_noncename" id="gallery_type_noncename"
- value="<?php echo wp_create_nonce( 'gallery_type'.$post->ID );?>" />
- <input type="radio" name="gallery_type" value="any"
- <?php if ($gallery_type == 'any') echo "checked=1";?>> Any.<br/>
- <input type="radio" name="gallery_type" value="attachment"
- <?php if ($gallery_type == 'attachment') echo "checked=1";?>> Only Attachments.<br/>
- <input type="radio" name="gallery_type" value="post"
- <?php if ($gallery_type == 'post') echo "checked=1";?>> Only Posts.<br/>
- <input type="radio" name="gallery_type" value="gallery"
- <?php if ($gallery_type == 'gallery') echo "checked=1";?>> Only Galleries.<br/>
- <?php
- }
- //----------------------------
- // Add to admin_init function
- //----------------------------
- add_action('save_post',
- array(&$this,'save_gallery_data') );
- //------------------------------------------
- function save_gallery_data($post_id) {
- //------------------------------------------
- //----------------------------------------
- // verify this came from the our screen
- // and with proper authorization.
- //----------------------------------------
- if ( !wp_verify_nonce( $_POST['gallery_type_noncename'],
- 'gallery_type'.$post_id )) {
- return $post_id;
- }
- //--------------------------------------------
- // verify if this is an auto save routine.
- // If it is our form has not been submitted,
- // so we dont want to do anything
- //--------------------------------------------
- if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
- return $post_id;
- //--------------------------------
- // Check permissions
- //--------------------------------
- if ( !current_user_can( 'edit_post', $post_id ) )
- return $post_id;
- //--------------------------------------------
- // OK, we're authenticated:
- // we need to find and save the data
- //--------------------------------------------
- $post = get_post($post_id);
- if ($post->post_type == 'gallery') {
- update_post_meta($post_id, '_gallery_type',
- esc_attr($_POST['gallery_type']) );
- return(
- esc_attr($_POST['gallery_type']));
- }
- return $post_id;
- }
- ?>
- <?php
- //-------------------------------------------------------------------
- // link categories and tags to pages
- // and output pages on category and tag archive pages
- //-------------------------------------------------------------------
- add_meta_box( 'tagsdiv-post_tag', __('Page Tags'),
- 'post_tags_meta_box',
- 'page', 'side', 'low');
- add_meta_box( 'categorydiv', __('Categories'),
- 'post_categories_meta_box',
- 'page', 'side', 'core');
- register_taxonomy_for_object_type('post_tag', 'page');
- register_taxonomy_for_object_type('category', 'page');
- //----------------------------------
- add_filter('request', 'my_expanded_request');
- //----------------------------------
- function my_expanded_request($q) {
- //----------------------------------
- if (isset($q['tag']) || isset($q['category_name']))
- $q['post_type'] = array('post', 'page');
- return $q;
- }
- //-------------------------------------------------------------------
- // registering and using dynamic sidebars
- //-------------------------------------------------------------------
- ?>
- <ul id="sidebar">
- <?php if ( ! dynamic_sidebar() ) : ?>
- <li>{static sidebar item 1}</li>
- <li>{static sidebar item 2}</li>
- <?php endif; ?>
- </ul>
- <ul id="sidebar">
- <?php dynamic_sidebar( 'right-sidebar' ); ?>
- </ul>
- <?php if ( is_active_sidebar( 'left-sidebar' ) ) : ?>
- <ul id="sidebar">
- <?php dynamic_sidebar( 'left-sidebar' ); ?>
- </ul>
- <?php endif; ?>
- <?php
- register_sidebar( array(
- 'id' => 'top-menu',
- 'name' => __( 'Top Menu', $text_domain ),
- 'description' => __( 'This sidebar is located above the age logo.', $text_domain ),
- ) );
- //-------------------------------------------------------------------
- // output standart widgets
- //-------------------------------------------------------------------
- ?>
- <?php the_widget( 'WP_Widget_Archives' ); ?>
- <?php the_widget( 'WP_Widget_Archives', 'dropdown=1' ); ?>
- <?php the_widget( 'WP_Widget_Calendar', $instance, $args ); ?>
- <?php the_widget( 'WP_Widget_Calendar' ); ?>
- <?php the_widget( 'WP_Widget_Categories', $instance, $args ); ?>
- <?php the_widget( 'WP_Widget_Categories'); ?>
- <?php the_widget( 'WP_Widget_Categories', 'dropdown=1&count=1' ); ?>
- <?php the_widget( 'WP_Widget_Links', $instance, $args ); ?>
- <?php the_widget( 'WP_Widget_Links' ); ?>
- <?php the_widget( 'WP_Widget_Links', 'category=2,3' ); ?>
- <?php the_widget( 'WP_Widget_Meta', $instance, $args ); ?>
- <?php the_widget('WP_Widget_Pages', 'title=Contents&sortby=post_modified',
- 'before_title=<h3>&after_title=</h3>'); ?>
- <?php the_widget( 'WP_Widget_Recent_Posts', $instance, $args ); ?>
- <?php the_widget( 'WP_Widget_RSS', $instance, $args ); ?>
- <?php the_widget( 'WP_Widget_Search', $instance, $args ); ?>
- <?php the_widget( 'WP_Widget_Tag_Cloud', $instance, $args ); ?>
- <?php the_widget( 'WP_Widget_Text', $instance, $args ); ?>
- <?php
- //-------------------------------------------------------------------
- // find out the name of current filter
- //-------------------------------------------------------------------
- add_filter("_my_filter","common_function");
- add_filter("_another_filter","common_function");
- //----------------------------------------
- function common_function(){
- //----------------------------------------
- $currentFilter = current_filter();
- switch ($currentFilter) {
- case '_my_filter':
- echo "Called by My Filter";
- break;
- case '_another_filter':
- echo "Called by another filter";
- break;
- }
- }
- //------------------------------------------
- // system processing of hooked filters
- //------------------------------------------
- function <process_hook>($hook, $value) {
- //------------------------------------------
- global $wp_filter, $wp_current_filter;
- $wp_current_filter[] = $hook; // "Push" the hook onto the stack.
- $value = call_user_func($wp_filter[$hook]['function'],$value);
- array_pop($wp_current_filter);
- return $value;
- }
- //---------------------------
- function current_filter() {
- //---------------------------
- global $wp_current_filter;
- return end( $wp_current_filter );
- }
- ?>
- <?php
- //-------------------------------------------------------------------
- // check if requested archive page of certain post type
- //-------------------------------------------------------------------
- if( is_post_type_archive( array( 'book', 'video' ) ) ) {
- // находимся на странице архива книг или видеозаписей
- }
- ?>
- <?php
- //-------------------------------------------------------------------
- // add tab view with posts of certain category
- //-------------------------------------------------------------------
- add_action('pre_get_posts', 'query_add_filter' );
- //-----------------------------------------
- function query_add_filter( $wp_query ) {
- //-----------------------------------------
- if( is_admin()) {
- add_filter('views_edit-post', 'Add_My_filter');
- }
- }
- //-----------------------------------------
- function Add_My_filter($views) {
- //-----------------------------------------
- global $wp_query;
- unset($views['mine']);
- $my_cat = YOUR-CAT-ID
- $query = array(
- 'author' => $current_user->ID,
- 'post_type' => 'post',
- 'post_status' => 'publish',
- 'cat' => $my_cat
- );
- //-----------------------------
- $result = new WP_Query($query);
- $class = ($wp_query->query_vars['cat'] == 'featured') ? ' class="current"' : '';
- $views['publish_f'] =
- sprintf('<a href="%s"'. $class .'>Publish Featured <span class="count">(%d)</span></a>',
- admin_url('edit.php?post_status=publish&post_type=post&cat='.$my_cat),
- $result->found_posts);
- return $views;
- }
- ?>
- <?php
- //-------------------------------------------------------------------
- // altering tabs in users view
- //-------------------------------------------------------------------
- add_filter( 'views_users', 'modify_views_users_so_15295853' );
- function modify_views_users_so_15295853( $views )
- {
- // Manipulate $views
- return $views;
- }
- ?>
- The content of $views in my system is:
- Array
- (
- [all] => <a href='users.php' class="current">
- All <span class="count">(7)</span></a>
- [administrator] => <a href='users.php?role=administrator'>
- Administrator <span class="count">(1)</span></a>
- [editor] => <a href='users.php?role=editor'>
- Editor <span class="count">(1)</span></a>
- [subscriber] => <a href='users.php?role=subscriber'>
- Subscriber <span class="count">(5)</span></a>
- )
- <?php
- //-------------------------------------------------------------------
- // remove tab from medialibrary window
- //-------------------------------------------------------------------
- add_filter('media_upload_tabs',
- 'remove_media_library_tab');
- //------------------------------------------
- function remove_media_library_tab($tabs) {
- //------------------------------------------
- unset($tabs['library']);
- return $tabs;
- }
- //------------------------------------------
- function remove_media_library_tab($tabs) {
- //------------------------------------------
- if (isset($_REQUEST['post_id'])) {
- $post_type = get_post_type($_REQUEST['post_id']);
- if ('post' == $post_type)
- unset($tabs['library']);
- unset($tabs['gallery']);
- }
- return $tabs;
- }
- ?>
- <?php
- //-------------------------------------------------------------------
- // register custom sidebars
- //-------------------------------------------------------------------
- function starkers_widgets_init() {
- // Area 1, located at the top of the sidebar.
- register_sidebar( array(
- 'name' => __( 'Primary Widget Area', 'starkers' ),
- 'id' => 'primary-widget-area',
- 'description' => __( 'The primary widget area', 'starkers' ),
- 'before_widget' => '<li>',
- 'after_widget' => '</li>',
- 'before_title' => '<h3>',
- 'after_title' => '</h3>',
- ) );
- // Area 3, located in the footer. Empty by default.
- register_sidebar( array(
- 'name' => __( 'First Footer Widget Area', 'starkers' ),
- 'id' => 'first-footer-widget-area',
- 'description' => __( 'The first footer widget area', 'starkers' ),
- 'before_widget' => '<li>',
- 'after_widget' => '</li>',
- 'before_title' => '<h3>',
- 'after_title' => '</h3>',
- ) );
- // ... more calls to register_sidebar() ...
- }
- ?>
- <?php
- //-------------------------------------------------------------------
- // choose custom static sidebar according to conditions
- //-------------------------------------------------------------------
- function mytheme_sidebar($name)
- {
- $name = apply_filters('mytheme_sidebar', $name);
- get_sidebar($name);
- }
- //-----------------------------
- add_filter('mytheme_sidebar',
- 'mytheme_custom_sidebar');
- //-----------------------------
- mytheme_sidebar('left');
- //------------------------------------
- function mytheme_custom_sidebar($name)
- //------------------------------------
- {
- return is_user_logged_in() ? 'loggedin' : $name;
- }
- ?>
- <?php
- //-------------------------------------------------------------------
- // Retrieve full list of sidebars and their widgets.
- //-------------------------------------------------------------------
- $sidebars_widgets = wp_get_sidebars_widgets();
- //-----------------------------------------------------
- function wp_get_sidebars_widgets($deprecated = true) {
- //-----------------------------------------------------
- if ( $deprecated !== true )
- _deprecated_argument( __FUNCTION__, '2.8.1' );
- global $wp_registered_widgets, $_wp_sidebars_widgets, $sidebars_widgets;
- //-------------------------------------------------
- // If loading from front page, consult $_wp_sidebars_widgets rather than options
- // to see if wp_convert_widget_settings() has made manipulations in memory.
- //-------------------------------------------------
- if ( !is_admin() ) {
- if ( empty($_wp_sidebars_widgets) )
- $_wp_sidebars_widgets = get_option('sidebars_widgets', array());
- $sidebars_widgets = $_wp_sidebars_widgets;
- } else {
- $sidebars_widgets = get_option('sidebars_widgets', array());
- }
- if ( is_array( $sidebars_widgets ) && isset($sidebars_widgets['array_version']) )
- unset($sidebars_widgets['array_version']);
- $sidebars_widgets = apply_filters('sidebars_widgets', $sidebars_widgets);
- return $sidebars_widgets;
- }
- ?>
- <?php
- //-------------------------------------------------------------------
- // switch sidebar contents according to conditions
- //-------------------------------------------------------------------
- add_action('widgets_init', 'wpse64492_register');
- //---------------------------------------------------
- function wpse64492_register()
- {
- register_sidebar(array(
- 'name' => __('Logged In Sidebar', 'wpse64492'),
- 'id' => 'logged-in'
- ));
- }
- //---------------------------------------------------
- add_filter('sidebars_widgets', 'wpse64492_switch');
- //---------------------------------------------------
- // switch to virtual sidebar 'logged-in'
- //---------------------------------------------------
- function wpse64492_switch($widgets)
- //---------------------------------------------------
- {
- if(is_admin())
- return $widgets;
- $key = 'sidebar-1'; // the sidebar you want to change!
- if(isset($widgets[$key]) && is_user_logged_in() && isset($widgets['logged-in']))
- $widgets[$key] = $widgets['logged-in'];
- return $widgets;
- }
- //-------------------------------------------------------------------
- // output sidebar if it is not empty
- //-------------------------------------------------------------------
- ?>
- <?php $sidebars_widgets = wp_get_sidebars_widgets(); ?>
- <?php if(!empty($sidebars_widgets['site-footer'])) : ?>
- <div id="footer-widgets">
- <div id="footer-widgets-wrapper">
- <?php dynamic_sidebar('Footer') ?>
- <div class="clear"></div>
- </div>
- </div>
- <?php endif; ?>
- <?php
- //-------------------------------------------------------------------
- // register and output dynamic sidebar
- //-------------------------------------------------------------------
- if ( function_exists('register_sidebar') )
- register_sidebar(array(
- 'before_widget' => '',
- 'after_widget' => '',
- 'before_title' => '<h4>',
- 'after_title' => '</h4>',
- ));
- ?>
- <?php if ( !function_exists('dynamic_sidebar')
- || !dynamic_sidebar() ) : ?>
- <?php endif; ?>
- //-------------------------------------------------------------------
- // The $wp_registered_sidebars global variable contains an array
- //-------------------------------------------------------------------
- Array (
- [sidebar-1] => Array (
- [name] => Right Sidebar
- [id] => sidebar-1
- [description] =>
- [before_widget] => <li id="%1$s" class="widget %2$s">
- [after_widget] => </li>
- [before_title] => <div class="widget-title">
- [after_title] => </div> )
- [sidebar-2] => Array (
- [name] => Extra Sidebar
- [id] => sidebar-2
- [description] =>
- [before_widget] => <li id="%1$s" class="widget %2$s">
- [after_widget] => </li>
- [before_title] => <div class="widget-title">
- [after_title] =></div> )
- ... )
- //-------------------------------------------------------------------
- The $wp_registered_widgets global variable contains an array
- //-------------------------------------------------------------------
- Array (
- [archives-1] => Array (
- [name] => Archives
- [id] => archives-1
- [callback] => Array (
- [0] => WP_Widget_Archives Object (
- [id_base] => archives
- [name] => Archives
- [widget_options] => Array (
- [classname] => widget_archive
- [description] => A monthly archive of your blog’s posts )
- [control_options] => Array (
- [id_base] => archives )
- [number] => 1
- [id] => archives-1
- [updated] =>
- [option_name] => widget_archives )
- [1] => display_callback )
- [params] => Array (
- [0] => Array (
- [number] => -1 )
- )
- [classname] => widget_archive
- [description] => A monthly archive of your blog’s posts )
- [text-8] => Array (
- [name] => Text
- [id] => text-8
- [callback] => Array (
- [0] => WP_Widget_Text Object (
- [id_base] => text
- [name] => Text
- [widget_options] => Array (
- [classname] => widget_text
- [description] => Arbitrary text or HTML )
- [control_options] => Array (
- [id_base] => text
- [width] => 400
- [height] => 350 )
- [number] => 8
- [id] => text-8
- [updated] =>
- [option_name] => widget_text )
- [1] => display_callback )
- [params] => Array (
- [0] => Array (
- [number] => 8 )
- )
- [classname] => widget_text
- [description] => Arbitrary text or HTML )
- ... )
- <?php
- //-------------------------------------------------
- $sidebar_widgets = wp_get_sidebars_widgets();
- //-------------------------------------------------
- ?>
- Array (
- [wp_inactive_widgets] => Array (
- [0] => pages-4
- [1] => archives-3
- [2] => categories-3
- [3] => text-4
- [4] => menubar-3
- [5] => calendar-19
- [6] => meta-6
- [7] => meta-7 )
- [sidebar-1] => Array (
- [0] => archives-2
- [1] => search-3
- [2] => categories-2 )
- [sidebar-2] => Array ()
- [sidebar-3] => Array (
- [0] => menubar-4 )
- ... )
- <?php
- wp_set_sidebars_widgets($sidebar_widgets);
- wp_enqueue_script('admin-widgets');
- add_filter('sidebars_widgets',
- array(&$this,'sidebars_widgets'));
- function sidebars_widgets($sidebars_widgets) {
- ...
- return $new_widgets;
- }
- ?>
- <?php
- //-------------------------------------------------------------------
- // Add "first" and "last" CSS classes to dynamic sidebar widgets.
- // Also adds numeric index class for each widget (widget-1, etc.)
- //-------------------------------------------------------------------
- function widget_first_last_classes($params) {
- global $my_widget_num; // Global a counter array
- //-------------------------------------------------------
- // Get the id for the current sidebar we're processing
- //-------------------------------------------------------
- $this_id = $params[0]['id'];
- //------------------------------------------
- // Get an array of ALL registered widgets
- //------------------------------------------
- $arr_registered_widgets = wp_get_sidebars_widgets();
- //---------------------------------------------------
- // If the counter array doesn't exist, create it
- //---------------------------------------------------
- if(!$my_widget_num) {
- $my_widget_num = array();
- }
- //------------------------------------------------------
- // Check if the current sidebar has no widgets
- //------------------------------------------------------
- if(!isset($arr_registered_widgets[$this_id]) || !is_array($arr_registered_widgets[$this_id])) {
- return $params;
- }
- //----------------------------------------------------------
- // See if the counter array has an entry for this sidebar
- //----------------------------------------------------------
- if(isset($my_widget_num[$this_id])) {
- $my_widget_num[$this_id] ++;
- }
- else {
- //-------------- If not, create it starting with 1
- $my_widget_num[$this_id] = 1;
- }
- //------------------------------------------------------------
- // Add a widget number class for additional styling options
- //------------------------------------------------------------
- $class = 'class="widget-' . $my_widget_num[$this_id] . ' ';
- if($my_widget_num[$this_id] == 1) { // If this is the first widget
- $class .= 'widget-first ';
- //---------------------------------------
- // If this is the last widget
- //---------------------------------------
- } elseif($my_widget_num[$this_id] == count($arr_registered_widgets[$this_id])) {
- $class .= 'widget-last ';
- }
- //-----------------------------------------------
- // Insert our new classes into "before widget"
- //-----------------------------------------------
- $params[0]['before_widget'] = str_replace('class="', $class, $params[0]['before_widget']);
- return $params;
- }
- //----------------------------------------------------
- add_filter('dynamic_sidebar_params',
- 'widget_first_last_classes');
- //----------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement