1 | <?php |
||
43 | class Tracks_Client { |
||
44 | const PIXEL = 'http://pixel.wp.com/t.gif'; |
||
45 | const BROWSER_TYPE = 'php-agent'; |
||
46 | const USER_AGENT_SLUG = 'tracks-client'; |
||
47 | const VERSION = '0.3'; |
||
48 | |||
49 | /** |
||
50 | * record_event |
||
51 | * @param mixed $event Event object to send to Tracks. An array will be cast to object. Required. |
||
52 | * Properties are included directly in the pixel query string after light validation. |
||
53 | * @return mixed True on success, WP_Error on failure |
||
54 | */ |
||
55 | static function record_event( $event ) { |
||
71 | |||
72 | /** |
||
73 | * Synchronously request the pixel |
||
74 | */ |
||
75 | static function record_pixel( $pixel ) { |
||
76 | // Add the Request Timestamp and URL terminator just before the HTTP request. |
||
77 | $pixel .= '&_rt=' . self::build_timestamp() . '&_=_'; |
||
78 | |||
79 | $response = wp_remote_get( $pixel, array( |
||
80 | 'blocking' => true, // The default, but being explicit here :) |
||
81 | 'timeout' => 1, |
||
82 | 'redirection' => 2, |
||
83 | 'httpversion' => '1.1', |
||
84 | 'user-agent' => self::get_user_agent(), |
||
85 | ) ); |
||
86 | |||
87 | if ( is_wp_error( $response ) ) { |
||
88 | return $response; |
||
89 | } |
||
90 | |||
91 | $code = isset( $response['response']['code'] ) ? $response['response']['code'] : 0; |
||
92 | |||
93 | if ( $code !== 200 ) { |
||
94 | return new WP_Error( 'request_failed', 'Tracks pixel request failed', $code ); |
||
95 | } |
||
96 | |||
97 | return true; |
||
98 | } |
||
99 | |||
100 | static function get_user_agent() { |
||
103 | |||
104 | /** |
||
105 | * Build an event and return its tracking URL |
||
106 | * @deprecated Call the `build_pixel_url` method on a Tracks_Event object instead. |
||
107 | * @param array $event Event keys and values |
||
108 | * @return string URL of a tracking pixel |
||
109 | */ |
||
110 | static function build_pixel_url( $event ) { |
||
114 | |||
115 | /** |
||
116 | * Validate input for a tracks event. |
||
117 | * @deprecated Instantiate a Tracks_Event object instead |
||
118 | * @param array $event Event keys and values |
||
119 | * @return mixed Validated keys and values or WP_Error on failure |
||
120 | */ |
||
121 | private static function validate_and_sanitize( $event ) { |
||
122 | $_event = new Tracks_Event( $event ); |
||
123 | if ( is_wp_error( $_event ) ) { |
||
124 | return $_event; |
||
125 | } |
||
126 | return get_object_vars( $_event ); |
||
127 | } |
||
128 | |||
129 | // Milliseconds since 1970-01-01 |
||
130 | static function build_timestamp() { |
||
134 | |||
135 | /** |
||
136 | * Grabs the user's anon id from cookies, or generates and sets a new one |
||
137 | * |
||
138 | * @return string An anon id for the user |
||
139 | */ |
||
140 | static function get_anon_id() { |
||
168 | } |
||
169 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.