繁体   English   中英

通过覆盖主题functions.php自定义插件

[英]Customise a plugin by overwriting from themes functions.php

我正在使用WP-Ultimo插件,并希望对注册表单进行一些更改。 我认为这实际上是一个问题,可以应用于自定义与我的主题一起使用的任何插件,但是从未找到任何文档可以显示该插件。

我有这个

/**
 * Normal Text Inputs
 */
case 'text':
case 'number':
case 'password':
case 'email':
case 'url':
?>

<p <?php echo $wrapper_attributes; ?> id="<?php echo $field_slug; ?>-field" <?php echo $wrapper_attributes; ?> style="<?php echo $display ? '' : "display: none"; ?>" >

  <label for="<?php echo $field_slug; ?>"><?php echo $field['name']; ?> <?php echo WU_Util::tooltip($field['tooltip']); ?><br>
  <input <?php echo $attributes; ?> <?php echo isset($field['required']) && $field['required'] ? 'required' : ''; ?> type="<?php echo $field['type']; ?>" name="<?php echo $field_slug; ?>" id="<?php echo $field_slug; ?>" class="input" value="<?php echo isset($results[$field_slug]) ? $results[$field_slug] : ''; ?>" size="20"></label>

  <?php if ($error_message = $results['errors']->get_error_message($field_slug)) {
    echo '<p class="error">' . $error_message . '</p>';
  } ?>

</p>

<?php 
break;

我想替换为

/**
 * Normal Text Inputs
 */
case 'text':
case 'number':
case 'password':
case 'email':
case 'url':
?>

<div <?php echo $wrapper_attributes; ?> id="<?php echo $field_slug; ?>-field" <?php echo $wrapper_attributes; ?> style="<?php echo $display ? '' : "display: none"; ?>" >

  <input <?php echo $attributes; ?> <?php echo isset($field['required']) && $field['required'] ? 'required' : ''; ?> type="<?php echo $field['type']; ?>" name="<?php echo $field_slug; ?>" id="<?php echo $field_slug; ?>" class="input" value="<?php echo isset($results[$field_slug]) ? $results[$field_slug] : ''; ?>" size="20">

  <?php if ($error_message = $results['errors']->get_error_message($field_slug)) {
    echo '<p class="error">' . $error_message . '</p>';
  } ?>

</div>

<?php 
break;

有没有简单的方法可以创建一个function来替换我的functions.php中的原始函数?

干杯

除非插件提供了您可以挂钩的过滤器或操作,否则无法通过主题functions.php对其进行修改。 您可以查看该插件的文档(或源代码),以查看其是否可用。

这是WP-Ultimo论坛上的评论,内容涉及在哪里可以访问该插件使用的所有操作/过滤器的列表,您也许可以在其中找到一个适合您的用例的列表: https : //docs.wpultimo.com/社会/主题/钩住到最系统/

WordPress插件可以使主题(或其他插件)以两种方式进行修改:一种是使用过滤器(使用apply_filter ),另一种是使用动作(使用do_action )。 通常,过滤器用于修改某些数据,动作用于在触发发生时执行某些动作。

在这里你可以找到更多:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM