PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 All 503 releases
jetpack / extensions / blocks / blogroll / blogroll.php

blogroll.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3-a.1, at extensions/blocks/blogroll/blogroll.php

124 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Blogroll Block.
4 *
5 * @since 12.1
6 *
7 * @package automattic/jetpack
8 */
9
10 namespace Automattic\Jetpack\Extensions\Blogroll;
11
12 require_once __DIR__ . '/blogroll-item/blogroll-item.php';
13
14 use Automattic\Jetpack\Blocks;
15 use Automattic\Jetpack\Status\Request;
16 use Jetpack_Gutenberg;
17
18 /**
19 * Registers the block for use in Gutenberg
20 * This is done via an action so that we can disable
21 * registration if we need to.
22 */
23 function register_block() {
24 Blocks::jetpack_register_block(
25 __DIR__,
26 array(
27 'render_callback' => __NAMESPACE__ . '\load_assets',
28 'provides_context' => array(
29 'openLinksNewWindow' => 'open_links_new_window',
30 ),
31 )
32 );
33 }
34 add_action( 'init', __NAMESPACE__ . '\register_block' );
35
36 /**
37 * Blogroll block registration/dependency declaration.
38 *
39 * @param array $attr Array containing the Blogroll block attributes.
40 * @param string $content String containing the Blogroll block content.
41 *
42 * @return string
43 */
44 function load_assets( $attr, $content ) {
45 global $wp;
46
47 /*
48 * Enqueue necessary scripts and styles.
49 */
50 Jetpack_Gutenberg::load_assets_as_required( __DIR__ );
51 $current_location = home_url( $wp->request );
52 $is_wpcom = ( defined( 'IS_WPCOM' ) && IS_WPCOM );
53
54 $form_content = <<<HTML
55 <form method="post" action="https://subscribe.wordpress.com" accept-charset="utf-8">
56 <input name="action" type="hidden" value="subscribe">
57 <input name="source" type="hidden" value="$current_location">
58 <input name="sub-type" type="hidden" value="jetpack_blogroll">
59 $content
60 </form>
61 HTML;
62
63 $blogroll_content = $is_wpcom && Request::is_frontend() ? $form_content : $content;
64
65 return sprintf(
66 '<div class="%1$s">%2$s</div>',
67 esc_attr( Blocks::classes( FEATURE_NAME, $attr ) ),
68 $blogroll_content
69 );
70 }
71
72 /**
73 * Register site_recommendations settings
74 *
75 * @since 12.7
76 */
77 function site_recommendations_settings() {
78 register_setting(
79 'general',
80 'Blogroll Recommendations', // Visible to the user see: https://github.com/WordPress/gutenberg/issues/41637
81 array(
82 'description' => __( 'Site Recommendations', 'jetpack' ),
83 'type' => 'array',
84 'show_in_rest' => array(
85 'schema' => array(
86 'items' => array(
87 'type' => 'object',
88 'properties' => array(
89 'id' => array(
90 'type' => 'string',
91 'format' => 'text-field',
92 ),
93 'name' => array(
94 'type' => 'string',
95 'format' => 'text-field',
96 ),
97 'icon' => array(
98 'type' => 'string',
99 'format' => 'uri',
100 ),
101 'url' => array(
102 'type' => 'string',
103 'format' => 'uri',
104 ),
105 'description' => array(
106 'type' => 'string',
107 'format' => 'text-field',
108 ),
109 'is_non_wpcom_site' => array(
110 'type' => 'boolean',
111 ),
112 ),
113 ),
114 ),
115 ),
116 'auth_callback' => function () {
117 return current_user_can( 'edit_posts' );
118 },
119 )
120 );
121 }
122
123 add_action( 'rest_api_init', __NAMESPACE__ . '\site_recommendations_settings' );
124