@@ -10,169 +10,169 @@ discard block |
||
10 | 10 | */ |
11 | 11 | class LSX_Projects { |
12 | 12 | |
13 | - public $columns, $responsive, $options; |
|
14 | - |
|
15 | - public function __construct() { |
|
16 | - $this->options = projects_get_options(); |
|
17 | - |
|
18 | - add_filter( 'lsx_banner_allowed_post_types', array( $this, 'lsx_banner_allowed_post_types' ) ); |
|
19 | - add_filter( 'lsx_banner_allowed_taxonomies', array( $this, 'lsx_banner_allowed_taxonomies' ) ); |
|
20 | - } |
|
21 | - |
|
22 | - /** |
|
23 | - * Enable project custom post type on LSX Banners. |
|
24 | - */ |
|
25 | - public function lsx_banner_allowed_post_types( $post_types ) { |
|
26 | - $post_types[] = 'project'; |
|
27 | - return $post_types; |
|
28 | - } |
|
29 | - |
|
30 | - /** |
|
31 | - * Enable project custom taxonomies on LSX Banners. |
|
32 | - */ |
|
33 | - public function lsx_banner_allowed_taxonomies( $taxonomies ) { |
|
34 | - $taxonomies[] = 'project-group'; |
|
35 | - return $taxonomies; |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * Returns the shortcode output markup |
|
40 | - */ |
|
41 | - public function output( $atts ) { |
|
42 | - // @codingStandardsIgnoreLine |
|
43 | - extract( shortcode_atts( array( |
|
44 | - 'columns' => 3, |
|
45 | - 'orderby' => 'name', |
|
46 | - 'order' => 'ASC', |
|
47 | - 'limit' => '-1', |
|
48 | - 'include' => '', |
|
49 | - 'display' => 'excerpt', |
|
50 | - 'size' => 'lsx-thumbnail-single', |
|
51 | - 'responsive' => 'true', |
|
52 | - 'show_image' => 'true', |
|
53 | - 'carousel' => 'true', |
|
54 | - 'featured' => 'false', |
|
55 | - ), $atts ) ); |
|
56 | - |
|
57 | - $output = ''; |
|
58 | - |
|
59 | - if ( 'true' === $responsive || true === $responsive ) { |
|
60 | - $responsive = ' img-responsive'; |
|
61 | - } else { |
|
62 | - $responsive = ''; |
|
63 | - } |
|
64 | - |
|
65 | - $this->columns = $columns; |
|
66 | - $this->responsive = $responsive; |
|
67 | - |
|
68 | - if ( ! empty( $include ) ) { |
|
69 | - $include = explode( ',', $include ); |
|
70 | - |
|
71 | - $args = array( |
|
72 | - 'post_type' => 'project', |
|
73 | - 'posts_per_page' => $limit, |
|
74 | - 'post__in' => $include, |
|
75 | - 'orderby' => 'post__in', |
|
76 | - 'order' => $order, |
|
77 | - ); |
|
78 | - } else { |
|
79 | - $args = array( |
|
80 | - 'post_type' => 'project', |
|
81 | - 'posts_per_page' => $limit, |
|
82 | - 'orderby' => $orderby, |
|
83 | - 'order' => $order, |
|
84 | - ); |
|
85 | - |
|
86 | - if ( 'true' === $featured || true === $featured ) { |
|
87 | - $args['meta_key'] = 'lsx_project_featured'; |
|
88 | - $args['meta_value'] = 1; |
|
89 | - } |
|
90 | - } |
|
91 | - |
|
92 | - $projects = new \WP_Query( $args ); |
|
93 | - |
|
94 | - if ( $projects->have_posts() ) { |
|
95 | - global $post; |
|
96 | - |
|
97 | - $count = 0; |
|
98 | - $count_global = 0; |
|
99 | - |
|
100 | - if ( 'true' === $carousel || true === $carousel ) { |
|
101 | - $output .= "<div id='lsx-projects-slider' class='lsx-projects-shortcode' data-slick='{\"slidesToShow\": $columns, \"slidesToScroll\": $columns }'>"; |
|
102 | - } else { |
|
103 | - $output .= "<div class='lsx-projects-shortcode'><div class='row'>"; |
|
104 | - } |
|
105 | - |
|
106 | - while ( $projects->have_posts() ) { |
|
107 | - $projects->the_post(); |
|
108 | - |
|
109 | - // Count |
|
110 | - $count++; |
|
111 | - $count_global++; |
|
112 | - |
|
113 | - // Content |
|
114 | - if ( 'full' === $display ) { |
|
115 | - $content = apply_filters( 'the_content', get_the_content() ); |
|
116 | - $content = str_replace( ']]>', ']]>', $content ); |
|
117 | - } elseif ( 'excerpt' === $display ) { |
|
118 | - $content = apply_filters( 'the_excerpt', get_the_excerpt() ); |
|
119 | - } |
|
120 | - |
|
121 | - // Image |
|
122 | - if ( 'true' === $show_image || true === $show_image ) { |
|
123 | - if ( is_numeric( $size ) ) { |
|
124 | - $thumb_size = array( $size, $size ); |
|
125 | - } else { |
|
126 | - $thumb_size = $size; |
|
127 | - } |
|
128 | - |
|
129 | - if ( ! empty( get_the_post_thumbnail( $post->ID ) ) ) { |
|
130 | - $image = get_the_post_thumbnail( $post->ID, $thumb_size, array( |
|
131 | - 'class' => $responsive, |
|
132 | - ) ); |
|
133 | - } else { |
|
134 | - $image = ''; |
|
135 | - } |
|
136 | - |
|
137 | - if ( empty( $image ) ) { |
|
138 | - if ( ! empty( $this->options['display']['projects_placeholder'] ) ) { |
|
139 | - $image = '<img class="' . $responsive . '" src="' . $this->options['display']['projects_placeholder'] . '" width="' . $size . '" alt="placeholder" />'; |
|
140 | - } else { |
|
141 | - $image = ''; |
|
142 | - } |
|
143 | - } |
|
144 | - } else { |
|
145 | - $image = ''; |
|
146 | - } |
|
147 | - |
|
148 | - // Project groups |
|
149 | - $groups = ''; |
|
150 | - $terms = get_the_terms( $post->ID, 'project-group' ); |
|
151 | - |
|
152 | - if ( $terms && ! is_wp_error( $terms ) ) { |
|
153 | - $groups = array(); |
|
154 | - |
|
155 | - foreach ( $terms as $term ) { |
|
156 | - $groups[] = $term->name; |
|
157 | - } |
|
158 | - |
|
159 | - $groups = join( ', ', $groups ); |
|
160 | - } |
|
161 | - |
|
162 | - $project_groups = '' !== $groups ? "<p class='lsx-projects-groups'>$groups</p>" : ''; |
|
163 | - |
|
164 | - if ( 'true' === $carousel || true === $carousel ) { |
|
165 | - $output .= " |
|
13 | + public $columns, $responsive, $options; |
|
14 | + |
|
15 | + public function __construct() { |
|
16 | + $this->options = projects_get_options(); |
|
17 | + |
|
18 | + add_filter( 'lsx_banner_allowed_post_types', array( $this, 'lsx_banner_allowed_post_types' ) ); |
|
19 | + add_filter( 'lsx_banner_allowed_taxonomies', array( $this, 'lsx_banner_allowed_taxonomies' ) ); |
|
20 | + } |
|
21 | + |
|
22 | + /** |
|
23 | + * Enable project custom post type on LSX Banners. |
|
24 | + */ |
|
25 | + public function lsx_banner_allowed_post_types( $post_types ) { |
|
26 | + $post_types[] = 'project'; |
|
27 | + return $post_types; |
|
28 | + } |
|
29 | + |
|
30 | + /** |
|
31 | + * Enable project custom taxonomies on LSX Banners. |
|
32 | + */ |
|
33 | + public function lsx_banner_allowed_taxonomies( $taxonomies ) { |
|
34 | + $taxonomies[] = 'project-group'; |
|
35 | + return $taxonomies; |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * Returns the shortcode output markup |
|
40 | + */ |
|
41 | + public function output( $atts ) { |
|
42 | + // @codingStandardsIgnoreLine |
|
43 | + extract( shortcode_atts( array( |
|
44 | + 'columns' => 3, |
|
45 | + 'orderby' => 'name', |
|
46 | + 'order' => 'ASC', |
|
47 | + 'limit' => '-1', |
|
48 | + 'include' => '', |
|
49 | + 'display' => 'excerpt', |
|
50 | + 'size' => 'lsx-thumbnail-single', |
|
51 | + 'responsive' => 'true', |
|
52 | + 'show_image' => 'true', |
|
53 | + 'carousel' => 'true', |
|
54 | + 'featured' => 'false', |
|
55 | + ), $atts ) ); |
|
56 | + |
|
57 | + $output = ''; |
|
58 | + |
|
59 | + if ( 'true' === $responsive || true === $responsive ) { |
|
60 | + $responsive = ' img-responsive'; |
|
61 | + } else { |
|
62 | + $responsive = ''; |
|
63 | + } |
|
64 | + |
|
65 | + $this->columns = $columns; |
|
66 | + $this->responsive = $responsive; |
|
67 | + |
|
68 | + if ( ! empty( $include ) ) { |
|
69 | + $include = explode( ',', $include ); |
|
70 | + |
|
71 | + $args = array( |
|
72 | + 'post_type' => 'project', |
|
73 | + 'posts_per_page' => $limit, |
|
74 | + 'post__in' => $include, |
|
75 | + 'orderby' => 'post__in', |
|
76 | + 'order' => $order, |
|
77 | + ); |
|
78 | + } else { |
|
79 | + $args = array( |
|
80 | + 'post_type' => 'project', |
|
81 | + 'posts_per_page' => $limit, |
|
82 | + 'orderby' => $orderby, |
|
83 | + 'order' => $order, |
|
84 | + ); |
|
85 | + |
|
86 | + if ( 'true' === $featured || true === $featured ) { |
|
87 | + $args['meta_key'] = 'lsx_project_featured'; |
|
88 | + $args['meta_value'] = 1; |
|
89 | + } |
|
90 | + } |
|
91 | + |
|
92 | + $projects = new \WP_Query( $args ); |
|
93 | + |
|
94 | + if ( $projects->have_posts() ) { |
|
95 | + global $post; |
|
96 | + |
|
97 | + $count = 0; |
|
98 | + $count_global = 0; |
|
99 | + |
|
100 | + if ( 'true' === $carousel || true === $carousel ) { |
|
101 | + $output .= "<div id='lsx-projects-slider' class='lsx-projects-shortcode' data-slick='{\"slidesToShow\": $columns, \"slidesToScroll\": $columns }'>"; |
|
102 | + } else { |
|
103 | + $output .= "<div class='lsx-projects-shortcode'><div class='row'>"; |
|
104 | + } |
|
105 | + |
|
106 | + while ( $projects->have_posts() ) { |
|
107 | + $projects->the_post(); |
|
108 | + |
|
109 | + // Count |
|
110 | + $count++; |
|
111 | + $count_global++; |
|
112 | + |
|
113 | + // Content |
|
114 | + if ( 'full' === $display ) { |
|
115 | + $content = apply_filters( 'the_content', get_the_content() ); |
|
116 | + $content = str_replace( ']]>', ']]>', $content ); |
|
117 | + } elseif ( 'excerpt' === $display ) { |
|
118 | + $content = apply_filters( 'the_excerpt', get_the_excerpt() ); |
|
119 | + } |
|
120 | + |
|
121 | + // Image |
|
122 | + if ( 'true' === $show_image || true === $show_image ) { |
|
123 | + if ( is_numeric( $size ) ) { |
|
124 | + $thumb_size = array( $size, $size ); |
|
125 | + } else { |
|
126 | + $thumb_size = $size; |
|
127 | + } |
|
128 | + |
|
129 | + if ( ! empty( get_the_post_thumbnail( $post->ID ) ) ) { |
|
130 | + $image = get_the_post_thumbnail( $post->ID, $thumb_size, array( |
|
131 | + 'class' => $responsive, |
|
132 | + ) ); |
|
133 | + } else { |
|
134 | + $image = ''; |
|
135 | + } |
|
136 | + |
|
137 | + if ( empty( $image ) ) { |
|
138 | + if ( ! empty( $this->options['display']['projects_placeholder'] ) ) { |
|
139 | + $image = '<img class="' . $responsive . '" src="' . $this->options['display']['projects_placeholder'] . '" width="' . $size . '" alt="placeholder" />'; |
|
140 | + } else { |
|
141 | + $image = ''; |
|
142 | + } |
|
143 | + } |
|
144 | + } else { |
|
145 | + $image = ''; |
|
146 | + } |
|
147 | + |
|
148 | + // Project groups |
|
149 | + $groups = ''; |
|
150 | + $terms = get_the_terms( $post->ID, 'project-group' ); |
|
151 | + |
|
152 | + if ( $terms && ! is_wp_error( $terms ) ) { |
|
153 | + $groups = array(); |
|
154 | + |
|
155 | + foreach ( $terms as $term ) { |
|
156 | + $groups[] = $term->name; |
|
157 | + } |
|
158 | + |
|
159 | + $groups = join( ', ', $groups ); |
|
160 | + } |
|
161 | + |
|
162 | + $project_groups = '' !== $groups ? "<p class='lsx-projects-groups'>$groups</p>" : ''; |
|
163 | + |
|
164 | + if ( 'true' === $carousel || true === $carousel ) { |
|
165 | + $output .= " |
|
166 | 166 | <div class='lsx-projects-slot'> |
167 | 167 | " . ( ! empty( $image ) ? "<a href='" . get_permalink() . "'><figure class='lsx-projects-avatar'>$image</figure></a>" : '' ) . " |
168 | 168 | <h5 class='lsx-projects-title'><a href='" . get_permalink() . "'>" . apply_filters( 'the_title', $post->post_title ) . "</a></h5> |
169 | 169 | $project_groups |
170 | 170 | <div class='lsx-projects-content'><a href='" . get_permalink() . "' class='moretag'>" . esc_html__( 'View more', 'lsx-projects' ) . '</a></div> |
171 | 171 | </div>'; |
172 | - } elseif ( $columns >= 1 && $columns <= 4 ) { |
|
173 | - $md_col_width = 12 / $columns; |
|
172 | + } elseif ( $columns >= 1 && $columns <= 4 ) { |
|
173 | + $md_col_width = 12 / $columns; |
|
174 | 174 | |
175 | - $output .= " |
|
175 | + $output .= " |
|
176 | 176 | <div class='col-xs-12 col-md-" . $md_col_width . "'> |
177 | 177 | <div class='lsx-projects-slot'> |
178 | 178 | " . ( ! empty( $image ) ? "<a href='" . get_permalink() . "'><figure class='lsx-projects-avatar'>$image</figure></a>" : '' ) . " |
@@ -182,30 +182,30 @@ discard block |
||
182 | 182 | </div> |
183 | 183 | </div>'; |
184 | 184 | |
185 | - if ( $count == $columns && $projects->post_count > $count_global ) { |
|
186 | - $output .= '</div>'; |
|
187 | - $output .= "<div class='row'>"; |
|
188 | - $count = 0; |
|
189 | - } |
|
190 | - } else { |
|
191 | - $output .= " |
|
185 | + if ( $count == $columns && $projects->post_count > $count_global ) { |
|
186 | + $output .= '</div>'; |
|
187 | + $output .= "<div class='row'>"; |
|
188 | + $count = 0; |
|
189 | + } |
|
190 | + } else { |
|
191 | + $output .= " |
|
192 | 192 | <p class='bg-warning' style='padding: 20px;'> |
193 | 193 | " . esc_html__( 'Invalid number of columns set. LSX Projects supports 1 to 4 columns.', 'lsx-projects' ) . ' |
194 | 194 | </p>'; |
195 | - } |
|
195 | + } |
|
196 | 196 | |
197 | - wp_reset_postdata(); |
|
198 | - } |
|
197 | + wp_reset_postdata(); |
|
198 | + } |
|
199 | 199 | |
200 | - if ( 'true' !== $carousel && true !== $carousel ) { |
|
201 | - $output .= '</div>'; |
|
202 | - } |
|
200 | + if ( 'true' !== $carousel && true !== $carousel ) { |
|
201 | + $output .= '</div>'; |
|
202 | + } |
|
203 | 203 | |
204 | - $output .= '</div>'; |
|
204 | + $output .= '</div>'; |
|
205 | 205 | |
206 | - return $output; |
|
207 | - } |
|
208 | - } |
|
206 | + return $output; |
|
207 | + } |
|
208 | + } |
|
209 | 209 | |
210 | 210 | } |
211 | 211 |
@@ -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__ ) ); |