public function tick()
 {
     $posts_array = $this->sitemap->get_all_posts_in_order();
     foreach ($posts_array as $post) {
         $slug = $this->return_slug($post);
         $slug = sanitize_title($slug);
         $post_object = get_page_by_path($slug, 'OBJECT', 'post');
         if (!$post_object) {
             try {
                 $check = Sync::importUrl($post);
             } catch (Exception $e) {
                 $error_message = $e->getMessage();
                 return $this->notify->error($error_message);
             }
             if ($check->success) {
                 $this->notify->post_import_complete($check->post->id);
                 print_r($check);
             } else {
                 print_r($check);
             }
         }
     }
 }
コード例 #2
0
<?php

namespace AgreableCatfishImporterPlugin;

use AgreableCatfishImporterPlugin\Services\Sync;
set_time_limit(0);
add_action('wp_ajax_catfishimporter_start_sync-category', function () {
    $response = Sync::importCategory($_POST['catfishimporter_category_sitemap'], $_POST['catfishimporter_limit']);
    catfishimporter_api_response($response);
});
add_action('wp_ajax_catfishimporter_start_sync-url', function () {
    $response = Sync::importUrl($_POST['catfishimporter_url']);
    catfishimporter_api_response($response);
});
add_action('wp_ajax_catfishimporter_list_categories', function () {
    $response = Sync::getCategories();
    catfishimporter_api_response($response);
});
function catfishimporter_api_response($response)
{
    header('Content-type: Application/json');
    echo json_encode($response);
    exit;
}