| 1 |
<?php |
| 2 |
function ova_elems_shortcode_handler($atts) { |
| 3 |
$atts = shortcode_atts(array( |
| 4 |
'id' => '', |
| 5 |
), $atts, 'ova_elems'); |
| 6 |
|
| 7 |
// Validate the ID |
| 8 |
$post_id = intval($atts['id']); |
| 9 |
if (!$post_id) { |
| 10 |
return 'Invalid Slider ID.'; |
| 11 |
} |
| 12 |
|
| 13 |
$post = get_post($post_id); |
| 14 |
if (!$post || $post->post_type != 'ova_elems') { |
| 15 |
return 'Slider not found.'; |
| 16 |
} |
| 17 |
|
| 18 |
$is_premium_user = get_option('ovation_slider_is_premium', false); |
| 19 |
|
| 20 |
$is_free = false; |
| 21 |
if ($is_premium_user) { |
| 22 |
$is_free = true; |
| 23 |
} else { |
| 24 |
$args = array( |
| 25 |
'post_type' => 'ova_elems', |
| 26 |
'post_status' => 'publish', |
| 27 |
'posts_per_page' => -1, |
| 28 |
'orderby' => 'date', |
| 29 |
'order' => 'ASC', |
| 30 |
); |
| 31 |
$existing_sliders = get_posts($args); |
| 32 |
$free_sliders = array_slice($existing_sliders, 0, 100000); |
| 33 |
|
| 34 |
foreach ($free_sliders as $free_slider) { |
| 35 |
if ($free_slider->ID == $post_id) { |
| 36 |
$is_free = true; |
| 37 |
break; |
| 38 |
} |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
if (!$is_free) { |
| 43 |
return '<p>' . esc_html__('This slider is locked. Upgrade to Pro to use it.', 'ovation-elements') . '</p>'; |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
//end |
| 48 |
|
| 49 |
$slides = get_post_meta($post_id, '_ova_elems_slides', true); |
| 50 |
$slides = $slides ? maybe_unserialize($slides) : array(); |
| 51 |
$template_id = get_post_meta($post_id, '_ova_elems_template_id', true); |
| 52 |
$static_settings = get_post_meta($post_id, '_ova_elems_static_settings', true); |
| 53 |
$static_settings = $static_settings ? maybe_unserialize($static_settings) : array(); |
| 54 |
$corner_images = isset($static_settings['corner_images']) ? $static_settings['corner_images'] : array(); |
| 55 |
|
| 56 |
ob_start(); |
| 57 |
$template_id = intval(get_post_meta($post_id, '_ova_elems_template_id', true)); |
| 58 |
|
| 59 |
if ($template_id) { |
| 60 |
add_static_settings_template($template_id); |
| 61 |
include plugin_dir_path(__FILE__) . "slider-shortcode-template{$template_id}.php"; |
| 62 |
} else { |
| 63 |
return 'Template not found.'; |
| 64 |
} |
| 65 |
return ob_get_clean(); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
//for css |
| 70 |
function add_static_settings_template($template_id) { |
| 71 |
global $wpdb; |
| 72 |
|
| 73 |
$meta_key = '_ova_elems_static_settings'; |
| 74 |
if ($template_id == 4 || $template_id == 7) { |
| 75 |
$meta_key = '_ova_elems_static_settings_template4'; |
| 76 |
} |
| 77 |
$template_meta_key = '_ova_elems_template_id'; |
| 78 |
// $default_font_size = 18; |
| 79 |
$default_font_size = 'initial'; |
| 80 |
$post_id = $wpdb->get_var( |
| 81 |
$wpdb->prepare( |
| 82 |
"SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = %s AND meta_value = %d", |
| 83 |
$template_meta_key, |
| 84 |
$template_id |
| 85 |
) |
| 86 |
); |
| 87 |
|
| 88 |
if ($post_id) { |
| 89 |
$static_settings = get_post_meta($post_id, $meta_key, true); |
| 90 |
$static_settings = $static_settings ? maybe_unserialize($static_settings) : []; |
| 91 |
|
| 92 |
$ov_mini_title_font_size = isset($static_settings['ov_mini_title_font_size']) ? intval($static_settings['ov_mini_title_font_size']) : $default_font_size; |
| 93 |
$mini_description_font_size = isset($static_settings['mini_description_font_size']) ? intval($static_settings['mini_description_font_size']) : $default_font_size; |
| 94 |
|
| 95 |
$social_icon_active_color = isset($static_settings['social_icon_active_color']) ? esc_attr($static_settings['social_icon_active_color']) : ''; |
| 96 |
$social_icon_hover_color = isset($static_settings['social_icon_hover_color']) ? esc_attr($static_settings['social_icon_hover_color']) : ''; |
| 97 |
$social_icon_size = isset($static_settings['social_icon_size']) ? intval($static_settings['social_icon_size']) : ''; |
| 98 |
$custom_css = isset($static_settings['custom_css']) ? sanitize_text_field($static_settings['custom_css']) : ''; |
| 99 |
|
| 100 |
$slide_email_font_size = isset($static_settings['slide_email_font_size']) ? intval($static_settings['slide_email_font_size']) : $default_font_size; |
| 101 |
$slide_no_font_size = isset($static_settings['slide_no_font_size']) ? intval($static_settings['slide_no_font_size']) : $default_font_size; |
| 102 |
|
| 103 |
|
| 104 |
$list_title_font_size = isset($static_settings['list_title_font_size']) ? intval($static_settings['list_title_font_size']) : 'initial'; |
| 105 |
$list_description_font_size = isset($static_settings['list_description_font_size']) ? intval($static_settings['list_description_font_size']) : 'initial'; |
| 106 |
$list_content_font_size = isset($static_settings['list_content_font_size']) ? intval($static_settings['list_content_font_size']) : 'initial'; |
| 107 |
$review_text_font_size = isset($static_settings['review_text_font_size']) ? intval($static_settings['review_text_font_size']) : $default_font_size; |
| 108 |
$review_no_font_size = isset($static_settings['review_no_font_size']) ? intval($static_settings['review_no_font_size']) : $default_font_size; |
| 109 |
|
| 110 |
$static_button_text_font_size = isset($static_settings['static_button_text_font_size']) ? intval($static_settings['static_button_text_font_size']) : $default_font_size; |
| 111 |
$title_head_font_size = isset($static_settings['title_head_font_size']) ? intval($static_settings['title_head_font_size']) : $default_font_size; |
| 112 |
|
| 113 |
//7 slider |
| 114 |
$ov_mini_title_right_font_size = isset($static_settings['ov_mini_title_right_font_size']) ? intval($static_settings['ov_mini_title_right_font_size']) : '14'; |
| 115 |
$ov_mini_description_font_size = isset($static_settings['ov_mini_description_font_size']) ? intval($static_settings['ov_mini_description_font_size']) : $default_font_size; |
| 116 |
$thmhead_font_size = isset($static_settings['thmhead_font_size']) ? intval($static_settings['thmhead_font_size']) : $default_font_size; |
| 117 |
$thmbtitle_font_size = isset($static_settings['thmbtitle_font_size']) ? intval($static_settings['thmbtitle_font_size']) : $default_font_size; |
| 118 |
$thmbdesc_font_size = isset($static_settings['thmbdesc_font_size']) ? intval($static_settings['thmbdesc_font_size']) : $default_font_size; |
| 119 |
|
| 120 |
|
| 121 |
$oe_left_side_title_font_size = isset($static_settings['oe_left_side_title_font_size']) ? intval($static_settings['oe_left_side_title_font_size']) : $default_font_size; |
| 122 |
$oe_button_font_size = isset($static_settings['oe_button_font_size']) ? intval($static_settings['oe_button_font_size']) : $default_font_size; |
| 123 |
|
| 124 |
//new |
| 125 |
$ov_review_text_font_size = isset($static_settings['ov_review_text_font_size']) ? intval($static_settings['ov_review_text_font_size']) : $default_font_size; |
| 126 |
$ov_social_text_font_size = isset($static_settings['ov_social_text_font_size']) ? intval($static_settings['ov_social_text_font_size']) : $default_font_size; |
| 127 |
|
| 128 |
$live_mini_text_font_size = isset($static_settings['live_mini_text_font_size']) ? intval($static_settings['live_mini_text_font_size']) : $default_font_size; |
| 129 |
$live_title_font_size = isset($static_settings['live_title_font_size']) ? intval($static_settings['live_title_font_size']) : $default_font_size; |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
$inline_css = " |
| 134 |
.oe-template7-slide-buttons { |
| 135 |
font-size: {$oe_button_font_size}px !important; |
| 136 |
} |
| 137 |
|
| 138 |
.ov-mini-title { |
| 139 |
font-size: {$ov_mini_title_font_size}px !important; |
| 140 |
} |
| 141 |
|
| 142 |
.oe-stat-head { |
| 143 |
font-size: {$ov_mini_title_font_size}px !important; |
| 144 |
} |
| 145 |
.ov-mini-imp { |
| 146 |
font-size: {$ov_mini_title_font_size}px !important; |
| 147 |
} |
| 148 |
|
| 149 |
.ov-mini-thumb-titleimp { |
| 150 |
font-size: {$ov_mini_title_font_size}px !important; |
| 151 |
} |
| 152 |
.ov-mini-description { |
| 153 |
font-size: {$mini_description_font_size}px !important; |
| 154 |
} |
| 155 |
.ov-social-icon { |
| 156 |
background-color: {$social_icon_active_color} !important; |
| 157 |
width: {$social_icon_size}px; |
| 158 |
height: {$social_icon_size}px; |
| 159 |
line-height: {$social_icon_size}px; |
| 160 |
} |
| 161 |
|
| 162 |
.ov-social-icon:hover { |
| 163 |
background-color: {$social_icon_hover_color} !important; |
| 164 |
} |
| 165 |
|
| 166 |
.set-offer-font { |
| 167 |
font-size: {$title_head_font_size}px !important; |
| 168 |
} |
| 169 |
|
| 170 |
.ov-right-news-tittle { |
| 171 |
font-size: {$oe_left_side_title_font_size}px !important; |
| 172 |
} |
| 173 |
|
| 174 |
.ov-social-news { |
| 175 |
font-size: {$ov_social_text_font_size}px !important; |
| 176 |
} |
| 177 |
|
| 178 |
.slide-list { |
| 179 |
font-size: {$list_title_font_size}px !important; |
| 180 |
} |
| 181 |
.slide-tittle { |
| 182 |
font-size: {$list_title_font_size}px !important; |
| 183 |
} |
| 184 |
.slide-desc { |
| 185 |
font-size: {$list_description_font_size}px !important; |
| 186 |
} |
| 187 |
.slide-list-content { |
| 188 |
font-size: {$list_content_font_size}px !important; |
| 189 |
} |
| 190 |
.slide-content { |
| 191 |
font-size: {$list_content_font_size}px !important; |
| 192 |
} |
| 193 |
.review-text-font { |
| 194 |
font-size: {$review_text_font_size}px !important; |
| 195 |
} |
| 196 |
.review-font { |
| 197 |
font-size: {$review_no_font_size}px !important; |
| 198 |
} |
| 199 |
.statichead-text-font { |
| 200 |
font-size: {$static_button_text_font_size}px !important; |
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
.staticbutton-text-font { |
| 206 |
font-size: {$title_head_font_size}px !important; |
| 207 |
} |
| 208 |
|
| 209 |
.ov-right-side-tittle { |
| 210 |
font-size: {$ov_mini_title_right_font_size}px !important; |
| 211 |
} |
| 212 |
.ov-right-side-desc { |
| 213 |
font-size: {$ov_mini_description_font_size }px !important; |
| 214 |
} |
| 215 |
|
| 216 |
.ov-thmb-head { |
| 217 |
font-size: {$thmhead_font_size }px !important; |
| 218 |
} |
| 219 |
.ov-thmb-tittle { |
| 220 |
font-size: {$thmbtitle_font_size}px !important; |
| 221 |
} |
| 222 |
.ov-thmb-desc { |
| 223 |
font-size: {$thmbdesc_font_size}px !important; |
| 224 |
} |
| 225 |
|
| 226 |
.ov_review_text_font_size { |
| 227 |
font-size: {$ov_review_text_font_size}px !important; |
| 228 |
} |
| 229 |
|
| 230 |
.ov_social-template8 { |
| 231 |
font-size: {$review_text_font_size}px !important; |
| 232 |
} |
| 233 |
|
| 234 |
.ov_social_text_font_size { |
| 235 |
font-size: {$ov_social_text_font_size}px !important; |
| 236 |
} |
| 237 |
|
| 238 |
.live_mini_text_font_size { |
| 239 |
font-size: {$live_mini_text_font_size}px !important; |
| 240 |
} |
| 241 |
|
| 242 |
.live_title_font_size { |
| 243 |
font-size: {$live_title_font_size}px !important; |
| 244 |
} |
| 245 |
"; |
| 246 |
|
| 247 |
if (!empty($custom_css)) { |
| 248 |
$inline_css .= "\n" . $custom_css; |
| 249 |
} |
| 250 |
|
| 251 |
// Add template-specific CSS |
| 252 |
wp_enqueue_style("ova-elems-style{$template_id}", OVA_ELEMS_URL . "assets/css/style{$template_id}.css", array(), OVA_ELEMS_VER); |
| 253 |
wp_add_inline_style("ova-elems-style{$template_id}", $inline_css); |
| 254 |
} |
| 255 |
|
| 256 |
// i change meta key for slides data _ova_elems_static_settings |
| 257 |
$meta_key_static = '_ova_elems_static_settings'; |
| 258 |
$meta_key_slides = '_ova_elems_slides'; |
| 259 |
|
| 260 |
$post_ids = $wpdb->get_col( |
| 261 |
$wpdb->prepare("SELECT DISTINCT post_id FROM {$wpdb->postmeta} WHERE meta_key = %s", $meta_key_static) |
| 262 |
); |
| 263 |
|
| 264 |
foreach ($post_ids as $post_id) { |
| 265 |
$static_settings = get_post_meta($post_id, $meta_key_static, true); |
| 266 |
$static_settings = $static_settings ? maybe_unserialize($static_settings) : []; |
| 267 |
$slides = get_post_meta($post_id, $meta_key_slides, true); |
| 268 |
$slides = $slides ? maybe_unserialize($slides) : []; |
| 269 |
|
| 270 |
$inline_css = ''; |
| 271 |
|
| 272 |
foreach ($slides as $index => $slide) { |
| 273 |
$bg_color = !empty($slide['slide_bg_color']) ? esc_attr($slide['slide_bg_color']) : '#2d4373'; // Default bg color |
| 274 |
|
| 275 |
// Add background color CSS rule |
| 276 |
$inline_css .= ".slider-main-image-{$post_id}-{$index} { background-color: {$bg_color}; }\n"; |
| 277 |
|
| 278 |
// Add other slide settings like font size, button colors using static settings |
| 279 |
if (!empty($static_settings)) { |
| 280 |
$banner_font_size = isset($static_settings['banner_font_size']) ? intval($static_settings['banner_font_size']) : $default_font_size; |
| 281 |
$button_font_size = isset($static_settings['button_font_size']) ? intval($static_settings['button_font_size']) : $default_font_size; |
| 282 |
$heading_font_size = isset($static_settings['heading_font_size']) ? intval($static_settings['heading_font_size']) : $default_font_size; |
| 283 |
$head_font_size = isset($static_settings['head_font_size']) ? intval($static_settings['head_font_size']) : $default_font_size; |
| 284 |
$button_bg_color = isset($static_settings['button_bg_color']) ? esc_attr($static_settings['button_bg_color']) : ''; |
| 285 |
$button_hover_bg_color = isset($static_settings['button_hover_bg_color']) ? esc_attr($static_settings['button_hover_bg_color']) : ''; |
| 286 |
$button_text_color = isset($static_settings['button_text_color']) ? esc_attr($static_settings['button_text_color']) : ''; |
| 287 |
$button_hover_text_color = isset($static_settings['button_hover_text_color']) ? esc_attr($static_settings['button_hover_text_color']) : ''; |
| 288 |
|
| 289 |
// Add additional CSS rules |
| 290 |
$inline_css .= " |
| 291 |
.description-{$post_id} { |
| 292 |
font-size: {$banner_font_size}px !important; |
| 293 |
} |
| 294 |
.slider-btn-{$post_id} { |
| 295 |
font-size: {$button_font_size}px !important; |
| 296 |
} |
| 297 |
.title-{$post_id} { |
| 298 |
font-size: {$heading_font_size}px !important; |
| 299 |
} |
| 300 |
.ovheadtag-{$post_id} { |
| 301 |
font-size: {$head_font_size}px !important; |
| 302 |
} |
| 303 |
|
| 304 |
.ov-btn-{$post_id} { |
| 305 |
background-color: {$button_bg_color} !important; |
| 306 |
} |
| 307 |
.ov-btn-{$post_id}:hover { |
| 308 |
background-color: {$button_hover_bg_color} !important; |
| 309 |
} |
| 310 |
"; |
| 311 |
} |
| 312 |
} |
| 313 |
|
| 314 |
// Enqueue the styles for the template |
| 315 |
wp_enqueue_style("ova-elems-style{$template_id}", OVA_ELEMS_URL . "assets/css/style{$template_id}.css", array(), OVA_ELEMS_VER); |
| 316 |
wp_add_inline_style("ova-elems-style{$template_id}", $inline_css); |
| 317 |
} |
| 318 |
} |
| 319 |
|
| 320 |
// add_action('wp_enqueue_scripts', function () use ($template_id) { |
| 321 |
// add_static_settings_template($template_id); |
| 322 |
// }); |
| 323 |
// add_action('wp_head', function () use ($template_id) { |
| 324 |
// add_static_settings_template($template_id); |
| 325 |
// }, 20); |
| 326 |
|