|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is included only if WordPress is set in DEBUG mode and provides |
|
4
|
|
|
* debugging features. |
|
5
|
|
|
* |
|
6
|
|
|
* @since 3.7.2 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Define the Wordlift_Debug_Service class. |
|
11
|
|
|
* |
|
12
|
|
|
* @since 3.7.2 |
|
13
|
|
|
*/ |
|
14
|
|
|
class Wordlift_Debug_Service { |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* The {@link Wordlift_Entity_Service} instance. |
|
18
|
|
|
* |
|
19
|
|
|
* @since 3.7.2 |
|
20
|
|
|
* @access private |
|
21
|
|
|
* @var Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
22
|
|
|
*/ |
|
23
|
|
|
private $entity_service; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Wordlift_Debug_Service constructor. |
|
27
|
|
|
* |
|
28
|
|
|
* @since 3.7.2 |
|
29
|
|
|
* |
|
30
|
|
|
* @param Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct( $entity_service ) { |
|
33
|
|
|
|
|
34
|
|
|
$this->entity_service = $entity_service; |
|
35
|
|
|
|
|
36
|
|
|
add_action( 'wp_ajax_wl_dump_uri', array( $this, 'dump_uri' ) ); |
|
37
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function dump_uri() { |
|
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
if ( ! isset( $_GET['id'] ) ) { |
|
43
|
|
|
wp_send_json_error( 'id not set' ); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$post_id = $_GET['id']; |
|
47
|
|
|
|
|
48
|
|
|
$post = get_post( $post_id ); |
|
49
|
|
|
|
|
50
|
|
|
$uri = $this->entity_service->get_uri( $post_id ); |
|
51
|
|
|
$encoding = mb_detect_encoding( $uri ); |
|
|
|
|
|
|
52
|
|
|
$build_uri = $this->entity_service->build_uri( $post->post_title, $post->post_type ); |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
var_dump( $uri ); |
|
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
wp_send_json_success( array( |
|
58
|
|
|
'uri' => $uri, |
|
59
|
|
|
'post_title' => sprintf( '%s (%s)', $post->post_title, mb_detect_encoding( $post->post_title ) ), |
|
60
|
|
|
'post_title_ascii' => mb_convert_encoding( $post->post_title, 'ASCII' ), |
|
61
|
|
|
'build_uri' => $build_uri, |
|
62
|
|
|
'build_uri_convert' => mb_convert_encoding( $build_uri, 'ASCII' ), |
|
63
|
|
|
) ); |
|
64
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
} |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: