@@ -29,6 +29,7 @@ public function __construct() {
2929 add_action ( 'add_meta_boxes ' , array ( $ this , 'add_meta_boxes_cpt ' ) );
3030 add_action ( 'add_meta_boxes ' , array ( $ this , 'maybe_load_imported_template ' ), 10 , 2 );
3131 add_action ( 'admin_enqueue_scripts ' , array ( $ this , 'admin_post_scripts_cpt ' ), 10 , 1 );
32+ add_action ( 'admin_notices ' , array ( $ this , 'print_notices ' ), 10 );
3233
3334 // edit.php view
3435 add_filter ( 'post_row_actions ' , array ( $ this , 'remove_row_actions ' ), 10 , 2 );
@@ -179,6 +180,45 @@ public function admin_post_scripts_cpt( $hook ) {
179180 wp_enqueue_style ( 'wplf-form-edit-css ' , $ assets_url . '/styles/wplf-admin-form.css ' );
180181 }
181182
183+ public function print_notices () {
184+ $ post_id = ! empty ( $ _GET ['post ' ] ) ? (int ) $ _GET ['post ' ] : false ;
185+ $ version_created_at = get_post_meta ( $ post_id , '_wplf_plugin_version ' , true );
186+ $ version_created_at = $ version_created_at ? $ version_created_at : '< 1.5 ' ;
187+
188+ // The notice prints outside the form element
189+ // a hidden field is created or deleted when this checkbox changes
190+ if ( version_compare ( $ version_created_at , WPLF_VERSION , '< ' ) ) { ?>
191+ <div class="notice notice-info">
192+ <p>
193+ <?php echo sprintf (
194+ esc_html (
195+ // translators: Placeholders indicate version numbers
196+ __ ( 'This form was created with WPLF version %1$s, and your installed WPLF version is %2$s ' , 'wp-libre-form ' )
197+ ),
198+ esc_html ( $ version_created_at ),
199+ esc_html ( WPLF_VERSION )
200+ ); ?>
201+ </p>
202+
203+ <p>
204+ <?php echo esc_html (
205+ __ ( 'There might be new features available, would you like to update the form version? ' , 'wp-libre-form ' )
206+ ); ?>
207+ </p>
208+
209+ <p>
210+ <label>
211+ <input type="checkbox" name="wplf_version_update_toggle" value="1">
212+ <?php echo esc_html (
213+ __ ( 'Yes, update when I save the form ' , 'wp-libre-form ' )
214+ ); ?>
215+ </label>
216+ </p>
217+ </div>
218+ <?php
219+ }
220+ }
221+
182222
183223 /**
184224 * Pre-populate form editor with default content
@@ -765,6 +805,12 @@ public function save_cpt( $post_id ) {
765805 // should be fine to save the meta field without further sanitisaton
766806 update_post_meta ( $ post_id , '_wplf_title_format ' , $ safe_title_format );
767807 }
808+
809+ // save plugin version, update if allowed
810+ $ version = get_post_meta ( $ post_id , '_wplf_plugin_version ' , true );
811+ if ( ! $ version || isset ( $ _POST ['wplf_update_plugin_version_to_meta ' ] ) ) {
812+ update_post_meta ( $ post_id , '_wplf_plugin_version ' , WPLF_VERSION );
813+ }
768814 }
769815
770816
0 commit comments