-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into enable-customizer-block-editor
Showing
15 changed files
with
803 additions
and
255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php return array('dependencies' => array('react', 'wp-i18n', 'wp-plugins'), 'version' => '16a2bbd70a4a05074098'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
/******/ (() => { // webpackBootstrap | ||
/******/ "use strict"; | ||
/******/ var __webpack_modules__ = ({ | ||
|
||
/***/ "react": | ||
/*!************************!*\ | ||
!*** external "React" ***! | ||
\************************/ | ||
/***/ ((module) => { | ||
|
||
module.exports = window["React"]; | ||
|
||
/***/ }), | ||
|
||
/***/ "@wordpress/i18n": | ||
/*!******************************!*\ | ||
!*** external ["wp","i18n"] ***! | ||
\******************************/ | ||
/***/ ((module) => { | ||
|
||
module.exports = window["wp"]["i18n"]; | ||
|
||
/***/ }), | ||
|
||
/***/ "@wordpress/plugins": | ||
/*!*********************************!*\ | ||
!*** external ["wp","plugins"] ***! | ||
\*********************************/ | ||
/***/ ((module) => { | ||
|
||
module.exports = window["wp"]["plugins"]; | ||
|
||
/***/ }) | ||
|
||
/******/ }); | ||
/************************************************************************/ | ||
/******/ // The module cache | ||
/******/ var __webpack_module_cache__ = {}; | ||
/******/ | ||
/******/ // The require function | ||
/******/ function __webpack_require__(moduleId) { | ||
/******/ // Check if module is in cache | ||
/******/ var cachedModule = __webpack_module_cache__[moduleId]; | ||
/******/ if (cachedModule !== undefined) { | ||
/******/ return cachedModule.exports; | ||
/******/ } | ||
/******/ // Create a new module (and put it into the cache) | ||
/******/ var module = __webpack_module_cache__[moduleId] = { | ||
/******/ // no module.id needed | ||
/******/ // no module.loaded needed | ||
/******/ exports: {} | ||
/******/ }; | ||
/******/ | ||
/******/ // Execute the module function | ||
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); | ||
/******/ | ||
/******/ // Return the exports of the module | ||
/******/ return module.exports; | ||
/******/ } | ||
/******/ | ||
/************************************************************************/ | ||
/******/ /* webpack/runtime/compat get default export */ | ||
/******/ (() => { | ||
/******/ // getDefaultExport function for compatibility with non-harmony modules | ||
/******/ __webpack_require__.n = (module) => { | ||
/******/ var getter = module && module.__esModule ? | ||
/******/ () => (module['default']) : | ||
/******/ () => (module); | ||
/******/ __webpack_require__.d(getter, { a: getter }); | ||
/******/ return getter; | ||
/******/ }; | ||
/******/ })(); | ||
/******/ | ||
/******/ /* webpack/runtime/define property getters */ | ||
/******/ (() => { | ||
/******/ // define getter functions for harmony exports | ||
/******/ __webpack_require__.d = (exports, definition) => { | ||
/******/ for(var key in definition) { | ||
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { | ||
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); | ||
/******/ } | ||
/******/ } | ||
/******/ }; | ||
/******/ })(); | ||
/******/ | ||
/******/ /* webpack/runtime/hasOwnProperty shorthand */ | ||
/******/ (() => { | ||
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) | ||
/******/ })(); | ||
/******/ | ||
/******/ /* webpack/runtime/make namespace object */ | ||
/******/ (() => { | ||
/******/ // define __esModule on exports | ||
/******/ __webpack_require__.r = (exports) => { | ||
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | ||
/******/ } | ||
/******/ Object.defineProperty(exports, '__esModule', { value: true }); | ||
/******/ }; | ||
/******/ })(); | ||
/******/ | ||
/************************************************************************/ | ||
var __webpack_exports__ = {}; | ||
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. | ||
(() => { | ||
/*!**************************************************!*\ | ||
!*** ./src/js/blocks/plugins/pattern-preview.js ***! | ||
\**************************************************/ | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react"); | ||
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); | ||
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); | ||
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__); | ||
/* harmony import */ var _wordpress_plugins__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/plugins */ "@wordpress/plugins"); | ||
/* harmony import */ var _wordpress_plugins__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_plugins__WEBPACK_IMPORTED_MODULE_2__); | ||
|
||
|
||
|
||
|
||
/** | ||
* Render a Preview Button. | ||
* | ||
* @return {Object} The rendered component. | ||
*/ | ||
var PatternPreviewButton = function PatternPreviewButton() { | ||
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(function () { | ||
var headerToolbar = document.querySelector('.edit-post-header'); | ||
if (null === headerToolbar) { | ||
return; | ||
} | ||
|
||
// Get the left toolbar and add to it. | ||
var settingsToolbar = headerToolbar.querySelector('.edit-post-header__settings'); | ||
if (null === settingsToolbar) { | ||
return; | ||
} | ||
|
||
// Create the button. | ||
var button = document.createElement('a'); | ||
button.className = 'dlx-button-preview components-button has-icon'; | ||
button.ariaLabel = (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)('Preview', 'futuris-demo-importer'); | ||
button.href = dlxPatternWranglerPreview.previewUrl; | ||
button.target = '_blank'; | ||
button.rel = 'noopener noreferrer'; | ||
|
||
// Add icon. | ||
var icon = document.createElement('svg'); | ||
icon.className = 'dlx-pattern-wrangler-preview-icon'; | ||
icon.innerHTML = '<svg width="16" height="16" style="display: inline-block; margin-right: 8px;"><use xlink:href="#dlx-pattern-wrangler-preview-icon" /></svg>'; | ||
button.prepend(icon); | ||
// Add the button to the toolbar as the first child. | ||
settingsToolbar.prepend(button); | ||
}, []); | ||
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("svg", { | ||
height: "0", | ||
width: "0", | ||
xmlns: "http://www.w3.org/2000/svg", | ||
style: { | ||
display: 'none' | ||
}, | ||
"aria-hidden": "true" | ||
}, /*#__PURE__*/React.createElement("symbol", { | ||
id: "dlx-pattern-wrangler-preview-icon", | ||
width: "16", | ||
height: "16", | ||
viewBox: "0 0 512 512" | ||
}, /*#__PURE__*/React.createElement("path", { | ||
fill: "currentColor", | ||
d: "M304 24c0 13.3 10.7 24 24 24h102.1L207 271c-9.4 9.4-9.4 24.6 0 33.9s24.6 9.4 33.9 0l223-223V184c0 13.3 10.7 24 24 24s24-10.7 24-24V24c0-13.3-10.7-24-24-24H328c-13.3 0-24 10.7-24 24zM72 32C32.2 32 0 64.2 0 104v336c0 39.8 32.2 72 72 72h336c39.8 0 72-32.2 72-72V312c0-13.3-10.7-24-24-24s-24 10.7-24 24v128c0 13.3-10.7 24-24 24H72c-13.3 0-24-10.7-24-24V104c0-13.3 10.7-24 24-24h128c13.3 0 24-10.7 24-24s-10.7-24-24-24H72z" | ||
})))); | ||
}; | ||
(0,_wordpress_plugins__WEBPACK_IMPORTED_MODULE_2__.registerPlugin)('dlx-pattern-wrangler-preview-button', { | ||
render: PatternPreviewButton | ||
}); | ||
})(); | ||
|
||
/******/ })() | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-commands', 'wp-components', 'wp-compose', 'wp-data', 'wp-edit-post', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives'), 'version' => '26478b4efd64b0e748b5'); | ||
<?php return array('dependencies' => array('react', 'wp-i18n', 'wp-plugins'), 'version' => 'c12991944f7fcbcff0d1'); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
<?php | ||
/** | ||
* Drafts class. Useful for switching to draft/undraft. | ||
* | ||
* @package PatternWrangler | ||
*/ | ||
|
||
namespace DLXPlugins\PatternWrangler; | ||
|
||
/** | ||
* Drafts class. | ||
*/ | ||
class Drafts { | ||
|
||
/** | ||
* Class runner. | ||
*/ | ||
public function run() { | ||
// Add a draft/publish button to the quick actions for the wp_block post type. | ||
add_filter( 'post_row_actions', array( $this, 'add_draft_button_quick_action' ), 10, 2 ); | ||
|
||
// Intercept draft/publish actions. | ||
add_action( 'admin_init', array( $this, 'intercept_draft_publish' ) ); | ||
|
||
// Add an admin notice when a pattern is unpublished or published. | ||
add_action( 'admin_notices', array( $this, 'add_admin_notice' ) ); | ||
} | ||
|
||
/** | ||
* Add an admin notice when a pattern is unpublished or published. | ||
*/ | ||
public function add_admin_notice() { | ||
$notice_action = sanitize_text_field( filter_input( INPUT_GET, 'notice_action', FILTER_DEFAULT ) ); | ||
if ( ! $notice_action ) { | ||
return; | ||
} | ||
if ( ! current_user_can( 'edit_posts' ) ) { | ||
return; | ||
} | ||
$notice_message = ''; | ||
switch ( $notice_action ) { | ||
case 'draft_pattern': | ||
$notice_message = esc_html__( 'Pattern unpublished.', 'dlx-pattern-wrangler' ); | ||
break; | ||
case 'publish_pattern': | ||
$notice_message = esc_html__( 'Pattern published.', 'dlx-pattern-wrangler' ); | ||
break; | ||
} | ||
printf( | ||
'<div class="notice notice-success is-dismissible"><p>%s</p></div>', | ||
esc_html( $notice_message ) | ||
); | ||
} | ||
|
||
/** | ||
* Intercept draft/publish actions. | ||
*/ | ||
public function intercept_draft_publish() { | ||
$action = sanitize_text_field( filter_input( INPUT_GET, 'action', FILTER_DEFAULT ) ); | ||
$nonce = sanitize_text_field( filter_input( INPUT_GET, 'nonce', FILTER_DEFAULT ) ); | ||
$post_id = absint( filter_input( INPUT_GET, 'post', FILTER_DEFAULT ) ); | ||
|
||
if ( ! $action ) { | ||
return; | ||
} | ||
if ( ! current_user_can( 'edit_posts' ) ) { | ||
return; | ||
} | ||
$notice_action = 'draft_pattern'; | ||
switch ( $action ) { | ||
case 'draft_pattern': | ||
if ( ! wp_verify_nonce( $nonce, 'draft-pattern_' . $post_id ) ) { | ||
return; | ||
} | ||
wp_update_post( | ||
array( | ||
'ID' => $post_id, | ||
'post_status' => 'draft', | ||
) | ||
); | ||
break; | ||
case 'publish_pattern': | ||
if ( ! wp_verify_nonce( $nonce, 'publish-pattern_' . $post_id ) ) { | ||
return; | ||
} | ||
$notice_action = 'publish_pattern'; | ||
wp_update_post( | ||
array( | ||
'ID' => $post_id, | ||
'post_status' => 'publish', | ||
) | ||
); | ||
break; | ||
default: | ||
return; | ||
} | ||
|
||
// Build redirect URL. | ||
$redirect_url = add_query_arg( | ||
array( | ||
'post_type' => 'wp_block', | ||
'notice_action' => $notice_action, | ||
), | ||
admin_url( 'edit.php' ) | ||
); | ||
wp_safe_redirect( esc_url_raw( $redirect_url ) ); | ||
exit; | ||
} | ||
|
||
/** | ||
* Add a draft button to the quick actions for the wp_block post type. | ||
* | ||
* @param array $actions Array of actions. | ||
* @param WP_Post $post Post object. | ||
* | ||
* @return array | ||
*/ | ||
public function add_draft_button_quick_action( $actions, $post ) { | ||
if ( 'wp_block' !== $post->post_type ) { | ||
return $actions; | ||
} | ||
if ( ! current_user_can( 'edit_posts' ) ) { | ||
return $actions; | ||
} | ||
$draft_disable_url = add_query_arg( | ||
array( | ||
'action' => 'draft_pattern', | ||
'nonce' => wp_create_nonce( 'draft-pattern_' . $post->ID ), | ||
'post' => $post->ID, | ||
), | ||
admin_url( 'edit.php?post_type=wp_block' ) | ||
); | ||
$draft_publish_url = add_query_arg( | ||
array( | ||
'action' => 'publish_pattern', | ||
'nonce' => wp_create_nonce( 'publish-pattern_' . $post->ID ), | ||
'post' => $post->ID, | ||
), | ||
admin_url( 'edit.php?post_type=wp_block' ) | ||
); | ||
if ( 'draft' === $post->post_status ) { | ||
$actions['draft_pattern'] = sprintf( | ||
'<a href="%s">%s</a>', | ||
esc_url_raw( $draft_publish_url ), | ||
esc_html__( 'Publish', 'dlx-pattern-wrangler' ) | ||
); | ||
} | ||
if ( 'publish' === $post->post_status ) { | ||
$actions['preview_pattern'] = sprintf( | ||
'<a href="%s">%s</a>', | ||
esc_url_raw( $draft_disable_url ), | ||
esc_html__( 'Switch to Draft', 'dlx-pattern-wrangler' ) | ||
); | ||
} | ||
return $actions; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.