PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-beta
Jetpack – WP Security, Backup, Speed, & Growth v16.3-beta
16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 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 All 507 releases
jetpack / jetpack_vendor / automattic / jetpack-sharing-likes / src / settings / class-sharing-section.php

class-sharing-section.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3-beta, at jetpack_vendor/automattic/jetpack-sharing-likes/src/settings/class-sharing-section.php

154 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The Sharing buttons section of Settings > Sharing.
4 *
5 * @package automattic/jetpack-sharing-likes
6 */
7
8 declare( strict_types = 1 );
9
10 namespace Automattic\Jetpack\Sharing_Likes\Settings;
11
12 /**
13 * Renders the Sharing buttons section.
14 */
15 final class Sharing_Section {
16
17 /**
18 * Nonce action for this section's action buttons.
19 */
20 public const NONCE_ACTION = 'jetpack-sharing-options';
21
22 /**
23 * Render the section.
24 */
25 public static function render(): void {
26 $state = self::state();
27
28 echo '<div class="jetpack-sharing-settings__section">';
29 printf( '<h2>%s</h2>', esc_html_x( 'Sharing buttons', 'Settings header', 'jetpack-sharing-likes' ) );
30
31 switch ( $state ) {
32 case Section_State::BLOCK_CALL_TO_ACTION:
33 self::render_block_call_to_action();
34 break;
35 case Section_State::OFF:
36 self::render_off();
37 break;
38 case Section_State::CONFIGURE_WITH_BLOCK_NUDGE:
39 self::render_block_nudge();
40 self::render_services_config();
41 break;
42 default:
43 self::render_services_config();
44 }
45
46 echo '</div>';
47 }
48
49 /**
50 * Which variant the section renders.
51 *
52 * @return string One of the `Section_State` constants.
53 */
54 public static function state(): string {
55 return Section_State::for_section(
56 self::can_offer_block(),
57 Environment::sharing_module_running(),
58 Environment::legacy_sharing_switched_off()
59 );
60 }
61
62 /**
63 * Whether the Sharing Buttons block is a route we can send this site down.
64 */
65 private static function can_offer_block(): bool {
66 return Environment::is_block_theme()
67 && Environment::sharing_block_registered()
68 && '' !== Environment::single_template_editor_url();
69 }
70
71 /**
72 * The legacy buttons are off and the site could use the block instead.
73 */
74 private static function render_block_call_to_action(): void {
75 printf(
76 '<p>%s</p>',
77 esc_html__( 'Add the Sharing Buttons block to your theme’s template.', 'jetpack-sharing-likes' )
78 );
79 self::render_site_editor_link();
80 }
81
82 /**
83 * The module is off on a theme with no block route.
84 *
85 * Nothing else on this site produces sharing buttons, so this is the one
86 * place the feature can be switched back on.
87 */
88 private static function render_off(): void {
89 printf(
90 '<p>%s</p>',
91 esc_html__( 'Sharing buttons are turned off for this site.', 'jetpack-sharing-likes' )
92 );
93
94 self::render_activate_form();
95 }
96
97 /**
98 * The way back. See `Post_Handler::activate_module()`.
99 */
100 private static function render_activate_form(): void {
101 if ( ! Environment::legacy_sharing_supported() ) {
102 printf(
103 '<p>%s</p>',
104 esc_html__( 'Connect your site to WordPress.com, or enable offline mode, to turn them back on.', 'jetpack-sharing-likes' )
105 );
106 return;
107 }
108
109 Post_Handler::render_action_form(
110 'activate-sharing',
111 self::NONCE_ACTION,
112 __( 'Turn on sharing buttons', 'jetpack-sharing-likes' )
113 );
114 }
115
116 /**
117 * The buttons are live, but the site would be better served by the block.
118 */
119 private static function render_block_nudge(): void {
120 echo '<div class="notice notice-info inline">';
121 printf( '<p>%s</p>', esc_html__( 'Legacy sharing buttons cannot be customized on block themes. Use the Sharing Buttons block in your theme’s template instead.', 'jetpack-sharing-likes' ) );
122 Post_Handler::render_action_form(
123 'switch-to-block-sharing',
124 self::NONCE_ACTION,
125 __( 'Switch to the Sharing Buttons block', 'jetpack-sharing-likes' ),
126 false
127 );
128 echo '</div>';
129 }
130
131 /**
132 * Link to the active theme's single post template, with the editor open.
133 */
134 private static function render_site_editor_link(): void {
135 printf(
136 '<p><a class="button" href="%1$s">%2$s</a></p>',
137 esc_url( Environment::single_template_editor_url() ),
138 esc_html__( 'Open Site Editor', 'jetpack-sharing-likes' )
139 );
140 }
141
142 /**
143 * The services list and its settings.
144 */
145 private static function render_services_config(): void {
146 // Placement is moot with no services: the buttons appear nowhere.
147 if ( ! Environment::legacy_sharing_switched_off() ) {
148 Placement_Section::render_summary( Placement_Section::FEATURE_SHARING );
149 }
150
151 ( new Services_Config() )->render();
152 }
153 }
154