| @@ -1,17 +1,79 @@ | ||
| 1 | 1 | <?php |
| 2 | +/** | |
| 3 | + * Debugging functions. | |
| 4 | + * | |
| 5 | + * @package Activitypub | |
| 6 | + */ | |
| 7 | + | |
| 2 | 8 | namespace Activitypub; |
| 3 | 9 | |
| 4 | 10 | /** |
| 5 | 11 | * Allow localhost URLs if WP_DEBUG is true. |
| 6 | 12 | * |
| 7 | - * @param array $r Array of HTTP request args. | |
| 8 | - * @param string $url The request URL. | |
| 13 | + * @param array $parsed_args An array of HTTP request arguments. | |
| 9 | 14 | * |
| 10 | 15 | * @return array Array or string of HTTP request arguments. |
| 11 | 16 | */ |
| 12 | -function allow_localhost( $r, $url ) { | |
| 13 | - $r['reject_unsafe_urls'] = false; | |
| 17 | +function allow_localhost( $parsed_args ) { | |
| 18 | + $parsed_args['reject_unsafe_urls'] = false; | |
| 14 | 19 | |
| 15 | - return $r; | |
| 20 | + return $parsed_args; | |
| 16 | 21 | } |
| 17 | -add_filter( 'http_request_args', '\Activitypub\allow_localhost', 10, 2 ); | |
| 22 | +\add_filter( 'http_request_args', '\Activitypub\allow_localhost' ); | |
| 23 | + | |
| 24 | +/** | |
| 25 | + * Debug the outbox post type. | |
| 26 | + * | |
| 27 | + * @param array $args The arguments for the post type. | |
| 28 | + * @param string $post_type The post type. | |
| 29 | + * | |
| 30 | + * @return array The arguments for the post type. | |
| 31 | + */ | |
| 32 | +function debug_outbox_post_type( $args, $post_type ) { | |
| 33 | + if ( 'ap_outbox' !== $post_type ) { | |
| 34 | + return $args; | |
| 35 | + } | |
| 36 | + | |
| 37 | + $args['show_ui'] = true; | |
| 38 | + $args['menu_icon'] = 'dashicons-upload'; | |
| 39 | + | |
| 40 | + return $args; | |
| 41 | +} | |
| 42 | +\add_filter( 'register_post_type_args', '\Activitypub\debug_outbox_post_type', 10, 2 ); | |
| 43 | + | |
| 44 | +/** | |
| 45 | + * Debug the outbox post type column. | |
| 46 | + * | |
| 47 | + * @param array $columns The columns. | |
| 48 | + * @param string $post_type The post type. | |
| 49 | + * | |
| 50 | + * @return array The updated columns. | |
| 51 | + */ | |
| 52 | +function debug_outbox_post_type_column( $columns, $post_type ) { | |
| 53 | + if ( 'ap_outbox' !== $post_type ) { | |
| 54 | + return $columns; | |
| 55 | + } | |
| 56 | + | |
| 57 | + $columns['ap_outbox_meta'] = 'Meta'; | |
| 58 | + | |
| 59 | + return $columns; | |
| 60 | +} | |
| 61 | +\add_filter( 'manage_posts_columns', '\Activitypub\debug_outbox_post_type_column', 10, 2 ); | |
| 62 | + | |
| 63 | +/** | |
| 64 | + * Debug the outbox post type meta. | |
| 65 | + * | |
| 66 | + * @param string $column_name The column name. | |
| 67 | + * @param int $post_id The post ID. | |
| 68 | + * | |
| 69 | + * @return void | |
| 70 | + */ | |
| 71 | +function manage_posts_custom_column( $column_name, $post_id ) { | |
| 72 | + if ( 'ap_outbox_meta' === $column_name ) { | |
| 73 | + $meta = \get_post_meta( $post_id ); | |
| 74 | + foreach ( $meta as $key => $value ) { | |
| 75 | + echo \esc_attr( $key ) . ': ' . \esc_html( $value[0] ) . '<br>'; | |
| 76 | + } | |
| 77 | + } | |
| 78 | +} | |
| 79 | +\add_action( 'manage_posts_custom_column', '\Activitypub\manage_posts_custom_column', 10, 2 ); | |