• Hopefully this is the correct section to ask this question. It’s not your normal type situation, but unique to me. I have several hundred blogs that are part of a large group PBN. Members can post to any of the blogs in the PBN when logged on to the PBN’s home site backend, using the posting s/ware hosted there. Posting was via xmlrpc.

    All posts when made are set to “publish” but I wanted to review all posts made to my blogs by members before publishing. So to do so, I changed the line (5036) in class-wp-xmlrpc-server.php under the

    do_action( 'xmlrpc_call', 'blogger.newPost' ); section from $post_status = ( $publish ) ? ‘publish’ : ‘draft’; to $post_status = ( $publish ) ? ‘draft’ : ‘publish’;

    On a daily basis I retrieve all posts marked as “draft” across all blogs, using my PBN management s/ware. Once I’ve checked all the posts, I then set them all to “publish”, again through my management s/ware. This has worked perfectly for past 10 years.

    But last week the decision was made to make posts using the REST API. So now I’m looking for a way to do the same as I’d done with xlmrpc, i.e. set “publish” to “draft”

    Now I’ve searched through a lot files, made some experimentation, but have failed to find a solution.

    Note I’m no coder, and just have enough understanding to get me by. But the API has me stumped. I’m hoping some one could point me to the code that would need to be modified, if it can be at all. I’ve been focusing on the “post.php” & “class-wp-rest-posts-controller.php” files to no avail.

    TIA for any help forthcoming
    Steve

    • This topic was modified 5 years, 1 month ago by Avo.
    • This topic was modified 5 years, 1 month ago by Avo.
    • This topic was modified 5 years, 1 month ago by Avo.
    • This topic was modified 5 years, 1 month ago by Avo.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Use the wp_insert_post_data filter to alter post statuses. It’s going to require that you write some code to do so. It’s not a simple modify existing code exercise. Maybe you’ll be able to find some examples to start from. This filter is applied to all post insertions or updates. You’ll need to apply conditions to only alter the posts that should be altered.

    You shouldn’t modify existing core files like you did for the XML-RPC server code. Sure, it works, but you either have to re-apply your change after updates or forego updates. Neither are good solutions. Filter and action hooks are the proper way to alter WP functionality. Code utilizing hooks can be placed in a simple custom plugin.

    Thread Starter Avo

    (@avo)

    Thanks, so I’d need to make modifications in the class-wp-rest-posts-controller.php then?

    I did add to line 1018 of that file $prepared_post->post_status = ( $status == 'publish' ) ? 'draft' : $status; but doesn’t seem to work

    Moderator bcworkz

    (@bcworkz)

    No, please don’t modify core code files. Make a simple custom plugin, it’s easier than it sounds. On your plugin page, hook the aforementioned action. Create a callback function for that action hook. Your function is passed an array of post data. Verify the passed post data is a post you want to modify and the current user is not someone who should be able to publish. Assign the desired value to the “post_status” array element, then return the entire modified array.

    ETA: Why don’t you make those user’s role “contributor”? Contributors can write posts, but they cannot publish. Then you don’t need any custom code to review posts before publishing.

    • This reply was modified 5 years, 1 month ago by bcworkz.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Bulk Change Posts from Published to Draft Across Multiple Sites’ is closed to new replies.