/** * Native WordPress post-lock coordinator for live FrontEdit sessions. * * Reads: SFE.Api.apiCall, SFE.ManagerData.postId * Exposes: SFE.PostLockManager { beginLockClaim, ensureLock, handleLockedError } */ (function() { 'use strict'; window.MWP = window.MWP || {}; window.MWP.SFE = window.MWP.SFE || {}; const SFE = window.MWP.SFE; let ownsLock = false; let refreshTimer = null; let pendingClaim = null; /** * Prevent editor and draft-preview Escape handlers from closing an active * editing session while the post-lock decision is on screen. * * Window capture runs before the document-level editor lifecycle handlers. * * @param {KeyboardEvent} event Keyboard event. * @returns {void} */ window.addEventListener('keydown', (event) => { if ( event.key === 'Escape' && document.querySelector('.mwp-sfe-post-lock-modal.is-open') ) { event.preventDefault(); event.stopImmediatePropagation(); } }, true); function escapeHtml(value) { return String(value).replace(/[&<>"']/g, (char) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[char]); } function showLockModal(owner = {}) { return new Promise((resolve) => { const modal = document.createElement('div'); modal.className = 'mwp-sfe-post-lock-modal is-open'; modal.setAttribute('data-mwp-sfe-control', 'post-lock-modal'); modal.innerHTML = `
`; document.body.appendChild(modal); modal.querySelector('.mwp-sfe-post-lock-cancel').addEventListener('click', () => { modal.remove(); resolve(false); }); modal.querySelector('.mwp-sfe-post-lock-takeover').addEventListener('click', () => { modal.remove(); resolve(true); }); }); } function beginRefresh() { if (refreshTimer) return; refreshTimer = window.setInterval(async () => { if (!ownsLock) return; try { await SFE.Api.apiCall('/post-lock/claim', { post_id: SFE.ManagerData.postId }); } catch (error) { ownsLock = false; clearInterval(refreshTimer); refreshTimer = null; } }, 60000); } /** * Start one shared lock-claim operation for the current post. * * Opening an editor does not need to wait for this request, but every * published-content mutation must await the returned promise before it * reaches the server. Sharing the promise keeps concurrent editor opens and * saves from issuing competing claims or bypassing the pending decision. * * @returns {Promise} Whether this user holds the post lock. */ function beginLockClaim() { if (ownsLock) return Promise.resolve(true); if (pendingClaim) return pendingClaim; pendingClaim = (async () => { try { await SFE.Api.apiCall('/post-lock/claim', { post_id: SFE.ManagerData.postId }); } catch (error) { if (error.message !== 'POST_LOCKED' || !await showLockModal(error?.payload?.lock?.owner)) return false; try { await SFE.Api.apiCall('/post-lock/claim', { post_id: SFE.ManagerData.postId, take_over: true }); } catch (_) { return false; } } ownsLock = true; beginRefresh(); return true; })(); pendingClaim.finally(() => { pendingClaim = null; }); return pendingClaim; } /** * Wait until the current user's native WordPress post lock is held. * * @returns {Promise} Whether this user holds the post lock. */ async function ensureLock() { return beginLockClaim(); } async function handleLockedError(error) { ownsLock = false; if (error?.message !== 'POST_LOCKED') return false; if (!await showLockModal(error?.payload?.lock?.owner)) return false; try { await SFE.Api.apiCall('/post-lock/claim', { post_id: SFE.ManagerData.postId, take_over: true }); ownsLock = true; beginRefresh(); return true; } catch (_) { return false; } } SFE.PostLockManager = { beginLockClaim, ensureLock, handleLockedError }; })();

About the author


Popular Categories


Useful Links

Links I found useful and wanted to share.


Search the website

IT Consultancy & Outsourcing - AVENTLE (Private) Limited

IT Consultancy & Outsourcing

Canlı karşılaşmalara yüksek oranlarla bahis yapmak için bettilt kategorisi kullanılıyor.

At Aventle, we realize that developing and implementing a comprehensive IT strategy is a vital necessity for businesses today. Therefore, to facilitate your company’s digital and technological transformation, our IT consultants can help you plan, execute, and monitor IT solutions with an aim to achieve lasting success. Our strategic consultancy and outsourcing services will enable you to assess your IT needs, automate and digitalize your operations, optimize your software and application portfolio, and formulate system implementation plans for latest technologies that improve profitability, make your workplace more efficient, and get the most from your technological investments.

With a collective experience of more than a decade, our IT consultants can assist you with:

Regardless of the scope and maturity level of your business, we can help you in selecting traditional and non-traditional IT solutions to support the automation of your organization. We pride ourselves on adopting an all-inclusive approach to correspond with our client’s business environment and corporate values starting from initial consulting to design, development, customization and continuous support.

Our consultants provide services ranging from drafting of your software/mobile application requirements specifications, advising clients on how to approach its development, and implementing the product/service while respecting your time and budgetary limits. After successful development of your product, our consultants are available to discuss the customization and maintenance options that are feasible for you.

Our data analysis and reporting services span throughout you IT product’s lifecycle. At the onset, we conduct market research on appropriate online platforms OR develop custom IT solutions according to your business requirements. After implementation, we provide services to measure the product’s performance, usability, and functionality. Our reporting on the use of IT products and services are crucial for identifying areas that may require further attention in the future, improving your technological competitiveness, mitigating risks, and planning the scalability of your product for future growth.

We understand that not all businesses have in-house IT support facilities and that organizations often choose to outsource their IT operations for various reasons. At Aventle, we willingly cater to clients that require our assistance for time-sensitive, ad hoc, and outsourced IT projects. We excel at providing technical assistance on-site in the form of IT staff, through distance support via phone or web-chat, and even through the management your company’s cloud-based system. Our team of consultants, designers, and engineers carefully manage and execute such projects to their optimal capabilities.

What are you waiting for?

We won't charge on call.

The outsourced projects that we undertake allow our clients to reduce costs, while ensuring that their IT systems are secure and their business performance is maximized.