MS_Helper_Settings

The Membership 2 MS Helper Settings class.

Defined (1)

The class is defined in the following location(s).

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