Skip to content

Conversation

@ShubhamGupta05
Copy link
Contributor

@ShubhamGupta05 ShubhamGupta05 commented Dec 17, 2025

Description

Main Purpose: This pull request introduces a new feature for duplicating posts within the admin interface of the Header Footer Elementor plugin. This functionality allows users to create copies of existing posts, enhancing content management for users who need to replicate posts quickly.

Key Changes:

  • A new class HFE_Post_Duplicator has been created in class-hfe-post-duplicator.php, which handles the duplication functionality.
  • The admin_post actions have been implemented to manage post duplication requests and enqueue admin-specific CSS styles from admin-post-duplicator.css.
  • The add_post_type_filters method dynamically adds a "UA Duplicate" link to the row actions for each public post type in the admin interface.
  • The feature includes necessary permissions checks and processes for handling the duplication safely (including copying of post meta, featured images, and taxonomies).

Additional Notes:

  • Please focus on the methods handling the duplication logic, especially duplicate_post, create_duplicate, and the admin notice for successful duplication which enhances user experience.
  • Reviewers should verify that the new feature works seamlessly across various post types and that proper permissions are enforced. Additionally, ensure the styling for the duplication notice is consistent with existing UI elements.

Screenshots

Types of changes

How has this been tested?

Checklist:

  • My code is tested
  • My code passes the PHPCS tests
  • My code follows accessibility standards
  • My code has proper inline documentation
  • I've included any necessary tests
  • I've included developer documentation
  • I've added proper labels to this pull request

@@ -0,0 +1,27 @@
/**

Choose a reason for hiding this comment

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

What: Consider specifying a version for the CSS file if applicable.

Why: Versioning helps in managing assets and ensures that users receive the correct style updates. It aids in cache management.

How: Add a comment at the top of the CSS file indicating the version, e.g., /* Version 1.0.0 */. This practice can be integrated with your build process or asset management approach.

@@ -0,0 +1,27 @@
/**
* Admin styles for Post Duplicator.
*

Choose a reason for hiding this comment

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

What: Consider adding more context to the comment above the .hfe-post-duplicator-notice class.

Why: While the comment generally states it's for the Post Duplicator, including what the notice signifies (e.g., success or error messages) can improve maintainability and understanding for future developers.

How: Change the comment to something like: /* Styles for success/error notices related to the Post Duplicator feature. */.

/**
* Admin styles for Post Duplicator.
*
* @package header-footer-elementor

Choose a reason for hiding this comment

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

What: The color definitions used here may benefit from being stored as CSS variables for easier theming or future changes.

Why: Utilizing CSS variables enhances maintainability and makes it easier to apply changes if the color scheme requires updates later on.

How: Define CSS variables in a root selector, like :root { --primary-color: #0073aa; --hover-color: #00a0d2; }, then use these variables in your styles, e.g., color: var(--primary-color);.

public function includes() {
require_once HFE_DIR . 'admin/class-hfe-admin.php';

require_once HFE_DIR . 'inc/hfe-functions.php';

Choose a reason for hiding this comment

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

What: The addition of the Post Duplicator class appears to be correctly included, but I recommend considering the implications of loading this class for all users who access the admin interface. If this class introduces heavy operations or data processing, it could impact performance.

Why: Loading unnecessary classes can lead to increased memory usage and slower performance, particularly for users who do not utilize the duplication feature. This is crucial for maintaining a responsive admin experience, especially if many users will be accessing the admin interface.

How: To improve performance, consider utilizing a conditional loading mechanism. For example, load the class-hfe-post-duplicator.php file only if the user is accessing a specific admin page or if the feature is enabled in the settings. This can be implemented using a check like if (isset($_GET['page']) && $_GET['page'] === 'desired_page_name'). This reduces unnecessary overhead for users who do not need the duplication functionality.

// Create duplicate link.
$duplicate_link = admin_url( 'admin.php?action=hfe_duplicate_post&post=' . $post->ID . '&nonce=' . $nonce );

// Add duplicate link to actions.

Choose a reason for hiding this comment

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

What: Sanitization for retrieved GET parameters is insufficient.

Why: While the code uses absint() for sanitizing the post parameter, it directly uses the nonces without appropriate sanitization for the nonce value being passed in the GET request. This could lead to security loopholes if it were to validate an invalid or malicious nonce.

How: Instead of using sanitize_text_field after wp_unslash, use sanitize_key() for the nonce variable. Ensure that nonce validation occurs immediately after any necessary sanitization.


/**
* Duplicate post.
*

Choose a reason for hiding this comment

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

What: Potential performance concern with the copy_post_meta function; unnecessary iterations.

Why: The code retrieves all post meta and updates each key/value pair one by one. If there are many meta fields, this could lead to performance issues because of the multiple database updates.

How: Consider using a bulk insert operation where possible, or if there's a way to process multiple key/value pairs efficiently that may reduce the number of database operations.

'post_author' => $post->post_author,
'post_content' => $post->post_content,
'post_excerpt' => $post->post_excerpt,
'post_parent' => $post->post_parent,

Choose a reason for hiding this comment

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

What: Enhance error handling when duplicating post; currently generic.

Why: When creating a duplicate post, the user receives a generic message if an error occurs, without knowing the actual issue that caused the failure (such as 'invalid data provided', etc.). This could lead to confusion in usage.

How: Instead of directly passing the error messages from wp_error, consider logging the error for development purposes and providing a user-friendly explanation to the admin that provides information on what the issue could be.

@ShubhamGupta05 ShubhamGupta05 changed the title New Post duplicator feature EPS-1483: New Post duplicator feature Dec 17, 2025
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.

2 participants