Changeset 2441390
- Timestamp:
- 12/17/2020 10:39:49 AM (5 years ago)
- Location:
- master-elements/trunk
- Files:
-
- 2 edited
-
masterelements.php (modified) (1 diff)
-
modules/theme-builder/me-cpt.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
master-elements/trunk/masterelements.php
r2421516 r2441390 10 10 * Plugin URI: https://akdesigner.com/ 11 11 * Author: TeamDevBunch 12 * Version: 7. 512 * Version: 7.6 13 13 * Tested up to: 5.5 14 14 * Author URI: https://devbunch.com/ -
master-elements/trunk/modules/theme-builder/me-cpt.php
r2427296 r2441390 1 1 <?php 2 2 3 4 3 5 namespace MasterElements\Modules\Theme_Builder; 4 6 7 8 5 9 use Elementor\Widgets_Manager; 10 6 11 use MasterElements; 12 7 13 use MasterElements\Modules\Manager\Api; 8 14 15 16 9 17 defined('ABSPATH') || exit; 10 18 11 19 20 21 22 12 23 $p_count = '1'; 13 24 25 26 14 27 class Master_Custom_Post 28 15 29 { 16 30 17 31 32 33 34 18 35 public function __construct() 36 19 37 { 20 38 39 40 21 41 $this->create_table(); 22 42 43 44 23 45 $this->post_type(); 24 46 25 47 48 49 50 26 51 if (is_admin()) { 52 27 53 $par = [ 54 28 55 "me_header_settings", 56 29 57 "me_footer_settings", 58 30 59 "me_archive_settings", 60 31 61 "me_single_settings", 62 32 63 "me_404_settings", 64 33 65 "me_blog_settings", 66 34 67 "me_maintenance_settings", 68 35 69 "me_section_settings", 70 36 71 "me_search_settings", 72 37 73 "me_comingsoon_settings", 74 38 75 "me_megamenu_settings", 76 39 77 "me_wooproduct_settings" 78 40 79 ]; 41 80 81 82 42 83 if (in_array(isset($_GET['page']), $par)) { 84 43 85 wp_enqueue_style('modal-css', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css', false, \MasterElements::version); 86 44 87 wp_enqueue_script('modal-js', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js', array('jquery'), \MasterElements::version, true); 88 45 89 } 46 90 91 92 47 93 } 48 94 49 95 96 97 98 50 99 // wp_enqueue_script('modal-js', 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js', array( 'jquery' ), \MasterElements::version, true ); 51 100 52 101 102 103 104 53 105 add_action('wp_ajax_save_me_settings', [$this, 'save_me_settings']); 54 106 107 108 55 109 add_action('wp_ajax_nopriv_save_me_settings', [$this, 'save_me_settings']); 56 110 111 112 57 113 add_action('wp_ajax_remove_post_meta_condition', [$this, 'remove_post_meta_condition']); 58 114 115 116 59 117 add_action('wp_ajax_nopriv_remove_post_meta_condition', [$this, 'remove_post_meta_condition']); 60 118 119 120 61 121 add_action('wp_ajax_open_edit_modal', [$this, 'open_edit_modal']); 62 122 123 124 63 125 add_action('wp_ajax_nopriv_open_edit_modal', [$this, 'open_edit_modal']); 64 126 127 128 65 129 add_action('wp_ajax_update_post_type_condition', [$this, 'update_post_type_condition']); 66 130 131 132 67 133 add_action('wp_ajax_nopriv_update_post_type_condition', [$this, 'update_post_type_condition']); 68 134 135 136 69 137 add_action('wp_ajax_activation_updated', [$this, 'activation_updated']); 70 138 139 140 71 141 add_action('wp_ajax_nopriv_activation_updated', [$this, 'activation_updated']); 72 142 143 144 73 145 add_action('admin_menu', [$this, 'cpt_menu']); 74 146 147 148 75 149 add_filter('single_template', [$this, 'load_canvas_template']); 76 150 151 152 77 153 add_filter('manage_me_footer_posts_columns', [$this, 'add_new_columns']); 78 154 155 156 79 157 add_action('manage_me_footer_posts_custom_column', [$this, 'custom_column_data']); 80 158 159 160 81 161 add_filter('manage_me_header_posts_columns', [$this, 'add_new_columns']); 82 162 163 164 83 165 add_action('manage_me_header_posts_custom_column', [$this, 'custom_column_data']); 84 166 167 168 85 169 add_filter('manage_me_archive_posts_columns', [$this, 'add_new_columns']); 86 170 171 172 87 173 add_action('manage_me_archive_posts_custom_column', [$this, 'custom_column_data']); 88 174 175 176 89 177 add_filter('manage_me_single_posts_columns', [$this, 'add_new_columns']); 90 178 179 180 91 181 add_action('manage_me_single_posts_custom_column', [$this, 'custom_column_data']); 92 182 183 184 93 185 add_filter('manage_me_wooproduct_posts_columns', [$this, 'add_new_columns']); 94 186 187 188 95 189 add_action('manage_me_wooproduct_posts_custom_column', [$this, 'custom_column_data']); 96 190 191 192 97 193 add_filter('manage_me_404_posts_columns', [$this, 'add_new_columns']); 98 194 195 196 99 197 add_action('manage_me_404_posts_custom_column', [$this, 'custom_column_data']); 100 198 199 200 101 201 add_filter('manage_me_blog_posts_columns', [$this, 'add_new_columns']); 102 202 203 204 103 205 add_action('manage_me_blog_posts_custom_column', [$this, 'custom_column_data']); 104 206 207 208 105 209 add_filter('manage_me_maintenance_posts_columns', [$this, 'add_new_columns']); 106 210 211 212 107 213 add_action('manage_me_maintenance_posts_custom_column', [$this, 'custom_column_data']); 108 214 215 216 109 217 add_filter('manage_me_section_posts_columns', [$this, 'add_new_columns']); 110 218 219 220 111 221 add_action('manage_me_section_posts_custom_column', [$this, 'custom_column_data']); 112 222 223 224 113 225 add_filter('manage_me_search_posts_columns', [$this, 'add_new_columns']); 114 226 227 228 115 229 add_action('manage_me_search_posts_custom_column', [$this, 'custom_column_data']); 116 230 231 232 117 233 add_action('wp_ajax_check_module_active', [$this, 'check_module_active']); 118 234 235 236 119 237 add_action('wp_ajax_get_menu_template', [$this, 'get_menu_template']); 120 238 239 240 121 241 add_action('wp_ajax_save_menu_postmeta', [$this, 'save_menu_postmeta']); 122 242 243 244 123 245 add_action('wp_ajax_get_megamenu_control', [$this, 'get_megamenu_control']); 124 246 247 248 125 249 add_action('wp_ajax_demo_data_import', [$this, 'demo_data_import']); 126 250 251 252 127 253 add_action('wp_ajax_send_feedback', [$this, 'send_feedback']); 128 254 255 256 129 257 add_action('wp_ajax_get_cat_data', [$this, 'get_cat_data']); 130 258 131 259 260 261 262 132 263 wp_enqueue_script('forms-js', \MasterElements::widgets_url() . '/me-forms/assets/js/forms.js', false, \MasterElements::version); 133 264 265 266 134 267 wp_localize_script('forms-js', 'MS_Ajax', array( 268 135 269 'ajaxurl' => admin_url('admin-ajax.php'), 270 136 271 )); 272 137 273 add_action('wp_ajax_custom_submit_form', [$this, 'custom_submit_form']); 274 138 275 add_action('wp_ajax_nopriv_custom_submit_form', [$this, 'custom_submit_form']); 139 276 277 278 140 279 } 141 280 281 282 142 283 function post_type() 284 143 285 { 144 286 145 287 288 289 290 146 291 $template_types = $this->register_sections(); 147 292 293 294 148 295 $settings = $this->get_main_settings_data(); 149 296 297 298 150 299 foreach ($template_types as $type) { 151 300 301 302 152 303 if (isset($settings[$type['id']]['name']) && $settings[$type['id']]['name'] = $type['id'] && $settings[$type['id']]['value'] != 'no') { 153 304 154 305 306 307 308 155 309 $labels = array( 156 310 311 312 157 313 'name' => __($type['name'], 'masterelements'), 158 314 315 316 159 317 'singular_name' => __($type['single'], 'masterelements'), 160 318 319 320 161 321 'menu_name' => __($type['name'], 'masterelements'), 162 322 323 324 163 325 'name_admin_bar' => __($type['name'], 'masterelements'), 164 326 327 328 165 329 'add_new' => __('Add New', 'masterelements'), 166 330 331 332 167 333 'add_new_item' => __('Add New ' . $type['item'], 'masterelements'), 168 334 335 336 169 337 'new_item' => __('New ' . $type['item'], 'masterelements'), 170 338 339 340 171 341 'edit_item' => __('Edit ' . $type['item'], 'masterelements'), 172 342 343 344 173 345 'view_item' => __('View ' . $type['item'], 'masterelements'), 174 346 347 348 175 349 'all_items' => __('All ' . $type['item'], 'masterelements'), 176 350 351 352 177 353 'search_items' => __('Search ' . $type['item'], 'masterelements'), 178 354 355 356 179 357 'parent_item_colon' => __('Parent ' . $type['item'], 'masterelements'), 180 358 359 360 181 361 'not_found' => __('No ' . $type['item'] . ' found.', 'masterelements'), 182 362 363 364 183 365 'not_found_in_trash' => __('No ' . $type['item'] . ' found in Trash.', 'masterelements'), 184 366 367 368 185 369 ); 186 370 371 372 187 373 $args = array( 188 374 375 376 189 377 'labels' => $labels, 190 378 379 380 191 381 'public' => true, 192 382 383 384 193 385 'menu_icon' => __((isset($type['icon']) ? $type['icon'] : 'dashicons-cart'), 'masterelements'), 194 386 387 388 195 389 'rewrite' => false, 196 390 391 392 197 393 'show_ui' => true, 198 394 395 396 199 397 'show_in_menu' => true, 200 398 399 400 201 401 'show_in_nav_menus' => true, 202 402 403 404 203 405 'exclude_from_search' => true, 204 406 407 408 205 409 'capability_type' => 'page', 206 410 411 412 207 413 'hierarchical' => false, 208 414 415 416 209 417 'supports' => array('title', 'elementor'), 210 418 419 420 211 421 ); 212 422 213 423 424 425 426 214 427 register_post_type($type['id'], $args); 215 428 429 430 216 431 } 217 432 433 434 218 435 } 219 436 437 438 220 439 } 221 440 222 441 442 443 444 223 445 function open_edit_modal() 224 446 447 448 225 449 { 226 450 451 452 227 453 if (!empty($_GET['meta_ids']) && !empty($_GET['meta_types'])) { 228 454 455 456 229 457 $meta_ids = explode(',', $_GET['meta_ids']); 230 458 459 460 231 461 $condition_a = self::get_complete_meta($meta_ids[0]); 232 462 463 464 233 465 $condition_sindular = self::get_complete_meta($meta_ids[1]); 234 466 467 468 235 469 $condition_singular_id = self::get_complete_meta($meta_ids[2]); 236 470 471 472 237 473 $selected_a = ''; 238 474 475 476 239 477 $selected_b = ''; 240 478 479 480 241 481 $data['condition_a'] = ''; 242 482 483 484 243 485 $data['condition_sing'] = ''; 244 486 487 488 245 489 $data['condition_singular_id'] = ''; 246 490 491 492 247 493 $condition_a_meta_val = $condition_a[0]->meta_value; 248 494 495 496 249 497 $consition_sing_meta_val = $condition_sindular[0]->meta_value; 250 498 499 500 251 501 $condition_sing_id_meta_val = $condition_singular_id[0]->meta_value; 252 502 503 504 253 505 // $postids = unserialize($condition_sing_id_meta_val); 254 506 507 508 255 509 // print_r($postids); 256 510 511 512 257 513 // exit(); 258 514 515 516 259 517 $data['condition_a_meta_value'] = $condition_a_meta_val; 260 518 519 520 261 521 $data['consition_sing_meta_val'] = $consition_sing_meta_val; 262 522 523 524 263 525 $data['condition_sing_id_meta_val'] = $condition_sing_id_meta_val; 264 526 265 527 528 529 530 266 531 $data['condition_a'] = '<option value="entire_site" ' . $selected_a = ($condition_a_meta_val === "entire_site" ? "selected='selected'" : "") . '>' . __("Entire Site", "masterelements") . '</option> <option value="singular" ' . $selected_a = ($condition_a_meta_val === "singular" ? "selected='selected'" : "") . '>' . __("Singular", "masterelements") . '</option> 267 532 533 534 268 535 <option value="archive" ' . $selected_a = ($condition_a_meta_val === "archive" ? "selected='selected'" : "") . '>' . __("Archive", "masterelements") . '</option> 269 536 270 537 538 539 540 271 541 <option value="archive" ' . $selected_a = ($condition_a_meta_val === "archive" ? "selected='selected'" : "") . '>' . __("Archive", "masterelements") . '</option> 272 542 543 544 273 545 <option value="woo_single_product" ' . $selected_a = ($condition_a_meta_val === "woo_single_product" ? "selected='selected'" : "") . '>' . __("MW: Single Product", "masterelements") . '</option> 274 546 547 548 275 549 <option value="woo_archive_product" ' . $selected_a = ($condition_a_meta_val === "woo_archive_product" ? "selected='selected'" : "") . '>' . __("MW: Archive Product", "masterelements") . '</option> 276 550 551 552 277 553 <option value="woo_product_cart" ' . $selected_a = ($condition_a_meta_val === "woo_product_cart" ? "selected='selected'" : "") . '>' . __("MW: Product Cart", "masterelements") . '</option> 278 554 555 556 279 557 <option value="woo_product_checkout" ' . $selected_a = ($condition_a_meta_val === "woo_product_checkout" ? "selected='selected'" : "") . '>' . __("MW: Product Checkout", "masterelements") . '</option> 558 280 559 560 281 561 <option value="woo_my_account" ' . $selected_a = ($condition_a_meta_val === "woo_my_account" ? "selected='selected'" : "") . '>' . __("MW: My Account Page", "masterelements") . '</option> 562 282 563 564 283 565 <option value="woo_thankyou_page" ' . $selected_a = ($condition_a_meta_val === "woo_thankyou_page" ? "selected='selected'" : "") . '>' . __("MW: Thankyou Page", "masterelements") . '</option>'; 284 566 567 568 285 569 $data['condition_sing'] = ' <option value="">' . __('Select Any', 'masterelements') . '</option> 286 570 571 572 287 573 <option value="all" ' . $selected_b = ($consition_sing_meta_val === "all" ? "selected='selected'" : "") . '>' . __('All Singulars', 'masterelements') . '</option> 288 574 575 576 289 577 <option value="front_page" ' . $selected_b = ($consition_sing_meta_val === "front_page" ? "selected='selected'" : "") . '>' . __('Front Page', 'masterelements') . '</option> 290 578 579 580 291 581 <option value="all_posts" ' . $selected_b = ($consition_sing_meta_val === "all_posts" ? "selected='selected'" : "") . '>' . __('All Posts', 'masterelements') . '</option> 292 582 583 584 293 585 <option value="all_pages" ' . $selected_b = ($consition_sing_meta_val === "all_pages" ? "selected='selected'" : "") . '>' . __('All Pages', 'masterelements') . '</option> 294 586 587 588 295 589 <option value="404page" ' . $selected_b = ($consition_sing_meta_val === "404page" ? "selected='selected'" : "") . '>' . __('404 Page', 'masterelements') . '</option> 296 590 591 592 297 593 <option value="selective" ' . $selected_b = ($consition_sing_meta_val === "selective" ? "selected='selected'" : "") . '>' . __('Selective Singular', 'masterelements') . '</option>'; 298 594 299 595 596 597 598 300 599 $data['condition_singular_id'] = ''; 301 600 601 602 302 603 $postids = array(); 303 604 605 606 304 607 if (!empty($condition_sing_id_meta_val)) { 305 608 609 610 306 611 $postids = unserialize($condition_sing_id_meta_val); 307 612 613 614 308 615 } 309 616 617 618 310 619 $args = array( 311 620 621 622 312 623 'public' => true, 313 624 625 626 314 627 ); 315 628 316 629 630 631 632 317 633 $output = 'names'; // 'names' or 'objects' (default: 'names') 318 634 635 636 319 637 $operator = 'and'; // 'and' or 'or' (default: 'and') 320 638 321 639 640 641 642 322 643 $post_types = get_post_types($args, $output, $operator); 323 644 324 645 646 647 648 325 649 if ($post_types) { // If there are any custom public post types. 326 650 651 652 327 653 foreach ($post_types as $post_type) { 328 654 655 656 329 657 $args = array( 330 658 659 660 331 661 'numberposts' => -1, 332 662 663 664 333 665 'post_type' => $post_type 334 666 667 668 335 669 ); 336 670 671 672 337 673 $ecpt = array('metemplate', 'elementor_library', 'attachment'); 338 674 675 676 339 677 if (!in_array($post_type, $ecpt)) { 340 678 679 680 341 681 $posts = get_posts($args); 342 682 683 684 343 685 if ($posts) { 344 686 687 688 345 689 foreach ($posts as $post) : 346 690 691 692 347 693 setup_postdata($post); 348 694 695 696 349 697 $selected = ''; 350 698 699 700 351 701 if (in_array($post->ID, $postids)) { 352 702 703 704 353 705 $selected = "selected"; 354 706 707 708 355 709 } 356 710 711 712 357 713 $data['condition_singular_id'] .= '<option value="' . $post->ID . '" ' . $selected . ' >' . $post->post_title . '</option>'; 358 714 715 716 359 717 endforeach; 360 718 719 720 361 721 wp_reset_postdata(); 362 722 723 724 363 725 } 364 726 727 728 365 729 } 366 730 731 732 367 733 } 368 734 735 736 369 737 } 370 738 739 740 371 741 print_r(json_encode($data, true)); 372 742 743 744 373 745 wp_die(); 374 746 747 748 375 749 } 376 750 377 751 752 753 754 378 755 } 379 756 757 758 380 759 function update_post_type_condition() 381 760 761 762 382 763 { 383 764 765 766 384 767 print_r($_GET['condition_singular_id']); 385 768 769 770 386 771 // exit(); 387 772 773 774 388 775 if (!empty($_GET['meta_ids'])) { 389 776 390 777 778 779 780 391 781 $meta_ids = explode(',', $_GET['meta_ids']); 392 782 783 784 393 785 $condition_a = self::get_complete_meta($meta_ids[0]); 394 786 787 788 395 789 $condition_sindular = self::get_complete_meta($meta_ids[1]); 396 790 791 792 397 793 $condition_singular_id = self::get_complete_meta($meta_ids[2]); 398 794 795 796 399 797 if (isset($_GET['condition_a']) && !empty($_GET['condition_a'])) { 400 798 799 800 401 801 update_post_meta($condition_a[0]->post_id, $condition_a[0]->meta_key, $_GET['condition_a']); 402 802 803 804 403 805 } 404 806 807 808 405 809 if (isset($_GET['condition_singular'])) { 406 810 811 812 407 813 update_post_meta($condition_sindular[0]->post_id, $condition_sindular[0]->meta_key, $_GET['condition_singular']); 408 814 815 816 409 817 } 410 818 819 820 411 821 if (isset($_GET['condition_singular_id'])) { 412 822 823 824 413 825 update_post_meta($condition_singular_id[0]->post_id, $condition_singular_id[0]->meta_key, $_GET['condition_singular_id']); 414 826 827 828 415 829 } 416 830 831 832 417 833 echo json_encode(array('status' => 'success', 'msg' => 'Settings Updated')); 418 834 835 836 419 837 // echo "here"; 420 838 839 840 421 841 wp_die(); 422 842 843 844 423 845 } 424 846 847 848 425 849 } 426 850 851 852 427 853 function cpt_menu() 854 428 855 { 429 856 857 858 430 859 $template_types = $this->register_sections(); 431 860 861 862 432 863 $settings = $this->get_main_settings_data(); 433 864 865 866 434 867 add_submenu_page('masterelements', esc_html__('Dashboard', 'masterelements'), esc_html__('Dashboard', 'masterelements'), 'manage_options', 'masterelements', [$this, 'dashboard']); 435 868 869 870 436 871 add_submenu_page('masterelements', esc_html__('Options', 'masterelements'), esc_html__('Options', 'masterelements'), 'manage_options', 'settings', [$this, 'me_settings']); 437 872 438 873 874 875 876 439 877 foreach ($template_types as $type) { 440 878 879 880 441 881 if (isset($settings[$type['id']]['name']) && $settings[$type['id']]['name'] = $type['id'] && $settings[$type['id']]['value'] != 'no') { 442 882 883 884 443 885 add_submenu_page( 444 886 887 888 445 889 'edit.php?post_type=' . $type['id'], 446 890 891 892 447 893 __('Settings', 'masterelements'), 448 894 895 896 449 897 __('Settings', 'masterelements'), 450 898 899 900 451 901 'manage_options', 452 902 903 904 453 905 $type['id'] . '_settings', 454 906 907 908 455 909 [$this, 'posttypes_settings']); 456 910 457 911 912 913 914 458 915 } 459 916 917 918 460 919 } 461 920 921 922 462 923 } 463 924 464 925 926 927 928 465 929 function me_settings() 930 466 931 { 467 932 933 934 468 935 require_once \MasterElements:: plugin_dir() . 'admin/pages/settings.php'; 469 936 937 938 470 939 } 471 940 472 941 942 943 944 473 945 function posttypes_settings() 946 474 947 { 475 948 949 950 476 951 $activation = 'no'; 477 952 953 954 478 955 $condition_a = ''; 479 956 957 958 480 959 $condition_singular = ''; 481 960 961 962 482 963 ?> 483 964 484 965 966 967 968 485 969 <form action="" method="POST"> 486 970 971 972 487 973 <div class="em-outer-box"> 488 974 975 976 489 977 <div class="em-option-boxes activation-box"> 490 978 491 979 980 981 982 492 983 <div class="activation-container-box"> 493 984 985 986 494 987 <label class="attr-input-label"><?php esc_html_e('Activition:', 'masterelements'); ?></label> 495 988 989 990 496 991 <div class="master-admin-input-switch"> 497 992 993 994 498 995 <input type="checkbox" value="<?= $activation; ?>" 996 499 997 class="master-admin-control-input master-template-activition master-active-<?= $activation; ?>" 998 500 999 name="activation_val" id="master_activation_input"> 501 1000 1001 1002 502 1003 <label class="master-admin-control-label" for="master_activation_modal_input"> 503 1004 1005 1006 504 1007 <span class="master-admin-control-label-switch" data-active="ON" 505 1008 1009 1010 506 1011 data-inactive="OFF"></span> 507 1012 1013 1014 508 1015 </label> 509 1016 1017 1018 510 1019 <input type="hidden" class="activation_filed" id="activation_filed" name="activation" 1020 511 1021 value=""> 512 1022 1023 1024 513 1025 </div> 514 1026 1027 1028 515 1029 </div> 516 1030 517 1031 1032 1033 1034 518 1035 <div class="activation-container-box"> 519 1036 1037 1038 520 1039 <div class="activation-flex-box"> 521 1040 1041 1042 522 1043 <label class="attr-input-label"><?php esc_html_e('Choose Template:', 'masterelements'); ?></label> 523 1044 1045 1046 524 1047 </div> 525 1048 1049 1050 526 1051 <div class="activation-flex-box"> 527 1052 1053 1054 528 1055 <div class="selection-box"> 529 1056 1057 1058 530 1059 <h4> 1060 531 1061 <label class="attr-input-label"><?php esc_html_e('Select One:', 'masterelements'); ?></label> 1062 532 1063 </h4> 533 1064 1065 1066 534 1067 <select id="header-selection" name="type" 1068 535 1069 class="master-template-type attr-form-control select2 header-selection-dropdown"> 536 1070 1071 1072 537 1073 <?php 538 1074 1075 1076 539 1077 $args = array( 540 1078 1079 1080 541 1081 'numberposts' => -1, 542 1082 1083 1084 543 1085 'post_type' => $_GET['post_type'] 544 1086 1087 1088 545 1089 ); 546 1090 1091 1092 547 1093 $posts = get_posts($args); 548 1094 1095 1096 549 1097 if ($posts) { 550 1098 1099 1100 551 1101 foreach ($posts as $post) : 552 1102 1103 1104 553 1105 setup_postdata($post); 554 1106 1107 1108 555 1109 $selected = ''; 556 1110 1111 1112 557 1113 // if (in_array($post->ID, $postids)) { 558 1114 1115 1116 559 1117 // $selected = "selected"; 560 1118 1119 1120 561 1121 // } 562 1122 1123 1124 563 1125 $cd = get_post_meta($post->ID, 'condition_a1'); 564 1126 1127 1128 565 1129 // echo '<pre>'.$post->ID.print_r($cd,true).'</pre>'; 566 1130 1131 1132 567 1133 if (is_array($cd) && count($cd) > 0) { 568 1134 1135 1136 569 1137 // echo get_post_meta( $post->ID, 'condition_a1'); 570 1138 1139 1140 571 1141 echo '<option value="' . $post->ID . '" ' . $selected . ' disabled >' . $post->post_title . '</option>'; 572 1142 1143 1144 573 1145 } else { 574 1146 1147 1148 575 1149 // echo get_post_meta( $post->ID, 'condition_a1'); 576 1150 1151 1152 577 1153 echo '<option value="' . $post->ID . '" ' . $selected . ' >' . $post->post_title . '</option>'; 578 1154 1155 1156 579 1157 } 580 1158 1159 1160 581 1161 endforeach; 582 1162 1163 1164 583 1165 wp_reset_postdata(); 584 1166 1167 1168 585 1169 } 586 1170 587 1171 1172 1173 1174 588 1175 ?> 589 1176 1177 1178 590 1179 </select> 591 1180 1181 1182 592 1183 </div> 593 1184 1185 1186 594 1187 </div> 595 1188 1189 1190 596 1191 </div> 597 1192 1193 1194 598 1195 <div class="activation-container-box"> 599 1196 1197 1198 600 1199 <div class="activation-flex-box"> 601 1200 1201 1202 602 1203 <div class="master-template-option-container "> 603 1204 1205 1206 604 1207 <div class="master-input-group"> 605 1208 1209 1210 606 1211 <label class="attr-input-label"><?php esc_html_e('Conditions:', 'masterelements'); ?></label> 607 1212 1213 1214 608 1215 <div class="full-widthbox"> 609 1216 1217 1218 610 1219 <div class="selection-box field-box margin-bottom20"> 611 1220 1221 1222 612 1223 <select class="master-template-condition_a attr-form-control"> 613 1224 1225 1226 614 1227 <?php if ($_GET['post_type'] == 'me_archive'): ?> 615 1228 1229 1230 616 1231 <option value="archive" 1232 617 1233 class="disabled" <?php selected($condition_a, 'archive', true); ?>><?php esc_html_e('Archive ', 'masterelements'); ?></option> 618 1234 1235 1236 619 1237 <?php elseif ($_GET['post_type'] == 'me_maintenance' || $_GET['post_type'] == 'me_404'): ?> 620 1238 1239 1240 621 1241 <option value="entire_site" <?php selected($condition_a, 'entire_site', true); ?>><?php esc_html_e('Entire Site', 'masterelements'); ?></option> 622 1242 1243 1244 623 1245 <?php elseif ($_GET['post_type'] == 'me_wooproduct'): ?> 624 1246 1247 1248 625 1249 <option value=" "><?php esc_html_e('Choose Condition', 'masterelements'); ?></option> 626 1250 1251 1252 627 1253 <option value="woo_single_product" <?php selected($condition_a, 'woo_single_product', true); ?>><?php esc_html_e('MW: Single Product Page', 'masterelements'); ?></option> 628 1254 1255 1256 629 1257 <option value="woo_archive_product" <?php selected($condition_a, 'woo_archive_product', true); ?>><?php esc_html_e('MW: Archive Product Page', 'masterelements'); ?></option> 630 1258 1259 1260 631 1261 <option value="woo_product_cart" <?php selected($condition_a, 'woo_product_cart', true); ?>><?php esc_html_e('MW: Cart Product Page', 'masterelements'); ?></option> 632 1262 1263 1264 633 1265 <option value="woo_product_checkout" <?php selected($condition_a, 'woo_product_checkout', true); ?>><?php esc_html_e('MW: Product Checkout Page', 'masterelements'); ?></option> 634 1266 1267 1268 635 1269 <option value="woo_my_account" <?php selected($condition_a, 'woo_my_account', true); ?>><?php esc_html_e('MW: My Account Page', 'masterelements'); ?></option> 636 1270 1271 1272 637 1273 <option value="woo_thankyou_page" <?php selected($condition_a, 'woo_thankyou_page', true); ?>><?php esc_html_e('MW: Thankyou Page', 'masterelements'); ?></option>; 638 1274 1275 1276 639 1277 <?php else: ?> 640 1278 1279 1280 641 1281 <option value="entire_site" <?php selected($condition_a, 'entire_site', true); ?>><?php esc_html_e('Entire Site', 'masterelements'); ?></option> 642 1282 1283 1284 643 1285 <option value="singular" <?php selected($condition_a, 'singular', true); ?>><?php esc_html_e('Singular ', 'masterelements'); ?></option> 644 1286 1287 1288 645 1289 <option value="archive" <?php selected($condition_a, 'archive', true); ?>><?php esc_html_e('Archive ', 'masterelements'); ?></option> 646 1290 1291 1292 647 1293 <?php endif; ?> 648 1294 1295 1296 649 1297 </select> 650 1298 1299 1300 651 1301 <input type="hidden" value="1" name="counterCondition" 1302 652 1303 id="counterCondition" 1304 653 1305 class="counterCondition"> 654 1306 1307 1308 655 1309 <?php if ($_GET['post_type'] == 'me_archive'): ?> 656 1310 1311 1312 657 1313 <input type="hidden" value="archive" name="condition_a1" 1314 658 1315 id="condition_a1" 1316 659 1317 class="condition_a1"> 660 1318 1319 1320 661 1321 <?php elseif ($_GET['post_type'] == 'me_wooproduct'): ?> 662 1322 1323 1324 663 1325 <input type="hidden" value="woo_single_product" name="condition_a1" 1326 664 1327 id="condition_a1" 1328 665 1329 class="condition_a1"> 666 1330 1331 1332 667 1333 <input type="hidden" value="woo_archive_product" name="condition_a1" 1334 668 1335 id="condition_a1" 1336 669 1337 class="condition_a1"> 670 1338 1339 1340 671 1341 <input type="hidden" value="woo_product_cart" name="condition_a1" 1342 672 1343 id="condition_a1" 1344 673 1345 class="condition_a1"> 674 1346 1347 1348 675 1349 <input type="hidden" value="woo_product_checkout" 1350 676 1351 name="condition_a1" 1352 677 1353 id="condition_a1" 1354 678 1355 class="condition_a1"> 679 1356 1357 1358 680 1359 <input type="hidden" value="woo_my_account" name="condition_a1" 1360 681 1361 id="condition_a1" 1362 682 1363 class="condition_a1"> 683 1364 1365 1366 684 1367 <input type="hidden" value="woo_thankyou_page" name="condition_a1" 1368 685 1369 id="condition_a1" 1370 686 1371 class="condition_a1"> 687 1372 1373 1374 688 1375 <?php else: ?> 1376 689 1377 <input type="hidden" value="entire_site" name="condition_a1" 1378 690 1379 id="condition_a1" 1380 691 1381 class="condition_a1"> 1382 692 1383 <?php endif; ?> 693 1384 1385 1386 694 1387 </div> 695 1388 1389 1390 696 1391 </div> 697 1392 1393 1394 698 1395 </div> 699 1396 700 1397 1398 1399 1400 701 1401 <?php 702 1402 1403 1404 703 1405 $display = 'block'; 704 1406 1407 1408 705 1409 if ($condition_a != 'singular') { 706 1410 1411 1412 707 1413 $display = 'none'; 708 1414 1415 1416 709 1417 } ?> 710 1418 1419 1420 711 1421 <div class="activation-flex-box"> 712 1422 1423 1424 713 1425 <div class="master-input-group condition_singular" 1426 714 1427 style="display: <?= $display; ?>"> 715 1428 1429 1430 716 1431 <label class="attr-input-label"><?php echo __('Select Any:', 'masterelements'); ?></</label> 717 1432 1433 1434 718 1435 <select class="master-template-condition_singular attr-form-control"> 719 1436 1437 1438 720 1439 <option value=""><?php echo __('Select Any', 'masterelements'); ?></ 1440 721 1441 </option> 722 1442 1443 1444 723 1445 <option value="all" <?php selected($condition_singular, 'all', true); ?>><?php esc_html_e('All Singulars', 'masterelements'); ?></option> 724 1446 1447 1448 725 1449 <option value="front_page" <?php selected($condition_singular, 'front_page', true); ?>><?php esc_html_e('Front Page', 'masterelements'); ?></option> 726 1450 1451 1452 727 1453 <option value="all_posts" <?php selected($condition_singular, 'all_posts', true); ?>><?php esc_html_e('All Posts', 'masterelements'); ?></option> 728 1454 1455 1456 729 1457 <option value="all_pages" <?php selected($condition_singular, 'all_pages', true); ?>><?php esc_html_e('All Pages', 'masterelements'); ?></option> 730 1458 1459 1460 731 1461 <option value="404page" <?php selected($condition_singular, '404page', true); ?>><?php esc_html_e('404 Page', 'masterelements'); ?></option> 732 1462 1463 1464 733 1465 <option value="selective" <?php selected($condition_singular, 'selective', true); ?>><?php esc_html_e('Selective Singular', 'masterelements'); ?></option> 734 1466 1467 1468 735 1469 </select> 736 1470 1471 1472 737 1473 <input type="hidden" name="condition_singular1" id="condition_singular1" 1474 738 1475 class="condition_singular1"> 739 1476 740 1477 1478 1479 1480 741 1481 </div> 742 1482 1483 1484 743 1485 <br> 744 1486 1487 1488 745 1489 <?php 746 1490 1491 1492 747 1493 $display = 'block'; 748 1494 1495 1496 749 1497 if ($condition_singular != 'selective') { 750 1498 1499 1500 751 1501 $display = 'none'; 752 1502 1503 1504 753 1505 } ?> 754 1506 1507 1508 755 1509 <div class="master-template-condition_singular_id-container condition_singular_id" 1510 756 1511 style="display: <?= $display; ?>"> 757 1512 1513 1514 758 1515 <div class="master-input-group"> 759 1516 1517 1518 760 1519 <label class="attr-input-label"><?php echo __('Select Any:', 'masterelements'); ?></</label> 761 1520 1521 1522 762 1523 <select style="width:150px;" multiple 1524 763 1525 class="master-template-modalinput-condition_singular_id select2"> 764 1526 1527 1528 765 1529 <?php 766 1530 1531 1532 767 1533 $postids = array(); 768 1534 1535 1536 769 1537 if (!empty($condition_singular_id)) { 770 1538 1539 1540 771 1541 $postids = explode(',', $condition_singular_id); 772 1542 1543 1544 773 1545 } 774 1546 1547 1548 775 1549 $args = array( 776 1550 1551 1552 777 1553 'public' => true, 778 1554 1555 1556 779 1557 ); 780 1558 781 1559 1560 1561 1562 782 1563 $output = 'names'; // 'names' or 'objects' (default: 'names') 783 1564 1565 1566 784 1567 $operator = 'and'; // 'and' or 'or' (default: 'and') 785 1568 786 1569 1570 1571 1572 787 1573 $post_types = get_post_types($args, $output, $operator); 788 1574 789 1575 1576 1577 1578 790 1579 if ($post_types) { // If there are any custom public post types. 791 1580 1581 1582 792 1583 foreach ($post_types as $post_type) { 793 1584 1585 1586 794 1587 $args = array( 795 1588 1589 1590 796 1591 'numberposts' => -1, 797 1592 1593 1594 798 1595 'post_type' => $post_type 799 1596 1597 1598 800 1599 ); 801 1600 1601 1602 802 1603 $ecpt = array('metemplate', 'elementor_library', 'attachment'); 803 1604 1605 1606 804 1607 if (!in_array($post_type, $ecpt)) { 805 1608 1609 1610 806 1611 $posts = get_posts($args); 807 1612 1613 1614 808 1615 if ($posts) { 809 1616 1617 1618 810 1619 foreach ($posts as $post) : 811 1620 1621 1622 812 1623 setup_postdata($post); 813 1624 1625 1626 814 1627 $selected = ''; 815 1628 1629 1630 816 1631 if (in_array($post->ID, $postids)) { 817 1632 1633 1634 818 1635 $selected = "selected"; 819 1636 1637 1638 820 1639 } 821 1640 1641 1642 822 1643 echo '<option value="' . $post->ID . '" ' . $selected . ' >' . $post->post_title . '</option>'; 823 1644 1645 1646 824 1647 endforeach; 825 1648 1649 1650 826 1651 wp_reset_postdata(); 827 1652 1653 1654 828 1655 } 829 1656 1657 1658 830 1659 } 831 1660 1661 1662 832 1663 } 833 1664 1665 1666 834 1667 } 835 1668 836 1669 1670 1671 1672 837 1673 ?> 838 1674 1675 1676 839 1677 </select> 840 1678 1679 1680 841 1681 <input type="hidden" name="condition_singular_id1[]" 1682 842 1683 id="condition_singular_id1" class="condition_singular_id1"> 843 1684 844 1685 1686 1687 1688 845 1689 </div> 846 1690 1691 1692 847 1693 <br/> 848 1694 1695 1696 849 1697 </div> 850 1698 1699 1700 851 1701 <br> 852 1702 1703 1704 853 1705 </div> 854 1706 1707 1708 855 1709 </div> 856 1710 1711 1712 857 1713 </div> 858 1714 1715 1716 859 1717 </div> 860 1718 1719 1720 861 1721 <div id="newConditionTemplate"> 862 1722 863 1723 1724 1725 1726 864 1727 </div> 865 1728 1729 1730 866 1731 </div> 867 1732 1733 1734 868 1735 </div> 869 1736 870 1737 1738 1739 1740 871 1741 <button type="submit" class="option-btn"><?php echo __('Save Data', 'masterelements'); ?></button> 872 1742 1743 1744 873 1745 <?php if ($_GET['post_type'] != 'me_archive'): ?> 1746 874 1747 <button type="button" id="addButton" 1748 875 1749 class="blue-btn"><?php echo __('Add more Condition', 'masterelements'); ?></button> 1750 876 1751 <?php endif; ?> 877 1752 1753 1754 878 1755 <br> 879 1756 1757 1758 880 1759 <br> 881 1760 882 1761 1762 1763 1764 883 1765 </form> 884 1766 1767 1768 885 1769 <div style="display: none" id="newRowDiv"> 886 1770 1771 1772 887 1773 <div class="master-input-group"> 888 1774 1775 1776 889 1777 <label class="attr-input-label"><?php esc_html_e('Conditions:', 'masterelements'); ?></label> 890 1778 1779 1780 891 1781 <select class="master-template-condition_a attr-form-control"> 892 1782 1783 1784 893 1785 <?php if ($_GET['post_type'] == 'me_archive'): ?> 894 1786 1787 1788 895 1789 <option value="archive" 1790 896 1791 class="disabled" <?php selected($condition_a, 'archive', true); ?>><?php esc_html_e('Archive ', 'masterelements'); ?></option> 897 1792 1793 1794 898 1795 <?php elseif ($_GET['post_type'] == 'me_wooproduct'): ?> 899 1796 1797 1798 900 1799 <option value="woo_single_product" 1800 901 1801 class="disabled" <?php selected($condition_a, 'woo_single_product', true); ?>><?php esc_html_e('MW: Single Product Page', 'masterelements'); ?></option> 902 1802 1803 1804 903 1805 <option value="woo_archive_product" 1806 904 1807 class="disabled" <?php selected($condition_a, 'woo_archive_product', true); ?>><?php esc_html_e('MW: Archive Product Page ', 'masterelements'); ?></option> 905 1808 1809 1810 906 1811 <option value="woo_product_cart" 1812 907 1813 class="disabled" <?php selected($condition_a, 'woo_product_cart', true); ?>><?php esc_html_e('MW: Product Cart Page ', 'masterelements'); ?></option> 908 1814 1815 1816 909 1817 <option value="woo_product_checkout" 1818 910 1819 class="disabled" <?php selected($condition_a, 'woo_product_checkout', true); ?>><?php esc_html_e('MW: Product Checkout Page ', 'masterelements'); ?></option> 911 1820 1821 1822 912 1823 <option value="woo_my_account" 1824 913 1825 class="disabled" <?php selected($condition_a, 'woo_my_account', true); ?>><?php esc_html_e('MW: My Account Page ', 'masterelements'); ?></option> 914 1826 1827 1828 915 1829 <option value="woo_thankyou_page" 1830 916 1831 class="disabled" <?php selected($condition_a, 'woo_thankyou_page', true); ?>><?php esc_html_e('MW: Thankyou Page ', 'masterelements'); ?></option>; 917 1832 1833 1834 918 1835 <?php else: ?> 919 1836 1837 1838 920 1839 <option value="entire_site" <?php selected($condition_a, 'entire_site', true); ?>><?php esc_html_e('Entire Site', 'masterelements'); ?></option> 921 1840 1841 1842 922 1843 <option value="singular" <?php selected($condition_a, 'singular', true); ?>><?php esc_html_e('Singular ', 'masterelements'); ?></option> 923 1844 1845 1846 924 1847 <option value="archive" <?php selected($condition_a, 'archive', true); ?>><?php esc_html_e('Archive ', 'masterelements'); ?></option> 925 1848 1849 1850 926 1851 <?php endif; ?> 927 1852 1853 1854 928 1855 </select> 929 1856 1857 1858 930 1859 <!-- <button type="button" id="addButton" class="btn btn-primary">Add more Condition</button> 931 1860 1861 1862 932 1863 <button style="display: none" type="button" id="removeButton" class="btn btn-primary">Remove Condition</button> --> 933 1864 1865 1866 934 1867 </div> 935 1868 936 1869 1870 1871 1872 937 1873 <?php 938 1874 1875 1876 939 1877 $display = 'block'; 940 1878 1879 1880 941 1881 if ($condition_a != 'singular') { 942 1882 1883 1884 943 1885 $display = 'none'; 944 1886 1887 1888 945 1889 } ?> 946 1890 1891 1892 947 1893 <div class="master-input-group condition_singular" style="display: <?= $display; ?>"> 948 1894 1895 1896 949 1897 <label class="attr-input-label"><?php echo __('Select Any:', 'masterelements'); ?></label> 950 1898 1899 1900 951 1901 <select class="master-template-condition_singular attr-form-control"> 952 1902 1903 1904 953 1905 <option value=""><?php echo __('Select Any', 'masterelements'); ?></option> 954 1906 1907 1908 955 1909 <option value="all" <?php selected($condition_singular, 'all', true); ?>><?php esc_html_e('All Singulars', 'masterelements'); ?></option> 956 1910 1911 1912 957 1913 <option value="front_page" <?php selected($condition_singular, 'front_page', true); ?>><?php esc_html_e('Front Page', 'masterelements'); ?></option> 958 1914 1915 1916 959 1917 <option value="all_posts" <?php selected($condition_singular, 'all_posts', true); ?>><?php esc_html_e('All Posts', 'masterelements'); ?></option> 960 1918 1919 1920 961 1921 <option value="all_pages" <?php selected($condition_singular, 'all_pages', true); ?>><?php esc_html_e('All Pages', 'masterelements'); ?></option> 962 1922 1923 1924 963 1925 <option value="404page" <?php selected($condition_singular, '404page', true); ?>><?php esc_html_e('404 Page', 'masterelements'); ?></option> 964 1926 1927 1928 965 1929 <option value="selective" <?php selected($condition_singular, 'selective', true); ?>><?php esc_html_e('Selective Singular', 'masterelements'); ?></option> 966 1930 1931 1932 967 1933 </select> 968 1934 1935 1936 969 1937 </div> 970 1938 1939 1940 971 1941 <br> 972 1942 1943 1944 973 1945 <?php 974 1946 1947 1948 975 1949 $display = 'block'; 976 1950 1951 1952 977 1953 if ($condition_singular != 'selective') { 978 1954 1955 1956 979 1957 $display = 'none'; 980 1958 1959 1960 981 1961 } ?> 982 1962 1963 1964 983 1965 <div class="master-template-condition_singular_id-container condition_singular_id" 1966 984 1967 style="display: <?= $display; ?>"> 985 1968 1969 1970 986 1971 <div class="master-input-group"> 987 1972 1973 1974 988 1975 <label class="attr-input-label"><?php echo __('Select Any:', 'masterelements'); ?></label> 989 1976 1977 1978 990 1979 <select style="width:150px;" multiple 1980 991 1981 class="master-template-modalinput-condition_singular_id select2"> 992 1982 1983 1984 993 1985 <?php 994 1986 1987 1988 995 1989 $postids = array(); 996 1990 1991 1992 997 1993 if (!empty($condition_singular_id)) { 998 1994 1995 1996 999 1997 $postids = explode(',', $condition_singular_id); 1000 1998 1999 2000 1001 2001 } 1002 2002 2003 2004 1003 2005 $args = array( 1004 2006 2007 2008 1005 2009 'public' => true, 1006 2010 2011 2012 1007 2013 ); 1008 2014 1009 2015 2016 2017 2018 1010 2019 $output = 'names'; // 'names' or 'objects' (default: 'names') 1011 2020 2021 2022 1012 2023 $operator = 'and'; // 'and' or 'or' (default: 'and') 1013 2024 1014 2025 2026 2027 2028 1015 2029 $post_types = get_post_types($args, $output, $operator); 1016 2030 1017 2031 2032 2033 2034 1018 2035 if ($post_types) { // If there are any custom public post types. 1019 2036 2037 2038 1020 2039 foreach ($post_types as $post_type) { 1021 2040 2041 2042 1022 2043 $args = array( 1023 2044 2045 2046 1024 2047 'numberposts' => -1, 1025 2048 2049 2050 1026 2051 'post_type' => $post_type 1027 2052 2053 2054 1028 2055 ); 1029 2056 2057 2058 1030 2059 $ecpt = array('metemplate', 'elementor_library', 'attachment'); 1031 2060 2061 2062 1032 2063 if (!in_array($post_type, $ecpt)) { 1033 2064 2065 2066 1034 2067 $posts = get_posts($args); 1035 2068 2069 2070 1036 2071 if ($posts) { 1037 2072 2073 2074 1038 2075 foreach ($posts as $post) : 1039 2076 2077 2078 1040 2079 setup_postdata($post); 1041 2080 2081 2082 1042 2083 $selected = ''; 1043 2084 2085 2086 1044 2087 if (in_array($post->ID, $postids)) { 1045 2088 2089 2090 1046 2091 $selected = "selected"; 1047 2092 2093 2094 1048 2095 } 1049 2096 2097 2098 1050 2099 echo '<option value="' . $post->ID . '" ' . $selected . ' >' . $post->post_title . '</option>'; 1051 2100 2101 2102 1052 2103 endforeach; 1053 2104 2105 2106 1054 2107 wp_reset_postdata(); 1055 2108 2109 2110 1056 2111 } 1057 2112 2113 2114 1058 2115 } 1059 2116 2117 2118 1060 2119 } 1061 2120 2121 2122 1062 2123 } 1063 2124 1064 2125 2126 2127 2128 1065 2129 ?> 1066 2130 2131 2132 1067 2133 </select> 1068 2134 1069 2135 2136 2137 2138 1070 2139 </div> 1071 2140 1072 2141 2142 2143 2144 1073 2145 <br/> 1074 2146 2147 2148 1075 2149 </div> 1076 2150 1077 2151 2152 2153 2154 1078 2155 <br> 1079 2156 1080 2157 2158 2159 2160 1081 2161 </div> 1082 2162 1083 2163 2164 2165 2166 1084 2167 <?php 1085 2168 2169 2170 1086 2171 if (isset($_POST) && !empty($_POST) && !empty($_POST['type'] && isset($_POST['counterCondition']))) { 1087 2172 2173 2174 1088 2175 for ($index = 1; $index <= $_POST['counterCondition']; $index++) { 1089 2176 2177 2178 1090 2179 if (isset($_POST['condition_a' . $index])) { 1091 2180 2181 2182 1092 2183 if (metadata_exists('post', $_POST['type'], $_POST['condition_a' . $index])) { 2184 1093 2185 update_post_meta($_POST['type'], 'condition_a' . $index, $_POST['condition_a' . $index]); 1094 2186 2187 2188 1095 2189 } else { 2190 1096 2191 add_post_meta($_POST['type'], 'condition_a' . $index, $_POST['condition_a' . $index]); 1097 2192 2193 2194 1098 2195 } 1099 2196 1100 2197 2198 2199 2200 1101 2201 } 1102 2202 2203 2204 1103 2205 if ($_POST['condition_a' . $index] == 'singular') { 1104 2206 2207 2208 1105 2209 if (isset($_POST['condition_singular' . $index])) { 1106 2210 2211 2212 1107 2213 if (metadata_exists('post', $_POST['type'], $_POST['condition_singular' . $index])) { 1108 2214 2215 2216 1109 2217 update_post_meta($_POST['type'], 'condition_singular' . $index, $_POST['condition_singular' . $index]); 1110 2218 2219 2220 1111 2221 } else { 1112 2222 2223 2224 1113 2225 add_post_meta($_POST['type'], 'condition_singular' . $index, $_POST['condition_singular' . $index]); 1114 2226 2227 2228 1115 2229 } 1116 2230 1117 2231 2232 2233 2234 1118 2235 } 1119 2236 2237 2238 1120 2239 if (isset($_POST['condition_singular_id' . $index])) { 1121 2240 2241 2242 1122 2243 if (metadata_exists('post', $_POST['type'], $_POST['condition_singular_id' . $index])) { 1123 2244 2245 2246 1124 2247 update_post_meta($_POST['type'], 'condition_singular_id', $index, $_POST['condition_singular_id' . $index]); 1125 2248 2249 2250 1126 2251 } else { 1127 2252 2253 2254 1128 2255 add_post_meta($_POST['type'], 'condition_singular_id' . $index, $_POST['condition_singular_id' . $index]); 1129 2256 2257 2258 1130 2259 } 1131 2260 1132 2261 2262 2263 2264 1133 2265 } 1134 2266 2267 2268 1135 2269 } else { 1136 2270 2271 2272 1137 2273 update_post_meta($_POST['type'], 'condition_singular' . $index, ''); 1138 2274 2275 2276 1139 2277 update_post_meta($_POST['type'], 'condition_singular_id' . $index, ''); 1140 2278 2279 2280 1141 2281 } 1142 2282 1143 2283 2284 2285 2286 1144 2287 } 1145 2288 2289 2290 1146 2291 if (metadata_exists('activation', $_POST['type'], $_POST['activation'])) { 1147 2292 2293 2294 1148 2295 update_post_meta($_POST['type'], 'activation', $_POST['activation']); 1149 2296 2297 2298 1150 2299 } else { 1151 2300 2301 2302 1152 2303 add_post_meta($_POST['type'], 'activation', $_POST['activation']); 1153 2304 1154 2305 2306 2307 2308 1155 2309 } 1156 2310 2311 2312 1157 2313 if (metadata_exists('counterCondition', $_POST['type'], $_POST['counterCondition'])) { 1158 2314 2315 2316 1159 2317 update_post_meta($_POST['type'], 'counterCondition', $_POST['counterCondition']); 1160 2318 2319 2320 1161 2321 } else { 1162 2322 2323 2324 1163 2325 add_post_meta($_POST['type'], 'counterCondition', $_POST['counterCondition']); 1164 2326 1165 2327 2328 2329 2330 1166 2331 } 1167 2332 2333 2334 1168 2335 // print_r(get_post_meta($_POST['type'])); 1169 2336 2337 2338 1170 2339 } 1171 2340 2341 2342 1172 2343 // } else { 1173 2344 2345 2346 1174 2347 // echo "Please Select Template"; 1175 2348 2349 2350 1176 2351 // } 1177 2352 2353 2354 1178 2355 if (isset($_POST) && isset($_POST['update']) && !empty($_POST['postmetaids']) && !empty($_POST['postmetatypes'])) { 1179 2356 2357 2358 1180 2359 echo $_POST; 1181 2360 2361 2362 1182 2363 exit(); 1183 2364 2365 2366 1184 2367 } 1185 2368 2369 2370 1186 2371 ?> 1187 2372 1188 2373 2374 2375 2376 1189 2377 <br> 1190 2378 2379 2380 1191 2381 <div class="meta-template-option-listing"> 1192 2382 2383 2384 1193 2385 <table class="table"> 1194 2386 2387 2388 1195 2389 <?php 2390 1196 2391 $args = array( 2392 1197 2393 'post_type' => $_GET['post_type'], 2394 1198 2395 'post_status' => array('publish'), 2396 1199 2397 'order' => 'ASC' 2398 1200 2399 ); 1201 2400 2401 2402 1202 2403 $posts = query_posts($args); 2404 1203 2405 ?> 1204 2406 2407 2408 1205 2409 <tr> 1206 2410 2411 2412 1207 2413 <th><?php echo __('Template', 'masterelements'); ?></th> 1208 2414 2415 2416 1209 2417 <th><?php echo __('Conditions', 'masterelements'); ?></th> 1210 2418 2419 2420 1211 2421 <th><?php echo __('Activation', 'masterelements'); ?></th> 1212 2422 2423 2424 1213 2425 </tr> 1214 2426 2427 2428 1215 2429 <?php 1216 2430 2431 2432 1217 2433 if ($posts) { 1218 2434 2435 2436 1219 2437 foreach ($posts as $post) : 1220 2438 2439 2440 1221 2441 setup_postdata($post); 2442 1222 2443 ?> 1223 2444 1224 2445 2446 2447 2448 1225 2449 <tr> 2450 1226 2451 <td> <?= $post->post_title ?></td> 2452 1227 2453 <td> 1228 2454 2455 2456 1229 2457 <?php $conditionCounter = get_post_meta($post->ID, 'counterCondition', true); 1230 2458 2459 2460 1231 2461 for ($index = 1; $index <= $conditionCounter; $index++) { 1232 2462 2463 2464 1233 2465 $ca = 'condition_a' . $index; 1234 2466 2467 2468 1235 2469 $cs = 'condition_singular' . $index; 1236 2470 2471 2472 1237 2473 $csid = 'condition_singular_id' . $index; 1238 2474 2475 2476 1239 2477 echo $cad = get_post_meta($post->ID, $ca, true); 1240 2478 2479 2480 1241 2481 $cr = get_post_meta($post->ID, $cs, true); 1242 2482 2483 2484 1243 2485 // echo '<pre>'.print_r($cr,true).'</pre>'; 1244 2486 2487 2488 1245 2489 if ($cad === 'singular' && !empty($cr)) { 1246 2490 2491 2492 1247 2493 echo ' > ' . $cr; 1248 2494 2495 2496 1249 2497 } 1250 2498 2499 2500 1251 2501 if ($cr == 'selective') { 1252 2502 2503 2504 1253 2505 print_r(' > ' . implode(',', get_post_meta($post->ID, $csid, true))); 1254 2506 2507 2508 1255 2509 } 1256 2510 2511 2512 1257 2513 if (!empty($cad) || !empty($cr) || !empty(get_post_meta($post->ID, $csid, true))) { 1258 2514 2515 2516 1259 2517 echo '<div class="mastter-post-metaids"> 1260 2518 2519 2520 1261 2521 <input type="hidden" class="templatePostMetaIds" value="' . self::get_mid_by_key($post->ID, 'condition_a' . $index) . ',' . self::get_mid_by_key($post->ID, 'condition_singular' . $index) . ',' . self::get_mid_by_key($post->ID, 'condition_singular_id' . $index) . '"> 1262 2522 2523 2524 1263 2525 1264 2526 2527 2528 1265 2529 <input type="hidden" class="templatePostMetatypes" value="condition_a' . $index . ',condition_singular' . $index . ',condition_singular_id' . $index . '"> 1266 2530 2531 2532 1267 2533 <button class="editPostcondition btn btn-primary btn xs" id="editPostcondition" type="button">Edit</button> 1268 2534 2535 2536 1269 2537 <button id="removePostcondition" class="removePostcondition btn btn-danger btn-xs" type="button">Remove</button></div>'; 1270 2538 1271 2539 2540 2541 2542 1272 2543 //$var = self::get_complete_meta(152); 1273 2544 2545 2546 1274 2547 // echo $var[0]->meta_value; 1275 2548 2549 2550 1276 2551 } 1277 2552 2553 2554 1278 2555 echo '<br>'; 1279 2556 2557 2558 1280 2559 } 1281 2560 2561 2562 1282 2563 //$activation = (isset($settings[$type['id']]['name']) &&$settings[$type['id']]['name'] = $type['id'])?$settings[$type['id']]['value']:'no'; 1283 2564 2565 2566 1284 2567 // echo '<pre>'. $activation.'<pre>'; 1285 2568 2569 2570 1286 2571 $activation = get_post_meta($post->ID, 'activation', true); 1287 2572 1288 2573 2574 2575 2576 1289 2577 ?> 1290 2578 2579 2580 1291 2581 </td> 2582 1292 2583 <td> 1293 2584 2585 2586 1294 2587 <div class="master-switch-group"> 1295 2588 2589 2590 1296 2591 <label class="attr-input-label"><?php esc_html_e('Activation:', 'masterelements'); ?></label> 1297 2592 2593 2594 1298 2595 <div class="master-admin-input-switch2"> 1299 2596 2597 2598 1300 2599 <input type="checkbox" value="<?= $activation; ?>" 2600 1301 2601 data-id="<?= $post->ID; ?>" 2602 1302 2603 class="master-admin-control-input master-filed-activation master-template-activition master-active-<?= $activation; ?>" 2604 1303 2605 name="activation_val"> 1304 2606 2607 2608 1305 2609 <label class="master-admin-control-label" 2610 1306 2611 for="master_activation_modal_input"> 1307 2612 2613 2614 1308 2615 <span class="master-admin-control-label-switch" data-active="ON" 1309 2616 2617 2618 1310 2619 data-inactive="OFF"></span> 1311 2620 2621 2622 1312 2623 </label> 1313 2624 2625 2626 1314 2627 <input type="hidden" name="type" class="post_id_<?= $post->ID; ?>" 2628 1315 2629 value="<?= $post->ID; ?>"> 1316 2630 2631 2632 1317 2633 <input type="hidden" class="activation_filed_<?= $post->ID; ?>" 2634 1318 2635 name="activation" 1319 2636 2637 2638 1320 2639 value="<?= (!empty($activation) ? $activation : 'yes?no'); ?>"> 1321 2640 2641 2642 1322 2643 </div> 2644 1323 2645 </div> 2646 1324 2647 </td> 2648 1325 2649 </tr> 1326 2650 2651 2652 1327 2653 <?php endforeach; 1328 2654 2655 2656 1329 2657 wp_reset_postdata(); 1330 2658 1331 2659 2660 2661 2662 1332 2663 } 1333 2664 2665 2666 1334 2667 ?> 1335 2668 2669 2670 1336 2671 </table> 1337 2672 1338 2673 2674 2675 2676 1339 2677 <!-- Link to open the modal --> 1340 2678 2679 2680 1341 2681 <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> 1342 2682 2683 2684 1343 2685 <div class="modal-dialog" role="document"> 1344 2686 2687 2688 1345 2689 <div class="modal-content"> 1346 2690 2691 2692 1347 2693 <div class="modal-header"> 1348 2694 2695 2696 1349 2697 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span 2698 1350 2699 aria-hidden="true">×</span></button> 1351 2700 2701 2702 1352 2703 <h4 class="modal-title" 2704 1353 2705 id="myModalLabel"><?php echo __('Update Condition', 'masterelements'); ?></h4> 1354 2706 2707 2708 1355 2709 </div> 1356 2710 2711 2712 1357 2713 <div class="modal-body"> 1358 2714 1359 2715 2716 2717 2718 1360 2719 <?php 1361 2720 2721 2722 1362 2723 ?> 1363 2724 2725 2726 1364 2727 <div class="master-template-option-container modal-parent-container"> 1365 2728 2729 2730 1366 2731 <input type="hidden" class="postmetaidsvalues" id="postmetaids" name="postmetaids" 2732 1367 2733 value=""> 1368 2734 2735 2736 1369 2737 <input type="hidden" class="postmetaidsvalues" id="postmetatypes" 2738 1370 2739 name="postmetatypes" 2740 1371 2741 value=""> 1372 2742 2743 2744 1373 2745 <div class="master-input-group"> 1374 2746 2747 2748 1375 2749 <label class="attr-input-label"><?php esc_html_e('Conditions:', 'masterelements'); ?></label> 1376 2750 2751 2752 1377 2753 <select name="condition_a" id="master-template-condition_a_popup" 2754 1378 2755 class="master-template-condition_a attr-form-control"> 1379 2756 2757 2758 1380 2759 </select> 1381 2760 2761 2762 1382 2763 </div> 1383 2764 1384 2765 2766 2767 2768 1385 2769 <?php 1386 2770 2771 2772 1387 2773 // $display = 'block'; 1388 2774 2775 2776 1389 2777 // if($condition_a!='singular'){ 1390 2778 2779 2780 1391 2781 // $display = 'none'; 1392 2782 2783 2784 1393 2785 // } 2786 1394 2787 ?> 1395 2788 2789 2790 1396 2791 <div class="master-input-group condition_singular" 2792 1397 2793 id="master-template-condition_singular-container"> 1398 2794 2795 2796 1399 2797 <label class="attr-input-label"><?php echo __('Select Any', 'masterelements'); ?></</label> 1400 2798 2799 2800 1401 2801 <select name="condition_singular" 2802 1402 2803 class="master-template-condition_singular attr-form-control" 2804 1403 2805 id="master-template-condition_singular_popup"> 1404 2806 2807 2808 1405 2809 </select> 1406 2810 2811 2812 1407 2813 </div> 1408 2814 2815 2816 1409 2817 <br> 1410 2818 2819 2820 1411 2821 <?php 1412 2822 2823 2824 1413 2825 // $display = 'block'; 1414 2826 2827 2828 1415 2829 // if($condition_singular!='selective'){ 1416 2830 2831 2832 1417 2833 // $display = 'none'; 1418 2834 2835 2836 1419 2837 // } 2838 1420 2839 ?> 1421 2840 2841 2842 1422 2843 <div class="master-template-condition_singular_id-container condition_singular_id" 2844 1423 2845 id="master-template-condition_singular_id-container"> 1424 2846 2847 2848 1425 2849 <div class="master-input-group"> 1426 2850 2851 2852 1427 2853 <label class="attr-input-label"><?php echo __('Select Any', 'masterelements'); ?></</label> 1428 2854 2855 2856 1429 2857 <select name="condition_singular_id" style="width:150px;" multiple 2858 1430 2859 class="master-template-modalinput-condition_singular_id select2" 2860 1431 2861 id="master-template-condition_singular_id_popup"> 1432 2862 1433 2863 2864 2865 2866 1434 2867 </select> 1435 2868 2869 2870 1436 2871 </div> 1437 2872 2873 2874 1438 2875 <br/> 1439 2876 2877 2878 1440 2879 </div> 1441 2880 2881 2882 1442 2883 <br> 1443 2884 2885 2886 1444 2887 <button type="button" class="btn btn-primary update_post_condition_modal" 2888 1445 2889 name="update" 2890 1446 2891 value="Update">Update 2892 1447 2893 </button> 1448 2894 1449 2895 2896 2897 2898 1450 2899 </div> 2900 1451 2901 </div> 1452 2902 2903 2904 1453 2905 <div class="modal-footer"> 1454 2906 2907 2908 1455 2909 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 1456 2910 1457 2911 2912 2913 2914 1458 2915 </div> 1459 2916 2917 2918 1460 2919 </div> 1461 2920 2921 2922 1462 2923 </div> 1463 2924 2925 2926 1464 2927 </div> 1465 2928 2929 2930 1466 2931 </div> 1467 2932 2933 2934 1468 2935 <?php 2936 1469 2937 } 1470 2938 1471 2939 2940 2941 2942 1472 2943 function get_mid_by_key($post_id, $meta_key) 2944 1473 2945 { 1474 2946 2947 2948 1475 2949 global $wpdb; 1476 2950 2951 2952 1477 2953 $mid = $wpdb->get_var($wpdb->prepare("SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s", $post_id, $meta_key)); 1478 2954 2955 2956 1479 2957 if ($mid != '') 1480 2958 2959 2960 1481 2961 return (int)$mid; 1482 2962 1483 2963 2964 2965 2966 1484 2967 return 0; 1485 2968 2969 2970 1486 2971 } 1487 2972 2973 2974 1488 2975 function get_complete_meta($meta_id) 2976 1489 2977 { 1490 2978 2979 2980 1491 2981 global $wpdb; 1492 2982 2983 2984 1493 2985 $data = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->postmeta WHERE meta_id = $meta_id")); 1494 2986 2987 2988 1495 2989 // echo "<pre>".print_r($data[0],true)."</pre>"; 1496 2990 1497 2991 2992 2993 2994 1498 2995 if ($data != '') { 1499 2996 2997 2998 1500 2999 return $data; 1501 3000 3001 3002 1502 3003 } else { 1503 3004 3005 3006 1504 3007 return false; 1505 3008 3009 3010 1506 3011 } 1507 3012 1508 3013 3014 3015 3016 1509 3017 } 1510 3018 1511 3019 3020 3021 3022 1512 3023 function load_canvas_template($single_template) 3024 1513 3025 { 1514 3026 1515 3027 3028 3029 3030 1516 3031 global $post; 1517 3032 3033 3034 1518 3035 $posttypes = $template_types = $this->register_sections(); 1519 3036 3037 3038 1520 3039 foreach ($posttypes as $posttype) 1521 3040 3041 3042 1522 3043 if ($posttype['id'] == $post->post_type) { 1523 3044 1524 3045 3046 3047 3048 1525 3049 $elementor_2_0_canvas = ELEMENTOR_PATH . '/modules/page-templates/templates/canvas.php'; 1526 3050 1527 3051 3052 3053 3054 1528 3055 if (file_exists($elementor_2_0_canvas)) { 1529 3056 3057 3058 1530 3059 return $elementor_2_0_canvas; 1531 3060 3061 3062 1532 3063 } else { 1533 3064 3065 3066 1534 3067 return ELEMENTOR_PATH . '/includes/page-templates/canvas.php'; 1535 3068 3069 3070 1536 3071 } 1537 3072 3073 3074 1538 3075 } 1539 3076 1540 3077 3078 3079 3080 1541 3081 return $single_template; 1542 3082 3083 3084 1543 3085 } 1544 3086 3087 3088 1545 3089 function register_sections() 3090 1546 3091 { 1547 3092 3093 3094 1548 3095 return $posttypes = [ 1549 3096 3097 3098 1550 3099 'header' => [ 1551 3100 3101 3102 1552 3103 'name' => 'Header', 1553 3104 3105 3106 1554 3107 'id' => 'me_header', 1555 3108 3109 3110 1556 3111 'd_addons' => array('site_navigation'), 1557 3112 3113 3114 1558 3115 'single' => 'Header Template', 1559 3116 3117 3118 1560 3119 'icon' => \MasterElements::assets_url() . 'images/icons/header.png', 1561 3120 3121 3122 1562 3123 'item' => 'Header', 1563 3124 3125 3126 1564 3127 ], 1565 3128 3129 3130 1566 3131 'footer' => [ 1567 3132 3133 3134 1568 3135 'name' => 'Footer', 1569 3136 3137 3138 1570 3139 'id' => 'me_footer', 1571 3140 3141 3142 1572 3143 'd_addons' => array(''), 1573 3144 3145 3146 1574 3147 'single' => 'Footer Template', 1575 3148 3149 3150 1576 3151 'icon' => \MasterElements::assets_url() . 'images/icons/footer.png', 1577 3152 3153 3154 1578 3155 'item' => 'Footer', 1579 3156 3157 3158 1580 3159 ], 1581 3160 3161 3162 1582 3163 'archive' => [ 1583 3164 3165 3166 1584 3167 'name' => 'Archive', 1585 3168 3169 3170 1586 3171 'id' => 'me_archive', 1587 3172 3173 3174 1588 3175 'd_addons' => array(''), 1589 3176 3177 3178 1590 3179 'single' => 'Archive Template', 1591 3180 3181 3182 1592 3183 'icon' => \MasterElements::assets_url() . 'images/icons/archive.png', 1593 3184 3185 3186 1594 3187 'item' => 'Archive', 1595 3188 3189 3190 1596 3191 ], 1597 3192 3193 3194 1598 3195 'single' => [ 1599 3196 3197 3198 1600 3199 'name' => 'Single', 1601 3200 3201 3202 1602 3203 'id' => 'me_single', 1603 3204 3205 3206 1604 3207 'd_addons' => array(''), 1605 3208 3209 3210 1606 3211 'single' => 'Single Template', 1607 3212 3213 3214 1608 3215 'icon' => \MasterElements::assets_url() . 'images/icons/single.png', 1609 3216 3217 3218 1610 3219 'item' => 'Single', 1611 3220 3221 3222 1612 3223 ], 1613 3224 3225 3226 1614 3227 '404' => [ 1615 3228 3229 3230 1616 3231 'name' => '404', 1617 3232 3233 3234 1618 3235 'id' => 'me_404', 1619 3236 3237 3238 1620 3239 'd_addons' => array(''), 1621 3240 3241 3242 1622 3243 'single' => '404 Template', 1623 3244 3245 3246 1624 3247 'icon' => \MasterElements::assets_url() . 'images/icons/404.png', 1625 3248 3249 3250 1626 3251 'item' => '404', 1627 3252 3253 3254 1628 3255 ], 1629 3256 3257 3258 1630 3259 'blog' => [ 1631 3260 3261 3262 1632 3263 'name' => 'Blog Page', 1633 3264 3265 3266 1634 3267 'id' => 'me_blog', 1635 3268 3269 3270 1636 3271 'd_addons' => array(''), 1637 3272 3273 3274 1638 3275 'single' => 'Blog Template', 1639 3276 3277 3278 1640 3279 'icon' => \MasterElements::assets_url() . 'images/icons/blog.png', 1641 3280 3281 3282 1642 3283 'item' => 'Blog', 1643 3284 3285 3286 1644 3287 ], 1645 3288 3289 3290 1646 3291 'Maintenance' => [ 1647 3292 3293 3294 1648 3295 'name' => 'Under Maintenance', 1649 3296 3297 3298 1650 3299 'id' => 'me_maintenance', 1651 3300 3301 3302 1652 3303 'd_addons' => array(''), 1653 3304 3305 3306 1654 3307 'single' => 'Maintenance Template', 1655 3308 3309 3310 1656 3311 'icon' => \MasterElements::assets_url() . 'images/icons/maintenance.png', 1657 3312 3313 3314 1658 3315 'item' => 'Maintenance', 1659 3316 3317 3318 1660 3319 ], 1661 3320 3321 3322 1662 3323 'Section' => [ 1663 3324 3325 3326 1664 3327 'name' => 'Section', 1665 3328 3329 3330 1666 3331 'id' => 'me_section', 1667 3332 3333 3334 1668 3335 'd_addons' => array(''), 1669 3336 3337 3338 1670 3339 'single' => 'Section Template', 1671 3340 3341 3342 1672 3343 'icon' => \MasterElements::assets_url() . 'images/icons/section.png', 1673 3344 3345 3346 1674 3347 'item' => 'Section', 1675 3348 3349 3350 1676 3351 ], 1677 3352 3353 3354 1678 3355 'Search' => [ 1679 3356 3357 3358 1680 3359 'name' => 'Search', 1681 3360 3361 3362 1682 3363 'id' => 'me_search', 1683 3364 3365 3366 1684 3367 'd_addons' => array(''), 1685 3368 3369 3370 1686 3371 'single' => 'Search Template', 1687 3372 3373 3374 1688 3375 'icon' => \MasterElements::assets_url() . 'images/icons/search.png', 1689 3376 3377 3378 1690 3379 'item' => 'Search', 1691 3380 3381 3382 1692 3383 ], 1693 3384 3385 3386 1694 3387 'Coming Soon' => [ 1695 3388 3389 3390 1696 3391 'name' => 'Coming Soon', 1697 3392 3393 3394 1698 3395 'id' => 'me_comingsoon', 1699 3396 3397 3398 1700 3399 'd_addons' => array(''), 1701 3400 3401 3402 1702 3403 'single' => 'Coming Soon Template', 1703 3404 3405 3406 1704 3407 'icon' => \MasterElements::assets_url() . 'images/icons/coming_soon.png', 1705 3408 3409 3410 1706 3411 'item' => 'Coming Soon', 1707 3412 3413 3414 1708 3415 ], 1709 3416 3417 3418 1710 3419 'Mega Menu' => [ 1711 3420 3421 3422 1712 3423 'name' => 'Mega Menu', 1713 3424 3425 3426 1714 3427 'id' => 'me_megamenu', 1715 3428 3429 3430 1716 3431 'd_addons' => array(''), 1717 3432 3433 3434 1718 3435 'single' => 'Mega Menu Template', 1719 3436 3437 3438 1720 3439 'icon' => \MasterElements::assets_url() . 'images/icons/coming_soon.png', 1721 3440 3441 3442 1722 3443 'item' => 'Mega Menu', 1723 3444 3445 3446 1724 3447 ], 1725 3448 3449 3450 1726 3451 'Nested Sections' => [ 1727 3452 3453 3454 1728 3455 'name' => 'Nested Sections', 1729 3456 3457 3458 1730 3459 'id' => 'me_nested_sections', 1731 3460 3461 3462 1732 3463 'd_addons' => array(''), 1733 3464 3465 3466 1734 3467 'single' => 'Nested Sections', 1735 3468 3469 3470 1736 3471 //'icon' => \MasterElements::assets_url() . 'images/icons/woo.png', 1737 3472 3473 3474 1738 3475 'item' => 'Nested Sections', 3476 1739 3477 ], 1740 3478 3479 3480 1741 3481 'Woocommerce Page' => [ 1742 3482 3483 3484 1743 3485 'name' => 'WooCommerce Page', 1744 3486 3487 3488 1745 3489 'id' => 'me_wooproduct', 1746 3490 3491 3492 1747 3493 'd_addons' => array('me_woo_products'), 1748 3494 3495 3496 1749 3497 'single' => 'Wooproduct Template', 1750 3498 3499 3500 1751 3501 //'icon' => \MasterElements::assets_url() . 'images/icons/woo.png', 1752 3502 3503 3504 1753 3505 'item' => 'WooCommerce Page', 3506 1754 3507 ], 1755 3508 1756 3509 3510 3511 3512 1757 3513 ]; 1758 3514 3515 3516 1759 3517 } 1760 3518 3519 3520 1761 3521 // Create table For Theme Builder Settings 1762 3522 3523 3524 1763 3525 function create_table() 3526 1764 3527 { 1765 3528 3529 3530 1766 3531 global $wpdb; 1767 3532 3533 3534 1768 3535 require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 1769 3536 1770 3537 3538 3539 3540 1771 3541 /************* Creating Fileds table ************/ 1772 3542 3543 3544 1773 3545 $table_name1 = $wpdb->prefix . "me_settings"; 1774 3546 3547 3548 1775 3549 if ($wpdb->get_var("show tables like '" . $table_name1 . "'") != $table_name1) { 1776 3550 3551 3552 1777 3553 $sql = "CREATE TABLE " . $table_name1 . "( 1778 3554 3555 3556 1779 3557 id int(11) NOT NULL AUTO_INCREMENT, 1780 3558 3559 3560 1781 3561 name VARCHAR(255) NOT NULL, 1782 3562 3563 3564 1783 3565 value VARCHAR(20) NOT NULL, 1784 3566 3567 3568 1785 3569 PRIMARY KEY (id) 1786 3570 3571 3572 1787 3573 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=0; "; 1788 3574 1789 3575 3576 3577 3578 1790 3579 dbDelta($sql); 1791 3580 3581 3582 1792 3583 } 1793 3584 3585 3586 1794 3587 } 1795 3588 3589 3590 1796 3591 // Retrieve data Theme Builder Settings table 1797 3592 3593 3594 1798 3595 function get_main_settings_data() 1799 3596 3597 3598 1800 3599 { 3600 1801 3601 global $wpdb; 1802 3602 3603 3604 1803 3605 $fields_table_name = $wpdb->prefix . "me_settings"; 1804 3606 3607 3608 1805 3609 $query = "SELECT * FROM " . $fields_table_name; 1806 3610 3611 3612 1807 3613 $ds = $wpdb->get_results($query, ARRAY_A); 3614 1808 3615 $data = []; 1809 3616 3617 3618 1810 3619 foreach ($ds as $d) { 1811 3620 3621 3622 1812 3623 $data[$d['name']] = $d; 1813 3624 3625 3626 1814 3627 } 1815 3628 3629 3630 1816 3631 return $data; 3632 1817 3633 } 1818 3634 3635 3636 1819 3637 // Save data for Theme Builder Settings table 1820 3638 3639 3640 1821 3641 function save_me_settings() 3642 1822 3643 { 3644 1823 3645 global $wpdb; 3646 1824 3647 $table_name = $wpdb->prefix . "me_settings"; 1825 3648 3649 3650 1826 3651 if ($_GET['addon'] != '') { 3652 1827 3653 $status_arr = explode(',', $_GET['addon']); 3654 1828 3655 $status_arr[count($status_arr)] = $_GET['type']; 3656 1829 3657 } else { 3658 1830 3659 $status_arr[0] = $_GET['type']; 3660 1831 3661 } 1832 3662 3663 3664 1833 3665 for ($i = 0; $i < count($status_arr); $i++) { 3666 1834 3667 $total = $wpdb->get_var("SELECT count(*) FROM " . $table_name . " where name='" . $status_arr[$i] . "'"); 1835 3668 3669 3670 1836 3671 if ($total < 1) { 1837 3672 3673 3674 1838 3675 $wpdb->query($wpdb->prepare("INSERT INTO " . $table_name . " (name,value) VALUES (%s,%s)", $status_arr[$i], $_GET['status'])); 1839 3676 3677 3678 1840 3679 } else { 1841 3680 3681 3682 1842 3683 $wpdb->update( 1843 3684 3685 3686 1844 3687 $table_name, 1845 3688 3689 3690 1846 3691 array( 1847 3692 3693 3694 1848 3695 'value' => stripslashes($_GET['status']), 1849 3696 3697 3698 1850 3699 ), 1851 3700 3701 3702 1852 3703 array('name' => $status_arr[$i]), 1853 3704 3705 3706 1854 3707 array( 1855 3708 3709 3710 1856 3711 '%s', 1857 3712 3713 3714 1858 3715 ) 1859 3716 3717 3718 1860 3719 ); 1861 3720 3721 3722 1862 3723 } 3724 1863 3725 } 1864 3726 3727 3728 1865 3729 echo json_encode(array('status' => 'success', 'msg' => 'Settings Updated')); 1866 3730 3731 3732 1867 3733 wp_die(); 1868 3734 1869 3735 3736 3737 3738 1870 3739 } 1871 3740 1872 3741 3742 3743 3744 1873 3745 function remove_post_meta_condition() 1874 3746 3747 3748 1875 3749 { 1876 3750 3751 3752 1877 3753 // echo $_GET['meta_ids']; 1878 3754 3755 3756 1879 3757 global $wpdb; 1880 3758 3759 3760 1881 3761 $table_name = $wpdb->prefix . "postmeta"; 1882 3762 3763 3764 1883 3765 $wpdb->get_var("DELETE FROM " . $table_name . " where meta_id IN (" . $_GET['meta_ids'] . ")"); 1884 3766 3767 3768 1885 3769 echo "Post Meta Setting Deleted Successfully"; 1886 3770 3771 3772 1887 3773 wp_die(); 1888 3774 1889 3775 3776 3777 3778 1890 3779 } 1891 3780 3781 3782 1892 3783 function activation_updated() 1893 3784 3785 3786 1894 3787 { 1895 3788 3789 3790 1896 3791 $post_id = $_REQUEST['meta_ids']; 1897 3792 3793 3794 1898 3795 global $wpdb; 1899 3796 3797 3798 1900 3799 $tablename = $wpdb->prefix . "postmeta"; 1901 3800 3801 3802 1902 3803 $status = $_REQUEST['status']; 1903 3804 3805 3806 1904 3807 echo $sql = "UPDATE `$tablename` SET `meta_value`='" . $status . "' WHERE meta_key = 'activation' AND post_id =" . $post_id; 1905 3808 3809 3810 1906 3811 $wpdb->query($wpdb->prepare($sql)); 1907 3812 3813 3814 1908 3815 echo 'data updated'; 1909 3816 3817 3818 1910 3819 wp_die(); 1911 3820 1912 3821 3822 3823 3824 1913 3825 } 1914 3826 3827 3828 1915 3829 function add_new_columns($columns) 3830 1916 3831 { 3832 1917 3833 return array_merge($columns, 1918 3834 3835 3836 1919 3837 array('type' => __('Status'), 1920 3838 3839 3840 1921 3841 'condition' => __('Condition'))); 1922 3842 3843 3844 1923 3845 } 1924 3846 3847 3848 1925 3849 function custom_column_data($column) 3850 1926 3851 { 1927 3852 3853 3854 1928 3855 global $post; 3856 1929 3857 global $p_count; 3858 1930 3859 $p_count++; 3860 1931 3861 //$c = count1(0); 3862 1932 3863 //echo '<pre>$Count'. $p_count++ .'</pre>'; 3864 1933 3865 if ($column == 'type' && $p_count % 2 == 0) { 3866 1934 3867 $activation = get_post_meta($post->ID, 'activation', true); 3868 1935 3869 echo '<span class="master-status master-status-' . ($activation == 'yes' ? 'active' : 'inactive') . '">' . ($activation == 'yes' ? 'Active' : 'Inactive') . '</span>'; 3870 1936 3871 $p_count++; 1937 3872 3873 3874 1938 3875 } elseif ($column == 'condition' && $p_count % 2 != 0) { 3876 1939 3877 $conditionCounter = get_post_meta($post->ID, 'counterCondition', true); 1940 3878 3879 3880 1941 3881 for ($index = 1; $index <= $conditionCounter; $index++) { 1942 3882 3883 3884 1943 3885 echo $condition_a = get_post_meta($post->ID, 'condition_a' . $index, true); 1944 3886 3887 3888 1945 3889 $condition_singular = get_post_meta($post->ID, 'condition_singular' . $index, true); 1946 3890 3891 3892 1947 3893 if ($condition_a == 'singular') { 1948 3894 3895 3896 1949 3897 echo ' > ' . $condition_singular; 1950 3898 3899 3900 1951 3901 } 1952 3902 3903 3904 1953 3905 if ($condition_singular == 'selective') { 1954 3906 3907 3908 1955 3909 print_r(' > ' . implode(',', get_post_meta($post->ID, 'condition_singular_id' . $index, true))); 1956 3910 3911 3912 1957 3913 } 1958 3914 3915 3916 1959 3917 echo '<br>'; 1960 3918 3919 3920 1961 3921 } 3922 1962 3923 $p_count++; 1963 3924 1964 3925 3926 3927 3928 1965 3929 } 3930 1966 3931 /* switch ($column) { 1967 3932 3933 3934 1968 3935 case 'type': 1969 3936 3937 3938 1970 3939 //echo get_post_meta($post->ID, 'type', true); 3940 1971 3941 $activation = get_post_meta($post->ID, 'activation', true); 3942 1972 3943 echo '<span id = " '. $c . ' " class="master-status master-status-' . ($activation == 'yes' ? 'active' : 'inactive') . '">' . ($activation == 'yes' ? 'Active' : 'Inactive') . '</span>'; 1973 3944 3945 3946 1974 3947 break; 1975 3948 3949 3950 1976 3951 case 'condition': 1977 3952 3953 3954 1978 3955 //echo get_post_meta( $post->ID , 'c' , true ); 1979 3956 3957 3958 1980 3959 $conditionCounter = get_post_meta($post->ID, 'counterCondition', true); 1981 3960 3961 3962 1982 3963 for ($index = 1; $index <= $conditionCounter; $index++) { 1983 3964 3965 3966 1984 3967 echo $condition_a = get_post_meta($post->ID, 'condition_a' . $index, true); 1985 3968 3969 3970 1986 3971 $condition_singular = get_post_meta($post->ID, 'condition_singular' . $index, true); 1987 3972 3973 3974 1988 3975 if ($condition_a == 'singular') { 1989 3976 3977 3978 1990 3979 echo ' > ' . $condition_singular; 1991 3980 3981 3982 1992 3983 } 1993 3984 3985 3986 1994 3987 if ($condition_singular == 'selective') { 1995 3988 3989 3990 1996 3991 print_r(' > ' . implode(',', get_post_meta($post->ID, 'condition_singular_id' . $index, true))); 1997 3992 3993 3994 1998 3995 } 1999 3996 3997 3998 2000 3999 echo '<br>'; 2001 4000 4001 4002 2002 4003 } 2003 4004 2004 4005 4006 4007 4008 2005 4009 break; 2006 4010 4011 4012 2007 4013 }*/ 2008 4014 4015 4016 2009 4017 } 2010 4018 4019 4020 2011 4021 function check_module_active() 4022 2012 4023 { 4024 2013 4025 global $wpdb; 4026 2014 4027 $table_name = $wpdb->prefix . "me_settings"; 4028 2015 4029 $result = $wpdb->get_row("SELECT * FROM " . $table_name . " where name='" . $_GET['module'] . "'"); 4030 2016 4031 $status = ($result->value == 'yes') ? 'yes' : 'no'; 4032 2017 4033 echo $status; 4034 2018 4035 die; 4036 2019 4037 } 2020 4038 4039 4040 2021 4041 function get_menu_template() 4042 2022 4043 { 4044 2023 4045 global $wpdb; 4046 2024 4047 $table_name = $wpdb->prefix . "posts"; 4048 2025 4049 $postslist = $wpdb->get_results ( 4050 2026 4051 " SELECT * FROM " . $table_name ." WHERE post_type = 'me_megamenu' AND post_status = 'publish' ORDER by post_title " ); 4052 2027 4053 $data = array(); 4054 2028 4055 foreach ($postslist as $key => $post) { 4056 2029 4057 $menu = explode('menu-item-', $_GET['menu']); 2030 $result = $wpdb->get_row("SELECT * FROM " . $table_name . " where post_id='" . $menu[1] . "'" . " AND meta_value='" . $post->ID . "'"); 4058 2031 4059 $data[$key]['ID'] = $post->ID; 4060 2032 4061 $data[$key]['post_title'] = $post->post_title; 2033 $data[$key]['menu_item'] = $result->post_id;4062 2034 4063 } 4064 2035 4065 echo json_encode($data, true); 4066 2036 4067 die; 4068 2037 4069 } 2038 4070 4071 4072 2039 4073 function save_menu_postmeta() 4074 2040 4075 { 4076 2041 4077 $menu = explode('menu-item-', $_POST['menu_id']); 4078 2042 4079 if (get_post_meta($menu[1])) { 4080 2043 4081 update_post_meta($menu[1], 'me_megamenu_item', $_POST['megamenu_id']); 4082 2044 4083 } else { 4084 2045 4085 add_post_meta($menu[1], 'me_megamenu_item', $_POST['megamenu_id']); 4086 2046 4087 } 4088 2047 4089 die; 4090 2048 4091 } 2049 4092 4093 4094 2050 4095 function get_megamenu_control() 4096 2051 4097 { 4098 2052 4099 global $wpdb; 4100 2053 4101 $table_name = $wpdb->prefix . "me_settings"; 4102 2054 4103 $menu = $wpdb->get_row("SELECT * FROM " . $table_name . " where name='" . $_GET['menu'] . "'"); 4104 2055 4105 echo json_encode($menu, true); 4106 2056 4107 die; 4108 2057 4109 } 2058 4110 4111 4112 2059 4113 function demo_data_import() 4114 2060 4115 { 4116 2061 4117 if ($_POST['url'] && $_POST['post_type']) { 4118 2062 4119 $api = new Api(); 4120 2063 4121 $api->render_widget($_POST['url'], $_POST['post_type']); 4122 2064 4123 } 4124 2065 4125 die; 4126 2066 4127 } 2067 4128 4129 4130 2068 4131 function get_cat_data() 4132 2069 4133 { 4134 2070 4135 $categoryTemplates = []; 4136 2071 4137 if (isset($_POST['category'])) { 4138 2072 4139 $demo_data_listing_url = 'http://demo.designingmedia.com/master-demo/template-categories.json'; 4140 2073 4141 $data = file_get_contents($demo_data_listing_url); 4142 2074 4143 $data = json_decode($data); 2075 4144 4145 4146 2076 4147 foreach ($data as $k => $d) { 4148 2077 4149 if ($k == $_POST['category']) { 4150 2078 4151 $categoryTemplates = $d; 4152 2079 4153 } 4154 2080 4155 } 4156 2081 4157 } 2082 4158 4159 4160 2083 4161 echo json_encode($categoryTemplates, true); 4162 2084 4163 die; 4164 2085 4165 } 2086 4166 4167 4168 2087 4169 function send_feedback() 4170 2088 4171 { 4172 2089 4173 //user posted variables 4174 2090 4175 $name = $_POST['name']; 4176 2091 4177 $email = $_POST['email']; 4178 2092 4179 $website = $_POST['website']; 4180 2093 4181 $comment = $_POST['comment']; 2094 4182 4183 4184 2095 4185 //php mailer variables 4186 2096 4187 $to = get_option('admin_email'); 4188 2097 4189 $subject = "Masterelement Feedback"; 4190 2098 4191 $headers = 'From: ' . $email . "\r\n" . 4192 2099 4193 'Reply-To: ' . $email . "\r\n"; 2100 4194 4195 4196 2101 4197 $body = 'Name: ' . $name . "\r\n" . 4198 2102 4199 'Email: ' . $email . "\r\n" . 4200 2103 4201 'Website: ' . $website . "\r\n" . 4202 2104 4203 'Message: ' . $comment . "\r\n"; 2105 4204 4205 4206 2106 4207 //Here put your Validation and send mail 4208 2107 4209 $sent = wp_mail($to, $subject, strip_tags($body), $headers); 4210 2108 4211 if ($sent) { 4212 2109 4213 echo 'Sent'; 4214 2110 4215 }//message sent! 4216 2111 4217 else { 4218 2112 4219 echo 'Not Sent'; 4220 2113 4221 }//message wasn't sent 2114 4222 4223 4224 2115 4225 die; 4226 2116 4227 } 2117 4228 4229 4230 2118 4231 function custom_submit_form() 4232 2119 4233 { 4234 2120 4235 $body = ''; 4236 2121 4237 if ($_POST['fileds']) { 4238 2122 4239 $fields = explode('&', $_POST['fileds']); 4240 2123 4241 foreach ($fields as $k => $v) { 4242 2124 4243 if ($v !== 'form_id=2fad637') { 4244 2125 4245 $body = ' ' . $v . "\r\n"; 4246 2126 4247 } 4248 2127 4249 } 4250 2128 4251 } 2129 4252 4253 4254 2130 4255 wp_mail(get_option('admin_email'), 'Contact Query', $body); 4256 2131 4257 wp_send_json_success(__('Thanks for reporting !', 'masterelements')); 4258 2132 4259 wp_die(); 4260 2133 4261 } 2134 4262 4263 4264 2135 4265 } 2136 4266 2137 4267 4268 4269 4270 2138 4271 new Master_Custom_Post();
Note: See TracChangeset
for help on using the changeset viewer.