BP_Profile_Tabs_Admin

The BuddyPress Profile Tabs BP Profile Tabs Admin class.

Defined (1)

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

/admin/class-bp-profile-tabs-admin.php  
  1. class BP_Profile_Tabs_Admin { 
  2.  
  3. /** 
  4. * Instance of this class. 
  5. * @since 1.5.0 
  6. * @var object 
  7. */ 
  8. protected static $instance = null; 
  9.  
  10. /** 
  11. * Slug of the plugin screen. 
  12. * @since 1.5.0 
  13. * @var string 
  14. */ 
  15. protected $plugin_screen_hook_suffix = null; 
  16.  
  17. /** 
  18. * Initialize the plugin by loading admin scripts & styles and adding a 
  19. * settings page and menu. 
  20. * @since 1.0.0 
  21. */ 
  22. private function __construct() { 
  23. /** 
  24. * Call $plugin_slug from public plugin class. 
  25. */ 
  26. $plugin = BP_Profile_Tabs::get_instance(); 
  27. $this->plugin_slug = $plugin->get_plugin_slug(); 
  28. $this->plugin_name = $plugin->get_plugin_name(); 
  29. $this->version = $plugin->get_plugin_version(); 
  30. $this->jquery_ui_version = $plugin->get_jquery_ui_version(); 
  31.  
  32. // Add the options page and menu item. 
  33. add_action( 'admin_menu', array( $this, 'add_plugin_admin_menu' ) ); 
  34.  
  35. // Add an action link pointing to the options page. 
  36. $plugin_basename = plugin_basename( plugin_dir_path( realpath( dirname( __FILE__ ) ) ) . $this->plugin_slug . '.php' ); 
  37. add_filter( 'plugin_action_links_' . $plugin_basename, array( $this, 'add_action_links' ) ); 
  38.  
  39. /** 
  40. * Custom Metabox and Fields for Wordpress 
  41. * https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress 
  42. */ 
  43. if ( ! class_exists( 'cmb_Meta_Box' ) ) { 
  44. add_action( 'init', array( $this, 'add_cmb_Meta_Box_class' ), 9999 ); 
  45.  
  46. // Add the export settings method. 
  47. add_action( 'admin_init', array( $this, 'settings_export' ) ); 
  48.  
  49. // Add the import settings method. 
  50. add_action( 'admin_init', array( $this, 'settings_import' ) ); 
  51.  
  52. add_action( 'admin_init', array( $this, 'admin_register_bpt_script' ) ); 
  53. add_action( 'admin_print_styles', array( $this, 'load_admin_scripts' ) ); 
  54.  
  55.  
  56. /** 
  57. * Return an instance of this class. 
  58. * @since 1.0.0 
  59. * @return object A single instance of this class. 
  60. */ 
  61. public static function get_instance() { 
  62.  
  63. // If the single instance hasn't been set, set it now. 
  64. if ( null === self::$instance ) { 
  65. self::$instance = new self; 
  66.  
  67. return self::$instance; 
  68.  
  69. /** 
  70. * Register the BuddyPress Profile Tabs administration menu into the WordPress Dashboard menu. 
  71. * @since 1.5.0 
  72. */ 
  73. public function add_plugin_admin_menu() { 
  74. /** 
  75. * Add BuddyPress Profile Tabs settings page to the Settings menu. 
  76. */ 
  77. $this->plugin_screen_hook_suffix = add_options_page( 
  78. __( 'BuddyPress Profile Tabs', $this->plugin_slug ),  
  79. __( 'BP Profile Tabs', $this->plugin_slug ),  
  80. 'manage_options',  
  81. $this->plugin_slug,  
  82. array( $this, 'display_plugin_admin_page' ) 
  83. ); 
  84.  
  85. /** 
  86. * Render the settings page for this plugin. 
  87. * @since 1.5.0 
  88. */ 
  89. public function display_plugin_admin_page() { 
  90. include_once( 'views/admin.php' ); 
  91.  
  92. /** 
  93. * Add settings action link to the plugins page. 
  94. * @param array $links Menu items array. 
  95. * @since 1.5.0 
  96. * @return array 
  97. */ 
  98. public function add_action_links( $links ) { 
  99. return array_merge( 
  100. array( 'settings' => '<a href="' . admin_url( 'options-general.php?page=' . $this->plugin_slug ) . '">' . __( 'Settings' ) . '</a>' ),  
  101. $links 
  102. ); 
  103.  
  104. /** 
  105. * Export settings. 
  106. */ 
  107. function settings_export() { 
  108. $post_vars = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); 
  109. if ( empty( $post_vars['pn_action'] ) || 'export_settings' !== $post_vars['pn_action'] ) { 
  110. return; 
  111.  
  112. if ( ! wp_verify_nonce( $post_vars['pn_export_nonce'], 'pn_export_nonce' ) ) { 
  113. return; 
  114.  
  115. if ( ! current_user_can( 'manage_options' ) ) { 
  116. return; 
  117. $settings[0] = get_option( 'bp_profile_tabs_option' ); 
  118.  
  119. ignore_user_abort( true ); 
  120.  
  121. nocache_headers(); 
  122. header( 'Content-Type: application/json; charset=utf-8' ); 
  123. header( 'Content-Disposition: attachment; filename=pn-settings-export-' . date( 'm-d-Y' ) . '.json' ); 
  124. header( 'Expires: 0' ); 
  125.  
  126. echo json_encode( $settings ); 
  127. exit; 
  128.  
  129. /** 
  130. * Process a settings import from a json file 
  131. */ 
  132. function settings_import() { 
  133. $post_vars = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); 
  134. if ( empty( $post_vars['pn_action'] ) || 'import_settings' !== $post_vars['pn_action'] ) { 
  135. return; 
  136.  
  137. if ( ! wp_verify_nonce( $post_vars['pn_import_nonce'], 'pn_import_nonce' ) ) { 
  138. return; 
  139.  
  140. if ( ! current_user_can( 'manage_options' ) ) { 
  141. return; 
  142. $extension = end( explode( '.', $_FILES[ 'import_file' ][ 'name' ] ) ); 
  143.  
  144. if ( 'json' !== $extension ) { 
  145. wp_die( __( 'Please upload a valid .json file', $this->plugin_slug ) ); 
  146.  
  147. $import_file = $_FILES[ 'import_file' ][ 'tmp_name' ]; 
  148.  
  149. if ( empty( $import_file ) ) { 
  150. wp_die( __( 'Please upload a file to import', $this->plugin_slug ) ); 
  151.  
  152. // Retrieve the settings from the file and convert the json object to an array. 
  153. $settings = (array) json_decode( file_get_contents( $import_file ) ); 
  154.  
  155. update_option( 'bp_profile_tabs_option', get_object_vars( $settings[0] ) ); 
  156.  
  157. wp_safe_redirect( admin_url( 'options-general.php?page=' . $this->plugin_slug ) ); 
  158. exit; 
  159.  
  160. /** 
  161. * Get the CMBF meta box class 
  162. */ 
  163. public function add_cmb_Meta_Box_class() { 
  164. require_once( plugin_dir_path( __FILE__ ) . 'includes/CMBF/init.php' ); 
  165.  
  166. /** 
  167. * Load the admin scripts 
  168. */ 
  169. public function load_admin_scripts() { 
  170. $post_vars = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); 
  171. $get_vars = filter_input_array( INPUT_GET, FILTER_SANITIZE_STRING ); 
  172. if ( isset( $get_vars['page'] ) && 'bp-profile-tabs' === $get_vars['page'] ) { 
  173. if ( isset( $post_vars['bpt_custom'] ) ) { 
  174. wp_deregister_style( $this->plugin_slug . '-jquery-ui-style' ); 
  175. wp_dequeue_style( $this->plugin_slug . '-jquery-ui-style' ); 
  176. $jquery_ui_css_url = $post_vars['bpt_custom']; 
  177. wp_enqueue_style( $this->plugin_slug . '-jquery-ui-style', $jquery_ui_css_url, array(), $this->version ); 
  178. } else { 
  179. wp_enqueue_style( $this->plugin_slug . '-jquery-ui-style' ); 
  180. wp_enqueue_script( $this->plugin_slug . '-script' ); 
  181.  
  182.  
  183. /** 
  184. * Register the BPT style 
  185. */ 
  186. public function admin_register_bpt_script() { 
  187. $post_vars = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); 
  188. wp_register_script( $this->plugin_slug . '-script', plugins_url( 'assets/js/admin.js', __FILE__ ), array( 'jquery', 'jquery-ui-tabs' ), $this->version ); 
  189. $bpt_theme = isset( $post_vars['bpt_theme'] ) ? sanitize_text_field( $post_vars['bpt_theme'] ) : ''; 
  190. $bpt_options = get_option( 'bp_profile_tabs_option' ); 
  191. if ( empty( $bpt_theme ) ) { 
  192. $bpt_theme = $bpt_options['bpt_theme']; 
  193.  
  194. $protocol = is_ssl() ? 'https' : 'http'; 
  195. $jquery_ui_version = $this->jquery_ui_version; 
  196. if ( 'google' === $bpt_options['bpt_cdn'] ) { 
  197. $jquery_ui_css_url = $protocol . '://ajax.googleapis.com/ajax/libs/jqueryui/'.$jquery_ui_version.'/themes/'.$bpt_theme.'/jquery-ui.css'; 
  198. if ( 'microsoft' === $bpt_options['bpt_cdn'] ) { 
  199. $jquery_ui_css_url = $protocol . '://ajax.aspnetcdn.com/ajax/jquery.ui/'.$jquery_ui_version.'/themes/'.$bpt_theme.'/jquery-ui.css'; 
  200. if ( 'jquery' === $bpt_options['bpt_cdn'] ) { 
  201. $jquery_ui_css_url = $protocol . '://code.jquery.com/ui/'.$jquery_ui_version.'/themes/'.$bpt_theme.'/jquery-ui.css'; 
  202. if ( ! empty( $bpt_options['bpt_custom'] ) ) { 
  203. $jquery_ui_css_url = $bpt_options['bpt_custom']; 
  204. wp_register_style( $this->plugin_slug . '-jquery-ui-style', $jquery_ui_css_url, array(), $this->version );