name = esc_html__( 'Revisions', 'wpforms-lite' ); $this->slug = 'revisions'; $this->icon = 'fa-history'; $this->order = 10; $this->sidebar = true; $this->hooks(); } /** * Hook into WordPress lifecycle. * * @since 1.7.3 */ private function hooks() { // Add a notice above all panels if revision is loaded. add_action( 'wpforms_builder_panels', [ $this, 'panel_notice' ], 100, 2 ); } /** * Primary panel button in the left panel navigation. * * @since 1.7.3 * * @param mixed $form The form object. * @param string $view Current view/panel. */ public function button( $form, $view ) { $classes = 'wpforms-panel-revisions-button'; if ( $view === $this->slug ) { $classes .= ' active'; } $badge = ''; if ( $this->form && ! wp_revisions_enabled( $this->form ) && ! wpforms()->get( 'revisions' )->panel_viewed() ) { $badge = ' '; } printf( '
', esc_attr( $classes ), esc_attr( $this->slug ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $badge, esc_attr( $this->icon ), esc_html( $this->name ), esc_html__( 'Form Revisions', 'wpforms-lite' ) ); } /** * Output the Settings panel sidebar. * * @since 1.7.3 */ public function panel_sidebar() { // Sidebar contents are not valid unless we have a form. if ( ! $this->form ) { return; } printf( '

%s

%s

', esc_html__( 'Form Revisions', 'wpforms-lite' ), esc_html__( 'Select a revision to roll back to that version. All changes, including settings, will be reverted.', 'wpforms-lite' ) ); // Render a list of form revisions, including current version. All data is safe, escaped in the template. // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo wpforms()->get( 'revisions' )->render_revisions_list(); $revisions_to_keep = wp_revisions_to_keep( $this->form ); if ( $revisions_to_keep === 0 ) { // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo wpforms_render( 'builder/revisions/notice-disabled' ); } if ( $revisions_to_keep > 0 ) { // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo wpforms_render( 'builder/revisions/notice-limited', [ 'revisions_to_keep' => $revisions_to_keep, ], true ); } } /** * Output revision notice above the panels. * * @since 1.7.3 * * @return void */ public function panel_notice() { $revision = wpforms()->get( 'revisions' )->get_revision(); if ( ! $revision ) { return; } $restore_link = sprintf( '%2$s', esc_url( wp_nonce_url( wpforms()->get( 'revisions' )->get_url( [ 'revision_id' => $revision->ID, 'action' => 'restore_revision', ] ), 'restore_revision', 'wpforms_nonce' ) ), __( 'Restore this revision', 'wpforms-lite' ) ); $back_link = sprintf( '%2$s', esc_url( wpforms()->get( 'revisions' )->get_url() ), __( 'go back to the current version', 'wpforms-lite' ) ); $message = sprintf( /* translators: %1$s - revision date, %2$s - revision time, %3$s - "Restore this revision" link, %4$s - "go back to the current version" link. */ __( 'You’re currently viewing a form revision from %1$s at %2$s. %3$s or %4$s.', 'wpforms-lite' ), wpforms()->get( 'revisions' )->get_formatted_datetime( $revision->post_modified_gmt ), wpforms()->get( 'revisions' )->get_formatted_datetime( $revision->post_modified_gmt, 'time' ), $restore_link, $back_link ); printf( '

%s

', wp_kses( $message, [ 'a' => [ 'href' => [], ], ] ) ); } } new WPForms_Builder_Panel_Revisions();