PluginProbe
Essential Content Types / trunk
Essential Content Types vtrunk
2.6 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1 1.2 1.3 1.4 1.5 1.5.1 1.6 1.7 1.8 1.8.1 1.8.2 1.8.3 1.8.4 All 41 releases
essential-content-types / essential-content-types.php

essential-content-types.php in Essential Content Types trunk, at essential-content-types.php

296 lines 10.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The plugin bootstrap file
5 *
6 * This file is read by WordPress to generate the plugin information in the plugin
7 * admin area. This file also includes all of the dependencies used by the plugin,
8 * registers the activation and deactivation functions, and defines a function
9 * that starts the plugin.
10 *
11 * @link https://catchplugins.com
12 * @since 1.0.0
13 * @package Essential_Content_Types
14 *
15 * @wordpress-plugin
16 * Plugin Name: Essential Content Types
17 * Plugin URI: https://catchplugins.com/plugins/essential-content-types/
18 * Description: Essential Content Types allows you to feature the impressive content through different content/post types on your website just the way you want it. These content/post types are missed by the themes in WordPress Theme Directory as the feature falls more towards the plugins’ territory.
19 * Version: 2.6
20 * Author: Catch Plugins
21 * Author URI: https://catchplugins.com
22 * License: GPL-3.0+
23 * License URI: https://www.gnu.org/licenses/gpl-3.0.txt
24 * Text Domain: essential-content-types
25 * Domain Path: /languages
26 */
27
28 // If this file is called directly, abort.
29 if (! defined('WPINC')) {
30 die;
31 }
32
33 // Define Version
34 if (! defined('ESSENTIAL_CONTENT_TYPES_VERSION')) {
35 define('ESSENTIAL_CONTENT_TYPES_VERSION', '2.6');
36 }
37
38 /**
39 * The code that runs during plugin activation.
40 * This action is documented in includes/class-essential-content-types-activator.php
41 */
42 // The URL of the directory that contains the plugin
43 if (! defined('ESSENTIAL_CONTENT_TYPES_URL')) {
44 define('ESSENTIAL_CONTENT_TYPES_URL', plugin_dir_url(__FILE__));
45 }
46
47 // The absolute path of the directory that contains the file
48 if (! defined('ESSENTIAL_CONTENT_TYPES_PATH')) {
49 define('ESSENTIAL_CONTENT_TYPES_PATH', plugin_dir_path(__FILE__));
50 }
51
52 // Gets the path to a plugin file or directory, relative to the plugins directory, without the leading and trailing slashes.
53 if (! defined('ESSENTIAL_CONTENT_TYPES_BASENAME')) {
54 define('ESSENTIAL_CONTENT_TYPES_BASENAME', plugin_basename(__FILE__));
55 }
56
57 /**
58 * Make plugin available for translation
59 * Translations can be filed in the /languages/ directory
60 */
61 function essential_content_types_activate()
62 {
63 $required = 'essential-content-types-pro/essential-content-types-pro.php';
64 if (is_plugin_active($required)) {
65 // Translators: %1$s and %2$s wrap the "Return to Plugins" link. The message informs the user that the Pro version is active.
66 $message = esc_html__('Sorry, Pro plugin is already active. No need to activate Free version. %1$s&laquo; Return to Plugins%2$s.', 'essential-content-types');
67 $message = sprintf($message, '<br><a href="' . esc_url(admin_url('plugins.php')) . '">', '</a>');
68 wp_die(wp_kses_post($message));
69 }
70 require_once plugin_dir_path(__FILE__) . 'includes/class-essential-content-types-activator.php';
71 Essential_Content_Types_Activator::activate();
72 }
73
74 /**
75 * The code that runs during plugin deactivation.
76 * This action is documented in includes/class-essential-content-types-deactivator.php
77 */
78 function essential_content_types_deactivate()
79 {
80 require_once plugin_dir_path(__FILE__) . 'includes/class-essential-content-types-deactivator.php';
81 Essential_Content_Types_Deactivator::deactivate();
82 }
83
84 register_activation_hook(__FILE__, 'essential_content_types_activate');
85 register_deactivation_hook(__FILE__, 'essential_content_types_deactivate');
86
87 /**
88 * The core plugin class that is used to define internationalization,
89 * admin-specific hooks, and public-facing site hooks.
90 */
91 require plugin_dir_path(__FILE__) . 'includes/class-essential-content-types.php';
92
93 /**
94 * Begins execution of the plugin.
95 *
96 * Since everything within the plugin is registered via hooks,
97 * then kicking off the plugin from this point in the file does
98 * not affect the page life cycle.
99 *
100 * @since 1.0.0
101 */
102 function essential_content_types_run()
103 {
104
105 $plugin = new Essential_Content_Types();
106 $plugin->run();
107 }
108 essential_content_types_run();
109
110 if (! function_exists('ect_get_layout')) :
111 function ect_get_layout() // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- ect_ is the established short prefix for this plugin.
112 {
113 $layout = array(
114 '1' => 'layout-one',
115 '2' => 'layout-two',
116 '3' => 'layout-three',
117 '4' => 'layout-four',
118 '5' => 'layout-five',
119 '6' => 'layout-six',
120 );
121 return $layout;
122 }
123 endif;
124
125 if (! function_exists('ect_plugin_path')) :
126 /**
127 * Get the plugin path.
128 *
129 * @return string
130 */
131 function ect_plugin_path() // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- ect_ is the established short prefix.
132 {
133 return untrailingslashit(plugin_dir_path(__FILE__));
134 }
135 endif;
136
137 if (! function_exists('ect_template_path')) :
138 /**
139 * Get the template path.
140 *
141 * @return string
142 */
143 function ect_template_path() // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- ect_ is the established short prefix.
144 {
145 return apply_filters('ect_template_path', 'ect-templates/'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- ect_ is the established short prefix.
146 }
147 endif;
148
149 if (! function_exists('ect_get_template_part')) :
150 /**
151 * Get template part (for templates like the shop-loop).
152 *
153 *
154 * @access public
155 * @param mixed $slug Template slug.
156 * @param string $name Template name (default: '').
157 * @param array $atts Options to pass into template.
158 */
159 function ect_get_template_part($slug, $name = '', $atts = '') // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- ect_ is the established short prefix.
160 {
161
162 $template = '';
163 set_query_var('atts', $atts);
164
165 // Look in yourtheme/slug-name.php and yourtheme/ect-templates/slug-name.php.
166 if ($name) {
167 $template = locate_template(array("{$slug}-{$name}.php", ect_template_path() . "{$slug}-{$name}.php"));
168 }
169
170 // Get default slug-name.php.
171 if (empty($template) && $name && file_exists(ect_plugin_path() . '/' . ect_template_path() . "{$slug}-{$name}.php")) {
172 $template = ect_plugin_path() . '/' . ect_template_path() . "{$slug}-{$name}.php";
173 }
174
175 // If template file doesn't exist, look in yourtheme/slug.php and yourtheme/ect-templates/slug.php.
176 if (! $template) {
177 $template = locate_template(array("{$slug}.php", ect_template_path() . "{$slug}.php"));
178 }
179
180 // Allow 3rd party plugins to filter template file from their plugin.
181 $template = apply_filters('ect_get_template_part', $template, $slug, $name); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- ect_ is the established short prefix.
182
183 if ($template) {
184 load_template($template, false, 'atts');
185 }
186 }
187 endif;
188
189 function ect_body_classes($classes) // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- ect_ is the established short prefix.
190 {
191 if ('featured-content' == get_post_type() || 'ect-service' == get_post_type() || 'jetpack-portfolio' == get_post_type() || 'jetpack-testimonial' == get_post_type()) {
192 $classes[] = 'ect-post';
193 }
194
195 return $classes;
196 }
197 add_filter('body_class', 'ect_body_classes');
198 /* CTP tabs removal options */
199 require plugin_dir_path(__FILE__) . '/includes/ctp-tabs-removal.php';
200
201 $essential_content_types_ctp_options = ctp_get_options();
202 if ( 1 == $essential_content_types_ctp_options['theme_plugin_tabs'] ) {
203 /* Adds Catch Themes tab in Add theme page and Themes by Catch Themes in Customizer's change theme option. */
204 if (! class_exists('CatchThemesThemePlugin') && ! function_exists('add_our_plugins_tab')) {
205 require plugin_dir_path(__FILE__) . '/includes/CatchThemesThemePlugin.php';
206 }
207 }
208
209 /* Modify ECT Post type archive title for default values */
210 function ect_check_archive_title() // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- ect_ is the established short prefix.
211 {
212 global $wp_query;
213 $post_type = false;
214 if (isset($wp_query->query['post_type'])) {
215 $post_type = $wp_query->query['post_type'];
216 }
217
218 $ect_post_types = array(
219 'featured-content',
220 'jetpack-portfolio',
221 'jetpack-testimonial',
222 'ect-service',
223 );
224
225 if ($post_type !== false && in_array($post_type, $ect_post_types, true)) {
226 add_filter('get_the_archive_title', 'ect_modify_archive_title', 10, 1);
227 }
228 }
229
230 add_action('wp_head', 'ect_check_archive_title');
231
232 /* set default title if options not found */
233 function ect_modify_archive_title($title) // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- ect_ is the established short prefix.
234 {
235 $title_label = '<span class="some-class">%1$s</span>%2$s';
236 $type = ect_get_archive_post_type();
237
238 if (! $type) {
239 return $title;
240 }
241
242 $default_title = array(
243 'ect_service_title' => esc_html__('Services', 'essential-content-types'),
244 'jetpack_testimonial_title' => esc_html__('Testimonial', 'essential-content-types'),
245 'jetpack_portfolio_title' => esc_html__('Portfolio', 'essential-content-types'),
246 'featured_content_title' => esc_html__('Featured Content', 'essential-content-types'),
247 );
248
249 // Testimonial archive title is stored as a theme_mod (Jetpack-compatible format).
250 // Fall back to the old flat option for sites that haven't run the one-time migration.
251 if ( 'jetpack_testimonial_title' === $type ) {
252 $jetpack_mods = (array) get_theme_mod( 'jetpack_testimonials', array() );
253 $archive_title = ! empty( $jetpack_mods['page-title'] )
254 ? $jetpack_mods['page-title']
255 : get_option( 'jetpack_testimonial_title', $default_title['jetpack_testimonial_title'] );
256 } else {
257 $archive_title = get_option( $type, $default_title[ $type ] );
258 }
259
260 if ('' !== $archive_title) {
261 return trim(
262 sprintf(
263 $title_label,
264 esc_html_x('Archives: ', 'Archive title label.', 'essential-content-types'),
265 $archive_title
266 )
267 );
268 } else {
269 return trim(
270 sprintf(
271 $title_label,
272 esc_html_x('Archives: ', 'Archive title label.', 'essential-content-types'),
273 post_type_archive_title('', false)
274 )
275 );
276 }
277 }
278
279 function ect_get_archive_post_type() // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- ect_ is the established short prefix.
280 {
281
282 global $wp_query;
283 $post_type = isset($wp_query->query['post_type']) ? $wp_query->query['post_type'] : '';
284
285 $type = array(
286 'featured-content' => 'featured_content_title',
287 'jetpack-portfolio' => 'jetpack_portfolio_title',
288 'jetpack-testimonial' => 'jetpack_testimonial_title',
289 'ect-service' => 'ect_service_title',
290 );
291
292 if (isset($type[$post_type])) {
293 return $type[$post_type];
294 }
295 }
296