class-bulk-title-editor-list-table.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin\Bulk Editor
  6. * @since 1.5.0
  7. */
  8. /**
  9. * Implements table for bulk title editing.
  10. */
  11. class WPSEO_Bulk_Title_Editor_List_Table extends WPSEO_Bulk_List_Table {
  12. /**
  13. * Current type for this class will be title.
  14. *
  15. * @var string
  16. */
  17. protected $page_type = 'title';
  18. /**
  19. * Settings with are used in __construct.
  20. *
  21. * @var array
  22. */
  23. protected $settings = [
  24. 'singular' => 'wpseo_bulk_title',
  25. 'plural' => 'wpseo_bulk_titles',
  26. 'ajax' => true,
  27. ];
  28. /**
  29. * The field in the database where meta field is saved.
  30. *
  31. * @var string
  32. */
  33. protected $target_db_field = 'title';
  34. /**
  35. * The columns shown on the table.
  36. *
  37. * @return array
  38. */
  39. public function get_columns() {
  40. $columns = [
  41. /* translators: %1$s expands to Yoast SEO */
  42. 'col_existing_yoast_seo_title' => sprintf( __( 'Existing %1$s Title', 'wordpress-seo' ), 'Yoast SEO' ),
  43. /* translators: %1$s expands to Yoast SEO */
  44. 'col_new_yoast_seo_title' => sprintf( __( 'New %1$s Title', 'wordpress-seo' ), 'Yoast SEO' ),
  45. ];
  46. return $this->merge_columns( $columns );
  47. }
  48. /**
  49. * Parse the title columns.
  50. *
  51. * @param string $column_name Column name.
  52. * @param object $record Data object.
  53. * @param string $attributes HTML attributes.
  54. *
  55. * @return string
  56. */
  57. protected function parse_page_specific_column( $column_name, $record, $attributes ) {
  58. // Fill meta data if exists in $this->meta_data.
  59. $meta_data = ( ! empty( $this->meta_data[ $record->ID ] ) ) ? $this->meta_data[ $record->ID ] : [];
  60. switch ( $column_name ) {
  61. case 'col_existing_yoast_seo_title':
  62. // @todo Inconsistent return/echo behavior R.
  63. // I traced the escaping of the attributes to WPSEO_Bulk_List_Table::column_attributes.
  64. // The output of WPSEO_Bulk_List_Table::parse_meta_data_field is properly escaped.
  65. // phpcs:ignore WordPress.Security.EscapeOutput
  66. echo $this->parse_meta_data_field( $record->ID, $attributes );
  67. break;
  68. case 'col_new_yoast_seo_title':
  69. return sprintf(
  70. '<input type="text" id="%1$s" name="%1$s" class="wpseo-new-title" data-id="%2$s" aria-labelledby="col_new_yoast_seo_title" />',
  71. 'wpseo-new-title-' . $record->ID,
  72. $record->ID
  73. );
  74. }
  75. unset( $meta_data );
  76. }
  77. } /* End of class */