plug_admin_bar.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <?php
  2. if (!class_exists("plug_admin_bar")) {
  3. class plug_admin_bar {
  4. function __construct($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. }
  74. function bu_admin_link_first() {
  75. global $wp_admin_bar;
  76. if (get_option($this->pluginname . "_admin_bar" . '_dags_logo', true)) {
  77. $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'))));
  78. }
  79. }
  80. function bu_admin_link_remove_comments() {
  81. global $wp_admin_bar;
  82. $wp_admin_bar->remove_menu('comments');
  83. }
  84. function bu_admin_link_last() {
  85. global $wp_admin_bar;
  86. if (get_option($this->pluginname . "_admin_bar" . '_dags_logo', true)) {
  87. $wp_admin_bar->remove_node("wp-logo");
  88. }
  89. if (get_option($this->pluginname . "_admin_bar" . '_show_ip', true)) {
  90. $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')));
  91. }
  92. if (current_user_can('manage_options') && get_option($this->pluginname . "_admin_bar_live_url")) {
  93. if (get_option($this->pluginname . "_admin_bar" . '_show_switcher', true)) {
  94. if ($_SERVER['HTTP_HOST'] == get_option($this->pluginname . "_admin_bar_live_url")) {
  95. $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')));
  96. $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' => '')));
  97. $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' => '')));
  98. } else if ($_SERVER['HTTP_HOST'] == get_option($this->pluginname . "_admin_bar_stage_url")) {
  99. $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' => '')));
  100. $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')));
  101. $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' => '')));
  102. } else {
  103. $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' => '')));
  104. $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' => '')));
  105. $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')));
  106. }
  107. }
  108. } else {
  109. }
  110. }
  111. function help() {
  112. ?>
  113. <?php echo (__("Server switcher : local > stage > live", "dagsopt")) ?><br>
  114. <?php echo (__("Swap WP for dags logo", "dagsopt")) ?><br>
  115. <?php echo (__("Show server ip", "dagsopt")) ?><br>
  116. <?php
  117. }
  118. function Option($pre) {
  119. update_option($pre . '_show_switcher', $_POST[$pre . '_show_switcher']);
  120. if (!empty($_POST[$pre . '_live_url'])) {
  121. update_option($pre . '_live_url', $_POST[$pre . '_live_url']);
  122. }
  123. if (!empty($_POST[$pre . '_live_title'])) {
  124. update_option($pre . '_live_title', $_POST[$pre . '_live_title']);
  125. }
  126. if (!empty($_POST[$pre . '_stage_url'])) {
  127. update_option($pre . '_stage_url', $_POST[$pre . '_stage_url']);
  128. }
  129. if (!empty($_POST[$pre . '_stage_title'])) {
  130. update_option($pre . '_stage_title', $_POST[$pre . '_stage_title']);
  131. }
  132. if (!empty($_POST[$pre . '_local_url'])) {
  133. update_option($pre . '_local_url', $_POST[$pre . '_local_url']);
  134. }
  135. if (!empty($_POST[$pre . '_local_title'])) {
  136. update_option($pre . '_local_title', $_POST[$pre . '_local_title']);
  137. }
  138. update_option($pre . '_dags_logo', $_POST[$pre . '_dags_logo']);
  139. update_option($pre . '_show_ip', $_POST[$pre . '_show_ip']);
  140. update_option($pre . '_remove_comments', $_POST[$pre . '_remove_comments']);
  141. update_option($pre . '_remove_new-post', $_POST[$pre . '_remove_new-post']);
  142. update_option($pre . '_remove_new-link', $_POST[$pre . '_remove_new-link']);
  143. update_option($pre . '_remove_new-media', $_POST[$pre . '_remove_new-media']);
  144. update_option($pre . '_remove_new-page', $_POST[$pre . '_remove_new-page']);
  145. update_option($pre . '_remove_new-user', $_POST[$pre . '_remove_new-user']);
  146. foreach ($this->gmenu as $id => $mm) {
  147. update_option($pre . '_remove_' . $mm[5], $_POST[$pre . '_remove_' . $mm[5]]);
  148. }
  149. }
  150. function admin_line($pre) {
  151. ?>
  152. <table>
  153. <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)) {
  154. echo 'checked';
  155. }
  156. ?> />
  157. <?php if (get_option($pre . '_show_switcher', true)) {
  158. ?>
  159. <table>
  160. <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>
  161. <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>
  162. <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>
  163. </table>
  164. <?php
  165. }?>
  166. </td></tr>
  167. <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)) {
  168. echo 'checked';
  169. }
  170. ?> /></td></tr>
  171. <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)) {
  172. echo 'checked';
  173. }
  174. ?> /></td></tr>
  175. <tr><td colspan="2"><a href="javascript:$('#dags_tools_menus').toggle();">Remove Menus</a></td></tr>
  176. <tr><td ></td><td>
  177. <table id="dags_tools_menus" style="display: none;">
  178. <tr><td colspan="2">Remove Admin Top Bar</td></tr>
  179. <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)) {
  180. echo 'checked';
  181. }
  182. ?> /></td></tr>
  183. <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)) {
  184. echo 'checked';
  185. }
  186. ?> /></td></tr>
  187. <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)) {
  188. echo 'checked';
  189. }
  190. ?> /></td></tr>
  191. <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)) {
  192. echo 'checked';
  193. }
  194. ?> /></td></tr>
  195. <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)) {
  196. echo 'checked';
  197. }
  198. ?> /></td></tr>
  199. <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)) {
  200. echo 'checked';
  201. }
  202. ?> /></td></tr>
  203. <tr><td colspan="2">Remove Admin Mode Bar</td></tr>
  204. <?php
  205. foreach ($this->gmenu as $id => $mm) {
  206. if (strstr($mm[2], "separator")) {
  207. continue;
  208. }
  209. ?>
  210. <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)) {
  211. echo 'checked';
  212. }
  213. ?> /> <?php echo ($mm[5]); ?></td></tr>
  214. <?php
  215. }
  216. ?>
  217. </table>
  218. </td></tr>
  219. </table>
  220. <?php
  221. }
  222. }
  223. global $plug_admin_bar;
  224. $plug_admin_bar = new plug_admin_bar($this);
  225. $this->dagsopt['plug_admin_bar'] = $plug_admin_bar;
  226. }