| 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.2.3 |
| 20 |
* Author: Catch Plugins |
| 21 |
* Author URI: https://catchplugins.com |
| 22 |
* License: GPL-3.0+ |
| 23 |
* License URI: http://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 |
define( 'ESSENTIAL_CONTENT_TYPES_VERSION', '2.2.3' ); |
| 35 |
|
| 36 |
/** |
| 37 |
* The code that runs during plugin activation. |
| 38 |
* This action is documented in includes/class-essential-content-types-activator.php |
| 39 |
*/ |
| 40 |
// The URL of the directory that contains the plugin |
| 41 |
if ( ! defined( 'ESSENTIAL_CONTENT_TYPES_URL' ) ) { |
| 42 |
define( 'ESSENTIAL_CONTENT_TYPES_URL', plugin_dir_url( __FILE__ ) ); |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
// The absolute path of the directory that contains the file |
| 47 |
if ( ! defined( 'ESSENTIAL_CONTENT_TYPES_PATH' ) ) { |
| 48 |
define( 'ESSENTIAL_CONTENT_TYPES_PATH', plugin_dir_path( __FILE__ ) ); |
| 49 |
} |
| 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 activate_essential_content_types() { |
| 62 |
$required = 'essential-content-types-pro/essential-content-types-pro.php'; |
| 63 |
if ( is_plugin_active( $required ) ) { |
| 64 |
$message = esc_html__( 'Sorry, Pro plugin is already active. No need to activate Free version. %1$s« Return to Plugins%2$s.', 'essential-content-types' ); |
| 65 |
$message = sprintf( $message, '<br><a href="' . esc_url( admin_url( 'plugins.php' ) ) . '">', '</a>' ); |
| 66 |
wp_die( $message ); |
| 67 |
} |
| 68 |
require_once plugin_dir_path( __FILE__ ) . 'includes/class-essential-content-types-activator.php'; |
| 69 |
Essential_Content_Types_Activator::activate(); |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* The code that runs during plugin deactivation. |
| 74 |
* This action is documented in includes/class-essential-content-types-deactivator.php |
| 75 |
*/ |
| 76 |
function deactivate_essential_content_types() { |
| 77 |
require_once plugin_dir_path( __FILE__ ) . 'includes/class-essential-content-types-deactivator.php'; |
| 78 |
Essential_Content_Types_Deactivator::deactivate(); |
| 79 |
} |
| 80 |
|
| 81 |
register_activation_hook( __FILE__, 'activate_essential_content_types' ); |
| 82 |
register_deactivation_hook( __FILE__, 'deactivate_essential_content_types' ); |
| 83 |
|
| 84 |
/** |
| 85 |
* The core plugin class that is used to define internationalization, |
| 86 |
* admin-specific hooks, and public-facing site hooks. |
| 87 |
*/ |
| 88 |
require plugin_dir_path( __FILE__ ) . 'includes/class-essential-content-types.php'; |
| 89 |
|
| 90 |
/** |
| 91 |
* Begins execution of the plugin. |
| 92 |
* |
| 93 |
* Since everything within the plugin is registered via hooks, |
| 94 |
* then kicking off the plugin from this point in the file does |
| 95 |
* not affect the page life cycle. |
| 96 |
* |
| 97 |
* @since 1.0.0 |
| 98 |
*/ |
| 99 |
function run_essential_content_types() { |
| 100 |
|
| 101 |
$plugin = new Essential_Content_Types(); |
| 102 |
$plugin->run(); |
| 103 |
|
| 104 |
} |
| 105 |
run_essential_content_types(); |
| 106 |
|
| 107 |
|
| 108 |
if ( ! function_exists( 'ect_get_layout' ) ) : |
| 109 |
function ect_get_layout() { |
| 110 |
$layout = array( |
| 111 |
'1' => 'layout-one', |
| 112 |
'2' => 'layout-two', |
| 113 |
'3' => 'layout-three', |
| 114 |
'4' => 'layout-four', |
| 115 |
'5' => 'layout-five', |
| 116 |
'6' => 'layout-six', |
| 117 |
); |
| 118 |
return $layout; |
| 119 |
} |
| 120 |
endif; |
| 121 |
|
| 122 |
|
| 123 |
if ( ! function_exists( 'ect_plugin_path' ) ) : |
| 124 |
/** |
| 125 |
* Get the plugin path. |
| 126 |
* |
| 127 |
* @return string |
| 128 |
*/ |
| 129 |
function ect_plugin_path() { |
| 130 |
return untrailingslashit( plugin_dir_path( __FILE__ ) ); |
| 131 |
} |
| 132 |
endif; |
| 133 |
|
| 134 |
|
| 135 |
if ( ! function_exists( 'ect_template_path' ) ) : |
| 136 |
/** |
| 137 |
* Get the template path. |
| 138 |
* |
| 139 |
* @return string |
| 140 |
*/ |
| 141 |
function ect_template_path() { |
| 142 |
return apply_filters( 'ect_template_path', 'ect-templates/' ); |
| 143 |
} |
| 144 |
endif; |
| 145 |
|
| 146 |
|
| 147 |
if ( ! function_exists( 'ect_get_template_part' ) ) : |
| 148 |
/** |
| 149 |
* Get template part (for templates like the shop-loop). |
| 150 |
* |
| 151 |
* |
| 152 |
* @access public |
| 153 |
* @param mixed $slug Template slug. |
| 154 |
* @param string $name Template name (default: ''). |
| 155 |
* @param array $atts Options to pass into template. |
| 156 |
*/ |
| 157 |
function ect_get_template_part( $slug, $name = '', $atts = '' ) { |
| 158 |
|
| 159 |
$template = ''; |
| 160 |
set_query_var( 'atts', $atts ); |
| 161 |
|
| 162 |
// Look in yourtheme/slug-name.php and yourtheme/ect-templates/slug-name.php. |
| 163 |
if ( $name ) { |
| 164 |
$template = locate_template( array( "{$slug}-{$name}.php", ect_template_path() . "{$slug}-{$name}.php" ) ); |
| 165 |
} |
| 166 |
|
| 167 |
// Get default slug-name.php. |
| 168 |
if ( empty( $template ) && $name && file_exists( ect_plugin_path() . '/' . ect_template_path() . "{$slug}-{$name}.php" ) ) { |
| 169 |
$template = ect_plugin_path() . '/' . ect_template_path() . "{$slug}-{$name}.php"; |
| 170 |
} |
| 171 |
|
| 172 |
// If template file doesn't exist, look in yourtheme/slug.php and yourtheme/ect-templates/slug.php. |
| 173 |
if ( ! $template ) { |
| 174 |
$template = locate_template( array( "{$slug}.php", ect_template_path() . "{$slug}.php" ) ); |
| 175 |
} |
| 176 |
|
| 177 |
// Allow 3rd party plugins to filter template file from their plugin. |
| 178 |
$template = apply_filters( 'ect_get_template_part', $template, $slug, $name ); |
| 179 |
|
| 180 |
if ( $template ) { |
| 181 |
load_template( $template, false, 'atts' ); |
| 182 |
} |
| 183 |
} |
| 184 |
endif; |
| 185 |
|
| 186 |
function ect_body_classes( $classes ) { |
| 187 |
if( 'featured-content' == get_post_type() || 'ect-service' == get_post_type() || 'jetpack-portfolio' == get_post_type() || 'jetpack-testimonial' == get_post_type() ) { |
| 188 |
$classes[] = 'ect-post'; |
| 189 |
} |
| 190 |
|
| 191 |
return $classes; |
| 192 |
} |
| 193 |
add_filter( 'body_class', 'ect_body_classes' ); |
| 194 |
/* CTP tabs removal options */ |
| 195 |
require plugin_dir_path( __FILE__ ) . '/includes/ctp-tabs-removal.php'; |
| 196 |
|
| 197 |
$ctp_options = ctp_get_options(); |
| 198 |
if ( 1 == $ctp_options['theme_plugin_tabs'] ) { |
| 199 |
/* Adds Catch Themes tab in Add theme page and Themes by Catch Themes in Customizer's change theme option. */ |
| 200 |
if ( ! class_exists( 'CatchThemesThemePlugin' ) && ! function_exists( 'add_our_plugins_tab' ) ) { |
| 201 |
require plugin_dir_path( __FILE__ ) . '/includes/CatchThemesThemePlugin.php'; |
| 202 |
} |
| 203 |
} |
| 204 |
|
| 205 |
/* Modify ECT Post type archive title for default values */ |
| 206 |
function ect_check_archive_title() { |
| 207 |
global $wp_query; |
| 208 |
$post_type = false; |
| 209 |
if ( isset( $wp_query->query['post_type'] ) ) { |
| 210 |
$post_type = $wp_query->query['post_type']; |
| 211 |
} |
| 212 |
|
| 213 |
$ect_post_types = array( |
| 214 |
'featured-content', |
| 215 |
'jetpack-portfolio', |
| 216 |
'jetpack-testimonial', |
| 217 |
'ect-service', |
| 218 |
); |
| 219 |
|
| 220 |
if ( $post_type !== false || in_array( $post_type, $ect_post_types, true ) ) { |
| 221 |
add_filter( 'get_the_archive_title', 'ect_modify_archive_title', 10, 1 ); |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
add_action( 'wp_head', 'ect_check_archive_title' ); |
| 226 |
|
| 227 |
/* set default title if options not found */ |
| 228 |
function ect_modify_archive_title( $title ) { |
| 229 |
$title_label = '<span class="some-class">%1$s</span>%2$s'; |
| 230 |
$type = ect_get_archive_post_type(); |
| 231 |
|
| 232 |
if ( ! $type ) { |
| 233 |
// Bail if type is not from ECT. |
| 234 |
return; |
| 235 |
} |
| 236 |
|
| 237 |
$default_title = array( |
| 238 |
'ect_service_title' => esc_html( 'Services', 'essential-content-types' ), |
| 239 |
'jetpack_testimonial_title' => esc_html( 'Testimonial', 'essential-content-types' ), |
| 240 |
'jetpack_portfolio_title' => esc_html( 'Portfolio', 'essential-content-types' ), |
| 241 |
'featured_content_title' => esc_html( 'Featured Content', 'essential-content-types' ), |
| 242 |
); |
| 243 |
|
| 244 |
$archive_title = get_option( $type, $default_title[ $type ] ); |
| 245 |
|
| 246 |
if ( '' !== $archive_title ) { |
| 247 |
return trim( |
| 248 |
sprintf( |
| 249 |
$title_label, |
| 250 |
esc_html_x( 'Archives: ', 'Archive title label.', 'archive-title' ), |
| 251 |
$archive_title |
| 252 |
) |
| 253 |
); |
| 254 |
} else { |
| 255 |
return trim( |
| 256 |
sprintf( |
| 257 |
$title_label, |
| 258 |
esc_html_x( 'Archives: ', 'Archive title label.', 'archive-title' ), |
| 259 |
post_type_archive_title( '', false ) |
| 260 |
) |
| 261 |
); |
| 262 |
} |
| 263 |
|
| 264 |
} |
| 265 |
|
| 266 |
function ect_get_archive_post_type() { |
| 267 |
|
| 268 |
global $wp_query; |
| 269 |
if ( isset( $wp_query->query['post_type'] ) ) { |
| 270 |
$post_type = $wp_query->query['post_type']; |
| 271 |
} |
| 272 |
|
| 273 |
$type = array( |
| 274 |
'featured-content' => 'featured_content_title', |
| 275 |
'jetpack-portfolio' => 'jetpack_portfolio_title', |
| 276 |
'jetpack-testimonial' => 'jetpack_testimonial_title', |
| 277 |
'ect-service' => 'ect_service_title', |
| 278 |
); |
| 279 |
|
| 280 |
if ( isset( $type[ $post_type ]) ) { |
| 281 |
return $type[ $post_type ]; |
| 282 |
} |
| 283 |
} |
| 284 |
|