@@ -488,15 +488,15 @@ function maybe_load_imported_template( $post_type, $post ) {
488488 */
489489 $ template_path = apply_filters ( 'wplf_import_html_template ' , null , $ form_id );
490490
491- if ($ template_path === null ) {
491+ if ( $ template_path === null ) {
492492 return ;
493493 }
494494
495495 $ this ->override_form_template ( $ template_path , $ form_id );
496496 }
497497
498498 /**
499- * Override a forms template with an imported template file.
499+ * Override a form's template with an imported template file.
500500 *
501501 * @param string $template_path Absolute path to template HTML file.
502502 * @param int $form_id ID of form we're overriding the template for.
@@ -513,44 +513,52 @@ protected function override_form_template( $template_path, $form_id ) {
513513 * @param string $contents The form HTML.
514514 * @param int $form_id ID of form we are importing a template for.
515515 */
516- $ contents = apply_filters ( 'wplf_imported_html_template_contents ' , $ contents , $ form_id );
516+ $ template_contents = apply_filters ( 'wplf_imported_html_template_contents ' , $ contents , $ form_id );
517517
518518 // Make the editor textarea uneditable. Also remove TinyMCE.
519519 add_filter ( 'the_editor ' , function ( $ editor ) {
520- if (! preg_match ('%id="wp-content-editor-container"% ' , $ editor) ) {
520+ if ( ! preg_match ( '%id="wp-content-editor-container"% ' , $ editor ) ) {
521521 return $ editor ;
522522 }
523523
524524 $ editor = preg_replace ( '%\<textarea % ' , '<textarea readonly="readonly" ' , $ editor );
525525
526- $ editor = preg_replace ( '%<div [^<>]*? class="quicktags-toolbar">.*?</div><textarea%imux ' , '<textarea ' , $ editor );
526+ $ editor = preg_replace (
527+ '%<div [^<>]*? class="quicktags-toolbar">.*?</div><textarea%imux ' ,
528+ '<textarea ' ,
529+ $ editor
530+ );
527531
528532 return $ editor ;
529533 } );
530534
531535 // Replace all editor content with template content.
532- add_filter ( 'the_editor_content ' , function ( $ content ) use ( $ contents ) {
533- return $ contents ;
536+ add_filter ( 'the_editor_content ' , function ( $ content ) use ( $ template_contents ) {
537+ return $ template_contents ;
534538 } );
535539
536540 // Add a notice about the override.
537541 add_action ( 'edit_form_after_title ' , function () use ( $ template_path ) {
538- $ printable_path = explode (DIRECTORY_SEPARATOR , $ template_path );
539-
540- if (count ($ printable_path ) < 4 ) {
541- $ printable_path = implode (DIRECTORY_SEPARATOR , $ template_path );
542- } else {
543- $ printable_path = array_reverse (array_slice (array_reverse ($ printable_path ), 0 , 4 ));
542+ $ printable_path = explode ( DIRECTORY_SEPARATOR , $ template_path );
544543
545- $ printable_path = '.. ' . DIRECTORY_SEPARATOR . implode (DIRECTORY_SEPARATOR , $ printable_path );
546- }
544+ // We may not want the full system path to be shown, 4 parent directories oughta suffice.
545+ if ( count ( $ printable_path ) < 4 ) {
546+ $ printable_path = implode ( DIRECTORY_SEPARATOR , $ printable_path );
547+ } else {
548+ $ printable_path = array_reverse ( array_slice ( array_reverse ( $ printable_path ), 0 , 4 ) );
549+ $ printable_path = '.. ' . DIRECTORY_SEPARATOR . implode ( DIRECTORY_SEPARATOR , $ printable_path );
550+ }
547551
548- $ notice = sprintf (
549- __ ( 'This form template is being overridden by code, the template being used is<br> <code>%s</code> ' , 'wplf ' ),
550- $ printable_path
551- );
552+ $ notice = sprintf (
553+ _x (
554+ 'This form template is being overridden by code, the template being used is<br> <code>%s</code> ' ,
555+ 'Template override notice in form edit admin view ' ,
556+ 'wp-libre-form '
557+ ),
558+ $ printable_path
559+ );
552560
553- printf ('<p>%s</p> ' , $ notice );
561+ printf ( '<p>%s</p> ' , $ notice );
554562 } );
555563 }
556564
0 commit comments