YITH WooCommerce Zoom Magnifier - Version 1.3.23

Version Description

Download this release

Release Info

Developer yithemes
Plugin Icon 128x128 YITH WooCommerce Zoom Magnifier
Version 1.3.23
Comparing to
See all releases

Code changes from version 1.3.22 to 1.3.23

README.txt CHANGED
@@ -4,7 +4,7 @@ Contributors: yithemes
4
  Tags: zoom, magnifier, slider, carousel, woocommerce
5
  Requires at least: 5.3
6
  Tested up to: 5.6
7
- Stable tag: 1.3.22
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  Documentation: https://docs.yithemes.com/yith-woocommerce-zoom-magnifier/
@@ -52,6 +52,11 @@ YITH WooCommerce Zoom Magnifier will add a new tab called "Zoom Magnifier" in "Y
52
 
53
  == Changelog ==
54
 
 
 
 
 
 
55
  = Version 1.3.22 - Released: Jan 20, 2021 =
56
 
57
  * New: support for WooCommerce 4.9
4
  Tags: zoom, magnifier, slider, carousel, woocommerce
5
  Requires at least: 5.3
6
  Tested up to: 5.6
7
+ Stable tag: 1.3.23
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  Documentation: https://docs.yithemes.com/yith-woocommerce-zoom-magnifier/
52
 
53
  == Changelog ==
54
 
55
+ = Version 1.3.23 - Released: Feb 18, 2021 =
56
+
57
+ * New: support for WooCommerce 5.0
58
+ * Update: YITH plugin framework
59
+
60
  = Version 1.3.22 - Released: Jan 20, 2021 =
61
 
62
  * New: support for WooCommerce 4.9
init.php CHANGED
@@ -3,13 +3,13 @@
3
  * Plugin Name: YITH WooCommerce Zoom Magnifier
4
  * Plugin URI: https://yithemes.com/themes/plugins/yith-woocommerce-zoom-magnifier/
5
  * Description: <code><strong>YITH WooCommerce Zoom Magnifier</strong></code> allows you to add a zoom effect to product images and a thumbnail slider for the product image gallery. <a href="https://yithemes.com/" target="_blank">Get more plugins for your e-commerce shop on <strong>YITH</strong></a>.
6
- * Version: 1.3.22
7
  * Author: YITH
8
  * Author URI: https://yithemes.com/
9
  * Text Domain: yith-woocommerce-zoom-magnifier
10
  * Domain Path: /languages/
11
  * WC requires at least: 4.2
12
- * WC tested up to: 4.9
13
  **/
14
 
15
  /* Copyright 2013-2018 Your Inspiration Themes (email : plugins@yithemes.com)
@@ -78,8 +78,8 @@ register_activation_hook ( __FILE__, 'yith_plugin_registration_hook' );
78
 
79
  defined ( 'YITH_YWZM_FREE_INIT' ) || define ( 'YITH_YWZM_FREE_INIT', plugin_basename ( __FILE__ ) );
80
  defined ( 'YITH_YWZM_SLUG' ) || define ( 'YITH_YWZM_SLUG', 'yith-woocommerce-zoom-magnifier' );
81
- defined ( 'YITH_YWZM_VERSION' ) || define ( 'YITH_YWZM_VERSION', '1.3.22' );
82
- defined ( 'YITH_YWZM_JS_VERSION' ) || define ( 'YITH_YWZM_JS_VERSION', '1.3.22' );
83
 
84
  defined ( 'YITH_YWZM_FILE' ) || define ( 'YITH_YWZM_FILE', __FILE__ );
85
  defined ( 'YITH_YWZM_DIR' ) || define ( 'YITH_YWZM_DIR', plugin_dir_path ( __FILE__ ) );
3
  * Plugin Name: YITH WooCommerce Zoom Magnifier
4
  * Plugin URI: https://yithemes.com/themes/plugins/yith-woocommerce-zoom-magnifier/
5
  * Description: <code><strong>YITH WooCommerce Zoom Magnifier</strong></code> allows you to add a zoom effect to product images and a thumbnail slider for the product image gallery. <a href="https://yithemes.com/" target="_blank">Get more plugins for your e-commerce shop on <strong>YITH</strong></a>.
6
+ * Version: 1.3.23
7
  * Author: YITH
8
  * Author URI: https://yithemes.com/
9
  * Text Domain: yith-woocommerce-zoom-magnifier
10
  * Domain Path: /languages/
11
  * WC requires at least: 4.2
12
+ * WC tested up to: 5.0
13
  **/
14
 
15
  /* Copyright 2013-2018 Your Inspiration Themes (email : plugins@yithemes.com)
78
 
79
  defined ( 'YITH_YWZM_FREE_INIT' ) || define ( 'YITH_YWZM_FREE_INIT', plugin_basename ( __FILE__ ) );
80
  defined ( 'YITH_YWZM_SLUG' ) || define ( 'YITH_YWZM_SLUG', 'yith-woocommerce-zoom-magnifier' );
81
+ defined ( 'YITH_YWZM_VERSION' ) || define ( 'YITH_YWZM_VERSION', '1.3.23' );
82
+ defined ( 'YITH_YWZM_JS_VERSION' ) || define ( 'YITH_YWZM_JS_VERSION', '1.3.23' );
83
 
84
  defined ( 'YITH_YWZM_FILE' ) || define ( 'YITH_YWZM_FILE', __FILE__ );
85
  defined ( 'YITH_YWZM_DIR' ) || define ( 'YITH_YWZM_DIR', plugin_dir_path ( __FILE__ ) );
plugin-fw/assets/css/metaboxes.css CHANGED
@@ -126,6 +126,7 @@
126
  width : auto !important;
127
  display : inline-block;
128
  font-weight : normal;
 
129
  }
130
 
131
  .metaboxes-tab input[type="checkbox"] {
126
  width : auto !important;
127
  display : inline-block;
128
  font-weight : normal;
129
+ float : none;
130
  }
131
 
132
  .metaboxes-tab input[type="checkbox"] {
plugin-fw/assets/css/yith-fields.css CHANGED
@@ -1435,9 +1435,11 @@ span.select2.select2-container.select2-container--default.yith-plugin-fw-select2
1435
  .yith-plugin-ui .yith-plugin-fw-onoff-container input + span {
1436
  border : 1px solid #d8d8d8;
1437
  background-color : #fff;
1438
- width : 58px;
1439
  height : 24px;
1440
  line-height : 14px;
 
 
1441
  }
1442
 
1443
  .yith-plugin-ui .yith-plugin-fw-onoff-container input + span:before {
@@ -1445,8 +1447,8 @@ span.select2.select2-container.select2-container--default.yith-plugin-fw-select2
1445
  }
1446
 
1447
  .yith-plugin-ui .yith-plugin-fw-onoff-container input + span:before {
1448
- width : 14px;
1449
- height : 14px;
1450
  top : 5px;
1451
  left : 6px;
1452
  background-color : #d8d8d8;
@@ -1454,15 +1456,14 @@ span.select2.select2-container.select2-container--default.yith-plugin-fw-select2
1454
 
1455
  .yith-plugin-ui .yith-plugin-fw-onoff-container input + span:after {
1456
  content : attr(data-text-off);
1457
- width : 14px;
1458
  height : 14px;
1459
- font-size : 13px;
1460
  font-weight : 600;
1461
- padding-left : 27px;
1462
  color : #979797;
1463
- margin-top : 5px;
1464
- display : inline-block;
1465
  white-space : nowrap;
 
1466
  }
1467
 
1468
  .yith-plugin-ui .yith-plugin-fw-onoff-container input:checked + span,
@@ -1479,16 +1480,16 @@ span.select2.select2-container.select2-container--default.yith-plugin-fw-select2
1479
 
1480
  .yith-plugin-ui .yith-plugin-fw-onoff-container input:checked + span:after,
1481
  .yith-plugin-ui.yith-plugin-fw-onoff-container input.onoffchecked + span:after {
1482
- content : attr(data-text-on);
1483
- color : #98aa36;
1484
- width : 14px;
1485
- height : 14px;
1486
- display : inline-block;
1487
- font-size : 13px;
1488
- font-weight : 600;
1489
- padding : 0 10px;
1490
- margin-top : 5px;
1491
- white-space : nowrap;
1492
  }
1493
 
1494
  .yith-plugin-ui .yith-plugin-fw-onoff-container input + span {
@@ -2211,6 +2212,11 @@ div#ui-datepicker-div.yith-plugin-fw-datepicker-div {
2211
  color : #007694;
2212
  }
2213
 
 
 
 
 
 
2214
  .yith-plugin-fw-dimensions__dimensions {
2215
  display : flex;
2216
  margin : 0;
1435
  .yith-plugin-ui .yith-plugin-fw-onoff-container input + span {
1436
  border : 1px solid #d8d8d8;
1437
  background-color : #fff;
1438
+ width : 60px;
1439
  height : 24px;
1440
  line-height : 14px;
1441
+ padding : 4px;
1442
+ box-sizing : border-box;
1443
  }
1444
 
1445
  .yith-plugin-ui .yith-plugin-fw-onoff-container input + span:before {
1447
  }
1448
 
1449
  .yith-plugin-ui .yith-plugin-fw-onoff-container input + span:before {
1450
+ width : 13px;
1451
+ height : 13px;
1452
  top : 5px;
1453
  left : 6px;
1454
  background-color : #d8d8d8;
1456
 
1457
  .yith-plugin-ui .yith-plugin-fw-onoff-container input + span:after {
1458
  content : attr(data-text-off);
 
1459
  height : 14px;
1460
+ font-size : 12px;
1461
  font-weight : 600;
1462
+ padding-left : 18px;
1463
  color : #979797;
1464
+ display : block;
 
1465
  white-space : nowrap;
1466
+ text-align : center;
1467
  }
1468
 
1469
  .yith-plugin-ui .yith-plugin-fw-onoff-container input:checked + span,
1480
 
1481
  .yith-plugin-ui .yith-plugin-fw-onoff-container input:checked + span:after,
1482
  .yith-plugin-ui.yith-plugin-fw-onoff-container input.onoffchecked + span:after {
1483
+ content : attr(data-text-on);
1484
+ color : #98aa36;
1485
+ height : 14px;
1486
+ font-size : 12px;
1487
+ font-weight : 600;
1488
+ padding-left : 0;
1489
+ padding-right : 18px;
1490
+ display : block;
1491
+ white-space : nowrap;
1492
+ text-align : center;
1493
  }
1494
 
1495
  .yith-plugin-ui .yith-plugin-fw-onoff-container input + span {
2212
  color : #007694;
2213
  }
2214
 
2215
+ .yith-plugin-fw-dimensions__unit--unique {
2216
+ text-decoration : none;
2217
+ cursor : default;
2218
+ }
2219
+
2220
  .yith-plugin-fw-dimensions__dimensions {
2221
  display : flex;
2222
  margin : 0;
plugin-fw/assets/js/yith-fields.min.js CHANGED
@@ -1 +1 @@
1
- !function(e){e(document).on("yith_fields_init",function(){var t=e(".yith-plugin-fw-datepicker"),i=e(".yith-plugin-fw-colorpicker"),n={imgPreviewHandler:".yith-plugin-fw-upload-img-preview",uploadButtonHandler:".yith-plugin-fw-upload-button",imgUrlHandler:".yith-plugin-fw-upload-img-url",resetButtonHandler:".yith-plugin-fw-upload-button-reset",imgUrl:e(".yith-plugin-fw-upload-img-url")},a=e(".add_media"),l={rootSelector:".yith-plugin-fw-image-gallery",buttonSelector:".yith-plugin-fw-image-gallery .image-gallery-button",sliderWrapper:e(".yith-plugin-fw-image-gallery ul.slides-wrapper")},o=e(".yith-plugin-fw-sidebar-layout"),s=e(".yith-plugin-fw .yith-plugin-fw-slider-container .ui-slider-horizontal"),r=e(".yit-icons-manager-wrapper");e(".yith-plugin-ui td.forminp-checkbox");t.each(function(){var t=e(this).data();t.showAnim=!1,t.beforeShow=function(e,t){t.dpDiv.addClass("yith-plugin-fw-datepicker-div")},t.onClose=function(e,t){t.dpDiv.removeClass("yith-plugin-fw-datepicker-div")},e(this).datepicker(t)}),i.wpColorPicker({palettes:!1,width:200,mode:"hsl",clear:function(){var t=e(this);t.val(t.data("default-color")),t.change()}}),i.each(function(){var t=e(this).data("variations-label"),i=e(this).closest(".yith-plugin-fw-colorpicker-field-wrapper"),n=e(this).closest(".yith-single-colorpicker"),a=i.find(".wp-picker-input-wrap"),l=n.find(".wp-picker-input-wrap");if(a.length&&i.find("a.wp-color-result").attr("title",t),n.length&&n.find("a.wp-color-result").attr("title",t),!a.find(".wp-picker-default-custom").length){var o=e("<span/>").attr({class:"wp-picker-default-custom"});a.find(".wp-picker-default").wrap(o)}l.find(".wp-picker-default-custom").length||(o=e("<span/>").attr({class:"wp-picker-default-custom"}),l.find(".wp-picker-default").wrap(o))}),"undefined"!=typeof wp&&void 0!==wp.media&&(n.imgUrl.change(function(){var t=e(this).val(),i=new RegExp("(http|ftp|https)://[a-zA-Z0-9@?^=%&amp;:/~+#-_.]*.(gif|jpg|jpeg|png|ico|svg)"),a=e(this).parent().find(n.imgPreviewHandler).first();a.length<1&&(a=e(this).parent().parent().find(n.imgPreviewHandler).first()),i.test(t)?a.html('<img src="'+t+'" style="max-width:100px; max-height:100px;" />'):a.html("")}).trigger("change"),e(document).on("click",n.uploadButtonHandler,function(t){t.preventDefault();var i,a=e(this).attr("id").replace(/-button$/,"").replace(/(\[|\])/g,"\\$1");if(i)i.open();else{var l=[new wp.media.controller.Library({library:wp.media.query(),multiple:!1,title:"Choose Image",priority:20,filterable:"uploaded"})];(i=wp.media.frames.downloadable_file=wp.media({title:"Choose Image",library:{type:""},button:{text:"Choose Image"},multiple:!1,states:l})).on("select",function(){var t=i.state().get("selection").first().toJSON();e("#"+a).val(t.url),e("#"+a+"-yith-attachment-id")&&e("#"+a+"-yith-attachment-id").val(t.id),n.imgUrl.trigger("change")}),i.open()}}),e(document).on("click",n.resetButtonHandler,function(t){var i=e(this),a=i.attr("id").replace(/(\[|\])/g,"\\$1"),l=i.attr("id").replace(/-button-reset$/,"").replace(/(\[|\])/g,"\\$1"),o=e("#"+a).data("default");e("#"+l).val(o),n.imgUrl.trigger("change")}));a.on("click",function(){}),"undefined"!=typeof wp&&void 0!==wp.media&&(e(document).on("click",l.buttonSelector,function(t){var i=e(this),n=i.closest(l.rootSelector),a=n.find(".image_gallery_ids"),o=a.val(),s=n.find("ul.slides-wrapper"),r=wp.media.frames.image_gallery=wp.media({title:i.data("choose"),button:{text:i.data("update")},states:[new wp.media.controller.Library({title:i.data("choose"),filterable:"all",multiple:!0})]});r.on("select",function(){r.state().get("selection").map(function(e){(e=e.toJSON()).id&&(o=o?o+","+e.id:e.id,s.append('<li class="image" data-attachment_id="'+e.id+'"><img src="'+e.sizes.thumbnail.url+'"/><ul class="actions"><li><a href="#" class="delete" title="'+i.data("delete")+'">x</a></li></ul></li>'))}),a.val(o),a.trigger("change")}),r.open()}),l.sliderWrapper.each(function(){var t=e(this);t.sortable({items:"li.image",cursor:"move",scrollSensitivity:40,forcePlaceholderSize:!0,forceHelperSize:!1,helper:"clone",opacity:.65,start:function(e,t){t.item.css("background-color","#f6f6f6")},stop:function(e,t){t.item.removeAttr("style")},update:function(i,n){var a="";t.find("li.image").css("cursor","default").each(function(){var t=e(this).attr("data-attachment_id");a=a+t+","}),t.closest(l.rootSelector).find(".image_gallery_ids").val(a)}})}),l.sliderWrapper.on("click","a.delete",function(t){t.preventDefault();var i=e(this).closest(l.rootSelector),n=i.find("ul.slides-wrapper"),a=i.find(".image_gallery_ids"),o="";e(this).closest("li.image").remove(),n.find("li.image").css("cursor","default").each(function(){var t=e(this).attr("data-attachment_id");o=o+t+","}),a.val(o)})),o.each(function(){e(this).find("img").on("click",function(){var t=e(this).closest(".yith-plugin-fw-sidebar-layout"),i=t.find(".yith-plugin-fw-sidebar-layout-sidebar-left-container"),n=t.find(".yith-plugin-fw-sidebar-layout-sidebar-right-container"),a=e(this).data("type");if(e(this).parent().children(":radio").attr("checked",!1),e(this).prev(":radio").attr("checked",!0),void 0!==a)switch(a){case"left":i.show(),n.hide();break;case"right":n.show(),i.hide();break;case"double":i.show(),n.show();break;default:i.hide(),n.hide()}})}),s.each(function(){var t=e(this).data("val"),i=e(this).data("min"),n=e(this).data("max"),a=e(this).data("step"),l=e(this).data("labels");e(this).slider({value:t,min:i,max:n,range:"min",step:a,create:function(){e(this).find(".ui-slider-handle").text(e(this).slider("value"))},slide:function(t,i){e(this).find("input").val(i.value),e(this).find(".ui-slider-handle").text(i.value),e(this).siblings(".feedback").find("strong").text(i.value+l)}})}),e(function(){e(document).on("yith-plugin-fw-codemirror-init",function(){"undefined"!=typeof wp&&void 0!==wp.codeEditor&&e(".codemirror:not(.codemirror--initialized)").each(function(){var t=e(this).data("settings"),i=wp.codeEditor.initialize(e(this),t);e(this).addClass("codemirror--initialized"),e(this).data("codemirrorInstance",i)})}).trigger("yith-plugin-fw-codemirror-init")}),e(document).on("click",".yith-plugin-fw-select-all",function(){e("#"+e(this).data("select-id")).find("option").prop("selected",!0).trigger("change")}),e(document).on("click",".yith-plugin-fw-deselect-all",function(){e("#"+e(this).data("select-id")).find("option").prop("selected",!1).trigger("change")}),r.each(function(){var t=e(this),i=t.find(".yit-icons-manager-icon-preview").first(),n=t.find(".yit-icons-manager-icon-text");t.on("click",".yit-icons-manager-list li",function(a){var l=e(a.target).closest("li"),o=l.data("font"),s=l.data("icon"),r=l.data("key"),d=l.data("name");i.attr("data-font",o),i.attr("data-icon",s),i.attr("data-key",r),i.attr("data-name",d),n.val(o+":"+d),t.find(".yit-icons-manager-list li").removeClass("active"),l.addClass("active")}),t.on("click",".yit-icons-manager-action-set-default",function(){t.find(".yit-icons-manager-list li.default").trigger("click")})}),e(document).on("click",".yith-plugin-fw-select-images__item",function(){var t=e(this),i=t.data("key"),n=t.closest(".yith-plugin-fw-select-images__wrapper"),a=n.find(".yith-plugin-fw-select-images__item"),l=n.find("select").first();l.length&&(l.val(i).trigger("yith_select_images_value_changed"),a.removeClass("yith-plugin-fw-select-images__item--selected"),t.addClass("yith-plugin-fw-select-images__item--selected"))}),e(document.body).trigger("wc-enhanced-select-init"),e(document).find(".ui-sortable .yith-toggle-elements").sortable({cursor:"move",axis:"y",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",stop:function(t,i){var n=jQuery(".ui-sortable-handle"),a=0,l=new Array;for(a=0;a<n.length;a++)l[a]=e(n[a]).data("item_key");l.length>0&&e(this).closest(".toggle-element").saveToggleElement(null,l)}}),e(document.body).trigger("yith-framework-enhanced-select-init")}).trigger("yith_fields_init"),e(document).on("click",".yith-plugin-fw-onoff-container span",function(){var t=e(this).prev("input");t.prop("checked")?t.prop("checked",!1).attr("value","no").removeClass("onoffchecked"):t.prop("checked",!0).attr("value","yes").addClass("onoffchecked"),t.change()}),e.fn.saveToggleElement=function(t,i){var n=e(this),a="yith_plugin_fw_save_toggle_element",l=n.serializeToggleElement(),o=n.find(".yith-toggle_wrapper"),s=o.attr("id"),r=e.urlParam("tab");l.append("security",o.data("nonce")),void 0!==i&&i.length>0&&l.append("yith_toggle_elements_order_keys",i),n.closest(".metaboxes-tab.yith-plugin-ui").length?(a="yith_plugin_fw_save_toggle_element_metabox",post_id=e(this).closest("form#post").find("#post_ID").val(),yit_metaboxes_nonce=e(this).closest("form#post").find("#yit_metaboxes_nonce").val(),metabox_tab=e(this).closest(".tabs-panel").attr("id"),url=yith_framework_fw_fields.ajax_url+"?action="+a+"&post_ID="+post_id+"&yit_metaboxes_nonce="+yit_metaboxes_nonce+"&toggle_id="+s+"&metabox_tab="+metabox_tab):url=yith_framework_fw_fields.admin_url+"?action="+a+"&tab="+r+"&toggle_id="+s,e.ajax({type:"POST",url:url,data:l,contentType:!1,processData:!1,success:function(i){t&&t.removeClass("show"),e(document).trigger("yith_save_toggle_element_done",[i,n])}})},e.fn.serializeToggleElement=function(){var t=e(this),i=new FormData,n=e(t).find(":input").serializeArray();return e.each(n,function(e,t){el_name=t.name,i.append(t.name,t.value)}),i},e.fn.formatToggleTitle=function(){var t=e(this),i=t.find(":input"),n=t.find("span.title").data("title_format"),a=t.find(".subtitle").data("subtitle_format"),l=new RegExp("[^%%]+(?=[%%])","g");if(void 0!==n)var o=n.match(l);if(void 0!==a)var s=a.match(l);e.each(i,function(t,i){void 0!==e(i).attr("id")&&($field_id=e(i).attr("id"),$field_array=$field_id.split("_"),$field_array.pop(),$field_id=$field_array.join("_"),$field_val=e(i).val(),null!=o&&void 0!==o&&-1!==o.indexOf($field_id)&&(n=n.replace("%%"+$field_id+"%%",$field_val)),null!=s&&void 0!==s&&-1!==s.indexOf($field_id)&&(a=a.replace("%%"+$field_id+"%%",$field_val)))}),""!==n&&t.find("span.title").html(n),""!==a&&t.find(".subtitle").html(a),e(document).trigger("yith-toggle-element-item-title",[t])},e.urlParam=function(e){var t=new RegExp("[?&]"+e+"=([^&#]*)").exec(window.location.search);return null!==t&&(t[1]||0)},e(document).on("click",".yith-toggle-title",function(t){var i=e(t.target),n=i.closest(".yith-toggle-row"),a=n.find(".yith-toggle-content");if(i.hasClass("yith-plugin-fw-onoff")||i.hasClass("yith-icon-drag"))return!1;n.is(".yith-toggle-row-opened")?a.slideUp(400):a.slideDown(400),n.toggleClass("yith-toggle-row-opened")}),e(document).on("click",".yith-add-box-button",function(t){t.preventDefault();var i=e(this),n=i.data("box_id"),a=i.data("closed_label"),l=i.data("opened_label"),o=i.closest(".yith-toggle_wrapper").attr("id"),s=wp.template("yith-toggle-element-add-box-content-"+o);""!==n&&(e("#"+n).html(s({index:"box_id"})).slideToggle(),""!==a&&(i.html()===a?i.html(l).removeClass("closed"):i.html(a).addClass("closed")),e(document).trigger("yith_fields_init"),e(document).trigger("yith-add-box-button-toggle",[i]))}),e(document).on("click",".yith-add-box-buttons .yith-save-button",function(t){t.preventDefault();var i=e(this).parents(".yith-add-box"),n=e(this).closest(".yith-toggle_wrapper").attr("id"),a=i.find(".spinner"),l=e(this).parents(".toggle-element"),o=i.find(":input"),s=0,r=e('<input type="hidden">');l.find(".yith-toggle-row").each(function(){var t=parseInt(e(this).data("item_key"));s<=t&&(s=t+1)}),r.val(s),e(document).trigger("yith-toggle-change-counter",[r,i]),s=r.val();var d=wp.template("yith-toggle-element-item-"+n),c=e(d({index:s}));a.addClass("show"),e.each(o,function(t,i){if(void 0!==e(i).attr("id")){var n=e(i).attr("id"),a=e(i).val();n="radio"===e(i).attr("type")?(n=(n=e(i).closest(".yith-plugin-fw-radio").attr("id")).replace("new_","")+"_"+s)+"-"+a:n.replace("new_","")+"_"+s,e(i).is(":checked")&&e(c).find("#"+n).prop("checked",!0),(e(i).hasClass("yith-post-search")||e(i).hasClass("yith-term-search"))&&e(c).find("#"+n).html(e("#"+e(i).attr("id")).html()),e(c).find("#"+n).val(a)}}),e(c).formatToggleTitle();var u=e('<input type="hidden">').val("yes");e(document).trigger("yith-toggle-element-item-before-add",[i,c,u]);setTimeout(function(){if("yes"===u.val()){e(l).find(".yith-toggle-elements").append(c),e(i).find(".yith-plugin-fw-datepicker").datepicker("destroy"),e(i).html(""),e(i).prev(".yith-add-box-button").trigger("click"),l.saveToggleElement();setTimeout(function(){e(l).find(".highlight").removeClass("highlight")},2e3),e(document).trigger("yith_fields_init")}},1e3)}),e(document).on("click",".yith-toggle-row .yith-save-button",function(t){t.preventDefault();var i=e(this).closest(".toggle-element"),n=e(this).closest(".yith-toggle-row"),a=n.find(".spinner");n.formatToggleTitle();var l=e('<input type="hidden">').val("yes");e(document).trigger("yith-toggle-element-item-before-update",[i,n,l]),"yes"===l.val()&&(a.addClass("show"),i.saveToggleElement(a))}),e(document).on("click",".yith-toggle-row .yith-delete-button",function(t){t.preventDefault();var i=e(this).closest(".toggle-element");e(this).closest(".yith-toggle-row").remove(),i.saveToggleElement()}),e(document).on("click",".yith-toggle-onoff",function(t){t.preventDefault(),e(this).closest(".toggle-element").saveToggleElement()}),e(document).on("click",".yith-plugin-fw-radio input[type=radio]",function(){var t=e(this).closest(".yith-plugin-fw-radio"),i=e(this).val();t.val(i).data("value",i).trigger("change")}),e(document.body).on("yith-plugin-fw-init-radio",function(){e(".yith-plugin-fw-radio:not(.yith-plugin-fw-radio--initialized)").each(function(){e(this).val(e(this).data("value")),e(this).addClass("yith-plugin-fw-radio--initialized")})}).trigger("yith-plugin-fw-init-radio"),e(document).on("click",".yith-password-eye",function(){var t=e(this),i=e(this).closest(".yith-password-wrapper").find("input");"password"===i.attr("type")?(i.attr("type","text"),t.addClass("yith-password-eye-closed")):(i.attr("type","password"),t.removeClass("yith-password-eye-closed"))}),e(document).on("select2:open",function(t){e(t.target).closest(".yith-plugin-ui").length&&e(".select2-results").closest(".select2-container").addClass("yith-plugin-fw-select2-container")});var t={selectors:{wrapper:".yith-plugin-fw-dimensions",units:{wrapper:".yith-plugin-fw-dimensions__units",single:".yith-plugin-fw-dimensions__unit",value:".yith-plugin-fw-dimensions__unit__value",selectedClass:"yith-plugin-fw-dimensions__unit--selected"},linked:{button:".yith-plugin-fw-dimensions__linked",value:".yith-plugin-fw-dimensions__linked__value",wrapperActiveClass:"yith-plugin-fw-dimensions--linked-active"},dimensions:{number:".yith-plugin-fw-dimensions__dimension__number"}},init:function(){var i=t;e(document).on("click",i.selectors.units.single,i.unitChange),e(document).on("click",i.selectors.linked.button,i.linkedChange),e(document).on("change keyup",i.selectors.dimensions.number,i.numberChange)},unitChange:function(i){var n=e(this).closest(t.selectors.units.single),a=n.closest(t.selectors.units.wrapper),l=a.find(t.selectors.units.single),o=a.find(t.selectors.units.value).first(),s=n.data("value");l.removeClass(t.selectors.units.selectedClass),n.addClass(t.selectors.units.selectedClass),o.val(s)},linkedChange:function(){var i=e(this).closest(t.selectors.linked.button),n=i.closest(t.selectors.wrapper),a=i.find(t.selectors.linked.value);"yes"===a.val()?(n.removeClass(t.selectors.linked.wrapperActiveClass),a.val("no")):(n.addClass(t.selectors.linked.wrapperActiveClass),a.val("yes"),n.find(t.selectors.dimensions.number).first().trigger("change"))},numberChange:function(i){var n=e(this).closest(t.selectors.dimensions.number),a=n.closest(t.selectors.wrapper);a.hasClass(t.selectors.linked.wrapperActiveClass)&&a.find(t.selectors.dimensions.number).val(n.val())}};t.init()}(jQuery);
1
+ !function(e){e(document).on("yith_fields_init",function(){var t=e(".yith-plugin-fw-datepicker"),i=e(".yith-plugin-fw-colorpicker"),n={imgPreviewHandler:".yith-plugin-fw-upload-img-preview",uploadButtonHandler:".yith-plugin-fw-upload-button",imgUrlHandler:".yith-plugin-fw-upload-img-url",resetButtonHandler:".yith-plugin-fw-upload-button-reset",imgUrl:e(".yith-plugin-fw-upload-img-url")},a=e(".add_media"),l={rootSelector:".yith-plugin-fw-image-gallery",buttonSelector:".yith-plugin-fw-image-gallery .image-gallery-button",sliderWrapper:e(".yith-plugin-fw-image-gallery ul.slides-wrapper")},o=e(".yith-plugin-fw-sidebar-layout"),s=e(".yith-plugin-fw .yith-plugin-fw-slider-container .ui-slider-horizontal"),r=e(".yit-icons-manager-wrapper");e(".yith-plugin-ui td.forminp-checkbox");t.each(function(){var t=e(this).data();t.showAnim=!1,t.beforeShow=function(e,t){t.dpDiv.addClass("yith-plugin-fw-datepicker-div")},t.onClose=function(e,t){t.dpDiv.removeClass("yith-plugin-fw-datepicker-div")},e(this).datepicker(t)}),i.wpColorPicker({palettes:!1,width:200,mode:"hsl",clear:function(){var t=e(this);t.val(t.data("default-color")),t.change()}}),i.each(function(){var t=e(this).data("variations-label"),i=e(this).closest(".yith-plugin-fw-colorpicker-field-wrapper"),n=e(this).closest(".yith-single-colorpicker"),a=i.find(".wp-picker-input-wrap"),l=n.find(".wp-picker-input-wrap");if(a.length&&i.find("a.wp-color-result").attr("title",t),n.length&&n.find("a.wp-color-result").attr("title",t),!a.find(".wp-picker-default-custom").length){var o=e("<span/>").attr({"class":"wp-picker-default-custom"});a.find(".wp-picker-default").wrap(o)}l.find(".wp-picker-default-custom").length||(o=e("<span/>").attr({"class":"wp-picker-default-custom"}),l.find(".wp-picker-default").wrap(o))}),"undefined"!=typeof wp&&"undefined"!=typeof wp.media&&(n.imgUrl.change(function(){var t=e(this).val(),i=new RegExp("(http|ftp|https)://[a-zA-Z0-9@?^=%&amp;:/~+#-_.]*.(gif|jpg|jpeg|png|ico|svg)"),a=e(this).parent().find(n.imgPreviewHandler).first();a.length<1&&(a=e(this).parent().parent().find(n.imgPreviewHandler).first()),i.test(t)?a.html('<img src="'+t+'" style="max-width:100px; max-height:100px;" />'):a.html("")}).trigger("change"),e(document).on("click",n.uploadButtonHandler,function(t){t.preventDefault();var i,a=e(this).attr("id").replace(/-button$/,"").replace(/(\[|\])/g,"\\$1");if(i)i.open();else{var l=[new wp.media.controller.Library({library:wp.media.query(),multiple:!1,title:"Choose Image",priority:20,filterable:"uploaded"})];(i=wp.media.frames.downloadable_file=wp.media({title:"Choose Image",library:{type:""},button:{text:"Choose Image"},multiple:!1,states:l})).on("select",function(){var t=i.state().get("selection").first().toJSON();e("#"+a).val(t.url),e("#"+a+"-yith-attachment-id")&&e("#"+a+"-yith-attachment-id").val(t.id),n.imgUrl.trigger("change")}),i.open()}}),e(document).on("click",n.resetButtonHandler,function(t){var i=e(this),a=i.attr("id").replace(/(\[|\])/g,"\\$1"),l=i.attr("id").replace(/-button-reset$/,"").replace(/(\[|\])/g,"\\$1"),o=e("#"+a).data("default");e("#"+l).val(o),n.imgUrl.trigger("change")}));a.on("click",function(){}),"undefined"!=typeof wp&&"undefined"!=typeof wp.media&&(e(document).on("click",l.buttonSelector,function(t){var i=e(this),n=i.closest(l.rootSelector),a=n.find(".image_gallery_ids"),o=a.val(),s=n.find("ul.slides-wrapper"),r=wp.media.frames.image_gallery=wp.media({title:i.data("choose"),button:{text:i.data("update")},states:[new wp.media.controller.Library({title:i.data("choose"),filterable:"all",multiple:!0})]});r.on("select",function(){r.state().get("selection").map(function(e){(e=e.toJSON()).id&&(o=o?o+","+e.id:e.id,s.append('<li class="image" data-attachment_id="'+e.id+'"><img src="'+e.sizes.thumbnail.url+'"/><ul class="actions"><li><a href="#" class="delete" title="'+i.data("delete")+'">x</a></li></ul></li>'))}),a.val(o),a.trigger("change")}),r.open()}),l.sliderWrapper.each(function(){var t=e(this);t.sortable({items:"li.image",cursor:"move",scrollSensitivity:40,forcePlaceholderSize:!0,forceHelperSize:!1,helper:"clone",opacity:.65,start:function(e,t){t.item.css("background-color","#f6f6f6")},stop:function(e,t){t.item.removeAttr("style")},update:function(i,n){var a="";t.find("li.image").css("cursor","default").each(function(){var t=e(this).attr("data-attachment_id");a=a+t+","}),t.closest(l.rootSelector).find(".image_gallery_ids").val(a)}})}),l.sliderWrapper.on("click","a.delete",function(t){t.preventDefault();var i=e(this).closest(l.rootSelector),n=i.find("ul.slides-wrapper"),a=i.find(".image_gallery_ids"),o="";e(this).closest("li.image").remove(),n.find("li.image").css("cursor","default").each(function(){var t=e(this).attr("data-attachment_id");o=o+t+","}),a.val(o)})),o.each(function(){e(this).find("img").on("click",function(){var t=e(this).closest(".yith-plugin-fw-sidebar-layout"),i=t.find(".yith-plugin-fw-sidebar-layout-sidebar-left-container"),n=t.find(".yith-plugin-fw-sidebar-layout-sidebar-right-container"),a=e(this).data("type");if(e(this).parent().children(":radio").attr("checked",!1),e(this).prev(":radio").attr("checked",!0),void 0!==a)switch(a){case"left":i.show(),n.hide();break;case"right":n.show(),i.hide();break;case"double":i.show(),n.show();break;default:i.hide(),n.hide()}})}),s.each(function(){var t=e(this).data("val"),i=e(this).data("min"),n=e(this).data("max"),a=e(this).data("step"),l=e(this).data("labels");e(this).slider({value:t,min:i,max:n,range:"min",step:a,create:function(){e(this).find(".ui-slider-handle").text(e(this).slider("value"))},slide:function(t,i){e(this).find("input").val(i.value),e(this).find(".ui-slider-handle").text(i.value),e(this).siblings(".feedback").find("strong").text(i.value+l)}})}),e(function(){e(document).on("yith-plugin-fw-codemirror-init",function(){"undefined"!=typeof wp&&"undefined"!=typeof wp.codeEditor&&e(".codemirror:not(.codemirror--initialized)").each(function(){var t=e(this).data("settings"),i=wp.codeEditor.initialize(e(this),t);e(this).addClass("codemirror--initialized"),e(this).data("codemirrorInstance",i)})}).trigger("yith-plugin-fw-codemirror-init")}),e(document).on("click",".yith-plugin-fw-select-all",function(){e("#"+e(this).data("select-id")).find("option").prop("selected",!0).trigger("change")}),e(document).on("click",".yith-plugin-fw-deselect-all",function(){e("#"+e(this).data("select-id")).find("option").prop("selected",!1).trigger("change")}),r.each(function(){var t=e(this),i=t.find(".yit-icons-manager-icon-preview").first(),n=t.find(".yit-icons-manager-icon-text");t.on("click",".yit-icons-manager-list li",function(a){var l=e(a.target).closest("li"),o=l.data("font"),s=l.data("icon"),r=l.data("key"),d=l.data("name");i.attr("data-font",o),i.attr("data-icon",s),i.attr("data-key",r),i.attr("data-name",d),n.val(o+":"+d),t.find(".yit-icons-manager-list li").removeClass("active"),l.addClass("active")}),t.on("click",".yit-icons-manager-action-set-default",function(){t.find(".yit-icons-manager-list li.default").trigger("click")})}),e(document).on("click",".yith-plugin-fw-select-images__item",function(){var t=e(this),i=t.data("key"),n=t.closest(".yith-plugin-fw-select-images__wrapper"),a=n.find(".yith-plugin-fw-select-images__item"),l=n.find("select").first();l.length&&(l.val(i).trigger("yith_select_images_value_changed"),a.removeClass("yith-plugin-fw-select-images__item--selected"),t.addClass("yith-plugin-fw-select-images__item--selected"))}),e(document.body).trigger("wc-enhanced-select-init"),e(document).find(".ui-sortable .yith-toggle-elements").sortable({cursor:"move",axis:"y",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",stop:function(t,i){var n=jQuery(".ui-sortable-handle"),a=0,l=new Array;for(a=0;a<n.length;a++)l[a]=e(n[a]).data("item_key");l.length>0&&e(this).closest(".toggle-element").saveToggleElement(null,l)}}),e(document.body).trigger("yith-framework-enhanced-select-init")}).trigger("yith_fields_init"),e(document).on("click",".yith-plugin-fw-onoff-container span",function(){var t=e(this).prev("input");t.prop("checked")?t.prop("checked",!1).attr("value","no").removeClass("onoffchecked"):t.prop("checked",!0).attr("value","yes").addClass("onoffchecked"),t.change()}),e.fn.saveToggleElement=function(t,i){var n=e(this),a="yith_plugin_fw_save_toggle_element",l=n.serializeToggleElement(),o=n.find(".yith-toggle_wrapper"),s=o.attr("id"),r=e.urlParam("tab");l.append("security",o.data("nonce")),void 0!==i&&i.length>0&&l.append("yith_toggle_elements_order_keys",i),n.closest(".metaboxes-tab.yith-plugin-ui").length?(a="yith_plugin_fw_save_toggle_element_metabox",post_id=e(this).closest("form#post").find("#post_ID").val(),yit_metaboxes_nonce=e(this).closest("form#post").find("#yit_metaboxes_nonce").val(),metabox_tab=e(this).closest(".tabs-panel").attr("id"),url=yith_framework_fw_fields.ajax_url+"?action="+a+"&post_ID="+post_id+"&yit_metaboxes_nonce="+yit_metaboxes_nonce+"&toggle_id="+s+"&metabox_tab="+metabox_tab):url=yith_framework_fw_fields.admin_url+"?action="+a+"&tab="+r+"&toggle_id="+s,e.ajax({type:"POST",url:url,data:l,contentType:!1,processData:!1,success:function(i){t&&t.removeClass("show"),e(document).trigger("yith_save_toggle_element_done",[i,n])}})},e.fn.serializeToggleElement=function(){var t=e(this),i=new FormData,n=e(t).find(":input").serializeArray();return e.each(n,function(e,t){el_name=t.name,i.append(t.name,t.value)}),i},e.fn.formatToggleTitle=function(){var t=e(this),i=t.find(":input"),n=t.find("span.title").data("title_format"),a=t.find(".subtitle").data("subtitle_format"),l=new RegExp("[^%%]+(?=[%%])","g");if(void 0!==n)var o=n.match(l);if(void 0!==a)var s=a.match(l);e.each(i,function(t,i){void 0!==e(i).attr("id")&&($field_id=e(i).attr("id"),$field_array=$field_id.split("_"),$field_array.pop(),$field_id=$field_array.join("_"),$field_val=e(i).val(),null!=o&&void 0!==o&&-1!==o.indexOf($field_id)&&(n=n.replace("%%"+$field_id+"%%",$field_val)),null!=s&&void 0!==s&&-1!==s.indexOf($field_id)&&(a=a.replace("%%"+$field_id+"%%",$field_val)))}),""!==n&&t.find("span.title").html(n),""!==a&&t.find(".subtitle").html(a),e(document).trigger("yith-toggle-element-item-title",[t])},e.urlParam=function(e){var t=new RegExp("[?&]"+e+"=([^&#]*)").exec(window.location.search);return null!==t&&(t[1]||0)},e(document).on("click",".yith-toggle-title",function(t){var i=e(t.target),n=i.closest(".yith-toggle-row"),a=n.find(".yith-toggle-content");if(i.hasClass("yith-plugin-fw-onoff")||i.hasClass("yith-icon-drag"))return!1;n.is(".yith-toggle-row-opened")?a.slideUp(400):a.slideDown(400),n.toggleClass("yith-toggle-row-opened")}),e(document).on("click",".yith-add-box-button",function(t){t.preventDefault();var i=e(this),n=i.data("box_id"),a=i.data("closed_label"),l=i.data("opened_label"),o=i.closest(".yith-toggle_wrapper").attr("id"),s=wp.template("yith-toggle-element-add-box-content-"+o);""!==n&&(e("#"+n).html(s({index:"box_id"})).slideToggle(),""!==a&&(i.html()===a?i.html(l).removeClass("closed"):i.html(a).addClass("closed")),e(document).trigger("yith_fields_init"),e(document).trigger("yith-add-box-button-toggle",[i]))}),e(document).on("click",".yith-add-box-buttons .yith-save-button",function(t){t.preventDefault();var i=e(this).parents(".yith-add-box"),n=e(this).closest(".yith-toggle_wrapper").attr("id"),a=i.find(".spinner"),l=e(this).parents(".toggle-element"),o=i.find(":input"),s=0,r=e('<input type="hidden">');l.find(".yith-toggle-row").each(function(){var t=parseInt(e(this).data("item_key"));s<=t&&(s=t+1)}),r.val(s),e(document).trigger("yith-toggle-change-counter",[r,i]),s=r.val();var d=wp.template("yith-toggle-element-item-"+n),c=e(d({index:s}));a.addClass("show"),e.each(o,function(t,i){if(void 0!==e(i).attr("id")){var n=e(i).attr("id"),a=e(i).val();n="radio"===e(i).attr("type")?(n=(n=e(i).closest(".yith-plugin-fw-radio").attr("id")).replace("new_","")+"_"+s)+"-"+a:n.replace("new_","")+"_"+s,e(i).is(":checked")&&e(c).find("#"+n).prop("checked",!0),(e(i).hasClass("yith-post-search")||e(i).hasClass("yith-term-search"))&&e(c).find("#"+n).html(e("#"+e(i).attr("id")).html()),e(c).find("#"+n).val(a)}}),e(c).formatToggleTitle();var u=e('<input type="hidden">').val("yes");e(document).trigger("yith-toggle-element-item-before-add",[i,c,u]);setTimeout(function(){if("yes"===u.val()){e(l).find(".yith-toggle-elements").append(c),e(i).find(".yith-plugin-fw-datepicker").datepicker("destroy"),e(i).html(""),e(i).prev(".yith-add-box-button").trigger("click"),l.saveToggleElement();setTimeout(function(){e(l).find(".highlight").removeClass("highlight")},2e3),e(document).trigger("yith_fields_init")}},1e3)}),e(document).on("click",".yith-toggle-row .yith-save-button",function(t){t.preventDefault();var i=e(this).closest(".toggle-element"),n=e(this).closest(".yith-toggle-row"),a=n.find(".spinner");n.formatToggleTitle();var l=e('<input type="hidden">').val("yes");e(document).trigger("yith-toggle-element-item-before-update",[i,n,l]),"yes"===l.val()&&(a.addClass("show"),i.saveToggleElement(a))}),e(document).on("click",".yith-toggle-row .yith-delete-button",function(t){t.preventDefault();var i=e(this).closest(".toggle-element");e(this).closest(".yith-toggle-row").remove(),i.saveToggleElement()}),e(document).on("click",".yith-toggle-onoff",function(t){t.preventDefault(),e(this).closest(".toggle-element").saveToggleElement()}),e(document).on("click",".yith-plugin-fw-radio input[type=radio]",function(){var t=e(this).closest(".yith-plugin-fw-radio"),i=e(this).val();t.val(i).data("value",i).trigger("change")}),e(document.body).on("yith-plugin-fw-init-radio",function(){e(".yith-plugin-fw-radio:not(.yith-plugin-fw-radio--initialized)").each(function(){e(this).val(e(this).data("value")),e(this).addClass("yith-plugin-fw-radio--initialized")})}).trigger("yith-plugin-fw-init-radio"),e(document).on("click",".yith-password-eye",function(){var t=e(this),i=e(this).closest(".yith-password-wrapper").find("input");"password"===i.attr("type")?(i.attr("type","text"),t.addClass("yith-password-eye-closed")):(i.attr("type","password"),t.removeClass("yith-password-eye-closed"))}),e(document).on("select2:open",function(t){e(t.target).closest(".yith-plugin-ui").length&&e(".select2-results").closest(".select2-container").addClass("yith-plugin-fw-select2-container")});var t={selectors:{wrapper:".yith-plugin-fw-dimensions",units:{wrapper:".yith-plugin-fw-dimensions__units",single:".yith-plugin-fw-dimensions__unit",value:".yith-plugin-fw-dimensions__unit__value",selectedClass:"yith-plugin-fw-dimensions__unit--selected"},linked:{button:".yith-plugin-fw-dimensions__linked",value:".yith-plugin-fw-dimensions__linked__value",wrapperActiveClass:"yith-plugin-fw-dimensions--linked-active"},dimensions:{number:".yith-plugin-fw-dimensions__dimension__number"}},init:function(){var i=t;e(document).on("click",i.selectors.units.single,i.unitChange),e(document).on("click",i.selectors.linked.button,i.linkedChange),e(document).on("change keyup",i.selectors.dimensions.number,i.numberChange)},unitChange:function(i){var n=e(this).closest(t.selectors.units.single),a=n.closest(t.selectors.units.wrapper),l=a.find(t.selectors.units.single),o=a.find(t.selectors.units.value).first(),s=n.data("value");l.removeClass(t.selectors.units.selectedClass),n.addClass(t.selectors.units.selectedClass),o.val(s)},linkedChange:function(){var i=e(this).closest(t.selectors.linked.button),n=i.closest(t.selectors.wrapper),a=i.find(t.selectors.linked.value);"yes"===a.val()?(n.removeClass(t.selectors.linked.wrapperActiveClass),a.val("no")):(n.addClass(t.selectors.linked.wrapperActiveClass),a.val("yes"),n.find(t.selectors.dimensions.number).first().trigger("change"))},numberChange:function(i){var n=e(this).closest(t.selectors.dimensions.number),a=n.closest(t.selectors.wrapper);a.hasClass(t.selectors.linked.wrapperActiveClass)&&a.find(t.selectors.dimensions.number).val(n.val())}};t.init()}(jQuery);
plugin-fw/includes/class-yit-cpt-unlimited.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /**
3
  * YITH Custom-Post-Type Unlimited Class.
4
- * Manage the custom post types as Portfolio, Contact Forms and similar (called CPTU)
5
  *
6
  * @class YIT_CPT_Unlimited
7
  * @package YITH\PluginFramework\Classes
@@ -19,76 +19,6 @@ if ( ! class_exists( 'YIT_CPT_Unlimited' ) ) {
19
  */
20
  class YIT_CPT_Unlimited {
21
 
22
- /**
23
- * The name of main post type of CPTU.
24
- *
25
- * @var string
26
- */
27
- protected $name = '';
28
-
29
- /**
30
- * The prefix of each post type created by the post of main CPTU
31
- *
32
- * @var string
33
- */
34
- protected $prefix_cpt = '';
35
-
36
- /**
37
- * Labels defined for the main CPTU
38
- *
39
- * @var string
40
- */
41
- protected $labels = '';
42
-
43
- /**
44
- * The configuration arguments of post type
45
- *
46
- * @var string
47
- */
48
- protected $args = '';
49
-
50
- /**
51
- * All post types created by the post of main CPTU
52
- *
53
- * @var array
54
- */
55
- public $post_types = array();
56
-
57
- /**
58
- * Array with all portfolio layouts available for this site
59
- *
60
- * @var array
61
- */
62
- public $layouts = array();
63
-
64
- /**
65
- * The pathname of template folder
66
- *
67
- * @var string
68
- */
69
- protected $template_path = '';
70
-
71
- /**
72
- * The URL of template folder
73
- *
74
- * @var string
75
- */
76
- protected $template_url = '';
77
-
78
- /**
79
- * Unique sequential ID to differentiate same shortcodes in the same page
80
- *
81
- * @var int
82
- */
83
- public $index = 0;
84
-
85
- /**
86
- * Temporary attribute to load automatically the settings for each layout
87
- *
88
- * @var string
89
- */
90
- private $layout = '';
91
-
92
  /**
93
  * YIT_CPT_Unlimited constructor.
94
  *
@@ -96,1810 +26,29 @@ if ( ! class_exists( 'YIT_CPT_Unlimited' ) ) {
96
  */
97
  public function __construct( $args = array() ) {
98
 
99
- $defaults = array(
100
- 'name' => '',
101
- 'post_type_prefix' => '',
102
- 'labels' => array(
103
- 'main_name' => '',
104
- 'singular' => '',
105
- 'plural' => '',
106
- 'menu' => '',
107
- ),
108
- 'manage_layouts' => false,
109
- 'add_multiuploader' => false,
110
- 'sortable' => false,
111
- 'has_single' => false,
112
- 'has_taxonomy' => false,
113
- 'label_item_sing' => '',
114
- 'label_item_plur' => '',
115
- 'shortcode_name' => '',
116
- 'shortcode_icon' => '', // URL or icon name from http://melchoyce.github.io/dashicons/.
117
- 'layout_option' => '_type', // The option ID of layout meta-box.
118
- );
119
- $this->args = wp_parse_args( $args, $defaults );
120
-
121
- // Fix the labels.
122
- if ( empty( $this->args['labels']['main_name'] ) ) {
123
- $this->args['labels']['main_name'] = $this->args['labels']['singular'];
124
- }
125
- if ( empty( $this->args['labels']['menu'] ) ) {
126
- $this->args['labels']['menu'] = $this->args['labels']['singular'];
127
- }
128
-
129
- // Populate.
130
- $this->name = $this->args['name'];
131
- $this->prefix_cpt = $this->args['post_type_prefix'];
132
- $this->labels = $this->args['labels'];
133
-
134
- add_action( 'init', array( $this, 'register_post_type' ) );
135
- add_action( 'init', array( $this, 'register_cptu_post_types' ) );
136
-
137
- add_action( 'save_post', array( $this, 'rewrite_flush' ) );
138
-
139
- // Admin interface.
140
- add_action( 'admin_head', array( $this, 'add_cptu_menu_item' ) );
141
- add_action( 'admin_init', array( $this, 'add_quick_links_metaboxes' ) );
142
- add_action( 'admin_enqueue_scripts', array( $this, 'admin_assets' ) );
143
-
144
- // Meta-boxes.
145
- if ( is_admin() ) {
146
- add_action( 'init', array( $this, 'add_metabox_cptu' ) );
147
- add_action( 'init', array( $this, 'add_metabox_item_fields' ) );
148
- }
149
-
150
- // Multi-uploader.
151
- if ( $this->args['add_multiuploader'] ) {
152
- add_action( 'admin_footer', array( $this, 'add_button_multiuploader' ) );
153
- add_action( 'wp_ajax_yit_cptu_multiuploader', array( $this, 'post_multiuploader' ) );
154
- }
155
-
156
- // Layouts.
157
- if ( $this->args['manage_layouts'] ) {
158
- $this->get_layouts();
159
- }
160
-
161
- // Single layout.
162
- if ( $this->args['has_single'] ) {
163
- add_action( 'yit_loop', array( $this, 'single_template' ) );
164
- add_action( 'wp', array( $this, 'single_template_config' ) );
165
-
166
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
167
- add_action( 'init', array( $this, 'single_template_config' ) );
168
- }
169
- }
170
-
171
- // Archive template.
172
- add_action( 'wp', array( $this, 'archive_template' ) );
173
-
174
- // Enqueue the assets of each layout.
175
- add_action( 'wp_enqueue_scripts', array( $this, 'frontend_assets' ) );
176
-
177
- // Add the shortcode, used to show the frontend.
178
- if ( ! empty( $this->args['shortcode_name'] ) ) {
179
- add_shortcode( $this->args['shortcode_name'], array( &$this, 'add_shortcode' ) );
180
- add_filter( 'yit_shortcode_' . $this->args['shortcode_name'] . '_icon', array( $this, 'shortcode_icon' ) );
181
- add_filter( 'yit-shortcode-plugin-init', array( $this, 'add_shortcode_to_box' ) );
182
- }
183
-
184
- // Add sortable feature.
185
- if ( $this->args['sortable'] ) {
186
- add_action( 'admin_enqueue_scripts', array( $this, 'admin_sortable_assets' ) );
187
- add_action( 'wp_ajax_cpt_sort_posts', array( $this, 'sort_posts' ) );
188
- add_action( 'admin_init', array( $this, 'init_menu_order' ) );
189
- add_filter( 'pre_get_posts', array( $this, 'filter_active' ) );
190
- add_filter( 'pre_get_posts', array( $this, 'pre_get_posts' ) );
191
- add_filter( 'get_next_post_where', array( $this, 'sorted_next_post_where' ) );
192
- add_filter( 'get_previous_post_where', array( $this, 'sorted_prev_post_where' ) );
193
- add_filter( 'get_next_post_sort', array( $this, 'sorted_next_post_sort' ) );
194
- add_filter( 'get_previous_post_sort', array( $this, 'sorted_prev_post_sort' ) );
195
- }
196
-
197
- // Add default columns to post type table list.
198
- add_filter( 'manage_edit-' . $this->name . '_columns', array( $this, 'cptu_define_columns' ) );
199
- add_action( 'manage_' . $this->name . '_posts_custom_column', array( $this, 'cptu_change_columns' ), 10, 2 );
200
-
201
- // Add required post type for WordPress importer.
202
- add_filter( 'wp_import_post_data_raw', array( $this, 'add_importer_required_post_type' ) );
203
- add_filter( 'wp_import_terms', array( $this, 'add_importer_required_taxonomy' ) );
204
- add_action( 'wp_import_set_post_terms', array( $this, 'recount_terms_post' ), 10, 3 );
205
-
206
- }
207
-
208
- /**
209
- * Enqueue the assets for the sortable feature
210
- *
211
- * @return void
212
- * @since 1.0
213
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
214
- */
215
- public function admin_sortable_assets() {
216
- global $post;
217
-
218
- if ( ! isset( $post->post_type ) || ! $this->is_valid( $post->post_type ) ) {
219
- return;
220
- }
221
-
222
- wp_enqueue_script( 'yit-cptu-sortable-posts', YIT_CORE_PLUGIN_URL . '/assets/js/yit-cptu-sortable-posts.js', array( 'jquery', 'jquery-ui-sortable' ), '1.0', true );
223
- }
224
-
225
- /**
226
- * Init menu order
227
- *
228
- * @param array $post_types The post types.
229
- */
230
- public function init_menu_order( $post_types = array() ) {
231
- global $wpdb;
232
-
233
- if ( empty( $post_types ) ) {
234
- $post_types = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT post_type FROM $wpdb->posts WHERE post_type LIKE %s", str_replace( '_', '\_', $this->prefix_cpt ) . '%' ) );
235
- } elseif ( ! is_array( $post_types ) ) {
236
- $post_types = array( $post_types );
237
- }
238
-
239
- foreach ( $post_types as $post_type ) {
240
- $count = $wpdb->get_var(
241
- $wpdb->prepare(
242
- "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = %s AND post_status IN ('publish', 'pending', 'draft', 'private', 'future') AND menu_order = 0",
243
- $post_type
244
- )
245
- );
246
-
247
- if ( empty( $count ) ) {
248
- continue;
249
- }
250
-
251
- $results = $wpdb->get_results(
252
- $wpdb->prepare(
253
- "SELECT ID FROM $wpdb->posts WHERE post_type = %s AND post_status IN ('publish', 'pending', 'draft', 'private', 'future') ORDER BY post_date DESC",
254
- $post_type
255
- )
256
- );
257
-
258
- foreach ( $results as $key => $result ) {
259
- $wpdb->update( $wpdb->posts, array( 'menu_order' => $key + 1 ), array( 'ID' => $result->ID ) );
260
- }
261
- }
262
- }
263
-
264
- /**
265
- * Save the order of posts from sortable feature
266
- *
267
- * @return void
268
- * @since 1.0
269
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
270
- */
271
- public function sort_posts() {
272
- global $wpdb;
273
-
274
- parse_str( $_REQUEST['order'], $data ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput
275
-
276
- if ( is_array( $data ) ) {
277
- $id_arr = array();
278
- foreach ( $data as $key => $values ) {
279
- foreach ( $values as $position => $id ) {
280
- $id_arr[] = $id;
281
- }
282
- }
283
-
284
- $menu_order_arr = array();
285
- foreach ( $id_arr as $key => $id ) {
286
- $results = $wpdb->get_results( $wpdb->prepare( "SELECT menu_order FROM $wpdb->posts WHERE ID = %d", $id ) );
287
- foreach ( $results as $result ) {
288
- $menu_order_arr[] = $result->menu_order;
289
- }
290
- }
291
-
292
- sort( $menu_order_arr );
293
-
294
- foreach ( $data as $key => $values ) {
295
- foreach ( $values as $position => $id ) {
296
- $wpdb->update( $wpdb->posts, array( 'menu_order' => $menu_order_arr[ $position ] ), array( 'ID' => $id ) );
297
- }
298
- }
299
- }
300
-
301
- die();
302
- }
303
-
304
- /**
305
- * Filter Active
306
- *
307
- * @param WC_Query $wp_query The query.
308
- *
309
- * @return mixed
310
- */
311
- public function filter_active( $wp_query ) {
312
- if ( is_admin() && isset( $wp_query->query['suppress_filters'] ) ) {
313
- $wp_query->query['suppress_filters'] = false;
314
- }
315
- if ( is_admin() && isset( $wp_query->query_vars['suppress_filters'] ) ) {
316
- $wp_query->query_vars['suppress_filters'] = false;
317
- }
318
-
319
- return $wp_query;
320
- }
321
-
322
- /**
323
- * Pre get post.
324
- *
325
- * @param WP_Query $wp_query The query.
326
- */
327
- public function pre_get_posts( $wp_query ) {
328
- if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
329
- if ( isset( $wp_query->query['post_type'] ) ) {
330
- $post_types = (array) $wp_query->query['post_type'];
331
- foreach ( $post_types as $post_type ) {
332
- if ( $this->is_valid( $post_type ) ) {
333
- $wp_query->set( 'orderby', 'menu_order' );
334
- $wp_query->set( 'order', 'ASC' );
335
- }
336
- }
337
- }
338
- } else {
339
- $active = false;
340
- if ( isset( $wp_query->query['suppress_filters'] ) || isset( $wp_query->query['post_type'] ) ) {
341
- $post_types = (array) $wp_query->query['post_type'];
342
- foreach ( $post_types as $post_type ) {
343
- if ( $this->is_valid( $post_type ) ) {
344
- $active = true;
345
- }
346
- }
347
- }
348
-
349
- if ( $active ) {
350
- if ( ! isset( $wp_query->query['orderby'] ) || 'post_date' === $wp_query->query['orderby'] ) {
351
- $wp_query->set( 'orderby', 'menu_order' );
352
- }
353
- if ( ! isset( $wp_query->query['order'] ) || 'DESC' === $wp_query->query['order'] ) {
354
- $wp_query->set( 'order', 'ASC' );
355
- }
356
- }
357
- }
358
- }
359
-
360
- /**
361
- * Filters where clause for get next post
362
- *
363
- * @param string $where The 'where'.
364
- *
365
- * @return string
366
- * @since 1.0
367
- * @author Antonio La Rocca <antonio.larocca@yithemes.com>
368
- */
369
- public function sorted_next_post_where( $where ) {
370
- // phpcs:disable WordPress.Security.NonceVerification.Recommended
371
- global $post;
372
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['post_id'] ) ) {
373
- $post = get_post( absint( $_REQUEST['post_id'] ) ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
374
- } else {
375
- $post = get_post(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
376
- }
377
-
378
- if ( ! $post || ! $this->is_valid( $post->post_type ) ) {
379
- return $where;
380
- }
381
-
382
- $result = str_replace( "'" . $post->post_date . "'", $post->menu_order, $where );
383
- $result = str_replace( 'p.post_date', 'p.menu_order', $result );
384
-
385
- return $result;
386
- // phpcs:enable
387
- }
388
-
389
- /**
390
- * Filters where clause for get prev post
391
- *
392
- * @param string $where The 'where'.
393
- *
394
- * @return string
395
- * @since 1.0
396
- * @author Antonio La Rocca <antonio.larocca@yithemes.com>
397
- */
398
- public function sorted_prev_post_where( $where ) {
399
- // phpcs:disable WordPress.Security.NonceVerification.Recommended
400
- global $post;
401
-
402
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['post_id'] ) ) {
403
- $post = get_post( absint( $_REQUEST['post_id'] ) ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
404
- } else {
405
- $post = get_post(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
406
- }
407
-
408
- if ( ! $post || ! $this->is_valid( $post->post_type ) ) {
409
- return $where;
410
- }
411
-
412
- $result = str_replace( "'" . $post->post_date . "'", $post->menu_order, $where );
413
- $result = str_replace( 'p.post_date', 'p.menu_order', $result );
414
-
415
- return $result;
416
- // phpcs:enable
417
- }
418
-
419
- /**
420
- * Filters sort clause for get next post
421
- *
422
- * @param string $sort The 'sort' param.
423
- *
424
- * @return string
425
- * @since 1.0
426
- * @author Antonio La Rocca <antonio.larocca@yithemes.com>
427
- */
428
- public function sorted_next_post_sort( $sort ) {
429
- // phpcs:disable WordPress.Security.NonceVerification.Recommended
430
- global $post;
431
-
432
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['post_id'] ) ) {
433
- $post = get_post( absint( $_REQUEST['post_id'] ) ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
434
- } else {
435
- $post = get_post(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
436
- }
437
-
438
- if ( ! $post || ! $this->is_valid( $post->post_type ) ) {
439
- return $sort;
440
- }
441
-
442
- return str_replace( 'p.post_date', 'p.menu_order', $sort );
443
- // phpcs:enable
444
- }
445
-
446
- /**
447
- * Filters sort clause for get prev post
448
- *
449
- * @param string $sort The 'sort' param.
450
- *
451
- * @return string
452
- * @since 1.0
453
- * @author Antonio La Rocca <antonio.larocca@yithemes.com>
454
- */
455
- public function sorted_prev_post_sort( $sort ) {
456
- // phpcs:disable WordPress.Security.NonceVerification.Recommended
457
- global $post;
458
-
459
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['post_id'] ) ) {
460
- $post = get_post( absint( $_REQUEST['post_id'] ) ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
461
- } else {
462
- $post = get_post(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
463
- }
464
-
465
- if ( ! $post || ! $this->is_valid( $post->post_type ) ) {
466
- return $sort;
467
- }
468
-
469
- return str_replace( 'p.post_date', 'p.menu_order', $sort );
470
- // phpcs:enable
471
- }
472
-
473
- /**
474
- * Register post type
475
- * Register the post type for the creation of portfolios
476
- *
477
- * @return void
478
- * @since 1.0
479
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
480
- */
481
- public function register_post_type() {
482
- $labels = array(
483
- 'name' => ucfirst( $this->labels['main_name'] ),
484
- 'singular_name' => ucfirst( $this->labels['singular'] ),
485
- // translators: %s is the singular name of the post type.
486
- 'add_new' => sprintf( __( 'Add %s', 'yith-plugin-fw' ), ucfirst( $this->labels['singular'] ) ),
487
- // translators: %s is the singular name of the post type.
488
- 'add_new_item' => sprintf( __( 'Add New %s', 'yith-plugin-fw' ), ucfirst( $this->labels['singular'] ) ),
489
- // translators: %s is the singular name of the post type.
490
- 'edit_item' => sprintf( __( 'Edit %s', 'yith-plugin-fw' ), ucfirst( $this->labels['singular'] ) ),
491
- // translators: %s is the singular name of the post type.
492
- 'new_item' => sprintf( __( 'New %s', 'yith-plugin-fw' ), ucfirst( $this->labels['singular'] ) ),
493
- // translators: %s is the plural name of the post type.
494
- 'all_items' => sprintf( __( 'All %s', 'yith-plugin-fw' ), ucfirst( $this->labels['plural'] ) ),
495
- // translators: %s is the singular name of the post type.
496
- 'view_item' => sprintf( __( 'View %s', 'yith-plugin-fw' ), ucfirst( $this->labels['singular'] ) ),
497
- // translators: %s is the plural name of the post type.
498
- 'search_items' => sprintf( __( 'Search %s', 'yith-plugin-fw' ), ucfirst( $this->labels['plural'] ) ),
499
- // translators: %s is the plural name of the post type.
500
- 'not_found' => sprintf( __( 'No %s found', 'yith-plugin-fw' ), ucfirst( $this->labels['plural'] ) ),
501
- // translators: %s is the plural name of the post type.
502
- 'not_found_in_trash' => sprintf( __( 'No %s found in Trash', 'yith-plugin-fw' ), ucfirst( $this->labels['plural'] ) ),
503
- 'parent_item_colon' => '',
504
- 'menu_name' => ucfirst( $this->labels['menu'] ),
505
- );
506
-
507
- $args = array(
508
- 'labels' => apply_filters( 'yit_' . $this->name . '_labels', $labels ),
509
- 'public' => false,
510
- 'publicly_queryable' => false,
511
- 'show_ui' => true,
512
- 'show_in_menu' => true,
513
- 'query_var' => false,
514
- 'capability_type' => 'post',
515
- 'hierarchical' => false,
516
- 'menu_position' => null,
517
- 'supports' => array( 'title' ),
518
- );
519
-
520
- if ( ! empty( $this->args['menu_icon'] ) ) {
521
- $args['menu_icon'] = $this->args['menu_icon'];
522
- }
523
-
524
- register_post_type( $this->name, apply_filters( 'yit_' . $this->name . '_args', $args ) );
525
- }
526
-
527
- /**
528
- * Retrieve the values configured inside the custom post type
529
- *
530
- * @param WP_Post $post The post where get the arguments configured in the cpt.
531
- *
532
- * @return array
533
- * @since 1.0
534
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
535
- */
536
- protected function cpt_args( $post ) {
537
- if ( ! isset( $post->ID ) ) {
538
- return;
539
- }
540
-
541
- $args = apply_filters(
542
- 'yit_cptu_register_post_type_args',
543
- array(
544
- 'layout' => get_post_meta( $post->ID, $this->args['layout_option'], true ),
545
- 'rewrite' => get_post_meta( $post->ID, '_rewrite', true ),
546
- 'label_singular' => ! empty( $this->args['label_item_sing'] ) ? $this->args['label_item_sing'] : get_post_meta( $post->ID, '_label_singular', true ),
547
- 'label_plural' => ! empty( $this->args['label_item_plur'] ) ? $this->args['label_item_plur'] : get_post_meta( $post->ID, '_label_plural', true ),
548
- 'taxonomy' => get_post_meta( $post->ID, '_taxonomy', true ),
549
- 'taxonomy_rewrite' => get_post_meta( $post->ID, '_taxonomy_rewrite', true ),
550
- ),
551
- $this->name,
552
- $post
553
- );
554
-
555
- $title = $post->post_title;
556
-
557
- if ( empty( $args['label_singular'] ) ) {
558
- $args['label_singular'] = $title;
559
- }
560
-
561
- if ( empty( $args['label_plural'] ) ) {
562
- $args['label_plural'] = $title;
563
- }
564
-
565
- return $args;
566
- }
567
-
568
- /**
569
- * Retrieve the post types created for this CPTU
570
- *
571
- * @return array The link changed
572
- * @since 1.0
573
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
574
- */
575
- public function get_post_types() {
576
- if ( ! empty( $this->post_types ) ) {
577
- return $this->post_types;
578
- }
579
-
580
- $args = array(
581
- 'post_type' => $this->name,
582
- 'posts_per_page' => - 1,
583
- 'post_status' => 'publish',
584
- );
585
- $this->post_types = get_posts( $args );
586
-
587
- return $this->post_types;
588
- }
589
-
590
- /**
591
- * Register portfolio post types
592
- * Register the post types for each portfolio created by admin
593
- *
594
- * @return void
595
- * @since 1.0
596
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
597
- */
598
- public function register_cptu_post_types() {
599
- $post_types = $this->get_post_types();
600
- $pts = array();
601
-
602
- foreach ( $post_types as $pt ) {
603
- extract( $this->cpt_args( $pt ) ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
604
- /**
605
- * Fields.
606
- *
607
- * @var string $label_singular The singular label.
608
- * @var string $label_plural The plural label.
609
- * @var string $layout The layout.
610
- */
611
-
612
- $name = $pt->post_name;
613
- $title = $pt->post_title;
614
-
615
- $labels = array(
616
- 'name' => $title,
617
- 'singular_name' => $label_singular,
618
- // translators: $s is the singular name of the post type.
619
- 'add_new' => sprintf( __( 'Add %s', 'yith-plugin-fw' ), $label_singular ),
620
- // translators: $s is the singular name of the post type.
621
- 'add_new_item' => sprintf( __( 'Add New %s', 'yith-plugin-fw' ), $label_singular ),
622
- // translators: $s is the singular name of the post type.
623
- 'edit_item' => sprintf( __( 'Edit %s', 'yith-plugin-fw' ), $label_singular ),
624
- // translators: $s is the singular name of the post type.
625
- 'new_item' => sprintf( __( 'New %s', 'yith-plugin-fw' ), $label_singular ),
626
- // translators: $s is the plural name of the post type.
627
- 'all_items' => sprintf( __( 'All %s', 'yith-plugin-fw' ), $label_plural ),
628
- // translators: $s is the singular name of the post type.
629
- 'view_item' => sprintf( __( 'View %s', 'yith-plugin-fw' ), $label_singular ),
630
- // translators: $s is the plural name of the post type.
631
- 'search_items' => sprintf( __( 'Search %s', 'yith-plugin-fw' ), $label_plural ),
632
- // translators: $s is the plural name of the post type.
633
- 'not_found' => sprintf( __( 'No %s found', 'yith-plugin-fw' ), $label_plural ),
634
- // translators: $s is the plural name of the post type.
635
- 'not_found_in_trash' => sprintf( __( 'No %s found in Trash', 'yith-plugin-fw' ), $label_plural ),
636
- 'parent_item_colon' => '',
637
- 'menu_name' => $title,
638
- );
639
-
640
- $args = array(
641
- 'labels' => apply_filters( 'yit_' . $this->prefix_cpt . $name . '_labels', $labels ),
642
- 'public' => true,
643
- 'publicly_queryable' => true,
644
- 'show_ui' => true,
645
- 'show_in_menu' => false,
646
- 'query_var' => true,
647
- 'capability_type' => 'post',
648
- 'hierarchical' => false,
649
- 'menu_position' => null,
650
- 'supports' => array( 'title', 'editor', 'thumbnail' ),
651
- );
652
-
653
- if ( ! $this->args['has_single'] ) {
654
- $args['public'] = false;
655
- $args['publicly_queryable'] = false;
656
- $args['query_var'] = false;
657
- }
658
-
659
- if ( $this->args['manage_layouts'] && isset( $this->layouts[ $layout ] ) && ! $this->layouts[ $layout ]['support']['description'] ) {
660
- unset( $args['supports'][1] ); // Remove 'editor'.
661
- }
662
-
663
- if ( ! empty( $rewrite ) ) {
664
- $args['rewrite'] = array( 'slug' => $rewrite );
665
- }
666
-
667
- $post_type = yit_avoid_duplicate( str_replace( '-', '_', substr( $this->prefix_cpt . $name, 0, 16 ) ), $post_types );
668
- register_post_type( $post_type, apply_filters( 'yit_' . $this->prefix_cpt . $name . '_args', $args, $pt ) );
669
-
670
- update_post_meta( $pt->ID, '_post_type', $post_type );
671
- $pts[] = $post_type;
672
-
673
- if ( $this->args['has_taxonomy'] && ! empty( $taxonomy ) ) {
674
- $labels = array(
675
- // translators: %s is the singular name of the post type.
676
- 'name' => sprintf( _x( '%s Categories', 'taxonomy general name', 'yith-plugin-fw' ), $label_singular ),
677
- 'singular_name' => _x( 'Category', 'taxonomy singular name', 'yith-plugin-fw' ),
678
- 'search_items' => __( 'Search Categories', 'yith-plugin-fw' ),
679
- 'all_items' => __( 'All Categories', 'yith-plugin-fw' ),
680
- 'parent_item' => __( 'Parent Category', 'yith-plugin-fw' ),
681
- 'parent_item_colon' => __( 'Parent Category:', 'yith-plugin-fw' ),
682
- 'edit_item' => __( 'Edit Category', 'yith-plugin-fw' ),
683
- 'update_item' => __( 'Update Category', 'yith-plugin-fw' ),
684
- 'add_new_item' => __( 'Add New Category', 'yith-plugin-fw' ),
685
- 'new_item_name' => __( 'New Category Name', 'yith-plugin-fw' ),
686
- 'menu_name' => __( 'Category', 'yith-plugin-fw' ),
687
- );
688
-
689
- $args = array(
690
- 'hierarchical' => true,
691
- 'labels' => $labels,
692
- 'show_ui' => true,
693
- 'show_admin_column' => true,
694
- 'query_var' => true,
695
- );
696
-
697
- if ( ! empty( $taxonomy_rewrite ) ) {
698
- $args['rewrite'] = array( 'slug' => $taxonomy_rewrite );
699
- }
700
-
701
- register_taxonomy( substr( $taxonomy, 0, 32 ), $post_type, $args );
702
- }
703
- }
704
-
705
- wp_cache_set( 'yit_cptu_post_types', $post_types );
706
- }
707
-
708
- /**
709
- * Flush Rewrite Rules
710
- * rewrite rules when a cpt unlimited is saved
711
- *
712
- * @param int $post The post ID.
713
- *
714
- * @return void
715
- * @since 1.0
716
- * @author Emanuela Castorina <emanuela.castorina@yithemes.com>
717
- */
718
- public function rewrite_flush( $post ) {
719
- if ( isset( $post ) && $this->is_valid( get_post_type( intval( $post ) ) ) ) {
720
- flush_rewrite_rules();
721
- }
722
- }
723
-
724
- /**
725
- * Add the item for each portfolio under "Portfolios"
726
- *
727
- * @return void
728
- * @since 1.0
729
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
730
- */
731
- public function add_cptu_menu_item() {
732
- // phpcs:disable WordPress.Security.NonceVerification.Recommended,WordPress.WP.GlobalVariablesOverride.Prohibited
733
- global $submenu, $post, $parent_file, $pagenow;
734
-
735
- if ( isset( $post->post_type ) ) {
736
- $post_type = $post->post_type;
737
- } elseif ( isset( $_REQUEST['post_type'] ) ) {
738
- $post_type = sanitize_key( wp_unslash( $_REQUEST['post_type'] ) );
739
- } else {
740
- return;
741
- }
742
-
743
- $item = 'edit.php?post_type=' . $this->name;
744
-
745
- if ( strpos( $post_type, $this->prefix_cpt ) !== false ) {
746
- global $wpdb;
747
- $portfolio = $wpdb->get_row( $wpdb->prepare( "SELECT p.* FROM $wpdb->postmeta AS pm INNER JOIN $wpdb->posts AS p ON p.ID = pm.post_id WHERE pm.meta_key = %s AND pm.meta_value = %s AND p.post_type = %s", '_post_type', $post_type, $this->name ) );
748
-
749
- if ( ! isset( $portfolio->ID ) ) {
750
- return;
751
- }
752
-
753
- $label_singular = ! empty( $this->args['label_item_sing'] ) ? $this->args['label_item_sing'] : get_post_meta( $portfolio->ID, '_label_singular', true );
754
- $label_plural = ! empty( $this->args['label_item_plur'] ) ? $this->args['label_item_plur'] : get_post_meta( $portfolio->ID, '_label_plural', true );
755
-
756
- if ( empty( $label_plural ) ) {
757
- $label_plural = $portfolio->post_title;
758
- }
759
-
760
- if ( empty( $label_singular ) ) {
761
- $label_singular = $portfolio->post_title;
762
- }
763
-
764
- $submenu[ $item ][15] = array( ucfirst( $label_plural ), 'edit_posts', 'edit.php?post_type=' . $post_type );
765
- $submenu[ $item ][20] = array(
766
- sprintf(
767
- // translators: %s is the singular name of the post type.
768
- __( 'Add %s', 'yith-plugin-fw' ),
769
- ucfirst( $label_singular )
770
- ),
771
- 'edit_posts',
772
- 'post-new.php?post_type=' . $post_type,
773
- );
774
-
775
- global $wp_taxonomies;
776
- $taxonomy = get_post_meta( $portfolio->ID, '_taxonomy', true );
777
- if ( isset( $wp_taxonomies[ $taxonomy ] ) ) {
778
- $submenu[ $item ][25] = array( __( 'Categories', 'yith-plugin-fw' ), 'edit_posts', 'edit-tags.php?taxonomy=' . $taxonomy . '&post_type=' . $post_type );
779
- }
780
- }
781
-
782
- // Set the parent item inside the single of each post type.
783
- if ( 'post.php' === $pagenow && isset( $_GET['post'] ) && $this->is_valid( get_post_type( intval( $_GET['post'] ) ) ) ) {
784
- $parent_file = 'edit.php?post_type=' . $this->name;
785
- }
786
-
787
- // phpcs:enable
788
- }
789
-
790
- /**
791
- * Locate folder of CPTU templates, if there isn't a layouts management
792
- *
793
- * @return string
794
- * @since 1.0
795
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
796
- */
797
- public function template_path() {
798
- if ( ! empty( $this->template_path ) ) {
799
- return $this->template_path;
800
- }
801
-
802
- $stylesheet_path_1 = get_stylesheet_directory() . '/theme/templates/' . $this->name . '/';
803
- $stylesheet_path_2 = get_template_directory() . '/theme/templates/' . $this->name . '/';
804
- $template_path_1 = get_stylesheet_directory() . '/' . $this->name . '/';
805
- $template_path_2 = get_template_directory() . '/' . $this->name . '/';
806
- $plugin_path = $this->args['plugin_path'] . '/templates/';
807
-
808
- foreach ( array( 'stylesheet_path_1', 'stylesheet_path_2', 'template_path_1', 'template_path_2', 'plugin_path' ) as $var ) {
809
- $path = ${$var};
810
-
811
- if ( file_exists( $path ) ) {
812
- $this->template_path = $path;
813
- }
814
- }
815
-
816
- return $this->template_path;
817
- }
818
-
819
- /**
820
- * Locate folder of CPTU templates, if there isn't a layouts management
821
- *
822
- * @return string
823
- * @since 1.0
824
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
825
- */
826
- public function template_url() {
827
- if ( ! empty( $this->template_url ) ) {
828
- return $this->template_path;
829
- }
830
-
831
- $this->template_url = str_replace(
832
- array(
833
- get_stylesheet_directory(),
834
- get_template_directory(),
835
- $this->args['plugin_path'],
836
- ),
837
- array(
838
- get_stylesheet_directory_uri(),
839
- get_template_directory_uri(),
840
- $this->args['plugin_url'],
841
- ),
842
- $this->template_path()
843
- );
844
-
845
- return $this->template_url;
846
- }
847
-
848
- /**
849
- * Retrieve all layouts to manage by custom post type added in the site in this order:
850
- * 1. Child theme (if exists)
851
- * 2. Theme
852
- * 3. Plugin
853
- * It also load the config.php file of each layout
854
- *
855
- * @return void
856
- * @since 1.0
857
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
858
- */
859
- public function get_layouts() {
860
- $stylesheet_path_1 = get_stylesheet_directory() . '/theme/templates/' . $this->name . '/';
861
- $stylesheet_path_2 = get_template_directory() . '/theme/templates/' . $this->name . '/';
862
- $template_path_1 = get_stylesheet_directory() . '/' . $this->name . '/';
863
- $template_path_2 = get_template_directory() . '/' . $this->name . '/';
864
- $plugin_path = $this->args['plugin_path'] . '/templates/';
865
-
866
- foreach ( array( 'stylesheet_path_1', 'stylesheet_path_2', 'template_path_1', 'template_path_2', 'plugin_path' ) as $var ) {
867
- $path = ${$var};
868
-
869
- if ( file_exists( $path ) ) {
870
- foreach ( scandir( $path ) as $scan ) {
871
- if ( ! isset( $this->layouts[ $scan ] ) && is_dir( $path . $scan ) && ! in_array( $scan, array( '.', '..', '.svn' ), true ) && '_' !== $scan[0] ) {
872
- $this->layouts[ $scan ] = array(
873
- 'name' => ucfirst( str_replace( '-', ' ', $scan ) ),
874
- 'path' => $path . $scan,
875
- 'url' => str_replace(
876
- array(
877
- get_stylesheet_directory(),
878
- get_template_directory(),
879
- $this->args['plugin_path'],
880
- ),
881
- array(
882
- get_stylesheet_directory_uri(),
883
- get_template_directory_uri(),
884
- $this->args['plugin_url'],
885
- ),
886
- $path . $scan
887
- ),
888
- 'css' => array(),
889
- 'js' => array(),
890
- 'support' => array(
891
- 'description' => true,
892
- ),
893
- 'columns' => array(),
894
- );
895
-
896
- // Set the vars for config.php.
897
- $layout = $scan;
898
- $this->layout = $layout; // temporary attribute to load automatically the configuration inside the config.php, for this layout.
899
-
900
- if ( ! in_array( $scan, array( 'single' ), true ) && file_exists( $path . $scan . '/config.php' ) ) {
901
- include_once $path . $scan . '/config.php';
902
- }
903
- }
904
- }
905
- }
906
- }
907
- }
908
-
909
- /**
910
- * Say if you want to set description for the current layout or not. This method must be used only inside the
911
- * config.php file of layout
912
- *
913
- * @param string $v 'yes' or 'no'.
914
- *
915
- * @return void
916
- * @since 1.0
917
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
918
- */
919
- public function add_description_field( $v ) {
920
- $this->layouts[ $this->layout ]['support']['description'] = 'yes' === $v;
921
- }
922
-
923
- /**
924
- * Add the extra fields for the specific layout type of portfolio
925
- *
926
- * @param array $fields The fields to add.
927
- *
928
- * @return void
929
- * @since 1.0
930
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
931
- */
932
- public function add_layout_fields( $fields = array() ) {
933
- foreach ( $fields as $id => $val ) {
934
- unset( $fields[ $id ] );
935
- $id = $this->layout . '_' . $id;
936
- $fields[ $id ] = $val;
937
- }
938
-
939
- $this->layouts[ $this->layout ]['fields'] = $fields;
940
- }
941
-
942
- /**
943
- * Add fields to add to the metabox of each item of each post type created
944
- *
945
- * @param array $fields The fields to add.
946
- *
947
- * @return void
948
- * @since 1.0
949
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
950
- */
951
- public function add_item_fields( $fields = array() ) {
952
- foreach ( $fields as $id => $val ) {
953
- unset( $fields[ $id ] );
954
- $fields[ $id ] = $val;
955
- }
956
- $this->layouts[ $this->layout ]['item_fields'] = $fields;
957
- }
958
-
959
- /**
960
- * Add columns to the table list
961
- *
962
- * @param array $columns The columns to add in the table list.
963
- *
964
- * @return void
965
- * @since 1.0
966
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
967
- */
968
- public function add_table_columns( $columns ) {
969
- $this->layouts[ $this->layout ]['columns'] = $columns;
970
- }
971
-
972
- /**
973
- * Enqueue the css files of layout
974
- *
975
- * @param string $handle Name of the stylesheet.
976
- * @param string|bool $src Path to the stylesheet from the root directory of WordPress. Example: '/css/mystyle.css'.
977
- * @param array $deps An array of registered style handles this stylesheet depends on. Default empty array.
978
- * @param string|bool $ver String specifying the stylesheet version number, if it has one. This parameter is used
979
- * to ensure that the correct version is sent to the client regardless of caching, and so
980
- * should be included if a version number is available and makes sense for the stylesheet.
981
- * @param string $media Optional. The media for which this stylesheet has been defined.
982
- * Default 'all'. Accepts 'all', 'aural', 'braille', 'handheld', 'projection', 'print',
983
- * 'screen', 'tty', or 'tv'.
984
- *
985
- * @return void
986
- * @since 1.0
987
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
988
- */
989
- public function enqueue_style( $handle, $src = false, $deps = array(), $ver = false, $media = 'all' ) {
990
- $this->layouts[ $this->layout ]['css'][] = compact( 'handle', 'src', 'deps', 'ver', 'media' );
991
- }
992
-
993
- /**
994
- * Enqueue the js files of layout
995
- *
996
- * @param string $handle Name of the script.
997
- * @param string|bool $src Path to the script from the root directory of WordPress. Example: '/js/myscript.js'.
998
- * @param array $deps An array of registered handles this script depends on. Default empty array.
999
- * @param string|bool $ver Optional. String specifying the script version number, if it has one. This parameter
1000
- * is used to ensure that the correct version is sent to the client regardless of caching,
1001
- * and so should be included if a version number is available and makes sense for the script.
1002
- * @param bool $in_footer Optional. Whether to enqueue the script before </head> or before </body>.
1003
- * Default 'false'. Accepts 'false' or 'true'.
1004
- *
1005
- * @return void
1006
- * @since 1.0
1007
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
1008
- */
1009
- public function enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $in_footer = false ) {
1010
- $this->layouts[ $this->layout ]['js'][] = compact( 'handle', 'src', 'deps', 'ver', 'in_footer' );
1011
- }
1012
-
1013
- /**
1014
- * Enqueue the assets for the frontend
1015
- *
1016
- * @return void
1017
- * @since 1.0
1018
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
1019
- */
1020
- public function frontend_assets() {
1021
- global $post;
1022
-
1023
- // Not single.
1024
- if ( ! is_single() || ! isset( $post->post_type ) || ! $this->is_valid( $post->post_type ) ) {
1025
- $posts = get_posts(
1026
- array(
1027
- 'post_type' => $this->name,
1028
- 'posts_per_page' => - 1,
1029
- 'post_status' => 'publish',
1030
- 'fields' => 'ids',
1031
- )
1032
- );
1033
-
1034
- $enqueued = array();
1035
-
1036
- foreach ( $posts as $post_id ) {
1037
- $layout = get_post_meta( $post_id, $this->args['layout_option'], true );
1038
-
1039
- if ( in_array( $layout, array( $enqueued ), true ) || ! isset( $this->layouts[ $layout ]['css'] ) ) {
1040
- continue;
1041
- }
1042
-
1043
- foreach ( $this->layouts[ $layout ]['css'] as $asset ) {
1044
- if ( empty( $asset ) ) {
1045
- continue;
1046
- }
1047
- yit_enqueue_style( $asset['handle'], empty( $asset['src'] ) ? false : $this->locate_url( $layout ) . $asset['src'], $asset['deps'], $asset['ver'], $asset['media'] );
1048
- }
1049
-
1050
- $enqueued[] = $layout;
1051
- }
1052
- } else {
1053
- // Load assets of single template.
1054
- $layout = 'single';
1055
-
1056
- if ( ! isset( $this->layouts[ $layout ]['css'] ) ) {
1057
- return;
1058
- }
1059
-
1060
- foreach ( $this->layouts[ $layout ]['css'] as $asset ) {
1061
- if ( empty( $asset ) ) {
1062
- continue;
1063
- }
1064
- yit_enqueue_style( $asset['handle'], $this->locate_url( $layout ) . $asset['src'], $asset['deps'], $asset['ver'], $asset['media'] );
1065
- }
1066
- }
1067
-
1068
  }
1069
 
1070
  /**
1071
- * Register Metaboxes options
1072
- * Add the metabox for the portfolio settings
1073
  *
1074
- * @return void
1075
- * @since 1.0
1076
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
1077
- */
1078
- public function add_metabox_cptu() {
1079
-
1080
- // Reorganize layouts.
1081
- if ( $this->args['manage_layouts'] ) {
1082
- $layouts = array();
1083
- foreach ( $this->layouts as $layout_id => $layout ) {
1084
- if ( 'single' === $layout_id ) {
1085
- continue;
1086
- }
1087
- $layouts[ $layout_id ] = $layout['name'];
1088
- }
1089
-
1090
- $layouts = apply_filters( 'yit_cptu_' . $this->name . '_layout_values', $layouts );
1091
- }
1092
-
1093
- $single_layouts = apply_filters( 'yit_cptu_' . $this->name . '_single_layout_values', array() );
1094
-
1095
- $metabox_args = array(
1096
- 'label' => sprintf(
1097
- // translators: %s is the singular name of the post type.
1098
- __( '%s Settings', 'yith-plugin-fw' ),
1099
- $this->labels['singular']
1100
- ),
1101
- 'pages' => $this->name,
1102
- 'context' => 'normal',
1103
- 'priority' => 'default',
1104
- 'tabs' => array(
1105
- 'settings' => array(
1106
- 'label' => __( 'Settings', 'yith-plugin-fw' ),
1107
- 'fields' => apply_filters(
1108
- 'yit_cptu_fields',
1109
- array(
1110
- 'type' => array(
1111
- 'label' => __( 'Type', 'yith-plugin-fw' ),
1112
- 'desc' => sprintf(
1113
- // translators: %s is the singular name of the post type.
1114
- __( 'Layout for this %s', 'yith-plugin-fw' ),
1115
- strtolower( $this->labels['singular'] )
1116
- ),
1117
- 'type' => 'select',
1118
- 'options' => isset( $layouts ) ? $layouts : array(),
1119
- 'std' => '',
1120
- ),
1121
- 'rewrite' => array(
1122
- 'label' => __( 'Rewrite', 'yith-plugin-fw' ),
1123
- 'desc' => __( 'Univocal identification name in the URL for each product (slug from post if empty)', 'yith-plugin-fw' ),
1124
- 'type' => 'text',
1125
- 'std' => '',
1126
- ),
1127
- 'label_singular' => array(
1128
- 'label' => __( 'Label in Singular', 'yith-plugin-fw' ),
1129
- 'desc' => __( 'Set a label in singular (title of portfolio if empty)', 'yith-plugin-fw' ),
1130
- 'type' => 'text',
1131
- 'std' => '',
1132
- ),
1133
- 'label_plural' => array(
1134
- 'label' => __( 'Label in Plural', 'yith-plugin-fw' ),
1135
- 'desc' => __( 'Set a label in plural (title of portfolio if empty)', 'yith-plugin-fw' ),
1136
- 'type' => 'text',
1137
- 'std' => '',
1138
- ),
1139
- 'taxonomy' => array(
1140
- 'label' => __( 'Taxonomy', 'yith-plugin-fw' ),
1141
- 'desc' => __( 'If you want to use categories in the portfolio, set a name for taxonomy. Name should be a slug (must not contain capital letters nor spaces) and must not be more than 32 characters long (database structure restriction).', 'yith-plugin-fw' ),
1142
- 'type' => 'text',
1143
- 'std' => '',
1144
- ),
1145
- 'taxonomy_rewrite' => array(
1146
- 'label' => __( 'Taxonomy Rewrite', 'yith-plugin-fw' ),
1147
- 'desc' => __( 'Set univocal name for each category page URL.', 'yith-plugin-fw' ),
1148
- 'type' => 'text',
1149
- 'std' => '',
1150
- ),
1151
- 'single_layout' => array(
1152
- 'label' => __( 'Single layout', 'yith-plugin-fw' ),
1153
- 'desc' => __( 'Layout for single page of this portfolio', 'yith-plugin-fw' ),
1154
- 'type' => 'select',
1155
- 'options' => $single_layouts,
1156
- 'std' => '',
1157
- ),
1158
- )
1159
- ),
1160
- ),
1161
- ),
1162
-
1163
- );
1164
-
1165
- if ( ! $this->args['has_single'] ) {
1166
- unset( $metabox_args['tabs']['settings']['fields']['rewrite'] );
1167
- }
1168
-
1169
- if ( ! $this->args['has_taxonomy'] ) {
1170
- unset( $metabox_args['tabs']['settings']['fields']['taxonomy'] );
1171
- unset( $metabox_args['tabs']['settings']['fields']['taxonomy_rewrite'] );
1172
- }
1173
-
1174
- if ( ! empty( $this->args['label_item_sing'] ) ) {
1175
- unset( $metabox_args['tabs']['settings']['fields']['label_singular'] );
1176
- }
1177
-
1178
- if ( ! empty( $this->args['label_item_plur'] ) ) {
1179
- unset( $metabox_args['tabs']['settings']['fields']['label_plural'] );
1180
- }
1181
-
1182
- if ( $this->args['manage_layouts'] ) {
1183
-
1184
- if ( count( $layouts ) < 1 ) {
1185
- unset( $metabox_args['tabs']['settings']['fields']['type'] );
1186
- }
1187
-
1188
- // Layouts options.
1189
- foreach ( $this->layouts as $layout => $args ) {
1190
- if ( ! isset( $args['fields'] ) ) {
1191
- continue;
1192
- }
1193
-
1194
- // Section title.
1195
- $metabox_args['tabs']['settings']['fields'][ $layout . '_title' ] = array(
1196
- 'desc' => $args['name'] . ' ' . __( 'layout settings', 'yith-plugin-fw' ),
1197
- 'type' => 'title',
1198
- 'deps' => array(
1199
- 'ids' => '_type',
1200
- 'values' => $layout,
1201
- ),
1202
- );
1203
-
1204
- // Options.
1205
- foreach ( $args['fields'] as $field_id => $field ) {
1206
- $metabox_args['tabs']['settings']['fields'][ $field_id ] = $field;
1207
- $metabox_args['tabs']['settings']['fields'][ $field_id ]['deps'] = array(
1208
- 'ids' => '_type',
1209
- 'values' => $layout,
1210
- );
1211
- }
1212
- }
1213
- } else {
1214
- unset( $metabox_args['tabs']['settings']['fields']['type'] );
1215
- }
1216
-
1217
- if ( count( $single_layouts ) < 1 ) {
1218
- unset( $metabox_args['tabs']['settings']['fields']['single_layout'] );
1219
- }
1220
-
1221
- // Undo if tab empty.
1222
- if ( empty( $metabox_args['tabs']['settings']['fields'] ) ) {
1223
- return;
1224
- }
1225
-
1226
- $metabox = YIT_Metabox( $this->name . '_cptu_settings' );
1227
- $metabox->init( $metabox_args );
1228
- }
1229
-
1230
- /**
1231
- * Register Metaboxes options
1232
- * Add the metabox for the portfolio settings
1233
- *
1234
- * @return void
1235
- * @since 1.0
1236
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
1237
- */
1238
- public function add_metabox_item_fields() {
1239
- // phpcs:disable WordPress.Security.NonceVerification.Recommended,WordPress.WP.GlobalVariablesOverride.Prohibited
1240
- global $pagenow, $post_type;
1241
-
1242
- // Get the actual post type, to add the metabox only if necessary.
1243
- if ( 'post.php' === $pagenow && isset( $_REQUEST['post'] ) ) {
1244
- $post_type = get_post_type( intval( $_REQUEST['post'] ) );
1245
- } elseif ( 'post.php' === $pagenow && isset( $_REQUEST['post_ID'] ) ) {
1246
- $post_type = get_post_type( intval( $_REQUEST['post_ID'] ) );
1247
- } elseif ( 'post-new.php' === $pagenow && isset( $_REQUEST['post_type'] ) ) {
1248
- $post_type = sanitize_key( wp_unslash( $_REQUEST['post_type'] ) );
1249
- } else {
1250
- return;
1251
- }
1252
-
1253
- $layout = get_post_meta( $this->get_id_by_name( $post_type ), $this->args['layout_option'], true );
1254
-
1255
- if ( empty( $this->layouts[ $layout ]['item_fields'] ) ) {
1256
- return;
1257
- }
1258
-
1259
- $metabox_args = array(
1260
- 'label' => __( 'Settings', 'yith-plugin-fw' ),
1261
- 'pages' => $post_type,
1262
- 'context' => 'normal',
1263
- 'priority' => 'default',
1264
- 'tabs' => array(
1265
- 'settings' => array(
1266
- 'label' => __( 'Settings', 'yith-plugin-fw' ),
1267
- 'fields' => $this->layouts[ $layout ]['item_fields'],
1268
- ),
1269
- ),
1270
- );
1271
-
1272
- $metabox = YIT_Metabox( $post_type . '_item_fields' );
1273
- $metabox->init( $metabox_args );
1274
-
1275
- // phpcs:enable
1276
- }
1277
-
1278
- /**
1279
- * Add quick links inside the editing page of CPTU and Custom Post Types
1280
- *
1281
- * @return void
1282
- * @since 1.0
1283
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
1284
- */
1285
- public function add_quick_links_metaboxes() {
1286
- add_meta_box( $this->name . '_quick_links', __( 'Quick links', 'yith-plugin-fw' ), array( $this, 'quick_links_cptu_inner' ), $this->name, 'side', 'high' );
1287
-
1288
- $args = array(
1289
- 'post_type' => $this->name,
1290
- 'posts_per_page' => - 1,
1291
- 'post_status' => 'publish',
1292
- );
1293
- $post_types = get_posts( $args );
1294
-
1295
- foreach ( $post_types as $post ) {
1296
- $post_type = get_post_meta( $post->ID, '_post_type', true );
1297
- add_meta_box( $post->post_type . '_quick_links', __( 'Quick links', 'yith-plugin-fw' ), array( $this, 'quick_links_cpt_inner' ), $post_type, 'side', 'high' );
1298
- }
1299
- }
1300
-
1301
- /**
1302
- * Link to: "View Items", inside the CPTU
1303
- *
1304
- * @param WP_Post $post The post.
1305
- *
1306
- * @return void
1307
- * @since 1.0
1308
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
1309
- */
1310
- public function quick_links_cptu_inner( $post ) {
1311
- extract( $this->cpt_args( $post ) ); //phpcs:ignore WordPress.PHP.DontExtract.extract_extract
1312
- /**
1313
- * Extracted fields.
1314
- *
1315
- * @var string $label_plural The plural label.
1316
- */
1317
- ?>
1318
- <a href="<?php echo esc_url( admin_url( 'edit.php?post_type=' . get_post_meta( $post->ID, '_post_type', true ) ) ); ?>">
1319
- <?php
1320
- echo esc_html(
1321
- sprintf(
1322
- // translators: %s is the plural label of the post type.
1323
- __( 'View %s', 'yith-plugin-fw' ),
1324
- $label_plural
1325
- )
1326
- );
1327
- ?>
1328
- </a>
1329
- <?php
1330
- }
1331
-
1332
- /**
1333
- * Link to: "Edit %s", inside the CPTU
1334
- *
1335
- * @param WP_Post $post The Post.
1336
- *
1337
- * @return void
1338
- * @since 1.0
1339
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
1340
- */
1341
- public function quick_links_cpt_inner( $post ) {
1342
- $post = get_post( $this->get_id_by_name( $post->post_type ) );
1343
- $url = admin_url( "post.php?post={$post->ID}&action=edit" );
1344
- ?>
1345
- <a href="<?php echo esc_url( $url ); ?>">
1346
- <?php
1347
- echo esc_html(
1348
- sprintf(
1349
- // translators: %s is the post title.
1350
- __( 'Edit %s', 'yith-plugin-fw' ),
1351
- $post->post_title
1352
- )
1353
- );
1354
- ?>
1355
- </a>
1356
- <?php
1357
- }
1358
-
1359
- /**
1360
- * Define the columns to use in the list table of main sliders post type
1361
- *
1362
- * @param array $columns The columns used in the list table.
1363
- *
1364
- * @return array
1365
- * @since 1.0
1366
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
1367
- */
1368
- public function cptu_define_columns( $columns ) {
1369
- unset( $columns['date'] );
1370
-
1371
- $columns['actions'] = '';
1372
-
1373
- return $columns;
1374
- }
1375
-
1376
- /**
1377
- * Change the content of each column of the table list
1378
- *
1379
- * @param string $column The current column.
1380
- * @param int $post_id The current post ID.
1381
- *
1382
- * @return void
1383
- * @since 1.0
1384
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
1385
- */
1386
- public function cptu_change_columns( $column, $post_id ) {
1387
- $post = get_post( $post_id );
1388
- extract( $this->cpt_args( $post ) ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
1389
- /**
1390
- * Extracted fields.
1391
- *
1392
- * @var string $label_plural The plural label.
1393
- */
1394
-
1395
- switch ( $column ) {
1396
- case 'actions':
1397
- $edit_url = admin_url( "post.php?post={$post_id}&action=edit" );
1398
- $view_url = admin_url( 'edit.php?post_type=' . get_post_meta( $post_id, '_post_type', true ) );
1399
- $edit_label = sprintf(
1400
- // translators: %s is the singular name of the post type.
1401
- __( 'Edit %s', 'yith-plugin-fw' ),
1402
- ucfirst( $this->labels['singular'] )
1403
- );
1404
- $view_label = sprintf(
1405
- // translators: %s is the plural name of the post type.
1406
- __( 'View %s', 'yith-plugin-fw' ),
1407
- $label_plural
1408
- );
1409
- echo '<a href="' . esc_url( $edit_url ) . '" class="button-secondary">' . esc_html( $edit_label ) . '</a> ';
1410
- echo '<a href="' . esc_url( $view_url ) . '" class="button-secondary">' . esc_html( $view_label ) . '</a> ';
1411
- break;
1412
- }
1413
- }
1414
-
1415
- /**
1416
- * Retrieve the path of layout specified in parameter
1417
- *
1418
- * @param string $layout The layout.
1419
- * @param string $file The file to find.
1420
- *
1421
- * @return bool|string
1422
- * @since 1.0
1423
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
1424
- */
1425
- public function locate_file( $layout, $file = '' ) {
1426
- if ( ! $this->args['manage_layouts'] ) {
1427
- return $this->template_path() . '/' . ( ! empty( $file ) ? $file . '.php' : '' );
1428
- }
1429
-
1430
- if ( ! isset( $this->layouts[ $layout ] ) ) {
1431
- $layout = 'default';
1432
- }
1433
-
1434
- return $this->layouts[ $layout ]['path'] . '/' . ( ! empty( $file ) ? $file . '.php' : '' );
1435
- }
1436
-
1437
- /**
1438
- * Retrieve the URL of layout specified in parameter
1439
- *
1440
- * @param string $layout The layout.
1441
- * @param string $file The file to find.
1442
- *
1443
- * @return bool|string
1444
- * @since 1.0
1445
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
1446
- */
1447
- public function locate_url( $layout, $file = '' ) {
1448
- if ( ! $this->args['manage_layouts'] ) {
1449
- return $this->template_url();
1450
-
1451
- }
1452
-
1453
- if ( ! isset( $this->layouts[ $layout ] ) ) {
1454
- $layout = 'default';
1455
- }
1456
-
1457
- return $this->layouts[ $layout ]['url'] . '/' . ( ! empty( $file ) ? $file . '.php' : '' );
1458
- }
1459
-
1460
- /**
1461
- * Retrieve the post ID relative to the post of post type
1462
- *
1463
- * @param string $name the name.
1464
- *
1465
- * @return mixed
1466
- * @since 1.0
1467
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
1468
- */
1469
- protected function get_id_by_name( $name ) {
1470
- global $wpdb;
1471
-
1472
- return $wpdb->get_var( $wpdb->prepare( "SELECT pm.post_id FROM $wpdb->postmeta AS pm INNER JOIN $wpdb->posts AS p ON p.ID = pm.post_id WHERE pm.meta_key = %s AND pm.meta_value = %s AND p.post_type = %s", '_post_type', $name, $this->name ) );
1473
- }
1474
-
1475
- /**
1476
- * Retrieve the post_type of portfolio by portfolio name
1477
- *
1478
- * @param string $name the name.
1479
- *
1480
- * @return mixed
1481
- * @since 1.0
1482
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
1483
- */
1484
- protected function get_post_type_by_name( $name ) {
1485
- global $wpdb;
1486
-
1487
- return $wpdb->get_var( $wpdb->prepare( "SELECT pm.meta_value FROM $wpdb->postmeta AS pm INNER JOIN $wpdb->posts AS p ON p.ID = pm.post_id WHERE pm.meta_key = %s AND p.post_name = %s AND p.post_type = %s", '_post_type', $name, $this->name ) );
1488
- }
1489
-
1490
- /**
1491
- * The shortcode used to show the frontend
1492
- *
1493
- * @param array $atts Attributes.
1494
- * @param string|null $content The content.
1495
- *
1496
- * @return string|null
1497
- * @since 1.0
1498
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
1499
- */
1500
- public function add_shortcode( $atts, $content = null ) {
1501
- $atts = wp_parse_args(
1502
- $atts,
1503
- array(
1504
- 'name' => null,
1505
- 'cat' => array(),
1506
- 'posts_per_page' => false,
1507
- 'style' => null,
1508
- )
1509
- );
1510
-
1511
- // Don't show the slider if 'name' is empty or is 'none'.
1512
- if ( empty( $atts['name'] ) || 'none' === $atts['name'] ) {
1513
- return null;
1514
- }
1515
-
1516
- // Compatibility fix: remove prefix if exists in portfolio object.
1517
- if ( function_exists( 'YIT_Portfolio' ) && method_exists( YIT_Portfolio(), 'is' ) && YIT_Portfolio()->is( $atts['name'] ) ) {
1518
- $atts['name'] = str_replace( YIT_Portfolio()->post_type_prefix, '', $atts['name'] );
1519
- }
1520
-
1521
- // Pass vars to template.
1522
- $atts['post_type'] = $this->get_post_type_by_name( $atts['name'] );
1523
- $atts['layout'] = $this->args['manage_layouts'] ? get_post_meta( $this->get_id_by_name( $atts['post_type'] ), $this->args['layout_option'], true ) : '';
1524
- extract( apply_filters( 'yit_cptu_frontend_vars', $atts, $this->name ) ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
1525
-
1526
- /**
1527
- * Extracted fields.
1528
- *
1529
- * @var string $layout The layout.
1530
- */
1531
-
1532
- // Add the javascript assets.
1533
- if ( $this->args['manage_layouts'] && isset( $this->layouts[ $layout ]['js'] ) && ! empty( $this->layouts[ $layout ]['js'] ) ) {
1534
- foreach ( $this->layouts[ $layout ]['js'] as $asset ) {
1535
- if ( empty( $asset ) ) {
1536
- continue;
1537
- }
1538
-
1539
- if ( empty( $asset['src'] ) ) {
1540
- wp_enqueue_script( $asset['handle'] );
1541
- continue;
1542
- }
1543
-
1544
- yit_enqueue_script( $asset['handle'], $this->locate_url( $layout ) . $asset['src'], $asset['deps'], $asset['ver'], $asset['in_footer'] );
1545
- }
1546
- }
1547
-
1548
- // Unique sequential index to differentiate more cpt in the same page.
1549
- ++ $this->index;
1550
-
1551
- ob_start();
1552
- include $this->locate_file( $layout, 'markup' );
1553
-
1554
- return ob_get_clean();
1555
- }
1556
-
1557
- /**
1558
- * Shortcode icon
1559
- * Return the shortcode icone to display on shortcode panel
1560
- *
1561
- * @param string $icon_url Icone url found by yit_shortcode plugin.
1562
- *
1563
- * @return string
1564
- * @since 1.0.0
1565
- * @author Antonino Scarfi' <antonio.scarfi@yithemes.it>
1566
- */
1567
- public function shortcode_icon( $icon_url ) {
1568
- return ! empty( $this->args['shortcode_icon'] ) ? $this->args['shortcode_icon'] : $icon_url;
1569
- }
1570
-
1571
- /**
1572
- * Return an array with cptu options to shortcode panel
1573
- * All definition settings to add cptu shortcode to Yit Shortcode Panel
1574
- *
1575
- * @param array $shortcodes Shortcodes.
1576
- *
1577
- * @return array
1578
- * @since 1.0
1579
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
1580
- */
1581
- public function add_shortcode_to_box( $shortcodes ) {
1582
- $post_types = array();
1583
-
1584
- foreach ( $this->get_post_types() as $post ) {
1585
- $post_types[ $post->post_name ] = $post->post_title;
1586
- }
1587
-
1588
- $args = array(
1589
- $this->args['shortcode_name'] => array(
1590
- 'title' => $this->labels['singular'],
1591
- 'description' => sprintf(
1592
- // translators: %s is the name of the post type.
1593
- __( 'Show frontend of the %s', 'yith-plugin-fw' ),
1594
- $this->labels['main_name']
1595
- ),
1596
- 'tab' => 'cpt',
1597
- 'create' => false,
1598
- 'has_content' => false,
1599
- 'in_visual_composer' => true,
1600
- 'attributes' => array(
1601
- 'name' => array(
1602
- 'title' => __( 'Name', 'yith-plugin-fw' ),
1603
- 'type' => 'select',
1604
- 'options' => $post_types,
1605
- 'std' => '',
1606
- ),
1607
- ),
1608
- ),
1609
- );
1610
-
1611
- return array_merge( $shortcodes, $args );
1612
- }
1613
-
1614
- /**
1615
- * Check the post type passed in parameter, if is generated by this CPTU
1616
- *
1617
- * @param string $post_type The post type to check.
1618
  *
1619
  * @return bool
1620
- * @since 1.0
1621
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
1622
- */
1623
- protected function is_valid( $post_type ) {
1624
- return (bool) ( strpos( $post_type, $this->args['post_type_prefix'] ) !== false );
1625
- }
1626
-
1627
- /**
1628
- * Add as a valid post type all cptu when importing dummy data
1629
- *
1630
- * @param array $post The post object.
1631
- *
1632
- * @return array
1633
- * @since 1.0
1634
- * @author Antonio La Rocca <antonio.larocca@yithemes.com>
1635
- */
1636
- public function add_importer_required_post_type( $post ) {
1637
- // phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited
1638
- global $wp_post_types, $wp_taxonomies;
1639
-
1640
- if ( strpos( $post['post_type'], $this->prefix_cpt ) === false ) {
1641
- return $post;
1642
- }
1643
-
1644
- if ( ! isset( $wp_post_types[ $post['post_type'] ] ) ) {
1645
- $wp_post_types[ $post['post_type'] ] = array( 'name' => '' );
1646
- }
1647
-
1648
- if ( ! empty( $post['terms'] ) ) {
1649
- foreach ( $post['terms'] as $term ) {
1650
- if ( ! isset( $wp_taxonomies[ $term['domain'] ] ) ) {
1651
- $wp_taxonomies[ $term['domain'] ] = array( 'name' => '' );
1652
- }
1653
- }
1654
- }
1655
-
1656
- return $post;
1657
- // phpcs:enable
1658
- }
1659
-
1660
- /**
1661
- * Add taxonomy when importing dummy data
1662
- *
1663
- * @param array $terms Array of terms.
1664
- *
1665
- * @return array
1666
- * @since 1.0
1667
- * @author Antonio La Rocca <antonio.larocca@yithemes.com>
1668
- */
1669
- public function add_importer_required_taxonomy( $terms ) {
1670
- // phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited
1671
- global $wp_taxonomies;
1672
-
1673
- if ( ! empty( $terms ) ) {
1674
- foreach ( $terms as $term ) {
1675
- if ( isset( $term['domain'] ) && ! isset( $wp_taxonomies[ $term['domain'] ] ) ) {
1676
- $wp_taxonomies[ $term['domain'] ] = array( 'name' => '' );
1677
- }
1678
- }
1679
- }
1680
-
1681
- return $terms;
1682
- // phpcs:enable
1683
- }
1684
-
1685
- /**
1686
- * Force terms recount for imported taxonomy
1687
- *
1688
- * @param array $tt_ids Terms ids.
1689
- * @param array $ids Post ids.
1690
- * @param string $tax Taxonomy name.
1691
- *
1692
- * @return void
1693
- * @since 1.0
1694
- * @author Antonio La Rocca <antonio.larocca@yithemes.com>
1695
  */
1696
- public function recount_terms_post( $tt_ids, $ids, $tax ) {
1697
- wp_update_term_count( $tt_ids, $tax );
1698
  }
1699
 
1700
- // ### ASSETS ###
1701
-
1702
  /**
1703
- * Enqueue the assets for the admin
1704
  *
1705
- * @return void
1706
- * @since 1.0
1707
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
1708
- */
1709
- public function admin_assets() {
1710
- $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1711
- wp_enqueue_media();
1712
- wp_enqueue_script( 'yit-cptu', YIT_CORE_PLUGIN_URL . '/assets/js/yit-cpt-unlimited' . $suffix . '.js', array( 'jquery' ), '1.0.0', true );
1713
- }
1714
-
1715
- /**
1716
- * Add the button to the top of the list table page of CPTU
1717
  *
1718
- * @return void
1719
- * @since 1.0
1720
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
1721
- */
1722
- public function add_button_multiuploader() {
1723
- global $pagenow, $post_type, $wpdb;
1724
-
1725
- if ( 'edit.php' !== $pagenow ) {
1726
- return;
1727
- }
1728
-
1729
- $cptu = $wpdb->get_var( $wpdb->prepare( "SELECT p.post_type FROM $wpdb->postmeta AS pm INNER JOIN $wpdb->posts AS p ON p.ID = pm.post_id WHERE pm.meta_key = %s AND pm.meta_value = %s", '_post_type', $post_type ) );
1730
-
1731
- $post = get_post( $this->get_id_by_name( $post_type ) );
1732
- if ( empty( $post ) ) {
1733
- return;
1734
- }
1735
- extract( $this->cpt_args( $post ) ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
1736
-
1737
- /**
1738
- * Extracted fields.
1739
- *
1740
- * @var string $label_plural The plural label.
1741
- */
1742
-
1743
- if ( $cptu !== $this->name || ! $this->is_valid( $post_type ) ) {
1744
- return;
1745
- }
1746
-
1747
- $uploader_title = sprintf(
1748
- // translators: %s is the plural name of the post type.
1749
- __( 'Add %s from images', 'yith-plugin-fw' ),
1750
- $label_plural
1751
- );
1752
-
1753
- $uploader_button_text = sprintf(
1754
- // translators: %s is the plural name of the post type.
1755
- __( 'Add %s', 'yith-plugin-fw' ),
1756
- $label_plural
1757
- );
1758
- ?>
1759
- <script>
1760
- ( function ( $ ) {
1761
- "use strict";
1762
-
1763
- var button = $( '<a />', {
1764
- href : '#',
1765
- class : 'multi-uploader add-new-h2',
1766
- 'data-uploader_title' : '<?php esc_html( $uploader_title ); ?>',
1767
- 'data-uploader_button_text': '<?php esc_html( $uploader_button_text ); ?>',
1768
- 'data-nonce' : '<?php echo esc_html( wp_create_nonce( 'cpt-unlimited-multiuploader' ) ); ?>'
1769
- } ).text( '<?php esc_html_e( 'Upload multiple files', 'yith-plugin-fw' ); ?>' );
1770
-
1771
- var spinner = $( '<span />', {
1772
- class: 'spinner',
1773
- style: 'float: none;'
1774
- } );
1775
-
1776
- button.appendTo( '.wrap h2, .wrap h1' ).after( spinner );
1777
-
1778
- } )( jQuery );
1779
- </script>
1780
- <?php
1781
- }
1782
-
1783
- /**
1784
- * Add more posts by multiupload
1785
- *
1786
- * @return void
1787
- * @since 1.0
1788
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
1789
- */
1790
- public function post_multiuploader() {
1791
- check_ajax_referer( 'cpt-unlimited-multiuploader' );
1792
-
1793
- if ( ! isset( $_REQUEST['images'] ) || ! isset( $_REQUEST['post_type'] ) && $this->is_valid( sanitize_key( wp_unslash( $_REQUEST['post_type'] ) ) ) ) {
1794
- return;
1795
- }
1796
-
1797
- foreach ( $_REQUEST['images'] as $the ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
1798
- // Create post object.
1799
- $arg = array(
1800
- 'post_title' => $the['title'],
1801
- 'post_type' => sanitize_key( wp_unslash( $_REQUEST['post_type'] ) ),
1802
- );
1803
- $post_id = wp_insert_post( $arg );
1804
- set_post_thumbnail( $post_id, $the['id'] );
1805
- }
1806
-
1807
- die();
1808
- }
1809
-
1810
-
1811
- // ###### SINGLE TEMPLATE ######
1812
-
1813
- /**
1814
- * Load the single template file
1815
- *
1816
- * @return void
1817
- * @since 1.0
1818
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
1819
- */
1820
- public function single_template() {
1821
- global $post, $wpdb;
1822
-
1823
- if ( ( ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) && ! is_single() ) || ! isset( $post->post_type ) || ! $this->is_valid( $post->post_type ) ) {
1824
- return;
1825
- }
1826
-
1827
- // Add the javascript assets.
1828
- if ( $this->args['manage_layouts'] ) {
1829
- foreach ( $this->layouts['single']['js'] as $asset ) {
1830
- yit_enqueue_script( $asset['handle'], $this->locate_url( 'single' ) . $asset['src'], $asset['deps'], $asset['ver'], $asset['in_footer'] );
1831
- }
1832
- }
1833
-
1834
- $post_name = $wpdb->get_var( $wpdb->prepare( "SELECT p.post_name FROM $wpdb->postmeta AS pm INNER JOIN $wpdb->posts AS p ON p.ID = pm.post_id WHERE pm.meta_key = %s AND pm.meta_value = %s AND p.post_type = %s", '_post_type', $post->post_type, $this->name ) );
1835
- extract( apply_filters( 'yit_cptu_frontend_vars', array( 'name' => $post_name ), $this->name ) ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
1836
-
1837
- include $this->locate_file( 'single', 'markup' );
1838
- }
1839
-
1840
- /**
1841
- * Load a file for the configuration of single template page of portfolio
1842
- *
1843
- * @return void
1844
- * @since 1.0
1845
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
1846
- */
1847
- public function single_template_config() {
1848
- // phpcs:disable WordPress.Security.NonceVerification.Recommended,WordPress.WP.GlobalVariablesOverride.Prohibited
1849
- global $post, $wpdb;
1850
-
1851
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['post_id'] ) ) {
1852
- $post = get_post( absint( $_REQUEST['post_id'] ) );
1853
- }
1854
-
1855
- if ( ( ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) && ! is_single() ) || ! isset( $post->post_type ) || ! $this->is_valid( $post->post_type ) ) {
1856
- return;
1857
- }
1858
-
1859
- $this->layout = 'single';
1860
- $path = $this->locate_file( 'single', 'config' );
1861
-
1862
- if ( file_exists( $path ) ) {
1863
- $post_name = $wpdb->get_var( $wpdb->prepare( "SELECT p.post_name FROM $wpdb->postmeta AS pm INNER JOIN $wpdb->posts AS p ON p.ID = pm.post_id WHERE pm.meta_key = %s AND pm.meta_value = %s AND p.post_type = %s", '_post_type', $post->post_type, $this->name ) );
1864
- extract( apply_filters( 'yit_cptu_frontend_vars', array( 'name' => $post_name ), $this->name ) ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
1865
-
1866
- include $path;
1867
- }
1868
- // phpcs:enable
1869
- }
1870
-
1871
- // ########################## ARCHIVE TEMPLATE ###############################
1872
-
1873
- /**
1874
- * Load the template for archive page
1875
- *
1876
- * @return void
1877
- * @since 1.0
1878
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
1879
- */
1880
- public function archive_template() {
1881
- global $wp_query;
1882
-
1883
- // Check if we are in archive template.
1884
- if ( ! ( ! is_admin() && is_archive() && isset( $wp_query->post ) && $this->is_valid( $wp_query->post->post_type ) ) ) {
1885
- return;
1886
- }
1887
-
1888
- // Remove the action from loop of theme.
1889
- remove_action( 'yit_content_loop', 'yit_content_loop', 10 );
1890
- add_action( 'yit_content_loop', array( $this, 'archive_template_loop' ), 10 );
1891
- }
1892
-
1893
- /**
1894
- * Load loop for the archive template
1895
- *
1896
- * @return void
1897
- * @since 1.0
1898
- * @author Antonino Scarfi' <antonino.scarfi@yithemes.com>
1899
  */
1900
- public function archive_template_loop() {
1901
- global $wp_query;
1902
- echo $this->add_shortcode( array( 'name' => $wp_query->post->post_type ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1903
  }
1904
  }
1905
  }
1
  <?php
2
  /**
3
  * YITH Custom-Post-Type Unlimited Class.
4
+ * Deprecated! Kept only to prevent fatal errors if someone is using it.
5
  *
6
  * @class YIT_CPT_Unlimited
7
  * @package YITH\PluginFramework\Classes
19
  */
20
  class YIT_CPT_Unlimited {
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  /**
23
  * YIT_CPT_Unlimited constructor.
24
  *
26
  */
27
  public function __construct( $args = array() ) {
28