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

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/clone/wp-inclu...
File: class-wp-xmlrpc-server.php
*
[1000] Fix | Delete
* @since 3.4.0
[1001] Fix | Delete
* @since 4.6.0 Converted the `$post_type` parameter to accept a WP_Post_Type object.
[1002] Fix | Delete
*
[1003] Fix | Delete
* @param WP_Post_Type $post_type Post type object.
[1004] Fix | Delete
* @param array $fields The subset of post fields to return.
[1005] Fix | Delete
* @return array The prepared post type data.
[1006] Fix | Delete
*/
[1007] Fix | Delete
protected function _prepare_post_type( $post_type, $fields ) {
[1008] Fix | Delete
$_post_type = array(
[1009] Fix | Delete
'name' => $post_type->name,
[1010] Fix | Delete
'label' => $post_type->label,
[1011] Fix | Delete
'hierarchical' => (bool) $post_type->hierarchical,
[1012] Fix | Delete
'public' => (bool) $post_type->public,
[1013] Fix | Delete
'show_ui' => (bool) $post_type->show_ui,
[1014] Fix | Delete
'_builtin' => (bool) $post_type->_builtin,
[1015] Fix | Delete
'has_archive' => (bool) $post_type->has_archive,
[1016] Fix | Delete
'supports' => get_all_post_type_supports( $post_type->name ),
[1017] Fix | Delete
);
[1018] Fix | Delete
[1019] Fix | Delete
if ( in_array( 'labels', $fields, true ) ) {
[1020] Fix | Delete
$_post_type['labels'] = (array) $post_type->labels;
[1021] Fix | Delete
}
[1022] Fix | Delete
[1023] Fix | Delete
if ( in_array( 'cap', $fields, true ) ) {
[1024] Fix | Delete
$_post_type['cap'] = (array) $post_type->cap;
[1025] Fix | Delete
$_post_type['map_meta_cap'] = (bool) $post_type->map_meta_cap;
[1026] Fix | Delete
}
[1027] Fix | Delete
[1028] Fix | Delete
if ( in_array( 'menu', $fields, true ) ) {
[1029] Fix | Delete
$_post_type['menu_position'] = (int) $post_type->menu_position;
[1030] Fix | Delete
$_post_type['menu_icon'] = $post_type->menu_icon;
[1031] Fix | Delete
$_post_type['show_in_menu'] = (bool) $post_type->show_in_menu;
[1032] Fix | Delete
}
[1033] Fix | Delete
[1034] Fix | Delete
if ( in_array( 'taxonomies', $fields, true ) ) {
[1035] Fix | Delete
$_post_type['taxonomies'] = get_object_taxonomies( $post_type->name, 'names' );
[1036] Fix | Delete
}
[1037] Fix | Delete
[1038] Fix | Delete
/**
[1039] Fix | Delete
* Filters XML-RPC-prepared date for the given post type.
[1040] Fix | Delete
*
[1041] Fix | Delete
* @since 3.4.0
[1042] Fix | Delete
* @since 4.6.0 Converted the `$post_type` parameter to accept a WP_Post_Type object.
[1043] Fix | Delete
*
[1044] Fix | Delete
* @param array $_post_type An array of post type data.
[1045] Fix | Delete
* @param WP_Post_Type $post_type Post type object.
[1046] Fix | Delete
*/
[1047] Fix | Delete
return apply_filters( 'xmlrpc_prepare_post_type', $_post_type, $post_type );
[1048] Fix | Delete
}
[1049] Fix | Delete
[1050] Fix | Delete
/**
[1051] Fix | Delete
* Prepares media item data for return in an XML-RPC object.
[1052] Fix | Delete
*
[1053] Fix | Delete
* @param WP_Post $media_item The unprepared media item data.
[1054] Fix | Delete
* @param string $thumbnail_size The image size to use for the thumbnail URL.
[1055] Fix | Delete
* @return array The prepared media item data.
[1056] Fix | Delete
*/
[1057] Fix | Delete
protected function _prepare_media_item( $media_item, $thumbnail_size = 'thumbnail' ) {
[1058] Fix | Delete
$_media_item = array(
[1059] Fix | Delete
'attachment_id' => (string) $media_item->ID,
[1060] Fix | Delete
'date_created_gmt' => $this->_convert_date_gmt( $media_item->post_date_gmt, $media_item->post_date ),
[1061] Fix | Delete
'parent' => $media_item->post_parent,
[1062] Fix | Delete
'link' => wp_get_attachment_url( $media_item->ID ),
[1063] Fix | Delete
'title' => $media_item->post_title,
[1064] Fix | Delete
'caption' => $media_item->post_excerpt,
[1065] Fix | Delete
'description' => $media_item->post_content,
[1066] Fix | Delete
'metadata' => wp_get_attachment_metadata( $media_item->ID ),
[1067] Fix | Delete
'type' => $media_item->post_mime_type,
[1068] Fix | Delete
'alt' => get_post_meta( $media_item->ID, '_wp_attachment_image_alt', true ),
[1069] Fix | Delete
);
[1070] Fix | Delete
[1071] Fix | Delete
$thumbnail_src = image_downsize( $media_item->ID, $thumbnail_size );
[1072] Fix | Delete
if ( $thumbnail_src ) {
[1073] Fix | Delete
$_media_item['thumbnail'] = $thumbnail_src[0];
[1074] Fix | Delete
} else {
[1075] Fix | Delete
$_media_item['thumbnail'] = $_media_item['link'];
[1076] Fix | Delete
}
[1077] Fix | Delete
[1078] Fix | Delete
/**
[1079] Fix | Delete
* Filters XML-RPC-prepared data for the given media item.
[1080] Fix | Delete
*
[1081] Fix | Delete
* @since 3.4.0
[1082] Fix | Delete
*
[1083] Fix | Delete
* @param array $_media_item An array of media item data.
[1084] Fix | Delete
* @param WP_Post $media_item Media item object.
[1085] Fix | Delete
* @param string $thumbnail_size Image size.
[1086] Fix | Delete
*/
[1087] Fix | Delete
return apply_filters( 'xmlrpc_prepare_media_item', $_media_item, $media_item, $thumbnail_size );
[1088] Fix | Delete
}
[1089] Fix | Delete
[1090] Fix | Delete
/**
[1091] Fix | Delete
* Prepares page data for return in an XML-RPC object.
[1092] Fix | Delete
*
[1093] Fix | Delete
* @param WP_Post $page The unprepared page data.
[1094] Fix | Delete
* @return array The prepared page data.
[1095] Fix | Delete
*/
[1096] Fix | Delete
protected function _prepare_page( $page ) {
[1097] Fix | Delete
// Get all of the page content and link.
[1098] Fix | Delete
$full_page = get_extended( $page->post_content );
[1099] Fix | Delete
$link = get_permalink( $page->ID );
[1100] Fix | Delete
[1101] Fix | Delete
// Get info the page parent if there is one.
[1102] Fix | Delete
$parent_title = '';
[1103] Fix | Delete
if ( ! empty( $page->post_parent ) ) {
[1104] Fix | Delete
$parent = get_post( $page->post_parent );
[1105] Fix | Delete
$parent_title = $parent->post_title;
[1106] Fix | Delete
}
[1107] Fix | Delete
[1108] Fix | Delete
// Determine comment and ping settings.
[1109] Fix | Delete
$allow_comments = comments_open( $page->ID ) ? 1 : 0;
[1110] Fix | Delete
$allow_pings = pings_open( $page->ID ) ? 1 : 0;
[1111] Fix | Delete
[1112] Fix | Delete
// Format page date.
[1113] Fix | Delete
$page_date = $this->_convert_date( $page->post_date );
[1114] Fix | Delete
$page_date_gmt = $this->_convert_date_gmt( $page->post_date_gmt, $page->post_date );
[1115] Fix | Delete
[1116] Fix | Delete
// Pull the categories info together.
[1117] Fix | Delete
$categories = array();
[1118] Fix | Delete
if ( is_object_in_taxonomy( 'page', 'category' ) ) {
[1119] Fix | Delete
foreach ( wp_get_post_categories( $page->ID ) as $cat_id ) {
[1120] Fix | Delete
$categories[] = get_cat_name( $cat_id );
[1121] Fix | Delete
}
[1122] Fix | Delete
}
[1123] Fix | Delete
[1124] Fix | Delete
// Get the author info.
[1125] Fix | Delete
$author = get_userdata( $page->post_author );
[1126] Fix | Delete
[1127] Fix | Delete
$page_template = get_page_template_slug( $page->ID );
[1128] Fix | Delete
if ( empty( $page_template ) ) {
[1129] Fix | Delete
$page_template = 'default';
[1130] Fix | Delete
}
[1131] Fix | Delete
[1132] Fix | Delete
$_page = array(
[1133] Fix | Delete
'dateCreated' => $page_date,
[1134] Fix | Delete
'userid' => $page->post_author,
[1135] Fix | Delete
'page_id' => $page->ID,
[1136] Fix | Delete
'page_status' => $page->post_status,
[1137] Fix | Delete
'description' => $full_page['main'],
[1138] Fix | Delete
'title' => $page->post_title,
[1139] Fix | Delete
'link' => $link,
[1140] Fix | Delete
'permaLink' => $link,
[1141] Fix | Delete
'categories' => $categories,
[1142] Fix | Delete
'excerpt' => $page->post_excerpt,
[1143] Fix | Delete
'text_more' => $full_page['extended'],
[1144] Fix | Delete
'mt_allow_comments' => $allow_comments,
[1145] Fix | Delete
'mt_allow_pings' => $allow_pings,
[1146] Fix | Delete
'wp_slug' => $page->post_name,
[1147] Fix | Delete
'wp_password' => $page->post_password,
[1148] Fix | Delete
'wp_author' => $author->display_name,
[1149] Fix | Delete
'wp_page_parent_id' => $page->post_parent,
[1150] Fix | Delete
'wp_page_parent_title' => $parent_title,
[1151] Fix | Delete
'wp_page_order' => $page->menu_order,
[1152] Fix | Delete
'wp_author_id' => (string) $author->ID,
[1153] Fix | Delete
'wp_author_display_name' => $author->display_name,
[1154] Fix | Delete
'date_created_gmt' => $page_date_gmt,
[1155] Fix | Delete
'custom_fields' => $this->get_custom_fields( $page->ID ),
[1156] Fix | Delete
'wp_page_template' => $page_template,
[1157] Fix | Delete
);
[1158] Fix | Delete
[1159] Fix | Delete
/**
[1160] Fix | Delete
* Filters XML-RPC-prepared data for the given page.
[1161] Fix | Delete
*
[1162] Fix | Delete
* @since 3.4.0
[1163] Fix | Delete
*
[1164] Fix | Delete
* @param array $_page An array of page data.
[1165] Fix | Delete
* @param WP_Post $page Page object.
[1166] Fix | Delete
*/
[1167] Fix | Delete
return apply_filters( 'xmlrpc_prepare_page', $_page, $page );
[1168] Fix | Delete
}
[1169] Fix | Delete
[1170] Fix | Delete
/**
[1171] Fix | Delete
* Prepares comment data for return in an XML-RPC object.
[1172] Fix | Delete
*
[1173] Fix | Delete
* @param WP_Comment $comment The unprepared comment data.
[1174] Fix | Delete
* @return array The prepared comment data.
[1175] Fix | Delete
*/
[1176] Fix | Delete
protected function _prepare_comment( $comment ) {
[1177] Fix | Delete
// Format page date.
[1178] Fix | Delete
$comment_date_gmt = $this->_convert_date_gmt( $comment->comment_date_gmt, $comment->comment_date );
[1179] Fix | Delete
[1180] Fix | Delete
if ( '0' == $comment->comment_approved ) {
[1181] Fix | Delete
$comment_status = 'hold';
[1182] Fix | Delete
} elseif ( 'spam' === $comment->comment_approved ) {
[1183] Fix | Delete
$comment_status = 'spam';
[1184] Fix | Delete
} elseif ( '1' == $comment->comment_approved ) {
[1185] Fix | Delete
$comment_status = 'approve';
[1186] Fix | Delete
} else {
[1187] Fix | Delete
$comment_status = $comment->comment_approved;
[1188] Fix | Delete
}
[1189] Fix | Delete
$_comment = array(
[1190] Fix | Delete
'date_created_gmt' => $comment_date_gmt,
[1191] Fix | Delete
'user_id' => $comment->user_id,
[1192] Fix | Delete
'comment_id' => $comment->comment_ID,
[1193] Fix | Delete
'parent' => $comment->comment_parent,
[1194] Fix | Delete
'status' => $comment_status,
[1195] Fix | Delete
'content' => $comment->comment_content,
[1196] Fix | Delete
'link' => get_comment_link( $comment ),
[1197] Fix | Delete
'post_id' => $comment->comment_post_ID,
[1198] Fix | Delete
'post_title' => get_the_title( $comment->comment_post_ID ),
[1199] Fix | Delete
'author' => $comment->comment_author,
[1200] Fix | Delete
'author_url' => $comment->comment_author_url,
[1201] Fix | Delete
'author_email' => $comment->comment_author_email,
[1202] Fix | Delete
'author_ip' => $comment->comment_author_IP,
[1203] Fix | Delete
'type' => $comment->comment_type,
[1204] Fix | Delete
);
[1205] Fix | Delete
[1206] Fix | Delete
/**
[1207] Fix | Delete
* Filters XML-RPC-prepared data for the given comment.
[1208] Fix | Delete
*
[1209] Fix | Delete
* @since 3.4.0
[1210] Fix | Delete
*
[1211] Fix | Delete
* @param array $_comment An array of prepared comment data.
[1212] Fix | Delete
* @param WP_Comment $comment Comment object.
[1213] Fix | Delete
*/
[1214] Fix | Delete
return apply_filters( 'xmlrpc_prepare_comment', $_comment, $comment );
[1215] Fix | Delete
}
[1216] Fix | Delete
[1217] Fix | Delete
/**
[1218] Fix | Delete
* Prepares user data for return in an XML-RPC object.
[1219] Fix | Delete
*
[1220] Fix | Delete
* @param WP_User $user The unprepared user object.
[1221] Fix | Delete
* @param array $fields The subset of user fields to return.
[1222] Fix | Delete
* @return array The prepared user data.
[1223] Fix | Delete
*/
[1224] Fix | Delete
protected function _prepare_user( $user, $fields ) {
[1225] Fix | Delete
$_user = array( 'user_id' => (string) $user->ID );
[1226] Fix | Delete
[1227] Fix | Delete
$user_fields = array(
[1228] Fix | Delete
'username' => $user->user_login,
[1229] Fix | Delete
'first_name' => $user->user_firstname,
[1230] Fix | Delete
'last_name' => $user->user_lastname,
[1231] Fix | Delete
'registered' => $this->_convert_date( $user->user_registered ),
[1232] Fix | Delete
'bio' => $user->user_description,
[1233] Fix | Delete
'email' => $user->user_email,
[1234] Fix | Delete
'nickname' => $user->nickname,
[1235] Fix | Delete
'nicename' => $user->user_nicename,
[1236] Fix | Delete
'url' => $user->user_url,
[1237] Fix | Delete
'display_name' => $user->display_name,
[1238] Fix | Delete
'roles' => $user->roles,
[1239] Fix | Delete
);
[1240] Fix | Delete
[1241] Fix | Delete
if ( in_array( 'all', $fields, true ) ) {
[1242] Fix | Delete
$_user = array_merge( $_user, $user_fields );
[1243] Fix | Delete
} else {
[1244] Fix | Delete
if ( in_array( 'basic', $fields, true ) ) {
[1245] Fix | Delete
$basic_fields = array( 'username', 'email', 'registered', 'display_name', 'nicename' );
[1246] Fix | Delete
$fields = array_merge( $fields, $basic_fields );
[1247] Fix | Delete
}
[1248] Fix | Delete
$requested_fields = array_intersect_key( $user_fields, array_flip( $fields ) );
[1249] Fix | Delete
$_user = array_merge( $_user, $requested_fields );
[1250] Fix | Delete
}
[1251] Fix | Delete
[1252] Fix | Delete
/**
[1253] Fix | Delete
* Filters XML-RPC-prepared data for the given user.
[1254] Fix | Delete
*
[1255] Fix | Delete
* @since 3.5.0
[1256] Fix | Delete
*
[1257] Fix | Delete
* @param array $_user An array of user data.
[1258] Fix | Delete
* @param WP_User $user User object.
[1259] Fix | Delete
* @param array $fields An array of user fields.
[1260] Fix | Delete
*/
[1261] Fix | Delete
return apply_filters( 'xmlrpc_prepare_user', $_user, $user, $fields );
[1262] Fix | Delete
}
[1263] Fix | Delete
[1264] Fix | Delete
/**
[1265] Fix | Delete
* Creates a new post for any registered post type.
[1266] Fix | Delete
*
[1267] Fix | Delete
* @since 3.4.0
[1268] Fix | Delete
*
[1269] Fix | Delete
* @link https://en.wikipedia.org/wiki/RSS_enclosure for information on RSS enclosures.
[1270] Fix | Delete
*
[1271] Fix | Delete
* @param array $args {
[1272] Fix | Delete
* Method arguments. Note: top-level arguments must be ordered as documented.
[1273] Fix | Delete
*
[1274] Fix | Delete
* @type int $0 Blog ID (unused).
[1275] Fix | Delete
* @type string $1 Username.
[1276] Fix | Delete
* @type string $2 Password.
[1277] Fix | Delete
* @type array $3 {
[1278] Fix | Delete
* Content struct for adding a new post. See wp_insert_post() for information on
[1279] Fix | Delete
* additional post fields
[1280] Fix | Delete
*
[1281] Fix | Delete
* @type string $post_type Post type. Default 'post'.
[1282] Fix | Delete
* @type string $post_status Post status. Default 'draft'
[1283] Fix | Delete
* @type string $post_title Post title.
[1284] Fix | Delete
* @type int $post_author Post author ID.
[1285] Fix | Delete
* @type string $post_excerpt Post excerpt.
[1286] Fix | Delete
* @type string $post_content Post content.
[1287] Fix | Delete
* @type string $post_date_gmt Post date in GMT.
[1288] Fix | Delete
* @type string $post_date Post date.
[1289] Fix | Delete
* @type string $post_password Post password (20-character limit).
[1290] Fix | Delete
* @type string $comment_status Post comment enabled status. Accepts 'open' or 'closed'.
[1291] Fix | Delete
* @type string $ping_status Post ping status. Accepts 'open' or 'closed'.
[1292] Fix | Delete
* @type bool $sticky Whether the post should be sticky. Automatically false if
[1293] Fix | Delete
* `$post_status` is 'private'.
[1294] Fix | Delete
* @type int $post_thumbnail ID of an image to use as the post thumbnail/featured image.
[1295] Fix | Delete
* @type array $custom_fields Array of meta key/value pairs to add to the post.
[1296] Fix | Delete
* @type array $terms Associative array with taxonomy names as keys and arrays
[1297] Fix | Delete
* of term IDs as values.
[1298] Fix | Delete
* @type array $terms_names Associative array with taxonomy names as keys and arrays
[1299] Fix | Delete
* of term names as values.
[1300] Fix | Delete
* @type array $enclosure {
[1301] Fix | Delete
* Array of feed enclosure data to add to post meta.
[1302] Fix | Delete
*
[1303] Fix | Delete
* @type string $url URL for the feed enclosure.
[1304] Fix | Delete
* @type int $length Size in bytes of the enclosure.
[1305] Fix | Delete
* @type string $type Mime-type for the enclosure.
[1306] Fix | Delete
* }
[1307] Fix | Delete
* }
[1308] Fix | Delete
* }
[1309] Fix | Delete
* @return int|IXR_Error Post ID on success, IXR_Error instance otherwise.
[1310] Fix | Delete
*/
[1311] Fix | Delete
public function wp_newPost( $args ) {
[1312] Fix | Delete
if ( ! $this->minimum_args( $args, 4 ) ) {
[1313] Fix | Delete
return $this->error;
[1314] Fix | Delete
}
[1315] Fix | Delete
[1316] Fix | Delete
$this->escape( $args );
[1317] Fix | Delete
[1318] Fix | Delete
$username = $args[1];
[1319] Fix | Delete
$password = $args[2];
[1320] Fix | Delete
$content_struct = $args[3];
[1321] Fix | Delete
[1322] Fix | Delete
$user = $this->login( $username, $password );
[1323] Fix | Delete
if ( ! $user ) {
[1324] Fix | Delete
return $this->error;
[1325] Fix | Delete
}
[1326] Fix | Delete
[1327] Fix | Delete
// Convert the date field back to IXR form.
[1328] Fix | Delete
if ( isset( $content_struct['post_date'] ) && ! ( $content_struct['post_date'] instanceof IXR_Date ) ) {
[1329] Fix | Delete
$content_struct['post_date'] = $this->_convert_date( $content_struct['post_date'] );
[1330] Fix | Delete
}
[1331] Fix | Delete
[1332] Fix | Delete
/*
[1333] Fix | Delete
* Ignore the existing GMT date if it is empty or a non-GMT date was supplied in $content_struct,
[1334] Fix | Delete
* since _insert_post() will ignore the non-GMT date if the GMT date is set.
[1335] Fix | Delete
*/
[1336] Fix | Delete
if ( isset( $content_struct['post_date_gmt'] ) && ! ( $content_struct['post_date_gmt'] instanceof IXR_Date ) ) {
[1337] Fix | Delete
if ( '0000-00-00 00:00:00' === $content_struct['post_date_gmt'] || isset( $content_struct['post_date'] ) ) {
[1338] Fix | Delete
unset( $content_struct['post_date_gmt'] );
[1339] Fix | Delete
} else {
[1340] Fix | Delete
$content_struct['post_date_gmt'] = $this->_convert_date( $content_struct['post_date_gmt'] );
[1341] Fix | Delete
}
[1342] Fix | Delete
}
[1343] Fix | Delete
[1344] Fix | Delete
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
[1345] Fix | Delete
do_action( 'xmlrpc_call', 'wp.newPost', $args, $this );
[1346] Fix | Delete
[1347] Fix | Delete
unset( $content_struct['ID'] );
[1348] Fix | Delete
[1349] Fix | Delete
return $this->_insert_post( $user, $content_struct );
[1350] Fix | Delete
}
[1351] Fix | Delete
[1352] Fix | Delete
/**
[1353] Fix | Delete
* Helper method for filtering out elements from an array.
[1354] Fix | Delete
*
[1355] Fix | Delete
* @since 3.4.0
[1356] Fix | Delete
*
[1357] Fix | Delete
* @param int $count Number to compare to one.
[1358] Fix | Delete
* @return bool True if the number is greater than one, false otherwise.
[1359] Fix | Delete
*/
[1360] Fix | Delete
private function _is_greater_than_one( $count ) {
[1361] Fix | Delete
return $count > 1;
[1362] Fix | Delete
}
[1363] Fix | Delete
[1364] Fix | Delete
/**
[1365] Fix | Delete
* Encapsulates the logic for sticking a post and determining if
[1366] Fix | Delete
* the user has permission to do so.
[1367] Fix | Delete
*
[1368] Fix | Delete
* @since 4.3.0
[1369] Fix | Delete
*
[1370] Fix | Delete
* @param array $post_data
[1371] Fix | Delete
* @param bool $update
[1372] Fix | Delete
* @return void|IXR_Error
[1373] Fix | Delete
*/
[1374] Fix | Delete
private function _toggle_sticky( $post_data, $update = false ) {
[1375] Fix | Delete
$post_type = get_post_type_object( $post_data['post_type'] );
[1376] Fix | Delete
[1377] Fix | Delete
// Private and password-protected posts cannot be stickied.
[1378] Fix | Delete
if ( 'private' === $post_data['post_status'] || ! empty( $post_data['post_password'] ) ) {
[1379] Fix | Delete
// Error if the client tried to stick the post, otherwise, silently unstick.
[1380] Fix | Delete
if ( ! empty( $post_data['sticky'] ) ) {
[1381] Fix | Delete
return new IXR_Error( 401, __( 'Sorry, you cannot stick a private post.' ) );
[1382] Fix | Delete
}
[1383] Fix | Delete
[1384] Fix | Delete
if ( $update ) {
[1385] Fix | Delete
unstick_post( $post_data['ID'] );
[1386] Fix | Delete
}
[1387] Fix | Delete
} elseif ( isset( $post_data['sticky'] ) ) {
[1388] Fix | Delete
if ( ! current_user_can( $post_type->cap->edit_others_posts ) ) {
[1389] Fix | Delete
return new IXR_Error( 401, __( 'Sorry, you are not allowed to make posts sticky.' ) );
[1390] Fix | Delete
}
[1391] Fix | Delete
[1392] Fix | Delete
$sticky = wp_validate_boolean( $post_data['sticky'] );
[1393] Fix | Delete
if ( $sticky ) {
[1394] Fix | Delete
stick_post( $post_data['ID'] );
[1395] Fix | Delete
} else {
[1396] Fix | Delete
unstick_post( $post_data['ID'] );
[1397] Fix | Delete
}
[1398] Fix | Delete
}
[1399] Fix | Delete
}
[1400] Fix | Delete
[1401] Fix | Delete
/**
[1402] Fix | Delete
* Helper method for wp_newPost() and wp_editPost(), containing shared logic.
[1403] Fix | Delete
*
[1404] Fix | Delete
* @since 3.4.0
[1405] Fix | Delete
*
[1406] Fix | Delete
* @see wp_insert_post()
[1407] Fix | Delete
*
[1408] Fix | Delete
* @param WP_User $user The post author if post_author isn't set in $content_struct.
[1409] Fix | Delete
* @param array|IXR_Error $content_struct Post data to insert.
[1410] Fix | Delete
* @return IXR_Error|string
[1411] Fix | Delete
*/
[1412] Fix | Delete
protected function _insert_post( $user, $content_struct ) {
[1413] Fix | Delete
$defaults = array(
[1414] Fix | Delete
'post_status' => 'draft',
[1415] Fix | Delete
'post_type' => 'post',
[1416] Fix | Delete
'post_author' => 0,
[1417] Fix | Delete
'post_password' => '',
[1418] Fix | Delete
'post_excerpt' => '',
[1419] Fix | Delete
'post_content' => '',
[1420] Fix | Delete
'post_title' => '',
[1421] Fix | Delete
'post_date' => '',
[1422] Fix | Delete
'post_date_gmt' => '',
[1423] Fix | Delete
'post_format' => null,
[1424] Fix | Delete
'post_name' => null,
[1425] Fix | Delete
'post_thumbnail' => null,
[1426] Fix | Delete
'post_parent' => 0,
[1427] Fix | Delete
'ping_status' => '',
[1428] Fix | Delete
'comment_status' => '',
[1429] Fix | Delete
'custom_fields' => null,
[1430] Fix | Delete
'terms_names' => null,
[1431] Fix | Delete
'terms' => null,
[1432] Fix | Delete
'sticky' => null,
[1433] Fix | Delete
'enclosure' => null,
[1434] Fix | Delete
'ID' => null,
[1435] Fix | Delete
);
[1436] Fix | Delete
[1437] Fix | Delete
$post_data = wp_parse_args( array_intersect_key( $content_struct, $defaults ), $defaults );
[1438] Fix | Delete
[1439] Fix | Delete
$post_type = get_post_type_object( $post_data['post_type'] );
[1440] Fix | Delete
if ( ! $post_type ) {
[1441] Fix | Delete
return new IXR_Error( 403, __( 'Invalid post type.' ) );
[1442] Fix | Delete
}
[1443] Fix | Delete
[1444] Fix | Delete
$update = ! empty( $post_data['ID'] );
[1445] Fix | Delete
[1446] Fix | Delete
if ( $update ) {
[1447] Fix | Delete
if ( ! get_post( $post_data['ID'] ) ) {
[1448] Fix | Delete
return new IXR_Error( 401, __( 'Invalid post ID.' ) );
[1449] Fix | Delete
}
[1450] Fix | Delete
if ( ! current_user_can( 'edit_post', $post_data['ID'] ) ) {
[1451] Fix | Delete
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) );
[1452] Fix | Delete
}
[1453] Fix | Delete
if ( get_post_type( $post_data['ID'] ) !== $post_data['post_type'] ) {
[1454] Fix | Delete
return new IXR_Error( 401, __( 'The post type may not be changed.' ) );
[1455] Fix | Delete
}
[1456] Fix | Delete
} else {
[1457] Fix | Delete
if ( ! current_user_can( $post_type->cap->create_posts ) || ! current_user_can( $post_type->cap->edit_posts ) ) {
[1458] Fix | Delete
return new IXR_Error( 401, __( 'Sorry, you are not allowed to post on this site.' ) );
[1459] Fix | Delete
}
[1460] Fix | Delete
}
[1461] Fix | Delete
[1462] Fix | Delete
switch ( $post_data['post_status'] ) {
[1463] Fix | Delete
case 'draft':
[1464] Fix | Delete
case 'pending':
[1465] Fix | Delete
break;
[1466] Fix | Delete
case 'private':
[1467] Fix | Delete
if ( ! current_user_can( $post_type->cap->publish_posts ) ) {
[1468] Fix | Delete
return new IXR_Error( 401, __( 'Sorry, you are not allowed to create private posts in this post type.' ) );
[1469] Fix | Delete
}
[1470] Fix | Delete
break;
[1471] Fix | Delete
case 'publish':
[1472] Fix | Delete
case 'future':
[1473] Fix | Delete
if ( ! current_user_can( $post_type->cap->publish_posts ) ) {
[1474] Fix | Delete
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish posts in this post type.' ) );
[1475] Fix | Delete
}
[1476] Fix | Delete
break;
[1477] Fix | Delete
default:
[1478] Fix | Delete
if ( ! get_post_status_object( $post_data['post_status'] ) ) {
[1479] Fix | Delete
$post_data['post_status'] = 'draft';
[1480] Fix | Delete
}
[1481] Fix | Delete
break;
[1482] Fix | Delete
}
[1483] Fix | Delete
[1484] Fix | Delete
if ( ! empty( $post_data['post_password'] ) && ! current_user_can( $post_type->cap->publish_posts ) ) {
[1485] Fix | Delete
return new IXR_Error( 401, __( 'Sorry, you are not allowed to create password protected posts in this post type.' ) );
[1486] Fix | Delete
}
[1487] Fix | Delete
[1488] Fix | Delete
$post_data['post_author'] = absint( $post_data['post_author'] );
[1489] Fix | Delete
if ( ! empty( $post_data['post_author'] ) && $post_data['post_author'] != $user->ID ) {
[1490] Fix | Delete
if ( ! current_user_can( $post_type->cap->edit_others_posts ) ) {
[1491] Fix | Delete
return new IXR_Error( 401, __( 'Sorry, you are not allowed to create posts as this user.' ) );
[1492] Fix | Delete
}
[1493] Fix | Delete
[1494] Fix | Delete
$author = get_userdata( $post_data['post_author'] );
[1495] Fix | Delete
[1496] Fix | Delete
if ( ! $author ) {
[1497] Fix | Delete
return new IXR_Error( 404, __( 'Invalid author ID.' ) );
[1498] Fix | Delete
}
[1499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function