Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../public_h.../wp-conte.../plugins/multisit...
File: multisite-post-reader.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/*
[2] Fix | Delete
Plugin Name: Multisite Post Reader
[3] Fix | Delete
Plugin URI: http://cellarweb.com/wordpress-plugins/
[4] Fix | Delete
Description: Shows posts from all subsites on a multisite via a shortcode used on pages/posts. SuperAdmins get an edit link. Optional parameters can limit number of posts and post length. Can be used for public pages.
[5] Fix | Delete
Version: 3.02
[6] Fix | Delete
Author: Rick Hellewell / CellarWeb.com
[7] Fix | Delete
Tested up to: 6.2
[8] Fix | Delete
Requires at least: 4.6
[9] Fix | Delete
PHP Version: 7.23
[10] Fix | Delete
Text Domain:
[11] Fix | Delete
Author URI: http://CellarWeb.com
[12] Fix | Delete
License: GPLv2 or later
[13] Fix | Delete
License URI: http://www.gnu.org/licenses/gpl-2.0.html
[14] Fix | Delete
*/
[15] Fix | Delete
[16] Fix | Delete
/*
[17] Fix | Delete
Copyright (c) 2016-2019 by Rick Hellewell and CellarWeb.com
[18] Fix | Delete
All Rights Reserved
[19] Fix | Delete
[20] Fix | Delete
email: rhellewell@gmail.com
[21] Fix | Delete
[22] Fix | Delete
This program is free software; you can redistribute it and/or modify
[23] Fix | Delete
it under the terms of the GNU General Public License, version 2, as
[24] Fix | Delete
published by the Free Software Foundation.
[25] Fix | Delete
[26] Fix | Delete
This program is distributed in the hope that it will be useful,
[27] Fix | Delete
but WITHOUT ANY WARRANTY; without even the implied warranty of
[28] Fix | Delete
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
[29] Fix | Delete
GNU General Public License for more details.
[30] Fix | Delete
[31] Fix | Delete
You should have received a copy of the GNU General Public License
[32] Fix | Delete
along with this program; if not, write to the Free Software
[33] Fix | Delete
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
[34] Fix | Delete
[35] Fix | Delete
*/
[36] Fix | Delete
// ----------------------------------------------------------------
[37] Fix | Delete
// ----------------------------------------------------------------
[38] Fix | Delete
define('MPR_VERSION', "3.02");
[39] Fix | Delete
define('MPR_VERSION_DATE', "(22 Mar 2023)");
[40] Fix | Delete
[41] Fix | Delete
global $atts; // used for the shortcode parameters
[42] Fix | Delete
if (!mpr_is_requirements_met()) {
[43] Fix | Delete
add_action('admin_init', 'mpr_disable_plugin');
[44] Fix | Delete
add_action('admin_notices', 'mpr_show_notice');
[45] Fix | Delete
add_action('network_admin_init', 'mpr_disable_plugin');
[46] Fix | Delete
add_action('network_admin_notices', 'mpr_show_notice');
[47] Fix | Delete
mpr_deregister();
[48] Fix | Delete
return;
[49] Fix | Delete
}
[50] Fix | Delete
// Add settings link on plugin page
[51] Fix | Delete
function mpr_settings_link($links) {
[52] Fix | Delete
$settings_link = '<a href="options-general.php?page=mpr_settings" title="Multisite Post Reader">Multisite Post Reader Info/Usage</a>';
[53] Fix | Delete
array_unshift($links, $settings_link);
[54] Fix | Delete
return $links;
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
$plugin = plugin_basename(__FILE__);
[58] Fix | Delete
add_filter("plugin_action_links_$plugin", 'mpr_settings_link');
[59] Fix | Delete
[60] Fix | Delete
// build the class for all of this
[61] Fix | Delete
class mpr_Settings_Page {
[62] Fix | Delete
// start your engines!
[63] Fix | Delete
[64] Fix | Delete
public function __construct() {
[65] Fix | Delete
add_action('admin_menu', array($this, 'mpr_add_plugin_page'));
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
// add options page
[69] Fix | Delete
[70] Fix | Delete
public function mpr_add_plugin_page() {
[71] Fix | Delete
// This page will be under "Settings"
[72] Fix | Delete
add_options_page('Multisite Post Reader Info/Usage', 'Multisite Post Reader Info/Usage', 'manage_options', 'mpr_settings', array($this, 'mpr_create_admin_page'));
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
// options page callback
[76] Fix | Delete
[77] Fix | Delete
public function mpr_create_admin_page() {
[78] Fix | Delete
[79] Fix | Delete
// Set class property
[80] Fix | Delete
$this->options = get_option('mpr_options');
[81] Fix | Delete
?>
[82] Fix | Delete
[83] Fix | Delete
<div align='center' class = 'mpr_header'>
[84] Fix | Delete
<img src="<?php echo plugin_dir_url(__FILE__); ?>assets/banner-1000x200.jpg" width="95%" alt="" class='mpr_shadow'>
[85] Fix | Delete
<p align='center'><b>Version:</b> <?php echo MPR_VERSION . " " . MPR_VERSION_DATE; ?></p>
[86] Fix | Delete
</div>
[87] Fix | Delete
<!--<div class = 'mpr_header'>
[88] Fix | Delete
<h1 align="center" >Multisite Post Reader</h1>
[89] Fix | Delete
</div>-->
[90] Fix | Delete
<div >
[91] Fix | Delete
<div class="mpr_options">
[92] Fix | Delete
<?php mpr_info_top();?>
[93] Fix | Delete
</div>
[94] Fix | Delete
<div class='mpr_sidebar'>
[95] Fix | Delete
<?php mpr_sidebar();?>
[96] Fix | Delete
</div>
[97] Fix | Delete
</div>
[98] Fix | Delete
<!-- not sure why this one is needed ... -->
[99] Fix | Delete
<div class="mpr_footer">
[100] Fix | Delete
<?php mpr_footer();?>
[101] Fix | Delete
</div>
[102] Fix | Delete
<?php
[103] Fix | Delete
echo '</div>';
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
// print the Section text
[107] Fix | Delete
[108] Fix | Delete
public function mpr_print_section_info() {
[109] Fix | Delete
print '<h3><strong>Information about Multisite Post Reader from CellarWeb.com</strong></h3>';
[110] Fix | Delete
}
[111] Fix | Delete
}
[112] Fix | Delete
// end of the class stuff
[113] Fix | Delete
[114] Fix | Delete
if (is_admin()) {
[115] Fix | Delete
$my_settings_page = new mpr_Settings_Page();
[116] Fix | Delete
[117] Fix | Delete
// ----------------------------------------------------------------------------
[118] Fix | Delete
// supporting functions
[119] Fix | Delete
// ----------------------------------------------------------------------------
[120] Fix | Delete
// display the top info part of the page
[121] Fix | Delete
// ----------------------------------------------------------------------------
[122] Fix | Delete
function mpr_info_top() {
[123] Fix | Delete
[124] Fix | Delete
?>
[125] Fix | Delete
<p><strong>Multisite Post Reader</strong> allows you to use a <strong>[mpr_display]</strong> shortcode on a page/post to display all posts from all sites in a multisite system. This allows you (as the network SuperAdmin or non-network Admin) to monitor all posts on your multi-site system. Although meant for multisite systems by creating a page/post on the 'master' site, it will also work on standalone sites. It can be used on public pages. No CSS styling is added, so the posts will display using your theme's styling. Shortcode could also be used in a widget, but you would want to use parameters to limit count and length of displayed posts.</p>
[126] Fix | Delete
<p>Each post has a clickable title, and also shows the publish date of the post. A "Read more" link is provided for all posts excerpts. Super-admins will see an Edit icon, which opens a new window/tab to edit the post. Each grouping of posts has a clickable link to the subsite's home page.</p>
[127] Fix | Delete
<h2>Shortcode Options</h2>
[128] Fix | Delete
<p>There are shortcode options/parameters for (adjust the values for your needs):</p>
[129] Fix | Delete
<ul style="list-style-type: disc; list-style-position: inside;padding-left:20px;">
[130] Fix | Delete
<li><strong>items=10</strong>&nbsp;&nbsp;&nbsp;show only the last 10 items (default all items, option used will be shown above each sites' posts group).</li>
[131] Fix | Delete
<li><strong>days=4</strong>&nbsp;&nbsp;&nbsp;show only the last 4 days (default all dates, option used will be shown above each sites' picture group).</li>
[132] Fix | Delete
<li><b>beforedate=YYYYMMDD</b> will select posts before the date. Note the required formatting for the date value. <i>Overridden if you select the 'days' parameter.</i></li>
[133] Fix | Delete
<li><b>afterdate=YYYYMMDD</b> will select posts after the date. Note the required formatting for the date value. <i>Overridden if you select the 'days' parameter.</i></li>
[134] Fix | Delete
<li><strong>showdate</strong>&nbsp;&nbsp;&nbsp;Suppress showing the date stamp of the post. (Default shows the datestamp.)</li>
[135] Fix | Delete
<li><strong>excerpt</strong>&nbsp;&nbsp;&nbsp;will show the post excerpt, using the current word count for excerpt. (default is the entire post). The previous <b>words</b> option now functions like <b>excerpt</b>.</li>
[136] Fix | Delete
<li><strong>showall</strong>&nbsp;&nbsp;&nbsp;show all posts, including drafts, scheduled, private; (default is only published posts, option used will be shown above each sites' posts group). Each post will show it's current status after the post publish date. This allows you to see all types of posts, including scheduled posts.</li>
[137] Fix | Delete
<li><strong>showsiteinfo</strong>&nbsp;&nbsp;&nbsp;do not show subsite info (id, path) (default is to show the site info)</li>
[138] Fix | Delete
<li><strong>disableheading</strong>&nbsp;&nbsp;&nbsp;do not show the selection criteria heading (default is to show selection criteria)</li>
[139] Fix | Delete
<li><strong>showempty</strong>&nbsp;&nbsp;&nbsp;do not show subsites with no results (default=yes, will show 'none found' if no results for that subsite). Note that if a subsite does not have results, the subsite info (ID, path) will not be shown.</li>
[140] Fix | Delete
<li><strong>showdivider</strong>&nbsp;&nbsp;&nbsp;Show the horizontal rule between posts (default will not show horizontal rule).</li>
[141] Fix | Delete
<li><strong>includesites=1,3</strong>&nbsp;&nbsp;&nbsp;show only site with site_id #1 and #3 (default is all sites). Numbers are the site ID number. Separate multiple site id numbers with a comma; do not include quote characters. </li>
[142] Fix | Delete
<li><strong>excludesites=2,4</strong>&nbsp;&nbsp;&nbsp;do not show sites with site_id of #2 and #4 (default is show all sites). Separate multiple site id numbers with a comma; do not include quote characters.</li>
[143] Fix | Delete
<ul style="list-style-type: disc; list-style-position: inside;padding-left:22px;">
[144] Fix | Delete
<li>You can use both includesites/excludesites parameters. The includesites list is processed first, then the excludesites list is processed.</li>
[145] Fix | Delete
</ul>
[146] Fix | Delete
<li><strong>category='one, two, three'</strong>&nbsp;&nbsp;&nbsp;Only include the categories 'one', 'two', and 'three'. These are category <strong>names</strong> (slugs), not category ID numbers (as names are more likely to be the same across multisites, but category ID number might be different). Default is all categories. Separate categories with a comma, but include the quote character around all the category names. Note that any 'children' of a category will also be included for a specified category.</li>
[147] Fix | Delete
<li><strong>type='x,y,z'</strong>&nbsp;&nbsp;&nbsp;Only include the post types indicated. Example: if you have a custom post type called 'product', then use type='product'. Separate multiple custom post type names with commas, and surround the post type names with a quote. Default is to only show 'posts'. </li>
[148] Fix | Delete
<li><strong>debug</strong>&nbsp;&nbsp;&nbsp;Debugging mode: shows the SQL query, plus the number of records found in the query. Will show all shortcode parameters at the top of the output page. Not normally used in production, but helpful when you get strange results.</li>
[149] Fix | Delete
<li><b>showsql</b> Shows the SQL statement used to query the data. For development only.</li>
[150] Fix | Delete
</ul>
[151] Fix | Delete
<p>The parameters can be combined, as in <strong>[mpr_display days=4 items=10]</strong>. The optional parameters will be shown above each site's group of posts unless you use the <strong>disableheading=yes</strong> parameter. If a parameter has a non-alphanumeric character other than a comma (like spaces), enclose the parameters in quotes, as in <b>category='red apples, blue sky'</b>.</p>
[152] Fix | Delete
<p>The individual post content is wrapped in a <strong>mpr_content</strong> CSS class, so you can add your own CSS to style the post content element. </p>
[153] Fix | Delete
<hr />
[154] Fix | Delete
<h2>CSS Classes Used</h2>
[155] Fix | Delete
<p>CSS classes are used for the elements of the posts being output. You can use these class names in your theme's Additional CSS, or in your custom-written theme. The plugin does not add any inline CSS. The CSS rules have no elements added by the plugin; you get to style the elements in your theme.</p>
[156] Fix | Delete
<ul style="list-style-type: disc; list-style-position: inside;padding-left:20px;">
[157] Fix | Delete
<li><strong>mpr_content</strong>: used around the entire post, including header, content, etc.</li>
[158] Fix | Delete
<li><strong>mpr_the_permalink</strong>: for the link to the post - the output of <strong>the_permalink()</strong>.</li>
[159] Fix | Delete
<li><strong>mpr_post_date</strong>: the post date/time stamp. Output can be disabled with the <b>showdate</b> parameter (see above).</li>
[160] Fix | Delete
<li><strong>mpr_the_title</strong>: the post title - the output of <strong>the_title()</strong>.</li>
[161] Fix | Delete
<li><strong>mpr_get_the_content</strong>: the post text/content, including read-more - the output of <strong>get_the_content()</strong>.</li>
[162] Fix | Delete
</ul>
[163] Fix | Delete
<hr>
[164] Fix | Delete
<p><strong>Tell us how the Multisite Post Reader plugin works for you - leave a <a href="https://wordpress.org/support/plugin/multisite-post-reader/reviews/" title="Multisite Post Reader Reviews" target="_blank" >review or rating</a> on our plugin page.&nbsp;&nbsp;&nbsp;<a href="https://wordpress.org/support/plugin/multisite-post-reader" title="Help or Questions" target="_blank">Get Help or Ask Questions here</a>.</strong></p>
[165] Fix | Delete
<hr />
[166] Fix | Delete
<?php
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
// ----------------------------------------------------------------------------
[170] Fix | Delete
// ``end of admin area
[171] Fix | Delete
//here's the closing bracket for the is_admin thing
[172] Fix | Delete
}
[173] Fix | Delete
// ----------------------------------------------------------------------------
[174] Fix | Delete
// register/deregister/uninstall hooks
[175] Fix | Delete
register_activation_hook(__FILE__, 'mpr_register');
[176] Fix | Delete
register_deactivation_hook(__FILE__, 'mpr_deregister');
[177] Fix | Delete
register_uninstall_hook(__FILE__, 'mpr_uninstall');
[178] Fix | Delete
[179] Fix | Delete
// register/deregister/uninstall options (even though there aren't options)
[180] Fix | Delete
function mpr_register() {
[181] Fix | Delete
return;
[182] Fix | Delete
}
[183] Fix | Delete
[184] Fix | Delete
function mpr_deregister() {
[185] Fix | Delete
return;
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
function mpr_uninstall() {
[189] Fix | Delete
return;
[190] Fix | Delete
}
[191] Fix | Delete
[192] Fix | Delete
// ----------------------------------------------------------------------------
[193] Fix | Delete
// set up shortcodes
[194] Fix | Delete
function mpr_shortcodes_init() {
[195] Fix | Delete
add_shortcode('mpr_display', 'mpr_setup_sites');
[196] Fix | Delete
// get some CSS loaded for the settings page
[197] Fix | Delete
wp_register_style('MPR_namespace', plugins_url('/css/settings.css', __FILE__), array(), MPR_VERSION);
[198] Fix | Delete
wp_enqueue_style('MPR_namespace'); // gets the above css file in the proper spot
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
add_action('init', 'mpr_shortcodes_init', 999);
[202] Fix | Delete
[203] Fix | Delete
// ----------------------------------------------------------------------------
[204] Fix | Delete
// here's where we do the work!
[205] Fix | Delete
// ----------------------------------------------------------------------------
[206] Fix | Delete
function mpr_setup_sites($atts = array()) {
[207] Fix | Delete
ob_start(); // to get the shortcode output in the middle of the content.
[208] Fix | Delete
// see https://wordpress.stackexchange.com/questions/47062/short-code-output-too-early
[209] Fix | Delete
// sanitize any parameters using the sanitize_text_field callback
[210] Fix | Delete
if (!is_array($atts)) {$atts = array();} // just in case
[211] Fix | Delete
if (!empty($atts)) {
[212] Fix | Delete
$atts = array_map('sanitize_text_field', $atts);
[213] Fix | Delete
$atts = array_map('strtolower', $atts);
[214] Fix | Delete
// set defaults for all $atts
[215] Fix | Delete
// look for attributes without values (see https://wordpress.stackexchange.com/a/123073/29416
[216] Fix | Delete
// - sets the value of that attribute as true if the attribute exists without a value
[217] Fix | Delete
foreach ($atts as $item => $value) {
[218] Fix | Delete
if ((strlen($value))) {
[219] Fix | Delete
$new_value = explode(",", $value);
[220] Fix | Delete
} else { $new_value = $value;}
[221] Fix | Delete
if (NULL == $value) {
[222] Fix | Delete
$new_value = true;
[223] Fix | Delete
}
[224] Fix | Delete
$atts[$item] = $new_value;
[225] Fix | Delete
}} // $atts not empty
[226] Fix | Delete
// now need to fix $atts[0] = option_name; this looks for attributes that are numbers
[227] Fix | Delete
// see https://wordpress.stackexchange.com/a/123073/29416
[228] Fix | Delete
foreach ($atts as $attribute => $value) {
[229] Fix | Delete
// echo "2nd loop $attribute with value of " . implode("",$value) . " <br>";
[230] Fix | Delete
if (is_int($attribute)) {
[231] Fix | Delete
$atts[implode("", $value)] = true;
[232] Fix | Delete
unset($atts[$attribute]); // gets rid of the numeric item
[233] Fix | Delete
}
[234] Fix | Delete
}
[235] Fix | Delete
$args = array();
[236] Fix | Delete
$heading = array(); // for text to display if disableheading false (default)
[237] Fix | Delete
$atts['datebefore'] = (isset($atts['datebefore'])) ? explode(',', $atts['datebefore']) : array();
[238] Fix | Delete
if (count($atts['datebefore'])) {$args['before'] = array(
[239] Fix | Delete
$atts['datebefore'][0], // YYYY
[240] Fix | Delete
$atts['datebefore'][1], // MM
[241] Fix | Delete
$atts['datebefore'][2], // DD
[242] Fix | Delete
);
[243] Fix | Delete
$heading[] = "Items before " . $atts['datebefore'][0] . "/" . $atts['datebefore'][1] . "/" . $atts['datebefore'][2] . "(YYYY/MM/DD)";
[244] Fix | Delete
$args['date_query'] = array(
[245] Fix | Delete
array(
[246] Fix | Delete
'year' => $atts['datebefore'][0],
[247] Fix | Delete
'month' => $atts['datebefore'][1],
[248] Fix | Delete
'day' => $atts['datebefore'][2],
[249] Fix | Delete
),
[250] Fix | Delete
);
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
$atts['dateafter'] = (isset($atts['dateafter'])) ? explode(',', $atts['dateafter']) : array();
[254] Fix | Delete
if (count($atts['dateafter'])) {$args['after'] = array(
[255] Fix | Delete
$atts['dateafter'][0], // YYYY
[256] Fix | Delete
$atts['dateafter'][1], // MM
[257] Fix | Delete
$atts['dateafter'][2], // DD
[258] Fix | Delete
);
[259] Fix | Delete
$heading[] = "Items after " . $atts['dateafter'][0] . "/" . $atts['dateafter'][1] . "/" . $atts['dateafter'][2] . "(YYYY/MM/DD)";
[260] Fix | Delete
$args['date_query'] = array(
[261] Fix | Delete
array(
[262] Fix | Delete
'year' => $atts['dateafter'][0],
[263] Fix | Delete
'month' => $atts['dateafter'][1],
[264] Fix | Delete
'day' => $atts['dateafter'][2],
[265] Fix | Delete
),
[266] Fix | Delete
);
[267] Fix | Delete
}
[268] Fix | Delete
[269] Fix | Delete
$atts['days'] = (isset($atts['days'])) ? $atts['days'] : 0;
[270] Fix | Delete
if ($atts['days'] > 0) {
[271] Fix | Delete
// get current date - days
[272] Fix | Delete
$newDate = date('Y-m-d', strtotime(' - ' . $atts['days'] . ' days'));
[273] Fix | Delete
// computer 'days' ago from current date
[274] Fix | Delete
// set that date string as the dateafter
[275] Fix | Delete
$args['after'] = $newdate;
[276] Fix | Delete
$heading[] = "Including sites " . implode(", ", $atts['includesites']);
[277] Fix | Delete
if ((isset($atts['dateafter'])) OR (isset($atts['dateafter']))) {
[278] Fix | Delete
unset($args['date_query']);
[279] Fix | Delete
$heading[] = "(The 'days' option is overriding the 'datebefore' and 'dateafter' options.)";
[280] Fix | Delete
}
[281] Fix | Delete
}
[282] Fix | Delete
[283] Fix | Delete
// convert following to array output
[284] Fix | Delete
$atts['includesites'] = (isset($atts['includesites'])) ? $atts['includesites'] : array();
[285] Fix | Delete
if (count($atts['includesites']) > 0) {
[286] Fix | Delete
$heading[] = "Including sites " . implode(", ", $atts['includesites']);
[287] Fix | Delete
}
[288] Fix | Delete
[289] Fix | Delete
$atts['excludesites'] = (isset($atts['excludesites'])) ? explode(",", $atts['excludesites']) : array();
[290] Fix | Delete
if (count($atts['excludesites']) > 0) {
[291] Fix | Delete
$heading[] = "Including sites " . implode(", ", $atts['excludesites']);
[292] Fix | Delete
}
[293] Fix | Delete
[294] Fix | Delete
$atts['category'] = (isset($atts['category'])) ? $atts['category'] : array();
[295] Fix | Delete
if (count($atts['category'])) {
[296] Fix | Delete
$args['category_name'] = implode(",", $atts['category']);
[297] Fix | Delete
//$args['category_name'] = "red";
[298] Fix | Delete
}
[299] Fix | Delete
[300] Fix | Delete
$atts['type'] = (isset($atts['type'])) ? explode(",", $atts['type']) : "post";
[301] Fix | Delete
$atts['post_type'] = (isset($atts['post_type'])) ? explode(",", $atts['post_type']) : "any";
[302] Fix | Delete
// set all the atts to default or settings value
[303] Fix | Delete
$atts['items'] = (isset($atts['items'])) ? $atts['items'] : 0;
[304] Fix | Delete
$atts['words'] = (isset($atts['words'])) ? $atts['words'] : 0;
[305] Fix | Delete
$atts['excerpt'] = (isset($atts['excerpt'])) ? 1 : 0;
[306] Fix | Delete
$atts['showall'] = (isset($atts['showall'])) ? 1 : 0;
[307] Fix | Delete
$atts['showsiteinfo'] = (isset($atts['showsiteinfo'])) ? 1 : 0;
[308] Fix | Delete
$atts['disableheading'] = (isset($atts['disableheading'])) ? 1 : 0;
[309] Fix | Delete
$atts['showempty'] = (isset($atts['showempty'])) ? 1 : 0;
[310] Fix | Delete
$atts['showdivider'] = (isset($atts['showdivider'])) ? 1 : 0;
[311] Fix | Delete
$atts['showdate'] = (isset($atts['showdate'])) ? 1 : 0;
[312] Fix | Delete
$atts['debug'] = (isset($atts['debug'])) ? 1 : 0;
[313] Fix | Delete
$atts['category'] = (isset($atts['category'])) ? $atts['category'] : array();
[314] Fix | Delete
// $atts['type'] = (isset($atts['type'])) ? $atts['type'] : 0;
[315] Fix | Delete
$atts['tag'] = (isset($atts['tag'])) ? $atts['tag'] : 0;
[316] Fix | Delete
$atts['nodate'] = (isset($atts['nodate'])) ? $atts['nodate'] : 0;
[317] Fix | Delete
$atts['showsql'] = (isset($atts['showsql'])) ? 1 : 0; // new in version 2.50
[318] Fix | Delete
if ($atts['debug'] == true) {
[319] Fix | Delete
echo "<strong>Debug:</strong> Shortcode Attributes array<br>";
[320] Fix | Delete
mpr_show_array($atts);
[321] Fix | Delete
echo "<hr>";
[322] Fix | Delete
}
[323] Fix | Delete
$args['post_type'] = $atts['type'];
[324] Fix | Delete
// process all sites
[325] Fix | Delete
mpr_get_sites_array($atts, $args, $heading); // get the sites array, and loop through them in that function
[326] Fix | Delete
// this will flush the output, putting shortcode content where it belongs
[327] Fix | Delete
// don't ob_flush/etc anywhere else
[328] Fix | Delete
return ob_get_clean();
[329] Fix | Delete
}
[330] Fix | Delete
[331] Fix | Delete
// --------------------------------------------------------------------------------
[332] Fix | Delete
// ===============================================================================
[333] Fix | Delete
// functions to display all posts
[334] Fix | Delete
// ===============================================================================
[335] Fix | Delete
/*
[336] Fix | Delete
Styles and code 'functionated' for displaying all posts files
[337] Fix | Delete
adapted from http://alijafarian.com/responsive-image-grids-using-css/
[338] Fix | Delete
*/
[339] Fix | Delete
// --------------------------------------------------------------------------------
[340] Fix | Delete
/*
[341] Fix | Delete
- $atts = shortcode attributes
[342] Fix | Delete
- $args = args for the wp_query object
[343] Fix | Delete
- $heading = text to show is 'disableheading' is set false (default is true)
[344] Fix | Delete
*/
[345] Fix | Delete
function mpr_get_sites_array($atts = array(), $args = array(), $heading = "") {
[346] Fix | Delete
global $posts; // need to ensure post data available to any called functions in here
[347] Fix | Delete
?>
[348] Fix | Delete
<div class='mpr_heading'>
[349] Fix | Delete
<?php
[350] Fix | Delete
if (!$atts['disableheading']) { // building and displaying heading text
[351] Fix | Delete
if ($atts['showempty']) {
[352] Fix | Delete
$atts['showempty'] = false;
[353] Fix | Delete
// $heading[] = "Subsites without entries not shown";
[354] Fix | Delete
}
[355] Fix | Delete
}
[356] Fix | Delete
?>
[357] Fix | Delete
</div>
[358] Fix | Delete
<?php
[359] Fix | Delete
$subsites_object = get_sites();
[360] Fix | Delete
$subsites = mpr_objectToArray($subsites_object);
[361] Fix | Delete
$subsites_copy = array();
[362] Fix | Delete
// headings created and shown at top of all posts
[363] Fix | Delete
$heading = array();
[364] Fix | Delete
if ($atts['includesites']) {
[365] Fix | Delete
$heading[] = "Including subsites: " . implode(", ", $atts['includesites']);
[366] Fix | Delete
foreach ($subsites as $subsite) {
[367] Fix | Delete
$found_include = in_array($subsite['blog_id'], $atts['includesites']);
[368] Fix | Delete
if ($found_include) {
[369] Fix | Delete
$subsites_copy[] = $subsite; // add site
[370] Fix | Delete
}
[371] Fix | Delete
}
[372] Fix | Delete
$subsites = $subsites_copy;
[373] Fix | Delete
}
[374] Fix | Delete
if ($atts['excludesites']) {
[375] Fix | Delete
$heading[] = "Excluding subsites: " . implode(", ", $atts['excludesites']);
[376] Fix | Delete
foreach ($subsites as $subsite) {
[377] Fix | Delete
$found_exclude = in_array($subsite['blog_id'], $atts['excludesites']);
[378] Fix | Delete
// add if not excluded
[379] Fix | Delete
if (!$found_exclude) {
[380] Fix | Delete
$subsites_copy[] = $subsite; // add site
[381] Fix | Delete
}
[382] Fix | Delete
}
[383] Fix | Delete
}
[384] Fix | Delete
if (count($subsites_copy)) {
[385] Fix | Delete
$subsites = $subsites_copy;
[386] Fix | Delete
}
[387] Fix | Delete
[388] Fix | Delete
if (isset($atts['showempty'])) {
[389] Fix | Delete
$heading[] = "Subsites without entries not shown";
[390] Fix | Delete
}
[391] Fix | Delete
if ($atts['items'] > 0) {
[392] Fix | Delete
$x = (is_array($atts['items'])) ? implode(", ", $atts['items']) : "All ";
[393] Fix | Delete
$heading[] = $x . " posts";
[394] Fix | Delete
}
[395] Fix | Delete
if ($atts['days'] > 0) {
[396] Fix | Delete
$heading[] = "Last " . $atts['days'] . " days";
[397] Fix | Delete
}
[398] Fix | Delete
if (($atts['words'] > 0) OR ($atts['excerpt'])) {
[399] Fix | Delete
$heading[] = "Showing the excerpt.";
[400] Fix | Delete
}
[401] Fix | Delete
if (isset($atts['category'])) {
[402] Fix | Delete
$heading[] = "Category: " . implode(", ", $atts['category']);
[403] Fix | Delete
}
[404] Fix | Delete
if ($atts['days']) {
[405] Fix | Delete
$daystring = $atts['days'] . " days ago";
[406] Fix | Delete
} // optional parameter
[407] Fix | Delete
/* if ($atts['showall']) {
[408] Fix | Delete
$xpost_status = 'any';
[409] Fix | Delete
} else {
[410] Fix | Delete
$xpost_status = 'post';
[411] Fix | Delete
}*/
[412] Fix | Delete
// for post type
[413] Fix | Delete
if (!isset($args['post_type'])) {
[414] Fix | Delete
$args['post_type'] = 'post';
[415] Fix | Delete
}
[416] Fix | Delete
if ($atts['showall']) {
[417] Fix | Delete
$heading[] = " All posts";
[418] Fix | Delete
$args['post_type'] = "any";
[419] Fix | Delete
}
[420] Fix | Delete
if ($atts['type']) {
[421] Fix | Delete
$heading[] = 'Post Type = ' . $atts['type'];
[422] Fix | Delete
$args['post_type'] = $atts['type'];
[423] Fix | Delete
}
[424] Fix | Delete
/* not needed, previously set as default = post
[425] Fix | Delete
if ((!count($atts['type'])) AND (!$args['post_type'])) {
[426] Fix | Delete
$args['post_type'] = "post";
[427] Fix | Delete
}*/
[428] Fix | Delete
if ($atts['tag']) {
[429] Fix | Delete
$heading[] = 'Tag(s) = ' . $atts['tag'];
[430] Fix | Delete
}
[431] Fix | Delete
if (count($heading)) {
[432] Fix | Delete
if ($atts['showdivider']) {echo "<hr>";} else {echo "<br>";}
[433] Fix | Delete
foreach ($heading as $item) {
[434] Fix | Delete
echo " - " . $item . "<br>";
[435] Fix | Delete
}
[436] Fix | Delete
}
[437] Fix | Delete
[438] Fix | Delete
foreach ($subsites as $subsite) {
[439] Fix | Delete
$subsite_id = $subsite['blog_id'];
[440] Fix | Delete
$subsite_name = get_blog_details($subsite_id)->blogname;
[441] Fix | Delete
$subsite_path = $subsite['path'];
[442] Fix | Delete
$subsite_domain = $subsite['domain'];
[443] Fix | Delete
switch_to_blog($subsite_id);
[444] Fix | Delete
if ($atts['showsiteinfo']) {
[445] Fix | Delete
$heading = "<hr>Site:<strong> $subsite_id - '$subsite_name'</strong> - <strong>";
[446] Fix | Delete
$thesite_url = site_url();
[447] Fix | Delete
$heading .= "<a href='" . $thesite_url . "' target='_blank'>" . $thesite_url . "</a>";
[448] Fix | Delete
$heading .= "</strong><hr>";
[449] Fix | Delete
} else {
[450] Fix | Delete
}
[451] Fix | Delete
$xsiteurl = "https://" . $subsite_domain . $subsite_path;
[452] Fix | Delete
mpr_site_show_posts($xsiteurl, $atts, $heading, $args);
[453] Fix | Delete
// don't ob_flush, that's taken care of elsewhere
[454] Fix | Delete
restore_current_blog();
[455] Fix | Delete
}
[456] Fix | Delete
if ($atts['showdivider']) { echo "<hr>";} // last entry, show divider if enabled
[457] Fix | Delete
return;
[458] Fix | Delete
}
[459] Fix | Delete
[460] Fix | Delete
// --------------------------------------------------------------------------------
[461] Fix | Delete
// list all posts on all multisite sites
[462] Fix | Delete
// inspired by https://wisdmlabs.com/blog/how-to-list-posts-from-all-blogs-on-wordpress-multisite/
[463] Fix | Delete
// --------------------------------------------------------------------------------
[464] Fix | Delete
// display posts on all sites
[465] Fix | Delete
[466] Fix | Delete
function mpr_site_show_posts($xsiteurl = "", $atts = array(), $heading = array(), $args = array()) {
[467] Fix | Delete
global $post;
[468] Fix | Delete
// ensure args are set with at least the post type parameter, otherwise, query results will be empty
[469] Fix | Delete
if (!is_array($args)) {$args = array();$args['post_type'] = "post";}
[470] Fix | Delete
// see https://developer.wordpress.org/reference/classes/wp_query/#tag-parameters
[471] Fix | Delete
// - for syntax of query element and value type (string, comma string, array)
[472] Fix | Delete
[473] Fix | Delete
$query = new WP_Query($args);
[474] Fix | Delete
if ($atts['showsql']) {
[475] Fix | Delete
$query->store_result();
[476] Fix | Delete
$records_found = $query->post_count;
[477] Fix | Delete
echo "<br><b>SQL Query:</b><br>" . $query->request . "<br>";
[478] Fix | Delete
echo "<strong>Found:</strong> " . $records_found . " records<br>";
[479] Fix | Delete
}
[480] Fix | Delete
if (!$query->have_posts()) {
[481] Fix | Delete
if (isset($atts['debug'])) {echo "<strong>Debug: </strong> (none found)<br>";}
[482] Fix | Delete
if (isset($atts['showempty'])) {
[483] Fix | Delete
echo "(none found)";
[484] Fix | Delete
return;
[485] Fix | Delete
}
[486] Fix | Delete
}
[487] Fix | Delete
[488] Fix | Delete
if ($query->have_posts()) {
[489] Fix | Delete
while ($query->have_posts()) {
[490] Fix | Delete
$query->the_post();
[491] Fix | Delete
$x = get_post();
[492] Fix | Delete
if ($atts['showdivider']) {echo "<hr>";} else {echo "<br>";}
[493] Fix | Delete
[494] Fix | Delete
?>
[495] Fix | Delete
<div class="mpr_content"> <strong> <a href="<?php the_permalink();?>" title="<?php the_title_attribute();?>" class="mpr_the_permalink">
[496] Fix | Delete
<div class="mpr_the_title"><?php the_title();?></div>
[497] Fix | Delete
</a></strong>&nbsp;&nbsp;&nbsp;
[498] Fix | Delete
<?php
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function