11<?php
2+ /**
3+ * Auto-distribution functionality for Distributor.
4+ *
5+ * @package distributor
6+ */
27
38namespace Distributor \AutoDistribute ;
49
10+ /**
11+ * Setup actions and filters.
12+ *
13+ * @since x.x.x
14+ */
515function setup () {
616 $ n = function ( $ function ) {
717 return __NAMESPACE__ . "\\$ function " ;
@@ -41,7 +51,7 @@ function setup() {
4151 * including both internal and external connections.
4252 *
4353 * @param int|WP_Post $post Post ID or WP_Post object.
44- * @param int $user_id User ID of the post author. Defaults to current user.
54+ * @param int $user_id User ID of the post author. Defaults to current user.
4555 */
4656function schedule_post_for_auto_distribution ( $ post = 0 , $ user_id = 0 ) {
4757 $ post = get_post ( $ post );
@@ -69,7 +79,7 @@ function schedule_post_for_auto_distribution( $post = 0, $user_id = 0 ) {
6979 * and distributes the post to each connection that is not already syndicated.
7080 *
7181 * @param int|WP_Post $post Post ID or WP_Post object.
72- * @param int $user_id User ID of the post author.
82+ * @param int $user_id User ID of the post author.
7383 */
7484function distribute_post_to_all_connections ( $ post = 0 , $ user_id = 0 ) {
7585 $ post = get_post ( $ post );
@@ -83,12 +93,12 @@ function distribute_post_to_all_connections( $post = 0, $user_id = 0 ) {
8393 return ;
8494 }
8595
86- foreach ( $ connections as $ connection ) {
96+ foreach ( $ connections as $ connection ) {
8797 if ( $ connection ['syndicated ' ] ) {
8898 continue ;
8999 }
90100
91- $ connection_id = $ connection ['id ' ];
101+ $ connection_id = $ connection ['id ' ];
92102 $ connection_type = $ connection ['type ' ];
93103
94104 distribute_post ( $ post ->ID , $ user_id , $ connection_id , $ connection_type );
@@ -121,16 +131,16 @@ function distribute_post( $post_id = 0, $user_id = 0, $connection_id = 0, $conne
121131 return ; // Invalid connection type
122132 }
123133
124- $ post_id = $ post ->ID ;
134+ $ post_id = $ post ->ID ;
125135 $ connection_map = get_post_meta ( intval ( $ post_id ), 'dt_connection_map ' , true );
126136 if ( ! is_array ( $ connection_map ) ) {
127137 $ connection_map = [];
128138 }
129- if ( empty ( $ connection_map [ 'internal ' ] ) ) {
130- $ connection_map [ 'internal ' ] = [];
139+ if ( empty ( $ connection_map ['internal ' ] ) ) {
140+ $ connection_map ['internal ' ] = [];
131141 }
132- if ( empty ( $ connection_map [ 'external ' ] ) ) {
133- $ connection_map [ 'external ' ] = [];
142+ if ( empty ( $ connection_map ['external ' ] ) ) {
143+ $ connection_map ['external ' ] = [];
134144 }
135145 $ remote_post = $ connection ->push ( $ post_id );
136146 if ( ! is_wp_error ( $ remote_post ) && ! empty ( $ remote_post ['id ' ] ) ) {
@@ -173,6 +183,7 @@ function get_external_connections( $post_id = 0, $user_id = 0 ) {
173183 'post_type ' => 'dt_ext_connection ' ,
174184 'fields ' => 'ids ' ,
175185 'no_found_rows ' => true ,
186+ // phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page -- All connections need to be fetched.
176187 'posts_per_page ' => 550 ,
177188 ]
178189 );
@@ -258,7 +269,7 @@ function get_internal_connections( $post_id = 0, $user_id = 0 ) {
258269 }
259270
260271 // Get our current connection mapping
261- $ connection_map = (array ) get_post_meta ( $ post_id , 'dt_connection_map ' , true );
272+ $ connection_map = (array ) get_post_meta ( $ post_id , 'dt_connection_map ' , true );
262273 if ( empty ( $ connection_map ['internal ' ] ) ) {
263274 $ connection_map ['internal ' ] = [];
264275 }
0 commit comments