简体   繁体   中英

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. 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?

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. 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/

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 ). 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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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