-
Notifications
You must be signed in to change notification settings - Fork 23
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
Pluggable WP-Sweep / Dynamic admin page #39
Comments
function register_sweep_admin_group( $title, $group_slug, $status ) {
?>
<h3><?php _e( 'Comment Sweep', 'wp-sweep' ); ?></h3>
<p><?php esc_html( $status ); ?></p>
<div class="sweep-message"></div>
<table class="widefat table-sweep">
<thead>
<tr>
<th class="col-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></th>
<th class="col-sweep-count"><?php _e( 'Count', 'wp-sweep' ); ?></th>
<th class="col-sweep-percent"><?php _e( '% Of', 'wp-sweep' ); ?></th>
<th class="col-sweep-action"><?php _e( 'Action', 'wp-sweep' ); ?></th>
</tr>
</thead>
<tbody>
<?php
// loop of sweeps for this group
?>
</tbody>
</table>
<?php do_action( 'wp_sweep_admin_' . $group . '_sweep' ); ?>
<p> </p>
<?php
} register_sweep_admin_group();
register_sweep_admin();
render_sweep_admin();
render_sweep_admin_group(); |
How do we link render_sweep_admin into render_sweep_admin_group()? actions? |
The register functions would make up an array: $sweep_groups = array(
$group_slug => array(
$sweep_details1,
$sweep_details2,
),
$group_slug2 => array(
$sweep_details1,
$sweep_details2,
),
); |
Ah I see! Sounds good! PR please 😅 |
@lesterchan I am starting to modularize WP-Sweep.
What else? |
@lesterchan First try on WP Sweep 2.0! <?php
/**
* WP-Sweep sweep skeleton
*
* @package wp-sweep
*/
/**
* Abstract class WPSweep_Sweep
*/
abstract class WPSweep_Sweep {
/**
* Sweep slug
*
* @access public
* @var string
*/
const SLUG = '';
/**
* Sweep name
*
* @access public
* @var string
*/
const NAME = self::SLUG;
/**
* The total the sweep pertains to
*
* @access public
* @var string
*/
const TOTAL = '';
/**
* "Processed" message in gettext format
*
* @access public
* @var string
*/
const PROCESSED_MESSAGE = "%s {self::NAME} Processed";
/**
* WPSweep instance
*
* @access private
* @var WPSweep $wp_sweep
*/
private $wp_sweep;
/**
* WPDB instance
*
* @access private
* @var wpdb $wpdb
*/
private $wp_db;
/**
* Initialize sweep
*
* @access public
*/
public function __construct( $wp_sweep ) {
global $wpdb;
$this->wp_sweep = $wp_sweep;
$this->wp_db = $wpdb;
}
/**
* Return count of items to be swept
*
* @access public
* @return int
*/
public function count() {}
/**
* Return details about the sweep
*
* @access public
* @return string
*/
public function details() {}
/**
* Does the sweeping
*
* @access public
* @return string Processed message
*/
public function sweep() {}
}
<?php
/**
* WP-Sweep unapproved comments sweep
*
* @package wp-sweep
*/
/**
* Class WPSweep_Unapproved_Sweep_Comments
*/
class WPSweep_Sweep_Unapproved_Comments extends WPSweep_Sweep {
const SLUG = 'unapproved_comments';
const NAME = 'Unapproved Comments';
const TOTAL = 'comments';
const PROCESSED_MESSAGE = '%s Unapproved Comments Processed';
public function count() {
return $this->wp_db->get_var( $this->wp_db->prepare( "SELECT COUNT(comment_ID) FROM {$this->wp_db->comments} WHERE comment_approved = %s", '0' ) );
}
public function details() {
return $this->wp_db->get_col( $this->wp_db->prepare( "SELECT comment_author FROM {$this->wp_db->comments} WHERE comment_approved = %s LIMIT %d", '0', $this->wp_sweep->
limit_details ) );
}
public function sweep() {
$query = $this->wp_db->get_col( $this->wp_db->prepare( "SELECT comment_ID FROM {$this->wp_db->comments} WHERE comment_approved = %s", '0' ) );
foreach ( $query as $id ) {
wp_delete_comment( (int) $id, true );
}
// translators: %s is the Unapproved Comments count.
return count( $query );
}
} |
Should the count(), details() and sweep() on the parent classes be abstract as well? |
Yes. This is just a theoretical plan. So it is probably not working. |
@lesterchan What if I complete the rewrite with Unapproved Comments only, and you add the rest of the built-in sweeps? (14 sloc/sweep) |
Sure if I have the time to do it! But it will not be that fast as I am quite busy with my day job. I also created a new branch called |
@lesterchan Now admin.php should fully become class WPSweep_Admin. |
For example
The text was updated successfully, but these errors were encountered: