| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) { |
| 3 |
exit; // Exit if accessed directly. |
| 4 |
} |
| 5 |
|
| 6 |
// Register Post Type |
| 7 |
function ova_elems_post_type() |
| 8 |
{ |
| 9 |
$labels = array( |
| 10 |
'name' => 'Sliders', |
| 11 |
'singular_name' => 'Slider', |
| 12 |
'menu_name' => 'Sliders', |
| 13 |
'name_admin_bar' => 'Slider', |
| 14 |
'add_new' => 'Add New', |
| 15 |
'add_new_item' => 'Add New Slider', |
| 16 |
'new_item' => 'New Slider', |
| 17 |
'edit_item' => 'Edit Slider', |
| 18 |
'view_item' => 'View Slider', |
| 19 |
'all_items' => 'All Sliders', |
| 20 |
'search_items' => 'Search Sliders', |
| 21 |
'not_found' => 'No sliders found.', |
| 22 |
'not_found_in_trash' => 'No sliders found in Trash.', |
| 23 |
); |
| 24 |
$args = array( |
| 25 |
'labels' => $labels, |
| 26 |
'public' => true, |
| 27 |
'publicly_queryable' => true, |
| 28 |
'show_ui' => true, |
| 29 |
'show_in_rest' => true, |
| 30 |
'show_in_menu' => false, |
| 31 |
'query_var' => true, |
| 32 |
'rewrite' => array('slug' => 'ova_elems'), |
| 33 |
'capability_type' => 'post', |
| 34 |
'has_archive' => true, |
| 35 |
'hierarchical' => false, |
| 36 |
'supports' => array('title', 'editor'), // Only title and editor are used |
| 37 |
); |
| 38 |
register_post_type('ova_elems', $args); |
| 39 |
} |
| 40 |
add_action('init', 'ova_elems_post_type'); |
| 41 |
|
| 42 |
// Add Meta Box |
| 43 |
function ova_elems_add_meta_boxes() |
| 44 |
{ |
| 45 |
add_meta_box( |
| 46 |
'ova_elems_settings', |
| 47 |
'Slider Settings', |
| 48 |
'ova_elems_meta_box_callback', |
| 49 |
'ova_elems', |
| 50 |
'normal', |
| 51 |
'high' |
| 52 |
); |
| 53 |
} |
| 54 |
add_action('add_meta_boxes', 'ova_elems_add_meta_boxes'); |
| 55 |
|
| 56 |
|
| 57 |
// Add Edit Template Page |
| 58 |
function ova_elems_add_edit_page() |
| 59 |
{ |
| 60 |
add_submenu_page( |
| 61 |
'', |
| 62 |
'Edit Slider Template', |
| 63 |
'Edit Slider Template', |
| 64 |
'manage_options', |
| 65 |
'edit_slider_template', |
| 66 |
'ova_elems_edit_slider_template_page' |
| 67 |
); |
| 68 |
} |
| 69 |
add_action('admin_menu', 'ova_elems_add_edit_page'); |
| 70 |
|
| 71 |
|
| 72 |
//i add |
| 73 |
// Redirect to Select Template Page for Add New |
| 74 |
|
| 75 |
function ova_elems_redirect_add_new() |
| 76 |
{ |
| 77 |
global $pagenow; |
| 78 |
if ($pagenow == 'post-new.php' && isset($_GET['post_type']) && $_GET['post_type'] == 'ova_elems') { |
| 79 |
wp_redirect(admin_url('admin.php?page=select-template')); |
| 80 |
exit; |
| 81 |
} |
| 82 |
} |
| 83 |
add_action('admin_init', 'ova_elems_redirect_add_new'); |
| 84 |
|
| 85 |
// added new menue |
| 86 |
|
| 87 |
function ova_elems_slider_add_menu_pages() |
| 88 |
{ |
| 89 |
|
| 90 |
add_menu_page( |
| 91 |
'Ovation Elements', |
| 92 |
'OT Elements', |
| 93 |
'manage_options', |
| 94 |
'ovation_elements', |
| 95 |
'ova_elems_slider_dashboard_page', // Dashboard callback function |
| 96 |
'dashicons-admin-multisite', |
| 97 |
6 // Position in the menu |
| 98 |
); |
| 99 |
add_submenu_page( |
| 100 |
'ovation_elements', |
| 101 |
'Slider Templates', |
| 102 |
'Slider Templates', |
| 103 |
'manage_options', |
| 104 |
'select-template', |
| 105 |
'ova_elems_slider_select_template_page' |
| 106 |
); |
| 107 |
|
| 108 |
|
| 109 |
add_submenu_page( |
| 110 |
'ovation_elements', |
| 111 |
'All Sliders', |
| 112 |
'All Sliders', |
| 113 |
'manage_options', |
| 114 |
'edit.php?post_type=ova_elems', |
| 115 |
'' |
| 116 |
); |
| 117 |
|
| 118 |
|
| 119 |
// Check if the premium plugin is activated |
| 120 |
if (is_plugin_active('ovation-elements-pro/ovation-elements-pro.php')) { |
| 121 |
add_submenu_page( |
| 122 |
'ovation_elements', |
| 123 |
'License Key', |
| 124 |
'License Key', |
| 125 |
'manage_options', |
| 126 |
'license-key', |
| 127 |
'ova_elems_license_key_page' |
| 128 |
); |
| 129 |
} else { |
| 130 |
add_submenu_page( |
| 131 |
'ovation_elements', |
| 132 |
'Go Pro', |
| 133 |
'Go Pro', |
| 134 |
'manage_options', |
| 135 |
'ovation_elements', |
| 136 |
'' |
| 137 |
); |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
add_submenu_page( |
| 142 |
'edit.php?post_type=ova_elems', |
| 143 |
'Select Template', |
| 144 |
'Select Template', |
| 145 |
'manage_options', |
| 146 |
'select-template', |
| 147 |
'ova_elems_slider_select_template_page' |
| 148 |
); |
| 149 |
|
| 150 |
// Add different edit pages for each template |
| 151 |
add_submenu_page( |
| 152 |
'slider-templates', |
| 153 |
'Edit Slider Template 1', |
| 154 |
'Edit Slider Template 1', |
| 155 |
'manage_options', |
| 156 |
'edit-slider-template-template1', |
| 157 |
'ova_elems_edit_page_template1' |
| 158 |
); |
| 159 |
|
| 160 |
add_submenu_page( |
| 161 |
'slider-templates', |
| 162 |
'Edit Slider Template 2', |
| 163 |
'Edit Slider Template 2', |
| 164 |
'manage_options', |
| 165 |
'edit-slider-template-template2', |
| 166 |
'ova_elems_edit_page_template2' |
| 167 |
); |
| 168 |
|
| 169 |
add_submenu_page( |
| 170 |
'slider-templates', |
| 171 |
'Edit Slider Template 3', |
| 172 |
'Edit Slider Template 3', |
| 173 |
'manage_options', |
| 174 |
'edit-slider-template-template3', |
| 175 |
'ova_elems_edit_page_template3' |
| 176 |
); |
| 177 |
|
| 178 |
add_submenu_page( |
| 179 |
'slider-templates', |
| 180 |
'Edit Slider Template 4', |
| 181 |
'Edit Slider Template 4', |
| 182 |
'manage_options', |
| 183 |
'edit-slider-template-template4', |
| 184 |
'ova_elems_edit_page_template4' |
| 185 |
); |
| 186 |
|
| 187 |
add_submenu_page( |
| 188 |
'slider-templates', |
| 189 |
'Edit Slider Template 5', |
| 190 |
'Edit Slider Template 5', |
| 191 |
'manage_options', |
| 192 |
'edit-slider-template-template5', |
| 193 |
'ova_elems_edit_page_template5' |
| 194 |
); |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
add_submenu_page( |
| 199 |
'slider-templates', |
| 200 |
'Edit Slider Template 6', |
| 201 |
'Edit Slider Template 6', |
| 202 |
'manage_options', |
| 203 |
'edit-slider-template-template6', |
| 204 |
'ova_elems_edit_page_template6' |
| 205 |
); |
| 206 |
|
| 207 |
add_submenu_page( |
| 208 |
'slider-templates', |
| 209 |
'Edit Slider Template 7', |
| 210 |
'Edit Slider Template 7', |
| 211 |
'manage_options', |
| 212 |
'edit-slider-template-template7', |
| 213 |
'ova_elems_edit_page_template7' |
| 214 |
); |
| 215 |
|
| 216 |
add_submenu_page( |
| 217 |
'slider-templates', |
| 218 |
'Edit Slider Template 8', |
| 219 |
'Edit Slider Template 8', |
| 220 |
'manage_options', |
| 221 |
'edit-slider-template-template8', |
| 222 |
'ova_elems_edit_page_template8' |
| 223 |
); |
| 224 |
|
| 225 |
|
| 226 |
} |
| 227 |
add_action('admin_menu', 'ova_elems_slider_add_menu_pages'); |
| 228 |
|
| 229 |
|
| 230 |
// hide notice n ads |
| 231 |
function ova_elems_hide_admin_notices() { |
| 232 |
$screen = get_current_screen(); |
| 233 |
$ova_plugin_pages = [ |
| 234 |
'ovation_elements', |
| 235 |
'select-template', |
| 236 |
'edit-slider-template-template1', |
| 237 |
'edit-slider-template-template2', |
| 238 |
'edit-slider-template-template3', |
| 239 |
'edit-slider-template-template4', |
| 240 |
'edit-slider-template-template5', |
| 241 |
'edit-slider-template-template6', |
| 242 |
'edit-slider-template-template7', |
| 243 |
'edit-slider-template-template8', |
| 244 |
]; |
| 245 |
|
| 246 |
foreach ($ova_plugin_pages as $ova_page) { |
| 247 |
if (strpos($screen->id, $ova_page) !== false) { |
| 248 |
remove_all_actions('admin_notices'); |
| 249 |
remove_all_actions('all_admin_notices'); |
| 250 |
break; |
| 251 |
} |
| 252 |
} |
| 253 |
} |
| 254 |
add_action('admin_head', 'ova_elems_hide_admin_notices'); |
| 255 |
|
| 256 |
|
| 257 |
//add for dashboard page |
| 258 |
function ova_elems_slider_dashboard_page() { |
| 259 |
?> |
| 260 |
<div class="outer-container"> |
| 261 |
<div class="ov-plugin-top" id="ov-top"> |
| 262 |
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="227" height="72" |
| 263 |
viewBox="0 0 227 72"> |
| 264 |
<defs> |
| 265 |
<clipPath id="clip-path"> |
| 266 |
<rect id="Rectangle_191" data-name="Rectangle 191" width="61.162" height="59.822" fill="none" /> |
| 267 |
</clipPath> |
| 268 |
</defs> |
| 269 |
<g id="Group_28" data-name="Group 28" transform="translate(-199 -74)"> |
| 270 |
<g id="Group_14" data-name="Group 14" transform="translate(199 82.219)"> |
| 271 |
<g id="Group_13" data-name="Group 13" clip-path="url(#clip-path)"> |
| 272 |
<path id="Path_42" data-name="Path 42" |
| 273 |
d="M120.213,0H105.239a6.554,6.554,0,0,0-6.545,6.548V29.911a6.553,6.553,0,0,0,6.545,6.545H120.19a6.553,6.553,0,0,0,6.545-6.545V8.441Zm1.851,29.911a1.873,1.873,0,0,1-1.873,1.87H105.239a1.871,1.871,0,0,1-1.87-1.87V6.548a1.873,1.873,0,0,1,1.87-1.873h13.626V7.143a1.243,1.243,0,0,0,1.172,1.3h2.026Z" |
| 274 |
transform="translate(-66.652)" fill="#0023c4" /> |
| 275 |
<path id="Path_43" data-name="Path 43" |
| 276 |
d="M14.208,115.5V96.339a4.208,4.208,0,0,1,4.208-4.208h-7.01A4.208,4.208,0,0,0,7.2,96.339V115.5a4.208,4.208,0,0,0,4.208,4.208h7.01a4.208,4.208,0,0,1-4.208-4.208" |
| 277 |
transform="translate(-4.861 -62.22)" fill="#cee1f2" /> |
| 278 |
<path id="Path_44" data-name="Path 44" |
| 279 |
d="M6.545,19.727H21.029c3.609,0,6.545-2.478,6.545-5.525V5.526C27.574,2.479,24.638,0,21.029,0H6.545C2.936,0,0,2.479,0,5.526V14.2c0,3.047,2.936,5.525,6.545,5.525M4.674,5.526a1.747,1.747,0,0,1,1.872-1.58H21.029A1.747,1.747,0,0,1,22.9,5.526V14.2a1.746,1.746,0,0,1-1.872,1.58H6.545A1.746,1.746,0,0,1,4.674,14.2Z" |
| 280 |
transform="translate(0 -0.001)" fill="#0023c4" /> |
| 281 |
<path id="Path_45" data-name="Path 45" |
| 282 |
d="M6.545,117.181H21.029a6.553,6.553,0,0,0,6.545-6.545V91.478a6.553,6.553,0,0,0-6.545-6.545H6.545A6.553,6.553,0,0,0,0,91.478v19.158a6.553,6.553,0,0,0,6.545,6.545m-1.872-25.7a1.874,1.874,0,0,1,1.872-1.872H21.029A1.874,1.874,0,0,1,22.9,91.478v19.158a1.874,1.874,0,0,1-1.872,1.872H6.545a1.874,1.874,0,0,1-1.872-1.872Z" |
| 283 |
transform="translate(0 -57.359)" fill="#0023c4" /> |
| 284 |
<path id="Path_46" data-name="Path 46" |
| 285 |
d="M41.509,69.206a1.868,1.868,0,1,1-1.868-1.868,1.868,1.868,0,0,1,1.868,1.868" |
| 286 |
transform="translate(-25.51 -45.476)" fill="#0023c4" /> |
| 287 |
<circle id="Ellipse_1" data-name="Ellipse 1" cx="1.529" cy="1.529" r="1.529" |
| 288 |
transform="translate(6.21 22.201)" fill="none" stroke="#0023c4" stroke-width="2" /> |
| 289 |
<circle id="Ellipse_2" data-name="Ellipse 2" cx="1.529" cy="1.529" r="1.529" |
| 290 |
transform="translate(18.995 22.201)" fill="none" stroke="#0023c4" stroke-width="2" /> |
| 291 |
<path id="Path_47" data-name="Path 47" |
| 292 |
d="M121.567,142.655a1.826,1.826,0,0,0-1.946,1.676v.876a2.01,2.01,0,0,1-1.825,2.152H101.579a2.01,2.01,0,0,1-1.825-2.152v-5.1a2.011,2.011,0,0,1,1.825-2.155h4.352a1.694,1.694,0,1,0,0-3.351H100.5c-2.669,0-4.834,2.56-4.834,5.719v4.676c0,3.158,2.165,5.718,4.834,5.718h18.373c2.669,0,4.834-2.56,4.834-5.718v-.661a1.826,1.826,0,0,0-1.946-1.676Z" |
| 293 |
transform="translate(-64.608 -90.899)" fill="#ff5cf4" /> |
| 294 |
<path id="Path_48" data-name="Path 48" |
| 295 |
d="M154.746,122.715l-5.808-6.031a.67.67,0,0,0-1.152.465v2.9h-.223a8.721,8.721,0,0,0-8.711,8.711v1.34a.661.661,0,0,0,.522.641.585.585,0,0,0,.147.018.693.693,0,0,0,.612-.381,7.328,7.328,0,0,1,6.592-4.074h1.062v2.9a.67.67,0,0,0,1.152.465l5.808-6.031a.671.671,0,0,0,0-.93" |
| 296 |
transform="translate(-93.772 -78.663)" fill="#ff5cf4" /> |
| 297 |
<path id="Path_49" data-name="Path 49" |
| 298 |
d="M63.3,27.955l.755-.755-.755-.755a.12.12,0,0,1,.17-.17l.84.84a.12.12,0,0,1,0,.17l-.84.84a.12.12,0,0,1-.17-.17" |
| 299 |
transform="translate(-42.724 -17.721)" fill="#ff5cf4" /> |
| 300 |
<path id="Path_50" data-name="Path 50" |
| 301 |
d="M63.3,27.955l.755-.755-.755-.755a.12.12,0,0,1,.17-.17l.84.84a.12.12,0,0,1,0,.17l-.84.84a.12.12,0,0,1-.17-.17Z" |
| 302 |
transform="translate(-42.724 -17.721)" fill="none" stroke="#ff5cf4" stroke-width="1" /> |
| 303 |
<path id="Path_51" data-name="Path 51" |
| 304 |
d="M17.964,27.955a.12.12,0,0,1-.17.17l-.84-.84a.12.12,0,0,1,0-.17l.84-.84a.12.12,0,0,1,.17.17l-.755.755Z" |
| 305 |
transform="translate(-11.427 -17.721)" fill="#ff5cf4" /> |
| 306 |
<path id="Path_52" data-name="Path 52" |
| 307 |
d="M17.964,27.955a.12.12,0,0,1-.17.17l-.84-.84a.12.12,0,0,1,0-.17l.84-.84a.12.12,0,0,1,.17.17l-.755.755Z" |
| 308 |
transform="translate(-11.427 -17.721)" fill="none" stroke="#ff5cf4" stroke-width="1" /> |
| 309 |
</g> |
| 310 |
</g> |
| 311 |
<text id="OVATION_ELEMENTS" data-name="OVATION |
| 312 |
ELEMENTS" transform="translate(275 74)" fill="#0023c4" font-size="30" font-family="SegoeUI-Bold, Segoe UI" |
| 313 |
font-weight="700"> |
| 314 |
<tspan x="0" y="32">OVATION</tspan> |
| 315 |
<tspan x="0" y="64">ELEMENTS</tspan> |
| 316 |
</text> |
| 317 |
</g> |
| 318 |
</svg> |
| 319 |
<a href="<?php echo esc_url('https://www.ovationthemes.com/products/ovation-elements-pro'); ?>" class="ov-header-review-btn" target="_blank" rel="noopener noreferrer">Get Pro</a> |
| 320 |
</div> |
| 321 |
<!-- <div class="container mt-5"> --> |
| 322 |
<!-- Tabs Navigation --> |
| 323 |
<ul class="nav nav-tabs" id="ova_elems_ovationSliderTabs" role="tablist" style="background-image:url('<?php echo esc_url(plugin_dir_url(__FILE__) . '../assets/images/nav-background.png'); ?>');"> |
| 324 |
|
| 325 |
<li class="nav-item"> |
| 326 |
<a class="nav-link" id="ova_elems_tab1-tab" data-toggle="tab" href="#ova_elems_tab1" role="tab" aria-controls="ova_elems_tab1" aria-selected="true">Dashboard</a> |
| 327 |
</li> |
| 328 |
<li class="nav-item"> |
| 329 |
<a class="nav-link" id="ova_elems_tab2-tab" data-toggle="tab" href="#ova_elems_tab2" role="tab" aria-controls="ova_elems_tab2" aria-selected="false">Sliders</a> |
| 330 |
</li> |
| 331 |
<li class="nav-item"> |
| 332 |
<a class="nav-link" id="ova_elems_tab3-tab" data-toggle="tab" href="#ova_elems_tab3" role="tab" aria-controls="ova_elems_tab3" aria-selected="false">Post Type</a> |
| 333 |
</li> |
| 334 |
<li class="nav-item"> |
| 335 |
<a class="nav-link" id="ova_elems_tab4-tab" data-toggle="tab" href="#ova_elems_tab4" role="tab" aria-controls="ova_elems_tab4" aria-selected="false">Page Builder</a> |
| 336 |
</li> |
| 337 |
<li class="nav-item"> |
| 338 |
<a class="nav-link active" id="ova_elems_tab5-tab" data-toggle="tab" href="#ova_elems_tab5" role="tab" aria-controls="ova_elems_tab5" aria-selected="false"> Block Themes</a> |
| 339 |
</li> |
| 340 |
<li class="nav-item"> |
| 341 |
<a class="nav-link" id="ova_elems_tab6-tab" data-toggle="tab" href="#ova_elems_tab6" role="tab" aria-controls="ova_elems_tab6" aria-selected="false">Support</a> |
| 342 |
</li> |
| 343 |
</ul> |
| 344 |
|
| 345 |
<!-- Tabs Content --> |
| 346 |
<div class="tab-content" id="ova_elems_ovationSliderTabsContent"> |
| 347 |
<div class="tab-pane fade" id="ova_elems_tab1" role="tabpanel" aria-labelledby="ova_elems_tab1-tab"> |
| 348 |
<?php include(plugin_dir_path(__FILE__) . 'ova-elems-tab1.php'); ?> |
| 349 |
</div> |
| 350 |
|
| 351 |
<div class="tab-pane fade" id="ova_elems_tab2" role="tabpanel" aria-labelledby="ova_elems_tab2-tab"> |
| 352 |
<?php include(plugin_dir_path(__FILE__) . 'ova-elems-tab2.php'); ?> |
| 353 |
</div> |
| 354 |
|
| 355 |
<div class="tab-pane fade" id="ova_elems_tab3" role="tabpanel" aria-labelledby="ova_elems_tab3-tab"> |
| 356 |
<?php include(plugin_dir_path(__FILE__) . 'ova-elems-tab3.php'); ?> |
| 357 |
</div> |
| 358 |
|
| 359 |
<div class="tab-pane fade" id="ova_elems_tab4" role="tabpanel" aria-labelledby="ova_elems_tab4-tab"> |
| 360 |
<?php include(plugin_dir_path(__FILE__) . 'ova-elems-tab4.php'); ?> |
| 361 |
</div> |
| 362 |
|
| 363 |
<div class="tab-pane fade show active" id="ova_elems_tab5" role="tabpanel" aria-labelledby="ova_elems_tab5-tab"> |
| 364 |
<?php include(plugin_dir_path(__FILE__) . 'ova-elems-tab5.php'); ?> |
| 365 |
</div> |
| 366 |
|
| 367 |
<div class="tab-pane fade" id="ova_elems_tab6" role="tabpanel" aria-labelledby="ova_elems_tab6-tab"> |
| 368 |
<?php include(plugin_dir_path(__FILE__) . 'ova-elems-tab6.php'); ?> |
| 369 |
</div> |
| 370 |
</div> |
| 371 |
</div> |
| 372 |
<?php |
| 373 |
} |
| 374 |
|
| 375 |
|
| 376 |
//end |
| 377 |
|
| 378 |
//addded for tabs end |
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
// Handle Template Selection and Redirect to Edit Page |
| 383 |
function ova_elems_handle_template_selection() { |
| 384 |
// Verify nonce |
| 385 |
if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'ova_elems_template_selection')) { |
| 386 |
wp_die(esc_html__('Security check failed.', 'ovation-elements')); |
| 387 |
} |
| 388 |
|
| 389 |
if (!current_user_can('edit_posts')) { |
| 390 |
wp_die(esc_html__('You do not have sufficient permissions to access this page.', 'ovation-elements')); |
| 391 |
} |
| 392 |
|
| 393 |
if (isset($_GET['template_id'])) { |
| 394 |
$template_id = absint($_GET['template_id']); |
| 395 |
|
| 396 |
// Create a new post of type 'ova_elems' |
| 397 |
$post_id = wp_insert_post( |
| 398 |
array( |
| 399 |
'post_title' => 'New Slider', |
| 400 |
'post_type' => 'ova_elems', |
| 401 |
'post_status' => 'publish', |
| 402 |
) |
| 403 |
); |
| 404 |
|
| 405 |
// Save the template ID as post meta |
| 406 |
if ($post_id && !is_wp_error($post_id)) { |
| 407 |
update_post_meta($post_id, '_ova_elems_template_id', $template_id); |
| 408 |
|
| 409 |
// Redirect to edit page |
| 410 |
wp_redirect(admin_url('edit.php?post_type=ova_elems&page=edit_slider_template&post=' . $post_id)); |
| 411 |
exit; |
| 412 |
} |
| 413 |
} |
| 414 |
|
| 415 |
wp_redirect(admin_url('admin.php?page=select-template')); |
| 416 |
exit; |
| 417 |
} |
| 418 |
add_action('admin_post_select_template', 'ova_elems_handle_template_selection'); |
| 419 |
|
| 420 |
|
| 421 |
//changes here by removing old for trash |
| 422 |
|
| 423 |
function ova_elems_custom_trash_action() { |
| 424 |
if (!current_user_can('delete_posts')) { |
| 425 |
wp_die(esc_html__('You do not have sufficient permissions to perform this action.', 'ovation-elements')); |
| 426 |
} |
| 427 |
|
| 428 |
if (isset($_GET['action']) && $_GET['action'] == 'trash' && isset($_GET['post']) && get_post_type($_GET['post']) == 'ova_elems') { |
| 429 |
$post_id = absint($_GET['post']); |
| 430 |
if (current_user_can('delete_post', $post_id)) { |
| 431 |
wp_trash_post($post_id); |
| 432 |
wp_redirect(admin_url('edit.php?post_type=ova_elems')); |
| 433 |
exit; |
| 434 |
} |
| 435 |
} |
| 436 |
} |
| 437 |
add_action('admin_init', 'ova_elems_custom_trash_action'); |
| 438 |
|
| 439 |
// Add columns to the post list |
| 440 |
function ova_elems_add_custom_columns($columns) |
| 441 |
{ |
| 442 |
$new_columns = array(); |
| 443 |
foreach ($columns as $key => $value) { |
| 444 |
$new_columns[$key] = $value; |
| 445 |
if ($key == 'title') { |
| 446 |
$new_columns['custom_template'] = 'Template'; |
| 447 |
$new_columns['shortcode'] = 'Shortcode'; // Adding new column for shortcode |
| 448 |
} |
| 449 |
} |
| 450 |
return $new_columns; |
| 451 |
} |
| 452 |
add_filter('manage_ova_elems_posts_columns', 'ova_elems_add_custom_columns'); |
| 453 |
|
| 454 |
// Populate custom columns with data |
| 455 |
|
| 456 |
function ova_elems_custom_column_data($column, $post_id) |
| 457 |
{ |
| 458 |
if ($column == 'custom_template') { |
| 459 |
$template_id = get_post_meta($post_id, '_ova_elems_template_id', true); |
| 460 |
echo $template_id ? 'Template ' . esc_html($template_id) : 'N/A'; |
| 461 |
} elseif ($column == 'shortcode') { |
| 462 |
$is_premium_user = get_option('ovation_slider_is_premium', false); |
| 463 |
|
| 464 |
$args = array( |
| 465 |
'post_type' => 'ova_elems', |
| 466 |
'post_status' => 'publish', |
| 467 |
'posts_per_page' => -1, |
| 468 |
'orderby' => 'date', |
| 469 |
'order' => 'ASC', |
| 470 |
); |
| 471 |
$existing_sliders = get_posts($args); |
| 472 |
$free_sliders = array_slice($existing_sliders, 0, 100); |
| 473 |
$is_locked = true; |
| 474 |
if ($is_premium_user) { |
| 475 |
$is_locked = false; |
| 476 |
} else { |
| 477 |
foreach ($free_sliders as $free_slider) { |
| 478 |
if ($free_slider->ID == $post_id) { |
| 479 |
$is_locked = false; |
| 480 |
break; |
| 481 |
} |
| 482 |
} |
| 483 |
} |
| 484 |
|
| 485 |
if ($is_locked) { |
| 486 |
echo '<span class="dashicons dashicons-lock"></span> ' . esc_html__('Locked', 'ovation-elements'); |
| 487 |
} else { |
| 488 |
echo '[ova-elems-slider-template id="' . esc_attr($post_id) . '"]'; |
| 489 |
} |
| 490 |
} |
| 491 |
} |
| 492 |
add_action('manage_ova_elems_posts_custom_column', 'ova_elems_custom_column_data', 10, 2); |
| 493 |
|
| 494 |
|
| 495 |
//end |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
add_action('admin_menu', 'ova_elems_register_edit_page'); |
| 500 |
function ova_elems_register_edit_page() |
| 501 |
{ |
| 502 |
add_menu_page( |
| 503 |
'Edit Slider Template', |
| 504 |
//'Edit Slider', |
| 505 |
'manage_options', |
| 506 |
'edit-slider-template', |
| 507 |
'ova_elems_edit_page_callback' |
| 508 |
); |
| 509 |
} |
| 510 |
|
| 511 |
function ova_elems_edit_page_callback() |
| 512 |
{ |
| 513 |
// Include the edit page file |
| 514 |
include (plugin_dir_path(__FILE__) . 'templates/edit-slider-template.php'); |
| 515 |
|
| 516 |
|
| 517 |
} |
| 518 |
|
| 519 |
//new one i add |
| 520 |
|
| 521 |
function ova_elems_edit_page_template1() |
| 522 |
{ |
| 523 |
include (plugin_dir_path(__FILE__) . 'templates/edit-slider-template1.php'); |
| 524 |
} |
| 525 |
|
| 526 |
function ova_elems_edit_page_template2() |
| 527 |
{ |
| 528 |
include (plugin_dir_path(__FILE__) . 'templates/edit-slider-template2.php'); |
| 529 |
} |
| 530 |
|
| 531 |
function ova_elems_edit_page_template3() |
| 532 |
{ |
| 533 |
include (plugin_dir_path(__FILE__) . 'templates/edit-slider-template3.php'); |
| 534 |
} |
| 535 |
|
| 536 |
function ova_elems_edit_page_template4() |
| 537 |
{ |
| 538 |
include (plugin_dir_path(__FILE__) . 'templates/edit-slider-template4.php'); |
| 539 |
} |
| 540 |
|
| 541 |
function ova_elems_edit_page_template5() { |
| 542 |
include(plugin_dir_path(__FILE__) . 'templates/edit-slider-template5.php'); |
| 543 |
} |
| 544 |
|
| 545 |
function ova_elems_edit_page_template6() |
| 546 |
{ |
| 547 |
include (plugin_dir_path(__FILE__) . 'templates/edit-slider-template6.php'); |
| 548 |
} |
| 549 |
|
| 550 |
function ova_elems_edit_page_template7() { |
| 551 |
include(plugin_dir_path(__FILE__) . 'templates/edit-slider-template7.php'); |
| 552 |
} |
| 553 |
|
| 554 |
function ova_elems_edit_page_template8() { |
| 555 |
include(plugin_dir_path(__FILE__) . 'templates/edit-slider-template8.php'); |
| 556 |
} |
| 557 |
|
| 558 |
//end |
| 559 |
|
| 560 |
//new redirect_to_edit_link |
| 561 |
add_action('admin_init', 'ova_elems_redirect_to_edit_page'); |
| 562 |
function ova_elems_redirect_to_edit_page() |
| 563 |
{ |
| 564 |
global $pagenow; |
| 565 |
if ($pagenow == 'post.php' && isset($_GET['post']) && get_post_type(absint($_GET['post'])) == 'ova_elems') { |
| 566 |
$post_id = intval($_GET['post']); |
| 567 |
$template_id = get_post_meta($post_id, '_ova_elems_template_id', true); |
| 568 |
switch ($template_id) { |
| 569 |
case 1: |
| 570 |
wp_redirect(admin_url('admin.php?page=edit-slider-template-template1&post=' . $post_id)); |
| 571 |
break; |
| 572 |
case 2: |
| 573 |
wp_redirect(admin_url('admin.php?page=edit-slider-template-template2&post=' . $post_id)); |
| 574 |
break; |
| 575 |
case 3: |
| 576 |
wp_redirect(admin_url('admin.php?page=edit-slider-template-template3&post=' . $post_id)); |
| 577 |
break; |
| 578 |
case 4: |
| 579 |
wp_redirect(admin_url('admin.php?page=edit-slider-template-template4&post=' . $post_id)); |
| 580 |
break; |
| 581 |
case 5: |
| 582 |
wp_redirect(admin_url('admin.php?page=edit-slider-template-template5&post=' . $post_id)); |
| 583 |
break; |
| 584 |
|
| 585 |
case 6: |
| 586 |
wp_redirect(admin_url('admin.php?page=edit-slider-template-template6&post=' . $post_id)); |
| 587 |
break; |
| 588 |
case 7: |
| 589 |
wp_redirect(admin_url('admin.php?page=edit-slider-template-template7&post=' . $post_id)); |
| 590 |
break; |
| 591 |
case 8: |
| 592 |
wp_redirect(admin_url('admin.php?page=edit-slider-template-template8&post=' . $post_id)); |
| 593 |
break; |
| 594 |
|
| 595 |
|
| 596 |
default: |
| 597 |
wp_redirect(admin_url('admin.php?page=edit-slider-template&post=' . $post_id)); |
| 598 |
break; |
| 599 |
} |
| 600 |
exit; |
| 601 |
} |
| 602 |
} |
| 603 |
|
| 604 |
//edit |
| 605 |
|
| 606 |
add_filter('post_row_actions', 'ova_elems_edit_link', 10, 2); |
| 607 |
function ova_elems_edit_link($actions, $post) |
| 608 |
{ |
| 609 |
if ($post->post_type == 'ova_elems') { |
| 610 |
$template_id = get_post_meta($post->ID, '_ova_elems_template_id', true); |
| 611 |
switch ($template_id) { |
| 612 |
case 1: |
| 613 |
$edit_link = admin_url('admin.php?page=edit-slider-template-template1&post=' . $post->ID); |
| 614 |
break; |
| 615 |
case 2: |
| 616 |
$edit_link = admin_url('admin.php?page=edit-slider-template-template2&post=' . $post->ID); |
| 617 |
break; |
| 618 |
case 3: |
| 619 |
$edit_link = admin_url('admin.php?page=edit-slider-template-template3&post=' . $post->ID); |
| 620 |
break; |
| 621 |
case 4: |
| 622 |
$edit_link = admin_url('admin.php?page=edit-slider-template-template4&post=' . $post->ID); |
| 623 |
break; |
| 624 |
case 5: |
| 625 |
$edit_link = admin_url('admin.php?page=edit-slider-template-template5&post=' . $post->ID); |
| 626 |
break; |
| 627 |
|
| 628 |
case 6: |
| 629 |
$edit_link = admin_url('admin.php?page=edit-slider-template-template6&post=' . $post->ID); |
| 630 |
break; |
| 631 |
case 7: |
| 632 |
$edit_link = admin_url('admin.php?page=edit-slider-template-template7&post=' . $post->ID); |
| 633 |
break; |
| 634 |
|
| 635 |
case 8: |
| 636 |
$edit_link = admin_url('admin.php?page=edit-slider-template-template8&post=' . $post->ID); |
| 637 |
break; |
| 638 |
|
| 639 |
default: |
| 640 |
$edit_link = admin_url('admin.php?page=edit-slider-template&post=' . $post->ID); |
| 641 |
break; |
| 642 |
} |
| 643 |
$actions['edit'] = '<a href="' . esc_url($edit_link) . '">Edit</a>'; |
| 644 |
} |
| 645 |
return $actions; |
| 646 |
} |
| 647 |
//end |
| 648 |
|
| 649 |
|
| 650 |
// Template Selection Page |
| 651 |
function ova_elems_slider_select_template_page() |
| 652 |
{ |
| 653 |
$is_premium_user = get_option('ovation_slider_is_premium', false); |
| 654 |
?> |
| 655 |
<div class="wrap"> |
| 656 |
<div class="heading-container"> |
| 657 |
<div class="container-custom"> |
| 658 |
<h1>Select a Template</h1> |
| 659 |
</div> |
| 660 |
</div> |
| 661 |
<div class="container-custom"> |
| 662 |
<div class="row"> |
| 663 |
<?php |
| 664 |
$templates = array( |
| 665 |
array('id' => 1, 'title' => 'Business Slider Template', 'image' => OVA_ELEMS_URL . 'assets/images/template-1.png'), |
| 666 |
array('id' => 2, 'title' => 'Travel Slider Template', 'image' => OVA_ELEMS_URL . 'assets/images/template-2.png'), |
| 667 |
array('id' => 3, 'title' => 'Ecommerce Slider Template', 'image' => OVA_ELEMS_URL . 'assets/images/template-3.png'), |
| 668 |
array('id' => 4, 'title' => 'News Slider Template', 'image' => OVA_ELEMS_URL . 'assets/images/template-4.png'), |
| 669 |
array('id' => 5, 'title' => 'Food Slider Template', 'image' => OVA_ELEMS_URL . 'assets/images/template-5.png'), |
| 670 |
array('id' => 6, 'title' => 'Restaurant Slider Template', 'image' => OVA_ELEMS_URL . 'assets/images/template-6.png'), |
| 671 |
array('id' => 7, 'title' => 'Travel2 Slider Template', 'image' => OVA_ELEMS_URL . 'assets/images/template-7.png'), |
| 672 |
array('id' => 8, 'title' => 'Education Slider Template', 'image' => OVA_ELEMS_URL . 'assets/images/template-8.png'), |
| 673 |
|
| 674 |
array('id' => 9, 'title' => 'E-commerce Slider Template', 'image' => OVA_ELEMS_URL . 'assets/images/template-9.png'), |
| 675 |
array('id' => 10, 'title' => 'Business Slider Template', 'image' => OVA_ELEMS_URL . 'assets/images/template-10.png'), |
| 676 |
|
| 677 |
|
| 678 |
array('id' => 11, 'title' => 'Travel Slider Template', 'image' => OVA_ELEMS_URL . 'assets/images/template-11.png'), |
| 679 |
array('id' => 12, 'title' => 'Restaurant Slider Template', 'image' => OVA_ELEMS_URL . 'assets/images/template-12.png'), |
| 680 |
|
| 681 |
array('id' => 13, 'title' => 'Ecommerce Slider Template', 'image' => OVA_ELEMS_URL . 'assets/images/template-13.png'), |
| 682 |
array('id' => 14, 'title' => 'Business Slider Template', 'image' => OVA_ELEMS_URL . 'assets/images/template-14.png'), |
| 683 |
|
| 684 |
array('id' => 15, 'title' => 'Education Slider Template', 'image' => OVA_ELEMS_URL . 'assets/images/template-15.png'), |
| 685 |
|
| 686 |
); |
| 687 |
|
| 688 |
foreach ($templates as $template) { |
| 689 |
$is_pro_template = in_array($template['id'], [6, 7, 8]); // Mark templates 6, 7, 8 as Pro only |
| 690 |
?> |
| 691 |
<div class="col-md-4 col-lg-4 col-12 mb-4"> |
| 692 |
<div class="slider-card" style=""> |
| 693 |
<div class="slider-image"> |
| 694 |
<img class="card-img-top" src="<?php echo esc_url($template['image']); ?>" |
| 695 |
alt="<?php echo esc_attr($template['title']); ?>"> |
| 696 |
</div> |
| 697 |
<!-- i change --> |
| 698 |
|
| 699 |
<div class="heading-wrapper mt-2"> |
| 700 |
<h5 class="card-title"><?php echo esc_html($template['title']); ?></h5> |
| 701 |
<?php if (in_array($template['id'], [9, 10, 11, 12, 13, 14, 15])) { ?> |
| 702 |
<button class="btn btn-warning" disabled>Coming Soon...</button> |
| 703 |
<?php } elseif (!$is_premium_user && $is_pro_template) { ?> |
| 704 |
<button class="btn btn-secondary" disabled>Pro Only</button> |
| 705 |
<p class="mt-2"> |
| 706 |
<a href="https://www.ovationthemes.com/products/ovation-elements-pro" target="_blank" class="btn btn-link"> |
| 707 |
Upgrade to Pro |
| 708 |
</a> |
| 709 |
</p> |
| 710 |
<?php } else { ?> |
| 711 |
<a href="<?php echo esc_url(admin_url('admin-post.php?action=create_ova_elems&template_id=' . $template['id'])); ?>" |
| 712 |
class="btn btn-primary">Select Template</a> |
| 713 |
<?php } ?> |
| 714 |
</div> |
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
<!-- end --> |
| 719 |
|
| 720 |
|
| 721 |
</div> |
| 722 |
</div> |
| 723 |
<?php |
| 724 |
} |
| 725 |
?> |
| 726 |
</div> |
| 727 |
</div> |
| 728 |
</div> |
| 729 |
<?php |
| 730 |
} |
| 731 |
|
| 732 |
//new handle slider |
| 733 |
|
| 734 |
function ova_elems_handle_create_slider() |
| 735 |
{ |
| 736 |
if (!current_user_can('edit_posts')) { |
| 737 |
wp_die(esc_html__('You do not have sufficient permissions to access this page.', 'ovation-elements')); |
| 738 |
} |
| 739 |
|
| 740 |
if (isset($_GET['template_id'])) { |
| 741 |
$template_id = absint($_GET['template_id']); |
| 742 |
|
| 743 |
// Create a new post of type 'ova_elems' |
| 744 |
$post_id = wp_insert_post( |
| 745 |
array( |
| 746 |
'post_title' => 'New Slider', // Default title, can be updated later |
| 747 |
'post_type' => 'ova_elems', |
| 748 |
'post_status' => 'publish', |
| 749 |
) |
| 750 |
); |
| 751 |
|
| 752 |
// Save the template ID as post meta |
| 753 |
if ($post_id && !is_wp_error($post_id)) { |
| 754 |
update_post_meta($post_id, '_ova_elems_template_id', $template_id); |
| 755 |
|
| 756 |
// Redirect to the specific edit page based on template ID |
| 757 |
switch ($template_id) { |
| 758 |
case 1: |
| 759 |
wp_redirect(admin_url('admin.php?page=edit-slider-template-template1&post=' . $post_id)); |
| 760 |
break; |
| 761 |
case 2: |
| 762 |
wp_redirect(admin_url('admin.php?page=edit-slider-template-template2&post=' . $post_id)); |
| 763 |
break; |
| 764 |
case 3: |
| 765 |
wp_redirect(admin_url('admin.php?page=edit-slider-template-template3&post=' . $post_id)); |
| 766 |
break; |
| 767 |
case 4: |
| 768 |
wp_redirect(admin_url('admin.php?page=edit-slider-template-template4&post=' . $post_id)); |
| 769 |
break; |
| 770 |
case 5: |
| 771 |
wp_redirect(admin_url('admin.php?page=edit-slider-template-template5&post=' . $post_id)); |
| 772 |
break; |
| 773 |
case 6: |
| 774 |
wp_redirect(admin_url('admin.php?page=edit-slider-template-template6&post=' . $post_id)); |
| 775 |
break; |
| 776 |
case 7: |
| 777 |
wp_redirect(admin_url('admin.php?page=edit-slider-template-template7&post=' . $post_id)); |
| 778 |
break; |
| 779 |
case 8: |
| 780 |
wp_redirect(admin_url('admin.php?page=edit-slider-template-template8&post=' . $post_id)); |
| 781 |
break; |
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
default: |
| 786 |
wp_redirect(admin_url('admin.php?page=edit-slider-template&post=' . $post_id)); |
| 787 |
break; |
| 788 |
} |
| 789 |
exit; |
| 790 |
} |
| 791 |
} |
| 792 |
|
| 793 |
wp_redirect(admin_url('admin.php?page=select-template')); |
| 794 |
exit; |
| 795 |
} |
| 796 |
add_action('admin_post_create_ova_elems', 'ova_elems_handle_create_slider'); |
| 797 |
|
| 798 |
function ova_elems_save_data() { |
| 799 |
// Verify nonce |
| 800 |
if (!isset($_POST['ova_elems_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['ova_elems_nonce'])), 'ova_elems_save_meta_boxes_data')) { |
| 801 |
wp_die(esc_html__('Nonce verification failed.', 'ovation-elements')); |
| 802 |
} |
| 803 |
|
| 804 |
$post_id = isset($_POST['post_id']) ? absint($_POST['post_id']) : 0; |
| 805 |
if (!$post_id) { |
| 806 |
wp_die(esc_html__('Invalid post ID.', 'ovation-elements')); |
| 807 |
} |
| 808 |
|
| 809 |
if (!current_user_can('edit_post', $post_id)) { |
| 810 |
wp_die(esc_html__('You do not have sufficient permissions to edit this post.', 'ovation-elements')); |
| 811 |
} |
| 812 |
|
| 813 |
// Retrieve and sanitize slide data |
| 814 |
$slides = []; |
| 815 |
$slide_titles = isset($_POST['slide_titles']) ? array_map('sanitize_text_field', wp_unslash($_POST['slide_titles'])) : []; |
| 816 |
$slide_descriptions = isset($_POST['slide_descriptions']) ? array_map('sanitize_textarea_field', wp_unslash($_POST['slide_descriptions'])) : []; |
| 817 |
$slide_images = isset($_POST['slide_images']) ? array_map('sanitize_text_field', wp_unslash($_POST['slide_images'])) : []; |
| 818 |
$slide_button_texts = isset($_POST['slide_button_texts']) ? array_map('sanitize_text_field', wp_unslash($_POST['slide_button_texts'])) : []; |
| 819 |
$slide_button_urls = isset($_POST['slide_button_urls']) ? array_map('esc_url_raw', wp_unslash($_POST['slide_button_urls'])) : []; |
| 820 |
|
| 821 |
$slide_button2_texts = isset($_POST['slide_button2_texts']) ? array_map('sanitize_text_field', wp_unslash($_POST['slide_button2_texts'])) : []; |
| 822 |
$slide_button2_urls = isset($_POST['slide_button2_urls']) ? array_map('esc_url_raw', wp_unslash($_POST['slide_button2_urls'])) : []; |
| 823 |
$slide_thumbnail_images = isset($_POST['slide_thumbnail_images']) ? array_map('sanitize_text_field', wp_unslash($_POST['slide_thumbnail_images'])) : []; |
| 824 |
$slide_thumbnail_titles = isset($_POST['slide_thumbnail_titles']) ? array_map('sanitize_text_field', wp_unslash($_POST['slide_thumbnail_titles'])) : []; |
| 825 |
|
| 826 |
$slide_head_tags = isset($_POST['slide_head_tags']) ? array_map('sanitize_text_field', wp_unslash($_POST['slide_head_tags'])) : []; |
| 827 |
$slide_mini_head_images = isset($_POST['slide_mini_head_images']) ? array_map('sanitize_text_field', wp_unslash($_POST['slide_mini_head_images'])) : []; |
| 828 |
|
| 829 |
$slide_courses = isset($_POST['slide_courses']) ? array_map('intval', wp_unslash($_POST['slide_courses'])) : []; // Added line |
| 830 |
$slide_bg_color = isset($_POST['slide_bg_color']) ? array_map('sanitize_hex_color', wp_unslash($_POST['slide_bg_color'])) : []; |
| 831 |
|
| 832 |
|
| 833 |
foreach ($slide_titles as $index => $title) { |
| 834 |
$slides[] = [ |
| 835 |
'title' => $title, |
| 836 |
'description' => $slide_descriptions[$index] ?? '', |
| 837 |
'image_id' => $slide_images[$index] ?? '', |
| 838 |
'button_text' => $slide_button_texts[$index] ?? '', |
| 839 |
'button_url' => $slide_button_urls[$index] ?? '', |
| 840 |
'button2_text' => $slide_button2_texts[$index] ?? '', |
| 841 |
'button2_url' => $slide_button2_urls[$index] ?? '', |
| 842 |
'thumbnail_image_id' => $slide_thumbnail_images[$index] ?? '', |
| 843 |
'thumbnail_title' => $slide_thumbnail_titles[$index] ?? '', |
| 844 |
'head_tag' => $slide_head_tags[$index] ?? '', |
| 845 |
'mini_head_image' => $slide_mini_head_images[$index] ?? '', // New setting |
| 846 |
'course_id' => $slide_courses[$index] ?? '', // Added field |
| 847 |
'slide_bg_color' => $slide_bg_color[$index] ?? '', |
| 848 |
]; |
| 849 |
} |
| 850 |
|
| 851 |
// print_r($slides); |
| 852 |
// exit; |
| 853 |
|
| 854 |
update_post_meta($post_id, '_ova_elems_slides', maybe_serialize($slides)); |
| 855 |
|
| 856 |
// Retrieve and sanitize static settings data |
| 857 |
$static_settings = []; |
| 858 |
$slide_corner_images = isset($_POST['slide_corner_images']) ? array_map('sanitize_text_field', wp_unslash($_POST['slide_corner_images'])) : []; |
| 859 |
$slide_mini_titles = isset($_POST['slide_mini_titles']) ? array_map('sanitize_text_field', wp_unslash($_POST['slide_mini_titles'])) : []; |
| 860 |
$slide_mini_descriptions = isset($_POST['slide_mini_descriptions']) ? array_map('sanitize_textarea_field', wp_unslash($_POST['slide_mini_descriptions'])) : []; |
| 861 |
$slide_mini_title2 = isset($_POST['slide_mini_title2']) ? array_map('sanitize_text_field', wp_unslash($_POST['slide_mini_title2'])) : []; |
| 862 |
$slide_mini_description2 = isset($_POST['slide_mini_description2']) ? array_map('sanitize_textarea_field', wp_unslash($_POST['slide_mini_description2'])) : []; |
| 863 |
|
| 864 |
$slide_email = isset($_POST['slide_email']) ? sanitize_email(wp_unslash($_POST['slide_email'])) : ''; |
| 865 |
$slide_no = isset($_POST['slide_no']) ? sanitize_text_field(wp_unslash($_POST['slide_no'])) : ''; |
| 866 |
|
| 867 |
$background_color = isset($_POST['background_color']) ? sanitize_hex_color(wp_unslash($_POST['background_color'])) : ''; |
| 868 |
|
| 869 |
$slide_mini_images_1 = isset($_POST['slide_mini_images_1']) ? array_map('sanitize_text_field', wp_unslash($_POST['slide_mini_images_1'])) : []; |
| 870 |
$slide_mini_images_2 = isset($_POST['slide_mini_images_2']) ? array_map('sanitize_text_field', wp_unslash($_POST['slide_mini_images_2'])) : []; |
| 871 |
|
| 872 |
$instagram_url = isset($_POST['instagram_url']) ? esc_url_raw(wp_unslash($_POST['instagram_url'])) : ''; |
| 873 |
$facebook_url = isset($_POST['facebook_url']) ? esc_url_raw(wp_unslash($_POST['facebook_url'])) : ''; |
| 874 |
$youtube_url = isset($_POST['youtube_url']) ? esc_url_raw(wp_unslash($_POST['youtube_url'])) : ''; |
| 875 |
$basketball_url = isset($_POST['basketball_url']) ? esc_url_raw(wp_unslash($_POST['basketball_url'])) : ''; |
| 876 |
$twitter_url = isset($_POST['twitter_url']) ? esc_url_raw(wp_unslash($_POST['twitter_url'])) : ''; |
| 877 |
|
| 878 |
$list_title = isset($_POST['list_title']) ? sanitize_text_field(wp_unslash($_POST['list_title'])) : ''; |
| 879 |
$list_description = isset($_POST['list_description']) ? sanitize_textarea_field(wp_unslash($_POST['list_description'])) : ''; |
| 880 |
$enter_list = isset($_POST['enter_list']) ? array_map('sanitize_text_field', array_map('trim', explode(',', wp_unslash($_POST['enter_list'])))) : []; |
| 881 |
|
| 882 |
$ov_template_review_text = isset($_POST['ov_template_review_text']) ? sanitize_text_field(wp_unslash($_POST['ov_template_review_text'])) : ''; |
| 883 |
$ov_template_social_review_text = isset($_POST['ov_template_social_review_text']) ? sanitize_text_field(wp_unslash($_POST['ov_template_social_review_text'])) : ''; |
| 884 |
|
| 885 |
//$ov_template_review_no = isset($_POST['ov_template_review_no']) ? intval(wp_unslash($_POST['ov_template_review_no'])) : 0; |
| 886 |
$ov_template_review_no = isset($_POST['ov_template_review_no']) ? sanitize_text_field(wp_unslash($_POST['ov_template_review_no'])) : ''; |
| 887 |
|
| 888 |
$slide_video_url = isset($_POST['slide_video_url']) ? esc_url_raw(wp_unslash($_POST['slide_video_url'])) : ''; |
| 889 |
|
| 890 |
$static_button_text = isset($_POST['static_button_text']) ? sanitize_text_field(wp_unslash($_POST['static_button_text'])) : ''; |
| 891 |
$static_button_url = isset($_POST['static_button_url']) ? esc_url_raw(wp_unslash($_POST['static_button_url'])) : ''; |
| 892 |
|
| 893 |
$static_button2_text = isset($_POST['static_button2_text']) ? sanitize_text_field(wp_unslash($_POST['static_button2_text'])) : ''; |
| 894 |
$static_button2_url = isset($_POST['static_button2_url']) ? esc_url_raw(wp_unslash($_POST['static_button2_url'])) : ''; |
| 895 |
$banner_font_size = isset($_POST['banner_font_size']) ? intval($_POST['banner_font_size']) : 18; |
| 896 |
$heading_font_size = isset($_POST['heading_font_size']) ? intval($_POST['heading_font_size']) : 18; |
| 897 |
|
| 898 |
$head_font_size = isset($_POST['head_font_size']) ? intval($_POST['head_font_size']) : 18; |
| 899 |
$button_font_size = isset($_POST['button_font_size']) ? intval($_POST['button_font_size']) : 18; |
| 900 |
$button2_font_size = isset($_POST['button2_font_size']) ? intval($_POST['button2_font_size']) : 18; |
| 901 |
$ov_mini_title_font_size = isset($_POST['ov_mini_title_font_size']) ? intval($_POST['ov_mini_title_font_size']) : 18; |
| 902 |
$mini_description_font_size = isset($_POST['mini_description_font_size']) ? intval($_POST['mini_description_font_size']) : 18; |
| 903 |
$slide_email_font_size = isset($_POST['slide_email_font_size']) ? intval($_POST['slide_email_font_size']) : 18; |
| 904 |
$slide_no_font_size = isset($_POST['slide_no_font_size']) ? intval($_POST['slide_no_font_size']) : 18; |
| 905 |
$list_title_font_size = isset($_POST['list_title_font_size']) ? intval($_POST['list_title_font_size']) : 'initial'; |
| 906 |
$list_description_font_size = isset($_POST['list_description_font_size']) ? intval($_POST['list_description_font_size']) : 'initial'; |
| 907 |
$list_content_font_size = isset($_POST['list_content_font_size']) ? intval($_POST['list_content_font_size']) : 'initial'; |
| 908 |
$review_text_font_size = isset($_POST['review_text_font_size']) ? intval($_POST['review_text_font_size']) : 18; // New setting |
| 909 |
$review_no_font_size = isset($_POST['review_no_font_size']) ? intval($_POST['review_no_font_size']) : 18; // New setting |
| 910 |
$static_button_text_font_size = isset($_POST['static_button_text_font_size']) ? intval($_POST['static_button_text_font_size']) : 18; |
| 911 |
$title_head_font_size = isset($_POST['title_head_font_size']) ? intval($_POST['title_head_font_size']) : 20; |
| 912 |
$static_loader_percentage = isset($_POST['static_loader_percentage']) ? intval($_POST['static_loader_percentage']) : 90; |
| 913 |
|
| 914 |
$ov_review_text_font_size = isset($_POST['ov_review_text_font_size']) ? intval($_POST['ov_review_text_font_size']) : 18; |
| 915 |
|
| 916 |
$ov_social_text_font_size = isset($_POST['ov_social_text_font_size']) ? intval($_POST['ov_social_text_font_size']) : 18; |
| 917 |
|
| 918 |
$video_bg_image = isset($_POST['video_bg_image']) ? esc_url($_POST['video_bg_image']) : ''; |
| 919 |
|
| 920 |
// bg image of 5 |
| 921 |
$bg_slide_image = isset($_POST['bg_slide_image']) ? esc_url($_POST['bg_slide_image']) : ''; |
| 922 |
|
| 923 |
|
| 924 |
$static_settings = [ |
| 925 |
'corner_images' => $slide_corner_images, |
| 926 |
'mini_titles' => $slide_mini_titles, |
| 927 |
'mini_descriptions' => $slide_mini_descriptions, |
| 928 |
'mini_title2' => $slide_mini_title2, |
| 929 |
'mini_description2' => $slide_mini_description2, |
| 930 |
'slide_email' => $slide_email, |
| 931 |
'slide_no' => $slide_no, |
| 932 |
|
| 933 |
'background_color' => $background_color, |
| 934 |
'mini_images_1' => $slide_mini_images_1, |
| 935 |
'mini_images_2' => $slide_mini_images_2, |
| 936 |
'instagram_url' => $instagram_url, |
| 937 |
'facebook_url' => $facebook_url, |
| 938 |
'youtube_url' => $youtube_url, |
| 939 |
'basketball_url' => $basketball_url, |
| 940 |
'twitter_url' => $twitter_url, |
| 941 |
'slide_video_url' => $slide_video_url, |
| 942 |
'list_title' => $list_title, |
| 943 |
'list_description' => $list_description, |
| 944 |
'enter_list' => $enter_list, |
| 945 |
|
| 946 |
'ov_template_review_text' => $ov_template_review_text, |
| 947 |
'ov_template_social_review_text' => $ov_template_social_review_text, |
| 948 |
'ov_template_review_no' => $ov_template_review_no, |
| 949 |
|
| 950 |
'static_button_text' => $static_button_text, |
| 951 |
'static_button_url' => $static_button_url, |
| 952 |
|
| 953 |
'static_button2_text' => $static_button2_text, |
| 954 |
'static_button2_url' => $static_button2_url, |
| 955 |
|
| 956 |
'background_color' => $background_color, |
| 957 |
|
| 958 |
'banner_font_size' => $banner_font_size, |
| 959 |
|
| 960 |
'heading_font_size' => $heading_font_size, |
| 961 |
|
| 962 |
'head_font_size' => $head_font_size, |
| 963 |
'button_font_size' => $button_font_size, |
| 964 |
'button2_font_size' => $button2_font_size, |
| 965 |
'ov_mini_title_font_size' => $ov_mini_title_font_size, |
| 966 |
'mini_description_font_size' => $mini_description_font_size, |
| 967 |
'slide_email_font_size' => $slide_email_font_size, |
| 968 |
'slide_no_font_size' => $slide_no_font_size, |
| 969 |
'list_title_font_size' => $list_title_font_size, |
| 970 |
'list_description_font_size' => $list_description_font_size, |
| 971 |
'list_content_font_size' => $list_content_font_size, |
| 972 |
'review_text_font_size' => $review_text_font_size, |
| 973 |
'review_no_font_size' => $review_no_font_size, |
| 974 |
'static_button_text_font_size' => $static_button_text_font_size, |
| 975 |
'title_head_font_size' => $title_head_font_size, |
| 976 |
'static_loader_percentage' => $static_loader_percentage , |
| 977 |
'ov_review_text_font_size' => $ov_review_text_font_size, |
| 978 |
|
| 979 |
'ov_social_text_font_size' => $ov_social_text_font_size, |
| 980 |
'video_bg_image' => $video_bg_image, |
| 981 |
'bg_slide_image' => $bg_slide_image |
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
]; |
| 987 |
|
| 988 |
update_post_meta($post_id, '_ova_elems_static_settings', maybe_serialize($static_settings)); |
| 989 |
|
| 990 |
// Redirect to the edit page after saving |
| 991 |
wp_redirect(admin_url('edit.php?post_type=ova_elems')); |
| 992 |
exit; |
| 993 |
} |
| 994 |
add_action('admin_post_save_ova_elems_data', 'ova_elems_save_data'); |
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
//templat4 save data |
| 999 |
|
| 1000 |
function ova_elems_save_template4_data() { |
| 1001 |
// Verify nonce |
| 1002 |
if (!isset($_POST['ova_elems_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['ova_elems_nonce'])), 'ova_elems_save_meta_boxes_data')) { |
| 1003 |
wp_die(esc_html__('Nonce verification failed.', 'ovation-elements')); |
| 1004 |
} |
| 1005 |
|
| 1006 |
// Get post ID |
| 1007 |
$post_id = isset($_POST['post_id']) ? absint($_POST['post_id']) : 0; |
| 1008 |
if (!$post_id) { |
| 1009 |
wp_die(esc_html__('Invalid post ID.', 'ovation-elements')); |
| 1010 |
} |
| 1011 |
|
| 1012 |
// Sanitize and save selected posts |
| 1013 |
$selected_posts = isset($_POST['selected_posts']) ? array_map('intval', (array)$_POST['selected_posts']) : array(); |
| 1014 |
update_post_meta($post_id, '_ova_elems_selected_posts_template4', maybe_serialize($selected_posts)); |
| 1015 |
|
| 1016 |
//newly add |
| 1017 |
$button_data = isset($_POST['button_data']) ? array_map(function($data) { |
| 1018 |
return [ |
| 1019 |
'text' => sanitize_text_field($data['text'] ?? ''), |
| 1020 |
'url' => esc_url_raw($data['url'] ?? ''), |
| 1021 |
'text2' => sanitize_text_field($data['text2'] ?? ''), // Button2 Text |
| 1022 |
'url2' => esc_url_raw($data['url2'] ?? ''), // Button2 URL |
| 1023 |
'video' => esc_url_raw($data['video'] ?? ''), |
| 1024 |
]; |
| 1025 |
}, $_POST['button_data']) : []; |
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
update_post_meta($post_id, '_ova_elems_button_data_template4', maybe_serialize($button_data)); |
| 1030 |
|
| 1031 |
$tour_info_data = isset($_POST['tour_info_data']) ? array_map('sanitize_textarea_field', (array)$_POST['tour_info_data']) : []; |
| 1032 |
|
| 1033 |
update_post_meta($post_id, '_ova_elems_tour_info_data_template4', maybe_serialize($tour_info_data)); |
| 1034 |
|
| 1035 |
|
| 1036 |
//new for vedio link |
| 1037 |
$video_data = isset($_POST['video_data']) ? array_map(function($data) { |
| 1038 |
return [ |
| 1039 |
'live_link' => esc_url_raw($data['live_link'] ?? ''), |
| 1040 |
'upload_video' => esc_url_raw($data['upload_video'] ?? ''), // Uploaded Video URL |
| 1041 |
]; |
| 1042 |
}, $_POST['video_data']) : []; |
| 1043 |
|
| 1044 |
// Save the live video link data |
| 1045 |
update_post_meta($post_id, '_ova_elems_video_data_template4', maybe_serialize($video_data)); |
| 1046 |
|
| 1047 |
|
| 1048 |
//newly end |
| 1049 |
|
| 1050 |
// Sanitize and save static settings |
| 1051 |
$static_settings = array( |
| 1052 |
'instagram_url' => isset($_POST['instagram_url']) ? esc_url_raw(wp_unslash($_POST['instagram_url'])) : '', |
| 1053 |
'facebook_url' => isset($_POST['facebook_url']) ? esc_url_raw(wp_unslash($_POST['facebook_url'])) : '', |
| 1054 |
'youtube_url' => isset($_POST['youtube_url']) ? esc_url_raw(wp_unslash($_POST['youtube_url'])) : '', |
| 1055 |
'basketball_url' => isset($_POST['basketball_url']) ? esc_url_raw(wp_unslash($_POST['basketball_url'])) : '', |
| 1056 |
'twitter_url' => isset($_POST['twitter_url']) ? esc_url_raw(wp_unslash($_POST['twitter_url'])) : '', |
| 1057 |
'ov_template_review_text' => isset($_POST['ov_template_review_text']) ? sanitize_textarea_field(wp_unslash($_POST['ov_template_review_text'])) : '', |
| 1058 |
'mini_description' => isset($_POST['mini_description']) ? sanitize_textarea_field(wp_unslash($_POST['mini_description'])) : '', |
| 1059 |
'live_video_link' => isset($_POST['live_video_link']) ? esc_url_raw(wp_unslash($_POST['live_video_link'])) : '', |
| 1060 |
'live_mini_text' => isset($_POST['live_mini_text']) ? sanitize_text_field(wp_unslash($_POST['live_mini_text'])) : '', |
| 1061 |
'live_title_text' => isset($_POST['live_title_text']) ? sanitize_text_field(wp_unslash($_POST['live_title_text'])) : '', |
| 1062 |
|
| 1063 |
'corner_posts_count' => isset($_POST['corner_posts_count']) ? absint(wp_unslash($_POST['corner_posts_count'])) : 1, |
| 1064 |
'corner_posts_category' => isset($_POST['corner_posts_category']) ? absint(wp_unslash($_POST['corner_posts_category'])) : '', |
| 1065 |
'corner_posts_order' => isset($_POST['corner_posts_order']) ? sanitize_text_field(wp_unslash($_POST['corner_posts_order'])) : 'asc', |
| 1066 |
|
| 1067 |
// New settings |
| 1068 |
'upload_minheadimage' => isset($_POST['upload_minheadimage']) ? esc_url_raw(wp_unslash($_POST['upload_minheadimage'])) : '', |
| 1069 |
'ov_travel_head_tag' => isset($_POST['ov_travel_head_tag']) ? sanitize_text_field(wp_unslash($_POST['ov_travel_head_tag'])) : '', |
| 1070 |
'ov_static_title' => isset($_POST['ov_static_title']) ? sanitize_text_field(wp_unslash($_POST['ov_static_title'])) : '', |
| 1071 |
'static_description' => isset($_POST['static_description']) ? sanitize_textarea_field(wp_unslash($_POST['static_description'])) : '', |
| 1072 |
'ov_button_text' => isset($_POST['ov_button_text']) ? sanitize_text_field(wp_unslash($_POST['ov_button_text'])) : '', |
| 1073 |
'ov_button_url' => isset($_POST['ov_button_url']) ? esc_url_raw(wp_unslash($_POST['ov_button_url'])) : '', |
| 1074 |
'ov_client_image' => isset($_POST['ov_client_image']) ? esc_url_raw(wp_unslash($_POST['ov_client_image'])) : '', |
| 1075 |
'ov_review_text' => isset($_POST['ov_review_text']) ? sanitize_text_field(wp_unslash($_POST['ov_review_text'])) : '', |
| 1076 |
|
| 1077 |
// 'ov_review_no' => isset($_POST['ov_review_no']) ? absint(wp_unslash($_POST['ov_review_no'])) : 0, |
| 1078 |
'ov_review_no' => isset($_POST['ov_review_no']) ? sanitize_text_field(wp_unslash($_POST['ov_review_no'])) : '', |
| 1079 |
|
| 1080 |
// New settings |
| 1081 |
'banner_font_size' => isset($_POST['banner_font_size']) ? absint(wp_unslash($_POST['banner_font_size'])) : 50, |
| 1082 |
'heading_font_size' => isset($_POST['heading_font_size']) ? absint(wp_unslash($_POST['heading_font_size'])) : 50, |
| 1083 |
'button_font_size' => isset($_POST['button_font_size']) ? absint(wp_unslash($_POST['button_font_size'])) : 18, |
| 1084 |
|
| 1085 |
// New font size settings |
| 1086 |
'ov_social_text_font_size' => isset($_POST['ov_social_text_font_size']) ? absint(wp_unslash($_POST['ov_social_text_font_size'])) : 18, |
| 1087 |
'ov_review_text_font_size' => isset($_POST['ov_review_text_font_size']) ? absint(wp_unslash($_POST['ov_review_text_font_size'])) : 18, |
| 1088 |
|
| 1089 |
'title_head_font_size' => isset($_POST['title_head_font_size']) ? absint(wp_unslash($_POST['title_head_font_size'])) : 18, |
| 1090 |
'list_title_font_size' => isset($_POST['list_title_font_size']) ? absint(wp_unslash($_POST['list_title_font_size'])) : 18, |
| 1091 |
'list_description_font_size' => isset($_POST['list_description_font_size']) ? absint(wp_unslash($_POST['list_description_font_size'])) : 18, |
| 1092 |
'list_content_font_size' => isset($_POST['list_content_font_size']) ? absint(wp_unslash($_POST['list_content_font_size'])) : 18, |
| 1093 |
'static_button_text_font_size' => isset($_POST['static_button_text_font_size']) ? absint(wp_unslash($_POST['static_button_text_font_size'])) : 18, |
| 1094 |
|
| 1095 |
'review_text_font_size' => isset($_POST['review_text_font_size']) ? absint(wp_unslash($_POST['review_text_font_size'])) : 18, |
| 1096 |
'review_no_font_size' => isset($_POST['review_no_font_size']) ? absint(wp_unslash($_POST['review_no_font_size'])) : 18, |
| 1097 |
'ov_mini_title_font_size' => isset($_POST['ov_mini_title_font_size']) ? absint(wp_unslash($_POST['ov_mini_title_font_size'])) : 18, |
| 1098 |
'oe_button_font_size' => isset($_POST['oe_button_font_size']) ? absint(wp_unslash($_POST['oe_button_font_size'])) : 18, |
| 1099 |
|
| 1100 |
'ov_mini_title_right_font_size' => isset($_POST['ov_mini_title_right_font_size']) ? absint(wp_unslash($_POST['ov_mini_title_right_font_size'])) : 14, |
| 1101 |
'ov_mini_description_font_size' => isset($_POST['ov_mini_description_font_size']) ? absint(wp_unslash($_POST['ov_mini_description_font_size'])) : 18, |
| 1102 |
'thmhead_font_size' => isset($_POST['thmhead_font_size']) ? absint(wp_unslash($_POST['thmhead_font_size'])) : 18, |
| 1103 |
'thmbtitle_font_size' => isset($_POST['thmbtitle_font_size']) ? absint(wp_unslash($_POST['thmbtitle_font_size'])) : 18, |
| 1104 |
'thmbdesc_font_size' => isset($_POST['thmbdesc_font_size']) ? absint(wp_unslash($_POST['thmbdesc_font_size'])) : 18, |
| 1105 |
|
| 1106 |
// New font size settings |
| 1107 |
'live_mini_text_font_size' => isset($_POST['live_mini_text_font_size']) ? intval($_POST['live_mini_text_font_size']) : 18, |
| 1108 |
'live_title_font_size' => isset($_POST['live_title_font_size']) ? intval($_POST['live_title_font_size']) : 18, |
| 1109 |
'oe_left_side_title_font_size' => isset($_POST['oe_left_side_title_font_size']) ? intval($_POST['oe_left_side_title_font_size']) : 18, |
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
); |
| 1115 |
|
| 1116 |
update_post_meta($post_id, '_ova_elems_static_settings_template4', maybe_serialize($static_settings)); |
| 1117 |
|
| 1118 |
|
| 1119 |
wp_redirect(admin_url('edit.php?post_type=ova_elems')); |
| 1120 |
} |
| 1121 |
add_action('admin_post_save_ova_elems_template4_data', 'ova_elems_save_template4_data'); |
| 1122 |
|
| 1123 |
|
| 1124 |
//end |
| 1125 |
|
| 1126 |
|
| 1127 |
//for shortcode |
| 1128 |
|
| 1129 |
function ova_elems_template_shortcode($atts){ |
| 1130 |
return ova_elems_shortcode_handler($atts); |
| 1131 |
} |
| 1132 |
|
| 1133 |
add_shortcode('ova-elems-slider-template', 'ova_elems_template_shortcode'); |
| 1134 |
|
| 1135 |
//for stylesheets according to different templates add |
| 1136 |
|
| 1137 |
function ova_elems_enqueue_styles() { |
| 1138 |
global $ova_elems_template; |
| 1139 |
|
| 1140 |
// Enqueue Swiper CSS and JS locally |
| 1141 |
wp_enqueue_style( |
| 1142 |
'swiper-css', |
| 1143 |
OVA_ELEMS_URL . 'assets/css/swiper-bundle.min.css', |
| 1144 |
[], |
| 1145 |
OVA_ELEMS_VER |
| 1146 |
); |
| 1147 |
wp_enqueue_script( |
| 1148 |
'swiper-js', |
| 1149 |
OVA_ELEMS_URL . 'assets/js/swiper-bundle.min.js', |
| 1150 |
[], |
| 1151 |
OVA_ELEMS_VER, |
| 1152 |
true |
| 1153 |
); |
| 1154 |
|
| 1155 |
wp_enqueue_style( |
| 1156 |
'oe-front-cs', |
| 1157 |
OVA_ELEMS_URL . 'assets/css/bootstrap.min.css', |
| 1158 |
[], |
| 1159 |
OVA_ELEMS_VER |
| 1160 |
); |
| 1161 |
wp_enqueue_script( |
| 1162 |
'oe-front-js', |
| 1163 |
OVA_ELEMS_URL . 'assets/js/bootstrap.bundle.min.js', |
| 1164 |
[], |
| 1165 |
OVA_ELEMS_VER, |
| 1166 |
true |
| 1167 |
); |
| 1168 |
|
| 1169 |
|
| 1170 |
wp_enqueue_style('ova-elems-google-fonts-montserrat-outfit', 'https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&family=Outfit:wght@100..900&display=swap', array(), OVA_ELEMS_VER, ''); |
| 1171 |
wp_enqueue_style('ova-elems-font-awesome', OVA_ELEMS_URL . 'assets/css/font.all.min.css', array(), OVA_ELEMS_VER); |
| 1172 |
} |
| 1173 |
|
| 1174 |
add_action('wp_enqueue_scripts', 'ova_elems_enqueue_styles' , 10 ); |
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
//end |
| 1179 |
|
| 1180 |
//for color picker |
| 1181 |
|
| 1182 |
function enqueue_wp_color_picker_assets($hook) { |
| 1183 |
// Enqueue color picker CSS and JS |
| 1184 |
wp_enqueue_style('wp-color-picker'); |
| 1185 |
wp_enqueue_script('wp-color-picker'); |
| 1186 |
} |
| 1187 |
add_action('admin_enqueue_scripts', 'enqueue_wp_color_picker_assets'); |
| 1188 |
|
| 1189 |
//end |
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
//for compressor and croping |
| 1194 |
|
| 1195 |
add_action('wp_ajax_upload_cropped_image', 'handle_cropped_image_upload'); |
| 1196 |
|
| 1197 |
function handle_cropped_image_upload() { |
| 1198 |
// Verify nonce |
| 1199 |
if (!isset($_POST['_ajax_nonce']) || !wp_verify_nonce($_POST['_ajax_nonce'], 'upload_cropped_image_nonce')) { |
| 1200 |
wp_send_json_error(['message' => 'Invalid nonce']); |
| 1201 |
wp_die(); |
| 1202 |
} |
| 1203 |
|
| 1204 |
// Check user capabilities |
| 1205 |
if (!current_user_can('upload_files')) { |
| 1206 |
wp_send_json_error(['message' => 'Insufficient permissions']); |
| 1207 |
wp_die(); |
| 1208 |
} |
| 1209 |
|
| 1210 |
if (!isset($_FILES['cropped_image']) || empty($_FILES['cropped_image'])) { |
| 1211 |
wp_send_json_error(['message' => 'No image file provided.']); |
| 1212 |
wp_die(); |
| 1213 |
} |
| 1214 |
|
| 1215 |
$file = $_FILES['cropped_image']; |
| 1216 |
|
| 1217 |
// Validate the file |
| 1218 |
if ($file['error'] !== UPLOAD_ERR_OK) { |
| 1219 |
wp_send_json_error(['message' => 'Error uploading file.']); |
| 1220 |
wp_die(); |
| 1221 |
} |
| 1222 |
|
| 1223 |
$upload = wp_handle_upload($file, ['test_form' => false]); |
| 1224 |
|
| 1225 |
if (!$upload || isset($upload['error'])) { |
| 1226 |
wp_send_json_error(['message' => 'Failed to upload image.', 'error' => $upload['error']]); |
| 1227 |
wp_die(); |
| 1228 |
} |
| 1229 |
|
| 1230 |
// Insert the uploaded image into the WordPress media library |
| 1231 |
$attachment_id = wp_insert_attachment([ |
| 1232 |
'guid' => $upload['url'], |
| 1233 |
'post_mime_type' => $upload['type'], |
| 1234 |
'post_title' => sanitize_file_name($file['name']), |
| 1235 |
'post_content' => '', |
| 1236 |
'post_status' => 'inherit', |
| 1237 |
], $upload['file']); |
| 1238 |
|
| 1239 |
if (is_wp_error($attachment_id)) { |
| 1240 |
wp_send_json_error(['message' => 'Failed to insert image into media library.']); |
| 1241 |
wp_die(); |
| 1242 |
} |
| 1243 |
|
| 1244 |
// Generate attachment metadata and update |
| 1245 |
require_once ABSPATH . 'wp-admin/includes/image.php'; |
| 1246 |
$metadata = wp_generate_attachment_metadata($attachment_id, $upload['file']); |
| 1247 |
wp_update_attachment_metadata($attachment_id, $metadata); |
| 1248 |
|
| 1249 |
wp_send_json_success(['message' => 'Image uploaded successfully!', 'url' => $upload['url']]); |
| 1250 |
wp_die(); |
| 1251 |
} |
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
//for tutor plugin installation |
| 1256 |
|
| 1257 |
add_action('wp_ajax_tutor_plugin_action', function() { |
| 1258 |
check_ajax_referer('tutor-plugin-action', 'nonce'); |
| 1259 |
|
| 1260 |
$action = $_POST['action_type'] ?? ''; |
| 1261 |
$response = ['success' => false, 'message' => '', 'is_active' => false]; |
| 1262 |
|
| 1263 |
if ($action === 'install') { |
| 1264 |
include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; |
| 1265 |
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 1266 |
|
| 1267 |
$api = plugins_api('plugin_information', ['slug' => 'tutor', 'fields' => ['sections' => false]]); |
| 1268 |
$upgrader = new Plugin_Upgrader(); |
| 1269 |
$result = $upgrader->install($api->download_link); |
| 1270 |
|
| 1271 |
if (is_wp_error($result)) { |
| 1272 |
$response['message'] = $result->get_error_message(); |
| 1273 |
} else { |
| 1274 |
// Automatically activate the plugin |
| 1275 |
include_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 1276 |
$plugin_slug = 'tutor/tutor.php'; |
| 1277 |
activate_plugin($plugin_slug); |
| 1278 |
|
| 1279 |
if (is_plugin_active($plugin_slug)) { |
| 1280 |
$response['success'] = true; |
| 1281 |
$response['message'] = __('Tutor LMS installed and activated successfully.', 'ovation-elements'); |
| 1282 |
$response['is_active'] = true; |
| 1283 |
} else { |
| 1284 |
$response['message'] = __('Tutor LMS installed but failed to activate.', 'ovation-elements'); |
| 1285 |
} |
| 1286 |
} |
| 1287 |
} elseif ($action === 'activate') { |
| 1288 |
include_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 1289 |
|
| 1290 |
$plugin_slug = 'tutor/tutor.php'; |
| 1291 |
activate_plugin($plugin_slug); |
| 1292 |
|
| 1293 |
if (is_plugin_active($plugin_slug)) { |
| 1294 |
$response['success'] = true; |
| 1295 |
$response['message'] = __('Tutor LMS activated successfully.', 'ovation-elements'); |
| 1296 |
$response['is_active'] = true; |
| 1297 |
} else { |
| 1298 |
$response['message'] = __('Failed to activate Tutor LMS.', 'ovation-elements'); |
| 1299 |
} |
| 1300 |
} |
| 1301 |
|
| 1302 |
// Handle HTML or JSON response |
| 1303 |
if (isset($_POST['response_type']) && $_POST['response_type'] === 'html') { |
| 1304 |
echo esc_html($response['message']); |
| 1305 |
} else { |
| 1306 |
wp_send_json($response); |
| 1307 |
} |
| 1308 |
|
| 1309 |
wp_die(); |
| 1310 |
}); |
| 1311 |
//end |
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|