| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly. |
| 4 |
} |
| 5 |
|
| 6 |
/** |
| 7 |
* Registers the block using the metadata loaded from the `block.json` file. |
| 8 |
* Behind the scenes, it registers also all assets so they can be enqueued |
| 9 |
* through the block editor in the corresponding context. |
| 10 |
* |
| 11 |
* @see https://developer.wordpress.org/reference/functions/register_block_type/ |
| 12 |
*/ |
| 13 |
register_block_type( __DIR__ . '/build/recover-password', |
| 14 |
[ |
| 15 |
'render_callback' => function( $attributes, $content ) { |
| 16 |
ob_start(); |
| 17 |
do_action( 'wppb/recover_password/render_callback', $attributes, $content ); |
| 18 |
return ob_get_clean(); |
| 19 |
}, |
| 20 |
] |
| 21 |
); |
| 22 |
|
| 23 |
add_action( |
| 24 |
'admin_enqueue_scripts', |
| 25 |
function () { |
| 26 |
// Add pre-loaded data for my-namespace/my-block |
| 27 |
wp_add_inline_script('wppb-recover-password-editor-script', 'window.wppbRecoverPasswordBlockConfig = ' . json_encode(array( |
| 28 |
'wppb_paid' => defined( 'WPPB_PAID_PLUGIN_DIR' ), |
| 29 |
)), 'before'); |
| 30 |
} |
| 31 |
); |
| 32 |
|
| 33 |
/** |
| 34 |
* Render: PHP. |
| 35 |
* |
| 36 |
* @param array $attributes Optional. Block attributes. Default empty array. |
| 37 |
* @param string $content Optional. Block content. Default empty string. |
| 38 |
*/ |
| 39 |
add_action( |
| 40 |
'wppb/recover_password/render_callback', |
| 41 |
function( $attributes, $content ) { |
| 42 |
if ( isset($attributes['is_preview']) && $attributes['is_preview'] === 'true' ) { |
| 43 |
echo ' |
| 44 |
<svg |
| 45 |
xmlns="http://www.w3.org/2000/svg" |
| 46 |
fill="none" |
| 47 |
viewBox="0 0 230 130" |
| 48 |
style="width: "100%";" |
| 49 |
> |
| 50 |
<title>Recover Password Block Preview</title> |
| 51 |
<rect |
| 52 |
width="100.80727" |
| 53 |
height="15" |
| 54 |
x="28.485535" |
| 55 |
y="27.950914" |
| 56 |
rx="8.0260563" |
| 57 |
id="rect6" |
| 58 |
style="fill:#a0a5aa;stroke-width:1.26696932" /> |
| 59 |
<rect |
| 60 |
width="146.85718" |
| 61 |
height="4.0700259" |
| 62 |
x="28.485535" |
| 63 |
y="64.117226" |
| 64 |
rx="7.9975109" |
| 65 |
id="rect4-3-5-7" |
| 66 |
style="fill:#a0a5aa;stroke-width:1.56730127" /> |
| 67 |
<rect |
| 68 |
width="50.390999" |
| 69 |
height="10.030812" |
| 70 |
x="28.485535" |
| 71 |
y="78.605385" |
| 72 |
rx="2.7441804" |
| 73 |
id="rect4-6" |
| 74 |
style="fill:#a0a5aa;stroke-width:1.44128823" /> |
| 75 |
<rect |
| 76 |
width="57.461281" |
| 77 |
height="15" |
| 78 |
x="28.485535" |
| 79 |
y="100.59328" |
| 80 |
rx="4.5749426" |
| 81 |
id="rect6-7" |
| 82 |
style="fill:#a0a5aa;stroke-width:0.95655036" /> |
| 83 |
<rect |
| 84 |
width="115.16996" |
| 85 |
height="4.0700259" |
| 86 |
x="28.485535" |
| 87 |
y="55.627056" |
| 88 |
rx="6.2718964" |
| 89 |
id="rect4-3-5" |
| 90 |
style="fill:#a0a5aa;stroke-width:1.38795221" /> |
| 91 |
<rect |
| 92 |
width="120.38487" |
| 93 |
height="10.030812" |
| 94 |
x="80.340279" |
| 95 |
y="78.605385" |
| 96 |
rx="6.5558887" |
| 97 |
id="rect4-3-5-5" |
| 98 |
style="fill:#a0a5aa;stroke-width:2.22771859" /> |
| 99 |
</svg>'; |
| 100 |
} else { |
| 101 |
$atts = [ |
| 102 |
'block' => $attributes['is_editor'] ? ' block="true"' : '', |
| 103 |
'ajax' => $attributes['ajax'] ? ' ajax="true"' : '', |
| 104 |
]; |
| 105 |
echo '<div class="wppb-block-container">' . do_shortcode( '[wppb-recover-password' . $atts['block'] . $atts['ajax'] . ' ]' ) . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 106 |
} |
| 107 |
} |
| 108 |
, 10, 2 ); |
| 109 |
|