无法更改插件的标题

时间:2016-10-06 作者:user310291

我试图更改的标题“相关帖子”https://wordpress.org/plugins/related-posts-thumbnails/ 去做别的事。

我试图改变$top_text<h3>THIS IS NEW CAPTION:</h3> 但它不起作用。为什么?

    <?php
    /**
     * Plugin Name:  Related Posts Thumbnails
     * Plugin URI:   http://wordpress.shaldybina.com/plugins/related-posts-thumbnails/
     * Description:  Showing related posts thumbnails under the post.
     * Version:      1.5.2
     * Author:       Maria Shaldybina
     * Author URI:   http://shaldybina.com/
     */

    /*
       Copyright 2010  Maria I Shaldybina

      This program is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published by
      the Free Software Foundation; either version 2 of the License, or
      (at your option) any later version.

      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU General Public License for more details.
    */
    class RelatedPostsThumbnails {
      /* Default values. PHP 4 compatible */
      var $single_only       = \'1\';
      var $auto              = \'1\';
      var $top_text          = \'<h3>NEW CAPTION:</h3>\';
      var $number            = 3;
      var $relation          = \'categories\';
      var $poststhname       = \'thumbnail\';
      var $background        = \'#FFFFFF\';
      var $hoverbackground   = \'#EEEEEF\';
      var $border_color      = \'#DDDDDD\';
      var $font_color        = \'#333333\';
      var $font_family       = \'Arial\';
      var $font_size         = \'12\';
      var $text_length       = \'100\';
      var $excerpt_length    = \'0\';
      var $custom_field      = \'\';
      var $custom_height     = \'100\';
      var $custom_width      = \'100\';
      var $text_block_height = \'75\';
      var $thsource          = \'post-thumbnails\';
      var $categories_all    = \'1\';
      var $devmode           = \'0\';
      var $output_style      = \'div\';
      var $post_types        = array( \'post\' );
      var $custom_taxonomies = array();

      protected $wp_kses_rp_args = array( 

                \'h1\' => array(),
                \'h2\' => array(),
                \'h3\' => array(),
                \'h4\' => array(),
                \'h5\' => array(),
                \'h6\' => array(),
                \'strong\' => array(),
              );

      function __construct() {
        // initialization
        load_plugin_textdomain( \'related-posts-thumbnails\', false, basename( dirname( __FILE__ ) ) . \'/locale\' );
        $this->default_image = esc_url( plugins_url( \'img/default.png\', __FILE__ ) );

        // Compatibility for old default image path.
        if ( $this->is_old_default_img() )
          update_option( \'relpoststh_default_image\', $this->default_image );

        if ( get_option( \'relpoststh_auto\', $this->auto ) ) {
          add_filter( \'the_content\', array( $this, \'auto_show\' ) );
        }

        add_action( \'admin_menu\',  array( $this, \'admin_menu\' ) );
        add_shortcode( \'related-posts-thumbnails\' , array( $this, \'get_html\' ) );

        $this->wp_version = get_bloginfo( \'version\' );
      }

2 个回复
最合适的回答,由SO网友:Dave Romsey 整理而成

您刚刚更改了的默认值$top_text. 像这样直接修改插件不是一个好主意,因为更新时更改将丢失。

该插件中有更多的代码,仔细查看,我发现有一个选项页面,其中设置了该值。您似乎应该将标题文本的值更改为<h3>THIS IS NEW CAPTION:</h3> 那里

可以通过编程方式更改选项值,因此您应该能够将其添加到functions.php 要动态更改值,请执行以下操作:

function wpse241711_related_posts_thumbnails_filter_top_text( $top_text ) {
    return \'<h3>THIS IS NEW CAPTION:</h3>\';
}
add_filter( \'option_relpoststh_top_text\', \'wpse241711_related_posts_thumbnails_filter_top_text\' );

SO网友:websupporter

因为如果您深入查看插件,您将看到$top_text 仅当选项relpoststh_top_text 未设置。看起来有一个设置页面,您可以在其中编辑此文本。

相关推荐