Version Description
- Support the Sites.
- Improved Activation.
Download this release
Release Info
Developer | hijiri |
Plugin | Intuitive Custom Post Order |
Version | 3.1.0 |
Comparing to | |
See all releases |
Code changes from version 3.0.8 to 3.1.0
- README.md +1 -1
- admin/settings-network.php +38 -0
- intuitive-custom-post-order.php +324 -12
- js/hicpo.js +33 -0
- readme.txt +17 -10
README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
|
5 |
## Description
|
6 |
|
7 |
-
Intuitively, order items( Posts, Pages,
|
8 |
|
9 |
Select sortable items from 'Intuitive CPT' menu of Setting menu in WordPress.
|
10 |
|
4 |
|
5 |
## Description
|
6 |
|
7 |
+
Intuitively, order items( Posts, Pages, ,Custom Post Types, Custom Taxonomies, Sites ) using a drag and drop sortable JavaScript.
|
8 |
|
9 |
Select sortable items from 'Intuitive CPT' menu of Setting menu in WordPress.
|
10 |
|
admin/settings-network.php
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div class="wrap">
|
2 |
+
|
3 |
+
<?php screen_icon( 'plugins' ); ?>
|
4 |
+
|
5 |
+
<h2><?php _e( 'Intuitive Custom Post Order Network Settings', 'intuitive-custom-post-order' ); ?></h2>
|
6 |
+
|
7 |
+
<?php if ( isset($_GET['msg'] )) : ?>
|
8 |
+
<div id="message" class="updated below-h2">
|
9 |
+
<?php if ( $_GET['msg'] == 'update' ) : ?>
|
10 |
+
<p><?php _e( 'Settings saved.' ); ?></p>
|
11 |
+
<?php endif; ?>
|
12 |
+
</div>
|
13 |
+
<?php endif; ?>
|
14 |
+
|
15 |
+
<form method="post">
|
16 |
+
|
17 |
+
<?php if ( function_exists( 'wp_nonce_field' ) ) wp_nonce_field( 'nonce_hicpo' ); ?>
|
18 |
+
|
19 |
+
<table class="form-table">
|
20 |
+
<tbody>
|
21 |
+
<tr valign="top">
|
22 |
+
<th scope="row">
|
23 |
+
<?php _e( 'Sortable Objects', 'intuitive-custom-post-order' ) ?>
|
24 |
+
</th>
|
25 |
+
<td>
|
26 |
+
<label><input type="checkbox" name="sites" value="1" <?php if ( get_option( 'hicpo_network_sites' ) ) { echo 'checked="checked"'; } ?>> <?php _e( 'Sites', 'intuitive-custom-post-order' ) ?></label>
|
27 |
+
</td>
|
28 |
+
</tr>
|
29 |
+
</tbody>
|
30 |
+
</table>
|
31 |
+
|
32 |
+
<p class="submit">
|
33 |
+
<input type="submit" class="button-primary" name="hicpo_network_submit" value="<?php _e( 'Update', 'cptg' ); ?>">
|
34 |
+
</p>
|
35 |
+
|
36 |
+
</form>
|
37 |
+
|
38 |
+
</div>
|
intuitive-custom-post-order.php
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
/*
|
3 |
* Plugin Name: Intuitive Custom Post Order
|
4 |
* Plugin URI: http://hijiriworld.com/web/plugins/intuitive-custom-post-order/
|
5 |
-
* Description: Intuitively, Order Items
|
6 |
-
* Version: 3.0
|
7 |
* Author: hijiri
|
8 |
* Author URI: http://hijiriworld.com/web/
|
9 |
* Text Domain: intuitive-custom-post-order
|
@@ -18,6 +18,7 @@
|
|
18 |
|
19 |
define( 'HICPO_URL', plugins_url( '', __FILE__ ) );
|
20 |
define( 'HICPO_DIR', plugin_dir_path( __FILE__ ) );
|
|
|
21 |
|
22 |
/**
|
23 |
* Uninstall hook
|
@@ -27,19 +28,25 @@ register_uninstall_hook( __FILE__, 'hicpo_uninstall' );
|
|
27 |
function hicpo_uninstall()
|
28 |
{
|
29 |
global $wpdb;
|
30 |
-
if ( function_exists( 'is_multisite' ) && is_multisite() )
|
|
|
31 |
$curr_blog = $wpdb->blogid;
|
32 |
$blogids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
|
33 |
foreach( $blogids as $blog_id ) {
|
34 |
switch_to_blog( $blog_id );
|
35 |
-
|
36 |
}
|
37 |
switch_to_blog( $curr_blog );
|
|
|
38 |
} else {
|
39 |
-
|
40 |
}
|
|
|
|
|
41 |
}
|
42 |
-
|
|
|
|
|
43 |
{
|
44 |
global $wpdb;
|
45 |
$result = $wpdb->query( "DESCRIBE $wpdb->terms `term_order`" );
|
@@ -47,7 +54,16 @@ function hicpo_uninstall_db()
|
|
47 |
$query = "ALTER TABLE $wpdb->terms DROP `term_order`";
|
48 |
$result = $wpdb->query( $query );
|
49 |
}
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
}
|
52 |
|
53 |
/**
|
@@ -56,17 +72,27 @@ function hicpo_uninstall_db()
|
|
56 |
|
57 |
$hicpo = new Hicpo();
|
58 |
|
59 |
-
class Hicpo
|
60 |
{
|
|
|
|
|
|
|
61 |
function __construct()
|
62 |
{
|
63 |
-
|
|
|
|
|
64 |
|
|
|
65 |
add_action( 'plugins_loaded', array( $this, 'my_plugin_load_plugin_textdomain' ) );
|
66 |
|
|
|
67 |
add_action( 'admin_menu', array( $this, 'admin_menu') );
|
68 |
|
69 |
-
|
|
|
|
|
|
|
70 |
add_action( 'admin_init', array( $this, 'update_options') );
|
71 |
add_action( 'admin_init', array( $this, 'load_script_css' ) );
|
72 |
|
@@ -86,23 +112,67 @@ class Hicpo
|
|
86 |
add_filter( 'get_terms_orderby', array( $this, 'hicpo_get_terms_orderby' ), 10, 3 );
|
87 |
add_filter( 'wp_get_object_terms', array( $this, 'hicpo_get_object_terms' ), 10, 3 );
|
88 |
add_filter( 'get_terms', array( $this, 'hicpo_get_object_terms' ), 10, 3 );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
}
|
90 |
|
|
|
|
|
|
|
91 |
function hicpo_activation()
|
92 |
{
|
93 |
global $wpdb;
|
|
|
|
|
94 |
$result = $wpdb->query( "DESCRIBE $wpdb->terms `term_order`" );
|
95 |
if ( !$result ) {
|
96 |
$query = "ALTER TABLE $wpdb->terms ADD `term_order` INT( 4 ) NULL DEFAULT '0'";
|
97 |
$result = $wpdb->query( $query );
|
98 |
}
|
99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
}
|
101 |
|
102 |
function my_plugin_load_plugin_textdomain()
|
103 |
{
|
104 |
load_plugin_textdomain( 'intuitive-custom-post-order', false, basename( dirname( __FILE__ ) ).'/languages/' );
|
105 |
}
|
|
|
106 |
function admin_menu()
|
107 |
{
|
108 |
add_options_page( __( 'Intuitive CPO', 'intuitive-custom-post-order' ), __( 'Intuitive CPO', 'intuitive-custom-post-order' ), 'manage_options', 'hicpo-settings', array( $this,'admin_page' ) );
|
@@ -112,11 +182,34 @@ class Hicpo
|
|
112 |
{
|
113 |
require HICPO_DIR.'admin/settings.php';
|
114 |
}
|
115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
function _check_load_script_css()
|
117 |
{
|
|
|
|
|
118 |
$active = false;
|
119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
$objects = $this->get_hicpo_options_objects();
|
121 |
$tags = $this->get_hicpo_options_tags();
|
122 |
|
@@ -205,6 +298,47 @@ class Hicpo
|
|
205 |
}
|
206 |
}
|
207 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
function update_menu_order()
|
209 |
{
|
210 |
global $wpdb;
|
@@ -271,6 +405,28 @@ class Hicpo
|
|
271 |
}
|
272 |
}
|
273 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
274 |
/**
|
275 |
* はじめて有効化されたオブジェクトは、ディフォルトの order に従って menu_order セットする
|
276 |
*
|
@@ -354,6 +510,39 @@ class Hicpo
|
|
354 |
wp_redirect( 'admin.php?page=hicpo-settings&msg=update' );
|
355 |
}
|
356 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
357 |
function hicpo_previous_post_where( $where )
|
358 |
{
|
359 |
global $post;
|
@@ -513,6 +702,129 @@ class Hicpo
|
|
513 |
return ( $a->term_order < $b->term_order ) ? -1 : 1;
|
514 |
}
|
515 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
516 |
function get_hicpo_options_objects()
|
517 |
{
|
518 |
$hicpo_options = get_option( 'hicpo_options' ) ? get_option( 'hicpo_options' ) : array();
|
2 |
/*
|
3 |
* Plugin Name: Intuitive Custom Post Order
|
4 |
* Plugin URI: http://hijiriworld.com/web/plugins/intuitive-custom-post-order/
|
5 |
+
* Description: Intuitively, Order Items( Posts, Pages, ,Custom Post Types, Custom Taxonomies, Sites ) using a Drag and Drop Sortable JavaScript.
|
6 |
+
* Version: 3.1.0
|
7 |
* Author: hijiri
|
8 |
* Author URI: http://hijiriworld.com/web/
|
9 |
* Text Domain: intuitive-custom-post-order
|
18 |
|
19 |
define( 'HICPO_URL', plugins_url( '', __FILE__ ) );
|
20 |
define( 'HICPO_DIR', plugin_dir_path( __FILE__ ) );
|
21 |
+
define( 'HICPO_VER', '3.1.0' );
|
22 |
|
23 |
/**
|
24 |
* Uninstall hook
|
28 |
function hicpo_uninstall()
|
29 |
{
|
30 |
global $wpdb;
|
31 |
+
if ( function_exists( 'is_multisite' ) && is_multisite() )
|
32 |
+
{
|
33 |
$curr_blog = $wpdb->blogid;
|
34 |
$blogids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
|
35 |
foreach( $blogids as $blog_id ) {
|
36 |
switch_to_blog( $blog_id );
|
37 |
+
hicpo_uninstall_db_terms();
|
38 |
}
|
39 |
switch_to_blog( $curr_blog );
|
40 |
+
hicpo_uninstall_db_blogs();
|
41 |
} else {
|
42 |
+
hicpo_uninstall_db_terms();
|
43 |
}
|
44 |
+
delete_option( 'hicpo_activation' ); // old version before than 3.1.0
|
45 |
+
delete_option( 'hicpo_ver' );
|
46 |
}
|
47 |
+
|
48 |
+
// drop term_order COLUMN to $wpdb->terms TABLE
|
49 |
+
function hicpo_uninstall_db_terms()
|
50 |
{
|
51 |
global $wpdb;
|
52 |
$result = $wpdb->query( "DESCRIBE $wpdb->terms `term_order`" );
|
54 |
$query = "ALTER TABLE $wpdb->terms DROP `term_order`";
|
55 |
$result = $wpdb->query( $query );
|
56 |
}
|
57 |
+
}
|
58 |
+
// drop menu_order COLUMN to $wpdb->blogs TABLE
|
59 |
+
function hicpo_uninstall_db_blogs()
|
60 |
+
{
|
61 |
+
global $wpdb;
|
62 |
+
$result = $wpdb->query( "DESCRIBE $wpdb->blogs `menu_order`" );
|
63 |
+
if ( $result ) {
|
64 |
+
$query = "ALTER TABLE $wpdb->blogs DROP `menu_order`";
|
65 |
+
$result = $wpdb->query( $query );
|
66 |
+
}
|
67 |
}
|
68 |
|
69 |
/**
|
72 |
|
73 |
$hicpo = new Hicpo();
|
74 |
|
75 |
+
class Hicpo
|
76 |
{
|
77 |
+
/**
|
78 |
+
* Construct
|
79 |
+
*/
|
80 |
function __construct()
|
81 |
{
|
82 |
+
// activation
|
83 |
+
$hicpo_ver = get_option( 'hicpo_ver' );
|
84 |
+
if ( version_compare( $hicpo_ver, HICPO_VER ) < 0 ) $this->hicpo_activation();
|
85 |
|
86 |
+
// textdomain
|
87 |
add_action( 'plugins_loaded', array( $this, 'my_plugin_load_plugin_textdomain' ) );
|
88 |
|
89 |
+
// add menu
|
90 |
add_action( 'admin_menu', array( $this, 'admin_menu') );
|
91 |
|
92 |
+
// admin init
|
93 |
+
if ( empty($_GET) ) {
|
94 |
+
add_action( 'admin_init', array( $this, 'refresh' ) );
|
95 |
+
}
|
96 |
add_action( 'admin_init', array( $this, 'update_options') );
|
97 |
add_action( 'admin_init', array( $this, 'load_script_css' ) );
|
98 |
|
112 |
add_filter( 'get_terms_orderby', array( $this, 'hicpo_get_terms_orderby' ), 10, 3 );
|
113 |
add_filter( 'wp_get_object_terms', array( $this, 'hicpo_get_object_terms' ), 10, 3 );
|
114 |
add_filter( 'get_terms', array( $this, 'hicpo_get_object_terms' ), 10, 3 );
|
115 |
+
|
116 |
+
// reorder sites
|
117 |
+
if ( function_exists( 'is_multisite' ) && is_multisite() )
|
118 |
+
{
|
119 |
+
add_action( 'network_admin_menu', array( $this, 'network_admin_menu' ) );
|
120 |
+
add_action( 'admin_init', array( $this, 'update_network_options' ) );
|
121 |
+
add_action( 'wp_ajax_update-menu-order-sites', array( $this, 'update_menu_order_sites' ) );
|
122 |
+
|
123 |
+
// networkadmin サイト削除時はサイト並び替え除外
|
124 |
+
if( empty( $_SERVER['QUERY_STRING'] ) ||
|
125 |
+
(
|
126 |
+
!empty( $_SERVER['QUERY_STRING'] ) &&
|
127 |
+
'action=deleteblog' !== $_SERVER['QUERY_STRING'] && // delete
|
128 |
+
'action=allblogs' !== $_SERVER['QUERY_STRING'] // delete all
|
129 |
+
)
|
130 |
+
) {
|
131 |
+
|
132 |
+
// call from 'get_sites'
|
133 |
+
add_filter( 'sites_clauses', array( $this, 'hicpo_sites_clauses' ), 10, 1 );
|
134 |
+
|
135 |
+
add_action( 'admin_init', array( $this, 'refresh_network' ) );
|
136 |
+
|
137 |
+
// adminbar sites reorder
|
138 |
+
add_filter( 'get_blogs_of_user', array( $this, 'hicpo_get_blogs_of_user' ), 10, 3 );
|
139 |
+
}
|
140 |
+
|
141 |
+
// before wp v4.6.0 * wp_get_sites
|
142 |
+
add_action( 'init', array( $this, 'refresh_front_network' ) );
|
143 |
+
}
|
144 |
}
|
145 |
|
146 |
+
/**
|
147 |
+
* Method
|
148 |
+
*/
|
149 |
function hicpo_activation()
|
150 |
{
|
151 |
global $wpdb;
|
152 |
+
|
153 |
+
// add term_order COLUMN to $wpdb->terms TABLE
|
154 |
$result = $wpdb->query( "DESCRIBE $wpdb->terms `term_order`" );
|
155 |
if ( !$result ) {
|
156 |
$query = "ALTER TABLE $wpdb->terms ADD `term_order` INT( 4 ) NULL DEFAULT '0'";
|
157 |
$result = $wpdb->query( $query );
|
158 |
}
|
159 |
+
|
160 |
+
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
|
161 |
+
// add menu_order COLUMN to $wpdb->blogs TABLE
|
162 |
+
$result = $wpdb->query( "DESCRIBE $wpdb->blogs `menu_order`" );
|
163 |
+
if ( !$result ) {
|
164 |
+
$query = "ALTER TABLE $wpdb->blogs ADD `menu_order` INT( 4 ) NULL DEFAULT '0'";
|
165 |
+
$result = $wpdb->query( $query );
|
166 |
+
}
|
167 |
+
}
|
168 |
+
update_option( 'hicpo_ver', HICPO_VER );
|
169 |
}
|
170 |
|
171 |
function my_plugin_load_plugin_textdomain()
|
172 |
{
|
173 |
load_plugin_textdomain( 'intuitive-custom-post-order', false, basename( dirname( __FILE__ ) ).'/languages/' );
|
174 |
}
|
175 |
+
|
176 |
function admin_menu()
|
177 |
{
|
178 |
add_options_page( __( 'Intuitive CPO', 'intuitive-custom-post-order' ), __( 'Intuitive CPO', 'intuitive-custom-post-order' ), 'manage_options', 'hicpo-settings', array( $this,'admin_page' ) );
|
182 |
{
|
183 |
require HICPO_DIR.'admin/settings.php';
|
184 |
}
|
185 |
+
|
186 |
+
function network_admin_menu()
|
187 |
+
{
|
188 |
+
add_submenu_page( 'settings.php', __( 'Intuitive CPO', 'hicpo' ), __( 'Intuitive CPO', 'hicpo' ), 'manage_options', 'hicpo-network-settings', array( $this, 'network_admin_page' ) );
|
189 |
+
}
|
190 |
+
|
191 |
+
function network_admin_page()
|
192 |
+
{
|
193 |
+
require HICPO_DIR.'admin/settings-network.php';
|
194 |
+
}
|
195 |
+
|
196 |
function _check_load_script_css()
|
197 |
{
|
198 |
+
global $pagenow, $typenow;
|
199 |
+
|
200 |
$active = false;
|
201 |
|
202 |
+
// multisite > sites
|
203 |
+
if (
|
204 |
+
function_exists( 'is_multisite' )
|
205 |
+
&& is_multisite()
|
206 |
+
&& $pagenow == 'sites.php'
|
207 |
+
&& get_option( 'hicpo_network_sites' )
|
208 |
+
)
|
209 |
+
{
|
210 |
+
return true;
|
211 |
+
}
|
212 |
+
|
213 |
$objects = $this->get_hicpo_options_objects();
|
214 |
$tags = $this->get_hicpo_options_tags();
|
215 |
|
298 |
}
|
299 |
}
|
300 |
|
301 |
+
function refresh_network()
|
302 |
+
{
|
303 |
+
global $pagenow;
|
304 |
+
if( 'sites.php' === $pagenow && !isset( $_GET['orderby'] ) ) {
|
305 |
+
add_filter( 'query', array( $this, 'refresh_network_2' ) );
|
306 |
+
}
|
307 |
+
}
|
308 |
+
|
309 |
+
function refresh_network_2( $query )
|
310 |
+
{
|
311 |
+
global $wpdb, $wp_version, $blog_id;
|
312 |
+
|
313 |
+
/**
|
314 |
+
* after wp4.7.0
|
315 |
+
* ブログのステータスが公開以外の際、$blog_id=1以外のoptionを取得しようとする処理のSQLを除外する
|
316 |
+
* eq.) SELECT option_name, option_value FROM wp_11_options WHERE autoload = 'yes'
|
317 |
+
*/
|
318 |
+
|
319 |
+
// $wpdb->get_varやswitch_to_blog(1)からのget_optionでは処理が止まるため、$blog_idで判別
|
320 |
+
if ( version_compare( $wp_version, '4.7.0' ) >= 0 ) {
|
321 |
+
if( 1 !== $blog_id ) {
|
322 |
+
return $query;
|
323 |
+
}
|
324 |
+
}
|
325 |
+
|
326 |
+
$hicpo_network_sites = get_option( 'hicpo_network_sites' );
|
327 |
+
if( !$hicpo_network_sites ) return $query;
|
328 |
+
|
329 |
+
|
330 |
+
if( false !== strpos( $query, "SELECT * FROM $wpdb->blogs WHERE site_id = '1'" ) ||
|
331 |
+
false !== strpos( $query, "SQL_CALC_FOUND_ROWS blog_id FROM $wpdb->blogs WHERE site_id = 1" )
|
332 |
+
) {
|
333 |
+
if ( false !== strpos( $query, " LIMIT " ) ) {
|
334 |
+
$query = preg_replace( '/^(.*) LIMIT(.*)$/', '$1 ORDER BY menu_order ASC LIMIT $2', $query );
|
335 |
+
} else {
|
336 |
+
$query .= " ORDER BY menu_order ASC";
|
337 |
+
}
|
338 |
+
}
|
339 |
+
return $query;
|
340 |
+
}
|
341 |
+
|
342 |
function update_menu_order()
|
343 |
{
|
344 |
global $wpdb;
|
405 |
}
|
406 |
}
|
407 |
|
408 |
+
function update_menu_order_sites()
|
409 |
+
{
|
410 |
+
global $wpdb;
|
411 |
+
|
412 |
+
parse_str( $_POST['order'], $data );
|
413 |
+
|
414 |
+
if ( !is_array( $data ) ) return false;
|
415 |
+
|
416 |
+
$id_arr = array();
|
417 |
+
foreach( $data as $key => $values ) {
|
418 |
+
foreach( $values as $position => $id ) {
|
419 |
+
$id_arr[] = $id;
|
420 |
+
}
|
421 |
+
}
|
422 |
+
|
423 |
+
foreach( $data as $key => $values ) {
|
424 |
+
foreach( $values as $position => $id ) {
|
425 |
+
$wpdb->update( $wpdb->blogs, array( 'menu_order' => $position+1 ), array( 'blog_id' => intval( $id ) ) );
|
426 |
+
}
|
427 |
+
}
|
428 |
+
}
|
429 |
+
|
430 |
/**
|
431 |
* はじめて有効化されたオブジェクトは、ディフォルトの order に従って menu_order セットする
|
432 |
*
|
510 |
wp_redirect( 'admin.php?page=hicpo-settings&msg=update' );
|
511 |
}
|
512 |
|
513 |
+
function update_network_options()
|
514 |
+
{
|
515 |
+
global $wpdb;
|
516 |
+
|
517 |
+
if ( !isset( $_POST['hicpo_network_submit' ] ) ) return false;
|
518 |
+
|
519 |
+
check_admin_referer( 'nonce_hicpo' );
|
520 |
+
|
521 |
+
$hicpo_network_sites = isset( $_POST['sites'] ) ? $_POST['sites'] : 0;
|
522 |
+
|
523 |
+
update_option( 'hicpo_network_sites', $hicpo_network_sites );
|
524 |
+
|
525 |
+
// Initial
|
526 |
+
$result = $wpdb->get_results( "
|
527 |
+
SELECT count(*) as cnt, max(menu_order) as max, min(menu_order) as min
|
528 |
+
FROM $wpdb->blogs
|
529 |
+
" );
|
530 |
+
if ( $result[0]->cnt == 0 || $result[0]->cnt == $result[0]->max ) {
|
531 |
+
|
532 |
+
} else {
|
533 |
+
$results = $wpdb->get_results( "
|
534 |
+
SELECT blog_id
|
535 |
+
FROM $wpdb->blogs
|
536 |
+
ORDER BY blog_id ASC
|
537 |
+
" );
|
538 |
+
foreach( $results as $key => $result ) {
|
539 |
+
$wpdb->update( $wpdb->blogs, array( 'menu_order' => $key+1 ), array( 'blog_id' => $result->blog_id ) );
|
540 |
+
}
|
541 |
+
}
|
542 |
+
|
543 |
+
wp_redirect( 'settings.php?page=hicpo-network-settings&msg=update' );
|
544 |
+
}
|
545 |
+
|
546 |
function hicpo_previous_post_where( $where )
|
547 |
{
|
548 |
global $post;
|
702 |
return ( $a->term_order < $b->term_order ) ? -1 : 1;
|
703 |
}
|
704 |
|
705 |
+
function hicpo_sites_clauses( $pieces = array() )
|
706 |
+
{
|
707 |
+
global $blog_id;
|
708 |
+
|
709 |
+
if ( is_admin() ) return $pieces;
|
710 |
+
if ( 1 != $blog_id ) {
|
711 |
+
$current = $blog_id;
|
712 |
+
switch_to_blog(1);
|
713 |
+
$hicpo_network_sites = get_option( 'hicpo_network_sites' );
|
714 |
+
switch_to_blog($current);
|
715 |
+
if ( !$hicpo_network_sites ) return $pieces;
|
716 |
+
} else {
|
717 |
+
if ( !get_option( 'hicpo_network_sites' ) ) return $pieces;
|
718 |
+
}
|
719 |
+
|
720 |
+
global $wp_version;
|
721 |
+
if ( version_compare( $wp_version, '4.6.0' ) >= 0 ) {
|
722 |
+
// サイト並び替え指定がデフォルトの場合のみ並び替え
|
723 |
+
if( 'blog_id ASC' === $pieces['orderby'] ) {
|
724 |
+
$pieces['orderby'] = 'menu_order ASC';
|
725 |
+
}
|
726 |
+
}
|
727 |
+
return $pieces;
|
728 |
+
}
|
729 |
+
|
730 |
+
function hicpo_get_blogs_of_user( $blogs )
|
731 |
+
{
|
732 |
+
global $blog_id;
|
733 |
+
if ( 1 != $blog_id ) {
|
734 |
+
$current = $blog_id;
|
735 |
+
switch_to_blog(1);
|
736 |
+
$hicpo_network_sites = get_option( 'hicpo_network_sites' );
|
737 |
+
switch_to_blog($current);
|
738 |
+
if ( !$hicpo_network_sites ) return $blogs;
|
739 |
+
} else {
|
740 |
+
if ( !get_option( 'hicpo_network_sites' ) ) return $blogs;
|
741 |
+
}
|
742 |
+
global $wpdb, $wp_version;
|
743 |
+
|
744 |
+
if ( version_compare( $wp_version, '4.6.0' ) >= 0 ) {
|
745 |
+
$sites = get_sites( array() );
|
746 |
+
$sort_keys = array();
|
747 |
+
foreach( $sites as $k => $v ) {
|
748 |
+
$sort_keys[] = $v->menu_order;
|
749 |
+
}
|
750 |
+
array_multisort( $sort_keys, SORT_ASC, $sites );
|
751 |
+
|
752 |
+
$blog_list = array();
|
753 |
+
foreach( $blogs as $k => $v ) {
|
754 |
+
$blog_list[$v->userblog_id] = $v;
|
755 |
+
}
|
756 |
+
|
757 |
+
$new = array();
|
758 |
+
foreach( $sites as $k => $v ) {
|
759 |
+
if ( isset($v->blog_id) &&
|
760 |
+
isset($blog_list[$v->blog_id]) &&
|
761 |
+
is_object( $blog_list[$v->blog_id] ) ) {
|
762 |
+
$new[] = $blog_list[$v->blog_id];
|
763 |
+
}
|
764 |
+
}
|
765 |
+
} else {
|
766 |
+
$sites = wp_get_sites( array( 'limit' => 9999 ) );
|
767 |
+
$sort_keys = array();
|
768 |
+
foreach( $sites as $k => $v ) {
|
769 |
+
$sort_keys[] = $v['menu_order'];
|
770 |
+
}
|
771 |
+
array_multisort( $sort_keys, SORT_ASC, $sites );
|
772 |
+
|
773 |
+
$blog_list = array();
|
774 |
+
foreach( $blogs as $k => $v ) {
|
775 |
+
$blog_list[$v->userblog_id] = $v;
|
776 |
+
}
|
777 |
+
|
778 |
+
$new = array();
|
779 |
+
foreach( $sites as $k => $v ) {
|
780 |
+
if ( isset($v['blog_id']) &&
|
781 |
+
isset($blog_list[$v['blog_id']]) &&
|
782 |
+
is_object( $blog_list[$v['blog_id']] ) ) {
|
783 |
+
$new[] = $blog_list[$v['blog_id']];
|
784 |
+
}
|
785 |
+
}
|
786 |
+
}
|
787 |
+
return $new;
|
788 |
+
}
|
789 |
+
|
790 |
+
/* before wp v4.6.0 */
|
791 |
+
function refresh_front_network()
|
792 |
+
{
|
793 |
+
global $wp_version;
|
794 |
+
if ( version_compare( $wp_version, '4.6.0' ) < 0 ) {
|
795 |
+
global $blog_id;
|
796 |
+
if ( 1 != $blog_id ) {
|
797 |
+
$current = $blog_id;
|
798 |
+
switch_to_blog(1);
|
799 |
+
$hicpo_network_sites = get_option( 'hicpo_network_sites' );
|
800 |
+
switch_to_blog($current);
|
801 |
+
if ( !$hicpo_network_sites ) return;
|
802 |
+
} else {
|
803 |
+
if ( !get_option( 'hicpo_network_sites' ) ) return;
|
804 |
+
}
|
805 |
+
add_filter( 'query', array( $this, 'refresh_front_network_2' ) );
|
806 |
+
}
|
807 |
+
}
|
808 |
+
function refresh_front_network_2( $query )
|
809 |
+
{
|
810 |
+
global $wpdb;
|
811 |
+
if ( false !== strpos( $query, "SELECT blog_id FROM $wpdb->blogs ORDER BY blog_id ASC" ) ) {
|
812 |
+
$query = str_replace( 'ORDER BY blog_id ASC', '', $query );
|
813 |
+
if ( false !== strpos( $query, " LIMIT " ) ) {
|
814 |
+
$query = preg_replace( '/^(.*) LIMIT(.*)$/', '$1 ORDER BY menu_order ASC LIMIT $2', $query );
|
815 |
+
} else {
|
816 |
+
$query .= " ORDER BY menu_order ASC";
|
817 |
+
}
|
818 |
+
} elseif ( false !== strpos( $query, "SELECT * FROM $wpdb->blogs WHERE 1=1 AND site_id IN (1)" ) ) {
|
819 |
+
if ( false !== strpos( $query, " LIMIT " ) ) {
|
820 |
+
$query = preg_replace( '/^(.*) LIMIT(.*)$/', '$1 ORDER BY menu_order ASC LIMIT $2', $query );
|
821 |
+
} else {
|
822 |
+
$query .= " ORDER BY menu_order ASC";
|
823 |
+
}
|
824 |
+
}
|
825 |
+
return $query;
|
826 |
+
}
|
827 |
+
|
828 |
function get_hicpo_options_objects()
|
829 |
{
|
830 |
$hicpo_options = get_option( 'hicpo_options' ) ? get_option( 'hicpo_options' ) : array();
|
js/hicpo.js
CHANGED
@@ -30,6 +30,39 @@
|
|
30 |
});
|
31 |
//$("#the-list").disableSelection();
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
var fixHelper = function(e, ui) {
|
34 |
ui.children().children().each(function() {
|
35 |
$(this).width($(this).width());
|
30 |
});
|
31 |
//$("#the-list").disableSelection();
|
32 |
|
33 |
+
// sites
|
34 |
+
|
35 |
+
// add number
|
36 |
+
var site_table_tr = $('table.sites #the-list tr');
|
37 |
+
site_table_tr.each( function() {
|
38 |
+
var ret=null;
|
39 |
+
var url = $(this).find('td.blogname a').attr('href');
|
40 |
+
parameters = url.split('?');
|
41 |
+
if( parameters.length > 1 ) {
|
42 |
+
var params = parameters[1].split('&');
|
43 |
+
var paramsArray = [];
|
44 |
+
for( var i=0; i<params.length; i++) {
|
45 |
+
var neet = params[i].split('=');
|
46 |
+
paramsArray.push(neet[0]);
|
47 |
+
paramsArray[neet[0]] = neet[1];
|
48 |
+
}
|
49 |
+
ret = paramsArray['id'];
|
50 |
+
}
|
51 |
+
$(this).attr('id','site-'+ret);
|
52 |
+
} );
|
53 |
+
|
54 |
+
$('table.sites #the-list').sortable({
|
55 |
+
'items': 'tr',
|
56 |
+
'axis': 'y',
|
57 |
+
'helper': fixHelper,
|
58 |
+
'update' : function(e, ui) {
|
59 |
+
$.post( ajaxurl, {
|
60 |
+
action: 'update-menu-order-sites',
|
61 |
+
order: $('#the-list').sortable('serialize'),
|
62 |
+
});
|
63 |
+
}
|
64 |
+
});
|
65 |
+
|
66 |
var fixHelper = function(e, ui) {
|
67 |
ui.children().children().each(function() {
|
68 |
$(this).width($(this).width());
|
readme.txt
CHANGED
@@ -4,15 +4,15 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
|
|
4 |
Tags: post order, posts order, order post, order posts, custom post type order, custom taxonomy order
|
5 |
Requires at least: 3.5.0
|
6 |
Tested up to: 4.7.3
|
7 |
-
Stable tag: 3.0
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
11 |
-
Intuitively, order items( Posts, Pages,
|
12 |
|
13 |
== Description ==
|
14 |
|
15 |
-
Intuitively, order items( Posts, Pages,
|
16 |
|
17 |
Select sortable items from 'Intuitive CPT' menu of Setting menu in WordPress.
|
18 |
|
@@ -29,9 +29,11 @@ This Plugin published on <a href="https://github.com/hijiriworld/intuitive-custo
|
|
29 |
|
30 |
== Screenshots ==
|
31 |
|
32 |
-
1.
|
33 |
-
2. Reorder
|
34 |
-
3.
|
|
|
|
|
35 |
|
36 |
== Frequently Asked Questions ==
|
37 |
|
@@ -41,7 +43,7 @@ This Plugin published on <a href="https://github.com/hijiriworld/intuitive-custo
|
|
41 |
|
42 |
By using the 'WP_Query', you can re-override the parameters.
|
43 |
|
44 |
-
|
45 |
|
46 |
`
|
47 |
<?php $query = new WP_Query( array(
|
@@ -50,7 +52,7 @@ By using the 'WP_Query', you can re-override the parameters.
|
|
50 |
) ) ?>
|
51 |
`
|
52 |
|
53 |
-
|
54 |
|
55 |
`
|
56 |
<?php $query = get_posts( array(
|
@@ -71,7 +73,7 @@ ATTENTION: Only if you use 'get_posts()' to re-overwrite to the default order( o
|
|
71 |
|
72 |
By using the 'pre_get_posts' action hook or 'query_posts()', you can re-override the parameters.
|
73 |
|
74 |
-
|
75 |
|
76 |
`
|
77 |
function my_filter( $query )
|
@@ -86,7 +88,7 @@ function my_filter( $query )
|
|
86 |
add_action( 'pre_get_posts', 'my_filter' );
|
87 |
`
|
88 |
|
89 |
-
|
90 |
|
91 |
`
|
92 |
<?php query_posts( array(
|
@@ -99,6 +101,11 @@ Go to "screen options" and change "Number of items per page:".
|
|
99 |
|
100 |
== Changelog ==
|
101 |
|
|
|
|
|
|
|
|
|
|
|
102 |
= 3.0.8 =
|
103 |
|
104 |
* Even for 'get_posts()', Your custom Query which uses the 'order' or 'orderby' parameters is preferred.
|
4 |
Tags: post order, posts order, order post, order posts, custom post type order, custom taxonomy order
|
5 |
Requires at least: 3.5.0
|
6 |
Tested up to: 4.7.3
|
7 |
+
Stable tag: 3.1.0
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
11 |
+
Intuitively, order items( Posts, Pages, ,Custom Post Types, Custom Taxonomies, Sites ) using a drag and drop sortable JavaScript.
|
12 |
|
13 |
== Description ==
|
14 |
|
15 |
+
Intuitively, order items( Posts, Pages, ,Custom Post Types, Custom Taxonomies, Sites ) using a drag and drop sortable JavaScript.
|
16 |
|
17 |
Select sortable items from 'Intuitive CPT' menu of Setting menu in WordPress.
|
18 |
|
29 |
|
30 |
== Screenshots ==
|
31 |
|
32 |
+
1. Settings
|
33 |
+
2. Reorder Posts
|
34 |
+
3. Reorder Taxonomies
|
35 |
+
4. ( for Multisite ) Network Settings
|
36 |
+
5. ( for Multisite ) Reorder Sites
|
37 |
|
38 |
== Frequently Asked Questions ==
|
39 |
|
43 |
|
44 |
By using the 'WP_Query', you can re-override the parameters.
|
45 |
|
46 |
+
WP_Query
|
47 |
|
48 |
`
|
49 |
<?php $query = new WP_Query( array(
|
52 |
) ) ?>
|
53 |
`
|
54 |
|
55 |
+
get_posts()
|
56 |
|
57 |
`
|
58 |
<?php $query = get_posts( array(
|
73 |
|
74 |
By using the 'pre_get_posts' action hook or 'query_posts()', you can re-override the parameters.
|
75 |
|
76 |
+
pre_get_posts
|
77 |
|
78 |
`
|
79 |
function my_filter( $query )
|
88 |
add_action( 'pre_get_posts', 'my_filter' );
|
89 |
`
|
90 |
|
91 |
+
query_posts()
|
92 |
|
93 |
`
|
94 |
<?php query_posts( array(
|
101 |
|
102 |
== Changelog ==
|
103 |
|
104 |
+
= 3.1.0 =
|
105 |
+
|
106 |
+
* Support the Sites.
|
107 |
+
* Improved Activation.
|
108 |
+
|
109 |
= 3.0.8 =
|
110 |
|
111 |
* Even for 'get_posts()', Your custom Query which uses the 'order' or 'orderby' parameters is preferred.
|