Skip to content

Commit

Permalink
Version 2013.09.26
Browse files Browse the repository at this point in the history
  • Loading branch information
brasofilo committed Sep 26, 2013
1 parent bc76225 commit e43c074
Show file tree
Hide file tree
Showing 14 changed files with 878 additions and 329 deletions.
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@
WordPress plugin for adding a custom meta to New Sites.

## Description
Based in this [WordPress Question](http://wordpress.stackexchange.com/questions/50235/multisite-how-to-add-custom-blog-options-to-new-blog-setup-form)
The plugin adds a new field "category" to the Site Info screen.
A sortable column is also added in the Sites list screen.
A Categories submenu is created under Sites, add or remove categories there.

A new field will be enabled when adding new site in the back and the front end.

Two columns will be added to the Sites listing screen: ID and Category.
Available hooks:
```
// Cache time, default 3600 (1hour)
add_filter( 'msc_transient_time', function(){ return 1; } );
// For debugging purposes
add_filter( 'msc_show_mature_column', '__return_true' );
```

Originally based on this [WordPress Question](http://wordpress.stackexchange.com/q/50235/12615).
[Here's a copy](https://gist.github.com/brasofilo/6715423) of the first version of the plugin.

## Installation
### Requirements
Expand All @@ -19,19 +27,17 @@ Two columns will be added to the Sites listing screen: ID and Category.
1. Unpack the download-package
1. Upload the file to the `/wp-content/plugins/` directory
1. Activate the plugin through the 'Network Plugins' menu in WordPress
1. Go to `/wp-admin/network/sites.php`, `/wp-admin/network/site-new.php` and `/wp-signup.php` to see it in action


## Screenshots
**Sites Manager**
**Sites Manager showing the debug column *mature*.**

![Sites Manager](https://github.com/brasofilo/multisite-site-category/raw/master/img/screenshot-1.png)

**Add site : back end**
**Site info**

![Site add back end](https://github.com/brasofilo/multisite-site-category/raw/master/img/screenshot-2.png)

**Add site : front end**
**Manage categories**

![Site add front end](https://github.com/brasofilo/multisite-site-category/raw/master/img/screenshot-3.png)

Expand Down
Binary file modified img/screenshot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/screenshot-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/screenshot-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
151 changes: 151 additions & 0 deletions inc/class-sites-categories-columns.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?php
/**
* Sites columns and sorting
*
* Also, filters Blog_Details so WP thinks all sites are mature==0
*
* @package Multisite Site Category
* @author Rodolfo Buaiz
* @since 2013.09.26
*/

class B5F_Sites_Categories_Columns
{
public function __construct()
{
add_action(
'manage_blogs_custom_column', array( $this, 'add_columns' ), 10, 2
);
add_action(
'manage_sites_custom_column', array( $this, 'add_columns' ), 10, 2
);
add_filter(
'wpmu_blogs_columns', array( $this, 'print_columns' )
);
add_action(
'admin_head-sites.php', array( $this, 'add_style' )
);
add_filter( "manage_sites-network_sortable_columns", array( $this, 'sortable' ) );
# SORT BY MATURE
global $pagenow;
if(
is_super_admin()
&& 'sites.php' == $pagenow
&& isset( $_GET['orderby'] ) && 'site-category' == $_GET['orderby']
)
add_filter( 'query', array( $this, 'filter_site_query' ) );
# WP, ALL MATURES ARE OK
elseif( 'sites.php' != $pagenow )
add_filter( 'blog_details', array( $this, 'hack_mature_queries' ) );

}

/**
* Add custom columns (ID and Site Category) in Sites listing
*
*/
public function add_columns( $column_name, $blog_id )
{
if( 'mature' === $column_name )
{
if( apply_filters(
'msc_show_mature_column',
B5F_Multisite_Categories::$show_mature_column )
)
{
echo get_blog_status( $blog_id,'mature' );
}
}
elseif( 'column-site-cat' === $column_name )
{
$cat_name = get_blog_option( $blog_id, 'site_category' );
$uncategorized = '<span style="opacity:.5">Uncategorized</span>';
echo ( empty( $cat_name ) ) ? $uncategorized : $cat_name;
}
return $column_name;
}


/**
* Add Columns
*
*/
public function print_columns( $cols )
{
if( apply_filters(
'msc_show_mature_column',
B5F_Multisite_Categories::$show_mature_column )
)
$cols['mature'] = __( 'Mature' );
$cols['column-site-cat'] = __( 'Category' );
return $cols;
}


/**
* Mark categories as sortable
*
* @param array $columns
* @return array
*/
public function sortable( $columns )
{
$columns['column-site-cat'] = 'site-category';
return $columns;

}


/**
* Add column widths
*
*/
public function add_style()
{
echo '<style>#mature { width:7%; } #column-site-cat { width:10%; }</style>';
}


/**
* Order sites by mature column
*
* @global object $wpdb
* @param string $query
* @return strin
*/
public function filter_site_query( $query )
{
global $wpdb;
$search_query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '1' LIMIT 0, 20";

# SANITIZE
if( isset( $_GET['order'] ) )
{
$order = ( 'asc' == $_GET['order'] ) ? 'ASC' : 'DESC';
}
else
$order = 'DESC';

# MODIFY
if( strpos( $query, $search_query ) !== FALSE )
{
$query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '1' ORDER BY mature $order LIMIT 0, 20";
}
return $query;
}


/**
* Tell WP all Matures are equal to 0
* Except in the screen sites.php
*
* @param object $details
* @return object
*/
public function hack_mature_queries( $details )
{
$details->mature = 0;
return $details;
}

}
Loading

0 comments on commit e43c074

Please sign in to comment.