plug_admin_bar.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <?php
  2. if (!class_exists("plug_admin_bar")) {
  3. class plug_admin_bar {
  4. function plug_admin_bar($ns) {
  5. $this->title = __("Admin bar","dagsopt");
  6. $this->pluginname = $ns->pluginname;
  7. $this->file = $ns->file;
  8. $this->ns = $ns;
  9. }
  10. function start(){
  11. add_action( 'admin_bar_menu' , array(&$this,'bu_admin_link_first'), 1 );
  12. add_action( 'admin_bar_menu' , array(&$this,'bu_admin_link_last'), 200 );
  13. if(get_option( $this->pluginname."_admin_bar".'_remove_comments' ,false)){
  14. add_action( 'wp_before_admin_bar_render' , array(&$this,'bu_admin_link_remove_comments'), 210 );
  15. }
  16. if(!function_exists('wp_get_current_user')) {
  17. include(ABSPATH . "wp-includes/pluggable.php");
  18. }
  19. // remove_submenu_page('index.php','update-core.php');
  20. $current_user = wp_get_current_user();
  21. if( current_user_can( 'manage_options' ) && $current_user->user_login == "admin") {
  22. add_action( 'admin_menu' , array(&$this,'setup_menus'), 220 );
  23. } else {
  24. add_action( 'admin_menu' , array(&$this,'remove_menus'), 220 );
  25. add_action( 'wp_before_admin_bar_render' , array(&$this,'remove_menus2'), 210 );
  26. }
  27. }
  28. function remove_menus2() {
  29. global $wp_admin_bar;
  30. if(get_option( $this->pluginname."_admin_bar".'_remove_new-post' ,false)){
  31. $wp_admin_bar->remove_menu("new-post");
  32. }
  33. if(get_option( $this->pluginname."_admin_bar".'_remove_new-link' ,false)){
  34. $wp_admin_bar->remove_menu("new-link");
  35. }
  36. if(get_option( $this->pluginname."_admin_bar".'_remove_new-page' ,false)){
  37. $wp_admin_bar->remove_menu("new-page");
  38. }
  39. if(get_option( $this->pluginname."_admin_bar".'_remove_new-media' ,false)){
  40. $wp_admin_bar->remove_menu("new-media");
  41. }
  42. if(get_option( $this->pluginname."_admin_bar".'_remove_new-user' ,false)){
  43. $wp_admin_bar->remove_menu("new-user");
  44. }
  45. }
  46. function setup_menus () {
  47. global $menu;
  48. $this->gmenu = $menu;
  49. }
  50. function remove_menus () {
  51. global $menu;
  52. $this->setup_menus();
  53. $rr = array();
  54. foreach($this->gmenu as $id => $mm){
  55. if(get_option($this->pluginname."_admin_bar".'_remove_'.$mm[5],false)){
  56. array_push($rr,$mm[5]);
  57. }
  58. }
  59. foreach($menu as $id => $menupoint){
  60. if(isset($menupoint[5]) && in_array($menupoint[5],$rr)){
  61. unset($menu[$id]);
  62. }
  63. }
  64. remove_submenu_page('index.php','update-core.php');
  65. remove_submenu_page('themes.php','update');
  66. remove_submenu_page('themes.php','checkupdate');
  67. remove_submenu_page('themes.php','custom-header');
  68. remove_submenu_page('themes.php','custom-background');
  69. remove_submenu_page('themes.php','theme-editor.php');
  70. remove_submenu_page('themes.php','themes.php');
  71. //add_submenu_page( 'themes.php', "Customize", "Customize", "", "customize.php", "");
  72. }
  73. function bu_admin_link_first() {
  74. global $wp_admin_bar;
  75. if(get_option( $this->pluginname."_admin_bar".'_dags_logo' ,true)){
  76. $wp_admin_bar->add_menu( array('id' => 'dags-logo', 'title' => '<img src="/wp-content/plugins/dagsplug/logo.png" style="margin-top: 4px;">', 'href' => 'https://dags.dk/' , 'meta' => array('title' => __('Dags dk','dagsopt'), ), ) );
  77. }
  78. }
  79. function bu_admin_link_remove_comments() {
  80. global $wp_admin_bar;
  81. $wp_admin_bar->remove_menu('comments');
  82. }
  83. function bu_admin_link_last() {
  84. global $wp_admin_bar;
  85. if(get_option( $this->pluginname."_admin_bar".'_dags_logo' ,true)){
  86. $wp_admin_bar->remove_node("wp-logo");
  87. }
  88. if(get_option( $this->pluginname."_admin_bar".'_show_ip' ,true)){
  89. $wp_admin_bar->add_menu( array( 'parent' => 'top-secondary', 'id' => 'IP', 'title' => 'IP: '.$_SERVER['SERVER_ADDR'], 'href' => admin_url( 'admin.php?page='.$this->pluginname.'-options' ) ) );
  90. }
  91. if ( current_user_can( 'manage_options' ) && get_option( $this->pluginname."_admin_bar_live_url" )) {
  92. if(get_option( $this->pluginname."_admin_bar".'_show_switcher' ,true)){
  93. if($_SERVER['HTTP_HOST']==get_option( $this->pluginname."_admin_bar_live_url" )){
  94. $wp_admin_bar->add_menu( array( 'parent' => 'top-secondary', 'id' => 'DEV_live', 'title' => get_option( $this->pluginname."_admin_bar_live_title" ), 'href' => get_option( $this->pluginname."_admin_bar_live_url" ).$_SERVER['REQUEST_URI'], 'meta'=>array('class'=> 'active') ) );
  95. $wp_admin_bar->add_menu( array( 'parent' => 'top-secondary', 'id' => 'DEV_stage', 'title' => get_option( $this->pluginname."_admin_bar_stage_title" ), 'href' => get_option( $this->pluginname."_admin_bar_stage_url" ).$_SERVER['REQUEST_URI'], 'meta'=>array('class'=> '') ) );
  96. $wp_admin_bar->add_menu( array( 'parent' => 'top-secondary', 'id' => 'DEV_local', 'title' => get_option( $this->pluginname."_admin_bar_local_title" ), 'href' => get_option( $this->pluginname."_admin_bar_local_url" ).$_SERVER['REQUEST_URI'], 'meta'=>array('class'=> '') ) );
  97. }else if($_SERVER['HTTP_HOST']==get_option( $this->pluginname."_admin_bar_stage_url" )){
  98. $wp_admin_bar->add_menu( array( 'parent' => 'top-secondary', 'id' => 'DEV_live', 'title' => get_option( $this->pluginname."_admin_bar_live_title" ), 'href' => get_option( $this->pluginname."_admin_bar_live_url" ).$_SERVER['REQUEST_URI'], 'meta'=>array('class'=> '') ) );
  99. $wp_admin_bar->add_menu( array( 'parent' => 'top-secondary', 'id' => 'DEV_stage', 'title' => get_option( $this->pluginname."_admin_bar_stage_title" ), 'href' => get_option( $this->pluginname."_admin_bar_stage_url" ).$_SERVER['REQUEST_URI'], 'meta'=>array('class'=> 'active') ) );
  100. $wp_admin_bar->add_menu( array( 'parent' => 'top-secondary', 'id' => 'DEV_local', 'title' => get_option( $this->pluginname."_admin_bar_local_title" ), 'href' => get_option( $this->pluginname."_admin_bar_local_url" ).$_SERVER['REQUEST_URI'], 'meta'=>array('class'=> '') ) );
  101. }else{
  102. $wp_admin_bar->add_menu( array( 'parent' => 'top-secondary', 'id' => 'DEV_live', 'title' => get_option( $this->pluginname."_admin_bar_live_title" ), 'href' => get_option( $this->pluginname."_admin_bar_live_url" ).$_SERVER['REQUEST_URI'], 'meta'=>array('class'=> '') ) );
  103. $wp_admin_bar->add_menu( array( 'parent' => 'top-secondary', 'id' => 'DEV_stage', 'title' => get_option( $this->pluginname."_admin_bar_stage_title" ), 'href' => get_option( $this->pluginname."_admin_bar_stage_url" ).$_SERVER['REQUEST_URI'], 'meta'=>array('class'=> '') ) );
  104. $wp_admin_bar->add_menu( array( 'parent' => 'top-secondary', 'id' => 'DEV_local', 'title' => get_option( $this->pluginname."_admin_bar_local_title" ), 'href' => get_option( $this->pluginname."_admin_bar_local_url" ).$_SERVER['REQUEST_URI'], 'meta'=>array('class'=> 'active') ) );
  105. }
  106. }
  107. } else {
  108. }
  109. }
  110. function help(){
  111. ?>
  112. <?php echo(__("Server switcher : local > stage > live","dagsopt")) ?><br>
  113. <?php echo(__("Swap WP for dags logo","dagsopt")) ?><br>
  114. <?php echo(__("Show server ip","dagsopt")) ?><br>
  115. <?php
  116. }
  117. function Option($pre){
  118. update_option ( $pre.'_show_switcher', $_POST [ $pre.'_show_switcher' ] );
  119. if(!empty($_POST [ $pre.'_live_url' ])){
  120. update_option ( $pre.'_live_url', $_POST [ $pre.'_live_url' ] );
  121. }
  122. if(!empty($_POST [ $pre.'_live_title' ])){
  123. update_option ( $pre.'_live_title', $_POST [ $pre.'_live_title' ] );
  124. }
  125. if(!empty($_POST [ $pre.'_stage_url' ])){
  126. update_option ( $pre.'_stage_url', $_POST [ $pre.'_stage_url' ] );
  127. }
  128. if(!empty($_POST [ $pre.'_stage_title' ])){
  129. update_option ( $pre.'_stage_title', $_POST [ $pre.'_stage_title' ] );
  130. }
  131. if(!empty($_POST [ $pre.'_local_url' ])){
  132. update_option ( $pre.'_local_url', $_POST [ $pre.'_local_url' ] );
  133. }
  134. if(!empty($_POST [ $pre.'_local_title' ])){
  135. update_option ( $pre.'_local_title', $_POST [ $pre.'_local_title' ] );
  136. }
  137. update_option ( $pre.'_dags_logo', $_POST [ $pre.'_dags_logo' ] );
  138. update_option ( $pre.'_show_ip', $_POST [ $pre.'_show_ip' ] );
  139. update_option ( $pre.'_remove_comments', $_POST [ $pre.'_remove_comments' ] );
  140. update_option ( $pre.'_remove_new-post', $_POST [ $pre.'_remove_new-post' ] );
  141. update_option ( $pre.'_remove_new-link', $_POST [ $pre.'_remove_new-link' ] );
  142. update_option ( $pre.'_remove_new-media', $_POST [ $pre.'_remove_new-media' ] );
  143. update_option ( $pre.'_remove_new-page', $_POST [ $pre.'_remove_new-page' ] );
  144. update_option ( $pre.'_remove_new-user', $_POST [ $pre.'_remove_new-user' ] );
  145. foreach($this->gmenu as $id => $mm){
  146. update_option ( $pre.'_remove_'.$mm[5], $_POST [ $pre.'_remove_'.$mm[5] ] );
  147. }
  148. }
  149. function admin_line($pre){
  150. ?>
  151. <table>
  152. <tr><td ><?php echo(__("Server switcher","dagsopt")) ?></td><td><input name="<?php echo( $pre.'_show_switcher' ); ?>" type="checkbox" id="<?php echo( $pre.'_show_switcher' ); ?>" <?php if(get_option( $pre.'_show_switcher' ,true)) echo 'checked'; ?> />
  153. <?php if(get_option( $pre.'_show_switcher' ,true)){
  154. ?>
  155. <table>
  156. <tr><td ><input type="text" name="<?php echo( $pre.'_live_title' ); ?>" value="<?php echo( get_option( $pre.'_live_title','live' ) ); ?>"></td><td><input type="text" name="<?php echo( $pre.'_live_url' ); ?>" value="<?php echo( get_option( $pre.'_live_url' ) ); ?>"></td></tr>
  157. <tr><td><input type="text" name="<?php echo( $pre.'_stage_title' ); ?>" value="<?php echo( get_option( $pre.'_stage_title','stage' ) ); ?>"></td><td><input type="text" name="<?php echo( $pre.'_stage_url' ); ?>" value="<?php echo( get_option( $pre.'_stage_url' ) ); ?>"></td></tr>
  158. <tr><td><input type="text" name="<?php echo( $pre.'_local_title' ); ?>" value="<?php echo( get_option( $pre.'_local_title','local' ) ); ?>"></td><td><input type="text" name="<?php echo( $pre.'_local_url' ); ?>" value="<?php echo( get_option( $pre.'_local_url' ) ); ?>"></td></tr>
  159. </table>
  160. <?php
  161. } ?>
  162. </td></tr>
  163. <tr><td ><?php echo(__("Dags logo","dagsopt")) ?></td><td><input name="<?php echo( $pre.'_dags_logo' ); ?>" type="checkbox" id="<?php echo( $pre.'_dags_logo' ); ?>" <?php if(get_option( $pre.'_dags_logo' ,true)) echo 'checked'; ?> /></td></tr>
  164. <tr><td ><?php echo(__("Show IP","dagsopt")) ?></td><td><input name="<?php echo( $pre.'_show_ip' ); ?>" type="checkbox" id="<?php echo( $pre.'_show_ip' ); ?>" <?php if(get_option( $pre.'_show_ip' ,true)) echo 'checked'; ?> /></td></tr>
  165. <tr><td colspan="2"><a href="javascript:$('#dags_tools_menus').toggle();">Remove Menus</a></td></tr>
  166. <tr><td ></td><td>
  167. <table id="dags_tools_menus" style="display: none;">
  168. <tr><td colspan="2">Remove Admin Top Bar</td></tr>
  169. <tr><td ><?php echo(__("Comments","dagsopt")) ?></td><td><input name="<?php echo( $pre.'_remove_comments' ); ?>" type="checkbox" id="<?php echo( $pre.'_remove_comments' ); ?>" <?php if(get_option( $pre.'_remove_comments' ,false)) echo 'checked'; ?> /></td></tr>
  170. <tr><td ><?php echo(__("New Post","dagsopt")) ?></td><td><input name="<?php echo( $pre.'_remove_new-post' ); ?>" type="checkbox" id="<?php echo( $pre.'_remove_new-post' ); ?>" <?php if(get_option( $pre.'_remove_new-post' ,false)) echo 'checked'; ?> /></td></tr>
  171. <tr><td ><?php echo(__("New Link","dagsopt")) ?></td><td><input name="<?php echo( $pre.'_remove_new-link' ); ?>" type="checkbox" id="<?php echo( $pre.'_remove_new-link' ); ?>" <?php if(get_option( $pre.'_remove_new-link' ,false)) echo 'checked'; ?> /></td></tr>
  172. <tr><td ><?php echo(__("New Media","dagsopt")) ?></td><td><input name="<?php echo( $pre.'_remove_new-media' ); ?>" type="checkbox" id="<?php echo( $pre.'_remove_new-media' ); ?>" <?php if(get_option( $pre.'_remove_new-media' ,false)) echo 'checked'; ?> /></td></tr>
  173. <tr><td ><?php echo(__("New Page","dagsopt")) ?></td><td><input name="<?php echo( $pre.'_remove_new-page' ); ?>" type="checkbox" id="<?php echo( $pre.'_remove_new-page' ); ?>" <?php if(get_option( $pre.'_remove_new-page' ,false)) echo 'checked'; ?> /></td></tr>
  174. <tr><td ><?php echo(__("New User","dagsopt")) ?></td><td><input name="<?php echo( $pre.'_remove_new-user' ); ?>" type="checkbox" id="<?php echo( $pre.'_remove_new-user' ); ?>" <?php if(get_option( $pre.'_remove_new-user' ,false)) echo 'checked'; ?> /></td></tr>
  175. <tr><td colspan="2">Remove Admin Mode Bar</td></tr>
  176. <?php
  177. foreach($this->gmenu as $id => $mm){
  178. if(strstr($mm[2],"separator")){
  179. continue;
  180. }
  181. ?>
  182. <tr><td ><?php echo($mm[0]) ?> </td><td><input name="<?php echo( $pre.'_remove_'.$mm[5] ); ?>" type="checkbox" id="<?php echo( $pre.'_remove_'.$mm[5] ); ?>" <?php if(get_option( $pre.'_remove_'.$mm[5] ,false)) echo 'checked'; ?> /> <?php echo($mm[5]); ?></td></tr>
  183. <?php
  184. }
  185. ?>
  186. </table>
  187. </td></tr>
  188. </table>
  189. <?php
  190. }
  191. }
  192. global $plug_admin_bar;
  193. $plug_admin_bar = new plug_admin_bar($this);
  194. $this->dagsopt['plug_admin_bar'] = $plug_admin_bar;
  195. }