/app/helper/class-ms-helper-settings.php

  1. <?php 
  2. class MS_Helper_Settings extends MS_Helper { 
  3.  
  4. // Success response codes 
  5. const SETTINGS_MSG_ADDED = 1; 
  6. const SETTINGS_MSG_DELETED = 2; 
  7. const SETTINGS_MSG_UPDATED = 3; 
  8. const SETTINGS_MSG_ACTIVATION_TOGGLED = 4; 
  9. const SETTINGS_MSG_STATUS_TOGGLED = 5; 
  10. const SETTINGS_MSG_BULK_UPDATED = 6; 
  11. const SETTINGS_MSG_SITE_UPDATED = 7; 
  12.  
  13. // Error response codes 
  14. const SETTINGS_MSG_NOT_ADDED = -1; 
  15. const SETTINGS_MSG_NOT_DELETED = -2; 
  16. const SETTINGS_MSG_NOT_UPDATED = -3; 
  17. const SETTINGS_MSG_ACTIVATION_NOT_TOGGLED = -4; 
  18. const SETTINGS_MSG_STATUS_NOT_TOGGLED = -5; 
  19. const SETTINGS_MSG_BULK_NOT_UPDATED = -6; 
  20. const SETTINGS_MSG_UNCONFIGURED = -7; 
  21.  
  22. /** 
  23. * Returns the status messages for a given status code 
  24. * 
  25. * @since 1.0.0 
  26. * @param int $msg Status code 
  27. * @return string Status message 
  28. */ 
  29. public static function get_admin_message( $msg = 0 ) { 
  30. static $Messages = null; 
  31.  
  32. if ( null === $Messages ) { 
  33. $Messages = apply_filters( 
  34. 'ms_helper_membership_get_admin_messages',  
  35. array( 
  36. // Success response codes 
  37. self::SETTINGS_MSG_ADDED => __( 'Setting added.', 'membership2' ),  
  38. self::SETTINGS_MSG_DELETED => __( 'Setting deleted.', 'membership2' ),  
  39. self::SETTINGS_MSG_UPDATED => __( 'Setting updated.', 'membership2' ),  
  40. self::SETTINGS_MSG_ACTIVATION_TOGGLED => __( 'Setting activation toggled.', 'membership2' ),  
  41. self::SETTINGS_MSG_STATUS_TOGGLED => __( 'Setting status toggled.', 'membership2' ),  
  42. self::SETTINGS_MSG_BULK_UPDATED => __( 'Bulk settings updated.', 'membership2' ),  
  43. self::SETTINGS_MSG_SITE_UPDATED => __( 'Changed the network site that hosts Membership pages. Remember to check your Pages and change them if needed!', 'membership2' ),  
  44.  
  45. // Error response messages 
  46. self::SETTINGS_MSG_NOT_ADDED => __( 'Setting not added.', 'membership2' ),  
  47. self::SETTINGS_MSG_NOT_DELETED => __( 'Setting not deleted.', 'membership2' ),  
  48. self::SETTINGS_MSG_NOT_UPDATED => __( 'Setting not updated.', 'membership2' ),  
  49. self::SETTINGS_MSG_ACTIVATION_NOT_TOGGLED => __( 'Setting activation not toggled.', 'membership2' ),  
  50. self::SETTINGS_MSG_STATUS_NOT_TOGGLED => __( 'Setting status not toggled.', 'membership2' ),  
  51. self::SETTINGS_MSG_BULK_NOT_UPDATED => __( 'Bulk settings not updated.', 'membership2' ),  
  52. ); 
  53.  
  54. if ( isset( $Messages[ $msg ] ) ) { 
  55. return $Messages[ $msg ]; 
  56. } else { 
  57. return false; 
  58.  
  59. /** 
  60. * Displays a status message on the Admin screen. 
  61. * 
  62. * The message to display is determined by the URL param 'msg' 
  63. * 
  64. * @since 1.0.0 
  65. */ 
  66. public static function print_admin_message() { 
  67. $msg = ! empty( $_GET['msg'] ) ? (int) $_GET['msg'] : 0; 
  68. $class = ( $msg > 0 ) ? 'updated' : 'error'; 
  69. $contents = self::get_admin_message( $msg ); 
  70.  
  71. if ( $contents ) { 
  72. lib3()->ui->admin_message( $contents, $class ); 
  73.  
  74. /** 
  75. * Returns an array of all sites in the current network. 
  76. * The array index is the blog-ID and the array value the blog title. 
  77. * 
  78. * @since 1.0.0 
  79. * @param bool $only_public By default only public sites are returned. 
  80. * @return array 
  81. */ 
  82. public static function get_blogs( $only_public = true ) { 
  83. static $List = array(); 
  84. $key = $only_public ? 'public' : 'all'; 
  85.  
  86. if ( ! isset( $List['_cache'] ) ) { 
  87. $List['_cache'] = array(); 
  88.  
  89. if ( ! isset( $List[$key] ) ) { 
  90. $args = array( 
  91. 'limit' => 0,  
  92. 'public' => true,  
  93. 'spam' => false,  
  94. 'deleted' => false,  
  95. ); 
  96. if ( $only_public ) { 
  97. $args['archived'] = false; 
  98. $args['mature'] = false; 
  99. $sites = wp_get_sites( $args ); 
  100. $List[$key] = array(); 
  101.  
  102. foreach ( $sites as $site_data ) { 
  103. $blog_id = $site_data['blog_id']; 
  104.  
  105. if ( isset( $List['_cache'][$blog_id] ) ) { 
  106. $title = $List['_cache'][$blog_id]; 
  107. } else { 
  108. switch_to_blog( $blog_id ); 
  109. $title = get_bloginfo( 'title' ); 
  110. $List['_cache'][$blog_id] = $title; 
  111. restore_current_blog(); 
  112. $List[$key][$blog_id] = $title; 
  113.  
  114. return $List[$key]; 
  115.  
.