Plugin Directory

Changeset 3225771


Ignore:
Timestamp:
01/20/2025 06:25:17 PM (14 months ago)
Author:
ColinD
Message:

Fixed bug when used in the Site Editor where the exclude current post toggle
would cause an error resulting in an endlessly spinning loading wheel in the
query loop.

Location:
query-loop-exclude-posts/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • query-loop-exclude-posts/trunk/build/index.asset.php

    r3211274 r3225771  
    1 <?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => 'b45954ed15c3db4720ea');
     1<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => '9a1a082afde341deb6db');
  • query-loop-exclude-posts/trunk/build/index.js

    r3211274 r3225771  
    1 (()=>{"use strict";const e=window.wp.hooks,t=window.wp.element,o=window.wp.blockEditor,s=window.wp.components,r=window.wp.i18n,l=window.wp.compose,n=window.wp.data,i=window.ReactJSXRuntime;(0,e.addFilter)("blocks.registerBlockType","query-loop-exclude-posts/add-exclude-current-attribute",((e,t)=>("core/query"!==t||(e.attributes={...e.attributes,excludeCurrent:{type:"boolean",default:!1}}),e)));const c=(0,l.createHigherOrderComponent)((e=>l=>{if("core/query"!==l.name)return(0,i.jsx)(e,{...l});const{setAttributes:n,attributes:c}=l,{query:u={},excludeCurrent:p=!1}=c,a=u.exclude||[],x=u.postType||"post",w=e=>{n({query:{...u,exclude:e}})};return(0,t.useEffect)((()=>{const e=wp.data.select("core/editor").getCurrentPostId();p&&e?a.includes(e)||w([...a,e]):e&&a.includes(e)&&w(a.filter((t=>t!==e)))}),[p,a,w]),(0,i.jsxs)(t.Fragment,{children:[(0,i.jsx)(e,{...l}),(0,i.jsx)(o.InspectorControls,{children:(0,i.jsxs)(s.PanelBody,{title:(0,r.sprintf)(/* Translators: %s is the post type name */ /* Translators: %s is the post type name */
     1(()=>{"use strict";const e=window.wp.hooks,t=window.wp.element,o=window.wp.blockEditor,s=window.wp.components,r=window.wp.i18n,l=window.wp.compose,n=window.wp.data,i=window.ReactJSXRuntime;(0,e.addFilter)("blocks.registerBlockType","query-loop-exclude-posts/add-exclude-current-attribute",((e,t)=>("core/query"!==t||(e.attributes={...e.attributes,excludeCurrent:{type:"boolean",default:!1}}),e)));const c=(0,l.createHigherOrderComponent)((e=>l=>{if("core/query"!==l.name)return(0,i.jsx)(e,{...l});const{setAttributes:n,attributes:c}=l,{query:u={},excludeCurrent:p=!1}=c,a=u.exclude||[],x=u.postType||"post",w=e=>{n({query:{...u,exclude:e}})};return(0,t.useEffect)((()=>{const e=wp.data.select("core/editor").getCurrentPostId();console.log(e),p&&e&&Number.isInteger(e)?a.includes(e)||w([...a,e]):e&&Number.isInteger(e)&&a.includes(e)&&w(a.filter((t=>t!==e)))}),[p,a,w]),(0,i.jsxs)(t.Fragment,{children:[(0,i.jsx)(e,{...l}),(0,i.jsx)(o.InspectorControls,{children:(0,i.jsxs)(s.PanelBody,{title:(0,r.sprintf)(/* Translators: %s is the post type name */ /* Translators: %s is the post type name */
    22(0,r.__)("Exclude %ss","query-loop-exclude-posts"),x.charAt(0).toUpperCase()+x.slice(1)),initialOpen:!0,children:[(0,i.jsx)(s.PanelRow,{children:(0,i.jsx)(d,{excludePosts:a,postType:x,onChange:w})}),(0,i.jsxs)(s.PanelRow,{children:[(0,i.jsx)("div",{children:(0,i.jsx)("label",{children:(0,r.sprintf)((0,r.__)("Exclude current %s","query-loop-exclude-posts"),x)})}),(0,i.jsx)(s.FormToggle,{label:(0,r.sprintf)((0,r.__)("Exclude current %s","query-loop-exclude-posts"),x),checked:p,onChange:()=>{n({excludeCurrent:!p})}})]})]})})]})}),"withExcludePostsControl");(0,e.addFilter)("editor.BlockEdit","query-loop-exclude-posts/with-exclude-posts-control",c);const d=(0,n.withSelect)(((e,t)=>{const{postType:o}=t,{getEntityRecords:s}=e("core");return{posts:s("postType",o,{per_page:-1})}}))((({posts:e,excludePosts:t,onChange:o})=>{const l=e?e.map((e=>({id:e.id,title:e.title.rendered}))):[],n=l.filter((e=>t.includes(e.id))).map((e=>e.title));return(0,i.jsx)(s.FormTokenField,{label:(0,r.__)("Exclude by Title","query-loop-exclude-posts"),value:n,suggestions:l.map((e=>e.title)),onChange:e=>{const t=l.filter((t=>e.includes(t.title))).map((e=>e.id));o(t)},__nextHasNoMarginBottom:!0,__experimentalShowHowTo:!1})}))})();
  • query-loop-exclude-posts/trunk/query-loop-exclude-posts.php

    r3211274 r3225771  
    33 * Plugin Name: Query Loop Exclude Posts
    44 * Description: Extends the Query Loop Block to allow excluding specific posts. Select specific posts by title as well as toggle the option to exclude the current post.
    5  * Version: 1.0.0
     5 * Version: 1.1.0
    66 * Author: Colin Duwe
    77 * Author URI: https://www.colinduwe.com/
  • query-loop-exclude-posts/trunk/readme.txt

    r3211274 r3225771  
    33Tags: Query Loop Block
    44Tested up to: 6.7.1
    5 Stable tag: 1.0.0
     5Stable tag: 1.1.0
    66Requires at least: 6.6
    77Requires PHP: 8.0
     
    2525
    2626=== Development and Support ===
    27 
     27wp
    2828This plugin is developed on Github. You can find the uncompressed source javascript and
    2929submit issues and pull requests there:
     
    4343== Changelog ==
    4444
     45= 1.1.0 =
     46* Fixed bug when used in the Site Editor where the exclude current post toggle
     47would cause an error resulting in an endlessly spinning loading wheel in the
     48query loop.
     49
    4550= 1.0.0 =
    4651*initial release
Note: See TracChangeset for help on using the changeset viewer.