PageRenderTime 55ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-admin/admin-ajax.php

https://github.com/schr/wordpress
PHP | 1237 lines | 1035 code | 173 blank | 29 comment | 261 complexity | c8d6f063396bdf3df0bdee513dcdb297 MD5 | raw file
  1. <?php
  2. /**
  3. * WordPress AJAX Process Execution.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. /**
  9. * Executing AJAX process.
  10. *
  11. * @since unknown
  12. */
  13. define('DOING_AJAX', true);
  14. define('WP_ADMIN', true);
  15. require_once('../wp-load.php');
  16. require_once('includes/admin.php');
  17. @header('Content-Type: text/html; charset=' . get_option('blog_charset'));
  18. do_action('admin_init');
  19. if ( ! is_user_logged_in() ) {
  20. if ( $_POST['action'] == 'autosave' ) {
  21. $id = isset($_POST['post_ID'])? (int) $_POST['post_ID'] : 0;
  22. if ( ! $id )
  23. die('-1');
  24. $message = sprintf( __('<strong>ALERT: You are logged out!</strong> Could not save draft. <a href="%s" target="blank">Please log in again.</a>'), wp_login_url() );
  25. $x = new WP_Ajax_Response( array(
  26. 'what' => 'autosave',
  27. 'id' => $id,
  28. 'data' => $message
  29. ) );
  30. $x->send();
  31. }
  32. if ( !empty( $_POST['action']) )
  33. do_action( 'wp_ajax_nopriv_' . $_POST['action'] );
  34. die('-1');
  35. }
  36. if ( isset( $_GET['action'] ) ) :
  37. switch ( $action = $_GET['action'] ) :
  38. case 'ajax-tag-search' :
  39. if ( !current_user_can( 'edit_posts' ) )
  40. die('-1');
  41. $s = $_GET['q']; // is this slashed already?
  42. if ( isset($_GET['tax']) )
  43. $taxonomy = sanitize_title($_GET['tax']);
  44. else
  45. die('0');
  46. if ( false !== strpos( $s, ',' ) ) {
  47. $s = explode( ',', $s );
  48. $s = $s[count( $s ) - 1];
  49. }
  50. $s = trim( $s );
  51. if ( strlen( $s ) < 2 )
  52. die; // require 2 chars for matching
  53. $results = $wpdb->get_col( "SELECT t.name FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = '$taxonomy' AND t.name LIKE ('%" . $s . "%')" );
  54. echo join( $results, "\n" );
  55. die;
  56. break;
  57. case 'wp-compression-test' :
  58. if ( !current_user_can( 'manage_options' ) )
  59. die('-1');
  60. if ( ini_get('zlib.output_compression') || 'ob_gzhandler' == ini_get('output_handler') ) {
  61. update_site_option('can_compress_scripts', 0);
  62. die('0');
  63. }
  64. if ( isset($_GET['test']) ) {
  65. header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );
  66. header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
  67. header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
  68. header( 'Pragma: no-cache' );
  69. header('Content-Type: application/x-javascript; charset=UTF-8');
  70. $force_gzip = ( defined('ENFORCE_GZIP') && ENFORCE_GZIP );
  71. $test_str = '"wpCompressionTest Lorem ipsum dolor sit amet consectetuer mollis sapien urna ut a. Eu nonummy condimentum fringilla tempor pretium platea vel nibh netus Maecenas. Hac molestie amet justo quis pellentesque est ultrices interdum nibh Morbi. Cras mattis pretium Phasellus ante ipsum ipsum ut sociis Suspendisse Lorem. Ante et non molestie. Porta urna Vestibulum egestas id congue nibh eu risus gravida sit. Ac augue auctor Ut et non a elit massa id sodales. Elit eu Nulla at nibh adipiscing mattis lacus mauris at tempus. Netus nibh quis suscipit nec feugiat eget sed lorem et urna. Pellentesque lacus at ut massa consectetuer ligula ut auctor semper Pellentesque. Ut metus massa nibh quam Curabitur molestie nec mauris congue. Volutpat molestie elit justo facilisis neque ac risus Ut nascetur tristique. Vitae sit lorem tellus et quis Phasellus lacus tincidunt nunc Fusce. Pharetra wisi Suspendisse mus sagittis libero lacinia Integer consequat ac Phasellus. Et urna ac cursus tortor aliquam Aliquam amet tellus volutpat Vestibulum. Justo interdum condimentum In augue congue tellus sollicitudin Quisque quis nibh."';
  72. if ( 1 == $_GET['test'] ) {
  73. echo $test_str;
  74. die;
  75. } elseif ( 2 == $_GET['test'] ) {
  76. if ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'deflate') && function_exists('gzdeflate') && ! $force_gzip ) {
  77. header('Content-Encoding: deflate');
  78. $out = gzdeflate( $test_str, 1 );
  79. } elseif ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'gzip') && function_exists('gzencode') ) {
  80. header('Content-Encoding: gzip');
  81. $out = gzencode( $test_str, 1 );
  82. } else {
  83. die('-1');
  84. }
  85. echo $out;
  86. die;
  87. } elseif ( 'no' == $_GET['test'] ) {
  88. update_site_option('can_compress_scripts', 0);
  89. } elseif ( 'yes' == $_GET['test'] ) {
  90. update_site_option('can_compress_scripts', 1);
  91. }
  92. }
  93. die('0');
  94. break;
  95. default :
  96. do_action( 'wp_ajax_' . $_GET['action'] );
  97. die('0');
  98. break;
  99. endswitch;
  100. endif;
  101. /**
  102. * Sends back current comment total and new page links if they need to be updated.
  103. *
  104. * Contrary to normal success AJAX response ("1"), die with time() on success.
  105. *
  106. * @since 2.7
  107. *
  108. * @param int $comment_id
  109. * @return die
  110. */
  111. function _wp_ajax_delete_comment_response( $comment_id ) {
  112. $total = (int) @$_POST['_total'];
  113. $per_page = (int) @$_POST['_per_page'];
  114. $page = (int) @$_POST['_page'];
  115. $url = clean_url( @$_POST['_url'], null, 'url' );
  116. // JS didn't send us everything we need to know. Just die with success message
  117. if ( !$total || !$per_page || !$page || !$url )
  118. die( (string) time() );
  119. if ( --$total < 0 ) // Take the total from POST and decrement it (since we just deleted one)
  120. $total = 0;
  121. if ( 0 != $total % $per_page && 1 != mt_rand( 1, $per_page ) ) // Only do the expensive stuff on a page-break, and about 1 other time per page
  122. die( (string) time() );
  123. $status = 'total_comments'; // What type of comment count are we looking for?
  124. $parsed = parse_url( $url );
  125. if ( isset( $parsed['query'] ) ) {
  126. parse_str( $parsed['query'], $query_vars );
  127. if ( !empty( $query_vars['comment_status'] ) )
  128. $status = $query_vars['comment_status'];
  129. }
  130. $comment_count = wp_count_comments();
  131. $time = time(); // The time since the last comment count
  132. if ( isset( $comment_count->$status ) ) // We're looking for a known type of comment count
  133. $total = $comment_count->$status;
  134. // else use the decremented value from above
  135. $page_links = paginate_links( array(
  136. 'base' => add_query_arg( 'apage', '%#%', $url ),
  137. 'format' => '',
  138. 'prev_text' => __('&laquo;'),
  139. 'next_text' => __('&raquo;'),
  140. 'total' => ceil($total / $per_page),
  141. 'current' => $page
  142. ) );
  143. $x = new WP_Ajax_Response( array(
  144. 'what' => 'comment',
  145. 'id' => $comment_id, // here for completeness - not used
  146. 'supplemental' => array(
  147. 'pageLinks' => $page_links,
  148. 'total' => $total,
  149. 'time' => $time
  150. )
  151. ) );
  152. $x->send();
  153. }
  154. $id = isset($_POST['id'])? (int) $_POST['id'] : 0;
  155. switch ( $action = $_POST['action'] ) :
  156. case 'delete-comment' : // On success, die with time() instead of 1
  157. check_ajax_referer( "delete-comment_$id" );
  158. if ( !$comment = get_comment( $id ) )
  159. die( (string) time() );
  160. if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) )
  161. die('-1');
  162. if ( isset($_POST['spam']) && 1 == $_POST['spam'] ) {
  163. if ( 'spam' == wp_get_comment_status( $comment->comment_ID ) )
  164. die( (string) time() );
  165. $r = wp_set_comment_status( $comment->comment_ID, 'spam' );
  166. } else {
  167. $r = wp_delete_comment( $comment->comment_ID );
  168. }
  169. if ( $r ) // Decide if we need to send back '1' or a more complicated response including page links and comment counts
  170. _wp_ajax_delete_comment_response( $comment->comment_ID );
  171. die( '0' );
  172. break;
  173. case 'delete-cat' :
  174. check_ajax_referer( "delete-category_$id" );
  175. if ( !current_user_can( 'manage_categories' ) )
  176. die('-1');
  177. $cat = get_category( $id );
  178. if ( !$cat || is_wp_error( $cat ) )
  179. die('1');
  180. if ( wp_delete_category( $id ) )
  181. die('1');
  182. else
  183. die('0');
  184. break;
  185. case 'delete-tag' :
  186. check_ajax_referer( "delete-tag_$id" );
  187. if ( !current_user_can( 'manage_categories' ) )
  188. die('-1');
  189. if ( !empty($_POST['taxonomy']) )
  190. $taxonomy = $_POST['taxonomy'];
  191. else
  192. $taxonomy = 'post_tag';
  193. $tag = get_term( $id, $taxonomy );
  194. if ( !$tag || is_wp_error( $tag ) )
  195. die('1');
  196. if ( wp_delete_term($id, $taxonomy))
  197. die('1');
  198. else
  199. die('0');
  200. break;
  201. case 'delete-link-cat' :
  202. check_ajax_referer( "delete-link-category_$id" );
  203. if ( !current_user_can( 'manage_categories' ) )
  204. die('-1');
  205. $cat = get_term( $id, 'link_category' );
  206. if ( !$cat || is_wp_error( $cat ) )
  207. die('1');
  208. $cat_name = get_term_field('name', $id, 'link_category');
  209. // Don't delete the default cats.
  210. if ( $id == get_option('default_link_category') ) {
  211. $x = new WP_AJAX_Response( array(
  212. 'what' => 'link-cat',
  213. 'id' => $id,
  214. 'data' => new WP_Error( 'default-link-cat', sprintf(__("Can&#8217;t delete the <strong>%s</strong> category: this is the default one"), $cat_name) )
  215. ) );
  216. $x->send();
  217. }
  218. $r = wp_delete_term($id, 'link_category');
  219. if ( !$r )
  220. die('0');
  221. if ( is_wp_error($r) ) {
  222. $x = new WP_AJAX_Response( array(
  223. 'what' => 'link-cat',
  224. 'id' => $id,
  225. 'data' => $r
  226. ) );
  227. $x->send();
  228. }
  229. die('1');
  230. break;
  231. case 'delete-link' :
  232. check_ajax_referer( "delete-bookmark_$id" );
  233. if ( !current_user_can( 'manage_links' ) )
  234. die('-1');
  235. $link = get_bookmark( $id );
  236. if ( !$link || is_wp_error( $link ) )
  237. die('1');
  238. if ( wp_delete_link( $id ) )
  239. die('1');
  240. else
  241. die('0');
  242. break;
  243. case 'delete-meta' :
  244. check_ajax_referer( "delete-meta_$id" );
  245. if ( !$meta = get_post_meta_by_id( $id ) )
  246. die('1');
  247. if ( !current_user_can( 'edit_post', $meta->post_id ) )
  248. die('-1');
  249. if ( delete_meta( $meta->meta_id ) )
  250. die('1');
  251. die('0');
  252. break;
  253. case 'delete-post' :
  254. check_ajax_referer( "{$action}_$id" );
  255. if ( !current_user_can( 'delete_post', $id ) )
  256. die('-1');
  257. if ( !get_post( $id ) )
  258. die('1');
  259. if ( wp_delete_post( $id ) )
  260. die('1');
  261. else
  262. die('0');
  263. break;
  264. case 'delete-page' :
  265. check_ajax_referer( "{$action}_$id" );
  266. if ( !current_user_can( 'delete_page', $id ) )
  267. die('-1');
  268. if ( !get_page( $id ) )
  269. die('1');
  270. if ( wp_delete_post( $id ) )
  271. die('1');
  272. else
  273. die('0');
  274. break;
  275. case 'dim-comment' : // On success, die with time() instead of 1
  276. if ( !$comment = get_comment( $id ) ) {
  277. $x = new WP_Ajax_Response( array(
  278. 'what' => 'comment',
  279. 'id' => new WP_Error('invalid_comment', sprintf(__('Comment %d does not exist'), $id))
  280. ) );
  281. $x->send();
  282. }
  283. if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) )
  284. die('-1');
  285. if ( !current_user_can( 'moderate_comments' ) )
  286. die('-1');
  287. $current = wp_get_comment_status( $comment->comment_ID );
  288. if ( $_POST['new'] == $current )
  289. die( (string) time() );
  290. $r = 0;
  291. if ( in_array( $current, array( 'unapproved', 'spam' ) ) ) {
  292. check_ajax_referer( "approve-comment_$id" );
  293. $result = wp_set_comment_status( $comment->comment_ID, 'approve', true );
  294. } else {
  295. check_ajax_referer( "unapprove-comment_$id" );
  296. $result = wp_set_comment_status( $comment->comment_ID, 'hold', true );
  297. }
  298. if ( is_wp_error($result) ) {
  299. $x = new WP_Ajax_Response( array(
  300. 'what' => 'comment',
  301. 'id' => $result
  302. ) );
  303. $x->send();
  304. }
  305. // Decide if we need to send back '1' or a more complicated response including page links and comment counts
  306. _wp_ajax_delete_comment_response( $comment->comment_ID );
  307. die( '0' );
  308. break;
  309. case 'add-category' : // On the Fly
  310. check_ajax_referer( $action );
  311. if ( !current_user_can( 'manage_categories' ) )
  312. die('-1');
  313. $names = explode(',', $_POST['newcat']);
  314. if ( 0 > $parent = (int) $_POST['newcat_parent'] )
  315. $parent = 0;
  316. $post_category = isset($_POST['post_category'])? (array) $_POST['post_category'] : array();
  317. $checked_categories = array_map( 'absint', (array) $post_category );
  318. $popular_ids = isset( $_POST['popular_ids'] ) ?
  319. array_map( 'absint', explode( ',', $_POST['popular_ids'] ) ) :
  320. false;
  321. $x = new WP_Ajax_Response();
  322. foreach ( $names as $cat_name ) {
  323. $cat_name = trim($cat_name);
  324. $category_nicename = sanitize_title($cat_name);
  325. if ( '' === $category_nicename )
  326. continue;
  327. $cat_id = wp_create_category( $cat_name, $parent );
  328. $checked_categories[] = $cat_id;
  329. if ( $parent ) // Do these all at once in a second
  330. continue;
  331. $category = get_category( $cat_id );
  332. ob_start();
  333. wp_category_checklist( 0, $cat_id, $checked_categories, $popular_ids );
  334. $data = ob_get_contents();
  335. ob_end_clean();
  336. $x->add( array(
  337. 'what' => 'category',
  338. 'id' => $cat_id,
  339. 'data' => $data,
  340. 'position' => -1
  341. ) );
  342. }
  343. if ( $parent ) { // Foncy - replace the parent and all its children
  344. $parent = get_category( $parent );
  345. ob_start();
  346. dropdown_categories( 0, $parent );
  347. $data = ob_get_contents();
  348. ob_end_clean();
  349. $x->add( array(
  350. 'what' => 'category',
  351. 'id' => $parent->term_id,
  352. 'old_id' => $parent->term_id,
  353. 'data' => $data,
  354. 'position' => -1
  355. ) );
  356. }
  357. $x->send();
  358. break;
  359. case 'add-link-category' : // On the Fly
  360. check_ajax_referer( $action );
  361. if ( !current_user_can( 'manage_categories' ) )
  362. die('-1');
  363. $names = explode(',', $_POST['newcat']);
  364. $x = new WP_Ajax_Response();
  365. foreach ( $names as $cat_name ) {
  366. $cat_name = trim($cat_name);
  367. $slug = sanitize_title($cat_name);
  368. if ( '' === $slug )
  369. continue;
  370. if ( !$cat_id = is_term( $cat_name, 'link_category' ) ) {
  371. $cat_id = wp_insert_term( $cat_name, 'link_category' );
  372. }
  373. $cat_id = $cat_id['term_id'];
  374. $cat_name = wp_specialchars(stripslashes($cat_name));
  375. $x->add( array(
  376. 'what' => 'link-category',
  377. 'id' => $cat_id,
  378. 'data' => "<li id='link-category-$cat_id'><label for='in-link-category-$cat_id' class='selectit'><input value='$cat_id' type='checkbox' checked='checked' name='link_category[]' id='in-link-category-$cat_id'/> $cat_name</label></li>",
  379. 'position' => -1
  380. ) );
  381. }
  382. $x->send();
  383. break;
  384. case 'add-cat' : // From Manage->Categories
  385. check_ajax_referer( 'add-category' );
  386. if ( !current_user_can( 'manage_categories' ) )
  387. die('-1');
  388. if ( '' === trim($_POST['cat_name']) ) {
  389. $x = new WP_Ajax_Response( array(
  390. 'what' => 'cat',
  391. 'id' => new WP_Error( 'cat_name', __('You did not enter a category name.') )
  392. ) );
  393. $x->send();
  394. }
  395. if ( category_exists( trim( $_POST['cat_name'] ) ) ) {
  396. $x = new WP_Ajax_Response( array(
  397. 'what' => 'cat',
  398. 'id' => new WP_Error( 'cat_exists', __('The category you are trying to create already exists.'), array( 'form-field' => 'cat_name' ) ),
  399. ) );
  400. $x->send();
  401. }
  402. $cat = wp_insert_category( $_POST, true );
  403. if ( is_wp_error($cat) ) {
  404. $x = new WP_Ajax_Response( array(
  405. 'what' => 'cat',
  406. 'id' => $cat
  407. ) );
  408. $x->send();
  409. }
  410. if ( !$cat || (!$cat = get_category( $cat )) )
  411. die('0');
  412. $level = 0;
  413. $cat_full_name = $cat->name;
  414. $_cat = $cat;
  415. while ( $_cat->parent ) {
  416. $_cat = get_category( $_cat->parent );
  417. $cat_full_name = $_cat->name . ' &#8212; ' . $cat_full_name;
  418. $level++;
  419. }
  420. $cat_full_name = attribute_escape($cat_full_name);
  421. $x = new WP_Ajax_Response( array(
  422. 'what' => 'cat',
  423. 'id' => $cat->term_id,
  424. 'position' => -1,
  425. 'data' => _cat_row( $cat, $level, $cat_full_name ),
  426. 'supplemental' => array('name' => $cat_full_name, 'show-link' => sprintf(__( 'Category <a href="#%s">%s</a> added' ), "cat-$cat->term_id", $cat_full_name))
  427. ) );
  428. $x->send();
  429. break;
  430. case 'add-link-cat' : // From Blogroll -> Categories
  431. check_ajax_referer( 'add-link-category' );
  432. if ( !current_user_can( 'manage_categories' ) )
  433. die('-1');
  434. if ( '' === trim($_POST['name']) ) {
  435. $x = new WP_Ajax_Response( array(
  436. 'what' => 'link-cat',
  437. 'id' => new WP_Error( 'name', __('You did not enter a category name.') )
  438. ) );
  439. $x->send();
  440. }
  441. $r = wp_insert_term($_POST['name'], 'link_category', $_POST );
  442. if ( is_wp_error( $r ) ) {
  443. $x = new WP_AJAX_Response( array(
  444. 'what' => 'link-cat',
  445. 'id' => $r
  446. ) );
  447. $x->send();
  448. }
  449. extract($r, EXTR_SKIP);
  450. if ( !$link_cat = link_cat_row( $term_id ) )
  451. die('0');
  452. $x = new WP_Ajax_Response( array(
  453. 'what' => 'link-cat',
  454. 'id' => $term_id,
  455. 'position' => -1,
  456. 'data' => $link_cat
  457. ) );
  458. $x->send();
  459. break;
  460. case 'add-tag' : // From Manage->Tags
  461. check_ajax_referer( 'add-tag' );
  462. if ( !current_user_can( 'manage_categories' ) )
  463. die('-1');
  464. if ( '' === trim($_POST['name']) ) {
  465. $x = new WP_Ajax_Response( array(
  466. 'what' => 'tag',
  467. 'id' => new WP_Error( 'name', __('You did not enter a tag name.') )
  468. ) );
  469. $x->send();
  470. }
  471. if ( !empty($_POST['taxonomy']) )
  472. $taxonomy = $_POST['taxonomy'];
  473. else
  474. $taxonomy = 'post_tag';
  475. $tag = wp_insert_term($_POST['name'], $taxonomy, $_POST );
  476. if ( is_wp_error($tag) ) {
  477. $x = new WP_Ajax_Response( array(
  478. 'what' => 'tag',
  479. 'id' => $tag
  480. ) );
  481. $x->send();
  482. }
  483. if ( !$tag || (!$tag = get_term( $tag['term_id'], $taxonomy )) )
  484. die('0');
  485. $tag_full_name = $tag->name;
  486. $tag_full_name = attribute_escape($tag_full_name);
  487. $x = new WP_Ajax_Response( array(
  488. 'what' => 'tag',
  489. 'id' => $tag->term_id,
  490. 'position' => '-1',
  491. 'data' => _tag_row( $tag ),
  492. 'supplemental' => array('name' => $tag_full_name, 'show-link' => sprintf(__( 'Tag <a href="#%s">%s</a> added' ), "tag-$tag->term_id", $tag_full_name))
  493. ) );
  494. $x->send();
  495. break;
  496. case 'get-tagcloud' :
  497. if ( !current_user_can( 'manage_categories' ) )
  498. die('-1');
  499. if ( isset($_POST['tax']) )
  500. $taxonomy = sanitize_title($_POST['tax']);
  501. else
  502. die('0');
  503. $tags = get_terms( $taxonomy, array( 'number' => 45, 'orderby' => 'count', 'order' => 'DESC' ) );
  504. if ( empty( $tags ) )
  505. die( __('No tags found!') );
  506. if ( is_wp_error($tags) )
  507. die($tags->get_error_message());
  508. foreach ( $tags as $key => $tag ) {
  509. $tags[ $key ]->link = '#';
  510. $tags[ $key ]->id = $tag->term_id;
  511. }
  512. $return = wp_generate_tag_cloud( $tags );
  513. if ( empty($return) )
  514. die('0');
  515. echo $return;
  516. exit;
  517. break;
  518. case 'add-comment' :
  519. check_ajax_referer( $action );
  520. if ( !current_user_can( 'edit_post', $id ) )
  521. die('-1');
  522. $search = isset($_POST['s']) ? $_POST['s'] : false;
  523. $start = isset($_POST['page']) ? intval($_POST['page']) * 25 - 1: 24;
  524. $status = isset($_POST['comment_status']) ? $_POST['comment_status'] : false;
  525. $mode = isset($_POST['mode']) ? $_POST['mode'] : 'detail';
  526. $p = isset($_POST['p']) ? $_POST['p'] : 0;
  527. $comment_type = isset($_POST['comment_type']) ? $_POST['comment_type'] : '';
  528. list($comments, $total) = _wp_get_comment_list( $status, $search, $start, 1, $p, $comment_type );
  529. if ( get_option('show_avatars') )
  530. add_filter( 'comment_author', 'floated_admin_avatar' );
  531. if ( !$comments )
  532. die('1');
  533. $x = new WP_Ajax_Response();
  534. foreach ( (array) $comments as $comment ) {
  535. get_comment( $comment );
  536. ob_start();
  537. _wp_comment_row( $comment->comment_ID, $mode, $status, true, true );
  538. $comment_list_item = ob_get_contents();
  539. ob_end_clean();
  540. $x->add( array(
  541. 'what' => 'comment',
  542. 'id' => $comment->comment_ID,
  543. 'data' => $comment_list_item
  544. ) );
  545. }
  546. $x->send();
  547. break;
  548. case 'get-comments' :
  549. check_ajax_referer( $action );
  550. $post_ID = (int) $_POST['post_ID'];
  551. if ( !current_user_can( 'edit_post', $post_ID ) )
  552. die('-1');
  553. $start = isset($_POST['start']) ? intval($_POST['start']) : 0;
  554. $num = isset($_POST['num']) ? intval($_POST['num']) : 10;
  555. list($comments, $total) = _wp_get_comment_list( false, false, $start, $num, $post_ID );
  556. if ( !$comments )
  557. die('1');
  558. $comment_list_item = '';
  559. $x = new WP_Ajax_Response();
  560. foreach ( (array) $comments as $comment ) {
  561. get_comment( $comment );
  562. ob_start();
  563. _wp_comment_row( $comment->comment_ID, 'single', false, false );
  564. $comment_list_item .= ob_get_contents();
  565. ob_end_clean();
  566. }
  567. $x->add( array(
  568. 'what' => 'comments',
  569. 'data' => $comment_list_item
  570. ) );
  571. $x->send();
  572. break;
  573. case 'replyto-comment' :
  574. check_ajax_referer( $action );
  575. $comment_post_ID = (int) $_POST['comment_post_ID'];
  576. if ( !current_user_can( 'edit_post', $comment_post_ID ) )
  577. die('-1');
  578. $status = $wpdb->get_var( $wpdb->prepare("SELECT post_status FROM $wpdb->posts WHERE ID = %d", $comment_post_ID) );
  579. if ( empty($status) )
  580. die('1');
  581. elseif ( in_array($status, array('draft', 'pending') ) )
  582. die( __('Error: you are replying to a comment on a draft post.') );
  583. $user = wp_get_current_user();
  584. if ( $user->ID ) {
  585. $comment_author = $wpdb->escape($user->display_name);
  586. $comment_author_email = $wpdb->escape($user->user_email);
  587. $comment_author_url = $wpdb->escape($user->user_url);
  588. $comment_content = trim($_POST['content']);
  589. if ( current_user_can('unfiltered_html') ) {
  590. if ( wp_create_nonce('unfiltered-html-comment_' . $comment_post_ID) != $_POST['_wp_unfiltered_html_comment'] ) {
  591. kses_remove_filters(); // start with a clean slate
  592. kses_init_filters(); // set up the filters
  593. }
  594. }
  595. } else {
  596. die( __('Sorry, you must be logged in to reply to a comment.') );
  597. }
  598. if ( '' == $comment_content )
  599. die( __('Error: please type a comment.') );
  600. $comment_parent = absint($_POST['comment_ID']);
  601. $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID');
  602. $comment_id = wp_new_comment( $commentdata );
  603. $comment = get_comment($comment_id);
  604. if ( ! $comment ) die('1');
  605. $modes = array( 'single', 'detail', 'dashboard' );
  606. $mode = isset($_POST['mode']) && in_array( $_POST['mode'], $modes ) ? $_POST['mode'] : 'detail';
  607. $position = ( isset($_POST['position']) && (int) $_POST['position']) ? (int) $_POST['position'] : '-1';
  608. $checkbox = ( isset($_POST['checkbox']) && true == $_POST['checkbox'] ) ? 1 : 0;
  609. if ( get_option('show_avatars') && 'single' != $mode )
  610. add_filter( 'comment_author', 'floated_admin_avatar' );
  611. $x = new WP_Ajax_Response();
  612. ob_start();
  613. if ( 'dashboard' == $mode ) {
  614. require_once( ABSPATH . 'wp-admin/includes/dashboard.php' );
  615. _wp_dashboard_recent_comments_row( $comment, false );
  616. } else {
  617. _wp_comment_row( $comment->comment_ID, $mode, false, $checkbox );
  618. }
  619. $comment_list_item = ob_get_contents();
  620. ob_end_clean();
  621. $x->add( array(
  622. 'what' => 'comment',
  623. 'id' => $comment->comment_ID,
  624. 'data' => $comment_list_item,
  625. 'position' => $position
  626. ));
  627. $x->send();
  628. break;
  629. case 'edit-comment' :
  630. check_ajax_referer( 'replyto-comment' );
  631. $comment_post_ID = (int) $_POST['comment_post_ID'];
  632. if ( ! current_user_can( 'edit_post', $comment_post_ID ) )
  633. die('-1');
  634. if ( '' == $_POST['content'] )
  635. die( __('Error: please type a comment.') );
  636. $comment_id = (int) $_POST['comment_ID'];
  637. $_POST['comment_status'] = $_POST['status'];
  638. edit_comment();
  639. $mode = ( isset($_POST['mode']) && 'single' == $_POST['mode'] ) ? 'single' : 'detail';
  640. $position = ( isset($_POST['position']) && (int) $_POST['position']) ? (int) $_POST['position'] : '-1';
  641. $checkbox = ( isset($_POST['checkbox']) && true == $_POST['checkbox'] ) ? 1 : 0;
  642. $comments_listing = isset($_POST['comments_listing']) ? $_POST['comments_listing'] : '';
  643. if ( get_option('show_avatars') && 'single' != $mode )
  644. add_filter( 'comment_author', 'floated_admin_avatar' );
  645. $x = new WP_Ajax_Response();
  646. ob_start();
  647. _wp_comment_row( $comment_id, $mode, $comments_listing, $checkbox );
  648. $comment_list_item = ob_get_contents();
  649. ob_end_clean();
  650. $x->add( array(
  651. 'what' => 'edit_comment',
  652. 'id' => $comment->comment_ID,
  653. 'data' => $comment_list_item,
  654. 'position' => $position
  655. ));
  656. $x->send();
  657. break;
  658. case 'add-meta' :
  659. check_ajax_referer( 'add-meta' );
  660. $c = 0;
  661. $pid = (int) $_POST['post_id'];
  662. if ( isset($_POST['metakeyselect']) || isset($_POST['metakeyinput']) ) {
  663. if ( !current_user_can( 'edit_post', $pid ) )
  664. die('-1');
  665. if ( '#NONE#' == $_POST['metakeyselect'] && empty($_POST['metakeyinput']) )
  666. die('1');
  667. if ( $pid < 0 ) {
  668. $now = current_time('timestamp', 1);
  669. if ( $pid = wp_insert_post( array(
  670. 'post_title' => sprintf('Draft created on %s at %s', date(get_option('date_format'), $now), date(get_option('time_format'), $now))
  671. ) ) ) {
  672. if ( is_wp_error( $pid ) ) {
  673. $x = new WP_Ajax_Response( array(
  674. 'what' => 'meta',
  675. 'data' => $pid
  676. ) );
  677. $x->send();
  678. }
  679. $mid = add_meta( $pid );
  680. } else {
  681. die('0');
  682. }
  683. } else if ( !$mid = add_meta( $pid ) ) {
  684. die('0');
  685. }
  686. $meta = get_post_meta_by_id( $mid );
  687. $pid = (int) $meta->post_id;
  688. $meta = get_object_vars( $meta );
  689. $x = new WP_Ajax_Response( array(
  690. 'what' => 'meta',
  691. 'id' => $mid,
  692. 'data' => _list_meta_row( $meta, $c ),
  693. 'position' => 1,
  694. 'supplemental' => array('postid' => $pid)
  695. ) );
  696. } else {
  697. $mid = (int) array_pop(array_keys($_POST['meta']));
  698. $key = $_POST['meta'][$mid]['key'];
  699. $value = $_POST['meta'][$mid]['value'];
  700. if ( !$meta = get_post_meta_by_id( $mid ) )
  701. die('0'); // if meta doesn't exist
  702. if ( !current_user_can( 'edit_post', $meta->post_id ) )
  703. die('-1');
  704. if ( !$u = update_meta( $mid, $key, $value ) )
  705. die('1'); // We know meta exists; we also know it's unchanged (or DB error, in which case there are bigger problems).
  706. $key = stripslashes($key);
  707. $value = stripslashes($value);
  708. $x = new WP_Ajax_Response( array(
  709. 'what' => 'meta',
  710. 'id' => $mid, 'old_id' => $mid,
  711. 'data' => _list_meta_row( array(
  712. 'meta_key' => $key,
  713. 'meta_value' => $value,
  714. 'meta_id' => $mid
  715. ), $c ),
  716. 'position' => 0,
  717. 'supplemental' => array('postid' => $meta->post_id)
  718. ) );
  719. }
  720. $x->send();
  721. break;
  722. case 'add-user' :
  723. check_ajax_referer( $action );
  724. if ( !current_user_can('create_users') )
  725. die('-1');
  726. require_once(ABSPATH . WPINC . '/registration.php');
  727. if ( !$user_id = add_user() )
  728. die('0');
  729. elseif ( is_wp_error( $user_id ) ) {
  730. $x = new WP_Ajax_Response( array(
  731. 'what' => 'user',
  732. 'id' => $user_id
  733. ) );
  734. $x->send();
  735. }
  736. $user_object = new WP_User( $user_id );
  737. $x = new WP_Ajax_Response( array(
  738. 'what' => 'user',
  739. 'id' => $user_id,
  740. 'data' => user_row( $user_object, '', $user_object->roles[0] ),
  741. 'supplemental' => array(
  742. 'show-link' => sprintf(__( 'User <a href="#%s">%s</a> added' ), "user-$user_id", $user_object->user_login),
  743. 'role' => $user_object->roles[0]
  744. )
  745. ) );
  746. $x->send();
  747. break;
  748. case 'autosave' : // The name of this action is hardcoded in edit_post()
  749. define( 'DOING_AUTOSAVE', true );
  750. $nonce_age = check_ajax_referer( 'autosave', 'autosavenonce' );
  751. global $current_user;
  752. $_POST['post_category'] = explode(",", $_POST['catslist']);
  753. if($_POST['post_type'] == 'page' || empty($_POST['post_category']))
  754. unset($_POST['post_category']);
  755. $do_autosave = (bool) $_POST['autosave'];
  756. $do_lock = true;
  757. $data = '';
  758. $message = sprintf( __('Draft Saved at %s.'), date_i18n( __('g:i:s a') ) );
  759. $supplemental = array();
  760. $id = $revision_id = 0;
  761. if($_POST['post_ID'] < 0) {
  762. $_POST['post_status'] = 'draft';
  763. $_POST['temp_ID'] = $_POST['post_ID'];
  764. if ( $do_autosave ) {
  765. $id = wp_write_post();
  766. $data = $message;
  767. }
  768. } else {
  769. $post_ID = (int) $_POST['post_ID'];
  770. $_POST['ID'] = $post_ID;
  771. $post = get_post($post_ID);
  772. if ( $last = wp_check_post_lock( $post->ID ) ) {
  773. $do_autosave = $do_lock = false;
  774. $last_user = get_userdata( $last );
  775. $last_user_name = $last_user ? $last_user->display_name : __( 'Someone' );
  776. $data = new WP_Error( 'locked', sprintf(
  777. $_POST['post_type'] == 'page' ? __( 'Autosave disabled: %s is currently editing this page.' ) : __( 'Autosave disabled: %s is currently editing this post.' ),
  778. wp_specialchars( $last_user_name )
  779. ) );
  780. $supplemental['disable_autosave'] = 'disable';
  781. }
  782. if ( 'page' == $post->post_type ) {
  783. if ( !current_user_can('edit_page', $post_ID) )
  784. die(__('You are not allowed to edit this page.'));
  785. } else {
  786. if ( !current_user_can('edit_post', $post_ID) )
  787. die(__('You are not allowed to edit this post.'));
  788. }
  789. if ( $do_autosave ) {
  790. // Drafts are just overwritten by autosave
  791. if ( 'draft' == $post->post_status ) {
  792. $id = edit_post();
  793. } else { // Non drafts are not overwritten. The autosave is stored in a special post revision.
  794. $revision_id = wp_create_post_autosave( $post->ID );
  795. if ( is_wp_error($revision_id) )
  796. $id = $revision_id;
  797. else
  798. $id = $post->ID;
  799. }
  800. $data = $message;
  801. } else {
  802. $id = $post->ID;
  803. }
  804. }
  805. if ( $do_lock && $id && is_numeric($id) )
  806. wp_set_post_lock( $id );
  807. if ( $nonce_age == 2 ) {
  808. $supplemental['replace-autosavenonce'] = wp_create_nonce('autosave');
  809. $supplemental['replace-getpermalinknonce'] = wp_create_nonce('getpermalink');
  810. $supplemental['replace-samplepermalinknonce'] = wp_create_nonce('samplepermalink');
  811. $supplemental['replace-closedpostboxesnonce'] = wp_create_nonce('closedpostboxes');
  812. if ( $id ) {
  813. if ( $_POST['post_type'] == 'post' )
  814. $supplemental['replace-_wpnonce'] = wp_create_nonce('update-post_' . $id);
  815. elseif ( $_POST['post_type'] == 'page' )
  816. $supplemental['replace-_wpnonce'] = wp_create_nonce('update-page_' . $id);
  817. }
  818. }
  819. $x = new WP_Ajax_Response( array(
  820. 'what' => 'autosave',
  821. 'id' => $id,
  822. 'data' => $id ? $data : '',
  823. 'supplemental' => $supplemental
  824. ) );
  825. $x->send();
  826. break;
  827. case 'autosave-generate-nonces' :
  828. check_ajax_referer( 'autosave', 'autosavenonce' );
  829. $ID = (int) $_POST['post_ID'];
  830. if($_POST['post_type'] == 'post') {
  831. if(current_user_can('edit_post', $ID))
  832. die(wp_create_nonce('update-post_' . $ID));
  833. }
  834. if($_POST['post_type'] == 'page') {
  835. if(current_user_can('edit_page', $ID)) {
  836. die(wp_create_nonce('update-page_' . $ID));
  837. }
  838. }
  839. die('0');
  840. break;
  841. case 'closed-postboxes' :
  842. check_ajax_referer( 'closedpostboxes', 'closedpostboxesnonce' );
  843. $closed = isset( $_POST['closed'] ) ? $_POST['closed'] : '';
  844. $closed = explode( ',', $_POST['closed'] );
  845. $hidden = isset( $_POST['hidden'] ) ? $_POST['hidden'] : '';
  846. $hidden = explode( ',', $_POST['hidden'] );
  847. $page = isset( $_POST['page'] ) ? $_POST['page'] : '';
  848. if ( !preg_match( '/^[a-z_-]+$/', $page ) )
  849. die(-1);
  850. if ( ! $user = wp_get_current_user() )
  851. die(-1);
  852. if ( is_array($closed) )
  853. update_usermeta($user->ID, 'closedpostboxes_'.$page, $closed);
  854. if ( is_array($hidden) )
  855. update_usermeta($user->ID, 'meta-box-hidden_'.$page, $hidden);
  856. die('1');
  857. break;
  858. case 'hidden-columns' :
  859. check_ajax_referer( 'hiddencolumns', 'hiddencolumnsnonce' );
  860. $hidden = isset( $_POST['hidden'] ) ? $_POST['hidden'] : '';
  861. $hidden = explode( ',', $_POST['hidden'] );
  862. $page = isset( $_POST['page'] ) ? $_POST['page'] : '';
  863. if ( !preg_match( '/^[a-z_-]+$/', $page ) )
  864. die(-1);
  865. if ( ! $user = wp_get_current_user() )
  866. die(-1);
  867. if ( is_array($hidden) )
  868. update_usermeta($user->ID, "manage-$page-columns-hidden", $hidden);
  869. die('1');
  870. break;
  871. case 'meta-box-order':
  872. check_ajax_referer( 'meta-box-order' );
  873. $order = isset( $_POST['order'] ) ? (array) $_POST['order'] : false;
  874. $page_columns = isset( $_POST['page_columns'] ) ? (int) $_POST['page_columns'] : 0;
  875. $page = isset( $_POST['page'] ) ? $_POST['page'] : '';
  876. if ( !preg_match( '/^[a-z_-]+$/', $page ) )
  877. die(-1);
  878. if ( ! $user = wp_get_current_user() )
  879. die(-1);
  880. if ( $order )
  881. update_user_option($user->ID, "meta-box-order_$page", $order);
  882. if ( $page_columns )
  883. update_usermeta($user->ID, "screen_layout_$page", $page_columns);
  884. die('1');
  885. break;
  886. case 'get-permalink':
  887. check_ajax_referer( 'getpermalink', 'getpermalinknonce' );
  888. $post_id = isset($_POST['post_id'])? intval($_POST['post_id']) : 0;
  889. die(add_query_arg(array('preview' => 'true'), get_permalink($post_id)));
  890. break;
  891. case 'sample-permalink':
  892. check_ajax_referer( 'samplepermalink', 'samplepermalinknonce' );
  893. $post_id = isset($_POST['post_id'])? intval($_POST['post_id']) : 0;
  894. $title = isset($_POST['new_title'])? $_POST['new_title'] : '';
  895. $slug = isset($_POST['new_slug'])? $_POST['new_slug'] : '';
  896. die(get_sample_permalink_html($post_id, $title, $slug));
  897. break;
  898. case 'inline-save':
  899. check_ajax_referer( 'inlineeditnonce', '_inline_edit' );
  900. if ( ! isset($_POST['post_ID']) || ! ( $post_ID = (int) $_POST['post_ID'] ) )
  901. exit;
  902. if ( 'page' == $_POST['post_type'] ) {
  903. if ( ! current_user_can( 'edit_page', $post_ID ) )
  904. die( __('You are not allowed to edit this page.') );
  905. } else {
  906. if ( ! current_user_can( 'edit_post', $post_ID ) )
  907. die( __('You are not allowed to edit this post.') );
  908. }
  909. if ( $last = wp_check_post_lock( $post_ID ) ) {
  910. $last_user = get_userdata( $last );
  911. $last_user_name = $last_user ? $last_user->display_name : __( 'Someone' );
  912. printf( $_POST['post_type'] == 'page' ? __( 'Saving is disabled: %s is currently editing this page.' ) : __( 'Saving is disabled: %s is currently editing this post.' ), wp_specialchars( $last_user_name ) );
  913. exit;
  914. }
  915. $data = &$_POST;
  916. $post = get_post( $post_ID, ARRAY_A );
  917. $data['content'] = $post['post_content'];
  918. $data['excerpt'] = $post['post_excerpt'];
  919. // rename
  920. $data['user_ID'] = $GLOBALS['user_ID'];
  921. if ( isset($data['post_parent']) )
  922. $data['parent_id'] = $data['post_parent'];
  923. // status
  924. if ( isset($data['keep_private']) && 'private' == $data['keep_private'] )
  925. $data['post_status'] = 'private';
  926. else
  927. $data['post_status'] = $data['_status'];
  928. if ( empty($data['comment_status']) )
  929. $data['comment_status'] = 'closed';
  930. if ( empty($data['ping_status']) )
  931. $data['ping_status'] = 'closed';
  932. // update the post
  933. $_POST = $data;
  934. edit_post();
  935. $post = array();
  936. if ( 'page' == $_POST['post_type'] ) {
  937. $post[] = get_post($_POST['post_ID']);
  938. page_rows($post);
  939. } elseif ( 'post' == $_POST['post_type'] ) {
  940. $mode = $_POST['post_view'];
  941. $post[] = get_post($_POST['post_ID']);
  942. post_rows($post);
  943. }
  944. exit;
  945. break;
  946. case 'inline-save-tax':
  947. check_ajax_referer( 'taxinlineeditnonce', '_inline_edit' );
  948. if ( ! current_user_can('manage_categories') )
  949. die( __('Cheatin&#8217; uh?') );
  950. if ( ! isset($_POST['tax_ID']) || ! ( $id = (int) $_POST['tax_ID'] ) )
  951. die(-1);
  952. switch ($_POST['tax_type']) {
  953. case 'cat' :
  954. $data = array();
  955. $data['cat_ID'] = $id;
  956. $data['cat_name'] = $_POST['name'];
  957. $data['category_nicename'] = $_POST['slug'];
  958. if ( isset($_POST['parent']) && (int) $_POST['parent'] > 0 )
  959. $data['category_parent'] = $_POST['parent'];
  960. $cat = get_category($id, ARRAY_A);
  961. $data['category_description'] = $cat['category_description'];
  962. $updated = wp_update_category($data);
  963. if ( $updated && !is_wp_error($updated) )
  964. echo _cat_row( $updated, 0 );
  965. else
  966. die( __('Category not updated.') );
  967. break;
  968. case 'link-cat' :
  969. $updated = wp_update_term($id, 'link_category', $_POST);
  970. if ( $updated && !is_wp_error($updated) )
  971. echo link_cat_row($updated['term_id']);
  972. else
  973. die( __('Category not updated.') );
  974. break;
  975. case 'tag' :
  976. if ( !empty($_POST['taxonomy']) )
  977. $taxonomy = $_POST['taxonomy'];
  978. else
  979. $taxonomy = 'post_tag';
  980. $updated = wp_update_term($id, $taxonomy, $_POST);
  981. if ( $updated && !is_wp_error($updated) ) {
  982. $tag = get_term( $updated['term_id'], $taxonomy );
  983. if ( !$tag || is_wp_error( $tag ) )
  984. die( __('Tag not updated.') );
  985. echo _tag_row($tag);
  986. } else {
  987. die( __('Tag not updated.') );
  988. }
  989. break;
  990. }
  991. exit;
  992. break;
  993. case 'find_posts':
  994. check_ajax_referer( 'find-posts' );
  995. if ( empty($_POST['ps']) )
  996. exit;
  997. $what = isset($_POST['pages']) ? 'page' : 'post';
  998. $s = stripslashes($_POST['ps']);
  999. preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
  1000. $search_terms = array_map(create_function('$a', 'return trim($a, "\\"\'\\n\\r ");'), $matches[0]);
  1001. $searchand = $search = '';
  1002. foreach( (array) $search_terms as $term) {
  1003. $term = addslashes_gpc($term);
  1004. $search .= "{$searchand}(($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%'))";
  1005. $searchand = ' AND ';
  1006. }
  1007. $term = $wpdb->escape($s);
  1008. if ( count($search_terms) > 1 && $search_terms[0] != $s )
  1009. $search .= " OR ($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%')";
  1010. $posts = $wpdb->get_results( "SELECT ID, post_title, post_status, post_date FROM $wpdb->posts WHERE post_type = '$what' AND $search ORDER BY post_date_gmt DESC LIMIT 50" );
  1011. if ( ! $posts )
  1012. exit( __('No posts found.') );
  1013. $html = '<table class="widefat"><thead><tr><th class="found-radio"><br /></th><th>'.__('Title').'</th><th>'.__('Time').'</th><th>'.__('Status').'</th></tr></thead><tbody>';
  1014. foreach ( $posts as $post ) {
  1015. switch ( $post->post_status ) {
  1016. case 'publish' :
  1017. case 'private' :
  1018. $stat = __('Published');
  1019. break;
  1020. case 'future' :
  1021. $stat = __('Scheduled');
  1022. break;
  1023. case 'pending' :
  1024. $stat = __('Pending Review');
  1025. break;
  1026. case 'draft' :
  1027. $stat = __('Unpublished');
  1028. break;
  1029. }
  1030. if ( '0000-00-00 00:00:00' == $post->post_date ) {
  1031. $time = '';
  1032. } else {
  1033. $time = mysql2date(__('Y/m/d'), $post->post_date);
  1034. }
  1035. $html .= '<tr class="found-posts"><td class="found-radio"><input type="radio" id="found-'.$post->ID.'" name="found_post_id" value="'.$post->ID.'"></td>';
  1036. $html .= '<td><label for="found-'.$post->ID.'">'.wp_specialchars($post->post_title, true).'</label></td><td>'.wp_specialchars($time, true).'</td><td>'.wp_specialchars($stat, true).'</td></tr>'."\n\n";
  1037. }
  1038. $html .= '</tbody></table>';
  1039. $x = new WP_Ajax_Response();
  1040. $x->add( array(
  1041. 'what' => $what,
  1042. 'data' => $html
  1043. ));
  1044. $x->send();
  1045. break;
  1046. case 'lj-importer' :
  1047. check_ajax_referer( 'lj-api-import' );
  1048. if ( !current_user_can( 'publish_posts' ) )
  1049. die('-1');
  1050. if ( empty( $_POST['step'] ) )
  1051. die( '-1' );
  1052. define('WP_IMPORTING', true);
  1053. include( ABSPATH . 'wp-admin/import/livejournal.php' );
  1054. $result = $lj_api_import->{ 'step' . ( (int) $_POST['step'] ) }();
  1055. if ( is_wp_error( $result ) )
  1056. echo $result->get_error_message();
  1057. die;
  1058. break;
  1059. default :
  1060. do_action( 'wp_ajax_' . $_POST['action'] );
  1061. die('0');
  1062. break;
  1063. endswitch;
  1064. ?>