class-fl-builder-user-templates-admin-menu.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * Logic for the user templates admin menu.
  4. *
  5. * @since 1.10
  6. */
  7. final class FLBuilderUserTemplatesAdminMenu {
  8. /**
  9. * Initialize hooks.
  10. *
  11. * @since 1.10
  12. * @return void
  13. */
  14. static public function init() {
  15. /* Actions */
  16. add_action( 'admin_menu', __CLASS__ . '::register' );
  17. /* Filters */
  18. add_filter( 'submenu_file', __CLASS__ . '::submenu_file', 999, 2 );
  19. }
  20. /**
  21. * Registers the builder admin menu for user templates.
  22. *
  23. * @since 1.10
  24. * @return void
  25. */
  26. static public function register() {
  27. global $submenu, $_registered_pages;
  28. $parent = 'edit.php?post_type=fl-builder-template';
  29. $cap = 'edit_posts';
  30. $list_url = 'edit.php?post_type=fl-builder-template&fl-builder-template-type=';
  31. $add_url = 'post-new.php?post_type=fl-builder-template';
  32. $cats_url = 'edit-tags.php?taxonomy=fl-builder-template-category&post_type=fl-builder-template';
  33. $add_new_hook = 'fl-builder-template_page_fl-builder-add-new';
  34. $submenu[ $parent ] = array();
  35. $submenu[ $parent ][100] = array( __( 'Templates', 'vamtam-elements-b' ), $cap, $list_url . 'layout' );
  36. $submenu[ $parent ][200] = array( __( 'Saved Rows', 'vamtam-elements-b' ), $cap, $list_url . 'row' );
  37. $submenu[ $parent ][300] = array( __( 'Saved Columns', 'vamtam-elements-b' ), $cap, $list_url . 'column' );
  38. $submenu[ $parent ][400] = array( __( 'Saved Modules', 'vamtam-elements-b' ), $cap, $list_url . 'module' );
  39. $submenu[ $parent ][500] = array( __( 'Categories', 'vamtam-elements-b' ), $cap, $cats_url );
  40. $submenu[ $parent ][700] = array( __( 'Add New', 'vamtam-elements-b' ), $cap, 'fl-builder-add-new', '' );
  41. if ( current_user_can( $cap ) ) {
  42. add_action( $add_new_hook, 'FLBuilderUserTemplatesAdminAdd::render' );
  43. $_registered_pages[ $add_new_hook ] = true;
  44. }
  45. $submenu[ $parent ] = apply_filters( 'fl_builder_user_templates_admin_menu', $submenu[ $parent ] );
  46. }
  47. /**
  48. * Sets the active menu item for the builder admin submenu.
  49. *
  50. * @since 1.10
  51. * @param string $submenu_file
  52. * @param string $parent_file
  53. * @return string
  54. */
  55. static public function submenu_file( $submenu_file, $parent_file ) {
  56. global $pagenow;
  57. global $post;
  58. $screen = get_current_screen();
  59. $list_url = 'edit.php?post_type=fl-builder-template';
  60. $new_url = 'post-new.php?post_type=fl-builder-template';
  61. if ( isset( $_GET['page'] ) && 'fl-builder-add-new' == $_GET['page'] ) {
  62. $submenu_file = 'fl-builder-add-new';
  63. } elseif ( isset( $_GET['fl-builder-template-type'] ) && $list_url == $parent_file ) {
  64. $type = sanitize_text_field( $_GET['fl-builder-template-type'] );
  65. $submenu_file = $parent_file . '&fl-builder-template-type=' . $type;
  66. } elseif ( 'post.php' == $pagenow && 'fl-builder-template' == $screen->post_type ) {
  67. $type = FLBuilderModel::get_user_template_type( $post->ID );
  68. $submenu_file = 'edit.php?post_type=fl-builder-template&fl-builder-template-type=' . $type;
  69. } elseif ( 'edit-tags.php' == $pagenow && 'fl-builder-template-category' == $screen->taxonomy ) {
  70. $submenu_file = 'edit-tags.php?taxonomy=fl-builder-template-category&post_type=fl-builder-template';
  71. } elseif ( 'term.php' == $pagenow && 'fl-builder-template-category' == $screen->taxonomy ) {
  72. $submenu_file = 'edit-tags.php?taxonomy=fl-builder-template-category&post_type=fl-builder-template';
  73. }
  74. return $submenu_file;
  75. }
  76. }
  77. FLBuilderUserTemplatesAdminMenu::init();