| @@ -11,8 +11,9 @@ | ||
| 11 | 11 | |
| 12 | 12 | require_once __DIR__ . '/blogroll-item/blogroll-item.php'; |
| 13 | 13 | |
| 14 | 14 | use Automattic\Jetpack\Blocks; |
| 15 | +use Automattic\Jetpack\Status\Request; | |
| 15 | 16 | use Jetpack_Gutenberg; |
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | 19 | * Registers the block for use in Gutenberg |
| @@ -24,10 +25,9 @@ | ||
| 24 | 25 | __DIR__, |
| 25 | 26 | array( |
| 26 | 27 | 'render_callback' => __NAMESPACE__ . '\load_assets', |
| 27 | 28 | 'provides_context' => array( |
| 28 | - 'showSubscribeButton' => 'show_subscribe_button', | |
| 29 | - 'openLinksNewWindow' => 'open_links_new_window', | |
| 29 | + 'openLinksNewWindow' => 'open_links_new_window', | |
| 30 | 30 | ), |
| 31 | 31 | ) |
| 32 | 32 | ); |
| 33 | 33 | } |
| @@ -41,15 +41,83 @@ | ||
| 41 | 41 | * |
| 42 | 42 | * @return string |
| 43 | 43 | */ |
| 44 | 44 | function load_assets( $attr, $content ) { |
| 45 | + global $wp; | |
| 46 | + | |
| 45 | 47 | /* |
| 46 | 48 | * Enqueue necessary scripts and styles. |
| 47 | 49 | */ |
| 48 | 50 | Jetpack_Gutenberg::load_assets_as_required( __DIR__ ); |
| 51 | + $current_location = home_url( $wp->request ); | |
| 52 | + $is_wpcom = ( defined( 'IS_WPCOM' ) && IS_WPCOM ); | |
| 49 | 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 | + | |
| 50 | 65 | return sprintf( |
| 51 | 66 | '<div class="%1$s">%2$s</div>', |
| 52 | 67 | esc_attr( Blocks::classes( FEATURE_NAME, $attr ) ), |
| 53 | - $content | |
| 68 | + $blogroll_content | |
| 54 | 69 | ); |
| 55 | 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' ); | |