ACF_Admin_Tool_Export::html_generate
Generates the HTML for the PHP export functionality.
Метод класса: ACF_Admin_Tool_Export{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$ACF_Admin_Tool_Export = new ACF_Admin_Tool_Export(); $ACF_Admin_Tool_Export->html_generate();
Список изменений
| С версии 5.6.3 | Введена. |
Код ACF_Admin_Tool_Export::html_generate() ACF Admin Tool Export::html generate ACF 6.4.2
<?php
public function html_generate() {
// Prevent default translation and fake __() within string.
acf_update_setting( 'l10n_var_export', true );
$json = $this->get_selected();
$to_export = array();
// Sort by ACF post type first so we can wrap them in related functions.
foreach ( $json as $post ) {
$post_type = acf_determine_internal_post_type( $post['key'] );
if ( $post_type ) {
$to_export[ $post_type ][] = $post;
}
}
echo '<textarea id="acf-export-textarea" readonly="readonly">';
foreach ( $to_export as $post_type => $posts ) {
if ( 'acf-field-group' === $post_type ) {
echo "add_action( 'acf/include_fields', function() {\r\n";
echo "\tif ( ! function_exists( 'acf_add_local_field_group' ) ) {\r\n\t\treturn;\r\n\t}\r\n\r\n";
} elseif ( 'acf-post-type' === $post_type || 'acf-taxonomy' === $post_type ) {
echo "add_action( 'init', function() {\r\n";
} elseif ( 'acf-ui-options-page' === $post_type ) {
echo "add_action( 'acf/init', function() {\r\n";
}
$count = 0;
foreach ( $posts as $post ) {
if ( $count !== 0 ) {
echo "\r\n";
}
echo "\t" . acf_export_internal_post_type_as_php( $post, $post_type ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- esc_textarea() used earlier.
++$count;
}
if ( in_array( $post_type, array( 'acf-post-type', 'acf-taxonomy', 'acf-field-group', 'acf-ui-options-page' ), true ) ) {
echo "} );\r\n\r\n";
}
if ( 'acf-post-type' === $post_type ) {
echo acf_export_enter_title_here( $posts ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- esc_textarea() used earlier.
}
}
echo '</textarea>';
?>
<p class="acf-submit">
<a class="button" id="acf-export-copy"><?php esc_html_e( 'Copy to clipboard', 'acf' ); ?></a>
</p>
<script type="text/javascript">
(function($){
const $a = $('#acf-export-copy');
const $textarea = $('#acf-export-textarea');
// Remove $a if 'copy' is not supported.
if( !document.queryCommandSupported('copy') ) {
return $a.remove();
}
$a.on('click', function( e ){
e.preventDefault();
$textarea.get(0).select();
try {
var copy = document.execCommand('copy');
if ( ! copy ) {
return;
}
acf.newTooltip({
text: "<?php esc_html_e( 'Copied', 'acf' ); ?>",
timeout: 250,
target: $(this),
});
} catch (err) {
// Do nothing.
}
});
})(jQuery);
</script>
<?php
}