class-vc-gutenberg-param.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. header( 'Status: 403 Forbidden' );
  4. header( 'HTTP/1.1 403 Forbidden' );
  5. exit;
  6. }
  7. /**
  8. * Class Vc_Gutenberg_Param
  9. */
  10. class Vc_Gutenberg_Param {
  11. protected $postTypeSlug = 'wpb_gutenberg_param';
  12. public function __construct() {
  13. add_action( 'init', array(
  14. $this,
  15. 'initialize',
  16. ) );
  17. }
  18. public function initialize() {
  19. global $pagenow, $wp_version;
  20. if ( version_compare( $wp_version, '4.9.8', '>' ) && 'post-new.php' === $pagenow && vc_user_access()->wpAll( 'edit_posts' )
  21. ->get() && vc_request_param( 'post_type' ) === $this->postTypeSlug ) {
  22. $this->registerGutenbergAttributeType();
  23. /** @see \Vc_Gutenberg_Param::removeAdminUi */
  24. add_action( 'admin_enqueue_scripts', array(
  25. $this,
  26. 'removeAdminUI',
  27. ) );
  28. }
  29. }
  30. public function removeAdminUi() {
  31. $style = '
  32. #adminmenumain, #wpadminbar {
  33. display: none;
  34. }
  35. html.wp-toolbar {
  36. padding: 0 !important;
  37. }
  38. .wp-toolbar #wpcontent {
  39. margin: 0;
  40. }
  41. .wp-toolbar #wpbody {
  42. padding-top: 0;
  43. }
  44. .gutenberg .gutenberg__editor .edit-post-layout .edit-post-header, html .block-editor-page .edit-post-header {
  45. top: 0;
  46. left: 0;
  47. }
  48. .gutenberg .gutenberg__editor .edit-post-layout.is-sidebar-opened .edit-post-layout__content, html .block-editor-page .edit-post-layout.is-sidebar-opened .edit-post-layout__content {
  49. margin-right: 0;
  50. }
  51. .gutenberg .gutenberg__editor .edit-post-layout .editor-post-publish-panel, html .block-editor-page .edit-post-layout .editor-post-publish-panel, html .block-editor-page .edit-post-header__settings {
  52. display: none;
  53. }
  54. .editor-post-title {
  55. display: none !important;
  56. }
  57. ';
  58. wp_add_inline_style( 'wp-edit-blocks', $style );
  59. }
  60. protected function registerGutenbergAttributeType() {
  61. $labels = array(
  62. 'name' => _x( 'Gutenberg attrs', 'Post type general name', 'js_composer' ),
  63. 'singular_name' => _x( 'Gutenberg attr', 'Post type singular name', 'js_composer' ),
  64. 'menu_name' => _x( 'Gutenberg attrs', 'Admin Menu text', 'js_composer' ),
  65. 'name_admin_bar' => _x( 'Gutenberg attr', 'Add New on Toolbar', 'js_composer' ),
  66. 'add_new' => esc_html__( 'Add New', 'js_composer' ),
  67. 'add_new_item' => esc_html__( 'Add New Gutenberg attr', 'js_composer' ),
  68. 'new_item' => esc_html__( 'New Gutenberg attr', 'js_composer' ),
  69. 'edit_item' => esc_html__( 'Edit Gutenberg attr', 'js_composer' ),
  70. 'view_item' => esc_html__( 'View Gutenberg attr', 'js_composer' ),
  71. 'all_items' => esc_html__( 'All Gutenberg attrs', 'js_composer' ),
  72. 'search_items' => esc_html__( 'Search Gutenberg attrs', 'js_composer' ),
  73. 'parent_item_colon' => esc_html__( 'Parent Gutenberg attrs:', 'js_composer' ),
  74. 'not_found' => esc_html__( 'No Gutenberg attrs found.', 'js_composer' ),
  75. 'not_found_in_trash' => esc_html__( 'No Gutenberg attrs found in Trash.', 'js_composer' ),
  76. 'featured_image' => _x( 'Gutenberg attr Cover Image', 'Overrides the “Featured Image” phrase for this post type. Added in 4.3', 'js_composer' ),
  77. 'set_featured_image' => _x( 'Set cover image', 'Overrides the “Set featured image” phrase for this post type. Added in 4.3', 'js_composer' ),
  78. 'remove_featured_image' => _x( 'Remove cover image', 'Overrides the “Remove featured image” phrase for this post type. Added in 4.3', 'js_composer' ),
  79. 'use_featured_image' => _x( 'Use as cover image', 'Overrides the “Use as featured image” phrase for this post type. Added in 4.3', 'js_composer' ),
  80. 'archives' => _x( 'Gutenberg attr archives', 'The post type archive label used in nav menus. Default “Post Archives”. Added in 4.4', 'js_composer' ),
  81. 'insert_into_item' => _x( 'Add into Gutenberg attr', 'Overrides the “Insert into post”/”Insert into page” phrase (used when inserting media into a post). Added in 4.4', 'js_composer' ),
  82. 'uploaded_to_this_item' => _x( 'Uploaded to this Gutenberg attr', 'Overrides the “Uploaded to this post”/”Uploaded to this page” phrase (used when viewing media attached to a post). Added in 4.4', 'js_composer' ),
  83. 'filter_items_list' => _x( 'Filter Gutenberg attrs list', 'Screen reader text for the filter links heading on the post type listing screen. Default “Filter posts list”/”Filter pages list”. Added in 4.4', 'js_composer' ),
  84. 'items_list_navigation' => _x( 'Gutenberg attrs list navigation', 'Screen reader text for the pagination heading on the post type listing screen. Default “Posts list navigation”/”Pages list navigation”. Added in 4.4', 'js_composer' ),
  85. 'items_list' => _x( 'Gutenberg attrs list', 'Screen reader text for the items list heading on the post type listing screen. Default “Posts list”/”Pages list”. Added in 4.4', 'js_composer' ),
  86. );
  87. $args = array(
  88. 'labels' => $labels,
  89. 'public' => true,
  90. 'publicly_queryable' => true,
  91. 'show_ui' => true,
  92. 'show_in_menu' => false,
  93. 'query_var' => false,
  94. 'capability_type' => 'page',
  95. 'has_archive' => false,
  96. 'hierarchical' => false,
  97. 'menu_position' => null,
  98. 'show_in_rest' => true,
  99. 'supports' => array( 'editor' ),
  100. );
  101. register_post_type( $this->postTypeSlug, $args );
  102. }
  103. }