Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor custom status module views #736

Merged
merged 4 commits into from
Jun 28, 2024

Conversation

alecgeatches
Copy link
Contributor

@alecgeatches alecgeatches commented Jun 27, 2024

Description

This PR is currently based on @ingeniumed's work in #734. Please review after that PR has been merged.


Some cleanup for the custom status module, as initial work to extend it. There were a few main changes:

  1. The print_configure_view() function had a lot of responsibilities, embedded HTML, and indentation. I moved the two HTML sections (configure page, edit status page) into separate view files and simplified the function.

  2. Fixed some PHPCS warnings from using $_GET and $_POST variables in print_configure_view() with some rewrites and some phpcs:ignores.

  3. Updated i18n functions to their escaped versions (_e()esc_html_e()) where appropriate.

  4. Moved one string (ef_confirm_delete_status_string) from an embeded <script> tag to wp_localize_script().

  5. Updated all array()s in the file to short syntax ([]). I did this automatically with PHP-CS-Fixer:

    php-cs-fixer fix modules/custom-status/custom-status.php --rules='{"array_syntax": {"syntax": "short"}}'
  6. A lot of whitespace alignment changes were automatically made by my editor.

Steps to Test

  1. Check out PR.
  2. Go to Admin -> Edit Flow -> Custom Statuses.
  3. Ensure adding and editing custom statuses works as expected.

@alecgeatches alecgeatches self-assigned this Jun 27, 2024
Base automatically changed from add/lint-modules to develop June 27, 2024 21:42
$description = ( isset( $_POST['description'] ) ) ? wp_strip_all_tags( $_POST['description'] ) : $custom_status->description;
}

include __DIR__ . '/views/edit-status.php';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless it's a shared/common view file, I usually default to using include_once to ensure no one accidentally include the file elsewhere. Would that fit the scenario here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that, better to not keep including it again and again.

} else {
$custom_status_list_table = new EF_Custom_Status_List_Table();
$custom_status_list_table->prepare_items();
include __DIR__ . '/views/configure.php';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that, better to not keep including it again and again.

<form class="basic-settings" action="<?php echo esc_url( $this->get_link( array( 'action' => 'change-options' ) ) ); ?>" method="post">
<?php settings_fields( $this->module->options_group_name ); ?>
<?php do_settings_sections( $this->module->options_group_name ); ?>
<?php echo '<input id="edit_flow_module_name" name="edit_flow_module_name" type="hidden" value="' . esc_attr( $this->module->name ) . '" />'; ?>
Copy link

@hanifn hanifn Jun 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can avoid echoing out the entire input field if we instead just echo out the module name.
Like this:

Suggested change
<?php echo '<input id="edit_flow_module_name" name="edit_flow_module_name" type="hidden" value="' . esc_attr( $this->module->name ) . '" />'; ?>
<input id="edit_flow_module_name" name="edit_flow_module_name" type="hidden" value="<?php echo esc_attr( $this->module->name ); ?>" />

</div>

<?php wp_nonce_field( 'custom-status-add-nonce' ); ?>
<?php echo '<input id="action" name="action" type="hidden" value="add-new" />'; ?>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really necessary to echo this line out I think

Suggested change
<?php echo '<input id="action" name="action" type="hidden" value="add-new" />'; ?>
<input id="action" name="action" type="hidden" value="add-new" />

Copy link

@hanifn hanifn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes looks good to me and everything seems to be working as expected 👍
🚢

@ingeniumed ingeniumed merged commit a81f39c into develop Jun 28, 2024
2 of 3 checks passed
@ingeniumed ingeniumed deleted the refactor/custom-status-module branch June 28, 2024 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants