From fac77d8a8a9edf2ce4fd6d128701d8dd5b003f09 Mon Sep 17 00:00:00 2001 From: siddhantdante Date: Sun, 13 Sep 2020 11:58:45 +0530 Subject: [PATCH] all page sync fix --- Wordpress Plugin/utils/monday-functions.php | 59 +++++++++++++++++++ Wordpress Plugin/utils/post-synch.php | 63 ++------------------- 2 files changed, 64 insertions(+), 58 deletions(-) diff --git a/Wordpress Plugin/utils/monday-functions.php b/Wordpress Plugin/utils/monday-functions.php index 55bda10..4dfeb24 100644 --- a/Wordpress Plugin/utils/monday-functions.php +++ b/Wordpress Plugin/utils/monday-functions.php @@ -406,4 +406,63 @@ function keys_refresh() { add_action( 'wp_ajax_keys_refresh', 'keys_refresh' ); +//create page or post +function process_post_or_page( $type, $board_id ) { + $args = array( + 'numberposts' => - 1, + 'post_type' => array( $type ), + 'orderby' => 'title', + 'order' => 'ASC', + 'post_status' => array( 'pending', 'draft', 'future', 'publish' ) + ); + + $posts_array = get_posts( $args ); + + foreach ( $posts_array as $post ) { + + //sync post comments + //sync_post_comments( $post->ID ); + + // get post tags + $tags = get_post_tags_array( $post->ID ); + + // get post categories + $categories = get_post_categories_array( $post->ID ); + + if ( $post->post_status == 'publish' ) { + $status = 1; + } else { + $status = 0; + } + + if ( empty( get_monday_user_id( $post->post_author ) ) ) { + $authors = array(); + } else { + $authors = array( + array( + 'id' => get_monday_user_id( $post->post_author ), + 'kind' => 'person' + ) + ); + } + + $post_array = array( + 'name' => $post->post_title, + 'author' => array( + 'personsAndTeams' => $authors + ), + 'tags' => array( 'tag_ids' => $tags ), + 'category' => array( 'tag_ids' => $categories ), + 'status' => array( 'index' => $status ), + 'date' => array( + 'date' => get_the_date( 'Y-m-d', $post->ID ), + 'time' => get_the_time( 'G:i:s', $post->ID ) + ), + 'post_link' => array( 'url' => get_post_permalink( $post->ID ), 'text' => $post->post_title ), + ); + + update_or_create_content_auto_synch( $board_id, $post_array, $post ); + + } +} diff --git a/Wordpress Plugin/utils/post-synch.php b/Wordpress Plugin/utils/post-synch.php index 821d2cc..6df0280 100644 --- a/Wordpress Plugin/utils/post-synch.php +++ b/Wordpress Plugin/utils/post-synch.php @@ -12,70 +12,17 @@ function sync_post() { //for create post subscription foreach ( get_board_ids( 'create_post' ) as $board_id ) { - $args = array( - 'numberposts' => - 1, - 'post_type' => array( 'post' ), - 'orderby' => 'title', - 'order' => 'ASC', - 'post_status' => array( 'pending', 'draft', 'future', 'publish' ) - ); - $posts_array = get_posts( $args ); + process_post_or_page( 'post', $board_id ); - foreach ( $posts_array as $post ) { - - //sync post comments - //sync_post_comments( $post->ID ); - - // get post tags - $tags = get_post_tags_array( $post->ID ); - - // get post categories - $categories = get_post_categories_array( $post->ID ); - - if ( $post->post_status == 'publish' ) { - $status = 1; - } else { - $status = 0; - } - - if ( empty( get_monday_user_id( $post->post_author ) ) ) { - $authors = array(); - } else { - $authors = array( - array( - 'id' => get_monday_user_id( $post->post_author ), - 'kind' => 'person' - ) - ); - } - - $post_array = array( - 'name' => $post->post_title, - 'author' => array( - 'personsAndTeams' => $authors - ), - 'tags' => array( 'tag_ids' => $tags ), - 'category' => array( 'tag_ids' => $categories ), - 'status' => array( 'index' => $status ), - 'date' => array( - 'date' => get_the_date( 'Y-m-d', $post->ID ), - 'time' => get_the_time( 'G:i:s', $post->ID ) - ), - 'post_link' => array( 'url' => get_post_permalink( $post->ID ), 'text' => $post->post_title ), - ); + } - update_or_create_content_auto_synch( $board_id, $post_array, $post ); + //for create page subscription + foreach ( get_board_ids( 'create_page' ) as $board_id ) { - } + process_post_or_page( 'page', $board_id ); } - //for create page subscription -// foreach ( get_board_ids( 'create_page' ) as $board_id ) { -// -// -// } - die(); }