Porto 主题的动作钩子和过滤器钩子

Porto 主题的动作钩子和过滤器钩子
Porto 主题的动作钩子过滤器钩子

WordPress 提供了许多动作钩子和过滤器钩子,以允许开发者将插件“连接”到 WordPress 的某些位置。Porto 主题使用相同的方法,提供了许多可连接到 Porto 主题特定位置的钩子,以便主题用户可以在 Porto 子主题中进行定制化的修改。

如何使用动作钩子或过滤器钩子?

假设您想在特定的单个产品页面中,显示产品的手风琴模块,便可以使用 Porto 主题的过滤器钩子。

第 1 步:复制单个产品模板文件并修改该文件中的代码。

第 2 步:在子主题的 product/tabs.php 中使用过滤器钩子。

示例代码如下所示:

add_filter( 'porto_single_product_data_tab_type', function() {
return 'accordion';
});

动作钩子与过滤器钩子类似。通过使用动作钩子,不需要编辑主题核心代码,就可以完成目标动作。

Porto 主题提供的钩子

过滤器钩子列表:

1. portofooterfooter_tooltip.php
// Filters footer tooltip content.
apply_filters( 'porto_footer_tooltip', $tooltip_content );
2. portoheaderheader_tooltip.php
// Filters header tooltip content.
apply_filters( 'porto_header_tooltip', $tooltip_content );
3. portoincadmincustomizerheader-builder.php
// Filters customizer header builder elements.
apply_filters( 'porto_header_elements', $elements );
4. portoincadminsetup_wizardspeed_optimize_wizard.php
// Filters all shortcode list.
apply_filters( 'porto_all_shortcode_list', $shortcode_list );
// Filters all used shortcode list on site.
apply_filters( 'porto_used_shortcode_list', $used, $return_ids );
5. portoincfunctionsclass-dynamic-style.php
// Filters dynamic style internal css.
apply_filters( 'porto_dynamic_style_internal_output', $this->minify_css( $css ) );
6. portoincfunctionscontent_type.php
// Filters the meta value.
apply_filters( 'porto_get_meta_value_' . $meta_key, $value );
// Filters the page( portfolio, event, faq ) layout default settings. ( especially sidebar setting )
apply_filters( 'porto_meta_use_default', ( 'default' != $value ) ? true : false );
// Filters the page layout. ( includes portfolio, event, faq, 404page and so on )
apply_filters( 'porto_meta_layout', array( $value, $sidebar, $sidebar2 ) );
// Filters the default page layout. ( includes portfolio, event, faq, 404page and so on )
apply_filters( 'porto_meta_default_layout', $value );
// Filters the setting of sticky sidebar.
apply_filters( 'porto_meta_sticky_sidebar', $value );
// Filters the portfolio sub title.
apply_filters( 'porto_portfolio_sub_title', $output );
7. portoincfunctionsgeneral.php
// Filters template part path.
apply_filters( 'porto_get_template_part', $template, $slug, $name );
// Filters generate column classes for grid.
apply_filters( 'porto_generate_column_classes', $cols_arr, $cols, true );
// Filters mini screen size.
apply_filters( 'porto_mini_screen_size', 320 );
// Fitlers whether current page is product page or not.
apply_filters( 'porto_is_product', $result );
// Filters whether current page is shop page or not.
apply_filters( 'porto_is_shop', $result );
8. portoincfunctionslayout.php
// Filters the porto header logo shortcode render.
apply_filters( 'porto_logo', ob_get_clean() );
// Filters the porto currency switcher shortcode render.
apply_filters( 'porto_currency_switcher', $result );
// Filters the porto mobile currency switcher shortcode render.
apply_filters( 'porto_mobile_currency_switcher', $result );
// Filters the porto view switcher shortcode render.
apply_filters( 'porto_view_switcher', $result );
// Filters the porto mobile view switcher shortcode render.
apply_filters( 'porto_mobile_view_switcher', $result );
// Filters the porto top navigation shortcode render.
apply_filters( 'porto_top_navigation', $output );
// Filters the porto mobile top navigation shortcode render.
apply_filters( 'porto_mobile_top_navigation', $output );
// Filters the porto main menu shortcode render.
apply_filters( 'porto_main_menu', $output );
// Filters the porto secondary menu shortcode render.
apply_filters( 'porto_secondary_menu', $output );
// Filters the porto main toggle menu shortcode render.
apply_filters( 'porto_main_toggle_menu', $output );
// Filters the porto header side menu shortcode render.
apply_filters( 'porto_header_side_menu', $output );
// Filters the whether site has sidebar menu or not.
apply_filters( 'porto_is_sidebar_menu', $have_sidebar_menu );
// Filters the sidebar menu shortcode render.
apply_filters( 'porto_sidebar_menu', $output );
// Filters the mobile menu shortcode render.
apply_filters( 'porto_mobile_menu', $output );
// Filters the search form shortcode render.
apply_filters( 'porto_search_form', $result );
// Filters the search form content shortcode render.
apply_filters( 'porto_search_form_content', ob_get_clean() );
// Filters the header socials shortcode render.
apply_filters( 'porto_header_socials', ob_get_clean() );
// Filters the minicart shortcode render.
apply_filters( 'porto_minicart', ob_get_clean() );
// Filters the page layout type. There are 3 types: boxed, wide, full.
apply_filters( 'porto_get_wrapper_type', $porto_settings['wrapper'] );
// Filters the header type.
apply_filters( 'porto_get_header_type', porto_header_type_is_preset() ? $porto_settings['header-type'] : '' );
// Filters the header builder layout.
apply_filters( 'porto_header_builder_current_layout', $porto_header_builder_layout );
// Filters the mini cart type. There are 4 types: simple, arrow-alt, inline, text.
apply_filters( 'porto_get_minicart_type', $minicart_type );
// Filters the blog id.
apply_filters( 'porto_get_blog_id', get_current_blog_id() );
// Filters the skin: dark or light
apply_filters( 'porto_is_dark_skin', ( isset( $porto_settings['css-type'] ) && 'dark' == $porto_settings['css-type'] ) );
9. portoincfunctionslayoutbreadcrumbs.php
// Filters the breadcrumb shortcode render.
apply_filters( 'porto_breadcrumbs', $output );
10. portoincfunctionslayoutpage-title.php
// Filters the page title.
apply_filters( 'porto_page_title', $output );
// Filters the page sub title.
apply_filters( 'porto_page_sub_title', $output );
11. portoincfunctionswoocommerce.php
// Filters lazy load images.
apply_filters( 'porto_lazy_load_images', $thumb_image );
// Filters product short description length.
apply_filters( 'porto_woocommerce_short_description_length', 30 );
// Filters product stock html.
apply_filters( 'porto_woocommerce_stock_html', $availability_html, $availability['availability'], $product );
// Filters cart page type ( Type 1, Type 2 )
apply_filters( 'porto_filter_cart_version', $cart_ver );
// Filters checkout page type ( Type 1, Type 2 )
apply_filters( 'porto_filter_checkout_version', $checkout_ver );
12. portoinclibinfinite-scrollinfinite-scroll.php
// Filters infinite scroll parameters.
apply_filters( 'porto_infinite_scroll_params', $params );
13. portoincliblive-searchlive-search.php
// Filters ajax search query.
apply_filters( 'porto_ajax_search_query', sanitize_text_field( $_REQUEST['query'] ) );
// Filters post type on search form.
apply_filters( 'porto_ajax_search_post_type', $post_type );
// Filters ajax search function.
apply_filters( 'porto_ajax_search_function', 'get_posts', $search_query, $args );
14. portoinclibwoocommerce-pre-orderclassesclass-porto-pre-order-view.php
// Filters pre-order available date.
apply_filters( 'porto_pre_order_available_date', $available_date, $product_id ) )
15. portoindex.php
// Filters whether current page has skeleton option or not.
apply_filters( 'porto_skeleton_lazyload', $value );
16. portowoocommercecheckoutreview-order.php
// Filters product price html.
apply_filters( 'porto_get_price_html', WC()->cart->get_cart_subtotal() );
17. portowoocommercecontent-product-cat.php
// Filters product filter categories list args.
apply_filters( 'porto_products_filter_categories_list_args', $list_args );
18. portowoocommercemyaccountdashboard.php
// Filters account subpage.
apply_filters( 'porto_woocommerce_account_box_items', $account_arr );
19. portowoocommercesingle-productproduct-thumbnails.php
// Filters html after thumbnails on single product page.
apply_filters( 'porto_single_product_after_thumbnails', '' );
20. porto-functionalitybuilderselementsheaderelementormenu-icon.php
// Filters mobile toggle shortcode render in header builder.
apply_filters( 'porto_header_builder_mobile_toggle', $html );
21. porto-functionalitybuilderselementsproductinit.php
// Filters product upsell args.
apply_filters( 'porto_woocommerce_upsell_display_args', $args );
22. porto-functionalitybuildersinit.php
// Filters template builder type( header, footer, single product, product archive, block, popup builder ).
apply_filters( 'porto_templates_builder_types', $this->builder_types );
// Filters default meta in new template builder.
apply_filters( 'porto_create_new_builder_meta', array() );
23. porto-functionalitybuilderslibclass-condition.php
// Filters global var for porto builder.
apply_filters( 'porto_builder', array() );
24. porto-functionalitybuildersviewscondition_template.php
// Filters list of post types for display condition.
apply_filters( 'porto_builder_post_types', $post_types );
// Filters taxonomy array for display condition.
apply_filters( 'porto_builder_condition_types', $taxonomies );
25. porto-functionalitymeta_boxeslibmeta_fields.php
// Filters page metabox fields.
apply_filters( 'porto_view_meta_fields', $fields );
// Filters page skin metabox fields.( page background color, page js, page css and so on )
apply_filters( 'porto_skin_meta_fields', $return );
26. porto-functionalityshortcodeslibfunctions.php
// Filters presets of creative grid layouts.
apply_filters( 'porto_creative_grid_layouts', false, $layout );
27. porto-functionalityshortcodeswoo_templatesporto_products.php
// Filters whether products have sticky option or not in porto products shortcode.
apply_filters( 'porto_wooocommerce_products_shortcode_sticky_filter', false ) );
// Filters categories html render.
apply_filters( 'porto_wooocommerce_products_shortcode_categories_html', $category_html );
28. porto-functionalityshortcodeswoo_templatesporto_products_filter.php
// Filters products price range.
apply_filters( 'porto_products_filter_price_range', $steps );
// Filters products price range html(render).
apply_filters( 'porto_products_filter_price_range_html', $format_text, $step );

动作钩子列表:

1. portocontent-archive-portfolio-fullscreen.php
// Fires after rendering portfolio content.
do_action( 'porto_portfolio_after_content' );
2. portofooter.php
// Fires after rendering content main.
do_action( 'porto_after_main' );
// Fires elementor pro alert on footer.
do_action( 'porto_elementor_pro_footer_location' );
// Fires after rendering footer template.
do_action( 'porto_after_wrapper' );
3. portofunctions.php
// Fires enqueue css after loaded porto theme css.
do_action( 'porto_enqueue_css' );
4. portoheaderheader_before.php
// Fires before 'div' tag which has page-wrapper class.
do_action( 'porto_before_wrapper' );
// Fires after 'div' tag which has page-wrapper class.
do_action( 'porto_wrapper_start' );
// Fires before rendering header template.
do_action( 'porto_before_header' );
// Fires before rendering banner template.
do_action( 'porto_before_banner' );
// Fires after rendering banner template.
do_action( 'porto_after_banner' );
// Fires before rendering content top template.
do_action( 'porto_before_content_top' );
// Fires after rendering content top template.
do_action( 'porto_after_content_top' );
// Fires before rendering main content template.
do_action( 'porto_before_content' );
// Fires before rendering content inner top template.
do_action( 'porto_before_content_inner_top' );
// Fires after rendering content inner top template.
do_action( 'porto_after_content_inner_top' );
5. portoincadminadmin_pagesclass-tools.php
// Fires after saving theme option.
do_action( 'porto_admin_save_theme_settings' );
6. portoincadminsetup_wizardsetup_wizard.php
// Fires before resetting menus on demo importing.
do_action( 'porto_importer_before_reset_menus' );
// Fires before importing widgets.
do_action( 'porto_importer_before_import_widgets' );
// Fires importing revolution slider.
do_action( 'porto_importer_import_revslider' );
// Fires before importing options.
do_action( 'porto_importer_before_import_options' );
7. portoincfunctionslayout.php
// Fires rendering header elements.
do_action( 'porto_header_elements', $key, $value );
8. portoincfunctionslayoutbreadcrumbs.php
// Fires before rendering breadcrumb template.
do_action( 'porto_before_breadcrumbs' );
9. portosidebar.php
// Fires before rendering sidebar.
do_action( 'porto_before_sidebar' );
// Fires after rendering sidebar.
do_action( 'porto_after_sidebar' );
// Fires after rendering main content.
do_action( 'porto_after_content' );
// Fires before rendering content bottom.
do_action( 'porto_before_content_bottom' );
// Fires after rendering content bottom.
do_action( 'porto_after_content_bottom' );
10. porto-functionalitybuilderslibclass-condition.php
// Fires before enqueuing theme scripts for builder condition.
do_action( 'porto_builder_condition_pre_enqueue' );

JS 钩子列表:

1. portojsadminadmin.js
// Fires when woocommerce plugin is loaded for swatch.
$wrapper.trigger( 'plugin_init' );
2. portojstheme-async.js
// Fires when login popup is loaded.
$( window ).trigger( 'porto_login_popup_opened' );
3. portojstheme.js
// Fires when shortcode is added or deleted in wpb frontend editor.
$( document.body ).trigger( 'porto_refresh_vc_content', [ $elements ] );
// Fires before executing init function of theme.js
$wrap.trigger( 'porto_init_start' );
// Fires after executing init function of theme.js
jQuery( document.body ).trigger( 'porto_init', [ $wrap ] );
// Fires after fully initializing theme main javascript.
$( document ).trigger( 'porto_theme_init' );
// Fires when real content is loaded but skeleton screen is shown still. You can mostly use when you want to execute javascript module in real content of skeleton screen.
$real.trigger( 'skeleton-loaded' );
// Fires before executing skeleton module.
$wrapper.trigger( 'skeleton:initialised' );
// Fires when countdown is initialized.
$( document.body ).trigger( 'porto_init_countdown', [ $( '.quickview-wrap-' + pid ) ] );
// Fires when products are updated. e.g: In category filter(ajax filter), top rated or best selling filter(ajax filter)
$el.trigger( 'porto_update_products', [ data, '' ] );

作者:牛奇网,本站文章均为辛苦原创,在此严正声明,本站内容严禁采集转载,面斥不雅请好自为之,本文网址:https://www.niuqi360.com/themes/do-action-and-fliter-hook-of-porto-theme/

(0)
上一篇 2022年3月13日 下午5:50
下一篇 2022年3月15日 下午10:33

相关推荐

发表评论

登录后才能评论