Completed
Push — try/block-editor-iframe ( 300600 )
by Kirk
32:35 queued 25:44
created

wordpress-com-compose.php ➔ jetpack_get_frame_nonce()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Module Name: WordPress.com Compose
4
 * Module Description: Allow new block editor posts to be composed on WordPress.com.
5
 * Jumpstart Description: Allow new block editor posts to be composed on WordPress.com.
6
 * Sort Order: 15
7
 * First Introduced: 7.2
8
 * Requires Connection: Yes
9
 * Auto Activate: No
10
 * Module Tags: Writing
11
 * Feature: Writing
12
 * Additional Search Queries: iframes, allow, compose, WordPress.com, block
13
 */
14
15
function jetpack_disable_send_frame_options_header() {
16
	if ( jetpack_framing_allowed() ) {
17
		remove_action( 'admin_init', 'send_frame_options_header' );
18
	}
19
}
20
add_action( 'admin_init', 'jetpack_disable_send_frame_options_header', 1 ); // High priority to get ahead of send_frame_options_header
21
22
function jetpack_get_frame_nonce() {
23
	return wp_create_nonce( 'frame-' . Jetpack_Options::get_option( 'id' ) );
24
}
25
26
function jetpack_framing_allowed() {
27
	if ( empty( $_GET['frame-nonce'] ) ) {
28
		return false;
29
	}
30
31
	$verified = wp_verify_nonce( $_GET['frame-nonce'], 'frame-' . Jetpack_Options::get_option( 'id' ) );
32
33
	if ( $verified ) {
34
		define( 'IFRAME_REQUEST', true );
35
		return true;
36
	}
37
	return false;
38
}
39
40
/**
41
 * Automatically add frame-nonce to any admin_url() calls when the current page is framed.
42
 */
43
function jetpack_auto_frame_nonce( $url ) {
44
	if ( jetpack_framing_allowed() ) {
45
		$url = add_query_arg( array( 'frame-nonce' => jetpack_get_frame_nonce() ), $url );
46
	}
47
	return $url;
48
}
49
add_filter( 'admin_url', 'jetpack_auto_frame_nonce' );
50
51
function jetpack_add_iframed_body_class( $classes ) {
52
	if ( jetpack_framing_allowed() ) {
53
		$classes .= ' is-iframed ';
54
	}
55
	return $classes;
56
}
57
add_filter( 'admin_body_class', 'jetpack_add_iframed_body_class' );
58