简体   繁体   English

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

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

I am using the plugin WP-Ultimo and want to make some changes to the signup forms. 我正在使用WP-Ultimo插件,并希望对注册表单进行一些更改。 It is actually a question that I believe could be applied to customising any plugin for use with my themes but have never found documentation showing it. 我认为这实际上是一个问题,可以应用于自定义与我的主题一起使用的任何插件,但是从未找到任何文档可以显示该插件。

I have this 我有这个

/**
 * 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;

that I would like to replace with 我想替换为

/**
 * 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;

Is there a simple way of creating a function to replace the original from within my functions.php? 有没有简单的方法可以创建一个function来替换我的functions.php中的原始函数?

Cheers 干杯

Unless a plugin provides filters or actions that you can hook into there isn't a way make modifications to it from your themes functions.php. 除非插件提供了您可以挂钩的过滤器或操作,否则无法通过主题functions.php对其进行修改。 You can check the documentation (or source code) for the plugin to look to and see if this is available. 您可以查看该插件的文档(或源代码),以查看其是否可用。

Here is comment on the WP-Ultimo forums about where to access a list of all of the actions/filters the plugin uses, you might be able to find one suitable for your use case there: https://docs.wpultimo.com/community/topic/hooking-into-the-system/ 这是WP-Ultimo论坛上的评论,内容涉及在哪里可以访问该插件使用的所有操作/过滤器的列表,您也许可以在其中找到一个适合您的用例的列表: https : //docs.wpultimo.com/社会/主题/钩住到最系统/

Wordpress plugins can allow themes (or other plugins) to make modications in two ways: one is with filters (using apply_filter ) and the other is with actions (using do_action ). WordPress插件可以使主题(或其他插件)以两种方式进行修改:一种是使用过滤器(使用apply_filter ),另一种是使用动作(使用do_action )。 Typically filters are used for modifying some data and actions are used for performing some action whenever a trigger occurs. 通常,过滤器用于修改某些数据,动作用于在触发发生时执行某些动作。

You can find out more here: 在这里你可以找到更多:

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

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