page-role-manager.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. die( '-1' );
  4. }
  5. /**
  6. * @param $tabs
  7. * @return array
  8. */
  9. function vc_settings_tabs_vc_roles( $tabs ) {
  10. // inster after vc-general tab
  11. if ( array_key_exists( 'vc-general', $tabs ) ) {
  12. $new = array();
  13. foreach ( $tabs as $key => $value ) {
  14. $new[ $key ] = $value;
  15. if ( 'vc-general' === $key ) {
  16. $new['vc-roles'] = esc_html__( 'Role Manager', 'js_composer' );
  17. }
  18. }
  19. $tabs = $new;
  20. } else {
  21. $tabs['vc-roles'] = esc_html__( 'Roles Manager', 'js_composer' );
  22. }
  23. return $tabs;
  24. }
  25. if ( ! is_network_admin() ) {
  26. add_filter( 'vc_settings_tabs', 'vc_settings_tabs_vc_roles' );
  27. }
  28. /**
  29. * @return string
  30. */
  31. function vc_settings_render_tab_vc_roles() {
  32. return 'pages/vc-settings/tab-vc-roles.php';
  33. }
  34. add_filter( 'vc_settings-render-tab-vc-roles', 'vc_settings_render_tab_vc_roles' );
  35. function vc_roles_settings_save() {
  36. if ( check_admin_referer( 'vc_settings-roles-action', 'vc_nonce_field' ) && current_user_can( 'manage_options' ) ) {
  37. require_once vc_path_dir( 'SETTINGS_DIR', 'class-vc-roles.php' );
  38. $vc_roles = new Vc_Roles();
  39. $data = $vc_roles->save( vc_request_param( 'vc_roles', array() ) );
  40. echo wp_json_encode( $data );
  41. die();
  42. }
  43. }
  44. add_action( 'wp_ajax_vc_roles_settings_save', 'vc_roles_settings_save' );
  45. if ( 'vc-roles' === vc_get_param( 'page' ) ) {
  46. function vc_settings_render_tab_vc_roles_scripts() {
  47. wp_register_script( 'vc_accordion_script', vc_asset_url( 'lib/vc_accordion/vc-accordion.min.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
  48. }
  49. add_action( 'admin_init', 'vc_settings_render_tab_vc_roles_scripts' );
  50. }