Oops, This Page Could Not Be Found!
Helpful Links
Search Our Website
Can't find what you need? Take a moment and do a search below!
/** * Posting Diagnostics Logger (stores last ~200 events in wp_options). */ function ucmr_log_posting_attempt( $platform, $attempt ) { $platform = sanitize_key( (string) $platform ); if ( empty( $platform ) ) { $platform = 'unknown'; } $opts = get_option( 'ucmr_options', [] ); $debug_enabled = ! empty( $opts['debug_enabled'] ); $attempt = is_array( $attempt ) ? $attempt : []; $attempt['platform'] = $platform; $attempt['ts'] = $attempt['ts'] ?? time(); // Truncate body unless debug enabled if ( ! $debug_enabled && isset( $attempt['body'] ) ) { $attempt['body'] = substr( (string) $attempt['body'], 0, 500 ); } $logs = get_option( 'ucmr_posting_logs', [] ); if ( ! is_array( $logs ) ) { $logs = []; } array_unshift( $logs, $attempt ); $logs = array_slice( $logs, 0, 200 ); update_option( 'ucmr_posting_logs', $logs, false ); if ( $debug_enabled ) { error_log( '[UCMR][POSTLOG] ' . wp_json_encode( $attempt ) ); } } function ucmr_get_posting_logs() { $logs = get_option( 'ucmr_posting_logs', [] ); return is_array( $logs ) ? $logs : []; } /** * Capture HTTP API responses for supported social endpoints (posting + test calls). * This powers Posting Diagnostics without rewriting each platform client. */ function ucmr_http_api_debug_logger( $response, $context, $class, $args, $url ) { if ( empty( $url ) || ! is_string( $url ) ) { return; } $host = parse_url( $url, PHP_URL_HOST ); if ( empty( $host ) ) { return; } $platform = ''; if ( strpos( $host, 'api.twitter.com' ) !== false ) { $platform = 'x'; } elseif ( strpos( $host, 'graph.facebook.com' ) !== false ) { $platform = 'facebook'; } elseif ( strpos( $host, 'api.linkedin.com' ) !== false ) { $platform = 'linkedin'; } elseif ( strpos( $host, 'googleapis.com' ) !== false ) { $platform = 'youtube'; } elseif ( strpos( $host, 'open-api.tiktok.com' ) !== false || strpos( $host, 'tiktokapis.com' ) !== false ) { $platform = 'tiktok'; } if ( empty( $platform ) ) { return; } $code = 0; $body = ''; if ( is_wp_error( $response ) ) { $body = $response->get_error_message(); } elseif ( is_array( $response ) ) { $code = (int) wp_remote_retrieve_response_code( $response ); $body = (string) wp_remote_retrieve_body( $response ); } // Only log responses (not request context) if ( $context !== 'response' ) { return; } if ( function_exists('ucmr_log_posting_attempt') ) { ucmr_log_posting_attempt( $platform, [ 'kind' => 'http', 'summary' => $args['method'] ?? 'HTTP', 'code' => $code, 'body' => $body, 'url' => $url, ] ); } } add_action( 'http_api_debug', 'ucmr_http_api_debug_logger', 10, 5 );
Can't find what you need? Take a moment and do a search below!