Changeset 2725825
- Timestamp:
- 05/18/2022 06:50:24 AM (4 years ago)
- Location:
- mywp-custom-patterns
- Files:
-
- 30 added
- 6 edited
-
tags/1.2 (added)
-
tags/1.2/admin-parts (added)
-
tags/1.2/admin-parts/admin-header.php (added)
-
tags/1.2/composer.json (added)
-
tags/1.2/core (added)
-
tags/1.2/core/Core.php (added)
-
tags/1.2/core/Plugin.php (added)
-
tags/1.2/core/admin (added)
-
tags/1.2/core/admin/Ajax.php (added)
-
tags/1.2/core/admin/Enqueue.php (added)
-
tags/1.2/core/admin/Patterns.php (added)
-
tags/1.2/css (added)
-
tags/1.2/css/template.css (added)
-
tags/1.2/css/template.min.css (added)
-
tags/1.2/fonts (added)
-
tags/1.2/fonts/NunitoSans-Black.ttf (added)
-
tags/1.2/fonts/NunitoSans-BlackItalic.ttf (added)
-
tags/1.2/fonts/NunitoSans-Bold.ttf (added)
-
tags/1.2/fonts/NunitoSans-Regular.ttf (added)
-
tags/1.2/fonts/NunitoSans-SemiBoldItalic.ttf (added)
-
tags/1.2/img (added)
-
tags/1.2/img/icon-gut.svg (added)
-
tags/1.2/img/icon-menu.svg (added)
-
tags/1.2/img/mywp-help.svg (added)
-
tags/1.2/js (added)
-
tags/1.2/js/template.js (added)
-
tags/1.2/js/template.min.js (added)
-
tags/1.2/mywp-custom-patterns.php (added)
-
tags/1.2/readme.txt (added)
-
trunk/core/admin/Ajax.php (modified) (2 diffs)
-
trunk/core/admin/Patterns.php (modified) (1 diff)
-
trunk/js/template.js (modified) (3 diffs)
-
trunk/js/template.min.js (modified) (1 diff)
-
trunk/languages (added)
-
trunk/mywp-custom-patterns.php (modified) (1 diff)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
mywp-custom-patterns/trunk/core/admin/Ajax.php
r2684466 r2725825 36 36 $title = ( isset( $_POST['title'] ) && '' !== $_POST['title'] ) ? wp_strip_all_tags( sanitize_text_field( $_POST['title'] ) ) : esc_html__( 'Pattern', 'mywp-custom-patterns' ); 37 37 38 $authorized = wp_kses_allowed_html( 'post' ); 38 39 $authorized = wp_kses_allowed_html( 'post' ); 40 39 41 $authorized['iframe'] = array( 40 42 'id' => 1, … … 47 49 ); 48 50 $authorized['script'] = array( 49 'src' => 1,51 'src' => 1, 50 52 ); 51 53 52 $template_content = wp_kses( json_decode( stripslashes( $_POST['template_content'] ), 1 ), $authorized ); 54 55 $template_content = $_POST['template_content']; 56 $template_content = wp_kses( stripslashes_deep( $template_content ), $authorized ); 57 58 $template_content = str_replace( array( 59 'u00', 60 ), array( 61 '\u00', 62 ), $template_content ); 63 53 64 54 65 $template_id = wp_insert_post( -
mywp-custom-patterns/trunk/core/admin/Patterns.php
r2684466 r2725825 24 24 25 25 public function register_pattern() { 26 27 if ( ! is_admin() ) {28 return;29 }30 31 26 if ( ! class_exists( 'WP_Block_Patterns_Registry' ) ) { 32 return;33 }34 global $pagenow;35 36 if ( 'post.php' !== $pagenow && 'post-new.php' !== $pagenow ) {37 27 return; 38 28 } 39 29 40 30 $mywp_categories = $this->core->get_categories(); 41 $default_cat = esc_html__( 'Custom Patterns', 'mywp-custom-patterns');31 $default_cat = esc_html__( 'Custom Patterns', 'mywp-custom-patterns' ); 42 32 $this->set_pattern_category( 'mywp_pattern_default', $default_cat ); 43 33 -
mywp-custom-patterns/trunk/js/template.js
r2684466 r2725825 237 237 data.append('action', 'save_template_who'); 238 238 data.append('title', name_pattern); 239 /*240 if (document.getElementsByName('mywp_template_cat')[0] !== undefined) {241 data.append('mywp_template_cat', mywp_template_cat);242 } */243 244 239 data.append('post_id', wp.data.select('core/editor').getCurrentPostId()); 245 240 data.append('template_content', content); 246 241 data.append('nonce', MYWP_DATA.nonce); 242 /* 243 let toto = new URLSearchParams({ 244 'action': 'save_template_who', 245 'nonce': MYWP_DATA.nonce, 246 'title': name_pattern, 247 'post_id' : wp.data.select('core/editor').getCurrentPostId(), 248 'template_content' : wp.data.select('core/editor').getEditedPostContent() 249 }); */ 250 // console.log(toto.toString()); 251 247 252 fetch(MYWP_DATA.ajaxurl, { 248 253 method: "POST", … … 294 299 } else { 295 300 content = Object(wp.blocks.serialize)(wp.data.select('core/editor').getSelectedBlock()); 296 } 297 298 saveMyWPCustomPatternAjax(name_pattern, JSON.stringify(content)); // console.log(Object(wp.data.select('core/editor').getSelectedBlock().serialize)); // getSelectedBlockClientId 301 } // saveMyWPCustomPatternAjax(name_pattern, JSON.stringify(content)); 302 303 304 saveMyWPCustomPatternAjax(name_pattern, content); // console.log(Object(wp.data.select('core/editor').getSelectedBlock().serialize)); // getSelectedBlockClientId 305 // console.log(Object(wp.data.select('core/block-editor').getSelectedBlock().serialize)); // getSelectedBlockClientId 299 306 // console.log(name_pattern); 300 307 … … 328 335 329 336 330 list_blocks = wp.data.select('core/editor').getEditedPostContent(); 331 saveMyWPCustomPatternAjax(name_pattern, JSON.stringify(list_blocks)); 337 list_blocks = wp.data.select('core/editor').getEditedPostContent(); // saveMyWPCustomPatternAjax(name_pattern, JSON.stringify(list_blocks)); 338 339 saveMyWPCustomPatternAjax(name_pattern, list_blocks); 332 340 /* 333 341 const data = new FormData(); -
mywp-custom-patterns/trunk/js/template.min.js
r2684466 r2725825 1 (()=>{"use strict";function e(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var a,r,o=[],c=!0,s=!1;try{for(n=n.call(e);!(c=(a=n.next()).done)&&(o.push(a.value),!t||o.length!==t);c=!0);}catch(e){s=!0,r=e}finally{try{c||null==n.return||n.return()}finally{if(s)throw r}}return o}}(e,n)||function(e,n){if(e){if("string"==typeof e)return t(e,n);var a=Object.prototype.toString.call(e).slice(8,-1);return"Object"===a&&e.constructor&&(a=e.constructor.name),"Map"===a||"Set"===a?Array.from(e):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?t(e,n):void 0}}(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=e[n];return a}var n=React.createElement("svg",{fillRule:"nonzero",clipRule:"evenodd",strokeLinecap:"round",strokeLinejoin:"round",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"18",height:"18"},React.createElement("g",null,React.createElement("path",{d:"M13.7104+8.56898L23.9931+8.56898L23.9931+15.4242L13.7104+15.4242L13.7104+8.56898ZM23.5647+0L13.7104+0L13.7104+6.85518L23.9931+6.85518L23.9931+0.428449C23.9931+0.191823+23.8013-1.03432e-08+23.5647+0ZM13.7104+23.9931L23.5647+23.9931C23.8013+23.9931+23.9931+23.8013+23.9931+23.5647L23.9931+17.138L13.7104+17.138L13.7104+23.9931ZM0.428449+23.9931L10.2828+23.9931L10.2828+13.7104L0+13.7104L0+23.5647C0+23.7995+0.193659+23.9931+0.428449+23.9931ZM10.2828+0L0.428449+0C0.191823+0-2.06865e-08+0.191823+0+0.428449L0+10.2828L10.2828+10.2828L10.2828+0Z"})));!function(t){var a,r ,o=t.plugins.registerPlugin,c=t.i18n.__,s=t.element,l=s.Fragment,m=s.useState,i=(t.hooks.addFilter,t.components),p=i.Modal,u=(i.Button,t.editPost),d=u.PluginSidebarMoreMenuItem,y=u.PluginSidebar,w=u.PluginBlockSettingsMenuItem;function f(e,n){var a=new FormData;a.append("action","save_template_who"),a.append("title",e),a.append("post_id",t.data.select("core/editor").getCurrentPostId()),a.append("template_content",n),a.append("nonce",MYWP_DATA.nonce),fetch(MYWP_DATA.ajaxurl,{method:"POST",credentials:"same-origin",body:a}).then((function(e){return e.json()})).then((function(e){if(1===e.response){t.data.dispatch("core/notices").createNotice("success",c("Pattern saved","mywp-custom-patterns"),{type:"snackbar",isDismissible:!0,actions:[{url:window.location.href,label:c("Reload page","mywp-custom-patterns")}]});var n=document.getElementsByName("list_patterns")[0],a=document.createElement("option");a.value=e.id,a.text=e.title,a.dataset.content=e.content,n.add(a,null)}else t.data.dispatch("core/notices").createNotice("warning",c("Pattern not saved","mywp-custom-patterns"));document.getElementById("saveMyWPCustomPattern").disabled=!1})).catch((function(e){}))}function g(){document.getElementById("saveMyWPCustomPattern").disabled=!0;var e=document.getElementsByName("mywp_name_pattern")[0].value;return""===e?(document.querySelector(".mywp-custom-patterns__wrapper .mywp-error-field").style.display="block",void(document.getElementById("saveMyWPCustomPattern").disabled=!1)):(document.querySelector(".mywp-custom-patterns__wrapper .mywp-error-field").style.display="none",void 0!==document.getElementsByName("mywp_template_cat")[0]&&document.getElementsByName("mywp_template_cat")[0].value,a=t.data.select("core/editor").getEditedPostContent(),f(e,JSON.stringify(a)),document.getElementById("saveMyWPCustomPattern").disabled=!1,!1)}function _(){if(confirm(c("Replace all you content by your custom pattern?","mywp-custom-patterns"))){var e=document.getElementsByName("list_patterns")[0],n=(e.value,e.selectedIndex),a=e.options[n].getAttribute("data-content");""!=a&&t.data.dispatch("core/editor").resetBlocks(t.blocks.parse(a))}return!1}o("mywp-custom-patterns-settings",{render:function(){var t=[];return t.push(React.createElement("option",{key:"0",disabled:!0,"data-content":"",value:""},c("Pattern name","mywp-custom-patterns"))),Object.entries(MYWP_DATA.template_list).forEach((function(n){var a=e(n,2),r=a[0],o=a[1];t.push(React.createElement("option",{key:r+1,"data-content":o.content,value:o.id},o.title))})),React.createElement(l,null,React.createElement(d,{target:"mywp-custom-patterns"},"MyWP Custom Patterns"),React.createElement(y,{name:"mywp-custom-patterns",title:c("MyWP Custom Patterns","mywp-custom-patterns")},React.createElement("div",{id:"mywp-custom-patterns__wrapper",className:"mywp-custom-patterns__wrapper"},React.createElement("div",{className:"mywp-custom-patterns__settings"},React.createElement("p",null,c("Save your current blocks patterns","mywp-custom-patterns")),React.createElement("div",{style:{display:"none"},className:"mywp-error-field"},c("Required field","mywp-custom-patterns")),React.createElement("input",{name:"mywp_name_pattern",type:"text",placeholder:c("Pattern name","mywp-custom-patterns")}),React.createElement("button",{onClick:g,className:"mywp-custom-patterns__button",id:"saveMyWPCustomPattern"},c("Save your pattern","mywp-custom-patterns"))),React.createElement("div",{className:"mywp-custom-patterns__settings"},React.createElement("p",null,React.createElement("strong",null,c("Load and replace all you content by your custom patterns","mywp-custom-patterns"))),React.createElement("select",{name:"list_patterns",id:"list_patterns",defaultValue:""},t),React.createElement("br",null),React.createElement("button",{onClick:_,className:"mywp-custom-patterns__button",id:"loadMyWPCustomPattern"},c("Load your pattern","mywp-custom-patterns"))))))},icon:n}),o("mywp-custom-patterns-settings-all-blocks",{render:function(){var a=e(m(!1),2),o=a[0],s=a[1];return r=function(){return s(!1)},React.createElement(l,null,React.createElement(w,{icon:n,label:c("Add to Block Patterns","mywp-custom-patterns"),onClick:function(){return s(!0)}}),o&&React.createElement(p,{title:c("Add to Block Patterns","mywp-custom-patterns"),onRequestClose:r,className:"mywp-modal-patterns",style:{width:"460px"}},React.createElement("input",{style:{width:"100%"},name:"mywp_name_pattern_single_block",type:"text",placeholder:c("Pattern name","mywp-custom-patterns")}),React.createElement("div",{style:{display:"none",color:"#c03",fontSize:"14px",marginBottom:"4px"},className:"mywp-error-field"},c("Required field","mywp-custom-patterns")),React.createElement("button",{className:"mywp-custom-patterns__button",onClick:function(e){!function(e){var n,a=document.getElementsByName("mywp_name_pattern_single_block")[0].value;if(document.querySelector(".mywp-modal-patterns .mywp-custom-patterns__button").disabled=!0,""===a)return document.querySelector(".mywp-modal-patterns .mywp-error-field").style.display="block",void(document.querySelector(".mywp-modal-patterns .mywp-custom-patterns__button").disabled=!1);document.querySelector(".mywp-modal-patterns .mywp-error-field").style.display="none",n=t.data.select("core/editor").getSelectedBlockCount()>1?Object(t.blocks.serialize)(t.data.select("core/editor").getMultiSelectedBlocks()):Object(t.blocks.serialize)(t.data.select("core/editor").getSelectedBlock()),f(a,JSON.stringify(n)),r()}()}},c("Save your pattern","mywp-custom-patterns")),React.createElement("p",{style:{marginTop:"3em",background:"#ff9b0014",padding:"0.5em",fontWeight:"700"}},c("Note: after the pattern has been created, you'll need to reload the page to make the pattern visible in the inserter.","mywp-custom-patterns"))))},icon:n})}(window.wp)})();1 (()=>{"use strict";function e(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var a,r,o=[],c=!0,s=!1;try{for(n=n.call(e);!(c=(a=n.next()).done)&&(o.push(a.value),!t||o.length!==t);c=!0);}catch(e){s=!0,r=e}finally{try{c||null==n.return||n.return()}finally{if(s)throw r}}return o}}(e,n)||function(e,n){if(e){if("string"==typeof e)return t(e,n);var a=Object.prototype.toString.call(e).slice(8,-1);return"Object"===a&&e.constructor&&(a=e.constructor.name),"Map"===a||"Set"===a?Array.from(e):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?t(e,n):void 0}}(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=e[n];return a}var n=React.createElement("svg",{fillRule:"nonzero",clipRule:"evenodd",strokeLinecap:"round",strokeLinejoin:"round",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"18",height:"18"},React.createElement("g",null,React.createElement("path",{d:"M13.7104+8.56898L23.9931+8.56898L23.9931+15.4242L13.7104+15.4242L13.7104+8.56898ZM23.5647+0L13.7104+0L13.7104+6.85518L23.9931+6.85518L23.9931+0.428449C23.9931+0.191823+23.8013-1.03432e-08+23.5647+0ZM13.7104+23.9931L23.5647+23.9931C23.8013+23.9931+23.9931+23.8013+23.9931+23.5647L23.9931+17.138L13.7104+17.138L13.7104+23.9931ZM0.428449+23.9931L10.2828+23.9931L10.2828+13.7104L0+13.7104L0+23.5647C0+23.7995+0.193659+23.9931+0.428449+23.9931ZM10.2828+0L0.428449+0C0.191823+0-2.06865e-08+0.191823+0+0.428449L0+10.2828L10.2828+10.2828L10.2828+0Z"})));!function(t){var a,r=t.plugins.registerPlugin,o=t.i18n.__,c=t.element,s=c.Fragment,l=c.useState,m=(t.hooks.addFilter,t.components),p=m.Modal,u=(m.Button,t.editPost),i=u.PluginSidebarMoreMenuItem,d=u.PluginSidebar,y=u.PluginBlockSettingsMenuItem;function w(e,n){var a=new FormData;a.append("action","save_template_who"),a.append("title",e),a.append("post_id",t.data.select("core/editor").getCurrentPostId()),a.append("template_content",n),a.append("nonce",MYWP_DATA.nonce),fetch(MYWP_DATA.ajaxurl,{method:"POST",credentials:"same-origin",body:a}).then((function(e){return e.json()})).then((function(e){if(1===e.response){t.data.dispatch("core/notices").createNotice("success",o("Pattern saved","mywp-custom-patterns"),{type:"snackbar",isDismissible:!0,actions:[{url:window.location.href,label:o("Reload page","mywp-custom-patterns")}]});var n=document.getElementsByName("list_patterns")[0],a=document.createElement("option");a.value=e.id,a.text=e.title,a.dataset.content=e.content,n.add(a,null)}else t.data.dispatch("core/notices").createNotice("warning",o("Pattern not saved","mywp-custom-patterns"));document.getElementById("saveMyWPCustomPattern").disabled=!1})).catch((function(e){}))}function f(){document.getElementById("saveMyWPCustomPattern").disabled=!0;var e=document.getElementsByName("mywp_name_pattern")[0].value;return""===e?(document.querySelector(".mywp-custom-patterns__wrapper .mywp-error-field").style.display="block",void(document.getElementById("saveMyWPCustomPattern").disabled=!1)):(document.querySelector(".mywp-custom-patterns__wrapper .mywp-error-field").style.display="none",void 0!==document.getElementsByName("mywp_template_cat")[0]&&document.getElementsByName("mywp_template_cat")[0].value,w(e,t.data.select("core/editor").getEditedPostContent()),document.getElementById("saveMyWPCustomPattern").disabled=!1,!1)}function g(){if(confirm(o("Replace all you content by your custom pattern?","mywp-custom-patterns"))){var e=document.getElementsByName("list_patterns")[0],n=(e.value,e.selectedIndex),a=e.options[n].getAttribute("data-content");""!=a&&t.data.dispatch("core/editor").resetBlocks(t.blocks.parse(a))}return!1}r("mywp-custom-patterns-settings",{render:function(){var t=[];return t.push(React.createElement("option",{key:"0",disabled:!0,"data-content":"",value:""},o("Pattern name","mywp-custom-patterns"))),Object.entries(MYWP_DATA.template_list).forEach((function(n){var a=e(n,2),r=a[0],o=a[1];t.push(React.createElement("option",{key:r+1,"data-content":o.content,value:o.id},o.title))})),React.createElement(s,null,React.createElement(i,{target:"mywp-custom-patterns"},"MyWP Custom Patterns"),React.createElement(d,{name:"mywp-custom-patterns",title:o("MyWP Custom Patterns","mywp-custom-patterns")},React.createElement("div",{id:"mywp-custom-patterns__wrapper",className:"mywp-custom-patterns__wrapper"},React.createElement("div",{className:"mywp-custom-patterns__settings"},React.createElement("p",null,o("Save your current blocks patterns","mywp-custom-patterns")),React.createElement("div",{style:{display:"none"},className:"mywp-error-field"},o("Required field","mywp-custom-patterns")),React.createElement("input",{name:"mywp_name_pattern",type:"text",placeholder:o("Pattern name","mywp-custom-patterns")}),React.createElement("button",{onClick:f,className:"mywp-custom-patterns__button",id:"saveMyWPCustomPattern"},o("Save your pattern","mywp-custom-patterns"))),React.createElement("div",{className:"mywp-custom-patterns__settings"},React.createElement("p",null,React.createElement("strong",null,o("Load and replace all you content by your custom patterns","mywp-custom-patterns"))),React.createElement("select",{name:"list_patterns",id:"list_patterns",defaultValue:""},t),React.createElement("br",null),React.createElement("button",{onClick:g,className:"mywp-custom-patterns__button",id:"loadMyWPCustomPattern"},o("Load your pattern","mywp-custom-patterns"))))))},icon:n}),r("mywp-custom-patterns-settings-all-blocks",{render:function(){var r=e(l(!1),2),c=r[0],m=r[1];return a=function(){return m(!1)},React.createElement(s,null,React.createElement(y,{icon:n,label:o("Add to Block Patterns","mywp-custom-patterns"),onClick:function(){return m(!0)}}),c&&React.createElement(p,{title:o("Add to Block Patterns","mywp-custom-patterns"),onRequestClose:a,className:"mywp-modal-patterns",style:{width:"460px"}},React.createElement("input",{style:{width:"100%"},name:"mywp_name_pattern_single_block",type:"text",placeholder:o("Pattern name","mywp-custom-patterns")}),React.createElement("div",{style:{display:"none",color:"#c03",fontSize:"14px",marginBottom:"4px"},className:"mywp-error-field"},o("Required field","mywp-custom-patterns")),React.createElement("button",{className:"mywp-custom-patterns__button",onClick:function(e){!function(e){var n=document.getElementsByName("mywp_name_pattern_single_block")[0].value;if(document.querySelector(".mywp-modal-patterns .mywp-custom-patterns__button").disabled=!0,""===n)return document.querySelector(".mywp-modal-patterns .mywp-error-field").style.display="block",void(document.querySelector(".mywp-modal-patterns .mywp-custom-patterns__button").disabled=!1);document.querySelector(".mywp-modal-patterns .mywp-error-field").style.display="none",w(n,t.data.select("core/editor").getSelectedBlockCount()>1?Object(t.blocks.serialize)(t.data.select("core/editor").getMultiSelectedBlocks()):Object(t.blocks.serialize)(t.data.select("core/editor").getSelectedBlock())),a()}()}},o("Save your pattern","mywp-custom-patterns")),React.createElement("p",{style:{marginTop:"3em",background:"#ff9b0014",padding:"0.5em",fontWeight:"700"}},o("Note: after the pattern has been created, you'll need to reload the page to make the pattern visible in the inserter.","mywp-custom-patterns"))))},icon:n})}(window.wp)})(); -
mywp-custom-patterns/trunk/mywp-custom-patterns.php
r2684466 r2725825 4 4 * Plugin URI: https://www.whodunit.fr/ 5 5 * Description: Build your own block patterns in one click. 6 * Version: 1. 1.26 * Version: 1.2 7 7 * Author: Agence Whodunit 8 8 * Author URI: https://www.whodunit.fr/ -
mywp-custom-patterns/trunk/readme.txt
r2694268 r2725825 75 75 == Changelog == 76 76 77 1.2 78 Add compatibility WP 6.0 & Stackable 79 77 80 1.1.2 78 81 Fix save html pattern
Note: See TracChangeset
for help on using the changeset viewer.