[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/js/dist/ -> hooks.js (source)

   1  /******/ (() => { // webpackBootstrap
   2  /******/     var __webpack_modules__ = ({
   3  
   4  /***/ 507:
   5  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
   6  
   7  "use strict";
   8  
   9  // EXPORTS
  10  __webpack_require__.d(__webpack_exports__, {
  11    A: () => (/* binding */ createHooks_default)
  12  });
  13  
  14  // UNUSED EXPORTS: _Hooks
  15  
  16  ;// ./node_modules/@wordpress/hooks/build-module/validateNamespace.js
  17  function validateNamespace(namespace) {
  18    if ("string" !== typeof namespace || "" === namespace) {
  19      console.error("The namespace must be a non-empty string.");
  20      return false;
  21    }
  22    if (!/^[a-zA-Z][a-zA-Z0-9_.\-\/]*$/.test(namespace)) {
  23      console.error(
  24        "The namespace can only contain numbers, letters, dashes, periods, underscores and slashes."
  25      );
  26      return false;
  27    }
  28    return true;
  29  }
  30  var validateNamespace_default = validateNamespace;
  31  
  32  
  33  ;// ./node_modules/@wordpress/hooks/build-module/validateHookName.js
  34  function validateHookName(hookName) {
  35    if ("string" !== typeof hookName || "" === hookName) {
  36      console.error("The hook name must be a non-empty string.");
  37      return false;
  38    }
  39    if (/^__/.test(hookName)) {
  40      console.error("The hook name cannot begin with `__`.");
  41      return false;
  42    }
  43    if (!/^[a-zA-Z][a-zA-Z0-9_.-]*$/.test(hookName)) {
  44      console.error(
  45        "The hook name can only contain numbers, letters, dashes, periods and underscores."
  46      );
  47      return false;
  48    }
  49    return true;
  50  }
  51  var validateHookName_default = validateHookName;
  52  
  53  
  54  ;// ./node_modules/@wordpress/hooks/build-module/createAddHook.js
  55  
  56  
  57  function createAddHook(hooks, storeKey) {
  58    return function addHook(hookName, namespace, callback, priority = 10) {
  59      const hooksStore = hooks[storeKey];
  60      if (!validateHookName_default(hookName)) {
  61        return;
  62      }
  63      if (!validateNamespace_default(namespace)) {
  64        return;
  65      }
  66      if ("function" !== typeof callback) {
  67        console.error("The hook callback must be a function.");
  68        return;
  69      }
  70      if ("number" !== typeof priority) {
  71        console.error(
  72          "If specified, the hook priority must be a number."
  73        );
  74        return;
  75      }
  76      const handler = { callback, priority, namespace };
  77      if (hooksStore[hookName]) {
  78        const handlers = hooksStore[hookName].handlers;
  79        let i;
  80        for (i = handlers.length; i > 0; i--) {
  81          if (priority >= handlers[i - 1].priority) {
  82            break;
  83          }
  84        }
  85        if (i === handlers.length) {
  86          handlers[i] = handler;
  87        } else {
  88          handlers.splice(i, 0, handler);
  89        }
  90        hooksStore.__current.forEach((hookInfo) => {
  91          if (hookInfo.name === hookName && hookInfo.currentIndex >= i) {
  92            hookInfo.currentIndex++;
  93          }
  94        });
  95      } else {
  96        hooksStore[hookName] = {
  97          handlers: [handler],
  98          runs: 0
  99        };
 100      }
 101      if (hookName !== "hookAdded") {
 102        hooks.doAction(
 103          "hookAdded",
 104          hookName,
 105          namespace,
 106          callback,
 107          priority
 108        );
 109      }
 110    };
 111  }
 112  var createAddHook_default = createAddHook;
 113  
 114  
 115  ;// ./node_modules/@wordpress/hooks/build-module/createRemoveHook.js
 116  
 117  
 118  function createRemoveHook(hooks, storeKey, removeAll = false) {
 119    return function removeHook(hookName, namespace) {
 120      const hooksStore = hooks[storeKey];
 121      if (!validateHookName_default(hookName)) {
 122        return;
 123      }
 124      if (!removeAll && !validateNamespace_default(namespace)) {
 125        return;
 126      }
 127      if (!hooksStore[hookName]) {
 128        return 0;
 129      }
 130      let handlersRemoved = 0;
 131      if (removeAll) {
 132        handlersRemoved = hooksStore[hookName].handlers.length;
 133        hooksStore[hookName] = {
 134          runs: hooksStore[hookName].runs,
 135          handlers: []
 136        };
 137      } else {
 138        const handlers = hooksStore[hookName].handlers;
 139        for (let i = handlers.length - 1; i >= 0; i--) {
 140          if (handlers[i].namespace === namespace) {
 141            handlers.splice(i, 1);
 142            handlersRemoved++;
 143            hooksStore.__current.forEach((hookInfo) => {
 144              if (hookInfo.name === hookName && hookInfo.currentIndex >= i) {
 145                hookInfo.currentIndex--;
 146              }
 147            });
 148          }
 149        }
 150      }
 151      if (hookName !== "hookRemoved") {
 152        hooks.doAction("hookRemoved", hookName, namespace);
 153      }
 154      return handlersRemoved;
 155    };
 156  }
 157  var createRemoveHook_default = createRemoveHook;
 158  
 159  
 160  ;// ./node_modules/@wordpress/hooks/build-module/createHasHook.js
 161  function createHasHook(hooks, storeKey) {
 162    return function hasHook(hookName, namespace) {
 163      const hooksStore = hooks[storeKey];
 164      if ("undefined" !== typeof namespace) {
 165        return hookName in hooksStore && hooksStore[hookName].handlers.some(
 166          (hook) => hook.namespace === namespace
 167        );
 168      }
 169      return hookName in hooksStore;
 170    };
 171  }
 172  var createHasHook_default = createHasHook;
 173  
 174  
 175  ;// ./node_modules/@wordpress/hooks/build-module/createRunHook.js
 176  function createRunHook(hooks, storeKey, returnFirstArg, async) {
 177    return function runHook(hookName, ...args) {
 178      const hooksStore = hooks[storeKey];
 179      if (!hooksStore[hookName]) {
 180        hooksStore[hookName] = {
 181          handlers: [],
 182          runs: 0
 183        };
 184      }
 185      hooksStore[hookName].runs++;
 186      const handlers = hooksStore[hookName].handlers;
 187      if (false) {}
 188      if (!handlers || !handlers.length) {
 189        return returnFirstArg ? args[0] : void 0;
 190      }
 191      const hookInfo = {
 192        name: hookName,
 193        currentIndex: 0
 194      };
 195      async function asyncRunner() {
 196        try {
 197          hooksStore.__current.add(hookInfo);
 198          let result = returnFirstArg ? args[0] : void 0;
 199          while (hookInfo.currentIndex < handlers.length) {
 200            const handler = handlers[hookInfo.currentIndex];
 201            result = await handler.callback.apply(null, args);
 202            if (returnFirstArg) {
 203              args[0] = result;
 204            }
 205            hookInfo.currentIndex++;
 206          }
 207          return returnFirstArg ? result : void 0;
 208        } finally {
 209          hooksStore.__current.delete(hookInfo);
 210        }
 211      }
 212      function syncRunner() {
 213        try {
 214          hooksStore.__current.add(hookInfo);
 215          let result = returnFirstArg ? args[0] : void 0;
 216          while (hookInfo.currentIndex < handlers.length) {
 217            const handler = handlers[hookInfo.currentIndex];
 218            result = handler.callback.apply(null, args);
 219            if (returnFirstArg) {
 220              args[0] = result;
 221            }
 222            hookInfo.currentIndex++;
 223          }
 224          return returnFirstArg ? result : void 0;
 225        } finally {
 226          hooksStore.__current.delete(hookInfo);
 227        }
 228      }
 229      return (async ? asyncRunner : syncRunner)();
 230    };
 231  }
 232  var createRunHook_default = createRunHook;
 233  
 234  
 235  ;// ./node_modules/@wordpress/hooks/build-module/createCurrentHook.js
 236  function createCurrentHook(hooks, storeKey) {
 237    return function currentHook() {
 238      const hooksStore = hooks[storeKey];
 239      const currentArray = Array.from(hooksStore.__current);
 240      return currentArray.at(-1)?.name ?? null;
 241    };
 242  }
 243  var createCurrentHook_default = createCurrentHook;
 244  
 245  
 246  ;// ./node_modules/@wordpress/hooks/build-module/createDoingHook.js
 247  function createDoingHook(hooks, storeKey) {
 248    return function doingHook(hookName) {
 249      const hooksStore = hooks[storeKey];
 250      if ("undefined" === typeof hookName) {
 251        return hooksStore.__current.size > 0;
 252      }
 253      return Array.from(hooksStore.__current).some(
 254        (hook) => hook.name === hookName
 255      );
 256    };
 257  }
 258  var createDoingHook_default = createDoingHook;
 259  
 260  
 261  ;// ./node_modules/@wordpress/hooks/build-module/createDidHook.js
 262  
 263  function createDidHook(hooks, storeKey) {
 264    return function didHook(hookName) {
 265      const hooksStore = hooks[storeKey];
 266      if (!validateHookName_default(hookName)) {
 267        return;
 268      }
 269      return hooksStore[hookName] && hooksStore[hookName].runs ? hooksStore[hookName].runs : 0;
 270    };
 271  }
 272  var createDidHook_default = createDidHook;
 273  
 274  
 275  ;// ./node_modules/@wordpress/hooks/build-module/createHooks.js
 276  
 277  
 278  
 279  
 280  
 281  
 282  
 283  class _Hooks {
 284    actions;
 285    filters;
 286    addAction;
 287    addFilter;
 288    removeAction;
 289    removeFilter;
 290    hasAction;
 291    hasFilter;
 292    removeAllActions;
 293    removeAllFilters;
 294    doAction;
 295    doActionAsync;
 296    applyFilters;
 297    applyFiltersAsync;
 298    currentAction;
 299    currentFilter;
 300    doingAction;
 301    doingFilter;
 302    didAction;
 303    didFilter;
 304    constructor() {
 305      this.actions = /* @__PURE__ */ Object.create(null);
 306      this.actions.__current = /* @__PURE__ */ new Set();
 307      this.filters = /* @__PURE__ */ Object.create(null);
 308      this.filters.__current = /* @__PURE__ */ new Set();
 309      this.addAction = createAddHook_default(this, "actions");
 310      this.addFilter = createAddHook_default(this, "filters");
 311      this.removeAction = createRemoveHook_default(this, "actions");
 312      this.removeFilter = createRemoveHook_default(this, "filters");
 313      this.hasAction = createHasHook_default(this, "actions");
 314      this.hasFilter = createHasHook_default(this, "filters");
 315      this.removeAllActions = createRemoveHook_default(this, "actions", true);
 316      this.removeAllFilters = createRemoveHook_default(this, "filters", true);
 317      this.doAction = createRunHook_default(this, "actions", false, false);
 318      this.doActionAsync = createRunHook_default(this, "actions", false, true);
 319      this.applyFilters = createRunHook_default(this, "filters", true, false);
 320      this.applyFiltersAsync = createRunHook_default(this, "filters", true, true);
 321      this.currentAction = createCurrentHook_default(this, "actions");
 322      this.currentFilter = createCurrentHook_default(this, "filters");
 323      this.doingAction = createDoingHook_default(this, "actions");
 324      this.doingFilter = createDoingHook_default(this, "filters");
 325      this.didAction = createDidHook_default(this, "actions");
 326      this.didFilter = createDidHook_default(this, "filters");
 327    }
 328  }
 329  function createHooks() {
 330    return new _Hooks();
 331  }
 332  var createHooks_default = createHooks;
 333  
 334  
 335  
 336  /***/ }),
 337  
 338  /***/ 8770:
 339  /***/ (() => {
 340  
 341  
 342  
 343  /***/ })
 344  
 345  /******/     });
 346  /************************************************************************/
 347  /******/     // The module cache
 348  /******/     var __webpack_module_cache__ = {};
 349  /******/     
 350  /******/     // The require function
 351  /******/ 	function __webpack_require__(moduleId) {
 352  /******/         // Check if module is in cache
 353  /******/         var cachedModule = __webpack_module_cache__[moduleId];
 354  /******/         if (cachedModule !== undefined) {
 355  /******/             return cachedModule.exports;
 356  /******/         }
 357  /******/         // Create a new module (and put it into the cache)
 358  /******/         var module = __webpack_module_cache__[moduleId] = {
 359  /******/             // no module.id needed
 360  /******/             // no module.loaded needed
 361  /******/             exports: {}
 362  /******/         };
 363  /******/     
 364  /******/         // Execute the module function
 365  /******/         __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
 366  /******/     
 367  /******/         // Return the exports of the module
 368  /******/         return module.exports;
 369  /******/     }
 370  /******/     
 371  /************************************************************************/
 372  /******/     /* webpack/runtime/compat get default export */
 373  /******/     (() => {
 374  /******/         // getDefaultExport function for compatibility with non-harmony modules
 375  /******/         __webpack_require__.n = (module) => {
 376  /******/             var getter = module && module.__esModule ?
 377  /******/                 () => (module['default']) :
 378  /******/                 () => (module);
 379  /******/             __webpack_require__.d(getter, { a: getter });
 380  /******/             return getter;
 381  /******/         };
 382  /******/     })();
 383  /******/     
 384  /******/     /* webpack/runtime/define property getters */
 385  /******/     (() => {
 386  /******/         // define getter functions for harmony exports
 387  /******/         __webpack_require__.d = (exports, definition) => {
 388  /******/             for(var key in definition) {
 389  /******/                 if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
 390  /******/                     Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
 391  /******/                 }
 392  /******/             }
 393  /******/         };
 394  /******/     })();
 395  /******/     
 396  /******/     /* webpack/runtime/hasOwnProperty shorthand */
 397  /******/     (() => {
 398  /******/         __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
 399  /******/     })();
 400  /******/     
 401  /******/     /* webpack/runtime/make namespace object */
 402  /******/     (() => {
 403  /******/         // define __esModule on exports
 404  /******/         __webpack_require__.r = (exports) => {
 405  /******/             if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
 406  /******/                 Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
 407  /******/             }
 408  /******/             Object.defineProperty(exports, '__esModule', { value: true });
 409  /******/         };
 410  /******/     })();
 411  /******/     
 412  /************************************************************************/
 413  var __webpack_exports__ = {};
 414  // This entry needs to be wrapped in an IIFE because it needs to be in strict mode.
 415  (() => {
 416  "use strict";
 417  __webpack_require__.r(__webpack_exports__);
 418  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
 419  /* harmony export */   actions: () => (/* binding */ actions),
 420  /* harmony export */   addAction: () => (/* binding */ addAction),
 421  /* harmony export */   addFilter: () => (/* binding */ addFilter),
 422  /* harmony export */   applyFilters: () => (/* binding */ applyFilters),
 423  /* harmony export */   applyFiltersAsync: () => (/* binding */ applyFiltersAsync),
 424  /* harmony export */   createHooks: () => (/* reexport safe */ _createHooks__WEBPACK_IMPORTED_MODULE_1__.A),
 425  /* harmony export */   currentAction: () => (/* binding */ currentAction),
 426  /* harmony export */   currentFilter: () => (/* binding */ currentFilter),
 427  /* harmony export */   defaultHooks: () => (/* binding */ defaultHooks),
 428  /* harmony export */   didAction: () => (/* binding */ didAction),
 429  /* harmony export */   didFilter: () => (/* binding */ didFilter),
 430  /* harmony export */   doAction: () => (/* binding */ doAction),
 431  /* harmony export */   doActionAsync: () => (/* binding */ doActionAsync),
 432  /* harmony export */   doingAction: () => (/* binding */ doingAction),
 433  /* harmony export */   doingFilter: () => (/* binding */ doingFilter),
 434  /* harmony export */   filters: () => (/* binding */ filters),
 435  /* harmony export */   hasAction: () => (/* binding */ hasAction),
 436  /* harmony export */   hasFilter: () => (/* binding */ hasFilter),
 437  /* harmony export */   removeAction: () => (/* binding */ removeAction),
 438  /* harmony export */   removeAllActions: () => (/* binding */ removeAllActions),
 439  /* harmony export */   removeAllFilters: () => (/* binding */ removeAllFilters),
 440  /* harmony export */   removeFilter: () => (/* binding */ removeFilter)
 441  /* harmony export */ });
 442  /* harmony import */ var _createHooks__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(507);
 443  /* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(8770);
 444  /* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_types__WEBPACK_IMPORTED_MODULE_0__);
 445  /* harmony reexport (unknown) */ var __WEBPACK_REEXPORT_OBJECT__ = {};
 446  /* harmony reexport (unknown) */ for(const __WEBPACK_IMPORT_KEY__ in _types__WEBPACK_IMPORTED_MODULE_0__) if(["default","actions","addAction","addFilter","applyFilters","applyFiltersAsync","createHooks","currentAction","currentFilter","defaultHooks","didAction","didFilter","doAction","doActionAsync","doingAction","doingFilter","filters","hasAction","hasFilter","removeAction","removeAllActions","removeAllFilters","removeFilter"].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = () => _types__WEBPACK_IMPORTED_MODULE_0__[__WEBPACK_IMPORT_KEY__]
 447  /* harmony reexport (unknown) */ __webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
 448  
 449  
 450  const defaultHooks = (0,_createHooks__WEBPACK_IMPORTED_MODULE_1__/* ["default"] */ .A)();
 451  const {
 452    addAction,
 453    addFilter,
 454    removeAction,
 455    removeFilter,
 456    hasAction,
 457    hasFilter,
 458    removeAllActions,
 459    removeAllFilters,
 460    doAction,
 461    doActionAsync,
 462    applyFilters,
 463    applyFiltersAsync,
 464    currentAction,
 465    currentFilter,
 466    doingAction,
 467    doingFilter,
 468    didAction,
 469    didFilter,
 470    actions,
 471    filters
 472  } = defaultHooks;
 473  
 474  
 475  })();
 476  
 477  (window.wp = window.wp || {}).hooks = __webpack_exports__;
 478  /******/ })()
 479  ;


Generated : Fri Nov 7 08:20:07 2025 Cross-referenced by PHPXref