class-recalculate-scores.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin
  6. */
  7. /**
  8. * Class WPSEO_Recalculate_Scores.
  9. *
  10. * This class handles the SEO score recalculation for all posts with a filled focus keyword.
  11. */
  12. class WPSEO_Recalculate_Scores {
  13. /**
  14. * Constructing the object by modalbox, the localization and the totals.
  15. */
  16. public function __construct() {
  17. add_action( 'admin_enqueue_scripts', [ $this, 'recalculate_assets' ] );
  18. add_action( 'admin_footer', [ $this, 'modal_box' ], 20 );
  19. }
  20. /**
  21. * Run the localize script.
  22. */
  23. public function recalculate_assets() {
  24. $asset_manager = new WPSEO_Admin_Asset_Manager();
  25. $asset_manager->enqueue_script( 'recalculate' );
  26. }
  27. /**
  28. * Initialize the modal box to be displayed when needed.
  29. */
  30. public function modal_box() {
  31. // Adding the thickbox.
  32. add_thickbox();
  33. $progress = sprintf(
  34. /* translators: 1: expands to a <span> containing the number of posts recalculated. 2: expands to a <strong> containing the total number of posts. */
  35. esc_html__( '%1$s of %2$s done.', 'wordpress-seo' ),
  36. '<span id="wpseo_count">0</span>',
  37. '<strong id="wpseo_count_total">0</strong>'
  38. );
  39. ?>
  40. <div id="wpseo_recalculate" class="hidden">
  41. <p><?php esc_html_e( 'Recalculating SEO scores for all pieces of content with a focus keyphrase.', 'wordpress-seo' ); ?></p>
  42. <div id="wpseo_progressbar"></div>
  43. <p><?php echo $progress; ?></p>
  44. </div>
  45. <?php
  46. }
  47. }