覆盖插件功能

问题描述 投票:0回答:1

我正在使用WP Jobs Plugin和附加的WP Jobs应用程序截止日期,并且我需要更改一个函数:

    public function display_the_deadline() {
    global $post;

    $deadline = get_post_meta( $post->ID, '_application_deadline', true );
    $expiring = false;
    $expired  = false;
    $date_str = null;

    if ( $deadline ) {
        $expiring_days = apply_filters( 'job_manager_application_deadline_expiring_days', 2 );
        $expiring      = ( floor( ( current_time( 'timestamp' ) - strtotime( $deadline ) ) / ( 60 * 60 * 24 ) ) >= -$expiring_days );
        $expired       = ( floor( ( current_time( 'timestamp' ) - strtotime( $deadline ) ) / ( 60 * 60 * 24 ) ) >= 0 );
        $date_str      = date_i18n( $this->get_date_format(), strtotime( $deadline ) );
    }

    // Do not display anything if listing is already expired.
    if ( is_singular( 'job_listing' ) && $expired ) {
        return;
    }

    $timestamp = strtotime( $deadline );

    /**
     * Filters the display string for the application closing date.
     *
     * @since 1.2.1
     *
     * @param string $date_str  The default date string to be displayed.
     * @param string $timestamp The timestamp of the closing date.
     */
    $date_str = apply_filters( 'job_manager_application_deadline_closing_date_display', $date_str, $timestamp );

    if ( $date_str ) {
        echo '<li class="application-deadline ' . ( $expiring ? 'expiring' : '' ) . ' ' . ( $expired ? 'expired' : '' ) . '"><label>' . ( $expired ? __( 'Closed', 'wp-job-manager-application-deadline' ) : __( 'Closes', 'wp-job-manager-application-deadline' ) ) . ':</label> ' . $date_str . '</li>';
    }
}

在echo的“li class =”应用程序截止日期......“我需要更改Closes:to Deadline:我想知道是否可以在functions.php文件中覆盖此函数。我试图替换它使用Jquery但是没有用。

wordpress function plugins
1个回答
1
投票

不幸的是,没有一种很好的方法可以过滤插件中的现有功能,除非它们是按照这种方式设计的 - 并且它似乎没有设置为允许这样做。

使用JavaScript应该绝对有效。由于您的HTML输出类似于:

<li class="application-deadline expiring"><label>Closes:</label> Sept 4th, 2018</li>

您应该能够相当容易地选择元素。看看这个vanilla JS片段:

let deadlines = document.querySelectorAll('.application-deadline');

for( i = 0, n = deadlines.length; i < n; ++i ){
  deadlines[i].innerText = deadlines[i].innerText.replace('Closes:', 'Deadline:');
}
<li class="application-deadline expiring"><label>Closes:</label> Sept 4th, 2018</li>

或者,如果你愿意,一个jQuery版本:

jQuery(document).ready(function($){
  $('.application-deadline').each(function(){
    $(this).text( $(this).text().replace('Closes:', 'Deadline:') );
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li class="application-deadline expiring"><label>Closes:</label> Sept 4th, 2018</li>

编辑:您的内容似乎是使用Ajax动态加载的。您可以尝试使用$.ajaxComplete来处理代码:

jQuery(document).ajaxComplete( function( event, request, settings){
  $('.application-deadline').each(function(){
    $(this).text( $(this).text().replace('Closes:', 'Deadline:') );
  });
});

或者,您可以滥用CSS伪元素来操作文本:

.job_listing-location.job-end label {
    font-size: 0;
}

.job_listing-location.job-end label:before {
    content: "Deadline:";
    font-size: 16px;
}
© www.soinside.com 2019 - 2024. All rights reserved.