Edit File by line
/home/barbar84/www/wp-conte.../plugins/updraftp.../central/modules
File: posts.php
<?php
[0] Fix | Delete
[1] Fix | Delete
if (!defined('UPDRAFTCENTRAL_CLIENT_DIR')) die('No access.');
[2] Fix | Delete
[3] Fix | Delete
/**
[4] Fix | Delete
* Handles Posts Commands
[5] Fix | Delete
*/
[6] Fix | Delete
class UpdraftCentral_Posts_Commands extends UpdraftCentral_Commands {
[7] Fix | Delete
[8] Fix | Delete
protected $switched = false;
[9] Fix | Delete
[10] Fix | Delete
protected $post_type = 'post';
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* Function that gets called before every action
[14] Fix | Delete
*
[15] Fix | Delete
* @param string $command a string that corresponds to UDC command to call a certain method for this class.
[16] Fix | Delete
* @param array $data an array of data post or get fields
[17] Fix | Delete
* @param array $extra_info extrainfo use in the udrpc_action, e.g. user_id
[18] Fix | Delete
*
[19] Fix | Delete
* link to udrpc_action main function in class UpdraftCentral_Listener
[20] Fix | Delete
*/
[21] Fix | Delete
public function _pre_action($command, $data, $extra_info) {// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- This function is called from listener.php and $extra_info is being sent.
[22] Fix | Delete
// Here we assign the current blog_id to a variable $blog_id
[23] Fix | Delete
$blog_id = get_current_blog_id();
[24] Fix | Delete
if (!empty($data['site_id'])) $blog_id = $data['site_id'];
[25] Fix | Delete
[26] Fix | Delete
if (function_exists('switch_to_blog') && is_multisite() && $blog_id) {
[27] Fix | Delete
$this->switched = switch_to_blog($blog_id);
[28] Fix | Delete
}
[29] Fix | Delete
}
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* Function that gets called after every action
[33] Fix | Delete
*
[34] Fix | Delete
* @param string $command a string that corresponds to UDC command to call a certain method for this class.
[35] Fix | Delete
* @param array $data an array of data post or get fields
[36] Fix | Delete
* @param array $extra_info extrainfo use in the udrpc_action, e.g. user_id
[37] Fix | Delete
*
[38] Fix | Delete
* link to udrpc_action main function in class UpdraftCentral_Listener
[39] Fix | Delete
*/
[40] Fix | Delete
public function _post_action($command, $data, $extra_info) {// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
[41] Fix | Delete
// Here, we're restoring to the current (default) blog before we switched
[42] Fix | Delete
if ($this->switched) restore_current_blog();
[43] Fix | Delete
}
[44] Fix | Delete
[45] Fix | Delete
/**
[46] Fix | Delete
* Returns the keys and fields names that are associated to a particular module type
[47] Fix | Delete
*
[48] Fix | Delete
* @param string $type The type of the module that the current request is processing
[49] Fix | Delete
*
[50] Fix | Delete
* @return array
[51] Fix | Delete
*/
[52] Fix | Delete
private function get_state_fields_by_type($type) {
[53] Fix | Delete
$state_fields = array(
[54] Fix | Delete
'post' => array(
[55] Fix | Delete
'validation_fields' => array('publish_posts', 'edit_posts', 'delete_posts'),
[56] Fix | Delete
'items_key' => 'posts',
[57] Fix | Delete
'count_key' => 'posts_count',
[58] Fix | Delete
'list_key' => 'posts',
[59] Fix | Delete
'result_key' => 'get',
[60] Fix | Delete
'error_key' => 'post_state_change_failed'
[61] Fix | Delete
),
[62] Fix | Delete
'page' => array(
[63] Fix | Delete
'validation_fields' => array('publish_pages', 'edit_pages', 'delete_pages'),
[64] Fix | Delete
'items_key' => 'pages',
[65] Fix | Delete
'count_key' => 'pages_count',
[66] Fix | Delete
'list_key' => 'pages',
[67] Fix | Delete
'result_key' => 'get',
[68] Fix | Delete
'error_key' => 'page_state_change_failed'
[69] Fix | Delete
)
[70] Fix | Delete
);
[71] Fix | Delete
[72] Fix | Delete
if (!isset($state_fields[$type])) return array();
[73] Fix | Delete
return $state_fields[$type];
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
/**
[77] Fix | Delete
* Fetch and retrieves posts based from the submitted parameters
[78] Fix | Delete
*
[79] Fix | Delete
* @param array $params Containing all the needed information to filter the results of the current request
[80] Fix | Delete
* @return array
[81] Fix | Delete
*/
[82] Fix | Delete
public function get($params) {
[83] Fix | Delete
[84] Fix | Delete
$state_fields = $this->get_state_fields_by_type($this->post_type);
[85] Fix | Delete
if (empty($state_fields)) return $this->_generic_error_response('unsupported_type_on_get_posts');
[86] Fix | Delete
[87] Fix | Delete
$error = $this->_validate_capabilities($state_fields['validation_fields']);
[88] Fix | Delete
if (!empty($error)) return $error;
[89] Fix | Delete
[90] Fix | Delete
// check paged parameter; if empty set to defaults
[91] Fix | Delete
$paged = !empty($params['paged']) ? (int) $params['paged'] : 1;
[92] Fix | Delete
$numberposts = !empty($params['numberposts']) ? (int) $params['numberposts'] : 10;
[93] Fix | Delete
$offset = ($paged - 1) * $numberposts;
[94] Fix | Delete
[95] Fix | Delete
$args = array(
[96] Fix | Delete
'posts_per_page' => $numberposts,
[97] Fix | Delete
'paged' => $paged,
[98] Fix | Delete
'offset' => $offset,
[99] Fix | Delete
'post_type' => $this->post_type,
[100] Fix | Delete
'post_status' => 'publish,private,draft,pending,future',
[101] Fix | Delete
);
[102] Fix | Delete
[103] Fix | Delete
if (!empty($params['keyword'])) {
[104] Fix | Delete
$args['s'] = $params['keyword'];
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
if ('post' == $this->post_type) {
[108] Fix | Delete
if (!empty($params['category'])) {
[109] Fix | Delete
$args['cat'] = (int) $params['category'];
[110] Fix | Delete
}
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
if (!empty($params['date'])) {
[114] Fix | Delete
list($monthnum, $year) = explode(':', $params['date']);
[115] Fix | Delete
[116] Fix | Delete
$args['monthnum'] = $monthnum;
[117] Fix | Delete
$args['year'] = $year;
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
if (!empty($params['status']) && 'all' !== $params['status']) {
[121] Fix | Delete
$args['post_status'] = $params['status'];
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
$query = new WP_Query($args);
[125] Fix | Delete
$result = $query->posts;
[126] Fix | Delete
[127] Fix | Delete
$count_posts = (int) $query->found_posts;
[128] Fix | Delete
$page_count = 0;
[129] Fix | Delete
[130] Fix | Delete
if ($count_posts > 0) {
[131] Fix | Delete
$page_count = absint($count_posts / $numberposts);
[132] Fix | Delete
$remainder = absint($count_posts % $numberposts);
[133] Fix | Delete
$page_count = ($remainder > 0) ? ++$page_count : $page_count;
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
$info = array(
[137] Fix | Delete
'page' => $paged,
[138] Fix | Delete
'pages' => $page_count,
[139] Fix | Delete
'results' => $count_posts,
[140] Fix | Delete
'items_from' => (($paged * $numberposts) - $numberposts) + 1,
[141] Fix | Delete
'items_to' => ($paged == $page_count) ? $count_posts : $paged * $numberposts,
[142] Fix | Delete
);
[143] Fix | Delete
[144] Fix | Delete
$posts = array();
[145] Fix | Delete
if (!empty($result)) {
[146] Fix | Delete
foreach ($result as $post) {
[147] Fix | Delete
// Pulling any other relevant and additional information regarding
[148] Fix | Delete
// the post before returning it in the response.
[149] Fix | Delete
$postdata = $this->get_postdata($post, false);
[150] Fix | Delete
if (!empty($postdata)) {
[151] Fix | Delete
array_push($posts, $postdata);
[152] Fix | Delete
}
[153] Fix | Delete
}
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
$response = array(
[157] Fix | Delete
$state_fields['items_key'] => $posts,
[158] Fix | Delete
'options' => $this->get_options($this->post_type),
[159] Fix | Delete
'info' => $info,
[160] Fix | Delete
$state_fields['count_key'] => $this->get_post_status_counts($this->post_type)
[161] Fix | Delete
);
[162] Fix | Delete
[163] Fix | Delete
// Load any additional information if preload parameter is set. Will only be
[164] Fix | Delete
// requested on initial load of items in UpdraftCentral.
[165] Fix | Delete
if (isset($params['preload']) && $params['preload']) {
[166] Fix | Delete
$timeout = !empty($params['timeout']) ? $params['timeout'] : 30;
[167] Fix | Delete
$response = array_merge($response, $this->get_preload_data($timeout, $this->post_type));
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
return $this->_response($response);
[171] Fix | Delete
}
[172] Fix | Delete
[173] Fix | Delete
/**
[174] Fix | Delete
* Extracts public properties from complex object and return a simple
[175] Fix | Delete
* object (stdClass) that contains the public properties of the original object.
[176] Fix | Delete
*
[177] Fix | Delete
* @param object $obj Any type of complex objects that needs converting (e.g. WP_Taxonomy, WP_Term or WP_User)
[178] Fix | Delete
* @return stdClass
[179] Fix | Delete
*/
[180] Fix | Delete
protected function trim_object($obj) {
[181] Fix | Delete
// To preserve the object's accessibility through its properties we recreate
[182] Fix | Delete
// the object using the stdClass and fill it with the public properties
[183] Fix | Delete
// that will be extracted from the original object ($obj).
[184] Fix | Delete
$newObj = new stdClass();
[185] Fix | Delete
[186] Fix | Delete
if (is_object($obj)) {
[187] Fix | Delete
// Making sure that we only extract those publicly accessible properties excluding
[188] Fix | Delete
// the private, protected, static ones and methods.
[189] Fix | Delete
$props = get_object_vars($obj);
[190] Fix | Delete
if (!empty($props)) {
[191] Fix | Delete
foreach ($props as $key => $value) {
[192] Fix | Delete
$newObj->{$key} = $value;
[193] Fix | Delete
}
[194] Fix | Delete
}
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
return $newObj;
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
/**
[201] Fix | Delete
* Retrieves information that will be preloaded in UC for quick and easy access
[202] Fix | Delete
* when editing a certain page or post
[203] Fix | Delete
*
[204] Fix | Delete
* @param int $timeout The user-defined timeout from UpdraftCentral
[205] Fix | Delete
* @param string $type The type of the module that the current request is processing
[206] Fix | Delete
*
[207] Fix | Delete
* @return array
[208] Fix | Delete
*/
[209] Fix | Delete
protected function get_preload_data($timeout, $type = 'post') {
[210] Fix | Delete
global $updraftcentral_host_plugin, $updraftcentral_main;
[211] Fix | Delete
[212] Fix | Delete
if (!function_exists('get_page_templates')) {
[213] Fix | Delete
require_once(ABSPATH.'wp-admin/includes/theme.php');
[214] Fix | Delete
}
[215] Fix | Delete
[216] Fix | Delete
$templates = ('post' == $type) ? get_page_templates(null, 'post') : get_page_templates();
[217] Fix | Delete
if (!empty($templates)) {
[218] Fix | Delete
$templates = array_flip($templates);
[219] Fix | Delete
if (!isset($templates['default'])) {
[220] Fix | Delete
$templates['default'] = $updraftcentral_host_plugin->retrieve_show_message('default_template');
[221] Fix | Delete
}
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
// Preloading elements saves time and avoid unnecessary round trips to fetch
[225] Fix | Delete
// these information individually.
[226] Fix | Delete
$authors = $this->get_authors();
[227] Fix | Delete
$parent_pages = $this->get_parent_pages();
[228] Fix | Delete
[229] Fix | Delete
$data = array(
[230] Fix | Delete
'authors' => $authors['data']['authors'],
[231] Fix | Delete
'parent_pages' => $parent_pages['data']['pages'],
[232] Fix | Delete
'templates' => $templates,
[233] Fix | Delete
'editor_styles' => $this->get_editor_styles($timeout),
[234] Fix | Delete
'wp_version' => $updraftcentral_main->get_wordpress_version()
[235] Fix | Delete
);
[236] Fix | Delete
[237] Fix | Delete
if ('post' == $type) {
[238] Fix | Delete
$categories = $this->get_categories();
[239] Fix | Delete
$tags = $this->get_tags();
[240] Fix | Delete
[241] Fix | Delete
$data['taxonomies'] = $this->get_taxonomies();
[242] Fix | Delete
$data['categories'] = $categories['data'];
[243] Fix | Delete
$data['tags'] = $tags['data'];
[244] Fix | Delete
}
[245] Fix | Delete
[246] Fix | Delete
return array(
[247] Fix | Delete
'preloaded' => json_encode($data)
[248] Fix | Delete
);
[249] Fix | Delete
}
[250] Fix | Delete
[251] Fix | Delete
/**
[252] Fix | Delete
* Extract content from the given css path
[253] Fix | Delete
*
[254] Fix | Delete
* @param string $style CSS file path
[255] Fix | Delete
* @param int $timeout The user-defined timeout from UpdraftCentral
[256] Fix | Delete
* @return string
[257] Fix | Delete
*/
[258] Fix | Delete
protected function extract_css_content($style, $timeout) {
[259] Fix | Delete
[260] Fix | Delete
$content = '';
[261] Fix | Delete
if (1 === preg_match('~^(https?:)?//~i', $style)) {
[262] Fix | Delete
$response = wp_remote_get($style, array('timeout' => $timeout));
[263] Fix | Delete
if (!is_wp_error($response)) {
[264] Fix | Delete
$result = trim(wp_remote_retrieve_body($response));
[265] Fix | Delete
if (!empty($result)) $content = $result;
[266] Fix | Delete
}
[267] Fix | Delete
} else {
[268] Fix | Delete
// Editor styles that resides in "css/dist"
[269] Fix | Delete
if (false !== ($pos = stripos($style, 'css/dist'))) {
[270] Fix | Delete
$file = ABSPATH.WPINC.substr_replace($style, '/', 0, $pos);
[271] Fix | Delete
} else {
[272] Fix | Delete
// Styles that resides in "wp-content/themes" (coming from $editor_styles global var)
[273] Fix | Delete
$file = get_theme_file_path($style);
[274] Fix | Delete
}
[275] Fix | Delete
[276] Fix | Delete
$is_valid = (function_exists('is_file')) ? is_file($file) : file_exists($file);
[277] Fix | Delete
if ($is_valid) {
[278] Fix | Delete
$result = trim(file_get_contents($file));
[279] Fix | Delete
if (!empty($result)) $content = $result;
[280] Fix | Delete
}
[281] Fix | Delete
}
[282] Fix | Delete
[283] Fix | Delete
return $this->filter_url($content);
[284] Fix | Delete
}
[285] Fix | Delete
[286] Fix | Delete
/**
[287] Fix | Delete
* Convert URL entries contained in the CSS content to absolute URLs
[288] Fix | Delete
*
[289] Fix | Delete
* @param string $content The content of the CSS file
[290] Fix | Delete
* @return string
[291] Fix | Delete
*/
[292] Fix | Delete
protected function filter_url($content) {
[293] Fix | Delete
[294] Fix | Delete
// Replace with valid URL (absolute)
[295] Fix | Delete
preg_match_all('~url\((.+?)\)~i', $content, $all_matches);
[296] Fix | Delete
if (!empty($all_matches) && isset($all_matches[1])) {
[297] Fix | Delete
$urls = array_unique($all_matches[1]);
[298] Fix | Delete
foreach ($urls as $url) {
[299] Fix | Delete
$url = str_replace('"', '', $url);
[300] Fix | Delete
if (false !== strpos($url, 'data:')) continue;
[301] Fix | Delete
[302] Fix | Delete
if (1 !== preg_match('~^(https?:)?//~i', $url)) {
[303] Fix | Delete
if (1 === preg_match('~(plugins|themes)~i', $url, $matches)) {
[304] Fix | Delete
if (false !== ($pos = stripos($url, $matches[1]))) {
[305] Fix | Delete
if (!function_exists('content_url')) {
[306] Fix | Delete
require_once ABSPATH.WPINC.'/link-template.php';
[307] Fix | Delete
}
[308] Fix | Delete
[309] Fix | Delete
$absolute_url = rtrim(content_url(), '/').substr_replace($url, '/', 0, $pos);
[310] Fix | Delete
$content = str_replace($url, $absolute_url, $content);
[311] Fix | Delete
}
[312] Fix | Delete
} else {
[313] Fix | Delete
$path = preg_replace('~(\.+\/)~', '', $url);
[314] Fix | Delete
$dirpath = trailingslashit(get_stylesheet_directory());
[315] Fix | Delete
if (!file_exists($dirpath.$url)) $path = $this->resolve_path($path);
[316] Fix | Delete
[317] Fix | Delete
$absolute_url = (!empty($path)) ? trailingslashit(get_stylesheet_directory_uri()).ltrim($path, '/') : '';
[318] Fix | Delete
$content = str_replace($url, $absolute_url, $content);
[319] Fix | Delete
}
[320] Fix | Delete
}
[321] Fix | Delete
}
[322] Fix | Delete
}
[323] Fix | Delete
[324] Fix | Delete
return $content;
[325] Fix | Delete
}
[326] Fix | Delete
[327] Fix | Delete
/**
[328] Fix | Delete
* Resolve URL to its actual absolute path
[329] Fix | Delete
*
[330] Fix | Delete
* @param string $path Some relative path to check
[331] Fix | Delete
* @return string
[332] Fix | Delete
*/
[333] Fix | Delete
protected function resolve_path($path) {
[334] Fix | Delete
$dir = trailingslashit(get_stylesheet_directory());
[335] Fix | Delete
// Some relative paths declared within the css file (e.g. only has '../fonts/etc/', called deep down from a subfolder) where parent
[336] Fix | Delete
// subfolder is not articulated needs to be resolve further to get its actual absolute path. Using glob will pinpoint its actual location
[337] Fix | Delete
// rather than iterating through a series of sublevels just to find the actual file.
[338] Fix | Delete
$result = str_replace($dir, '', glob($dir.'{,*/}{'.$path.'}', GLOB_BRACE));
[339] Fix | Delete
[340] Fix | Delete
if (!empty($result)) return $result[0];
[341] Fix | Delete
return false;
[342] Fix | Delete
}
[343] Fix | Delete
[344] Fix | Delete
/**
[345] Fix | Delete
* Retrieve the editor styles/assets to be use by UpdraftCentral when editing a post
[346] Fix | Delete
*
[347] Fix | Delete
* @param int $timeout The user-defined timeout from UpdraftCentral
[348] Fix | Delete
* @return array()
[349] Fix | Delete
*/
[350] Fix | Delete
protected function get_editor_styles($timeout) {
[351] Fix | Delete
global $editor_styles, $wp_styles;
[352] Fix | Delete
$editing_styles = $loaded = array();
[353] Fix | Delete
[354] Fix | Delete
$required = array('css/dist/editor/style.css', 'css/dist/block-library/style.css', 'css/dist/block-library/theme.css');
[355] Fix | Delete
foreach ($required as $style) {
[356] Fix | Delete
$editing_styles[] = array('css' => $this->extract_css_content($style, $timeout), 'inline' => '');
[357] Fix | Delete
};
[358] Fix | Delete
[359] Fix | Delete
do_action('enqueue_block_editor_assets');
[360] Fix | Delete
do_action('enqueue_block_assets');
[361] Fix | Delete
[362] Fix | Delete
// Checking for editor styles support since styles make vary from theme to theme
[363] Fix | Delete
if ($editor_styles) {
[364] Fix | Delete
foreach ($editor_styles as $style) {
[365] Fix | Delete
if (false !== array_search($style, $loaded)) continue;
[366] Fix | Delete
[367] Fix | Delete
$editing_styles[] = array('css' => $this->extract_css_content($style, $timeout), 'inline' => '');
[368] Fix | Delete
$loaded[] = $style;
[369] Fix | Delete
}
[370] Fix | Delete
}
[371] Fix | Delete
[372] Fix | Delete
if ($wp_styles) {
[373] Fix | Delete
foreach ($wp_styles->queue as $handle) {
[374] Fix | Delete
$style = $wp_styles->registered[$handle]->src;
[375] Fix | Delete
if (false !== array_search($style, $loaded)) continue;
[376] Fix | Delete
[377] Fix | Delete
$inline = $wp_styles->print_inline_style($handle, false);
[378] Fix | Delete
$editing_styles[] = array(
[379] Fix | Delete
'css' => $this->extract_css_content($style, $timeout),
[380] Fix | Delete
'inline' => (!$inline) ? '' : $inline
[381] Fix | Delete
);
[382] Fix | Delete
$loaded[] = $style;
[383] Fix | Delete
}
[384] Fix | Delete
}
[385] Fix | Delete
[386] Fix | Delete
$editing_styles[] = array('css' => $this->extract_css_content('/style.css', $timeout), 'inline' => '');
[387] Fix | Delete
return $editing_styles;
[388] Fix | Delete
}
[389] Fix | Delete
[390] Fix | Delete
/**
[391] Fix | Delete
* Retrieves the total number of items found under each post statuses
[392] Fix | Delete
*
[393] Fix | Delete
* @param string $type The type of the module that the current request is processing
[394] Fix | Delete
*
[395] Fix | Delete
* @return array
[396] Fix | Delete
*/
[397] Fix | Delete
protected function get_post_status_counts($type = 'post') {
[398] Fix | Delete
$posts = wp_count_posts($type);
[399] Fix | Delete
[400] Fix | Delete
$publish = (int) $posts->publish;
[401] Fix | Delete
$private = (int) $posts->private;
[402] Fix | Delete
$draft = (int) $posts->draft;
[403] Fix | Delete
$pending = (int) $posts->pending;
[404] Fix | Delete
$future = (int) $posts->future;
[405] Fix | Delete
$trash = (int) $posts->trash;
[406] Fix | Delete
[407] Fix | Delete
// We exclude "trash" from the overall total as WP doesn't actually
[408] Fix | Delete
// consider or include it in the total count.
[409] Fix | Delete
$all = $publish + $private + $draft + $pending + $future;
[410] Fix | Delete
[411] Fix | Delete
return array(
[412] Fix | Delete
'all' => $all,
[413] Fix | Delete
'publish' => $publish,
[414] Fix | Delete
'private' => $private,
[415] Fix | Delete
'draft' => $draft,
[416] Fix | Delete
'pending' => $pending,
[417] Fix | Delete
'future' => $future,
[418] Fix | Delete
'trash' => $trash,
[419] Fix | Delete
);
[420] Fix | Delete
}
[421] Fix | Delete
[422] Fix | Delete
/**
[423] Fix | Delete
* Retrieves a collection of formatted dates found for the given post statuses.
[424] Fix | Delete
* It will be used as options for the date filter when managing the posts in UpdraftCentral.
[425] Fix | Delete
*
[426] Fix | Delete
* @param string $type The type of the module that the current request is processing
[427] Fix | Delete
*
[428] Fix | Delete
* @return array
[429] Fix | Delete
*/
[430] Fix | Delete
protected function get_date_options($type = 'post') {
[431] Fix | Delete
global $wpdb;
[432] Fix | Delete
[433] Fix | Delete
$date_options = $wpdb->get_col("SELECT DATE_FORMAT(`post_date`, '%M %Y') as `formatted_post_date` FROM {$wpdb->posts} WHERE `post_type` = '{$type}' AND `post_status` IN ('publish', 'private', 'draft', 'pending', 'future') GROUP BY `formatted_post_date` ORDER BY `post_date` DESC");
[434] Fix | Delete
[435] Fix | Delete
return $date_options;
[436] Fix | Delete
}
[437] Fix | Delete
[438] Fix | Delete
/**
[439] Fix | Delete
* Make sure that we have the required fields to use in UpdraftCentral for
[440] Fix | Delete
* displaying the categories and tags sections. Add if missing.
[441] Fix | Delete
*
[442] Fix | Delete
* @param object $item Taxonomy item to check
[443] Fix | Delete
* @return object
[444] Fix | Delete
*/
[445] Fix | Delete
protected function map_tax($item) {
[446] Fix | Delete
$taxs = array('category' => 'categories', 'post_tag' => 'tags');
[447] Fix | Delete
if (array_key_exists($item->name, $taxs)) {
[448] Fix | Delete
if (!isset($item->show_in_rest)) $item->show_in_rest = true;
[449] Fix | Delete
if (!isset($item->rest_base)) $item->rest_base = $taxs[$item->name];
[450] Fix | Delete
}
[451] Fix | Delete
[452] Fix | Delete
return $item;
[453] Fix | Delete
}
[454] Fix | Delete
[455] Fix | Delete
/**
[456] Fix | Delete
* Fetch and retrieves available taxonomies for this site and some capabilities specific
[457] Fix | Delete
* to tags and categories when managing them.
[458] Fix | Delete
*
[459] Fix | Delete
* @return array
[460] Fix | Delete
*/
[461] Fix | Delete
protected function get_taxonomies() {
[462] Fix | Delete
$taxonomies = get_taxonomies(array(), 'objects');
[463] Fix | Delete
$taxonomies = array_map(array($this, 'map_tax'), $taxonomies);
[464] Fix | Delete
[465] Fix | Delete
$response = array(
[466] Fix | Delete
'taxonomies' => $taxonomies,
[467] Fix | Delete
'current_user_cap' => array(
[468] Fix | Delete
'manage_categories' => current_user_can('manage_categories'),
[469] Fix | Delete
'edit_categories' => current_user_can('edit_categories'),
[470] Fix | Delete
'delete_categories' => current_user_can('delete_categories'),
[471] Fix | Delete
'assign_categories' => current_user_can('assign_categories'),
[472] Fix | Delete
'manage_post_tags' => current_user_can('manage_post_tags'),
[473] Fix | Delete
'edit_post_tags' => current_user_can('edit_post_tags'),
[474] Fix | Delete
'delete_post_tags' => current_user_can('delete_post_tags'),
[475] Fix | Delete
'assign_post_tags' => current_user_can('assign_post_tags'),
[476] Fix | Delete
)
[477] Fix | Delete
);
[478] Fix | Delete
[479] Fix | Delete
return $response;
[480] Fix | Delete
}
[481] Fix | Delete
[482] Fix | Delete
/**
[483] Fix | Delete
* Fetch and retrieves categories based from the submitted parameters
[484] Fix | Delete
*
[485] Fix | Delete
* @param array $query Containing all the needed information to filter the results of the current request
[486] Fix | Delete
* @return array
[487] Fix | Delete
*/
[488] Fix | Delete
public function get_categories($query = array()) {
[489] Fix | Delete
$page = !empty($query['page']) ? (int) $query['page'] : 1;
[490] Fix | Delete
$items_per_page = !empty($query['per_page']) ? (int) $query['per_page'] : 100;
[491] Fix | Delete
$offset = ($page - 1) * $items_per_page;
[492] Fix | Delete
$order = !empty($query['order']) ? $query['order'] : 'asc';
[493] Fix | Delete
$orderby = !empty($query['orderby']) ? $query['orderby'] : 'name';
[494] Fix | Delete
[495] Fix | Delete
$args = array(
[496] Fix | Delete
'hide_empty' => false,
[497] Fix | Delete
'orderby' => $orderby,
[498] Fix | Delete
'order' => $order,
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function