| @@ -1,84 +1,72 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -defined('ABSPATH') or exit; | |
| 3 | +defined( 'ABSPATH' ) or exit; | |
| 4 | 4 | |
| 5 | 5 | $boxzilla = boxzilla(); |
| 6 | 6 | |
| 7 | 7 | // Register custom post type |
| 8 | -add_action( | |
| 9 | - 'init', | |
| 10 | - function () { | |
| 11 | - $args = [ | |
| 12 | - 'public' => false, | |
| 13 | - 'labels' => [ | |
| 14 | - 'name' => esc_html__('Boxzilla', 'boxzilla'), | |
| 15 | - 'singular_name' => esc_html__('Box', 'boxzilla'), | |
| 16 | - 'add_new' => esc_html__('Add New', 'boxzilla'), | |
| 17 | - 'add_new_item' => esc_html__('Add New Box', 'boxzilla'), | |
| 18 | - 'edit_item' => esc_html__('Edit Box', 'boxzilla'), | |
| 19 | - 'new_item' => esc_html__('New Box', 'boxzilla'), | |
| 20 | - 'all_items' => esc_html__('All Boxes', 'boxzilla'), | |
| 21 | - 'view_item' => esc_html__('View Box', 'boxzilla'), | |
| 22 | - 'search_items' => esc_html__('Search Boxes', 'boxzilla'), | |
| 23 | - 'not_found' => esc_html__('No Boxes found', 'boxzilla'), | |
| 24 | - 'not_found_in_trash' => esc_html__('No Boxes found in Trash', 'boxzilla'), | |
| 25 | - 'parent_item_colon' => '', | |
| 26 | - 'menu_name' => esc_html__('Boxzilla', 'boxzilla'), | |
| 27 | - ], | |
| 28 | - 'show_ui' => true, | |
| 29 | - 'menu_position' => 108, | |
| 30 | - 'menu_icon' => 'data:image/svg+xml;base64,' . base64_encode('<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="xMidYMid meet" viewBox="0 0 16 16" width="16" height="16"><defs><path d="M0 0L16 0L16 16L0 16L0 16L0 0ZM6.72 13.59L6.72 12.47L7.71 13.28L8.94 13.59L10.17 13.28L11.17 12.46L11.85 11.25L12.1 9.76L11.85 8.27L11.17 7.05L10.17 6.23L8.94 5.93L7.71 6.23L6.72 7.04L6.72 2.27L4.16 2.27L4.16 13.59L4.16 13.59L6.72 13.59ZM9.93 9.03L10.06 9.76L9.93 10.49L9.56 11.08L9.01 11.48L8.35 11.63L7.68 11.48L7.13 11.08L6.76 10.49L6.72 10.26L6.72 9.25L6.76 9.03L7.13 8.43L7.68 8.03L8.35 7.88L9.01 8.03L9.56 8.43L9.56 8.43L9.93 9.03Z" id="c1kAiZqIlD"></path></defs><g><g><g><use xlink:href="#c1kAiZqIlD" opacity="1" fill="#a0a5aa" fill-opacity="1"></use></g></g></g></svg>'), | |
| 31 | - 'query_var' => false, | |
| 32 | - 'capability_type' => 'box', | |
| 33 | - 'capabilities' => [ | |
| 34 | - 'edit_post' => 'edit_box', | |
| 35 | - 'edit_posts' => 'edit_boxes', | |
| 36 | - 'edit_others_posts' => 'edit_other_boxes', | |
| 37 | - 'publish_posts' => 'publish_boxes', | |
| 38 | - 'read_post' => 'read_box', | |
| 39 | - 'read_private_posts' => 'read_private_box', | |
| 40 | - 'delete_posts' => 'delete_box', | |
| 41 | - ], | |
| 42 | - ]; | |
| 8 | +add_action( 'init', function() use( $boxzilla ){ | |
| 9 | + $args = array( | |
| 10 | + 'public' => false, | |
| 11 | + 'labels' => array( | |
| 12 | + 'name' => __( 'Boxzilla', 'boxzilla' ), | |
| 13 | + 'singular_name' => __( 'Box', 'boxzilla' ), | |
| 14 | + 'add_new' => __( 'Add New', 'boxzilla' ), | |
| 15 | + 'add_new_item' => __( 'Add New Box', 'boxzilla' ), | |
| 16 | + 'edit_item' => __( 'Edit Box', 'boxzilla' ), | |
| 17 | + 'new_item' => __( 'New Box', 'boxzilla' ), | |
| 18 | + 'all_items' => __( 'All Boxes', 'boxzilla' ), | |
| 19 | + 'view_item' => __( 'View Box', 'boxzilla' ), | |
| 20 | + 'search_items' => __( 'Search Boxes', 'boxzilla' ), | |
| 21 | + 'not_found' => __( 'No Boxes found', 'boxzilla' ), | |
| 22 | + 'not_found_in_trash' => __( 'No Boxes found in Trash', 'boxzilla' ), | |
| 23 | + 'parent_item_colon' => '', | |
| 24 | + 'menu_name' => __( 'Boxzilla', 'boxzilla' ) | |
| 25 | + ), | |
| 26 | + 'show_ui' => true, | |
| 27 | + 'menu_position' => '108.1337133', | |
| 28 | + 'menu_icon' => 'data:image/svg+xml;base64,' . base64_encode( '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="xMidYMid meet" viewBox="0 0 16 16" width="16" height="16"><defs><path d="M0 0L16 0L16 16L0 16L0 16L0 0ZM6.72 13.59L6.72 12.47L7.71 13.28L8.94 13.59L10.17 13.28L11.17 12.46L11.85 11.25L12.1 9.76L11.85 8.27L11.17 7.05L10.17 6.23L8.94 5.93L7.71 6.23L6.72 7.04L6.72 2.27L4.16 2.27L4.16 13.59L4.16 13.59L6.72 13.59ZM9.93 9.03L10.06 9.76L9.93 10.49L9.56 11.08L9.01 11.48L8.35 11.63L7.68 11.48L7.13 11.08L6.76 10.49L6.72 10.26L6.72 9.25L6.76 9.03L7.13 8.43L7.68 8.03L8.35 7.88L9.01 8.03L9.56 8.43L9.56 8.43L9.93 9.03Z" id="c1kAiZqIlD"></path></defs><g><g><g><use xlink:href="#c1kAiZqIlD" opacity="1" fill="black" fill-opacity="1"></use></g></g></g></svg>' ), | |
| 29 | + 'query_var' => false, | |
| 30 | + 'capability_type' => 'box', | |
| 31 | + 'capabilities' => array( | |
| 32 | + 'edit_post' => 'edit_box', | |
| 33 | + 'edit_posts' => 'edit_boxes', | |
| 34 | + 'edit_others_posts' => 'edit_other_boxes', | |
| 35 | + 'publish_posts' => 'publish_boxes', | |
| 36 | + 'read_post' => 'read_box', | |
| 37 | + 'read_private_posts' => 'read_private_box', | |
| 38 | + 'delete_posts' => 'delete_box', | |
| 39 | + ), | |
| 40 | + ); | |
| 43 | 41 | |
| 44 | - register_post_type('boxzilla-box', $args); | |
| 42 | + register_post_type( 'boxzilla-box', $args ); | |
| 45 | 43 | |
| 46 | - add_shortcode('boxzilla_link', 'boxzilla_get_link_html'); | |
| 47 | - } | |
| 48 | -); | |
| 44 | + add_shortcode( 'boxzilla_link', 'boxzilla_get_link_html' ); | |
| 45 | +}); | |
| 49 | 46 | |
| 50 | -add_action( | |
| 51 | - 'admin_init', | |
| 52 | - function () { | |
| 53 | - $admins = get_role('administrator'); | |
| 47 | +add_action( 'admin_init', function() { | |
| 48 | + $admins = get_role( 'administrator' ); | |
| 54 | 49 | |
| 55 | - if (empty($admins)) { | |
| 56 | - return; | |
| 57 | - } | |
| 58 | - | |
| 59 | - if (! $admins->has_cap('edit_box')) { | |
| 60 | - $admins->add_cap('edit_box'); | |
| 61 | - $admins->add_cap('edit_boxes'); | |
| 62 | - $admins->add_cap('edit_other_boxes'); | |
| 63 | - $admins->add_cap('publish_boxes'); | |
| 64 | - $admins->add_cap('read_box'); | |
| 65 | - $admins->add_cap('read_private_box'); | |
| 66 | - $admins->add_cap('delete_box'); | |
| 67 | - } | |
| 50 | + if( ! $admins->has_cap( 'edit_box' ) ) { | |
| 51 | + $admins->add_cap('edit_box'); | |
| 52 | + $admins->add_cap('edit_boxes'); | |
| 53 | + $admins->add_cap('edit_other_boxes'); | |
| 54 | + $admins->add_cap('publish_boxes'); | |
| 55 | + $admins->add_cap('read_box'); | |
| 56 | + $admins->add_cap('read_private_box'); | |
| 57 | + $admins->add_cap('delete_box'); | |
| 68 | 58 | } |
| 69 | -); | |
| 59 | +}); | |
| 70 | 60 | |
| 71 | -function boxzilla_get_link_html($args = [], $content = '') | |
| 72 | -{ | |
| 73 | - $valid_actions = [ | |
| 61 | +function boxzilla_get_link_html( $args = array(), $content = '' ) { | |
| 62 | + $valid_actions = array( | |
| 74 | 63 | 'show', |
| 75 | 64 | 'toggle', |
| 76 | 65 | 'hide', |
| 77 | - 'dismiss', | |
| 78 | - ]; | |
| 79 | - $box_id = empty($args['box']) ? '' : absint($args['box']); | |
| 80 | - $class_attr = empty($args['class']) ? '' : esc_attr($args['class']); | |
| 81 | - $action = empty($args['action']) || ! in_array($args['action'], $valid_actions, true) ? 'show' : $args['action']; | |
| 82 | - | |
| 83 | - return "<a href=\"javascript:Boxzilla.{$action}({$box_id})\" class=\"{$class_attr}\">{$content}</a>"; | |
| 66 | + 'dismiss' | |
| 67 | + ); | |
| 68 | + $box_id = empty( $args['box'] ) ? '' : absint( $args['box'] ); | |
| 69 | + $class_attr = empty( $args['class'] ) ? '' : esc_attr( $args['class'] ); | |
| 70 | + $action = empty( $args['action'] ) || ! in_array( $args['action'], $valid_actions ) ? 'show' : $args['action']; | |
| 71 | + return sprintf( '<a href="javascript:Boxzilla.%s(%s)" class="%s">', $action, $box_id, $class_attr ) . $content . '</a>'; | |
| 84 | 72 | } |