【问题标题】:Wordpress WooCommerce Storefront Theme - Where are functions defined?Wordpress WooCommerce 店面主题 - 函数在哪里定义?
【发布时间】:2016-08-03 02:28:27
【问题描述】:

我是 WooCommerce 和 Storefront 主题的新手。在开始修改源代码之前,我试图了解它。我只是很难找出所有必要代码的位置。

当我打开 header.php 时,我迷路了,因为每个函数都与其他类似的文件挂钩。

do_action( 'storefront_before_header' );

这些功能在 Storefront 主题中定义在哪里?除了打开所有文件正在搜索字符串之外,我如何才能找到所有这些 do_action 函数在未来定义的位置?

我查看了以下文件:

  • storefront-functions.php
  • storefront-template-functions.php
  • storefront-template-hooks.php
  • functions.php

【问题讨论】:

    标签: php wordpress woocommerce storefront


    【解决方案1】:

    对于所有与 woocommerce 相关的产品,在每个钩子之前的 phpdoc 块中都有一个 @hooked 标签。如果没有@hooked 标签,则该钩子只是一个保留的钩子,将来可能会使用。

    让我们看看storefront_header hook

    /**
     * Functions hooked into storefront_header action
     *
     * @hooked storefront_skip_links                       - 0
     * @hooked storefront_social_icons                     - 10
     * @hooked storefront_site_branding                    - 20
     * @hooked storefront_secondary_navigation             - 30
     * @hooked storefront_product_search                   - 40
     * @hooked storefront_primary_navigation_wrapper       - 42
     * @hooked storefront_primary_navigation               - 50
     * @hooked storefront_header_cart                      - 60
     * @hooked storefront_primary_navigation_wrapper_close - 68
     */
    do_action( 'storefront_header' );
    

    @hooked 标记之后是函数名称和触发操作时执行该函数的优先级。较低的数字对应于较早的执行。

    挂钩到钩子的大部分函数都位于storefront-template-functions.php 内部,并添加在storefront-template-hooks.php 内部。

    您可以在主题文件夹中通过简单的 IDE 搜索找到这些功能。

    【讨论】:

      猜你喜欢
      • 2015-11-17
      • 2023-03-14
      • 2013-01-29
      • 2023-04-07
      • 1970-01-01
      • 2019-12-02
      • 1970-01-01
      • 1970-01-01
      • 2017-08-01
      相关资源
      最近更新 更多