Skip to content

Commit

Permalink
Update dashboard.php
Browse files Browse the repository at this point in the history
  • Loading branch information
ptibogxiv committed Apr 1, 2019
1 parent ceae85b commit 62f9375
Showing 1 changed file with 1 addition and 119 deletions.
120 changes: 1 addition & 119 deletions functions/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -2073,24 +2073,7 @@ function demo(){
<?php
echo '</style>';

echo '<ul class="list-group">
<li class="list-group-item d-flex justify-content-between align-items-center">
Cras justo odio
<span class="badge badge-primary badge-pill">14</span>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
Dapibus ac facilisis in
<span class="badge badge-primary badge-pill">2</span>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
Morbi leo risus
<div class="btn-group" role="group" aria-label="Basic example">
<a class="btn btn-primary" href="#" role="button">Link</a>
<a class="btn btn-primary" href="#" role="button">Link</a>
</div>
</li>
</ul>
<div class="accordion" id="accordionExample">
echo '<div class="accordion" id="accordionExample">
<div class="card">
<div class="card-header" id="headingOne">
<h2 class="mb-0">
Expand Down Expand Up @@ -2176,107 +2159,6 @@ function generate_license($suffix = null) {
return $license_string;
}

class WP_Query_Multisite {
function __construct() {
add_filter('query_vars', array($this, 'query_vars'));
add_action('pre_get_posts', array($this, 'pre_get_posts'), 100);
add_filter('posts_clauses', array($this, 'posts_clauses'), 10, 2);
add_filter('posts_request', array($this, 'posts_request'), 10, 2);
add_action('the_post', array($this, 'the_post'));
add_action('loop_end', array($this, 'loop_end'));
}
function query_vars($vars) {
$vars[] = 'multisite';
$vars[] = 'sites__not_in';
$vars[] = 'sites__in';
return $vars;
}
function pre_get_posts($query) {
if($query->get('multisite')) {
global $wpdb, $blog_id;
$this->loop_end = false;
$this->blog_id = $blog_id;
$site_IDs = $wpdb->get_col( "select blog_id from $wpdb->blogs" );
if ( $query->get('sites__not_in') )
foreach($site_IDs as $key => $site_ID )
if (in_array($site_ID, $query->get('sites__not_in')) ) unset($site_IDs[$key]);
if ( $query->get('sites__in') )
foreach($site_IDs as $key => $site_ID )
if ( ! in_array($site_ID, $query->get('sites__in')) )
unset($site_IDs[$key]);
$site_IDs = array_values($site_IDs);
$this->sites_to_query = $site_IDs;
}
}
function posts_clauses($clauses, $query) {
if($query->get('multisite')) {
global $wpdb;
// Start new mysql selection to replace wp_posts on posts_request hook
$this->ms_select = array();
$root_site_db_prefix = $wpdb->prefix;
foreach($this->sites_to_query as $site_ID) {
switch_to_blog($site_ID);
$ms_select = $clauses['join'] . ' WHERE 1=1 '. $clauses['where'];
if($clauses['groupby'])
$ms_select .= ' GROUP BY ' . $clauses['groupby'];
$ms_select = str_replace($root_site_db_prefix, $wpdb->prefix, $ms_select);
$ms_select = " SELECT $wpdb->posts.*, '$site_ID' as site_ID FROM $wpdb->posts $ms_select ";
$this->ms_select[] = $ms_select;
restore_current_blog();
}
// Clear join, where and groupby to populate with parsed ms select on posts_request hook;
$clauses['join'] = '';
$clauses['where'] = '';
$clauses['groupby'] = '';
// Orderby for tables (not wp_posts)
$clauses['orderby'] = str_replace($wpdb->posts, 'tables', $clauses['orderby']);
}
return $clauses;
}
function posts_request($sql, $query) {
if($query->get('multisite')) {
global $wpdb;
// Clean up remanescent WHERE request
$sql = str_replace('WHERE 1=1', '', $sql);
// Multisite request
$sql = str_replace("$wpdb->posts.* FROM $wpdb->posts", 'tables.* FROM ( ' . implode(" UNION ", $this->ms_select) . ' ) tables', $sql);
}
return $sql;
}
function the_post($post) {
global $blog_id;
if( isset( $this->loop_end ) && !$this->loop_end && $post->site_ID && $blog_id !== $post->site_ID) {
switch_to_blog($post->site_ID);
}
}
function loop_end($query) {
global $switched;
if($query->get('multisite')) {
$this->loop_end = true;
if($switched) {
switch_to_blog($this->blog_id);
}
}
}
}
new WP_Query_Multisite();

$args = array(
'multisite' => '1',
'tax_query' => array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => array('post-format-quote','post-format-audio','post-format-gallery','post-format-image','post-format-link','post-format-video'),
'operator' => 'NOT IN'
)
);

$query = new WP_Query( $args );
while($query->have_posts()) : $query->the_post();
echo "<a href='".get_the_permalink()."'>".get_the_title()."</a><br>";
endwhile;
wp_reset_postdata();

//echo generate_license();

}
Expand Down

0 comments on commit 62f9375

Please sign in to comment.