{"id":15806,"date":"2019-05-22T14:41:47","date_gmt":"2019-05-22T17:41:47","guid":{"rendered":"https:\/\/blog.hostinger.io\/br-tutoriais\/?p=15806"},"modified":"2023-08-04T21:08:15","modified_gmt":"2023-08-05T00:08:15","slug":"wordpress-hooks","status":"publish","type":"post","link":"\/br\/tutoriais\/wordpress-hooks","title":{"rendered":"O que s\u00e3o hooks WordPress \u2013 guia para iniciantes"},"content":{"rendered":"<p><span style=\"font-weight: 400\">WordPress<\/span><span style=\"font-weight: 400\"> Hooks (tamb&eacute;m conhecidos como ganchos) s&atilde;o recursos que permitem que voc&ecirc; manipule processos sem modificar o arquivo no n&uacute;cleo do WordPress. Um gancho pode ser aplicado tanto numa a&ccedil;&atilde;o (<em>action hook<\/em>) quanto num filtro (<em>filter hook<\/em>).<\/span><\/p><p><span style=\"font-weight: 400\">Aprender sobre hooks &eacute; essencial para qualquer usu&aacute;rio do CMS WordPress. Eles podem ajud&aacute;-lo a criar algumas fun&ccedil;&otilde;es ou editar as configura&ccedil;&otilde;es padr&otilde;es de <\/span><span style=\"font-weight: 400\">temas<\/span><span style=\"font-weight: 400\"> ou <\/span><span style=\"font-weight: 400\">plugins<\/span><span style=\"font-weight: 400\">.<\/span><\/p><figure class=\"wp-block-image size-large\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/WordPress-Security-Checklist(pt-br).pdf\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" width=\"1024\" height=\"283\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2022\/12\/WordPress-Cheat-Sheet-BR.png\/public\" alt=\"\" class=\"wp-image-30402\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2022\/12\/WordPress-Cheat-Sheet-BR.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2022\/12\/WordPress-Cheat-Sheet-BR.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2022\/12\/WordPress-Cheat-Sheet-BR.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2022\/12\/WordPress-Cheat-Sheet-BR.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2022\/12\/WordPress-Cheat-Sheet-BR.png\/w=1536,fit=scale-down 1536w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><p>\n\n\n\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-o-proposito-dos-hooks\"><b>O Prop&oacute;sito dos Hooks<\/b><\/h2><p><span style=\"font-weight: 400\">O principal prop&oacute;sito dos ganchos &eacute; rodar uma fun&ccedil;&atilde;o automaticamente. Al&eacute;m disso, essa t&eacute;cnica tamb&eacute;m tem a habilidade de modificar, estender ou limitar uma funcionalidade ou tema de um plugin.<\/span><\/p><p><span style=\"font-weight: 400\">Aqui est&aacute; um exemplo de um hook no WordPress:<\/span><\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">function mytheme_enqueue_script()\n{wp_enqueue_script( 'my-custom-js', 'custom.js', false );}\nadd_action( 'wp_enqueue_scripts', 'mytheme_enqueue_script' );<\/pre><p><span style=\"font-weight: 400\">O exemplo acima mostra um gancho criado para conectar a fun&ccedil;&atilde;o <\/span><b>mytheme_enqueue_script<\/b><span style=\"font-weight: 400\"> com a a&ccedil;&atilde;o <\/span><b>wp_enqueue_scripts<\/b><span style=\"font-weight: 400\">. Esse hook ativa uma nova a&ccedil;&atilde;o para o seu site e, portanto, &eacute; chamado de action hook.<\/span><\/p><p><span style=\"font-weight: 400\">Ganchos frequentemente s&atilde;o usados na cria&ccedil;&atilde;o de componentes de plugin de uma aplica&ccedil;&atilde;o. Eles n&atilde;o apenas s&atilde;o usados nos <\/span><a href=\"\/br\/tutoriais\/o-que-e-cms\"><span style=\"font-weight: 400\">sistemas de gerenciamento de conte&uacute;do<\/span><\/a><span style=\"font-weight: 400\"> (da sigla em ingl&ecirc;s CMS, ou content management systems) como o WordPress, mas tamb&eacute;m s&atilde;o comumente usados em sites de <\/span><a href=\"\/br\/tutoriais\/o-que-e-e-commerce\"><span style=\"font-weight: 400\">e-commerce<\/span><\/a><span style=\"font-weight: 400\"> e de intranet dentro de uma empresa.<\/span><\/p><h2 class=\"wp-block-heading\" id=\"h-como-usar-hooks-wordpress\"><b>Como Usar Hooks WordPress?<\/b><\/h2><p><span style=\"font-weight: 400\">Usar hooks no WordPress requer um pouco mais de conhecimento sobre HTML e PHP. Mesmo assim, ainda que voc&ecirc; seja um completo iniciante, criar ganchos de a&ccedil;&atilde;o e de filtro pode n&atilde;o ser t&atilde;o dif&iacute;cil quanto voc&ecirc; pensa.<\/span><\/p><p><span style=\"font-weight: 400\">Voc&ecirc; somente precisa ir para a sua p&aacute;gina de postagem e ent&atilde;o mudar para o editor de texto. Quando estiver l&aacute;, voc&ecirc; pode colar os hooks que copiou que outros sites ou aqueles de sua cria&ccedil;&atilde;o.<\/span><\/p><h3 class=\"wp-block-heading\" id=\"h-como-utilizar-o-comando-add-action-no-wordpress\"><b>Como Utilizar o Comando add_action no WordPress<\/b><\/h3><p><span style=\"font-weight: 400\">Para adicionar um hook de a&ccedil;&atilde;o, voc&ecirc; deve ativar a fun&ccedil;&atilde;o <\/span><b>add_action () <\/b><span style=\"font-weight: 400\">no plugin WordPress. Essa fun&ccedil;&atilde;o pode ser ativada ao escrever os padr&otilde;es abaixo no seu arquivo functions.php:<\/span><\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">add_action(the 'nome da fun&ccedil;&atilde;o do target_hook', 'O_nome_da_fun&ccedil;&atilde;o_que_voc&ecirc;_quer_usar' ,'priority_scale'<\/pre><p><span style=\"font-weight: 400\">Conforme n&oacute;s vemos acima, hooks usam uma escala de prioridade para funcionar adequadamente. Essa escala &eacute; um valor ordinal autom&aacute;tico baseado numa escala de 1 a 999. &nbsp;Isso define a ordem de prefer&ecirc;ncia para fun&ccedil;&otilde;es associadas com um gancho em particular.<\/span><\/p><p><span style=\"font-weight: 400\">Um valor de prioridade mais baixo significa que a fun&ccedil;&atilde;o ser&aacute; rodada antes, enquanto um valor maior representa uma que vai ser executada depois. A escala vai mostrar a sequ&ecirc;ncia de execu&ccedil;&atilde;o das fun&ccedil;&otilde;es instaladas quando se usam os mesmos <\/span><b>target_hooks<\/b><span style=\"font-weight: 400\">.<\/span><\/p><p><span style=\"font-weight: 400\">O valor padr&atilde;o da <\/span><b>priority_scale <\/b><span style=\"font-weight: 400\">&eacute; de 10. Voc&ecirc; pode ajustar a escala de acordo com seu n&uacute;mero de <\/span><b>target_hooks<\/b><span style=\"font-weight: 400\">.<\/span><\/p><p><span style=\"font-weight: 400\">Aqui est&aacute; um exemplo de um gancho de a&ccedil;&atilde;o:<\/span><\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\nadd_action( 'wp_print_footer_scripts',\n'hostinger_custom_footer_scripts' );\nfunction webhost_custom_footer_scripts(){\n?&gt;&lt;script&gt;\/\/preencha os scripts de rodap&eacute; aqui&lt;\/script&gt;\n&lt;?php\n}\n?&gt;<\/pre><p><span style=\"font-weight: 400\">Note o padr&atilde;o no exemplo acima:<\/span><\/p><ul class=\"wp-block-list\">\n<li><strong>&lt;?php <\/strong>&eacute; o lugar onde voc&ecirc; p&otilde;e o hook para funcionar<\/li>\n\n\n\n<li><strong>add_action<\/strong> &eacute; o comando para criar um gancho de a&ccedil;&atilde;o<\/li>\n\n\n\n<li><strong>Wp_print_footer_scripts<\/strong> &eacute; o <strong>target_hook<\/strong> que voc&ecirc; ir&aacute; ligar a uma nova fun&ccedil;&atilde;o<\/li>\n\n\n\n<li><strong>Hostinger_custom_footer_scripts<\/strong> &eacute; a fun&ccedil;&atilde;o instalada e linkada com o <strong>target_hook<\/strong><\/li>\n\n\n\n<li><strong>&lt;script&gt;<\/strong> representa o texto que voc&ecirc; quer mostrar no <strong>target_hook<\/strong> (nesse caso, &eacute; o <strong>wp_print_footer_scripts<\/strong>)<\/li>\n<\/ul><h3 class=\"wp-block-heading\" id=\"h-como-usar-o-comando-add-filter\"><b>Como Usar o Comando add_filter<\/b><\/h3><p><span style=\"font-weight: 400\">Voc&ecirc; pode criar um hook de filtro usando a fun&ccedil;&atilde;o <\/span><b>apply_filters ()<\/b><span style=\"font-weight: 400\">. O gancho de filtro &eacute; usado para modificar, filtrar ou substituir um valor por um novo.<\/span><\/p><p><span style=\"font-weight: 400\">Da mesma maneira que na hora de usar o hook de a&ccedil;&atilde;o, ele traz uma fun&ccedil;&atilde;o que filtra o valor com as fun&ccedil;&otilde;es de filtro associadas (<\/span><b>apply_filter<\/b><span style=\"font-weight: 400\">).<\/span><\/p><p><span style=\"font-weight: 400\">Mais do que isso, ele tem fun&ccedil;&atilde;o de adicionar um hook filter para ser associado com outras fun&ccedil;&otilde;es (<\/span><b>add_filter)<\/b><span style=\"font-weight: 400\">.<\/span><\/p><p><span style=\"font-weight: 400\">Aqui est&aacute; um exemplo de gancho de filtro:<\/span><\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$score = 100;\necho \"Current score is : \". apply_filters( 'change_score', $score );<\/pre><ul class=\"wp-block-list\">\n<li><strong>$score = 100<\/strong> &eacute; o valor inicial<\/li>\n\n\n\n<li><strong>echo &ldquo;Current score is: &rdquo;<\/strong> representa o script que voc&ecirc; est&aacute; mostrando<\/li>\n\n\n\n<li><strong>apply_filters<\/strong> &eacute; o comando usado para criar um filtro de gancho<\/li>\n\n\n\n<li><strong>&lsquo;Change_score&rsquo;, $score<\/strong> &eacute; a fun&ccedil;&atilde;o a ser filtrada<\/li>\n<\/ul><p><span style=\"font-weight: 400\">Esse aqui &eacute; o filtro:<\/span><\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">add_filter( 'change_score', 'function_change_score' );\nfunction function_change_score( $score ){\n? $score+=100;\n? return $score;}<\/pre><ul class=\"wp-block-list\">\n<li><strong>Add_filter<\/strong> &eacute; criado para conectar o hook filter com uma nova fun&ccedil;&atilde;o<\/li>\n\n\n\n<li><strong>&lsquo;Change_score&lsquo;<\/strong> &eacute; o gancho alvo que ser&aacute; modificado<\/li>\n\n\n\n<li><strong>&lsquo;Function_change_score&lsquo;<\/strong> &eacute; uma nova fun&ccedil;&atilde;o que vai afetar o valor inicial<\/li>\n\n\n\n<li><strong>? $score+=100;<\/strong> &eacute; o c&oacute;digo que vai adicionar um valor maior para o valor atual ($score)<\/li>\n\n\n\n<li><strong>? return $score;<\/strong> &eacute; o c&oacute;digo que vai mostrar um novo valor no final<\/li>\n<\/ul><p><span style=\"font-weight: 400\">O resultado deve ser algo assim:<\/span><\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Current score: 200<\/pre><h3 class=\"wp-block-heading\" id=\"h-entenda-os-comandos-remove-action-e-remove-filter\"><b>Entenda os Comandos remove_action e remove_filter<\/b><\/h3><p><span style=\"font-weight: 400\">Se voc&ecirc; quiser desabilitar os comandos <\/span><b>add_action() <\/b><span style=\"font-weight: 400\">ou <\/span><b>add_filter<\/b><span style=\"font-weight: 400\"> de seu c&oacute;digo do WordPress, voc&ecirc; pode usar os comandos <\/span><b>remove_action <\/b><span style=\"font-weight: 400\">e <\/span><b>remove_filter ()<\/b><span style=\"font-weight: 400\">.<\/span><\/p><p><span style=\"font-weight: 400\">Esses c&oacute;digos basicamente s&atilde;o uma maneira de excluir certas a&ccedil;&otilde;es ou fun&ccedil;&otilde;es de filtro. Isso permite que voc&ecirc; modifique um plugin que tenha muitos ganchos desnecess&aacute;rios ou que pode afetar negativamente a otimiza&ccedil;&atilde;o de seu site.<\/span><\/p><p><span style=\"font-weight: 400\">Neste momento, voc&ecirc; pode estar se perguntando: &ldquo;por que n&atilde;o apenas deletar c&oacute;digos desnecess&aacute;rios?&rdquo;<\/span><\/p><p><span style=\"font-weight: 400\">Bom, essa certamente &eacute; uma op&ccedil;&atilde;o vi&aacute;vel se voc&ecirc; usa os seus pr&oacute;prios c&oacute;digos.<\/span><\/p><p><span style=\"font-weight: 400\">Contudo, no WordPress, voc&ecirc; frequentemente trabalha com os plugins ou temas de outra pessoa. Isso significa que voc&ecirc; est&aacute; arriscando criar um erro fatal se acabar deletando os arquivos incorretos.<\/span><\/p><p><span style=\"font-weight: 400\">Aqui est&aacute; um exemplo do uso do <\/span><b>remove_action()<\/b> <span style=\"font-weight: 400\">no WordPress:<\/span><\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">remove_action( 'wp_print_footer_scripts',\n'hostinger_custom_footer_scripts', 11 );\nadd_action( 'wp_print_footer_scripts', 'hostinger_custom_footer_scripts_theme', 11 );\nfunction hostinger_custom_footer_scripts_theme()\n{\n?&gt;\n&lt;script&gt;\/\/exemplo de sa&iacute;da por tema&lt;\/script&gt;\n&lt;?php\n}<\/pre><p><span style=\"font-weight: 400\">O exemplo acima mostra que o remove_action &eacute; usado para deletar os scripts de rodap&eacute; padr&atilde;o do WordPress e substitu&iacute;-lo com o script de rodap&eacute; customizado do tema da Hostinger.<\/span><\/p><p><span style=\"font-weight: 400\">Esse comando &eacute; aplic&aacute;vel para todos os tipos de action hooks no WordPress.<\/span><\/p><p><span style=\"font-weight: 400\">Al&eacute;m disso, aqui est&aacute; um exemplo do remove_filter:<\/span><\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );\nadd_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' );\n}<\/pre><p><span style=\"font-weight: 400\">Esse exemplo mostra como desativar o <\/span><b>wp_staticize_emoji_for_email<\/b><span style=\"font-weight: 400\">,<\/span> <span style=\"font-weight: 400\">que converte emojis em imagens est&aacute;ticas.<\/span><\/p><p><span style=\"font-weight: 400\">Ent&atilde;o n&oacute;s o substitu&iacute;mos com o <\/span><b>disable_emojis_tinymce<\/b><span style=\"font-weight: 400\">, que ir&aacute; desativar o recurso de emoji no WordPress (emoji s&atilde;o conhecidos por reduzir as velocidades de sites por faz&ecirc;-los criar um pedido adicional HTTP).<\/span><\/p><p><span style=\"font-weight: 400\">Ademais, voc&ecirc; pode usar o comando <\/span><b>remove_filter <\/b><span style=\"font-weight: 400\">para desabilitar m&uacute;ltiplos filtros numa sequ&ecirc;ncia. Aqui est&aacute; um exemplo:<\/span><\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">function disable_emojis() {\nremove_action( 'wp_head', 'print_emoji_detection_script', 7 );\nremove_action( 'admin_print_scripts', 'print_emoji_detection_script' );\nremove_action( 'wp_print_styles', 'print_emoji_styles' );\nremove_action( 'admin_print_styles', 'print_emoji_styles' );\nremove_filter( 'the_content_feed', 'wp_staticize_emoji' );\nremove_filter( 'comment_text_rss', 'wp_staticize_emoji' );\nremove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );\nadd_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' );\nadd_action( 'init', 'disable_emojis' );}<\/pre><p><span style=\"font-weight: 400\">O c&oacute;digo acima busca eliminar a fun&ccedil;&atilde;o emoji completamente no WordPress. Isso ilustra que n&atilde;o existe um limite para quantos comandos <\/span><b>remove_filter <\/b><span style=\"font-weight: 400\">voc&ecirc; pode incorporar no <\/span><b>functions.php.<\/b><\/p><h2 class=\"wp-block-heading\" id=\"h-exemplos-praticos\"><b>Exemplos Pr&aacute;ticos<\/b><\/h2><p><span style=\"font-weight: 400\">Como mencionamos anteriormente, existem v&aacute;rios hooks que voc&ecirc; pode usar para criar fun&ccedil;&otilde;es customizadas do WordPress. Aqui est&atilde;o alguns deles:<\/span><\/p><h3 class=\"wp-block-heading\" id=\"h-admin-post-thumbnail-size\"><b>admin_post_thumbnail_size<\/b><\/h3><p><span style=\"font-weight: 400\">Esse gancho de filtro mostra uma imagem de thumbnail no seu post dentro de &ldquo;Imagem Destacada&rdquo;. Existem tr&ecirc;s par&acirc;metros que s&atilde;o conectados com as fun&ccedil;&otilde;es: <\/span><b>$size, $thumbnail_id, <\/b><span style=\"font-weight: 400\">e<\/span><b> $post.<\/b><\/p><p><span style=\"font-weight: 400\">O hook deve parecer com algo assim:<\/span><\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$size = apply_filters( 'admin_post_thumbnail_size', $size, $thumbnail_id, $post );<\/pre><p><span style=\"font-weight: 400\">Tenha em mente que o par&acirc;metro <\/span><b>$size<\/b><span style=\"font-weight: 400\"> pode ser alterado de acordo com as suas necessidades. Por exemplo, se voc&ecirc; quiser configurar o seu tamanho de miniatura para 240 x 240 pixels, voc&ecirc; pode escrever o seguinte c&oacute;digo:<\/span><\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$size = apply_filters( 'admin_post_thumbnail_size', 240, $thumbnail_id, $post);<\/pre><p><span style=\"font-weight: 400\">Voc&ecirc; pode definir um tamanho customizado para a sua thumbnail ao adicionar a fun&ccedil;&atilde;o matriz (). O c&oacute;digo ficar&aacute; assim:<\/span><\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$size = apply_filters( 'admin_post_thumbnail_size', array(240, 400), $thumbnail_id, $post);<\/pre><p><span style=\"font-weight: 400\">A fun&ccedil;&atilde;o <\/span><b>array () <\/b><span style=\"font-weight: 400\">acima configura a sua miniatura para ser exibida em 240 x 400 pixels. Voc&ecirc; deve encontrar o melhor tamanho que se ajusta perfeitamente &agrave; sua p&aacute;gina.<\/span><\/p><h3 class=\"wp-block-heading\" id=\"h-after-password-reset\"><b>after_password_reset<\/b><\/h3><p><span style=\"font-weight: 400\">Esse action hook &eacute; ativado quando um usu&aacute;rio reseta a sua senha. O gancho consiste de dois par&acirc;metros: <\/span><b>$user e $new_pass.<\/b><\/p><p><span style=\"font-weight: 400\">O hook deve parecer algo assim:<\/span><\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">do_action( 'after_password_reset', $user, $new_pass );\n<\/pre><h3 class=\"wp-block-heading\" id=\"h-customize-loaded-components\"><b>customize_loaded_components<\/b><\/h3><p><span style=\"font-weight: 400\">Esse gancho age como um filtro que exclui alguns componentes do WordPress de seu processo central. Essas s&atilde;o fun&ccedil;&otilde;es que funcionam nos arquivos do core, como <\/span><b>wp-activate.php<\/b><span style=\"font-weight: 400\">, <\/span><b>wp-config-sample.php<\/b><span style=\"font-weight: 400\"> ou <\/span><b>wp-settings.php<\/b><span style=\"font-weight: 400\">. Enquanto isso, o componente &eacute; uma cole&ccedil;&atilde;o de recursos no WordPress que representam uma fun&ccedil;&atilde;o em particular no widget.<\/span><\/p><p><span style=\"font-weight: 400\">Entretanto, &eacute; importante notar que <\/span><b>customize_loaded_components <\/b><span style=\"font-weight: 400\">n&atilde;o podem ser adicionados num tema, j&aacute; que ele s&oacute; &eacute; ativado durante a fase &ldquo;<\/span><a href=\"https:\/\/developer.wordpress.org\/reference\/hooks\/plugins_loaded\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400\">plugins loaded<\/span><\/a><span style=\"font-weight: 400\">&rdquo;.<\/span><\/p><p><span style=\"font-weight: 400\">O hook consiste de dois par&acirc;metros: $components e $this. Ele deve ser escrito nesse formato:<\/span><\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$components = apply_filters( 'customize_loaded_components', array( 'widgets', 'nav_menus' ), $this );<\/pre><p><span style=\"font-weight: 400\">O par&acirc;metro <\/span><b>$components <\/b><span style=\"font-weight: 400\">&eacute; um grupo de fun&ccedil;&otilde;es do core que ser&atilde;o carregadas, enquanto o <\/span><b>$this <\/b><span style=\"font-weight: 400\">se refere ao objeto na classe existente.<\/span><\/p><p><span style=\"font-weight: 400\">Voc&ecirc; pode customizar a fun&ccedil;&atilde;o <\/span><b>array () <\/b><span style=\"font-weight: 400\">para determinar que componentes ser&atilde;o exclu&iacute;dos. O exemplo acima mostra que as widgets e os nav_menus s&atilde;o os componentes que ficaram de fora do processo do n&uacute;cleo.<\/span><\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"\/br\/hospedagem-wordpress\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2024\/06\/BR-New-WP_in-text-banner.png\/public\" alt=\"\" class=\"wp-image-44638\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2024\/06\/BR-New-WP_in-text-banner.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2024\/06\/BR-New-WP_in-text-banner.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2024\/06\/BR-New-WP_in-text-banner.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2024\/06\/BR-New-WP_in-text-banner.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><h2 class=\"wp-block-heading\" id=\"h-conclusao\"><b>Conclus&atilde;o<\/b><\/h2><p><span style=\"font-weight: 400\">Em suma, hooks s&atilde;o recursos que mudam a configura&ccedil;&atilde;o padr&atilde;o do seu site WordPress. Isso permite que voc&ecirc; adicione fun&ccedil;&otilde;es customizadas ou desabilite processos sem mudar o arquivo core.<\/span><\/p><p><span style=\"font-weight: 400\">Ganchos podem ser divididos em duas categorias: a&ccedil;&atilde;o e filtro. <\/span><span style=\"font-weight: 400\">Apesar dos m&eacute;todos de usar esses dois serem quase os mesmos, ambos possuem fun&ccedil;&otilde;es completamente diferentes.<\/span><\/p><p><span style=\"font-weight: 400\">O action hook &eacute; usado para criar novas fun&ccedil;&otilde;es, enquanto o filter hook serve para modificar o c&oacute;digo j&aacute; existente no arquivo function.php.<\/span><\/p><p><span style=\"font-weight: 400\">Al&eacute;m disso, existem diversos hooks que voc&ecirc; pode incorporar no WordPress. Tente experimentar usar v&aacute;rios tipos de ganchos para manipular as fun&ccedil;&otilde;es que voc&ecirc; deseja.<\/span><\/p><p><span style=\"font-weight: 400\">Quando voc&ecirc; se tornar proficiente, voc&ecirc; pode at&eacute; mesmo <\/span><a href=\"https:\/\/www.hostinger.com\/br\/tutoriais\/como-criar-um-plugin-um-wordpress\/\"><span style=\"font-weight: 400\">criar seus pr&oacute;prios plugins<\/span><\/a><span style=\"font-weight: 400\"> com esse recurso. E o mais legal: ele &eacute; compat&iacute;vel com todos os <a href=\"\/br\/hospedagem-wordpress\">planos WordPress<\/a> da Hostinger<\/span>.<span style=\"font-weight: 400\"> Boa sorte!<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>WordPress Hooks (tamb&eacute;m conhecidos como ganchos) s&atilde;o recursos que permitem que voc&ecirc; manipule processos sem modificar o arquivo no n&uacute;cleo do WordPress. Um gancho pode ser aplicado tanto numa a&ccedil;&atilde;o (action hook) quanto num filtro (filter hook). Aprender sobre hooks &eacute; essencial para qualquer usu&aacute;rio do CMS WordPress. Eles podem ajud&aacute;-lo a criar algumas fun&ccedil;&otilde;es [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/br\/tutoriais\/wordpress-hooks\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":125,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"rank_math_title":"","rank_math_description":"WordPress Hooks manipulam um processo sem mexer no core do WP. Aprenda como eles podem ajud\u00e1-lo a editar temas ou plugins!","rank_math_focus_keyword":"wordpress hooks","footnotes":""},"categories":[5602],"tags":[6580,6577,6578,6579,6581,6576,6574,4798,6575],"class_list":["post-15806","post","type-post","status-publish","format-standard","hentry","category-glossario","tag-acao","tag-add_action-wordpress","tag-add_filter-wordpress","tag-filtro","tag-ganchos","tag-hooks-wordpress","tag-o-que-sao-hooks-wordpress","tag-wordpress","tag-wordpress-hooks"],"hreflangs":[{"locale":"pt-BR","link":"https:\/\/www.hostinger.com\/br\/tutoriais\/wordpress-hooks","default":1},{"locale":"pt-PT","link":"https:\/\/www.hostinger.com\/pt\/tutoriais\/wordpress-hooks","default":0}],"acf":[],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/posts\/15806","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/users\/125"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/comments?post=15806"}],"version-history":[{"count":12,"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/posts\/15806\/revisions"}],"predecessor-version":[{"id":38991,"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/posts\/15806\/revisions\/38991"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/media?parent=15806"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/categories?post=15806"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/tags?post=15806"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}