add_cap( 'delete_anb_locations', true ); $role->add_cap( 'delete_others_anb_locations', true ); $role->add_cap( 'delete_private_anb_locations', true ); $role->add_cap( 'delete_published_anb_locations', true ); $role->add_cap( 'edit_anb_locations', true ); $role->add_cap( 'edit_others_anb_locations', true ); $role->add_cap( 'edit_private_anb_locations', true ); $role->add_cap( 'edit_published_anb_locations', true ); $role->add_cap( 'publish_anb_locations', true ); $role->add_cap( 'read_private_anb_locations', true ); } function anb_locations_deactivation() { $role = get_role( 'administrator' ); $role->remove_cap( 'delete_anb_locations'); $role->remove_cap( 'delete_others_anb_locations'); $role->remove_cap( 'delete_private_anb_locations'); $role->remove_cap( 'delete_published_anb_locations'); $role->remove_cap( 'edit_anb_locations'); $role->remove_cap( 'edit_others_anb_locations'); $role->remove_cap( 'edit_private_anb_locations'); $role->remove_cap( 'edit_published_anb_locations'); $role->remove_cap( 'publish_anb_locations'); $role->remove_cap( 'read_private_anb_locations'); } function add_menus_to_anb() { add_submenu_page( 'edit.php?post_type=anb', __( 'Locations', 'alert-notice-boxes' ), __( 'Locations', 'alert-notice-boxes' ), 'edit_anb_locations', 'edit.php?post_type=anb_locations' ); } function register_anb_locations() { register_post_type( 'anb_locations', array( 'labels' => array( 'name' => __( 'Alert Notice Locations', 'alert-notice-boxes' ), 'singular_name' => _x( 'Alert Notice Locations', 'post type singular name', 'alert-notice-boxes' ), 'menu_name' => _x( 'Alert Notice Locations', 'admin menu', 'alert-notice-boxes' ), 'name_admin_bar' => _x( 'Alert Notice Locations', 'add new on admin bar', 'alert-notice-boxes' ), 'add_new' => _x( 'Add New', 'Post Type', 'alert-notice-boxes' ), 'add_new_item' => __( 'Add New Location', 'alert-notice-boxes' ), 'new_item' => __( 'New Box Location', 'alert-notice-boxes' ), 'edit_item' => __( 'Edit Box Location', 'alert-notice-boxes' ), 'view_item' => __( 'View Box Location', 'alert-notice-boxes' ), 'all_items' => __( 'Alert Notice Locations', 'alert-notice-boxes' ), 'search_items' => __( 'Search', 'alert-notice-boxes' ), 'parent_item_colon' => __( 'Parent Alert Notice Box:', 'alert-notice-boxes' ), 'not_found' => __( 'No Box Location found.', 'alert-notice-boxes' ), 'not_found_in_trash' => __( 'No Box Location found in Trash.', 'alert-notice-boxes' ), ), // Frontend // Admin 'supports' => array( 'title'), 'hierarchical' => true, 'public' => false, 'show_ui' => true, 'show_in_menu' => false, 'menu_position' => 100, 'menu_icon' => 'dashicons-megaphone', 'show_in_admin_bar' => true, 'show_in_nav_menus' => false, 'can_export' => true, 'has_archive' => false, 'exclude_from_search' => true, 'publicly_queryable' => true, 'capability_type' => 'anb_location', 'map_meta_cap' => true ) ); } function anb_locations_remove_post_meta_boxes( $hidden, $screen, $use_defaults ) { global $wp_meta_boxes; $cpt = 'anb_locations'; // Modify this to your needs! if( $cpt === $screen->id && isset( $wp_meta_boxes[$cpt] ) ) { $tmp = array(); foreach( (array) $wp_meta_boxes[$cpt] as $context_key => $context_item ) { foreach( $context_item as $priority_key => $priority_item ) { foreach( $priority_item as $metabox_key => $metabox_item ) { if ( $metabox_key != 'submitdiv' && $metabox_key != 'locations-boxes-item-meta-box' ) { $tmp[] = $metabox_key; } } } } $hidden = $tmp; // Override the current user option here. } return $hidden; } function anb_locations_create_meta_boxes() { add_meta_box("locations-boxes-item-meta-box", __( 'Alert Notice Box settings', 'alert-notice-boxes' ), array($this, 'anb_locations_item_meta_box'), "anb_locations", "normal", "core", null); } function anb_locations_cpt_parent_file( $parent_file ){ global $current_screen, $self; if ( in_array( $current_screen->base, array( 'post', 'edit' ) ) && 'anb_locations' == $current_screen->post_type ) { $parent_file = 'edit.php?post_type=anb'; } return $parent_file; } function anb_locations_cpt_submenu_file( $submenu_file ){ global $current_screen, $self; if ( in_array( $current_screen->base, array( 'post', 'edit' ) ) && 'anb_locations' == $current_screen->post_type ) { $submenu_file = 'edit.php?post_type=anb_locations'; } return $submenu_file; } function anb_locations_item_meta_box() { wp_nonce_field(basename(__FILE__), "meta-box-nonce"); $post = get_post(); $post->ID ?>

" min="1" >

ID, "anb_location_post_option_side_value", true ) == '' ) { ?> ID, "anb_location_post_option_side", true )== 'center') {echo 'style="display: none;"';} ?>> " ID, "anb_location_post_option_side", true )== 'center') {echo 'style="display: none;"';} ?>>
ID, "anb_location_post_option_height_value", true ) == '' ) { ?> " >

" min="1" >
post_type) return $post_id; update_post_meta($post_id, "anb_location_id", $post_id); $anb_location_post_option_width = $_POST["anb_location_post_option_width"]; update_post_meta($post_id, "anb_location_post_option_width", $anb_location_post_option_width); $anb_location_post_option_width_unit = $_POST["anb_location_post_option_width_unit"]; update_post_meta($post_id, "anb_location_post_option_width_unit", $anb_location_post_option_width_unit); $anb_location_post_option_side = $_POST["anb_location_post_option_side"]; update_post_meta($post_id, "anb_location_post_option_side", $anb_location_post_option_side); $anb_location_post_option_side_value = $_POST["anb_location_post_option_side_value"]; update_post_meta($post_id, "anb_location_post_option_side_value", $anb_location_post_option_side_value); $anb_location_post_option_side_unit = $_POST["anb_location_post_option_side_unit"]; update_post_meta($post_id, "anb_location_post_option_side_unit", $anb_location_post_option_side_unit); $anb_location_post_option_height = $_POST["anb_location_post_option_height"]; update_post_meta($post_id, "anb_location_post_option_height", $anb_location_post_option_height); $anb_location_post_option_height_value = $_POST["anb_location_post_option_height_value"]; update_post_meta($post_id, "anb_location_post_option_height_value", $anb_location_post_option_height_value); $anb_location_post_option_height_unit = $_POST["anb_location_post_option_height_unit"]; update_post_meta($post_id, "anb_location_post_option_height_unit", $anb_location_post_option_height_unit); $anb_location_post_option_z_index = $_POST["anb_location_post_option_z_index"]; update_post_meta($post_id, "anb_location_post_option_z_index", $anb_location_post_option_z_index); $locations_style_css_file = fopen( YCANB_PLUGIN_DIR . "css/parts/locations_style.css", "w") or die("Unable to open file!"); $posts_anb_locations = get_posts(array( 'posts_per_page'=> -1, 'post_type' => 'anb_locations', )); $css_code = "\n"; $css_code .= "\n"; foreach ( $posts_anb_locations as $post_anb_location ) { $css_code .= '#anb-location-id-' . get_post_meta( $post_anb_location->ID, "anb_location_id", true ) . " {\n" ; $css_code .= "\t"; $css_code .= "position: fixed;\n"; $css_code .= "\t"; $css_code .= "width: " . get_post_meta( $post_anb_location->ID, "anb_location_post_option_width", true ) . get_post_meta( $post_anb_location->ID, "anb_location_post_option_width_unit", true ) .";\n" ; if ( get_post_meta( $post_anb_location->ID, "anb_location_post_option_side", true ) == 'center' ) { $css_code .= "\t"; $css_code .= "right: 50%;\n"; $css_code .= "\t"; $css_code .= "margin-right: -" . get_post_meta( $post_anb_location->ID, "anb_location_post_option_width", true ) / 2 . get_post_meta( $post_anb_location->ID, "anb_location_post_option_width_unit", true ) .";\n"; } else { $css_code .= "\t"; $css_code .= get_post_meta( $post_anb_location->ID, "anb_location_post_option_side", true ) . ': ' . get_post_meta( $post_anb_location->ID, "anb_location_post_option_side_value", true ) . get_post_meta( $post_anb_location->ID, "anb_location_post_option_side_unit", true ) .";\n" ; } $css_code .= "\t"; $css_code .= get_post_meta( $post_anb_location->ID, "anb_location_post_option_height", true ) . ': ' . get_post_meta( $post_anb_location->ID, "anb_location_post_option_height_value", true ) . get_post_meta( $post_anb_location->ID, "anb_location_post_option_height_unit", true ) .";\n" ; $css_code .= "\t"; $css_code .= "z-index: 99" . get_post_meta( $post_anb_location->ID, "anb_location_post_option_z_index", true ) .";\n" ; $css_code .= "}\n"; } fwrite($locations_style_css_file, $css_code); fclose($locations_style_css_file); create_anb_css_stylesheet(); } function duplicate_anb_locations_as_draft() { global $wpdb; if (! ( isset( $_GET['post']) || isset( $_POST['post']) || ( isset($_REQUEST['action']) && 'anb_locations_duplicate_post_as_draft' == $_REQUEST['action'] ) ) ) { wp_die('No post to duplicate has been supplied!'); } $post_id = (isset($_GET['post']) ? absint( $_GET['post'] ) : absint( $_POST['post'] ) ); $post = get_post( $post_id ); $current_user = wp_get_current_user(); $new_post_author = $current_user->ID; if (isset( $post ) && $post != null) { $args = array( 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, 'post_author' => $new_post_author, 'post_content' => $post->post_content, 'post_excerpt' => $post->post_excerpt, 'post_name' => $post->post_name . ' - ' . __('copy', 'alert-notice-boxes'), 'post_parent' => $post->post_parent, 'post_password' => $post->post_password, 'post_status' => 'draft', 'post_title' => $post->post_title . ' - ' . __('copy', 'alert-notice-boxes'), 'post_type' => $post->post_type, 'to_ping' => $post->to_ping, 'menu_order' => $post->menu_order ); $new_post_id = wp_insert_post( $args ); $taxonomies = get_object_taxonomies($post->post_type); // returns array of taxonomy names for post type, ex array("category", "post_tag"); foreach ($taxonomies as $taxonomy) { $post_terms = wp_get_object_terms($post_id, $taxonomy, array('fields' => 'slugs')); wp_set_object_terms($new_post_id, $post_terms, $taxonomy, false); } $post_meta_infos = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$post_id"); if (count($post_meta_infos)!=0) { $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) "; foreach ($post_meta_infos as $meta_info) { $meta_key = $meta_info->meta_key; $meta_value = addslashes($meta_info->meta_value); $sql_query_sel[]= "SELECT $new_post_id, '$meta_key', '$meta_value'"; } $sql_query.= implode(" UNION ALL ", $sql_query_sel); $wpdb->query($sql_query); } wp_redirect( admin_url( 'post.php?action=edit&post=' . $new_post_id ) ); exit; } else { wp_die('Post creation failed, could not find original post: ' . $post_id); } } function duplicate_anb_locations_link( $actions, $post ) { if ($post->post_type=='anb_locations' && current_user_can('edit_posts')) { $actions['duplicate'] = '' . __('Duplicate', 'alert-notice-boxes') . ''; unset( $actions['view'] ); } return $actions; } } $YCanb_Locations = new YCanb_Locations;