Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/updraftp.../central/modules
File: comments.php
<?php
[0] Fix | Delete
[1] Fix | Delete
if (!defined('UPDRAFTCENTRAL_CLIENT_DIR')) die('No access.');
[2] Fix | Delete
[3] Fix | Delete
class UpdraftCentral_Comments_Commands extends UpdraftCentral_Commands {
[4] Fix | Delete
[5] Fix | Delete
/**
[6] Fix | Delete
* The _search_comments function searches all available comments based
[7] Fix | Delete
* on the following query parameters (type, status, search)
[8] Fix | Delete
*
[9] Fix | Delete
* Search Parameters/Filters:
[10] Fix | Delete
* type - comment types can be 'comment', 'trackback' and 'pingback', defaults to 'comment'
[11] Fix | Delete
* status - comment status can be 'hold' or unapprove, 'approve', 'spam', 'trash'
[12] Fix | Delete
* search - user generated content or keyword
[13] Fix | Delete
*
[14] Fix | Delete
* @param array $query The query to search comments
[15] Fix | Delete
* @return array
[16] Fix | Delete
*/
[17] Fix | Delete
private function _search_comments($query) {
[18] Fix | Delete
[19] Fix | Delete
// Basic parameters to the query and should display
[20] Fix | Delete
// the results in descending order (latest comments) first
[21] Fix | Delete
// based on their generated IDs
[22] Fix | Delete
[23] Fix | Delete
$args = array(
[24] Fix | Delete
'orderby' => 'ID',
[25] Fix | Delete
'order' => 'DESC',
[26] Fix | Delete
'type' => $query['type'],
[27] Fix | Delete
'status' => $query['status'],
[28] Fix | Delete
'search' => esc_attr($query['search']),
[29] Fix | Delete
);
[30] Fix | Delete
[31] Fix | Delete
$query = new WP_Comment_Query;
[32] Fix | Delete
$found_comments = $query->query($args);
[33] Fix | Delete
[34] Fix | Delete
$comments = array();
[35] Fix | Delete
foreach ($found_comments as $comment) {
[36] Fix | Delete
[37] Fix | Delete
// We're returning a collection of comment in an array,
[38] Fix | Delete
// in sync with the originator of the request on the ui side
[39] Fix | Delete
// so, we're pulling it one by one into the array before
[40] Fix | Delete
// returning it.
[41] Fix | Delete
[42] Fix | Delete
if (!in_array($comment, $comments)) {
[43] Fix | Delete
array_push($comments, $comment);
[44] Fix | Delete
}
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
return $comments;
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
/**
[51] Fix | Delete
* The _calculate_pages function generates and builds the pagination links
[52] Fix | Delete
* based on the current search parameters/filters. Please see _search_comments
[53] Fix | Delete
* for the breakdown of these parameters.
[54] Fix | Delete
*
[55] Fix | Delete
* @param array $query Query to generate pagination links
[56] Fix | Delete
* @return array
[57] Fix | Delete
*/
[58] Fix | Delete
private function _calculate_pages($query) {
[59] Fix | Delete
$per_page_options = array(10, 20, 30, 40, 50);
[60] Fix | Delete
[61] Fix | Delete
if (!empty($query)) {
[62] Fix | Delete
if (!empty($query['search'])) {
[63] Fix | Delete
return array(
[64] Fix | Delete
'page_count' => 1,
[65] Fix | Delete
'page_no' => 1
[66] Fix | Delete
);
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
$pages = array();
[70] Fix | Delete
$page_query = new WP_Comment_Query;
[71] Fix | Delete
[72] Fix | Delete
// Here, we're pulling the comments based on the
[73] Fix | Delete
// two parameters namely type and status.
[74] Fix | Delete
//
[75] Fix | Delete
// The number of results/comments found will then
[76] Fix | Delete
// be use to compute for the number of pages to be
[77] Fix | Delete
// displayed as navigation links when browsing all
[78] Fix | Delete
// comments from the frontend.
[79] Fix | Delete
[80] Fix | Delete
$comments = $page_query->query(array(
[81] Fix | Delete
'type' => $query['type'],
[82] Fix | Delete
'status' => $query['status']
[83] Fix | Delete
));
[84] Fix | Delete
[85] Fix | Delete
$total_comments = count($comments);
[86] Fix | Delete
$page_count = ceil($total_comments / $query['per_page']);
[87] Fix | Delete
[88] Fix | Delete
if ($page_count > 1) {
[89] Fix | Delete
for ($i = 0; $i < $page_count; $i++) {
[90] Fix | Delete
if ($i + 1 == $query['page_no']) {
[91] Fix | Delete
$paginator_item = array(
[92] Fix | Delete
'value' => $i+1,
[93] Fix | Delete
'setting' => 'disabled'
[94] Fix | Delete
);
[95] Fix | Delete
} else {
[96] Fix | Delete
$paginator_item = array(
[97] Fix | Delete
'value' => $i+1
[98] Fix | Delete
);
[99] Fix | Delete
}
[100] Fix | Delete
array_push($pages, $paginator_item);
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
if ($query['page_no'] >= $page_count) {
[104] Fix | Delete
$page_next = array(
[105] Fix | Delete
'value' => $page_count,
[106] Fix | Delete
'setting' => 'disabled'
[107] Fix | Delete
);
[108] Fix | Delete
} else {
[109] Fix | Delete
$page_next = array(
[110] Fix | Delete
'value' => $query['page_no'] + 1
[111] Fix | Delete
);
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
if (1 === $query['page_no']) {
[115] Fix | Delete
$page_prev = array(
[116] Fix | Delete
'value' => 1,
[117] Fix | Delete
'setting' => 'disabled'
[118] Fix | Delete
);
[119] Fix | Delete
} else {
[120] Fix | Delete
$page_prev = array(
[121] Fix | Delete
'value' => $query['page_no'] - 1
[122] Fix | Delete
);
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
return array(
[126] Fix | Delete
'page_no' => $query['page_no'],
[127] Fix | Delete
'per_page' => $query['per_page'],
[128] Fix | Delete
'page_count' => $page_count,
[129] Fix | Delete
'pages' => $pages,
[130] Fix | Delete
'page_next' => $page_next,
[131] Fix | Delete
'page_prev' => $page_prev,
[132] Fix | Delete
'total_results' => $total_comments,
[133] Fix | Delete
'per_page_options' => $per_page_options
[134] Fix | Delete
);
[135] Fix | Delete
[136] Fix | Delete
} else {
[137] Fix | Delete
return array(
[138] Fix | Delete
'page_no' => $query['page_no'],
[139] Fix | Delete
'per_page' => $query['per_page'],
[140] Fix | Delete
'page_count' => $page_count,
[141] Fix | Delete
'total_results' => $total_comments,
[142] Fix | Delete
'per_page_options' => $per_page_options
[143] Fix | Delete
);
[144] Fix | Delete
}
[145] Fix | Delete
} else {
[146] Fix | Delete
return array(
[147] Fix | Delete
'per_page_options' => $per_page_options
[148] Fix | Delete
);
[149] Fix | Delete
}
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
/**
[153] Fix | Delete
* The get_blog_sites function pulls blog sites available for the current WP instance.
[154] Fix | Delete
* If Multisite is enabled on the server, then sites under the network will be pulled, otherwise, it will return an empty array.
[155] Fix | Delete
*
[156] Fix | Delete
* @return array
[157] Fix | Delete
*/
[158] Fix | Delete
private function get_blog_sites() {
[159] Fix | Delete
[160] Fix | Delete
if (!is_multisite()) return array();
[161] Fix | Delete
[162] Fix | Delete
// Initialize array container
[163] Fix | Delete
$sites = $network_sites = array();
[164] Fix | Delete
[165] Fix | Delete
// Check to see if latest get_sites (available on WP version >= 4.6) function is
[166] Fix | Delete
// available to pull any available sites from the current WP instance. If not, then
[167] Fix | Delete
// we're going to use the fallback function wp_get_sites (for older version).
[168] Fix | Delete
[169] Fix | Delete
if (function_exists('get_sites') && class_exists('WP_Site_Query')) {
[170] Fix | Delete
$network_sites = get_sites();
[171] Fix | Delete
} else {
[172] Fix | Delete
if (function_exists('wp_get_sites')) {
[173] Fix | Delete
$network_sites = wp_get_sites();
[174] Fix | Delete
}
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
// We only process if sites array is not empty, otherwise, bypass
[178] Fix | Delete
// the next block.
[179] Fix | Delete
[180] Fix | Delete
if (!empty($network_sites)) {
[181] Fix | Delete
foreach ($network_sites as $site) {
[182] Fix | Delete
[183] Fix | Delete
// Here we're checking if the site type is an array, because
[184] Fix | Delete
// we're pulling the blog_id property based on the type of
[185] Fix | Delete
// site returned.
[186] Fix | Delete
// get_sites returns an array of object, whereas the wp_get_sites
[187] Fix | Delete
// function returns an array of array.
[188] Fix | Delete
[189] Fix | Delete
$blog_id = (is_array($site)) ? $site['blog_id'] : $site->blog_id;
[190] Fix | Delete
[191] Fix | Delete
[192] Fix | Delete
// We're saving the blog_id and blog name as an associative item
[193] Fix | Delete
// into the sites array, that will be used as "Sites" option in
[194] Fix | Delete
// the frontend.
[195] Fix | Delete
[196] Fix | Delete
$sites[$blog_id] = get_blog_details($blog_id)->blogname;
[197] Fix | Delete
}
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
return $sites;
[201] Fix | Delete
}
[202] Fix | Delete
[203] Fix | Delete
/**
[204] Fix | Delete
* The get_wp_option function pulls current blog options
[205] Fix | Delete
* from the database using either following functions:
[206] Fix | Delete
* - get_blog_option (for multisite)
[207] Fix | Delete
* - get_option (for ordinary blog)
[208] Fix | Delete
*
[209] Fix | Delete
* @param array $blog_id This is the specific blog ID
[210] Fix | Delete
* @param array $setting specifies settings
[211] Fix | Delete
* @return array
[212] Fix | Delete
*/
[213] Fix | Delete
private function _get_wp_option($blog_id, $setting) {
[214] Fix | Delete
return is_multisite() ? get_blog_option($blog_id, $setting) : get_option($setting);
[215] Fix | Delete
}
[216] Fix | Delete
[217] Fix | Delete
/**
[218] Fix | Delete
* The get_comments function pull all the comments from the database
[219] Fix | Delete
* based on the current search parameters/filters. Please see _search_comments
[220] Fix | Delete
* for the breakdown of these parameters.
[221] Fix | Delete
*
[222] Fix | Delete
* @param array $query Specific query to pull comments
[223] Fix | Delete
* @return array
[224] Fix | Delete
*/
[225] Fix | Delete
public function get_comments($query) {
[226] Fix | Delete
[227] Fix | Delete
// Here, we're getting the current blog id. If blog id
[228] Fix | Delete
// is passed along with the parameters then we override
[229] Fix | Delete
// that current (default) value with the parameter blog id value.
[230] Fix | Delete
[231] Fix | Delete
$blog_id = get_current_blog_id();
[232] Fix | Delete
if (isset($query['blog_id'])) $blog_id = $query['blog_id'];
[233] Fix | Delete
[234] Fix | Delete
[235] Fix | Delete
// Here, we're switching to the actual blog that we need
[236] Fix | Delete
// to pull comments from.
[237] Fix | Delete
[238] Fix | Delete
$switched = false;
[239] Fix | Delete
if (function_exists('switch_to_blog')) {
[240] Fix | Delete
$switched = switch_to_blog($blog_id);
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
if (!empty($query['search'])) {
[244] Fix | Delete
// If a search keyword is present, then we'll call the _search_comments
[245] Fix | Delete
// function to process the query.
[246] Fix | Delete
[247] Fix | Delete
$comments = $this->_search_comments($query);
[248] Fix | Delete
} else {
[249] Fix | Delete
// Set default parameter values if the designated
[250] Fix | Delete
// parameters are empty.
[251] Fix | Delete
[252] Fix | Delete
if (empty($query['per_page'])) {
[253] Fix | Delete
$query['per_page'] = 10;
[254] Fix | Delete
}
[255] Fix | Delete
if (empty($query['page_no'])) {
[256] Fix | Delete
$query['page_no'] = 1;
[257] Fix | Delete
}
[258] Fix | Delete
if (empty($query['type'])) {
[259] Fix | Delete
$query['type'] = '';
[260] Fix | Delete
}
[261] Fix | Delete
if (empty($query['status'])) {
[262] Fix | Delete
$query['status'] = '';
[263] Fix | Delete
}
[264] Fix | Delete
[265] Fix | Delete
// Since WP_Comment_Query parameters doesn't have a "page" attribute, we
[266] Fix | Delete
// need to compute for the offset to get the exact content based on the
[267] Fix | Delete
// current page and the number of items per page.
[268] Fix | Delete
[269] Fix | Delete
$offset = ((int) $query['page_no'] - 1) * (int) $query['per_page'];
[270] Fix | Delete
$args = array(
[271] Fix | Delete
'orderby' => 'ID',
[272] Fix | Delete
'order' => 'DESC',
[273] Fix | Delete
'number' => $query['per_page'],
[274] Fix | Delete
'offset' => $offset,
[275] Fix | Delete
'type' => $query['type'],
[276] Fix | Delete
'status' => $query['status']
[277] Fix | Delete
);
[278] Fix | Delete
[279] Fix | Delete
$comments_query = new WP_Comment_Query;
[280] Fix | Delete
$comments = $comments_query->query($args);
[281] Fix | Delete
}
[282] Fix | Delete
[283] Fix | Delete
// If no comments are found based on the current query then
[284] Fix | Delete
// we return with error.
[285] Fix | Delete
[286] Fix | Delete
if (empty($comments)) {
[287] Fix | Delete
$result = array('message' => 'comments_not_found');
[288] Fix | Delete
return $this->_response($result);
[289] Fix | Delete
}
[290] Fix | Delete
[291] Fix | Delete
// Otherwise, we're going to process each comment
[292] Fix | Delete
// before we return it to the one issuing the request.
[293] Fix | Delete
//
[294] Fix | Delete
// Process in the sense that we add additional related info
[295] Fix | Delete
// such as the post tile where the comment belongs to, the
[296] Fix | Delete
// comment status, a formatted date field, and to which parent comment
[297] Fix | Delete
// does the comment was intended to be as a reply.
[298] Fix | Delete
[299] Fix | Delete
foreach ($comments as &$comment) {
[300] Fix | Delete
$comment = get_comment($comment->comment_ID, ARRAY_A);
[301] Fix | Delete
if ($comment) {
[302] Fix | Delete
$post = get_post($comment['comment_post_ID']);
[303] Fix | Delete
[304] Fix | Delete
if ($post) $comment['in_response_to'] = $post->post_title;
[305] Fix | Delete
if (!empty($comment['comment_parent'])) {
[306] Fix | Delete
$parent_comment = get_comment($comment['comment_parent'], ARRAY_A);
[307] Fix | Delete
if ($parent_comment) $comment['in_reply_to'] = $parent_comment['comment_author'];
[308] Fix | Delete
}
[309] Fix | Delete
[310] Fix | Delete
// We're formatting the comment_date to be exactly the same
[311] Fix | Delete
// with that of WP Comments table (e.g. 2016/12/21 at 10:30 PM)
[312] Fix | Delete
[313] Fix | Delete
$comment['comment_date'] = date('Y/m/d \a\t g:i a', strtotime($comment['comment_date']));
[314] Fix | Delete
[315] Fix | Delete
$status = wp_get_comment_status($comment['comment_ID']);
[316] Fix | Delete
if ($status) {
[317] Fix | Delete
$comment['comment_status'] = $status;
[318] Fix | Delete
}
[319] Fix | Delete
}
[320] Fix | Delete
}
[321] Fix | Delete
[322] Fix | Delete
// We return the following to the one issuing
[323] Fix | Delete
// the request.
[324] Fix | Delete
[325] Fix | Delete
$result = array(
[326] Fix | Delete
'comments' => $comments,
[327] Fix | Delete
'paging' => $this->_calculate_pages($query)
[328] Fix | Delete
);
[329] Fix | Delete
[330] Fix | Delete
[331] Fix | Delete
// Here, we're restoring to the current (default) blog before we
[332] Fix | Delete
// do the switched.
[333] Fix | Delete
[334] Fix | Delete
if (function_exists('restore_current_blog') && $switched) {
[335] Fix | Delete
restore_current_blog();
[336] Fix | Delete
}
[337] Fix | Delete
[338] Fix | Delete
return $this->_response($result);
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
/**
[342] Fix | Delete
* The get_comment_filters function builds a array of options
[343] Fix | Delete
* to be use as filters for the search function on the frontend.
[344] Fix | Delete
*/
[345] Fix | Delete
public function get_comment_filters() {
[346] Fix | Delete
// Options for comment_types field
[347] Fix | Delete
$comment_types = apply_filters('admin_comment_types_dropdown', array(
[348] Fix | Delete
'comment' => __('Comments'),
[349] Fix | Delete
'pings' => __('Pings'),
[350] Fix | Delete
));
[351] Fix | Delete
[352] Fix | Delete
// Options for comment_status field
[353] Fix | Delete
$comment_statuses = array(
[354] Fix | Delete
'approve' => __('Approve'),
[355] Fix | Delete
'hold' => __('Hold or Unapprove'),
[356] Fix | Delete
'trash' => __('Trash'),
[357] Fix | Delete
'spam' => __('Spam'),
[358] Fix | Delete
);
[359] Fix | Delete
[360] Fix | Delete
// Pull sites options if available.
[361] Fix | Delete
$sites = $this->get_blog_sites();
[362] Fix | Delete
[363] Fix | Delete
$result = array(
[364] Fix | Delete
'sites' => $sites,
[365] Fix | Delete
'types' => $comment_types,
[366] Fix | Delete
'statuses' => $comment_statuses,
[367] Fix | Delete
'paging' => $this->_calculate_pages(null),
[368] Fix | Delete
);
[369] Fix | Delete
[370] Fix | Delete
return $this->_response($result);
[371] Fix | Delete
}
[372] Fix | Delete
[373] Fix | Delete
/**
[374] Fix | Delete
* The get_settings function pulls the current discussion settings
[375] Fix | Delete
* option values.
[376] Fix | Delete
*
[377] Fix | Delete
* @param array $params Passing specific params for getting current discussion settings
[378] Fix | Delete
* @return array
[379] Fix | Delete
*/
[380] Fix | Delete
public function get_settings($params) {
[381] Fix | Delete
global $updraftcentral_main;
[382] Fix | Delete
[383] Fix | Delete
// Here, we're getting the current blog id. If blog id
[384] Fix | Delete
// is passed along with the parameters then we override
[385] Fix | Delete
// that current (default) value with the parameter blog id value.
[386] Fix | Delete
[387] Fix | Delete
$blog_id = get_current_blog_id();
[388] Fix | Delete
if (isset($params['blog_id'])) $blog_id = $params['blog_id'];
[389] Fix | Delete
[390] Fix | Delete
[391] Fix | Delete
// If user does not have sufficient privileges to manage and edit
[392] Fix | Delete
// WP options then we return with error.
[393] Fix | Delete
[394] Fix | Delete
if (!current_user_can_for_blog($blog_id, 'manage_options')) {
[395] Fix | Delete
$result = array('error' => true, 'message' => 'insufficient_permission');
[396] Fix | Delete
return $this->_response($result);
[397] Fix | Delete
}
[398] Fix | Delete
[399] Fix | Delete
// Pull sites options if available.
[400] Fix | Delete
$sites = $this->get_blog_sites();
[401] Fix | Delete
[402] Fix | Delete
// Wrap current discussion settings values into an array item
[403] Fix | Delete
// named settings.
[404] Fix | Delete
[405] Fix | Delete
$result = array(
[406] Fix | Delete
'settings' => array(
[407] Fix | Delete
'default_pingback_flag' => $this->_get_wp_option($blog_id, 'default_pingback_flag'),
[408] Fix | Delete
'default_ping_status' => $this->_get_wp_option($blog_id, 'default_ping_status'),
[409] Fix | Delete
'default_comment_status' => $this->_get_wp_option($blog_id, 'default_comment_status'),
[410] Fix | Delete
'require_name_email' => $this->_get_wp_option($blog_id, 'require_name_email'),
[411] Fix | Delete
'comment_registration' => $this->_get_wp_option($blog_id, 'comment_registration'),
[412] Fix | Delete
'close_comments_for_old_posts' => $this->_get_wp_option($blog_id, 'close_comments_for_old_posts'),
[413] Fix | Delete
'close_comments_days_old' => $this->_get_wp_option($blog_id, 'close_comments_days_old'),
[414] Fix | Delete
'thread_comments' => $this->_get_wp_option($blog_id, 'thread_comments'),
[415] Fix | Delete
'thread_comments_depth' => $this->_get_wp_option($blog_id, 'thread_comments_depth'),
[416] Fix | Delete
'page_comments' => $this->_get_wp_option($blog_id, 'page_comments'),
[417] Fix | Delete
'comments_per_page' => $this->_get_wp_option($blog_id, 'comments_per_page'),
[418] Fix | Delete
'default_comments_page' => $this->_get_wp_option($blog_id, 'default_comments_page'),
[419] Fix | Delete
'comment_order' => $this->_get_wp_option($blog_id, 'comment_order'),
[420] Fix | Delete
'comments_notify' => $this->_get_wp_option($blog_id, 'comments_notify'),
[421] Fix | Delete
'moderation_notify' => $this->_get_wp_option($blog_id, 'moderation_notify'),
[422] Fix | Delete
'comment_moderation' => $this->_get_wp_option($blog_id, 'comment_moderation'),
[423] Fix | Delete
'comment_max_links' => $this->_get_wp_option($blog_id, 'comment_max_links'),
[424] Fix | Delete
'moderation_keys' => $this->_get_wp_option($blog_id, 'moderation_keys'),
[425] Fix | Delete
),
[426] Fix | Delete
'sites' => $sites,
[427] Fix | Delete
);
[428] Fix | Delete
[429] Fix | Delete
$wp_version = $updraftcentral_main->get_wordpress_version();
[430] Fix | Delete
if (version_compare($wp_version, '5.5.0', '<')) {
[431] Fix | Delete
$result['settings']['comment_whitelist'] = $this->_get_wp_option($blog_id, 'comment_whitelist');
[432] Fix | Delete
$result['settings']['blacklist_keys'] = $this->_get_wp_option($blog_id, 'blacklist_keys');
[433] Fix | Delete
} else {
[434] Fix | Delete
$result['settings']['comment_previously_approved'] = $this->_get_wp_option($blog_id, 'comment_previously_approved');
[435] Fix | Delete
$result['settings']['disallowed_keys'] = $this->_get_wp_option($blog_id, 'disallowed_keys');
[436] Fix | Delete
}
[437] Fix | Delete
[438] Fix | Delete
return $this->_response($result);
[439] Fix | Delete
}
[440] Fix | Delete
[441] Fix | Delete
/**
[442] Fix | Delete
* The update_settings function updates the discussion settings
[443] Fix | Delete
* basing on the user generated content/option from the frontend
[444] Fix | Delete
* form.
[445] Fix | Delete
*
[446] Fix | Delete
* @param array $params Specific params to update settings based on discussion
[447] Fix | Delete
* @return array
[448] Fix | Delete
*/
[449] Fix | Delete
public function update_settings($params) {
[450] Fix | Delete
[451] Fix | Delete
// Extract settings values from passed parameters.
[452] Fix | Delete
$settings = $params['settings'];
[453] Fix | Delete
[454] Fix | Delete
// Here, we're getting the current blog id. If blog id
[455] Fix | Delete
// is passed along with the parameters then we override
[456] Fix | Delete
// that current (default) value with the parameter blog id value.
[457] Fix | Delete
[458] Fix | Delete
$blog_id = get_current_blog_id();
[459] Fix | Delete
if (isset($params['blog_id'])) $blog_id = $params['blog_id'];
[460] Fix | Delete
[461] Fix | Delete
[462] Fix | Delete
// If user does not have sufficient privileges to manage and edit
[463] Fix | Delete
// WP options then we return with error.
[464] Fix | Delete
[465] Fix | Delete
if (!current_user_can_for_blog($blog_id, 'manage_options')) {
[466] Fix | Delete
$result = array('error' => true, 'message' => 'insufficient_permission');
[467] Fix | Delete
return $this->_response($result);
[468] Fix | Delete
}
[469] Fix | Delete
[470] Fix | Delete
// Here, we're sanitizing the input fields before we save them to the database
[471] Fix | Delete
// for safety and security reason. The "explode" and "implode" functions are meant
[472] Fix | Delete
// to maintain the line breaks associated with a textarea input/value.
[473] Fix | Delete
[474] Fix | Delete
foreach ($settings as $key => $value) {
[475] Fix | Delete
[476] Fix | Delete
// We're using update_blog_option and update_option altogether to update the current
[477] Fix | Delete
// discussion settings.
[478] Fix | Delete
[479] Fix | Delete
if (is_multisite()) {
[480] Fix | Delete
update_blog_option($blog_id, $key, implode("\n", array_map('sanitize_text_field', explode("\n", $value))));
[481] Fix | Delete
} else {
[482] Fix | Delete
update_option($key, implode("\n", array_map('sanitize_text_field', explode("\n", $value))));
[483] Fix | Delete
}
[484] Fix | Delete
}
[485] Fix | Delete
[486] Fix | Delete
// We're not checking for errors here, but instead we're directly returning a success (error = false)
[487] Fix | Delete
// status always, because WP's update_option will return fail if values were not changed, meaning
[488] Fix | Delete
// previous values were not changed by the user's current request, not an actual exception thrown.
[489] Fix | Delete
// Thus, giving a false positive message or report to the frontend.
[490] Fix | Delete
[491] Fix | Delete
$result = array('error' => false, 'message' => 'settings_updated', 'values' => array());
[492] Fix | Delete
return $this->_response($result);
[493] Fix | Delete
}
[494] Fix | Delete
[495] Fix | Delete
/**
[496] Fix | Delete
* The get_comment function pulls a single comment based
[497] Fix | Delete
* on a comment ID.
[498] Fix | Delete
*
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function