admin-pages
4 years ago
core-api
3 years ago
debugger
3 years ago
markdown
4 years ago
class-jetpack-currencies.php
5 years ago
class-jetpack-instagram-gallery-helper.php
5 years ago
class-jetpack-mapbox-helper.php
4 years ago
class-jetpack-podcast-feed-locator.php
5 years ago
class-jetpack-podcast-helper.php
4 years ago
class-jetpack-recommendations.php
4 years ago
class-jetpack-tweetstorm-helper.php
5 years ago
class-jetpack-wizard.php
5 years ago
class.color.php
4 years ago
class.core-rest-api-endpoints.php
3 years ago
class.jetpack-automatic-install-skin.php
4 years ago
class.jetpack-iframe-embed.php
4 years ago
class.jetpack-keyring-service-helper.php
4 years ago
class.jetpack-password-checker.php
4 years ago
class.jetpack-photon-image-sizes.php
4 years ago
class.jetpack-photon-image.php
4 years ago
class.jetpack-search-performance-logger.php
4 years ago
class.media-extractor.php
4 years ago
class.media-summary.php
4 years ago
class.media.php
4 years ago
components.php
5 years ago
debugger.php
4 years ago
functions.wp-notify.php
4 years ago
icalendar-reader.php
4 years ago
markdown.php
5 years ago
plans.php
4 years ago
plugins.php
4 years ago
tonesque.php
4 years ago
widgets.php
3 years ago
components.php
120 lines
| 1 | <?php //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | |
| 3 | use Automattic\Jetpack\Status; |
| 4 | |
| 5 | /** |
| 6 | * Components Library |
| 7 | * |
| 8 | * Load and display a pre-rendered component |
| 9 | */ |
| 10 | class Jetpack_Components { |
| 11 | /** |
| 12 | * Load and display a pre-rendered component |
| 13 | * |
| 14 | * @since 7.7.0 |
| 15 | * |
| 16 | * @param string $name Component name. |
| 17 | * @param array $props Component properties. |
| 18 | * |
| 19 | * @return string The component markup |
| 20 | */ |
| 21 | public static function render_component( $name, $props ) { |
| 22 | |
| 23 | $rtl = is_rtl() ? '.rtl' : ''; |
| 24 | wp_enqueue_style( 'jetpack-components', plugins_url( "_inc/blocks/components{$rtl}.css", JETPACK__PLUGIN_FILE ), array( 'wp-components' ), JETPACK__VERSION ); |
| 25 | |
| 26 | ob_start(); |
| 27 | // `include` fails gracefully and throws a warning, but doesn't halt execution. |
| 28 | include JETPACK__PLUGIN_DIR . "_inc/blocks/$name.html"; |
| 29 | $markup = ob_get_clean(); |
| 30 | |
| 31 | foreach ( $props as $key => $value ) { |
| 32 | $markup = str_replace( |
| 33 | "#$key#", |
| 34 | $value, |
| 35 | $markup |
| 36 | ); |
| 37 | |
| 38 | // Workaround, required to replace strings in `sprintf`-expressions. |
| 39 | // See extensions/i18n-to-php.js for more information. |
| 40 | $markup = str_replace( |
| 41 | "%($key)s", |
| 42 | $value, |
| 43 | $markup |
| 44 | ); |
| 45 | } |
| 46 | |
| 47 | return $markup; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Renders the frontend-nudge with the provided props. |
| 52 | * |
| 53 | * @param array $props Component properties. |
| 54 | * |
| 55 | * @return string The component markup. |
| 56 | */ |
| 57 | public static function render_frontend_nudge( $props ) { |
| 58 | return self::render_component( |
| 59 | 'frontend-nudge', |
| 60 | $props |
| 61 | ); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Load and display a pre-rendered component |
| 66 | * |
| 67 | * @since 7.7.0 |
| 68 | * |
| 69 | * @param array $props Component properties. |
| 70 | * |
| 71 | * @return string The component markup |
| 72 | */ |
| 73 | public static function render_upgrade_nudge( $props ) { |
| 74 | $plan_slug = $props['plan']; |
| 75 | jetpack_require_lib( 'plans' ); |
| 76 | $plan = Jetpack_Plans::get_plan( $plan_slug ); |
| 77 | |
| 78 | if ( ! $plan ) { |
| 79 | return self::render_component( |
| 80 | 'upgrade-nudge', |
| 81 | array( |
| 82 | 'checkoutUrl' => '', |
| 83 | ) |
| 84 | ); |
| 85 | } |
| 86 | |
| 87 | // WP.com plan objects have a dedicated `path_slug` field, Jetpack plan objects don't. |
| 88 | $plan_path_slug = wp_startswith( $plan_slug, 'jetpack_' ) |
| 89 | ? $plan_slug |
| 90 | : $plan->path_slug; |
| 91 | |
| 92 | $post_id = get_the_ID(); |
| 93 | |
| 94 | $site_slug = ( new Status() )->get_site_suffix(); |
| 95 | |
| 96 | // Post-checkout: redirect back to the editor. |
| 97 | $redirect_to = add_query_arg( |
| 98 | array( |
| 99 | 'plan_upgraded' => 1, |
| 100 | ), |
| 101 | get_edit_post_link( $post_id ) |
| 102 | ); |
| 103 | |
| 104 | $upgrade_url = |
| 105 | $plan_path_slug |
| 106 | ? add_query_arg( |
| 107 | 'redirect_to', |
| 108 | $redirect_to, |
| 109 | "https://wordpress.com/checkout/${site_slug}/${plan_path_slug}" |
| 110 | ) : ''; |
| 111 | |
| 112 | return self::render_component( |
| 113 | 'upgrade-nudge', |
| 114 | array( |
| 115 | 'checkoutUrl' => $upgrade_url, |
| 116 | ) |
| 117 | ); |
| 118 | } |
| 119 | } |
| 120 |