NEXT craftinamerica.org. Base setup for headless wordpress https://www.craftinamerica.org
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. class P2P_Tools_Page extends scbAdminPage {
  3. function setup() {
  4. $this->args = array(
  5. 'page_title' => __( 'Connection Types', P2P_TEXTDOMAIN ),
  6. 'page_slug' => 'connection-types',
  7. 'parent' => 'tools.php'
  8. );
  9. add_action( 'admin_notices', array( $this, 'maybe_install' ) );
  10. }
  11. function maybe_install() {
  12. if ( !current_user_can( 'manage_options' ) )
  13. return;
  14. $current_ver = get_option( 'p2p_storage' );
  15. if ( $current_ver == P2P_Storage::$version )
  16. return;
  17. P2P_Storage::install();
  18. update_option( 'p2p_storage', P2P_Storage::$version );
  19. }
  20. function form_handler() {
  21. if ( empty( $_POST['p2p_convert'] ) )
  22. return false;
  23. check_admin_referer( $this->nonce );
  24. global $wpdb;
  25. $old_p2p_type = $_POST['old_p2p_type'];
  26. $new_p2p_type = $_POST['new_p2p_type'];
  27. if ( !p2p_type( $new_p2p_type ) ) {
  28. $this->admin_msg( sprintf( __( '<em>%s</em> is not a registered connection type.', P2P_TEXTDOMAIN ), esc_html( $new_p2p_type ) ) );
  29. return;
  30. }
  31. $count = $wpdb->update( $wpdb->p2p,
  32. array( 'p2p_type' => $new_p2p_type ),
  33. array( 'p2p_type' => $old_p2p_type )
  34. );
  35. $this->admin_msg( sprintf( __( 'Converted %1$s connections from <em>%2$s</em> to <em>%3$s</em>.', P2P_TEXTDOMAIN ),
  36. number_format_i18n( $count ),
  37. esc_html( $old_p2p_type ),
  38. esc_html( $new_p2p_type )
  39. ) );
  40. }
  41. function page_head() {
  42. wp_enqueue_style( 'p2p-tools', plugins_url( 'tools.css', __FILE__ ), array(), P2P_PLUGIN_VERSION );
  43. }
  44. function page_content() {
  45. $data = array(
  46. 'columns' => array(
  47. __( 'Name', P2P_TEXTDOMAIN ),
  48. __( 'Information', P2P_TEXTDOMAIN ),
  49. __( 'Connections', P2P_TEXTDOMAIN ),
  50. )
  51. );
  52. $connection_counts = $this->get_connection_counts();
  53. if ( empty( $connection_counts ) ) {
  54. $data['has-rows'] = false;
  55. $data['no-rows'] = __( 'No connection types registered.', P2P_TEXTDOMAIN );
  56. $data['no-rows2'] = sprintf(
  57. __( 'To register a connection type, see <a href="%s">the wiki</a>.', P2P_TEXTDOMAIN ),
  58. 'https://github.com/scribu/wp-posts-to-posts/wiki/'
  59. );
  60. } else {
  61. $data['has-rows'] = array(true);
  62. foreach ( $connection_counts as $p2p_type => $count ) {
  63. $row = array(
  64. 'p2p_type' => $p2p_type,
  65. 'count' => number_format_i18n( $count )
  66. );
  67. $ctype = p2p_type( $p2p_type );
  68. if ( $ctype ) {
  69. $row['desc'] = $ctype->get_desc();
  70. } else {
  71. $row['desc'] = __( 'Convert to registered connection type:', P2P_TEXTDOMAIN ) . scbForms::form_wrap( $this->get_dropdown( $p2p_type ), $this->nonce );
  72. $row['class'] = 'error';
  73. }
  74. $data['rows'][] = $row;
  75. }
  76. }
  77. echo P2P_Mustache::render( 'connection-types', $data );
  78. }
  79. private function get_connection_counts() {
  80. global $wpdb;
  81. $counts = $wpdb->get_results( "
  82. SELECT p2p_type, COUNT(*) as count
  83. FROM $wpdb->p2p
  84. GROUP BY p2p_type
  85. " );
  86. $counts = scb_list_fold( $counts, 'p2p_type', 'count' );
  87. foreach ( P2P_Connection_Type_Factory::get_all_instances() as $p2p_type => $ctype ) {
  88. if ( !isset( $counts[ $p2p_type ] ) )
  89. $counts[ $p2p_type ] = 0;
  90. }
  91. ksort( $counts );
  92. return $counts;
  93. }
  94. private function get_dropdown( $p2p_type ) {
  95. $data = array(
  96. 'old_p2p_type' => $p2p_type,
  97. 'options' => array_keys( P2P_Connection_Type_Factory::get_all_instances() ),
  98. 'button_text' => __( 'Go', P2P_TEXTDOMAIN )
  99. );
  100. return P2P_Mustache::render( 'connection-types-form', $data );
  101. }
  102. }