@@ -10,409 +10,409 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class LSX_Projects_Admin { |
| 12 | 12 | |
| 13 | - public function __construct() { |
|
| 14 | - $this->load_classes(); |
|
| 15 | - |
|
| 16 | - add_action( 'init', array( $this, 'post_type_setup' ) ); |
|
| 17 | - add_action( 'init', array( $this, 'taxonomy_setup' ) ); |
|
| 18 | - add_filter( 'cmb2_admin_init', array( $this, 'field_setup' ) ); |
|
| 19 | - add_filter( 'cmb2_admin_init', array( $this, 'projects_services_metaboxes' ) ); |
|
| 20 | - add_filter( 'cmb2_admin_init', array( $this, 'projects_testimonials_metaboxes' ) ); |
|
| 21 | - add_filter( 'cmb2_admin_init', array( $this, 'projects_team_metaboxes' ) ); |
|
| 22 | - add_filter( 'cmb2_admin_init', array( $this, 'projects_woocommerce_metaboxes' ) ); |
|
| 23 | - add_action( 'cmb_save_custom', array( $this, 'post_relations' ), 3, 20 ); |
|
| 24 | - add_action( 'admin_enqueue_scripts', array( $this, 'assets' ) ); |
|
| 25 | - |
|
| 26 | - add_filter( 'type_url_form_media', array( $this, 'change_attachment_field_button' ), 20, 1 ); |
|
| 27 | - add_filter( 'enter_title_here', array( $this, 'change_title_text' ) ); |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Loads the admin subclasses |
|
| 32 | - */ |
|
| 33 | - private function load_classes() { |
|
| 34 | - require_once LSX_PROJECTS_PATH . 'classes/admin/class-settings.php'; |
|
| 35 | - $this->settings = \lsx\projects\classes\admin\Settings::get_instance(); |
|
| 36 | - |
|
| 37 | - require_once LSX_PROJECTS_PATH . 'classes/admin/class-settings-theme.php'; |
|
| 38 | - $this->settings_theme = \lsx\projects\classes\admin\Settings_Theme::get_instance(); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Register the Project and Product Tag post type |
|
| 43 | - */ |
|
| 44 | - public function post_type_setup() { |
|
| 45 | - $labels = array( |
|
| 46 | - 'name' => esc_html_x( 'Projects', 'post type general name', 'lsx-projects' ), |
|
| 47 | - 'singular_name' => esc_html_x( 'Project', 'post type singular name', 'lsx-projects' ), |
|
| 48 | - 'add_new' => esc_html_x( 'Add New', 'post type general name', 'lsx-projects' ), |
|
| 49 | - 'add_new_item' => esc_html__( 'Add New Project', 'lsx-projects' ), |
|
| 50 | - 'edit_item' => esc_html__( 'Edit Project', 'lsx-projects' ), |
|
| 51 | - 'new_item' => esc_html__( 'New Project', 'lsx-projects' ), |
|
| 52 | - 'all_items' => esc_html__( 'All Projects', 'lsx-projects' ), |
|
| 53 | - 'view_item' => esc_html__( 'View Project', 'lsx-projects' ), |
|
| 54 | - 'search_items' => esc_html__( 'Search Projects', 'lsx-projects' ), |
|
| 55 | - 'not_found' => esc_html__( 'No projects found', 'lsx-projects' ), |
|
| 56 | - 'not_found_in_trash' => esc_html__( 'No projects found in Trash', 'lsx-projects' ), |
|
| 57 | - 'parent_item_colon' => '', |
|
| 58 | - 'menu_name' => esc_html_x( 'Projects', 'admin menu', 'lsx-projects' ), |
|
| 59 | - ); |
|
| 60 | - |
|
| 61 | - $args = array( |
|
| 62 | - 'labels' => $labels, |
|
| 63 | - 'public' => true, |
|
| 64 | - 'publicly_queryable' => true, |
|
| 65 | - 'show_ui' => true, |
|
| 66 | - 'show_in_menu' => true, |
|
| 67 | - 'menu_icon' => 'dashicons-portfolio', |
|
| 68 | - 'query_var' => true, |
|
| 69 | - 'rewrite' => array( |
|
| 70 | - 'slug' => 'portfolio', |
|
| 71 | - ), |
|
| 72 | - 'capability_type' => 'post', |
|
| 73 | - 'has_archive' => 'portfolio', |
|
| 74 | - 'hierarchical' => false, |
|
| 75 | - 'menu_position' => null, |
|
| 76 | - 'supports' => array( |
|
| 77 | - 'title', |
|
| 78 | - 'editor', |
|
| 79 | - 'thumbnail', |
|
| 80 | - 'excerpt', |
|
| 81 | - ), |
|
| 82 | - 'show_in_rest' => true, |
|
| 83 | - 'supports' => array( 'editor', 'title', 'excerpt', 'thumbnail' ), |
|
| 84 | - ); |
|
| 85 | - |
|
| 86 | - register_post_type( 'project', $args ); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Register the Group taxonomy |
|
| 91 | - */ |
|
| 92 | - public function taxonomy_setup() { |
|
| 93 | - $labels = array( |
|
| 94 | - 'name' => esc_html_x( 'Project Groups', 'taxonomy general name', 'lsx-projects' ), |
|
| 95 | - 'singular_name' => esc_html_x( 'Group', 'taxonomy singular name', 'lsx-projects' ), |
|
| 96 | - 'search_items' => esc_html__( 'Search Groups', 'lsx-projects' ), |
|
| 97 | - 'all_items' => esc_html__( 'All Groups', 'lsx-projects' ), |
|
| 98 | - 'parent_item' => esc_html__( 'Parent Group', 'lsx-projects' ), |
|
| 99 | - 'parent_item_colon' => esc_html__( 'Parent Group:', 'lsx-projects' ), |
|
| 100 | - 'edit_item' => esc_html__( 'Edit Group', 'lsx-projects' ), |
|
| 101 | - 'update_item' => esc_html__( 'Update Group', 'lsx-projects' ), |
|
| 102 | - 'add_new_item' => esc_html__( 'Add New Group', 'lsx-projects' ), |
|
| 103 | - 'new_item_name' => esc_html__( 'New Group Name', 'lsx-projects' ), |
|
| 104 | - 'menu_name' => esc_html__( 'Groups', 'lsx-projects' ), |
|
| 105 | - ); |
|
| 106 | - |
|
| 107 | - $args = array( |
|
| 108 | - 'hierarchical' => true, |
|
| 109 | - 'labels' => $labels, |
|
| 110 | - 'show_ui' => true, |
|
| 111 | - 'show_admin_column' => true, |
|
| 112 | - 'query_var' => true, |
|
| 113 | - 'rewrite' => array( |
|
| 114 | - 'slug' => 'portfolio-group', |
|
| 115 | - ), |
|
| 116 | - ); |
|
| 117 | - |
|
| 118 | - register_taxonomy( 'project-group', array( 'project' ), $args ); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Add metabox with custom fields to the Project post type |
|
| 123 | - */ |
|
| 124 | - public function field_setup() { |
|
| 125 | - $prefix = 'lsx_project_'; |
|
| 126 | - |
|
| 127 | - $cmb = new_cmb2_box( |
|
| 128 | - array( |
|
| 129 | - 'id' => $prefix . '_project', |
|
| 130 | - 'title' => __( 'General', 'lsx-projects' ), |
|
| 131 | - 'object_types' => 'project', |
|
| 132 | - 'context' => 'normal', |
|
| 133 | - 'priority' => 'low', |
|
| 134 | - 'show_names' => true, |
|
| 135 | - ) |
|
| 136 | - ); |
|
| 137 | - |
|
| 138 | - $cmb->add_field( |
|
| 139 | - array( |
|
| 140 | - 'name' => esc_html__( 'Featured:', 'lsx-projects' ), |
|
| 141 | - 'id' => $prefix . 'featured', |
|
| 142 | - 'type' => 'checkbox', |
|
| 143 | - 'value' => 1, |
|
| 144 | - 'default' => 0, |
|
| 145 | - 'show_in_rest' => true, |
|
| 146 | - ) |
|
| 147 | - ); |
|
| 148 | - |
|
| 149 | - $cmb->add_field( |
|
| 150 | - array( |
|
| 151 | - 'name' => esc_html__( 'Client:', 'lsx-projects' ), |
|
| 152 | - 'id' => $prefix . 'client', |
|
| 153 | - 'type' => 'text', |
|
| 154 | - 'show_in_rest' => true, |
|
| 155 | - ) |
|
| 156 | - ); |
|
| 157 | - |
|
| 158 | - $cmb->add_field( |
|
| 159 | - array( |
|
| 160 | - 'name' => esc_html__( 'Client logo:', 'lsx-projects' ), |
|
| 161 | - 'id' => $prefix . 'client_logo', |
|
| 162 | - 'type' => 'image', |
|
| 163 | - 'desc' => esc_html__( 'Recommended image size: 320 x 50~60', 'lsx-projects' ), |
|
| 164 | - 'options' => array( |
|
| 165 | - 'url' => false, // Hide the text input for the url. |
|
| 166 | - ), |
|
| 167 | - 'text' => array( |
|
| 168 | - 'add_upload_file_text' => 'Choose Image', |
|
| 169 | - ), |
|
| 170 | - 'show_in_rest' => true, |
|
| 171 | - ) |
|
| 172 | - ); |
|
| 173 | - |
|
| 174 | - $cmb->add_field( |
|
| 175 | - array( |
|
| 176 | - 'name' => esc_html__( 'URL for the finished project:', 'lsx-projects' ), |
|
| 177 | - 'id' => $prefix . 'url', |
|
| 178 | - 'type' => 'text', |
|
| 179 | - 'show_in_rest' => true, |
|
| 180 | - ) |
|
| 181 | - ); |
|
| 182 | - |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * Project Services Metaboxes. |
|
| 187 | - */ |
|
| 188 | - public function projects_services_metaboxes() { |
|
| 189 | - $prefix = 'lsx_project_'; |
|
| 190 | - |
|
| 191 | - $cmb = new_cmb2_box( |
|
| 192 | - array( |
|
| 193 | - 'id' => $prefix . '_project', |
|
| 194 | - 'object_types' => 'projects', |
|
| 195 | - 'context' => 'normal', |
|
| 196 | - 'priority' => 'low', |
|
| 197 | - 'show_names' => true, |
|
| 198 | - ) |
|
| 199 | - ); |
|
| 200 | - |
|
| 201 | - $cmb->add_field( |
|
| 202 | - array( |
|
| 203 | - 'name' => esc_html__( 'Services related to this project:', 'lsx-projects' ), |
|
| 204 | - 'id' => 'page_to_project', |
|
| 205 | - 'type' => 'post_search_ajax', |
|
| 206 | - 'show_in_rest' => true, |
|
| 207 | - 'limit' => 15, |
|
| 208 | - 'sortable' => true, |
|
| 209 | - 'query_args' => array( |
|
| 210 | - 'post_type' => array( 'page' ), |
|
| 211 | - 'post_status' => array( 'publish' ), |
|
| 212 | - 'nopagin' => true, |
|
| 213 | - 'posts_per_page' => '50', |
|
| 214 | - 'orderby' => 'title', |
|
| 215 | - 'order' => 'ASC', |
|
| 216 | - ), |
|
| 217 | - ) |
|
| 218 | - ); |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * Project Testimonials Metaboxes. |
|
| 223 | - */ |
|
| 224 | - public function projects_testimonials_metaboxes() { |
|
| 225 | - $prefix = 'lsx_project_'; |
|
| 226 | - |
|
| 227 | - $cmb = new_cmb2_box( |
|
| 228 | - array( |
|
| 229 | - 'id' => $prefix . '_project', |
|
| 230 | - 'object_types' => 'projects', |
|
| 231 | - 'context' => 'normal', |
|
| 232 | - 'priority' => 'low', |
|
| 233 | - 'show_names' => true, |
|
| 234 | - ) |
|
| 235 | - ); |
|
| 236 | - |
|
| 237 | - if ( class_exists( 'LSX_Testimonials' ) ) { |
|
| 238 | - $cmb->add_field( |
|
| 239 | - array( |
|
| 240 | - 'name' => esc_html__( 'Testimonials related to this project:', 'lsx-projects' ), |
|
| 241 | - 'id' => 'testimonial_to_project', |
|
| 242 | - 'type' => 'post_search_ajax', |
|
| 243 | - 'show_in_rest' => true, |
|
| 244 | - 'limit' => 15, |
|
| 245 | - 'sortable' => true, |
|
| 246 | - 'query_args' => array( |
|
| 247 | - 'post_type' => array( 'testimonials' ), |
|
| 248 | - 'post_status' => array( 'publish' ), |
|
| 249 | - 'nopagin' => true, |
|
| 250 | - 'posts_per_page' => '50', |
|
| 251 | - 'orderby' => 'title', |
|
| 252 | - 'order' => 'ASC', |
|
| 253 | - ), |
|
| 254 | - ) |
|
| 255 | - ); |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * Project Team Metaboxes. |
|
| 261 | - */ |
|
| 262 | - public function projects_team_metaboxes() { |
|
| 263 | - $prefix = 'lsx_project_'; |
|
| 264 | - |
|
| 265 | - $cmb = new_cmb2_box( |
|
| 266 | - array( |
|
| 267 | - 'id' => $prefix . '_project', |
|
| 268 | - 'object_types' => 'project', |
|
| 269 | - 'context' => 'normal', |
|
| 270 | - 'priority' => 'low', |
|
| 271 | - 'show_names' => true, |
|
| 272 | - ) |
|
| 273 | - ); |
|
| 274 | - |
|
| 275 | - if ( class_exists( 'LSX_Team' ) ) { |
|
| 276 | - $cmb->add_field( |
|
| 277 | - array( |
|
| 278 | - 'name' => esc_html__( 'Team members involved with this project:', 'lsx-projects' ), |
|
| 279 | - 'id' => 'team_to_project', |
|
| 280 | - 'type' => 'post_search_ajax', |
|
| 281 | - 'show_in_rest' => true, |
|
| 282 | - 'limit' => 15, |
|
| 283 | - 'sortable' => true, |
|
| 284 | - 'query_args' => array( |
|
| 285 | - 'post_type' => array( 'team' ), |
|
| 286 | - 'post_status' => array( 'publish' ), |
|
| 287 | - 'nopagin' => true, |
|
| 288 | - 'posts_per_page' => '50', |
|
| 289 | - 'orderby' => 'title', |
|
| 290 | - 'order' => 'ASC', |
|
| 291 | - ), |
|
| 292 | - ) |
|
| 293 | - ); |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * Project Woocommerce Metaboxes. |
|
| 299 | - */ |
|
| 300 | - public function projects_woocommerce_metaboxes() { |
|
| 301 | - $prefix = 'lsx_project_'; |
|
| 302 | - |
|
| 303 | - $cmb = new_cmb2_box( |
|
| 304 | - array( |
|
| 305 | - 'id' => $prefix . '_project', |
|
| 306 | - 'object_types' => 'projects', |
|
| 307 | - 'context' => 'normal', |
|
| 308 | - 'priority' => 'low', |
|
| 309 | - 'show_names' => true, |
|
| 310 | - ) |
|
| 311 | - ); |
|
| 312 | - |
|
| 313 | - if ( class_exists( 'woocommerce' ) ) { |
|
| 314 | - $cmb->add_field( |
|
| 315 | - array( |
|
| 316 | - 'name' => esc_html__( 'Products used for this project:', 'lsx-projects' ), |
|
| 317 | - 'id' => 'product_to_project', |
|
| 318 | - 'type' => 'post_search_ajax', |
|
| 319 | - 'show_in_rest' => true, |
|
| 320 | - 'limit' => 15, |
|
| 321 | - 'sortable' => true, |
|
| 322 | - 'query_args' => array( |
|
| 323 | - 'post_type' => array( 'product' ), |
|
| 324 | - 'post_status' => array( 'publish' ), |
|
| 325 | - 'nopagin' => true, |
|
| 326 | - 'posts_per_page' => '50', |
|
| 327 | - 'orderby' => 'title', |
|
| 328 | - 'order' => 'ASC', |
|
| 329 | - ), |
|
| 330 | - ) |
|
| 331 | - ); |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * Sets up the "post relations". |
|
| 337 | - */ |
|
| 338 | - public function post_relations( $post_id, $field, $value ) { |
|
| 339 | - $connections = array( |
|
| 340 | - // 'project_to_project', |
|
| 341 | - |
|
| 342 | - 'page_to_project', |
|
| 343 | - 'project_to_page', |
|
| 344 | - |
|
| 345 | - 'project_to_service', |
|
| 346 | - 'service_to_project', |
|
| 347 | - |
|
| 348 | - 'project_to_testimonial', |
|
| 349 | - 'testimonial_to_project', |
|
| 350 | - |
|
| 351 | - 'project_to_team', |
|
| 352 | - 'team_to_project', |
|
| 353 | - ); |
|
| 354 | - |
|
| 355 | - if ( in_array( $field['id'], $connections ) ) { |
|
| 356 | - $this->save_related_post( $connections, $post_id, $field, $value ); |
|
| 357 | - } |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * Save the reverse post relation. |
|
| 362 | - */ |
|
| 363 | - public function save_related_post( $connections, $post_id, $field, $value ) { |
|
| 364 | - $ids = explode( '_to_', $field['id'] ); |
|
| 365 | - $relation = $ids[1] . '_to_' . $ids[0]; |
|
| 366 | - |
|
| 367 | - if ( in_array( $relation, $connections ) ) { |
|
| 368 | - $previous_values = get_post_meta( $post_id, $field['id'], false ); |
|
| 369 | - |
|
| 370 | - if ( ! empty( $previous_values ) ) { |
|
| 371 | - foreach ( $previous_values as $v ) { |
|
| 372 | - delete_post_meta( $v, $relation, $post_id ); |
|
| 373 | - } |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - if ( is_array( $value ) ) { |
|
| 377 | - foreach ( $value as $v ) { |
|
| 378 | - if ( ! empty( $v ) ) { |
|
| 379 | - add_post_meta( $v, $relation, $post_id ); |
|
| 380 | - } |
|
| 381 | - } |
|
| 382 | - } |
|
| 383 | - } |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - public function assets() { |
|
| 387 | - //wp_enqueue_media(); |
|
| 388 | - wp_enqueue_script( 'media-upload' ); |
|
| 389 | - wp_enqueue_script( 'thickbox' ); |
|
| 390 | - wp_enqueue_style( 'thickbox' ); |
|
| 391 | - |
|
| 392 | - wp_enqueue_script( 'lsx-projects-admin', LSX_PROJECTS_URL . 'assets/js/lsx-projects-admin.min.js', array( 'jquery' ), LSX_PROJECTS_VER, true ); |
|
| 393 | - wp_enqueue_style( 'lsx-projects-admin', LSX_PROJECTS_URL . 'assets/css/lsx-projects-admin.css', array(), LSX_PROJECTS_VER ); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * Change the "Insert into Post" button text when media modal is used for feature images |
|
| 398 | - */ |
|
| 399 | - public function change_attachment_field_button( $html ) { |
|
| 400 | - if ( isset( $_GET['feature_image_text_button'] ) ) { |
|
| 401 | - $html = str_replace( 'value="Insert into Post"', sprintf( 'value="%s"', esc_html__( 'Select featured image', 'lsx-projects' ) ), $html ); |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - return $html; |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - public function change_title_text( $title ) { |
|
| 408 | - $screen = get_current_screen(); |
|
| 409 | - |
|
| 410 | - if ( 'project' === $screen->post_type ) { |
|
| 411 | - $title = esc_attr__( 'Enter project title', 'lsx-projects' ); |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - return $title; |
|
| 415 | - } |
|
| 13 | + public function __construct() { |
|
| 14 | + $this->load_classes(); |
|
| 15 | + |
|
| 16 | + add_action( 'init', array( $this, 'post_type_setup' ) ); |
|
| 17 | + add_action( 'init', array( $this, 'taxonomy_setup' ) ); |
|
| 18 | + add_filter( 'cmb2_admin_init', array( $this, 'field_setup' ) ); |
|
| 19 | + add_filter( 'cmb2_admin_init', array( $this, 'projects_services_metaboxes' ) ); |
|
| 20 | + add_filter( 'cmb2_admin_init', array( $this, 'projects_testimonials_metaboxes' ) ); |
|
| 21 | + add_filter( 'cmb2_admin_init', array( $this, 'projects_team_metaboxes' ) ); |
|
| 22 | + add_filter( 'cmb2_admin_init', array( $this, 'projects_woocommerce_metaboxes' ) ); |
|
| 23 | + add_action( 'cmb_save_custom', array( $this, 'post_relations' ), 3, 20 ); |
|
| 24 | + add_action( 'admin_enqueue_scripts', array( $this, 'assets' ) ); |
|
| 25 | + |
|
| 26 | + add_filter( 'type_url_form_media', array( $this, 'change_attachment_field_button' ), 20, 1 ); |
|
| 27 | + add_filter( 'enter_title_here', array( $this, 'change_title_text' ) ); |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Loads the admin subclasses |
|
| 32 | + */ |
|
| 33 | + private function load_classes() { |
|
| 34 | + require_once LSX_PROJECTS_PATH . 'classes/admin/class-settings.php'; |
|
| 35 | + $this->settings = \lsx\projects\classes\admin\Settings::get_instance(); |
|
| 36 | + |
|
| 37 | + require_once LSX_PROJECTS_PATH . 'classes/admin/class-settings-theme.php'; |
|
| 38 | + $this->settings_theme = \lsx\projects\classes\admin\Settings_Theme::get_instance(); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Register the Project and Product Tag post type |
|
| 43 | + */ |
|
| 44 | + public function post_type_setup() { |
|
| 45 | + $labels = array( |
|
| 46 | + 'name' => esc_html_x( 'Projects', 'post type general name', 'lsx-projects' ), |
|
| 47 | + 'singular_name' => esc_html_x( 'Project', 'post type singular name', 'lsx-projects' ), |
|
| 48 | + 'add_new' => esc_html_x( 'Add New', 'post type general name', 'lsx-projects' ), |
|
| 49 | + 'add_new_item' => esc_html__( 'Add New Project', 'lsx-projects' ), |
|
| 50 | + 'edit_item' => esc_html__( 'Edit Project', 'lsx-projects' ), |
|
| 51 | + 'new_item' => esc_html__( 'New Project', 'lsx-projects' ), |
|
| 52 | + 'all_items' => esc_html__( 'All Projects', 'lsx-projects' ), |
|
| 53 | + 'view_item' => esc_html__( 'View Project', 'lsx-projects' ), |
|
| 54 | + 'search_items' => esc_html__( 'Search Projects', 'lsx-projects' ), |
|
| 55 | + 'not_found' => esc_html__( 'No projects found', 'lsx-projects' ), |
|
| 56 | + 'not_found_in_trash' => esc_html__( 'No projects found in Trash', 'lsx-projects' ), |
|
| 57 | + 'parent_item_colon' => '', |
|
| 58 | + 'menu_name' => esc_html_x( 'Projects', 'admin menu', 'lsx-projects' ), |
|
| 59 | + ); |
|
| 60 | + |
|
| 61 | + $args = array( |
|
| 62 | + 'labels' => $labels, |
|
| 63 | + 'public' => true, |
|
| 64 | + 'publicly_queryable' => true, |
|
| 65 | + 'show_ui' => true, |
|
| 66 | + 'show_in_menu' => true, |
|
| 67 | + 'menu_icon' => 'dashicons-portfolio', |
|
| 68 | + 'query_var' => true, |
|
| 69 | + 'rewrite' => array( |
|
| 70 | + 'slug' => 'portfolio', |
|
| 71 | + ), |
|
| 72 | + 'capability_type' => 'post', |
|
| 73 | + 'has_archive' => 'portfolio', |
|
| 74 | + 'hierarchical' => false, |
|
| 75 | + 'menu_position' => null, |
|
| 76 | + 'supports' => array( |
|
| 77 | + 'title', |
|
| 78 | + 'editor', |
|
| 79 | + 'thumbnail', |
|
| 80 | + 'excerpt', |
|
| 81 | + ), |
|
| 82 | + 'show_in_rest' => true, |
|
| 83 | + 'supports' => array( 'editor', 'title', 'excerpt', 'thumbnail' ), |
|
| 84 | + ); |
|
| 85 | + |
|
| 86 | + register_post_type( 'project', $args ); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Register the Group taxonomy |
|
| 91 | + */ |
|
| 92 | + public function taxonomy_setup() { |
|
| 93 | + $labels = array( |
|
| 94 | + 'name' => esc_html_x( 'Project Groups', 'taxonomy general name', 'lsx-projects' ), |
|
| 95 | + 'singular_name' => esc_html_x( 'Group', 'taxonomy singular name', 'lsx-projects' ), |
|
| 96 | + 'search_items' => esc_html__( 'Search Groups', 'lsx-projects' ), |
|
| 97 | + 'all_items' => esc_html__( 'All Groups', 'lsx-projects' ), |
|
| 98 | + 'parent_item' => esc_html__( 'Parent Group', 'lsx-projects' ), |
|
| 99 | + 'parent_item_colon' => esc_html__( 'Parent Group:', 'lsx-projects' ), |
|
| 100 | + 'edit_item' => esc_html__( 'Edit Group', 'lsx-projects' ), |
|
| 101 | + 'update_item' => esc_html__( 'Update Group', 'lsx-projects' ), |
|
| 102 | + 'add_new_item' => esc_html__( 'Add New Group', 'lsx-projects' ), |
|
| 103 | + 'new_item_name' => esc_html__( 'New Group Name', 'lsx-projects' ), |
|
| 104 | + 'menu_name' => esc_html__( 'Groups', 'lsx-projects' ), |
|
| 105 | + ); |
|
| 106 | + |
|
| 107 | + $args = array( |
|
| 108 | + 'hierarchical' => true, |
|
| 109 | + 'labels' => $labels, |
|
| 110 | + 'show_ui' => true, |
|
| 111 | + 'show_admin_column' => true, |
|
| 112 | + 'query_var' => true, |
|
| 113 | + 'rewrite' => array( |
|
| 114 | + 'slug' => 'portfolio-group', |
|
| 115 | + ), |
|
| 116 | + ); |
|
| 117 | + |
|
| 118 | + register_taxonomy( 'project-group', array( 'project' ), $args ); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Add metabox with custom fields to the Project post type |
|
| 123 | + */ |
|
| 124 | + public function field_setup() { |
|
| 125 | + $prefix = 'lsx_project_'; |
|
| 126 | + |
|
| 127 | + $cmb = new_cmb2_box( |
|
| 128 | + array( |
|
| 129 | + 'id' => $prefix . '_project', |
|
| 130 | + 'title' => __( 'General', 'lsx-projects' ), |
|
| 131 | + 'object_types' => 'project', |
|
| 132 | + 'context' => 'normal', |
|
| 133 | + 'priority' => 'low', |
|
| 134 | + 'show_names' => true, |
|
| 135 | + ) |
|
| 136 | + ); |
|
| 137 | + |
|
| 138 | + $cmb->add_field( |
|
| 139 | + array( |
|
| 140 | + 'name' => esc_html__( 'Featured:', 'lsx-projects' ), |
|
| 141 | + 'id' => $prefix . 'featured', |
|
| 142 | + 'type' => 'checkbox', |
|
| 143 | + 'value' => 1, |
|
| 144 | + 'default' => 0, |
|
| 145 | + 'show_in_rest' => true, |
|
| 146 | + ) |
|
| 147 | + ); |
|
| 148 | + |
|
| 149 | + $cmb->add_field( |
|
| 150 | + array( |
|
| 151 | + 'name' => esc_html__( 'Client:', 'lsx-projects' ), |
|
| 152 | + 'id' => $prefix . 'client', |
|
| 153 | + 'type' => 'text', |
|
| 154 | + 'show_in_rest' => true, |
|
| 155 | + ) |
|
| 156 | + ); |
|
| 157 | + |
|
| 158 | + $cmb->add_field( |
|
| 159 | + array( |
|
| 160 | + 'name' => esc_html__( 'Client logo:', 'lsx-projects' ), |
|
| 161 | + 'id' => $prefix . 'client_logo', |
|
| 162 | + 'type' => 'image', |
|
| 163 | + 'desc' => esc_html__( 'Recommended image size: 320 x 50~60', 'lsx-projects' ), |
|
| 164 | + 'options' => array( |
|
| 165 | + 'url' => false, // Hide the text input for the url. |
|
| 166 | + ), |
|
| 167 | + 'text' => array( |
|
| 168 | + 'add_upload_file_text' => 'Choose Image', |
|
| 169 | + ), |
|
| 170 | + 'show_in_rest' => true, |
|
| 171 | + ) |
|
| 172 | + ); |
|
| 173 | + |
|
| 174 | + $cmb->add_field( |
|
| 175 | + array( |
|
| 176 | + 'name' => esc_html__( 'URL for the finished project:', 'lsx-projects' ), |
|
| 177 | + 'id' => $prefix . 'url', |
|
| 178 | + 'type' => 'text', |
|
| 179 | + 'show_in_rest' => true, |
|
| 180 | + ) |
|
| 181 | + ); |
|
| 182 | + |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * Project Services Metaboxes. |
|
| 187 | + */ |
|
| 188 | + public function projects_services_metaboxes() { |
|
| 189 | + $prefix = 'lsx_project_'; |
|
| 190 | + |
|
| 191 | + $cmb = new_cmb2_box( |
|
| 192 | + array( |
|
| 193 | + 'id' => $prefix . '_project', |
|
| 194 | + 'object_types' => 'projects', |
|
| 195 | + 'context' => 'normal', |
|
| 196 | + 'priority' => 'low', |
|
| 197 | + 'show_names' => true, |
|
| 198 | + ) |
|
| 199 | + ); |
|
| 200 | + |
|
| 201 | + $cmb->add_field( |
|
| 202 | + array( |
|
| 203 | + 'name' => esc_html__( 'Services related to this project:', 'lsx-projects' ), |
|
| 204 | + 'id' => 'page_to_project', |
|
| 205 | + 'type' => 'post_search_ajax', |
|
| 206 | + 'show_in_rest' => true, |
|
| 207 | + 'limit' => 15, |
|
| 208 | + 'sortable' => true, |
|
| 209 | + 'query_args' => array( |
|
| 210 | + 'post_type' => array( 'page' ), |
|
| 211 | + 'post_status' => array( 'publish' ), |
|
| 212 | + 'nopagin' => true, |
|
| 213 | + 'posts_per_page' => '50', |
|
| 214 | + 'orderby' => 'title', |
|
| 215 | + 'order' => 'ASC', |
|
| 216 | + ), |
|
| 217 | + ) |
|
| 218 | + ); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * Project Testimonials Metaboxes. |
|
| 223 | + */ |
|
| 224 | + public function projects_testimonials_metaboxes() { |
|
| 225 | + $prefix = 'lsx_project_'; |
|
| 226 | + |
|
| 227 | + $cmb = new_cmb2_box( |
|
| 228 | + array( |
|
| 229 | + 'id' => $prefix . '_project', |
|
| 230 | + 'object_types' => 'projects', |
|
| 231 | + 'context' => 'normal', |
|
| 232 | + 'priority' => 'low', |
|
| 233 | + 'show_names' => true, |
|
| 234 | + ) |
|
| 235 | + ); |
|
| 236 | + |
|
| 237 | + if ( class_exists( 'LSX_Testimonials' ) ) { |
|
| 238 | + $cmb->add_field( |
|
| 239 | + array( |
|
| 240 | + 'name' => esc_html__( 'Testimonials related to this project:', 'lsx-projects' ), |
|
| 241 | + 'id' => 'testimonial_to_project', |
|
| 242 | + 'type' => 'post_search_ajax', |
|
| 243 | + 'show_in_rest' => true, |
|
| 244 | + 'limit' => 15, |
|
| 245 | + 'sortable' => true, |
|
| 246 | + 'query_args' => array( |
|
| 247 | + 'post_type' => array( 'testimonials' ), |
|
| 248 | + 'post_status' => array( 'publish' ), |
|
| 249 | + 'nopagin' => true, |
|
| 250 | + 'posts_per_page' => '50', |
|
| 251 | + 'orderby' => 'title', |
|
| 252 | + 'order' => 'ASC', |
|
| 253 | + ), |
|
| 254 | + ) |
|
| 255 | + ); |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * Project Team Metaboxes. |
|
| 261 | + */ |
|
| 262 | + public function projects_team_metaboxes() { |
|
| 263 | + $prefix = 'lsx_project_'; |
|
| 264 | + |
|
| 265 | + $cmb = new_cmb2_box( |
|
| 266 | + array( |
|
| 267 | + 'id' => $prefix . '_project', |
|
| 268 | + 'object_types' => 'project', |
|
| 269 | + 'context' => 'normal', |
|
| 270 | + 'priority' => 'low', |
|
| 271 | + 'show_names' => true, |
|
| 272 | + ) |
|
| 273 | + ); |
|
| 274 | + |
|
| 275 | + if ( class_exists( 'LSX_Team' ) ) { |
|
| 276 | + $cmb->add_field( |
|
| 277 | + array( |
|
| 278 | + 'name' => esc_html__( 'Team members involved with this project:', 'lsx-projects' ), |
|
| 279 | + 'id' => 'team_to_project', |
|
| 280 | + 'type' => 'post_search_ajax', |
|
| 281 | + 'show_in_rest' => true, |
|
| 282 | + 'limit' => 15, |
|
| 283 | + 'sortable' => true, |
|
| 284 | + 'query_args' => array( |
|
| 285 | + 'post_type' => array( 'team' ), |
|
| 286 | + 'post_status' => array( 'publish' ), |
|
| 287 | + 'nopagin' => true, |
|
| 288 | + 'posts_per_page' => '50', |
|
| 289 | + 'orderby' => 'title', |
|
| 290 | + 'order' => 'ASC', |
|
| 291 | + ), |
|
| 292 | + ) |
|
| 293 | + ); |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * Project Woocommerce Metaboxes. |
|
| 299 | + */ |
|
| 300 | + public function projects_woocommerce_metaboxes() { |
|
| 301 | + $prefix = 'lsx_project_'; |
|
| 302 | + |
|
| 303 | + $cmb = new_cmb2_box( |
|
| 304 | + array( |
|
| 305 | + 'id' => $prefix . '_project', |
|
| 306 | + 'object_types' => 'projects', |
|
| 307 | + 'context' => 'normal', |
|
| 308 | + 'priority' => 'low', |
|
| 309 | + 'show_names' => true, |
|
| 310 | + ) |
|
| 311 | + ); |
|
| 312 | + |
|
| 313 | + if ( class_exists( 'woocommerce' ) ) { |
|
| 314 | + $cmb->add_field( |
|
| 315 | + array( |
|
| 316 | + 'name' => esc_html__( 'Products used for this project:', 'lsx-projects' ), |
|
| 317 | + 'id' => 'product_to_project', |
|
| 318 | + 'type' => 'post_search_ajax', |
|
| 319 | + 'show_in_rest' => true, |
|
| 320 | + 'limit' => 15, |
|
| 321 | + 'sortable' => true, |
|
| 322 | + 'query_args' => array( |
|
| 323 | + 'post_type' => array( 'product' ), |
|
| 324 | + 'post_status' => array( 'publish' ), |
|
| 325 | + 'nopagin' => true, |
|
| 326 | + 'posts_per_page' => '50', |
|
| 327 | + 'orderby' => 'title', |
|
| 328 | + 'order' => 'ASC', |
|
| 329 | + ), |
|
| 330 | + ) |
|
| 331 | + ); |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * Sets up the "post relations". |
|
| 337 | + */ |
|
| 338 | + public function post_relations( $post_id, $field, $value ) { |
|
| 339 | + $connections = array( |
|
| 340 | + // 'project_to_project', |
|
| 341 | + |
|
| 342 | + 'page_to_project', |
|
| 343 | + 'project_to_page', |
|
| 344 | + |
|
| 345 | + 'project_to_service', |
|
| 346 | + 'service_to_project', |
|
| 347 | + |
|
| 348 | + 'project_to_testimonial', |
|
| 349 | + 'testimonial_to_project', |
|
| 350 | + |
|
| 351 | + 'project_to_team', |
|
| 352 | + 'team_to_project', |
|
| 353 | + ); |
|
| 354 | + |
|
| 355 | + if ( in_array( $field['id'], $connections ) ) { |
|
| 356 | + $this->save_related_post( $connections, $post_id, $field, $value ); |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * Save the reverse post relation. |
|
| 362 | + */ |
|
| 363 | + public function save_related_post( $connections, $post_id, $field, $value ) { |
|
| 364 | + $ids = explode( '_to_', $field['id'] ); |
|
| 365 | + $relation = $ids[1] . '_to_' . $ids[0]; |
|
| 366 | + |
|
| 367 | + if ( in_array( $relation, $connections ) ) { |
|
| 368 | + $previous_values = get_post_meta( $post_id, $field['id'], false ); |
|
| 369 | + |
|
| 370 | + if ( ! empty( $previous_values ) ) { |
|
| 371 | + foreach ( $previous_values as $v ) { |
|
| 372 | + delete_post_meta( $v, $relation, $post_id ); |
|
| 373 | + } |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + if ( is_array( $value ) ) { |
|
| 377 | + foreach ( $value as $v ) { |
|
| 378 | + if ( ! empty( $v ) ) { |
|
| 379 | + add_post_meta( $v, $relation, $post_id ); |
|
| 380 | + } |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | + } |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + public function assets() { |
|
| 387 | + //wp_enqueue_media(); |
|
| 388 | + wp_enqueue_script( 'media-upload' ); |
|
| 389 | + wp_enqueue_script( 'thickbox' ); |
|
| 390 | + wp_enqueue_style( 'thickbox' ); |
|
| 391 | + |
|
| 392 | + wp_enqueue_script( 'lsx-projects-admin', LSX_PROJECTS_URL . 'assets/js/lsx-projects-admin.min.js', array( 'jquery' ), LSX_PROJECTS_VER, true ); |
|
| 393 | + wp_enqueue_style( 'lsx-projects-admin', LSX_PROJECTS_URL . 'assets/css/lsx-projects-admin.css', array(), LSX_PROJECTS_VER ); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * Change the "Insert into Post" button text when media modal is used for feature images |
|
| 398 | + */ |
|
| 399 | + public function change_attachment_field_button( $html ) { |
|
| 400 | + if ( isset( $_GET['feature_image_text_button'] ) ) { |
|
| 401 | + $html = str_replace( 'value="Insert into Post"', sprintf( 'value="%s"', esc_html__( 'Select featured image', 'lsx-projects' ) ), $html ); |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + return $html; |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + public function change_title_text( $title ) { |
|
| 408 | + $screen = get_current_screen(); |
|
| 409 | + |
|
| 410 | + if ( 'project' === $screen->post_type ) { |
|
| 411 | + $title = esc_attr__( 'Enter project title', 'lsx-projects' ); |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + return $title; |
|
| 415 | + } |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | $lsx_projects_admin = new LSX_Projects_Admin(); |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | |
| 15 | 15 | // If this file is called directly, abort. |
| 16 | 16 | if ( ! defined( 'WPINC' ) ) { |
| 17 | - die; |
|
| 17 | + die; |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | define( 'LSX_PROJECTS_PATH', plugin_dir_path( __FILE__ ) ); |
@@ -5,23 +5,23 @@ discard block |
||
| 5 | 5 | ?> |
| 6 | 6 | |
| 7 | 7 | <?php |
| 8 | - $groups = ''; |
|
| 9 | - $groups_class = ''; |
|
| 10 | - $terms = get_the_terms( get_the_ID(), 'project-group' ); |
|
| 11 | - $lsx_projects_frontend = projects_get_options(); |
|
| 12 | - |
|
| 13 | - if ( $terms && ! is_wp_error( $terms ) ) { |
|
| 14 | - $groups = array(); |
|
| 15 | - $groups_class = array(); |
|
| 16 | - |
|
| 17 | - foreach ( $terms as $term ) { |
|
| 18 | - $groups[] = '<a href="' . get_term_link( $term ) . '">' . $term->name . '</a>'; |
|
| 19 | - $groups_class[] = 'filter-' . $term->slug; |
|
| 20 | - } |
|
| 21 | - |
|
| 22 | - $groups = join( ', ', $groups ); |
|
| 23 | - $groups_class = join( ' ', $groups_class ); |
|
| 24 | - } |
|
| 8 | + $groups = ''; |
|
| 9 | + $groups_class = ''; |
|
| 10 | + $terms = get_the_terms( get_the_ID(), 'project-group' ); |
|
| 11 | + $lsx_projects_frontend = projects_get_options(); |
|
| 12 | + |
|
| 13 | + if ( $terms && ! is_wp_error( $terms ) ) { |
|
| 14 | + $groups = array(); |
|
| 15 | + $groups_class = array(); |
|
| 16 | + |
|
| 17 | + foreach ( $terms as $term ) { |
|
| 18 | + $groups[] = '<a href="' . get_term_link( $term ) . '">' . $term->name . '</a>'; |
|
| 19 | + $groups_class[] = 'filter-' . $term->slug; |
|
| 20 | + } |
|
| 21 | + |
|
| 22 | + $groups = join( ', ', $groups ); |
|
| 23 | + $groups_class = join( ' ', $groups_class ); |
|
| 24 | + } |
|
| 25 | 25 | ?> |
| 26 | 26 | |
| 27 | 27 | <div class="col-xs-12 col-sm-6 col-md-4 lsx-projects-column <?php echo esc_attr( $groups_class ); ?>"> |
@@ -35,12 +35,12 @@ discard block |
||
| 35 | 35 | <?php } ?> |
| 36 | 36 | |
| 37 | 37 | <?php |
| 38 | - if ( empty( lsx_get_thumbnail( 'lsx-thumbnail-single' ) ) ) { |
|
| 39 | - if ( ! empty( projects_get_option( 'projects_placeholder' ) ) ) { |
|
| 40 | - echo wp_kses_post( '<img src="' . projects_get_option( 'projects_placeholder' ) . '" width="auto" alt="placeholder" />' ); |
|
| 41 | - } |
|
| 42 | - } |
|
| 43 | - ?> |
|
| 38 | + if ( empty( lsx_get_thumbnail( 'lsx-thumbnail-single' ) ) ) { |
|
| 39 | + if ( ! empty( projects_get_option( 'projects_placeholder' ) ) ) { |
|
| 40 | + echo wp_kses_post( '<img src="' . projects_get_option( 'projects_placeholder' ) . '" width="auto" alt="placeholder" />' ); |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | + ?> |
|
| 44 | 44 | |
| 45 | 45 | <h5 class="lsx-projects-title"> |
| 46 | 46 | <?php if ( 'on' !== projects_get_option( 'projects_disable_single', false ) ) { ?> |