PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.4.0-beta2
Secure Custom Fields v6.4.0-beta2
6.9.5 6.9.4 6.9.3 6.9.2 6.9.1 6.9.0 6.8.9 6.8.7 6.8.8 6.8.6 6.8.4 6.8.5 trunk 6.4.0-beta1 6.4.0-beta2 6.4.1 6.4.1-beta3 6.4.1-beta4 6.4.1-beta5 6.4.1-beta6 6.4.1-beta7 6.4.2 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.5.5 6.5.6 6.5.7 6.6.0 6.7.0 6.7.1 6.8.0 6.8.1 6.8.2 6.8.3
secure-custom-fields / includes / ajax / class-acf-ajax-local-json-diff.php
secure-custom-fields / includes / ajax Last commit date
class-acf-ajax-check-screen.php 1 year ago class-acf-ajax-local-json-diff.php 1 year ago class-acf-ajax-query-users.php 1 year ago class-acf-ajax-query.php 1 year ago class-acf-ajax-upgrade.php 1 year ago class-acf-ajax-user-setting.php 1 year ago class-acf-ajax.php 1 year ago index.php 1 year ago
class-acf-ajax-local-json-diff.php
104 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly
5 }
6
7 if ( ! class_exists( 'ACF_Ajax_Local_JSON_Diff' ) ) :
8
9 class ACF_Ajax_Local_JSON_Diff extends ACF_Ajax {
10
11 /**
12 * The AJAX action name.
13 *
14 * @var string
15 */
16 public $action = 'acf/ajax/local_json_diff';
17
18 /**
19 * Prevents access for non-logged in users.
20 *
21 * @var boolean
22 */
23 public $public = false;
24
25 /**
26 * Returns the response data to sent back.
27 *
28 * @date 31/7/18
29 * @since 5.7.2
30 *
31 * @param array $request The request args.
32 * @return array|WP_Error The response data or WP_Error.
33 */
34 public function get_response( $request ) {
35 // Bail early if the current user can't access the ACF admin.
36 if ( ! acf_current_user_can_admin() ) {
37 return new WP_Error( 'acf_not_allowed', __( 'Sorry, you do not have permission to do that.', 'acf' ), array( 'status' => 403 ) );
38 }
39
40 $json = array();
41
42 // Extract props.
43 $id = isset( $request['id'] ) ? intval( $request['id'] ) : 0;
44
45 // Bail early if missing props.
46 if ( ! $id ) {
47 return new WP_Error( 'acf_invalid_param', __( 'Invalid field group parameter(s).', 'acf' ), array( 'status' => 404 ) );
48 }
49
50 $post_type = get_post_type( $id );
51 if ( ! in_array( $post_type, acf_get_internal_post_types(), true ) ) {
52 return new WP_Error( 'acf_invalid_post_type', __( 'Invalid post type selected for review.', 'acf' ), array( 'status' => 404 ) );
53 }
54
55 // Disable filters and load the post directly from database.
56 acf_disable_filters();
57
58 $post = acf_get_internal_post_type( $id, $post_type );
59 if ( ! $post ) {
60 return new WP_Error( 'acf_invalid_id', __( 'Invalid post ID.', 'acf' ), array( 'status' => 404 ) );
61 }
62
63 // Field groups also load in fields.
64 if ( 'acf-field-group' === $post_type ) {
65 $post['fields'] = acf_get_fields( $post );
66 }
67
68 $post['modified'] = get_post_modified_time( 'U', true, $post['ID'] );
69 $post = acf_prepare_internal_post_type_for_export( $post, $post_type );
70
71 // Load local field group file.
72 $files = acf_get_local_json_files( $post_type );
73 $key = $post['key'];
74 if ( ! isset( $files[ $key ] ) ) {
75 return new WP_Error( 'acf_cannot_compare', __( 'Sorry, this post is unavailable for diff comparison.', 'acf' ), array( 'status' => 404 ) );
76 }
77 $local_post = json_decode( file_get_contents( $files[ $key ] ), true );
78
79 // Render diff HTML.
80 $date_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
81 $date_template = __( 'Last updated: %s', 'acf' );
82 $json['html'] = '
83 <div class="acf-diff">
84 <div class="acf-diff-title">
85 <div class="acf-diff-title-left">
86 <strong>' . __( 'Original', 'acf' ) . '</strong>
87 <span>' . sprintf( $date_template, wp_date( $date_format, $post['modified'] ) ) . '</span>
88 </div>
89 <div class="acf-diff-title-right">
90 <strong>' . __( 'JSON (newer)', 'acf' ) . '</strong>
91 <span>' . sprintf( $date_template, wp_date( $date_format, $local_post['modified'] ) ) . '</span>
92 </div>
93 </div>
94 <div class="acf-diff-content">
95 ' . wp_text_diff( acf_json_encode( $post ), acf_json_encode( $local_post ) ) . '
96 </div>
97 </div>';
98 return $json;
99 }
100 }
101
102 acf_new_instance( 'ACF_Ajax_Local_JSON_Diff' );
103 endif; // class_exists check
104