| 1 |
<?php |
| 2 |
/* |
| 3 |
* @link http://digitalkroy.com/click-to-top/ |
| 4 |
* @since 1.0.0 |
| 5 |
* @package gallery box |
| 6 |
* description gallery box post type |
| 7 |
* |
| 8 |
* @link http://codex.wordpress.org/Function_Reference/register_post_type |
| 9 |
* @wordpress-plugin |
| 10 |
*/ |
| 11 |
|
| 12 |
if (!function_exists('gallerybox_post_type')) : |
| 13 |
function gallerybox_post_type() |
| 14 |
{ |
| 15 |
$labels = array( |
| 16 |
'name' => __('galleries', 'gallery-box'), |
| 17 |
'singular_name' => __('gallery', 'gallery-box'), |
| 18 |
'menu_name' => __('Gallery Box', 'gallery-box'), |
| 19 |
'name_admin_bar' => __('Gallery Box', 'gallery-box'), |
| 20 |
'add_new' => __('Add New gallery', 'gallery-box'), |
| 21 |
'add_new_item' => __('Add New gallery', 'gallery-box'), |
| 22 |
'new_item' => __('New gallery', 'gallery-box'), |
| 23 |
'edit_item' => __('Edit gallery', 'gallery-box'), |
| 24 |
'view_item' => __('View gallery', 'gallery-box'), |
| 25 |
'all_items' => __('All gallery', 'gallery-box'), |
| 26 |
'parent_item_colon' => __('Parent gallery:', 'gallery-box'), |
| 27 |
'not_found' => __('No gallery found.', 'gallery-box'), |
| 28 |
'not_found_in_trash' => __('No gallery found in Trash.', 'gallery-box'), |
| 29 |
); |
| 30 |
|
| 31 |
$args = array( |
| 32 |
'labels' => $labels, |
| 33 |
'description' => __('You can create gallery with image, Youtube and Vimeo video, Soundcloud audio and i-frame content by gallery box.', 'gallery-box'), |
| 34 |
'public' => false, |
| 35 |
'show_ui' => true, |
| 36 |
'show_in_menu' => true, |
| 37 |
'query_var' => false, |
| 38 |
'rewrite' => array('slug' => 'gallery-box'), |
| 39 |
'capabilities' => array( |
| 40 |
'edit_post' => 'edit_gallery', |
| 41 |
'read_post' => 'read_galleries', |
| 42 |
'delete_post' => 'delete_gallery', |
| 43 |
'delete_posts' => 'delete_galleries', |
| 44 |
'edit_posts' => 'edit_galleries', |
| 45 |
'edit_others_posts' => 'edit_others_galleries', |
| 46 |
'publish_posts' => 'publish_galleries', |
| 47 |
'read_private_posts' => 'read_private_galleries', |
| 48 |
'create_posts' => 'create_galleries', |
| 49 |
), |
| 50 |
'has_archive' => false, |
| 51 |
'hierarchical' => false, |
| 52 |
'menu_position' => 25, |
| 53 |
'menu_icon' => 'dashicons-images-alt2', |
| 54 |
'supports' => array('title') |
| 55 |
); |
| 56 |
|
| 57 |
register_post_type('gallery_box', $args); |
| 58 |
} |
| 59 |
add_action('init', 'gallerybox_post_type'); |
| 60 |
endif; |
| 61 |
|
| 62 |
|
| 63 |
/** |
| 64 |
* Gallery item update messages. |
| 65 |
* |
| 66 |
* |
| 67 |
*/ |
| 68 |
if (!function_exists('gbox_updated_messages')) : |
| 69 |
function gbox_updated_messages($messages) |
| 70 |
{ |
| 71 |
global $post; |
| 72 |
$post_ID = $post->ID; |
| 73 |
$post = get_post(); |
| 74 |
$post_type = get_post_type($post); |
| 75 |
$post_type_object = get_post_type_object($post_type); |
| 76 |
$gallery_shortcode = '[gallerybox id="' . $post_ID . '"]'; |
| 77 |
$messages['gallery_box'] = array( |
| 78 |
0 => '', // Unused. Messages start at index 1. |
| 79 |
1 => sprintf(__('Gallery updated. Shortcode is : <strong>%s</strong>', 'gallery-box'), $gallery_shortcode), |
| 80 |
2 => sprintf(__('Gallery updated. Shortcode is : <strong>%s</strong>', 'gallery-box'), $gallery_shortcode), |
| 81 |
3 => __('Gallery field deleted.', 'gallery-box'), |
| 82 |
4 => __('Gallery item updated.', 'gallery-box'), |
| 83 |
/* translators: %s: date and time of the revision */ |
| 84 |
5 => isset($_GET['revision']) ? sprintf(__('Gallery restored to revision from %s', 'gallery-box'), wp_post_revision_title((int) sanitize_text_field(wp_unslash($_GET['revision'])), false)) : false, |
| 85 |
6 => sprintf(__('Gallery published. Shortcode is : <strong>%s</strong>', 'gallery-box'), $gallery_shortcode), |
| 86 |
7 => sprintf(__('Gallery saved. Shortcode is : <strong>%s</strong>', 'gallery-box'), $gallery_shortcode), |
| 87 |
8 => sprintf(__('Gallery submitted. Shortcode is : <strong>%s</strong>', 'gallery-box'), $gallery_shortcode), |
| 88 |
9 => sprintf( |
| 89 |
__('Gallery item scheduled for: <strong>%1$s</strong>.', 'gallery-box'), |
| 90 |
// translators: Publish box date format, see http://php.net/date |
| 91 |
date_i18n(__('M j, Y @ G:i', 'gallery-box'), strtotime($post->post_date)) |
| 92 |
), |
| 93 |
10 => __('Gallery draft updated.', 'gallery-box') |
| 94 |
); |
| 95 |
|
| 96 |
|
| 97 |
return $messages; |
| 98 |
} |
| 99 |
add_filter('post_updated_messages', 'gbox_updated_messages'); |
| 100 |
endif; |
| 101 |
|
| 102 |
// Shortcode Generator |
| 103 |
if (!function_exists('gbox_column_add_gallery_type')) : |
| 104 |
function gbox_column_add_gallery_type($post_ID) |
| 105 |
{ |
| 106 |
|
| 107 |
//simple image gallery meta |
| 108 |
$gbox_simple_imgs = get_post_meta(get_the_ID(), 'simple_imgs', true); |
| 109 |
//advance image gallery meta |
| 110 |
$gbox_img_main = get_post_meta(get_the_ID(), 'img_main', true); |
| 111 |
$image_title = !empty($gbox_img_main[0]['image_title']) ? $gbox_img_main[0]['image_title'] : ''; |
| 112 |
$image_small = !empty($gbox_img_main[0]['image_small']) ? $gbox_img_main[0]['image_small'] : ''; |
| 113 |
|
| 114 |
|
| 115 |
//Youtube gallery meta |
| 116 |
$gbox_youtube_main = get_post_meta(get_the_ID(), 'youtube_main', true); |
| 117 |
$you_url = !empty($gbox_youtube_main[0]['you_url']) ? $gbox_youtube_main[0]['you_url'] : ''; |
| 118 |
|
| 119 |
|
| 120 |
//Vimeo gallery meta |
| 121 |
$gbox_vimeo_main = get_post_meta(get_the_ID(), 'vimeo_main', true); |
| 122 |
$vimeo_url = !empty($gbox_vimeo_main[0]['vimeo_url']) ? $gbox_vimeo_main[0]['vimeo_url'] : ''; |
| 123 |
|
| 124 |
//Portfolio gallery meta |
| 125 |
$gbox_portfo_main = get_post_meta(get_the_ID(), 'portfo_main', true); |
| 126 |
$portfolio_title = !empty($gbox_portfo_main[0]['portfolio_title']) ? $gbox_portfo_main[0]['portfolio_title'] : ''; |
| 127 |
$port_img = !empty($gbox_portfo_main[0]['port_img']) ? $gbox_portfo_main[0]['port_img'] : ''; |
| 128 |
|
| 129 |
//Iframe gallery meta |
| 130 |
$gbox_iframe_main = get_post_meta(get_the_ID(), 'iframe_main', true); |
| 131 |
$iframe_url = !empty($gbox_iframe_main[0]['iframe_url']) ? $gbox_iframe_main[0]['iframe_url'] : ''; |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
if (!empty($image_title) || !empty($image_small) || !empty($gbox_simple_imgs)) { |
| 136 |
$img_main = __('Image gallery', 'gallery-box'); |
| 137 |
} else { |
| 138 |
$img_main = ''; |
| 139 |
} |
| 140 |
if (!empty($you_url)) { |
| 141 |
$youtube_main = __('Youtube gallery', 'gallery-box'); |
| 142 |
} else { |
| 143 |
$youtube_main = ''; |
| 144 |
} |
| 145 |
if (!empty($vimeo_url)) { |
| 146 |
$vimeo_main = __('Vimeo gallery', 'gallery-box'); |
| 147 |
} else { |
| 148 |
$vimeo_main = ''; |
| 149 |
} |
| 150 |
if (!empty($portfolio_title) || !empty($port_img)) { |
| 151 |
$portfolio_main = __('Portfolio gallery', 'gallery-box'); |
| 152 |
} else { |
| 153 |
$portfolio_main = ''; |
| 154 |
} |
| 155 |
if (!empty($iframe_url)) { |
| 156 |
$iframe_main = __('iframe gallery', 'gallery-box'); |
| 157 |
} else { |
| 158 |
$iframe_main = ''; |
| 159 |
} |
| 160 |
$gallery_type = array($img_main, $youtube_main, $vimeo_main, $portfolio_main, $iframe_main); |
| 161 |
|
| 162 |
return $gallery_type; |
| 163 |
} |
| 164 |
|
| 165 |
add_filter('manage_gallery_box_posts_columns', 'gbox_wp_shortcode_column_head', 10); |
| 166 |
function gbox_wp_shortcode_column_head($defaults) |
| 167 |
{ |
| 168 |
$defaults['shortcode_generate'] = __('Gallery Shortcode', 'gallery-box'); |
| 169 |
$defaults['gallery_images_count'] = __('Gallery type', 'gallery-box'); |
| 170 |
return $defaults; |
| 171 |
} |
| 172 |
add_action('manage_gallery_box_posts_custom_column', 'gbox_wp_shortcode_column_content', 10, 2); |
| 173 |
|
| 174 |
function gbox_wp_shortcode_column_content($column_name, $post_ID) |
| 175 |
{ |
| 176 |
|
| 177 |
if ($column_name == 'shortcode_generate') { |
| 178 |
$shortcode_render = '[gallerybox id="' . $post_ID . '"]'; |
| 179 |
|
| 180 |
echo '<input style="min-width:165px" type=\'text\' onClick=\'this.setSelectionRange(0, this.value.length)\' value=\'' . $shortcode_render . '\' />'; |
| 181 |
} |
| 182 |
if ($column_name == 'gallery_images_count') { |
| 183 |
$gbox_type = gbox_column_add_gallery_type($post_ID); |
| 184 |
$type_name = array_filter($gbox_type); |
| 185 |
$gbox_tottal_type = implode(", ", $type_name); |
| 186 |
echo $gbox_tottal_type; |
| 187 |
} |
| 188 |
} |
| 189 |
endif; |
| 190 |
/** |
| 191 |
*add gallery box administrator role |
| 192 |
* |
| 193 |
* |
| 194 |
*/ |
| 195 |
if (!function_exists('gallerybox_admin_role')) : |
| 196 |
function gallerybox_admin_role() |
| 197 |
{ |
| 198 |
// gets the administrator role |
| 199 |
$admins = get_role('administrator'); |
| 200 |
|
| 201 |
$admins->add_cap('edit_gallery'); |
| 202 |
$admins->add_cap('read_galleries'); |
| 203 |
$admins->add_cap('delete_gallery'); |
| 204 |
$admins->add_cap('delete_galleries'); |
| 205 |
$admins->add_cap('edit_galleries'); |
| 206 |
$admins->add_cap('edit_others_galleries'); |
| 207 |
$admins->add_cap('publish_galleries'); |
| 208 |
$admins->add_cap('read_private_galleries'); |
| 209 |
$admins->add_cap('create_galleries'); |
| 210 |
} |
| 211 |
add_action('admin_init', 'gallerybox_admin_role'); |
| 212 |
endif; |
| 213 |
/** |
| 214 |
*Remove gallery box administrator role |
| 215 |
* |
| 216 |
* |
| 217 |
*/ |
| 218 |
if (!function_exists('gallerybox_admin_role_remove')) : |
| 219 |
function gallerybox_admin_role_remove() |
| 220 |
{ |
| 221 |
// gets the administrator role |
| 222 |
$admins = get_role('administrator'); |
| 223 |
|
| 224 |
$admins->remove_cap('edit_gallery'); |
| 225 |
$admins->remove_cap('read_galleries'); |
| 226 |
$admins->remove_cap('delete_gallery'); |
| 227 |
$admins->remove_cap('delete_galleries'); |
| 228 |
$admins->remove_cap('edit_galleries'); |
| 229 |
$admins->remove_cap('edit_others_galleries'); |
| 230 |
$admins->remove_cap('publish_galleries'); |
| 231 |
$admins->remove_cap('read_private_galleries'); |
| 232 |
$admins->remove_cap('create_galleries'); |
| 233 |
} |
| 234 |
endif; |
| 235 |
/** |
| 236 |
* Change Gallery Box title placeholder |
| 237 |
* |
| 238 |
* |
| 239 |
*/ |
| 240 |
if (!function_exists('gbox_change_title_text')) : |
| 241 |
function gbox_change_title_text($title) |
| 242 |
{ |
| 243 |
$screen = get_current_screen(); |
| 244 |
|
| 245 |
if ('gallery_box' == $screen->post_type) { |
| 246 |
$title = __('Enter gallery name', 'gallery-box'); |
| 247 |
} |
| 248 |
|
| 249 |
return $title; |
| 250 |
} |
| 251 |
|
| 252 |
add_filter('enter_title_here', 'gbox_change_title_text'); |
| 253 |
endif; |
| 254 |
|