diff --git a/build/cptui-scripts.js b/build/cptui-scripts.js index 200eee5b..92732d66 100644 --- a/build/cptui-scripts.js +++ b/build/cptui-scripts.js @@ -288,4 +288,25 @@ postboxes.add_postbox_toggles(pagenow); $(el).val(""); }); }); + $(".cptui-delete-post-type, .cptui-delete-taxonomy").on("click tap", function(e) { + e.preventDefault(); + let msg = ""; + let href = $(this).attr("href"); + if (typeof cptui_listings_data !== "undefined") { + msg = cptui_listings_data.confirm; + } + let submit_delete_warning = $('
' + msg + "
").appendTo(".cptui-listings").dialog({ + dialogClass: "wp-dialog", + modal: true, + autoOpen: true, + buttons: { + OK: function() { + window.location.href = href; + }, + Cancel: function() { + $(this).dialog("close"); + } + } + }); + }); })(jQuery); \ No newline at end of file diff --git a/build/cptui-scripts.min.js b/build/cptui-scripts.min.js index e6cf2465..5631772d 100644 --- a/build/cptui-scripts.min.js +++ b/build/cptui-scripts.min.js @@ -1 +1 @@ -postboxes.add_postbox_toggles(pagenow),function(c){var i;function t(e){var t=/(http|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/.test(e);return e?0===e.indexOf("dashicons-")?c('

').addClass(String(e).replace(/[^-\w. ]/gi,function(e){return"&#"+e.charCodeAt(0)+";"})):t?(t=encodeURI(e),(e=document.createElement("IMG")).src=t,e):void 0:""}c("#cptui_select_post_type_submit").hide(),c("#cptui_select_taxonomy_submit").hide(),"edit"===function(e,t){t=t||window.location.href;e=e.replace(/[\[\]]/g,"\\$&");e=new RegExp("[?&]"+e+"(=([^&#]*)|&|#|$)").exec(t);return e?e[2]?decodeURIComponent(e[2].replace(/\+/g," ")):"":null}("action")&&(i=c("#name").val()),c("#hierarchical").on("change",function(){"1"===c(this).val()?c("#page-attributes").prop("checked",!0):c("#page-attributes").prop("checked",!1)}),c("#post_type").on("change",function(){c("#cptui_select_post_type").submit()}),c("#taxonomy").on("change",function(){c("#cptui_select_taxonomy").submit()}),c(".cptui-delete-top, .cptui-delete-bottom").on("click",function(e){e.preventDefault();var t="";"undefined"!=typeof cptui_type_data?t=cptui_type_data.confirm:"undefined"!=typeof cptui_tax_data&&(t=cptui_tax_data.confirm),c('
'+t+"
").appendTo("#poststuff").dialog({dialogClass:"wp-dialog",modal:!0,autoOpen:!0,buttons:{OK:function(){c(e.target).closest("form");c(e.target).off("click").click()},Cancel:function(){c(this).dialog("close")}}})}),c("#support .question").each(function(){var t=c(this),a=!1,i=t.next("div").slideUp();t.on("click keydown",function(e){"keydown"===e.type&&32!==e.keyCode&&13!==e.keyCode||(e.preventDefault(),a=!a,i.slideToggle(a),t.toggleClass("active",a),t.attr("aria-expanded",a.toString()),t.focus())})}),c("#name").on("keyup",function(e){var t=a=c(this).val(),a=(9!==e.keyCode&&37!==e.keyCode&&38!==e.keyCode&&39!==e.keyCode&&40!==e.keyCode&&(t=function(e){e="cpt-ui_page_cptui_manage_post_types"===window.pagenow?e.replace(/[^a-z0-9\s-]/gi,"_"):e.replace(/[^a-z0-9\s]/gi,"_");return e}(t=(t=function(e){for(var t=[/[\300-\306]/g,/[\340-\346]/g,/[\310-\313]/g,/[\350-\353]/g,/[\314-\317]/g,/[\354-\357]/g,/[\322-\330]/g,/[\362-\370]/g,/[\331-\334]/g,/[\371-\374]/g,/[\321]/g,/[\361]/g,/[\307]/g,/[\347]/g],a=["A","a","E","e","I","i","O","o","U","u","N","n","C","c"],i=0;i'+cptui_tax_data.no_associated_type+"").appendTo("#poststuff").dialog({dialogClass:"wp-dialog",modal:!0,autoOpen:!0,buttons:{OK:function(){c(this).dialog("close")}}}))}),c("#auto-populate").on("click tap",function(e){e.preventDefault();var e=c("#name").val(),n=c("#label").val(),o=c("#singular_label").val(),t=c('.cptui-labels input[type="text"]');""!==e&&(""===n&&(n=e),""===o&&(o=e),c(t).each(function(e,t){var a=c(t).data("label"),i=c(t).data("plurality");"undefined"!==a&&(a="plural"===i?a.replace(/item/gi,n):a.replace(/item/gi,o),""===c(t).val()&&c(t).val(a))}))}),c("#auto-clear").on("click tap",function(e){e.preventDefault();e=c('.cptui-labels input[type="text"]');c(e).each(function(e,t){c(t).val("")})})}(jQuery); \ No newline at end of file +postboxes.add_postbox_toggles(pagenow),function(c){var i;function t(e){var t=/(http|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/.test(e);return e?0===e.indexOf("dashicons-")?c('

').addClass(String(e).replace(/[^-\w. ]/gi,function(e){return"&#"+e.charCodeAt(0)+";"})):t?(t=encodeURI(e),(e=document.createElement("IMG")).src=t,e):void 0:""}c("#cptui_select_post_type_submit").hide(),c("#cptui_select_taxonomy_submit").hide(),"edit"===function(e,t){t=t||window.location.href;e=e.replace(/[\[\]]/g,"\\$&");e=new RegExp("[?&]"+e+"(=([^&#]*)|&|#|$)").exec(t);return e?e[2]?decodeURIComponent(e[2].replace(/\+/g," ")):"":null}("action")&&(i=c("#name").val()),c("#hierarchical").on("change",function(){"1"===c(this).val()?c("#page-attributes").prop("checked",!0):c("#page-attributes").prop("checked",!1)}),c("#post_type").on("change",function(){c("#cptui_select_post_type").submit()}),c("#taxonomy").on("change",function(){c("#cptui_select_taxonomy").submit()}),c(".cptui-delete-top, .cptui-delete-bottom").on("click",function(e){e.preventDefault();var t="";"undefined"!=typeof cptui_type_data?t=cptui_type_data.confirm:"undefined"!=typeof cptui_tax_data&&(t=cptui_tax_data.confirm),c('
'+t+"
").appendTo("#poststuff").dialog({dialogClass:"wp-dialog",modal:!0,autoOpen:!0,buttons:{OK:function(){c(e.target).closest("form");c(e.target).off("click").click()},Cancel:function(){c(this).dialog("close")}}})}),c("#support .question").each(function(){var t=c(this),a=!1,i=t.next("div").slideUp();t.on("click keydown",function(e){"keydown"===e.type&&32!==e.keyCode&&13!==e.keyCode||(e.preventDefault(),a=!a,i.slideToggle(a),t.toggleClass("active",a),t.attr("aria-expanded",a.toString()),t.focus())})}),c("#name").on("keyup",function(e){var t=a=c(this).val(),a=(9!==e.keyCode&&37!==e.keyCode&&38!==e.keyCode&&39!==e.keyCode&&40!==e.keyCode&&(t=function(e){e="cpt-ui_page_cptui_manage_post_types"===window.pagenow?e.replace(/[^a-z0-9\s-]/gi,"_"):e.replace(/[^a-z0-9\s]/gi,"_");return e}(t=(t=function(e){for(var t=[/[\300-\306]/g,/[\340-\346]/g,/[\310-\313]/g,/[\350-\353]/g,/[\314-\317]/g,/[\354-\357]/g,/[\322-\330]/g,/[\362-\370]/g,/[\331-\334]/g,/[\371-\374]/g,/[\321]/g,/[\361]/g,/[\307]/g,/[\347]/g],a=["A","a","E","e","I","i","O","o","U","u","N","n","C","c"],i=0;i'+cptui_tax_data.no_associated_type+"").appendTo("#poststuff").dialog({dialogClass:"wp-dialog",modal:!0,autoOpen:!0,buttons:{OK:function(){c(this).dialog("close")}}}))}),c("#auto-populate").on("click tap",function(e){e.preventDefault();var e=c("#name").val(),n=c("#label").val(),o=c("#singular_label").val(),t=c('.cptui-labels input[type="text"]');""!==e&&(""===n&&(n=e),""===o&&(o=e),c(t).each(function(e,t){var a=c(t).data("label"),i=c(t).data("plurality");"undefined"!==a&&(a="plural"===i?a.replace(/item/gi,n):a.replace(/item/gi,o),""===c(t).val()&&c(t).val(a))}))}),c("#auto-clear").on("click tap",function(e){e.preventDefault();e=c('.cptui-labels input[type="text"]');c(e).each(function(e,t){c(t).val("")})}),c(".cptui-delete-post-type, .cptui-delete-taxonomy").on("click tap",function(e){e.preventDefault();let t="",a=c(this).attr("href");"undefined"!=typeof cptui_listings_data&&(t=cptui_listings_data.confirm);c('
'+t+"
").appendTo(".cptui-listings").dialog({dialogClass:"wp-dialog",modal:!0,autoOpen:!0,buttons:{OK:function(){window.location.href=a},Cancel:function(){c(this).dialog("close")}}})})}(jQuery); \ No newline at end of file diff --git a/build/cptui-scripts.min.js.map b/build/cptui-scripts.min.js.map index 82f6d221..debcf8a8 100644 --- a/build/cptui-scripts.min.js.map +++ b/build/cptui-scripts.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["src/js/cptui-scripts.js"],"names":["postboxes","add_postbox_toggles","pagenow","$","original_slug","composePreviewContent","value","is_url","test","indexOf","addClass","String","replace","c","charCodeAt","imgsrc","encodeURI","theimg","document","createElement","src","hide","name","url","window","location","href","results","RegExp","exec","decodeURIComponent","getParameterByName","val","on","this","prop","submit","e","preventDefault","msg","cptui_type_data","confirm","cptui_tax_data","appendTo","dialog","dialogClass","modal","autoOpen","buttons","OK","target","closest","off","click","Cancel","each","tis","state","answer","next","slideUp","type","keyCode","slideToggle","toggleClass","attr","toString","focus","original_value","$slugexists","s","replaceSpecialCharacters","diacritics","chars","i","length","replaceDiacritics","toLowerCase","split","map","char","cyrillic","join","$slugchanged","removeClass","existing_post_types","hasOwnProperty","existing_taxonomies","_custom_media","_orig_send_attachment","Ё","Й","Ц","У","К","Е","Н","Г","Ш","Щ","З","Х","Ъ","ё","й","ц","у","к","е","н","г","ш","щ","з","х","ъ","Ф","Ы","В","А","П","Р","О","Л","Д","Ж","Э","ф","ы","в","а","п","р","о","л","д","ж","э","Я","Ч","С","М","И","Т","Ь","Б","Ю","я","ч","с","м","и","т","ь","б","ю","undefined","wp","media","editor","send","attachment","button","id","jQuery","props","apply","change","open","trim","html","no_associated_type","slug","plural","singular","fields","el","newval","data","plurality"],"mappings":"AAGAA,UAAUC,oBAAoBC,SAK9B,SAAUC,GAKT,IAEKC,EA0IL,SAASC,EAAsBC,GAE9B,IACIC,EADK,4EACOC,KAAKF,GAErB,OAAKA,EAEM,IAAMA,EAAMG,QAAQ,cACvBN,EAAE,4CAA4CO,SAU/CC,OAVmEL,GAUvDM,QAAQ,aAAc,SAAUC,GAClD,MAAO,KAAOA,EAAEC,WAAW,GAAK,OAVrBP,GACPQ,EAASC,UAAUV,IACnBW,EAASC,SAASC,cAAc,QAC7BC,IAAML,EACNE,QAJD,EAHC,GArJTd,EAAE,kCAAkCkB,OACpClB,EAAE,iCAAiCkB,OAE/B,SAkLJ,SAA4BC,EAAMC,GACvBA,EAALA,GAAWC,O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,EAAS5K,EAAE,oCAEfA,EAAE4K,GAAQxH,KAAM,SAAUmB,EAAGsG,GAC5B7K,EAAE6K,GAAIhJ,IAAI,QAtRb,CA0RGoI"} \ No newline at end of file +{"version":3,"sources":["src/js/cptui-scripts.js"],"names":["postboxes","add_postbox_toggles","pagenow","$","original_slug","composePreviewContent","value","is_url","test","indexOf","addClass","String","replace","c","charCodeAt","imgsrc","encodeURI","theimg","document","createElement","src","hide","name","url","window","location","href","results","RegExp","exec","decodeURIComponent","getParameterByName","val","on","this","prop","submit","e","preventDefault","msg","cptui_type_data","confirm","cptui_tax_data","appendTo","dialog","dialogClass","modal","autoOpen","buttons","OK","target","closest","off","click","Cancel","each","tis","state","answer","next","slideUp","type","keyCode","slideToggle","toggleClass","attr","toString","focus","original_value","$slugexists","s","replaceSpecialCharacters","diacritics","chars","i","length","replaceDiacritics","toLowerCase","split","map","char","cyrillic","join","$slugchanged","removeClass","existing_post_types","hasOwnProperty","existing_taxonomies","_custom_media","_orig_send_attachment","Ё","Й","Ц","У","К","Е","Н","Г","Ш","Щ","З","Х","Ъ","ё","й","ц","у","к","е","н","г","ш","щ","з","х","ъ","Ф","Ы","В","А","П","Р","О","Л","Д","Ж","Э","ф","ы","в","а","п","р","о","л","д","ж","э","Я","Ч","С","М","И","Т","Ь","Б","Ю","я","ч","с","м","и","т","ь","б","ю","undefined","wp","media","editor","send","attachment","button","id","jQuery","props","apply","change","open","trim","html","no_associated_type","slug","plural","singular","fields","el","newval","data","plurality","let","cptui_listings_data"],"mappings":"AAGAA,UAAUC,oBAAoBC,SAK9B,SAAUC,GAKT,IAEKC,EA0IL,SAASC,EAAsBC,GAE9B,IACIC,EADK,4EACOC,KAAKF,GAErB,OAAKA,EAEM,IAAMA,EAAMG,QAAQ,cACvBN,EAAE,4CAA4CO,SAU/CC,OAVmEL,GAUvDM,QAAQ,aAAc,SAAUC,GAClD,MAAO,KAAOA,EAAEC,WAAW,GAAK,OAVrBP,GACPQ,EAASC,UAAUV,IACn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rK,QAAQ,SAAUkK,GAEZ,KAAlB3K,EAAG6K,GAAKhJ,OACZ7B,EAAE6K,GAAIhJ,IAAIiJ,SAMd9K,EAAE,eAAe8B,GAAI,YAAa,SAASI,GAC1CA,EAAEC,iBAEEyI,EAAS5K,EAAE,oCAEfA,EAAE4K,GAAQxH,KAAM,SAAUmB,EAAGsG,GAC5B7K,EAAE6K,GAAIhJ,IAAI,QAKZ7B,EAAE,mDAAmD8B,GAAG,YAAa,SAASI,GAC7EA,EAAEC,iBACF8I,IAAI7I,EAAM,GACNb,EAAOvB,EAAE+B,MAAM+B,KAAK,QACW,oBAAxBoH,sBACV9I,EAAM8I,oBAAoB5I,SAECtC,EAAE,2CAA6CoC,EAAM,UAAUI,SAAS,mBAAmBC,OAAO,CAC7HC,YAAe,YACfC,OAAe,EACfC,UAAe,EACfC,QAAe,CACdC,GAAU,WACTzB,OAAOC,SAASC,KAAOA,GAExB4B,OAAU,WACTnD,EAAE+B,MAAMU,OAAO,eA3SpB,CAgTGwH"} \ No newline at end of file diff --git a/custom-post-type-ui.php b/custom-post-type-ui.php index 3ce66bf1..42b15e49 100644 --- a/custom-post-type-ui.php +++ b/custom-post-type-ui.php @@ -204,6 +204,7 @@ function cptui_create_submenus() { require_once plugin_dir_path( __FILE__ ) . 'inc/taxonomies.php'; require_once plugin_dir_path( __FILE__ ) . 'inc/listings.php'; require_once plugin_dir_path( __FILE__ ) . 'inc/tools.php'; + require_once plugin_dir_path( __FILE__ ) . 'inc/local-json.php'; require_once plugin_dir_path( __FILE__ ) . 'inc/tools-sections/tools-post-types.php'; require_once plugin_dir_path( __FILE__ ) . 'inc/tools-sections/tools-taxonomies.php'; require_once plugin_dir_path( __FILE__ ) . 'inc/tools-sections/tools-get-code.php'; @@ -265,10 +266,12 @@ function cptui_create_custom_post_types() { * Filters an override array of post type data to be registered instead of our saved option. * * @since 1.10.0 + * @since 1.14.0 Added $cpts as secondary argument. * * @param array $value Default override value. + * @param array $cpts Existing CPTUI data. */ - $cpts_override = apply_filters( 'cptui_post_types_override', [] ); + $cpts_override = apply_filters( 'cptui_post_types_override', [], $cpts ); if ( empty( $cpts ) && empty( $cpts_override ) ) { return; @@ -569,10 +572,12 @@ function cptui_create_custom_taxonomies() { * Filters an override array of taxonomy data to be registered instead of our saved option. * * @since 1.10.0 + * @since 1.14.0 Added $taxes as secondary argument * * @param array $value Default override value. + * @param array $taxes Existing CPTUI data. */ - $taxes_override = apply_filters( 'cptui_taxonomies_override', [] ); + $taxes_override = apply_filters( 'cptui_taxonomies_override', [], $taxes ); if ( empty( $taxes ) && empty( $taxes_override ) ) { return; @@ -927,27 +932,27 @@ function cptui_admin_notices( $action = '', $object_type = '', $success = true, if ( 'add' === $action ) { if ( $success ) { - $message .= sprintf( __( '%s has been successfully added', 'custom-post-type-ui' ), $object_type ); + $message .= sprintf( __( '%s has been successfully added.', 'custom-post-type-ui' ), $object_type ); } else { - $message .= sprintf( __( '%s has failed to be added', 'custom-post-type-ui' ), $object_type ); + $message .= sprintf( __( '%s has failed to be added.', 'custom-post-type-ui' ), $object_type ); } } elseif ( 'update' === $action ) { if ( $success ) { - $message .= sprintf( __( '%s has been successfully updated', 'custom-post-type-ui' ), $object_type ); + $message .= sprintf( __( '%s has been successfully updated.', 'custom-post-type-ui' ), $object_type ); } else { - $message .= sprintf( __( '%s has failed to be updated', 'custom-post-type-ui' ), $object_type ); + $message .= sprintf( __( '%s has failed to be updated.', 'custom-post-type-ui' ), $object_type ); } } elseif ( 'delete' === $action ) { if ( $success ) { - $message .= sprintf( __( '%s has been successfully deleted', 'custom-post-type-ui' ), $object_type ); + $message .= sprintf( __( '%s has been successfully deleted.', 'custom-post-type-ui' ), $object_type ); } else { - $message .= sprintf( __( '%s has failed to be deleted', 'custom-post-type-ui' ), $object_type ); + $message .= sprintf( __( '%s has failed to be deleted.', 'custom-post-type-ui' ), $object_type ); } } elseif ( 'import' === $action ) { if ( $success ) { - $message .= sprintf( __( '%s has been successfully imported', 'custom-post-type-ui' ), $object_type ); + $message .= sprintf( __( '%s has been successfully imported.', 'custom-post-type-ui' ), $object_type ); } else { - $message .= sprintf( __( '%s has failed to be imported', 'custom-post-type-ui' ), $object_type ); + $message .= sprintf( __( '%s has failed to be imported.', 'custom-post-type-ui' ), $object_type ); } } elseif ( 'error' === $action ) { if ( ! empty( $custom ) ) { diff --git a/inc/listings.php b/inc/listings.php index b9826de9..3719e2f3 100644 --- a/inc/listings.php +++ b/inc/listings.php @@ -33,6 +33,13 @@ function cptui_listings_assets() { } wp_enqueue_style( 'cptui-css' ); + wp_enqueue_script( 'cptui' ); + + wp_localize_script( 'cptui', 'cptui_listings_data', + [ + 'confirm' => esc_html__( 'Are you sure you want to delete this? Deleting will NOT remove created content.', 'custom-post-type-ui' ), + ] + ); } add_action( 'admin_enqueue_scripts', 'cptui_listings_assets' ); @@ -104,6 +111,7 @@ function cptui_listings() { $post_type_settings ) { $rowclass = ( 0 === $counter % 2 ) ? '' : 'alternate'; @@ -141,7 +149,7 @@ function cptui_listings() { $edit_path = 'admin.php?page=cptui_manage_post_types&action=edit&cptui_post_type=' . $post_type; $post_type_link_url = is_network_admin() ? network_admin_url( $edit_path ) : admin_url( $edit_path ); ?> - + %s
@@ -159,7 +167,13 @@ function cptui_listings() { if ( $archive ) { ?> - +
+ + + + + + @@ -324,6 +338,7 @@ function cptui_listings() { $taxonomy_settings ) { $rowclass = ( 0 === $counter % 2 ) ? '' : 'alternate'; @@ -355,7 +370,7 @@ function cptui_listings() { $edit_path = 'admin.php?page=cptui_manage_taxonomies&action=edit&cptui_taxonomy=' . $taxonomy; $taxonomy_link_url = is_network_admin() ? network_admin_url( $edit_path ) : admin_url( $edit_path ); ?> - + %s
@@ -370,7 +385,12 @@ function cptui_listings() { esc_attr( admin_url( 'admin.php?page=cptui_tools&action=get_code#' . $taxonomy ) ), esc_html__( 'Get code', 'custom-post-type-ui' ) ); - ?> + ?>
+ + + + + '; } add_action( 'cptui_no_taxonomies_listing', 'cptui_no_taxonomies_to_list' ); + +/** + * Handle the deletion of registered content types from within the CPTUI Listings page. + * + * @since 1.14.0 + */ +function cptui_listings_delete_post_type_or_taxonomy() { + + if ( wp_doing_ajax() ) { + return; + } + + if ( empty( $_GET['page'] ) || 'cptui_listings' !== $_GET['page'] ) { + return; + } + + $result = false; + $values = []; + if ( ! empty( $_GET['delete_post_type'] ) ) { + $post_type = filter_input( INPUT_GET, 'delete_post_type', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); + if ( ! wp_verify_nonce( $_GET[ 'delete_' . $post_type ], 'do_delete_' . $post_type ) ) { + return; + } + $values['post_type'] = $post_type; + $result = cptui_delete_post_type( $post_type, true ); + } + + if ( ! empty( $_GET['delete_taxonomy'] ) ) { + $taxonomy = filter_input( INPUT_GET, 'delete_taxonomy', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); + if ( ! wp_verify_nonce( $_GET[ 'delete_' . $taxonomy ], 'do_delete_' . $taxonomy ) ) { + return; + } + $values['taxonomy'] = $taxonomy; + $result = cptui_delete_taxonomy( $taxonomy, true ); + } + + if ( $result ) { + add_filter( + 'cptui_get_object_from_post_global', + function( $orig_value ) use ( $values ) { + if ( ! empty( $values['post_type'] ) ) { + return $values['post_type']; + } + if ( ! empty( $values['taxonomy'] ) ) { + return $values['taxonomy']; + } + return $orig_value; + } + ); + if ( is_callable( "cptui_{$result}_admin_notice" ) ) { + add_action( 'admin_notices', "cptui_{$result}_admin_notice" ); + } + + wp_safe_redirect( + add_query_arg( + [ 'page' => 'cptui_listings' ], + cptui_admin_url( 'admin.php?page=cptui_listings' ) + ) + ); + } +} +add_action( 'admin_init', 'cptui_listings_delete_post_type_or_taxonomy', 8 ); + +/** + * Handle the import of individual content types from within the CPTUI Listings page. + * + * @since 1.14.0 + */ +function cptui_listings_import_post_type_or_taxonomy() { + + if ( wp_doing_ajax() ) { + return; + } + + if ( empty( $_GET['page'] ) || 'cptui_listings' !== $_GET['page'] ) { + return; + } + + $result = false; + $values = []; + if ( ! empty( $_GET['import_post_type'] ) ) { + $post_type = filter_input( INPUT_GET, 'import_post_type', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); + if ( ! wp_verify_nonce( $_GET[ 'import_' . $post_type ], 'do_import_' . $post_type ) ) { + return; + } + $values['post_type'] = $post_type; + $content = file_get_contents( CPTUI\get_specific_type_tax_file_name( 'post_type', $post_type ) ); + $content_decoded = json_decode( $content, true ); + $database_content = cptui_get_post_type_data(); + $database_content[ $post_type ] = $content_decoded; + $result = update_option( 'cptui_post_types', $database_content ); + } + + if ( ! empty( $_GET['import_taxonomy'] ) ) { + $taxonomy = filter_input( INPUT_GET, 'import_taxonomy', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); + if ( ! wp_verify_nonce( $_GET[ 'import_' . $taxonomy ], 'do_import_' . $taxonomy ) ) { + return; + } + $values['taxonomy'] = $taxonomy; + $content = file_get_contents( CPTUI\get_specific_type_tax_file_name( 'taxonomy', $taxonomy ) ); + $content_decoded = json_decode( $content, true ); + $database_content = cptui_get_taxonomy_data(); + $database_content[ $taxonomy ] = $content_decoded; + $result = update_option( 'cptui_taxonomies', $database_content ); + } + + if ( $result ) { + add_filter( + 'cptui_get_object_from_post_global', + function ( $orig_value ) use ( $values ) { + if ( ! empty( $values['post_type'] ) ) { + return $values['post_type']; + } + if ( ! empty( $values['taxonomy'] ) ) { + return $values['taxonomy']; + } + + return $orig_value; + } + ); + if ( is_callable( "cptui_{$result}_admin_notice" ) ) { + add_action( 'admin_notices', "cptui_{$result}_admin_notice" ); + } + + wp_safe_redirect( + add_query_arg( + [ 'page' => 'cptui_listings' ], + cptui_admin_url( 'admin.php?page=cptui_listings' ) + ) + ); + } +} +add_action( 'admin_init', 'cptui_listings_import_post_type_or_taxonomy', 8 ); diff --git a/inc/local-json.php b/inc/local-json.php new file mode 100644 index 00000000..764d0bbf --- /dev/null +++ b/inc/local-json.php @@ -0,0 +1,460 @@ +base && + empty( $_GET['action'] ) + ) || + ( + 'cpt-ui_page_cptui_manage_post_types' === $current_screen->base + ) + ) { + return $cpts; + } + } + + $data_new = local_combine_post_types(); + + if ( empty( $data_new ) ) { + return $cpts; + } + + return $data_new; +} +add_filter( 'cptui_get_post_type_data', __NAMESPACE__ . '\local_get_post_type_data', 10, 2 ); + +function local_get_taxonomy_data( $taxes = [], $current_site_id = 0 ) { + + if ( ! local_json_is_enabled() ) { + return $taxes; + } + + if ( function_exists( 'get_current_screen' ) ) { + $current_screen = \get_current_screen(); + + if ( + ! is_object( $current_screen ) || + ( + 'cpt-ui_page_cptui_tools' === $current_screen->base && + $_GET['action'] === 'taxonomies' + ) || + ( + 'cpt-ui_page_cptui_manage_taxonomies' === $current_screen->base + ) + + ) { + return $taxes; + } + } + + $data_new = local_combine_taxonomies(); + + if ( empty( $data_new ) ) { + return $taxes; + } + + return $data_new; +} +add_filter( 'cptui_get_taxonomy_data', __NAMESPACE__ . '\local_get_taxonomy_data', 10, 2 ); + +/** + * Check if `cptui-json` is a directory and writable, thus enabled. + * + * @since 1.14.0 + * + * @return bool + */ +function local_json_is_enabled() { + $dirpath = local_json_get_dirpath(); + + $is_enabled = ( is_dir( $dirpath ) && is_writable( $dirpath ) ); + + /** + * Filters the `$is_enabled value for local JSON status. + * + * @since 1.14.0 + * + * @oaram bool $is_enabled Whether or not the folder exists and is writeable. + */ + return apply_filters( 'cptui_local_json_is_enabled', $is_enabled ); +} + +/** + * Return our intended local JSON folder server path. + * + * @since 1.14.0 + * + * @return string + */ +function local_json_get_dirpath() { + + /** + * Filters the server directory path to the intended folder in active theme. + * + * @since 1.14.0 + * + * @param string $value Path to the folder in the active theme. + */ + return apply_filters( 'cptui_local_json_dirpath', get_stylesheet_directory() . '/cptui-json' ); +} + +/** + * Potentially add an admin notice about `cptui-json` not being writeable. + * + * @since 1.14.0 + */ +function local_json_is_writable_admin_notice() { + $dirpath = local_json_get_dirpath(); + if ( ! is_dir( $dirpath ) ) { + return; + } + if ( ! is_writable( $dirpath ) ) { + add_action( 'admin_notices', "cptui_local_json_not_writable_admin_notice" ); + } +} +add_action( 'admin_init', __NAMESPACE__ . '\local_json_is_writable_admin_notice' ); + +/** + * Retrieve full JSON file path for a specified content type. + * + * @since 1.14.0 + * + * @param string $content_type Content type, Either "post_type" or "taxonomy". + * @param string $content_slug Slug for the desired content type. + * @return mixed|null + */ +function get_specific_type_tax_file_name( $content_type = '', $content_slug = '' ) { + $theme_dir = local_json_get_dirpath(); + $blog_id = '1'; + + if ( is_multisite() ) { + $blog_id = '_' . get_current_blog_id(); + } + $full_path = $theme_dir . "/cptui_{$content_type}_{$content_slug}_data{$blog_id}.json"; + + /** + * Filters the full path including file for chosen content type for current site. + * + * @param string $full_path Full server path including file name. + * @param string $content_type Whether or not we are fetching post type or taxonomy + * @param string $content_slug The slug of the content type being managed. + * @param string $blog_id Current site ID, with underscore prefix. + * + * @since 1.14.0 + */ + return apply_filters( 'cptui_specific_type_tax_file_name', $full_path, $content_type, $content_slug, $blog_id ); +} + +/** + * Whether or not there's some post types in local JSON. + * + * @since 1.14.0 + * + * @return bool|void + */ +function local_has_post_types() { + if ( ! local_json_is_enabled() ) { + return; + } + + $maybe_post_types = local_combine_post_types(); + return ! empty( $maybe_post_types ); +} + +/** + * Whether or not there's some taxonomies in local JSON. + * + * @since 1.14.0 + * + * @return bool|void + */ +function local_has_taxonomies() { + if ( ! local_json_is_enabled() ) { + return; + } + + $maybe_taxonomies = local_combine_taxonomies(); + return ! empty( $maybe_taxonomies ); +} + +/** + * Iterates and combines all local post type JSON files into one array. + * + * @since 1.14.0 + * + * @return array + */ +function local_combine_post_types() { + $post_types = []; + foreach ( new \DirectoryIterator( local_json_get_dirpath() ) as $fileInfo ) { + if ( $fileInfo->isDot() ) { + continue; + } + if ( false === strpos( $fileInfo->getFilename(), 'post_type' ) ) { + continue; + } + + $file_site_id = local_get_site_id_from_json_file( $fileInfo->getFilename() ); + $site_id = get_current_blog_id(); + if ( $file_site_id !== $site_id ) { + continue; + } + + $content = file_get_contents( $fileInfo->getPathname() ); + $content_decoded = json_decode( $content, true ); + $post_types[ $content_decoded['name'] ] = $content_decoded; + } + return $post_types; +} + +/** + * Iteratesand combines all local taxonomy JSON files into one array. + * + * @since 1.14.0 + * + * @return array + */ +function local_combine_taxonomies() { + $taxonomies = []; + foreach ( new \DirectoryIterator( local_json_get_dirpath() ) as $fileInfo ) { + if ( $fileInfo->isDot() ) { + continue; + } + if ( false === strpos( $fileInfo->getFilename(), 'taxonomy' ) ) { + continue; + } + + $file_site_id = local_get_site_id_from_json_file( $fileInfo->getFilename() ); + $site_id = get_current_blog_id(); + if ( $file_site_id !== $site_id ) { + continue; + } + + $content = file_get_contents( $fileInfo->getPathname() ); + $content_decoded = json_decode( $content, true ); + $taxonomies[ $content_decoded['name'] ] = $content_decoded; + } + + return $taxonomies; +} + +/** + * Filters the text used when there are no post types registered in database. + * + * @since 1.14.0 + * + * @param string $orig_text Original text for the messaging. + * @return mixed|string + */ +function local_post_type_tools_export_message( $orig_text ) { + + if ( ! local_json_is_enabled() ) { + return $orig_text; + } + + $db_types = get_option( 'cptui_post_types', [] ); + $loaded = local_has_post_types(); + + if ( ! empty( $db_types ) || false === $loaded ) { + return $orig_text; + } + + return esc_html__( 'Post types are registered with local JSON.', 'custom-post-type-ui' ); +} +add_filter( 'cptui_no_post_types_registered_message', __NAMESPACE__ . '\local_post_type_tools_export_message' ); + +/** + * Filters the text used when there are no taxonomies registered in database. + * + * @since 1.14.0 + * + * @param string $orig_text Original text for the messaging. + * @return mixed|string + */ +function local_taxonomy_tools_export_message( $orig_text ) { + + if ( ! local_json_is_enabled() ) { + return $orig_text; + } + + $db_taxes = get_option( 'cptui_taxonomies', [] ); + $loaded = local_has_taxonomies(); + + if ( ! empty( $db_taxes ) || false === $loaded ) { + return $orig_text; + } + + return esc_html__( 'Taxonomies are registered with local JSON.', 'custom-post-type-ui' ); +} +add_filter( 'cptui_no_taxonomies_registered_message', __NAMESPACE__ . '\local_taxonomy_tools_export_message' ); + +/** + * Extracts the site ID from a local JSON file name. + * + * @since 1.14.0 + * + * @param string $filename File name used for extraction. + * @return int + */ +function local_get_site_id_from_json_file( $filename = '' ) { + return (int) substr( basename( $filename, '.json' ), - 1 ); +} diff --git a/inc/post-types.php b/inc/post-types.php index ef623ae7..a55d0986 100644 --- a/inc/post-types.php +++ b/inc/post-types.php @@ -1884,10 +1884,11 @@ function cptui_get_current_post_type( $post_type_deleted = false ) { * * @internal * - * @param array $data $_POST values. Optional. + * @param array $data $_POST values. Optional. + * @param bool $bypass_after_delete_hook Whether or not to run after delete hook. Optional. * @return bool|string False on failure, string on success. */ -function cptui_delete_post_type( $data = [] ) { +function cptui_delete_post_type( $data = [], $bypass_after_delete_hook = false ) { // Pass double data into last function despite matching values. if ( is_string( $data ) && cptui_get_post_type_exists( $data, $data ) ) { @@ -1929,14 +1930,17 @@ function cptui_delete_post_type( $data = [] ) { } } - /** - * Fires after a post type is deleted from our saved options. - * - * @since 1.0.0 - * - * @param array $data Array of post type data that was deleted. - */ - do_action( 'cptui_after_delete_post_type', $data ); + if ( false === $bypass_after_delete_hook ) { + + /** + * Fires after a post type is deleted from our saved options. + * + * @param array $data Array of post type data that was deleted. + * + * @since 1.0.0 + */ + do_action( 'cptui_after_delete_post_type', $data ); + } // Used to help flush rewrite rules on init. set_transient( 'cptui_flush_rewrite_rules', 'true', 5 * 60 ); diff --git a/inc/taxonomies.php b/inc/taxonomies.php index 46d6fbac..92a2cd7b 100644 --- a/inc/taxonomies.php +++ b/inc/taxonomies.php @@ -1479,13 +1479,16 @@ function cptui_get_current_taxonomy( $taxonomy_deleted = false ) { * Delete our custom taxonomy from the array of taxonomies. * * @since 1.0.0 + * @since 1.14.0 Added `$bypass_after_delete_hook` parameter * * @internal * - * @param array $data The $_POST values. Optional. + * @param array $data The $_POST values. Optional. + * @param bool $bypass_after_delete_hook Whether or not to run after delete hook. Optional. + * * @return bool|string False on failure, string on success. */ -function cptui_delete_taxonomy( $data = [] ) { +function cptui_delete_taxonomy( $data = [], $bypass_after_delete_hook = false ) { if ( is_string( $data ) && taxonomy_exists( $data ) ) { $slug = $data; @@ -1528,14 +1531,17 @@ function cptui_delete_taxonomy( $data = [] ) { } delete_option( "default_term_{$data['name']}" ); - /** - * Fires after a taxonomy is deleted from our saved options. - * - * @since 1.0.0 - * - * @param array $data Array of taxonomy data that was deleted. - */ - do_action( 'cptui_after_delete_taxonomy', $data ); + if ( false === $bypass_after_delete_hook ) { + + /** + * Fires after a taxonomy is deleted from our saved options. + * + * @param array $data Array of taxonomy data that was deleted. + * + * @since 1.0.0 + */ + do_action( 'cptui_after_delete_taxonomy', $data ); + } // Used to help flush rewrite rules on init. set_transient( 'cptui_flush_rewrite_rules', 'true', 5 * 60 ); diff --git a/inc/tools.php b/inc/tools.php index 52695e72..ce58d167 100644 --- a/inc/tools.php +++ b/inc/tools.php @@ -381,6 +381,15 @@ function cptui_render_posttypes_taxonomies_section() {

+ + + + +

@@ -395,7 +404,10 @@ function cptui_render_posttypes_taxonomies_section() { } $content = wp_json_encode( $cptui_post_types ); } else { - $content = esc_html__( 'No post types registered yet.', 'custom-post-type-ui' ); + $content = apply_filters( + 'cptui_no_post_types_registered_message', + esc_html__( 'No post types registered yet.', 'custom-post-type-ui' ) + ); } ?> @@ -423,6 +435,15 @@ function cptui_render_posttypes_taxonomies_section() {

+ + + + +

@@ -437,7 +458,10 @@ function cptui_render_posttypes_taxonomies_section() { } $content = wp_json_encode( $cptui_taxonomies ); } else { - $content = esc_html__( 'No taxonomies registered yet.', 'custom-post-type-ui' ); + $content = apply_filters( + 'cptui_no_taxonomies_registered_message', + esc_html__( 'No taxonomies registered yet.', 'custom-post-type-ui' ) + ); } ?> @@ -527,3 +551,49 @@ function cptui_do_import_types_taxes() { } } add_action( 'init', 'cptui_do_import_types_taxes', 8 ); + +/** + * Handle the import of transferred post types and taxonomies. + * + * @since 1.5.0 + */ +function cptui_do_import_types_taxes_json() { + if ( empty( $_POST ) ) { + return; + } + + if ( + empty( $_POST['cptui_import_post_types_json'] ) && + empty( $_POST['cptui_import_taxonomies_json'] ) + ) { + return; + } + + if ( + ( ! empty( $_POST['cptui_import_post_types_json_hidden'] ) && 'do-import-json' === $_POST['cptui_import_post_types_json_hidden'] ) || // phpcs:ignore WordPress.Security.NonceVerification + ( ! empty( $_POST['cptui_import_taxonomies_json_hidden'] ) && 'do-import-json' === $_POST['cptui_import_taxonomies_json_hidden'] ) + ) { + $data = []; + $decoded_post_data = null; + $decoded_tax_data = null; + + if ( ! empty( $_POST['cptui_import_post_types_json'] ) ) { // phpcs:ignore. + $decoded_post_data = CPTUI\local_combine_post_types(); + } + + if ( ! empty( $_POST['cptui_import_taxonomies_json'] ) ) { // phpcs:ignore. + $decoded_tax_data = CPTUI\local_combine_taxonomies(); // phpcs:ignore. + } + + if ( null !== $decoded_post_data ) { + $data['cptui_post_import'] = $decoded_post_data; + } + if ( null !== $decoded_tax_data ) { + $data['cptui_tax_import'] = $decoded_tax_data; + } + + $success = cptui_import_types_taxes_settings( $data ); + add_action( 'admin_notices', "cptui_{$success}_admin_notice" ); + } +} +add_action( 'init', 'cptui_do_import_types_taxes_json', 8 ); diff --git a/inc/utility.php b/inc/utility.php index 018e888b..38ba1526 100644 --- a/inc/utility.php +++ b/inc/utility.php @@ -606,7 +606,17 @@ function cptui_get_object_from_post_global() { } } - return esc_html__( 'Object', 'custom-post-type-ui' ); + /** + * Filter the value used for `cptui_get_object_from_post_global` text + * + * @since 1.14.0 + * + * @oaram string $value Default object text if post type or taxonomy not available. + */ + return apply_filters( + 'cptui_get_object_from_post_global', + esc_html__( 'Object', 'custom-post-type-ui' ) + ); } /** @@ -618,7 +628,7 @@ function cptui_add_success_admin_notice() { echo cptui_admin_notices_helper( // phpcs:ignore WordPress.Security.EscapeOutput sprintf( /* translators: Placeholders are just for HTML markup that doesn't need translated */ - esc_html__( '%s has been successfully added', 'custom-post-type-ui' ), + esc_html__( '%s has been successfully added.', 'custom-post-type-ui' ), cptui_get_object_from_post_global() ) ); @@ -633,7 +643,7 @@ function cptui_add_fail_admin_notice() { echo cptui_admin_notices_helper( // phpcs:ignore WordPress.Security.EscapeOutput sprintf( /* translators: Placeholders are just for HTML markup that doesn't need translated */ - esc_html__( '%s has failed to be added', 'custom-post-type-ui' ), + esc_html__( '%s has failed to be added.', 'custom-post-type-ui' ), cptui_get_object_from_post_global() ), false @@ -649,7 +659,7 @@ function cptui_update_success_admin_notice() { echo cptui_admin_notices_helper( // phpcs:ignore WordPress.Security.EscapeOutput sprintf( /* translators: Placeholders are just for HTML markup that doesn't need translated */ - esc_html__( '%s has been successfully updated', 'custom-post-type-ui' ), + esc_html__( '%s has been successfully updated.', 'custom-post-type-ui' ), cptui_get_object_from_post_global() ) ); @@ -664,7 +674,7 @@ function cptui_update_fail_admin_notice() { echo cptui_admin_notices_helper( // phpcs:ignore WordPress.Security.EscapeOutput sprintf( /* translators: Placeholders are just for HTML markup that doesn't need translated */ - esc_html__( '%s has failed to be updated', 'custom-post-type-ui' ), + esc_html__( '%s has failed to be updated.', 'custom-post-type-ui' ), cptui_get_object_from_post_global() ), false @@ -680,7 +690,7 @@ function cptui_delete_success_admin_notice() { echo cptui_admin_notices_helper( // phpcs:ignore WordPress.Security.EscapeOutput sprintf( /* translators: Placeholders are just for HTML markup that doesn't need translated */ - esc_html__( '%s has been successfully deleted', 'custom-post-type-ui' ), + esc_html__( '%s has been successfully deleted.', 'custom-post-type-ui' ), cptui_get_object_from_post_global() ) ); @@ -695,7 +705,7 @@ function cptui_delete_fail_admin_notice() { echo cptui_admin_notices_helper( // phpcs:ignore WordPress.Security.EscapeOutput sprintf( /* translators: Placeholders are just for HTML markup that doesn't need translated */ - esc_html__( '%s has failed to be deleted', 'custom-post-type-ui' ), + esc_html__( '%s has failed to be deleted.', 'custom-post-type-ui' ), cptui_get_object_from_post_global() ), false @@ -720,7 +730,7 @@ function cptui_import_success_admin_notice() { */ function cptui_import_fail_admin_notice() { echo cptui_admin_notices_helper( // phpcs:ignore WordPress.Security.EscapeOutput - esc_html__( 'Invalid data provided', 'custom-post-type-ui' ), + esc_html__( 'Invalid data provided.', 'custom-post-type-ui' ), false ); } @@ -732,7 +742,18 @@ function cptui_import_fail_admin_notice() { */ function cptui_nonce_fail_admin_notice() { echo cptui_admin_notices_helper( // phpcs:ignore WordPress.Security.EscapeOutput - esc_html__( 'Nonce failed verification', 'custom-post-type-ui' ), + esc_html__( 'Nonce failed verification.', 'custom-post-type-ui' ), + false + ); +} + +/** + * Local JSON folder not writable callback + * @since 1.14.0 + */ +function cptui_local_json_not_writable_admin_notice() { + echo cptui_admin_notices_helper( // phpcs:ignore WordPress.Security.EscapeOutput + esc_html__( 'A "cptui_data" folder exists in your active theme but the server cannot write to it. Please check folder permissions.', 'custom-post-type-ui' ), false ); } @@ -815,7 +836,7 @@ function cptui_slug_matches_page() { */ function cptui_slug_has_quotes() { return sprintf( - esc_html__( 'Please do not use quotes in post type/taxonomy names or rewrite slugs', 'custom-post-type-ui' ), + esc_html__( 'Please do not use quotes in post type/taxonomy names or rewrite slugs.', 'custom-post-type-ui' ), cptui_get_object_from_post_global() ); } @@ -1002,3 +1023,48 @@ function cptui_get_add_new_link( $content_type = '' ) { return cptui_admin_url( 'admin.php?page=cptui_manage_' . $content_type ); } + +/** + * Construct a URL to use to delete a post type or taxonomy. + * + * @since 1.14.0 + * + * @param string $content_type The content type being deleted. `post_type` or `taxonomy` + * @param string $content_type_slug The slug of the specific content type being deleted. + * + * @return string $value. The constructed URL. + */ +function cptui_get_delete_listing_link( $content_type, $content_type_slug ) { + return add_query_arg( + [ + 'delete_' . $content_type_slug => wp_create_nonce( + 'do_delete_' . $content_type_slug + ), + 'delete_' . $content_type => esc_attr( $content_type_slug ) + ], + admin_url( 'admin.php?page=cptui_listings' ) + ); +} + +/** + * Construct a URL to use to import a post type or taxonomy. + * + * @since 1.14.0 + * + * @param string $content_type The content type being imported. `post_type` or `taxonomy` + * @param string $content_type_slug The slug of the specific content type being imported. + * + * @return string $value. The constructed URL. + * + */ +function cptui_get_impoort_listing_link( $content_type, $content_type_slug ) { + return add_query_arg( + [ + 'import_' . $content_type_slug => wp_create_nonce( + 'do_import_' . $content_type_slug + ), + 'import_' . $content_type => esc_attr( $content_type_slug ) + ], + admin_url( 'admin.php?page=cptui_listings' ) + ); +} diff --git a/src/js/cptui-scripts.js b/src/js/cptui-scripts.js index 1313ce63..5242e802 100644 --- a/src/js/cptui-scripts.js +++ b/src/js/cptui-scripts.js @@ -288,4 +288,26 @@ postboxes.add_postbox_toggles(pagenow); }); }); + // Confirm our deletions from CPTUI Listings + $('.cptui-delete-post-type, .cptui-delete-taxonomy').on('click tap', function(e) { + e.preventDefault(); + let msg = ''; + let href = $(this).attr('href'); + if (typeof cptui_listings_data !== 'undefined') { + msg = cptui_listings_data.confirm; + } + let submit_delete_warning = $('
' + msg + '
').appendTo('.cptui-listings').dialog({ + 'dialogClass': 'wp-dialog', + 'modal' : true, + 'autoOpen' : true, + 'buttons' : { + "OK" : function () { + window.location.href = href; + }, + "Cancel": function () { + $(this).dialog('close'); + } + } + }); + }); })(jQuery);