diff --git a/capsman-enhanced.php b/capsman-enhanced.php index 958facfb..6f71d0e6 100644 --- a/capsman-enhanced.php +++ b/capsman-enhanced.php @@ -3,7 +3,7 @@ * Plugin Name: PublishPress Capabilities * Plugin URI: https://publishpress.com/capability-manager/ * Description: Manage WordPress role definitions, per-site or network-wide. Organizes post capabilities by post type and operation. - * Version: 2.8.1 + * Version: 2.9.0 * Author: PublishPress * Author URI: https://publishpress.com/ * Text Domain: capsman-enhanced @@ -44,7 +44,7 @@ } if (!defined('CAPSMAN_VERSION')) { - define('CAPSMAN_VERSION', '2.8.1'); + define('CAPSMAN_VERSION', '2.9.0'); define('CAPSMAN_ENH_VERSION', CAPSMAN_VERSION); define('PUBLISHPRESS_CAPS_VERSION', CAPSMAN_VERSION); } diff --git a/classes/pp-capabilities-installer.php b/classes/pp-capabilities-installer.php index dcff89e8..71552602 100644 --- a/classes/pp-capabilities-installer.php +++ b/classes/pp-capabilities-installer.php @@ -29,6 +29,9 @@ public static function runUpgradeTasks($currentVersions) if (version_compare($currentVersions, '2.8.0', '<')) { self::addPluginCapabilities(); } + if (version_compare($currentVersions, '2.9.0', '<')) { + self::addFrontendFeaturesCapabilities(); + } /** * @param string $previousVersion @@ -74,4 +77,20 @@ private static function addPluginCapabilities() } } + private static function addFrontendFeaturesCapabilities() + { + + $eligible_roles = ['administrator', 'editor']; + + /** + * Add frontend features capabilities to admin and editor roles + */ + foreach ($eligible_roles as $eligible_role) { + $role = get_role($eligible_role); + if (!$role->has_cap('manage_capabilities_frontend_features')) { + $role->add_cap('manage_capabilities_frontend_features'); + } + } + } + } diff --git a/common/css/admin.css b/common/css/admin.css index c6c2b3fe..6577db10 100644 --- a/common/css/admin.css +++ b/common/css/admin.css @@ -509,7 +509,7 @@ table#akmin .pp-capability-menus-select .restrict-column { } -table#akmin .pp-capability-menus-select .restrict-column + .menu-column.ppc-menu-item { +table#akmin .pp-capability-menus-select .restrict-column + .menu-column.ppc-menu-item:not(.frontend-features) { width: 100%; } @@ -531,11 +531,13 @@ table#akmin .pp-capability-menus-select .restrict-column + .menu-column.ppc-menu .pp-capability-menus-wrapper:not(.nav-menus) .pp-capability-menus .menu-item-link:hover, .pp-capability-menus-wrapper:not(.nav-menus) .pp-capability-menus .menu-item-link:focus { - border-color: #eee; - background: #fafafa; cursor: pointer; } +.pp-capability-menus-wrapper.nav-menus .pp-capability-menus-select.fse-nav-menu .ppc-nav-item-title { + vertical-align: top; +} + .pp-capability-menus .menu-item-link:active { color: #0073aa; border-color: #0073aa; @@ -774,6 +776,7 @@ div.ppc-editor-features-classic-toggle { .pp-column-right.capabilities-sidebar .pp-sidebar-box ul, .pp-capability-menus-wrapper.editor-features .pp-column-right .pp-sidebar-box:first-of-type ul, .pp-capability-menus-wrapper.admin-features .pp-column-right .pp-sidebar-box:first-of-type ul, +.pp-capability-menus-wrapper.frontend-features .pp-column-right .pp-sidebar-box:first-of-type ul, .pp-capability-menus-wrapper.profile-features .pp-column-right .pp-sidebar-box ul, .pp-capability-menus-wrapper.nav-menus .pp-column-right .pp-sidebar-box:first-of-type ul { padding: 0 !important; @@ -787,6 +790,7 @@ div.ppc-editor-features-classic-toggle { .pp-column-right.capabilities-sidebar .pp-sidebar-box:first-of-type ul input:disabled, .pp-capability-menus-wrapper.editor-features .pp-column-right .pp-sidebar-box:first-of-type ul input:disabled, .pp-capability-menus-wrapper.admin-features .pp-column-right .pp-sidebar-box:first-of-type ul input:disabled, +.pp-capability-menus-wrapper.frontend-features .pp-column-right .pp-sidebar-box:first-of-type ul input:disabled, .pp-capability-menus-wrapper.profile-features .pp-column-right .pp-sidebar-box:first-of-type ul input:disabled, .pp-capability-menus-wrapper.nav-menus .pp-column-right .pp-sidebar-box:first-of-type ul input:disabled { opacity: 1 !important; @@ -815,6 +819,7 @@ div.ppc-editor-features-classic-toggle { .pp-capability-menus-wrapper.editor-features .pp-column-right .pp-sidebar-box:first-of-type ul, .pp-capability-menus-wrapper.admin-features .pp-column-right .pp-sidebar-box:first-of-type ul, +.pp-capability-menus-wrapper.frontend-features .pp-column-right .pp-sidebar-box:first-of-type ul, .pp-capability-menus-wrapper.profile-features .pp-column-right .pp-sidebar-box:nth-of-type(1) ul, .pp-capability-menus-wrapper.profile-features .pp-column-right .pp-sidebar-box:nth-of-type(2) ul, .pp-capability-menus-wrapper.nav-menus .pp-column-right .pp-sidebar-box:first-of-type ul { @@ -974,6 +979,14 @@ user-select: none; -webkit-mask-position: left; } +.pp-capabilities-sidebar .advertisement-box-content a.advert-link { + display: block; + margin-top: 10px; + font-size: 1em; + text-decoration: underline; + color: #2271b1; +} + .pp-capabilities-sidebar .advertisement-box-header { background: #655897; color: #ffffff; @@ -1100,11 +1113,13 @@ user-select: none; color: #ffffff; } -.publishpress-caps-manage .pp-columns-wrapper.pp-enable-sidebar .pp-column-left { +body.capabilities_page_pp-capabilities .publishpress-caps-manage .pp-columns-wrapper.pp-enable-sidebar .pp-column-left, +body.toplevel_page_pp-capabilitie .publishpress-caps-manage .pp-columns-wrapper.pp-enable-sidebar .pp-column-left { width: 72%; } -.publishpress-caps-manage .pp-columns-wrapper.pp-enable-sidebar .pp-column-right { +body.capabilities_page_pp-capabilities .pp-columns-wrapper.pp-enable-sidebar .pp-column-right, +body.toplevel_page_pp-capabilitie .pp-columns-wrapper.pp-enable-sidebar .pp-column-right { width: calc(28% - 20px); } @@ -1154,6 +1169,284 @@ tr.opened .ppc-nav-menu-expand svg { display: none !important; } +.frontend-features-form.simple-form .field-row th { + width: 155px; + padding-right: 0; + padding-top: 0; + padding-bottom: 0; + vertical-align: baseline; + border: none !important; +} + +.frontend-features-form.simple-form .field-row td { + padding-left: 0; + padding-top: 0; + padding-bottom: 0; +} + +.frontend-features-form.simple-form .field-row input, +.frontend-features-form.simple-form .field-row textarea { + width: 100%; +} + +.frontend-features-form.simple-form .field-row textarea { + resize: none; + height: 30px; + vertical-align: top; +} + +.frontend-features-form.simple-form .field-row .chosen-container + input, +.frontend-features-form.simple-form .field-row .post-ids-label { + margin-top: 10px; +} + +.frontend-features-save-button-warning { + display: none; + color: red; + padding-left: 10px; +} + +.pressshack-admin-wrapper input[type=submit][disabled]:hover + .frontend-features-save-button-warning { + display: block; + float: left; + margin-right: 10px; +} + +.frontend-feature-entry { + color: #50575e; +} + +.frontend-feature-entry-pages { + color: green; +} + +.frontend-feature-red { + color: red !important; +} + +.custom-item-display { + max-height: 200px; + overflow-y: auto; + width: auto; + background-color: #fff; + color: #000; + padding: 8px 12px; + border-left: 4px solid #3071A5; + word-wrap: break-word; + font-size: 15px; + margin-top: 16px; + margin-bottom: 16px; + max-width: 480px; +} + +.ppc-post-features-note { + margin-top: 15px; +} + +.ppc-menu-overlay-item { + background: #feb123 !important; + opacity: 0.7 !important; +} + +.ppc-button-group { + padding-left: 1px; + display: inline-flex; + flex-direction: row; + flex-wrap: nowrap; + width: 99.83%; +} + +.ppc-button-group label { + display: inline-block; + border: #7e8993 solid 1px; + border-bottom: none; + position: relative; + z-index: 1; + padding: 5px 10px; + background: #fff; + margin: 0 0 0 -1px; + flex: 1; + text-align: center; + white-space: nowrap; +} + +.ppc-button-group-border { + border-top: #7e8993 solid 1px !important; +} + +.ppc-button-group label.selected { + border-color: #00d084; + background: #00d084; + color: #fff; + font-weight: bold; + z-index: 2; +} + + +.ppc-button-group label:first-child { + border-radius: 3px 0 0 0; +} + +.ppc-button-group input { + display: none !important; +} + +.frontend-element-new-element, +.frontend-new-element-class { + border-top-right-radius: 0; + border-top-left-radius: 0; +} + +.pp-capability-menus-wrapper.frontend-features .code-mirror-before { + border: 1px solid #ddd; + border-bottom: none; + background-color: #f7f7f7; +} + +.pp-capability-menus-wrapper.frontend-features .code-mirror-before div { + color: #8F8F8F; + margin-left: 45px; + border-left: 1px solid #ddd; + padding: 3px 8px; + background-color: #fff; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; +} + +.pp-capability-menus-wrapper.frontend-features .code-mirror-after { + border: 1px solid #ddd; + border-top: none; + background-color: #f7f7f7; +} +.pp-capability-menus-wrapper.frontend-features .code-mirror-after div { + color: #8F8F8F; + margin-left: 45px; + border-left: 1px solid #ddd; + padding: 3px 8px; + background-color: #fff; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; +} + +.pp-capability-menus-wrapper.frontend-features .CodeMirror { + margin-top: 0px; + border: 1px solid #ddd; + border-bottom: none; + border-top: none; +} + +.pp-capability-menus-wrapper.frontend-features .CodeMirror pre { + padding-left: 7px; + line-height: 1.25; +} + +.pp-capability-menus-wrapper.frontend-features #pp-capability-menus-general #ppc-capabilities-wrapper { + border: none; +} + +.pp-capability-menus-wrapper.frontend-features .ppc-capabilities-tabs { + min-width: 255px; +} + +.pp-capability-menus-wrapper.frontend-features .ppc-capabilities-tabs li i { + font-size: 18px; +} + +.pp-capability-menus-wrapper.frontend-features #ppc-capabilities-wrapper .ppc-capabilities-content > div { + padding: 0 !important; +} + +.pp-capability-menus-wrapper.frontend-features .striped > tbody > :nth-child(odd) { + background-color: transparent; +} +.pp-capability-menus-wrapper.frontend-features .striped > tbody > :nth-child(even) { + background-color: #f6f7f7; +} + +.pp-capability-menus-wrapper.frontend-features .restrict-column input[type=checkbox]:checked:focus { + border-color: green; + box-shadow: 0 0 0 1px green; +} + +.pp-capability-menus-wrapper.frontend-features .restrict-column input[type=checkbox]:checked::before { + content: url("data:image/svg+xml;utf8,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%2020%2020%27%3E%3Cpath%20d%3D%27M14.83%204.89l1.34.94-5.81%208.38H9.02L5.78%209.67l1.34-1.25%202.57%202.4z%27%20fill%3D%27%233582c4%27%2F%3E%3C%2Fsvg%3E"); +} + +.pp-capability-menus-wrapper.frontend-features .pp-capability-menus .menu-item-link.restricted:active { + color: green; +} + +.pp-capability-menus-wrapper.frontend-features .pp-capability-menus .menu-item-link.restricted { + color: #3071A5; +} + +.custom-item-output:not(.show), +.editing-custom-item { + display: none; +} + +.custom-item-action { + float: right; +} + +.editing-custom-item span.title { + color: green; +} + +.cancel-custom-item-edit { + color: red !important; + cursor: pointer; + visibility: hidden; +} + +.custom-item-submit-buttons { + display: flex; + justify-content: space-between; +} + +.custom-item-wrapper-td { + padding: 0 !important; +} + +.pp-capability-menus-wrapper.frontend-features thead td { + border-bottom: 1px solid #c3c4c7 !important; +} + +.pp-capability-menus-wrapper.frontend-features .content-title-column { + margin-left: -48px; +} + +.custom-items-table { + border-top: 1px solid #c3c4c7 !important; + border-left: none !important; +} + +.custom-items-table .manage-column { + padding-left: 9px; +} + +.custom-table-title { + background: #f0f0f1 !important; + font-weight: 600; +} + +.custom-table-title .title-td { + padding-left: 25px; +} + +body.capabilities_page_pp-capabilities-frontend-features .pp-capability-menus-select .restrict-column { + width: 99px !important; +} + +.hidden-element { + display: none !important; +} + + /* Start COPIED FROM PP BLOCKS */ .pp-capability-menus-wrapper.capabilities-dashboard input { float: right; @@ -1363,13 +1656,23 @@ tr.opened .ppc-nav-menu-expand svg { padding-top: 110px; } .pp-capability-menus-wrapper.admin-features div.pp-column-right { - padding-top: 80px; + padding-top: 81px; } + .pp-capability-menus-wrapper.frontend-features div.pp-column-right { + padding-top: 62px; + } + .pp-capability-menus-wrapper.capabilities-dashboard div.pp-column-right { + padding-top: 21px; + } + .pp-capability-menus-wrapper.nav-menus div.pp-column-right { padding-top: 62px; } .pp-capability-menus-wrapper.profile-features div.pp-column-right { - padding-top: 80px; + padding-top: 81px; + } + .publishpress-caps-manage.publishpress-caps-backup div.pp-column-right { + padding-top: 67px; } } diff --git a/common/js/admin.dev.js b/common/js/admin.dev.js index bc7df528..3d118919 100644 --- a/common/js/admin.dev.js +++ b/common/js/admin.dev.js @@ -463,19 +463,299 @@ jQuery(document).ready( function($) { }); } - /** - * Toggle capabilities sidebar panel - */ - $(document).on('click', '.ppc-sidebar-panel .postbox-header', function () { - if ($(this).closest('.ppc-sidebar-panel').hasClass('closed')) { - $(this).closest('.ppc-sidebar-panel').find('.metabox-state').val('opened'); - $(this).closest('.ppc-sidebar-panel').toggleClass('closed'); + /** + * Toggle capabilities sidebar panel + */ + $(document).on('click', '.ppc-sidebar-panel .postbox-header', function () { + if ($(this).closest('.ppc-sidebar-panel').hasClass('closed')) { + $(this).closest('.ppc-sidebar-panel').find('.metabox-state').val('opened'); + $(this).closest('.ppc-sidebar-panel').toggleClass('closed'); + } else { + $(this).closest('.ppc-sidebar-panel').find('.metabox-state').val('closed'); + $(this).closest('.ppc-sidebar-panel').toggleClass('closed'); + } + }); + + + // ------------------------------------------------------------- + // Custom styles new entry + // ------------------------------------------------------------- + $(document).on("click", ".ppc-button-group label", function () { + var current_button = $(this); + var target_value = current_button.find('input').val(); + var button_group = current_button.closest('.ppc-button-group'); + var hide_selector = button_group.attr('data-hide-selector'); + + //remove active class + button_group.find('label.selected').removeClass('selected'); + //hide all selector + $(hide_selector).addClass('hidden-element'); + //display current select + $(target_value).removeClass('hidden-element'); + //add active class to current select + current_button.addClass('selected'); + if (target_value === '.frontend-element-styles') { + $(".ppc-code-editor-refresh-editor").trigger("click"); + } + }); + + // ------------------------------------------------------------- + // Frontend elements new entry + // ------------------------------------------------------------- + $(document).on("click", ".frontend-element-form-submit", function (event) { + event.preventDefault(); + var button = $(this), + ajax_action = 'ppc_submit_frontend_element_by_ajax'; + custom_label = $('.frontend-element-new-name').val(), + custom_element_selector = $('.frontend-element-new-element').val(), + custom_element_styles = $('.frontendelements-form-styles').val(), + custom_element_bodyclass = $('.frontendelements-form-bodyclass').val(), + element_pages = $('.frontend-element-new-element-pages').val(), + element_post_types = $('.frontend-element-new-element-post-types').val(), + security = $('.frontend-element-form-nonce').val(), + item_section = $(this).attr('data-section'), + item_id = $('.' + item_section + '-form').find('.custom-edit-id').val(); + + if ($('input[name="frontend_feature_pages"]:checked').val() === '.frontend-element-whole-site') { + element_pages = ['whole_site']; + } + + if (custom_label == '' || (custom_element_selector == '' && custom_element_styles == '' && custom_element_bodyclass == '')) { + button.closest('tr').find('.ppc-post-features-note').html('

' + button.attr('data-required') + '

'); + $(".ppc-feature-submit-form-error").delay(2000).fadeOut('slow'); + return; + } + + $('.ppc-feature-submit-form-error').remove(); + button.attr('disabled', true); + button.closest('tr').find(".ppc-feature-post-loader").addClass("is-active"); + + var data = { + 'action': ajax_action, + 'security': security, + 'custom_label': custom_label, + 'custom_element_selector': custom_element_selector, + 'custom_element_styles': custom_element_styles, + 'custom_element_bodyclass': custom_element_bodyclass, + 'element_pages': element_pages, + 'element_post_types': element_post_types, + 'item_id': item_id, + }; + + $.post(ajaxurl, data, function (response) { + + if (response.status == 'error') { + button.closest('tr').find('.ppc-post-features-note').html('

' + response.message + '

'); + $(".ppc-feature-submit-form-error").delay(2000).fadeOut('slow'); + } else { + var parent_table = $('table.frontendelements-table'); + + $('.frontend-features-save-button-warning').remove(); + + $('.frontend-element-new-name').val(''); + $('.frontend-element-new-element').val(''); + $('.frontendelements-form-bodyclass').val(''); + $(".css-new-element-clear").trigger("click"); + $('.frontend-element-new-element-pages').val([]).trigger('chosen:updated'); + $('.frontend-element-new-element-post-types').val([]).trigger('chosen:updated'); + + button.closest('tr').find('.ppc-post-features-note').html('

' + response.message + '

'); + $(".ppc-feature-submit-form-error").delay(5000).fadeOut('slow'); + setTimeout(function () { + $('.ppc-menu-overlay-item').removeClass('ppc-menu-overlay-item'); + }, 5000); + + if (item_id !== '') { + $('.cancel-custom-item-edit').trigger("click"); + $('.custom-item-' + item_id).replaceWith(response.content); + } else { + parent_table.find('.custom-items-table tbody').append(response.content); + parent_table.find('.temporarily.hidden-element').removeClass('temporarily hidden-element'); + } + + if ($('table.frontendelements-table table.custom-items-table tr.custom-item-row').length > 1) { + $('table.frontendelements-table .custom-item-toggle-row').removeClass('hidden-element'); + } else { + $('table.frontendelements-table .custom-item-toggle-row').addClass('hidden-element'); + } + + } + + button.closest('form').find('input[type=submit]').attr('disabled', false); + button.closest('tr').find(".ppc-feature-post-loader").removeClass("is-active"); + button.attr('disabled', false); + + }); + }); + + + // ------------------------------------------------------------- + // Delete frontend features item + // ------------------------------------------------------------- + $(document).on("click", ".frontend-features-delete-item", function (event) { + if (confirm(cmeAdmin.deleteWarning)) { + var item = $(this); + var item_id = item.attr('data-id'); + var security = item.attr('data-delete-nonce'); + var item_section = item.attr('data-section'); + + item.closest('.ppc-menu-row').fadeOut(300); + + var data = { + 'action': 'ppc_delete_frontend_feature_item_by_ajax', + 'security': security, + 'item_id': item_id + }; + + $.post(ajaxurl, data, function (response) { + if (response.status == 'error') { + item.closest('.ppc-menu-row').show(); + alert(response.message); + } else { + item.closest('.ppc-menu-row').remove(); + if ($('table.' + item_section + '-table table.custom-items-table tr.custom-item-row').length > 1) { + $('table.' + item_section + '-table .custom-item-toggle-row').removeClass('hidden-element'); + } else { + $('table.' + item_section + '-table .custom-item-toggle-row').addClass('hidden-element'); + } + } + + }); + + } + }); + + // ------------------------------------------------------------- + // View custom item + // ------------------------------------------------------------- + $(document).on("click", ".view-custom-item", function (event) { + event.preventDefault(); + $(this).closest('.custom-item-row').find('.custom-item-output').toggleClass('show'); + }); + + // ------------------------------------------------------------- + // Edit custom item + // ------------------------------------------------------------- + $(document).on("click", ".edit-custom-item", function (event) { + event.preventDefault(); + + var item = $(this); + var item_section = item.attr('data-section'); + var item_id = item.attr('data-id'); + var item_label = item.attr('data-label'); + var item_selector = item.attr('data-selector'); + var item_bodyclass = item.attr('data-bodyclass'); + var item_element = item.attr('data-element'); + var item_pages = ''; + var item_post_types = ''; + var item_form = $('.' + item_section + '-form'); + + if (item_id == '') { + return; + } + + item_form.find('.' + item_section + '-form-label').val(item_label).trigger('change'); + item_form.find('.editing-custom-item').show(); + item_form.find('.cancel-custom-item-edit').attr('style', 'visibility: visible'); + item_form.find('.editing-custom-item .title').html(item_label); + item_form.find('.submit-button').html(item_form.find('.submit-button').attr('data-edit')); + item_form.find('.custom-edit-id').val(item_id); + + + if (item_section === 'frontendelements') { + item.closest('.custom-item-row').find('.css-new-element-update').trigger("click"); + item_form.find('.' + item_section + '-form-element').val(item_selector); + item_form.find('.' + item_section + '-form-bodyclass').val(item_bodyclass); + + if (item_selector !== '') { + $('.frontend-element-toggle .ppc-button-group label.element-classes').trigger('click'); + } else if (item_bodyclass !== '') { + $('.frontend-element-toggle .ppc-button-group label.body-class').trigger('click'); + } else { + $('.frontend-element-toggle .ppc-button-group label.custom-css').trigger('click'); + } + + //update form pages + item_pages = item.attr('data-pages'); + item_pages = item_pages.split(', '); + if (item_pages.includes('whole_site')) { + $('.frontend-element-toggle .ppc-button-group label.whole-site').trigger('click'); + } else { + $('.frontend-element-toggle .ppc-button-group label.other-pages').trigger('click'); + var page_items = []; + item_pages.forEach(function (item_page) { + page_items.push(item_page); + }); + item_form.find('.' + item_section + '-form-pages').val(page_items).trigger('chosen:updated'); + } + + //update form post types + item_post_types = item.attr('data-post-types'); + item_post_types = item_post_types.split(', '); + var post_types_items = []; + item_post_types.forEach(function (item_post_type) { + post_types_items.push(item_post_type); + }); + item_form.find('.' + item_section + '-form-post-types').val(post_types_items).trigger('chosen:updated'); } else { - $(this).closest('.ppc-sidebar-panel').find('.metabox-state').val('closed'); - $(this).closest('.ppc-sidebar-panel').toggleClass('closed'); + item_form.find('.' + item_section + '-form-element').val(item_element); } + + //scroll to the form + $([document.documentElement, document.body]).animate({ + scrollTop: item_form.offset().top - 50 + }, 'fast'); }); + // ------------------------------------------------------------- + // Cancel custom item edit + // ------------------------------------------------------------- + $(document).on("click", ".cancel-custom-item-edit", function (event) { + event.preventDefault(); + var item = $(this); + var item_section = item.attr('data-section'); + var item_form = $('.' + item_section + '-form'); + + item_form.find('.' + item_section + '-form-label').val(''); + item_form.find('.editing-custom-item').hide(); + item_form.find('.cancel-custom-item-edit').attr('style', ''); + item_form.find('.submit-button').html(item_form.find('.submit-button').attr('data-add')); + item_form.find('.custom-edit-id').val(''); + item_form.find('.' + item_section + '-form-element').val(''); + + if (item_section === 'frontendelements') { + $('.css-new-element-clear').trigger("click"); + item_form.find('.' + item_section + '-form-element').val(''); + item_form.find('.' + item_section + '-form-bodyclass').val(''); + + item_form.find('.' + item_section + '-form-pages').val([]).trigger('chosen:updated'); + item_form.find('.' + item_section + '-form-post-types').val([]).trigger('chosen:updated'); + } + + item_form.find('.' + item_section + '-form-label').trigger('change'); + }); + + // ------------------------------------------------------------- + // Lock Frontend Features 'Save changes' button if unsaved custom items exist + // ------------------------------------------------------------- + $(document).on("keyup paste change", ".frontent-form-field", function (event) { + var lock_button = false; + $('.frontend-features-save-button-warning').remove(); + + $('.frontent-form-field').each(function () { + if ($(this).val() !== '' && $(this).val().replace(/\s/g, '').length) { + lock_button = true; + } + }); + + if (lock_button) { + $(this).closest('form').find('input[type=submit]').attr('disabled', true).after('' + cmeAdmin.saveWarning + ''); + } else { + $(this).closest('form').find('input[type=submit]').attr('disabled', false); + } + }); + + /* Start COPIED FROM PP BLOCKS */ $(".dashboard-settings-control .slider").bind("click", function (e) { try { @@ -515,7 +795,8 @@ jQuery(document).ready( function($) { } catch (e) { console.error(e); } - }); + }); + function ppcTimerStatus(type = "success") { setTimeout(function () { var uniqueClass = "ppc-floating-msg-" + Math.round(new Date().getTime() + Math.random() * 100); diff --git a/common/js/admin.js b/common/js/admin.js index dbc91188..4f9702aa 100644 --- a/common/js/admin.js +++ b/common/js/admin.js @@ -1 +1 @@ -jQuery(document).ready(function(e){var{__:t,_x:a,_n:s,_nx:n}=wp.i18n;function i(a="success"){setTimeout(function(){var s="ppc-floating-msg-"+Math.round(new Date().getTime()+100*Math.random()),n="success"===a?t("Changes saved!","capsman-enhanced"):t(" Error: changes can't be saved.","capsman-enhanced"),i=e(".ppc-floating-status").length;e("#wpbody-content").after(''+n+""),e("."+s).css("bottom",45*i).fadeIn(1e3).delay(1e4).fadeOut(1e3,function(){e(this).remove()})},500)}function p(t,a){var s=e("#toplevel_page_pp-capabilities-dashboard"),n=e(s).find("li."+t+"-menu-item");n.length&&(1==a?n.removeClass("ppc-hide-menu-item").find("a").removeClass("ppc-hide-menu-item"):n.addClass("ppc-hide-menu-item").find("a").addClass("ppc-hide-menu-item"))}e("a.neg-cap").attr("title",cmeAdmin.negationCaption),e("a.neg-type-caps").attr("title",cmeAdmin.typeCapsNegationCaption),e("a.normal-cap").attr("title",cmeAdmin.switchableCaption),e('span.cap-x:not([class*="pp-cap-key"])').attr("title",cmeAdmin.capNegated),e('table.cme-checklist input[class!="cme-check-all"]').not(":disabled").attr("title",cmeAdmin.chkCaption),e(".ppc-checkboxes-documentation-link").length>0&&e(".ppc-checkboxes-documentation-link").attr("target","blank"),e("table.cme-checklist a.neg-cap").click(function(t){e(this).closest("td").removeClass("cap-yes").removeClass("cap-no").addClass("cap-neg");var a=e(this).parent().find('input[type="checkbox"]').attr("name");return e(this).after(''),e('input[name="'+a+'"]').closest("td").removeClass("cap-yes").removeClass("cap-no").addClass("cap-neg"),e(this).closest("tr").hasClass("unfiltered_upload")&&(e('input[name="caps[upload_files]"]').closest("td").addClass("cap-neg"),e('input[name="caps[upload_files]"]').closest("td").append(''),e('input[name="caps[upload_files]"]').parent().next("a.neg-cap:visible").click()),!1}),e(document).on("click","table.cme-typecaps span.cap-x,table.cme-checklist span.cap-x,table.cme-checklist td.cap-neg span",function(t){e(this).closest("td").removeClass("cap-neg").removeClass("cap-yes").addClass("cap-no"),e(this).parent().find('input[type="checkbox"]').prop("checked",!1),e(this).parent().find("input.cme-negation-input").remove();var a=e(this).next('input[type="checkbox"]').attr("name");return a||(a=e(this).next("label").find('input[type="checkbox"]').attr("name")),e('input[name="'+a+'"]').parent().closest("td").removeClass("cap-neg").removeClass("cap-yes").addClass("cap-no"),e('input[name="'+a+'"]').prop("checked",!1).parent().find("input.cme-negation-input").remove(),e(this).closest("td").hasClass("capability-checkbox-rotate")&&(e(this).closest("td").find('input[type="checkbox"]').prop("checked",!0),e(this).closest("td").hasClass("upload_files")&&(e("tr.unfiltered_upload").find("td").removeClass("cap-neg").removeClass("cap-yes").addClass("cap-no"),e("tr.unfiltered_upload").find('input[type="checkbox"]').prop("checked",!1),e("tr.unfiltered_upload").find("input.cme-negation-input").remove(),e('input[name="caps[unfiltered_upload]"]').parent().closest("td").removeClass("cap-neg").removeClass("cap-yes").addClass("cap-no"),e('input[name="caps[unfiltered_upload]"]').prop("checked",!0).parent().find("input.cme-negation-input").remove())),e(this).closest("td").find('input[type="checkbox"]').hasClass("pp-single-action-rotate")&&e(this).closest("td").find('input[type="checkbox"]').prop("checked",!0),e(this).closest("tr").hasClass("unfiltered_upload")&&(e('input[name="caps[upload_files]"]').parent().closest("td").removeClass("cap-neg").removeClass("cap-yes").addClass("cap-no"),e('input[name="caps[upload_files]"]').prop("checked",!0).parent().find("input.cme-negation-input").remove()),!1}),e("#publishpress_caps_form").bind("keypress",function(t){if(13==t.keyCode)return e(document.activeElement).parent().find('input[type="submit"]').first().click(),!1}),e("input.cme-check-all").click(function(t){e(this).closest("table").find('input[type="checkbox"][disabled!="disabled"]:visible').prop("checked",e(this).is(":checked"))}),e("a.cme-neg-all").click(function(t){return e(this).closest("table").find("a.neg-cap:visible").click(),!1}),e("a.cme-switch-all").click(function(t){return e(this).closest("table").find("td.cap-neg span").click(),!1}),e("table.cme-typecaps a.neg-type-caps").click(function(t){return e(this).closest("tr").find('td[class!="cap-neg"]').filter('td[class!="cap-unreg"]').each(function(){e(this).addClass("cap-neg");var t=e(this).find('input[type="checkbox"]').attr("name");e(this).append(''),e('input[name="'+t+'"]').parent().next("a.neg-cap:visible").click()}),!1}),e("table.cme-typecaps th").click(function(){var t=e(this).index(),a=!e(this).prop("checked_all");if(e(this).hasClass("term-cap"))var s='[class*="term-cap"]';else var s='[class*="post-cap"]';var n=e(this).closest("table").find("tr td"+s+":nth-child("+(t+1)+') input[type="checkbox"]:visible');e(n).each(function(t,s){e('input[name="'+e(this).attr("name")+'"]').prop("checked",a)}),e(this).prop("checked_all",a)}),e("a.cme-fix-read-cap").click(function(){return e('input[name="caps[read]"]').prop("checked",!0),e('input[name="SaveRole"]').trigger("click"),!1}),e(".ppc-filter-select").each(function(){var t=e(this),a=[];e(this).parent().siblings("table").find("tbody").find("tr").each(function(){a.push({value:e(this).attr("class"),text:e(this).find(".cap_type").text()})}),a.forEach(function(a,s){t.append(e("