Plugin Directory

Changeset 2738624


Ignore:
Timestamp:
06/07/2022 12:56:14 PM (4 years ago)
Author:
vladimir.s
Message:

Terms descriptions v.3.4.2. New feature: support of additional filters added (https://github.com/vladimir-s/terms-descriptions/issues/1) Bug fixes: support of widgets in the sidebar, hooks above the loop added (https://github.com/vladimir-s/terms-descriptions/issues/4) Wordpress 6.0 support

Location:
terms-descriptions/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • terms-descriptions/trunk/includes/parsers/td_simple_parser.php

    r1867074 r2738624  
    7373                    continue;
    7474                }
    75                 if ( isset( $term[ 't_post_type' ] ) && $term[ 't_post_type' ] === 'ext_link'
     75                if ( isset( $term[ 't_post_type' ] ) && in_array($term[ 't_post_type' ], ['ext_link','page'])
    7676                        && $this->is_current_url( $term[ 't_post_url' ] ) ) {
    7777                    continue;
  • terms-descriptions/trunk/includes/parsers/td_simple_quotes_parser.php

    r1867074 r2738624  
    4040                    continue;
    4141                }
    42                 if ( isset( $term[ 't_post_type' ] ) && $term[ 't_post_type' ] === 'ext_link'
     42                if ( isset( $term[ 't_post_type' ] ) && in_array($term[ 't_post_type' ], ['ext_link','page'])
    4343                        && $this->is_current_url( $term[ 't_post_url' ] ) ) {
    4444                    continue;
  • terms-descriptions/trunk/includes/td_admin_options.php

    r2720242 r2738624  
    7878                    <th scope="row"><?php _e( 'Convert terms in shortcodes', 'terms-descriptions' ); ?></th>
    7979                    <td>
    80                         <label><input name="td_options[convert_in_shortcodes]" type="checkbox" id="convert_in_posts"
     80                        <label><input name="td_options[convert_in_shortcodes]" type="checkbox" id="convert_in_shortcodes"
    8181                                <?php if(isset($options[ 'convert_in_shortcodes' ])) { checked( $options[ 'convert_in_shortcodes' ], 'on' ); } ?> /></label><br />
    8282                    </td>
     
    210210                    </td>
    211211                </tr>
     212                <tr valign="middle">
     213                    <th scope="row"><?php _e( 'Additional filters', 'terms-descriptions' ); ?></th>
     214                    <td>
     215                        <?php $additional_filters = ( isset( $options[ 'additional_filters' ] ) ) ? $options[ 'additional_filters' ] : ''; ?>
     216                        <textarea name="td_options[additional_filters]" rows="7" cols="40" class="large-text code"><?php echo $additional_filters ?></textarea>
     217                        <span class="description"><?php _e( 'This option allows adding list of filters for which conversion will be applied. Each filter name should start from a new line. For example,<br>
     218<pre><code>bbp_get_reply_content</code>
     219<code>bbp_get_topic_content</code></pre>
     220Please, pay attention that <code>the_content</code>, <code>comment_text</code> and <code>get_the_archive_description</code> filters are set by other options and will be ignored.', 'terms-descriptions' ); ?></span>
     221                    </td>
     222                </tr>
    212223            </tbody>
    213224        </table>
     
    294305            $input[ 'time_step' ] = 1000;
    295306        }
     307        if ( !isset( $input[ 'additional_filters' ] ) ) {
     308            $input[ 'additional_filters' ] = '';
     309        }
    296310        if ( false !== $old_options ) {
    297311            return array_merge( $old_options, $input );
  • terms-descriptions/trunk/includes/td_frontend.php

    r2720242 r2738624  
    55class SCO_TD_Frontend {
    66    private $options;
    7    
     7
    88    /**
    99     * Constuctor. Sets the filters handlers.
     
    2727        }
    2828
     29        //applying additional filters
     30        if ( !empty( $additional_filters = $this->options->getOption( 'additional_filters' ) ) ) {
     31            $additional_filters_lines = explode( "\n", $additional_filters );
     32            foreach ( $additional_filters_lines as $filter_name ) {
     33                $trimmed_filter_name = trim( $filter_name );
     34                if ( !empty( $trimmed_filter_name ) && !in_array( $trimmed_filter_name, ['the_content', 'comment_text', 'get_the_archive_description'] ) ) {
     35                    add_filter( $trimmed_filter_name, array( $this, 'parse_content' ) );
     36                }
     37            }
     38        }
     39
    2940        add_shortcode('terms-descriptions', function ( $atts, $content = "" ) {
    3041            return $this->parse_content( $content, true );
     
    3748     * @global wpdb $wpdb wordpress database class
    3849     * @param string $content original post content
     50     * @param bool $is_td_shortcode whether parsing [terms-descriptions] shortcode
    3951     * @return string updated post content
    4052     */
    4153    public function parse_content( $content, $is_td_shortcode = false ) {
    42         //checking if have to convert terms on this page
    43         if ( false === $this->options->getOption( 'convert_only_single' ) || is_single() || is_page() ) {
    44             global $wpdb, $post;
    45             if ( false === $is_td_shortcode && 'on' === get_post_meta( $post->ID, '_disable_terms_descriptions', true ) ) {
    46                 return $content;
    47             }
    48             if ( 'on' !== $this->options->getOption( 'convert_in__'.$post->post_type )
    49                  && 'on' !== $this->options->getOption( 'convert_in_posts' ) ) {
    50                 return $content;
    51             }
    52             //selecting parser
    53             switch ( $this->options->getOption( 'parser' ) ) {
    54                 case 'simple_parser' :
    55                     $parser = new SCO_TD_Simple_Parser();
    56                     break;
    57                 case 'quotes_parser' :
    58                     $parser = new SCO_TD_Simple_Quotes_Parser();
    59                     break;
    60                 case 'long_terms_first_parser' :
    61                     $parser = new SCO_TD_Long_Terms_First_Parser();
    62                     break;
    63                 default :
    64                     $parser = new SCO_TD_Simple_Parser();
    65                     break;
    66             }
    67             //getting the terms
    68             $terms = $wpdb->get_results( 'SELECT * FROM ' . $wpdb->prefix . 'td_terms ORDER BY t_id DESC', ARRAY_A );
    69             foreach ( $terms as $key => $term ) {
    70                 $convert_in_post_types = ( !empty( $term['t_use_in_post_types'] ) ) ? unserialize( $term['t_use_in_post_types'] ) : $term['t_use_in_post_types'];
    71                 if ( is_array( $convert_in_post_types ) && !empty( $convert_in_post_types )
    72                     && !in_array( $post->post_type, $convert_in_post_types ) ) {
    7354
    74                         unset( $terms[$key] );
     55        global $wpdb, $post;
     56
     57        if ( false === $this->check_parse_conditions( $is_td_shortcode ) ) {
     58            return $content;
     59        }
     60
     61        //selecting parser
     62        switch ( $this->options->getOption( 'parser' ) ) {
     63            case 'simple_parser' :
     64                $parser = new SCO_TD_Simple_Parser();
     65                break;
     66            case 'quotes_parser' :
     67                $parser = new SCO_TD_Simple_Quotes_Parser();
     68                break;
     69            case 'long_terms_first_parser' :
     70                $parser = new SCO_TD_Long_Terms_First_Parser();
     71                break;
     72            default :
     73                $parser = new SCO_TD_Simple_Parser();
     74                break;
     75        }
     76        //getting the terms
     77        $terms = $wpdb->get_results( 'SELECT * FROM ' . $wpdb->prefix . 'td_terms ORDER BY t_id DESC', ARRAY_A );
     78
     79        if (!empty($post->post_type)) {
     80            foreach ($terms as $key => $term) {
     81                $convert_in_post_types = (!empty($term['t_use_in_post_types'])) ? unserialize($term['t_use_in_post_types'])
     82                    : $term['t_use_in_post_types'];
     83                if (is_array($convert_in_post_types) && !empty($convert_in_post_types)
     84                    && !in_array($post->post_type, $convert_in_post_types)) {
     85
     86                    unset($terms[$key]);
    7587                }
    7688            }
     89        }
    7790
    78             //setting up parser
    79             $parser->set_terms( $terms );
    80             $parser->add_skip_tags( $this->options->getOption( 'skip_tags' ) );
    81             //target attribute
    82             $target = '';
    83             if ( 'on' === $this->options->getOption( 'open_new_tab' ) ) {
    84                 $target = ' target="_blank" ';
    85             }
     91        //setting up parser
     92        $parser->set_terms( $terms );
     93        $parser->add_skip_tags( $this->options->getOption( 'skip_tags' ) );
     94        //target attribute
     95        $target = '';
     96        if ( 'on' === $this->options->getOption( 'open_new_tab' ) ) {
     97            $target = ' target="_blank" ';
     98        }
    8699
    87             $consider_existing_links = false;
    88             if ( 'on' === $this->options->getOption( 'consider_existing_links' ) ) {
    89                 $consider_existing_links = true;
    90             }
     100        $consider_existing_links = false;
     101        if ( 'on' === $this->options->getOption( 'consider_existing_links' ) ) {
     102            $consider_existing_links = true;
     103        }
    91104
    92             //replacing terms
    93             return $parser->parse( $content, $this->options->getOption( 'convert_first_n_terms' ), $this->options->getOption( 'class' )
    94                     , ( int )$this->options->getOption( 'convert_total' ), $this->options->getOption( 'show_title' )
    95                     , $this->options->getOption( 'text_before' ), $this->options->getOption( 'text_after' ), $target, $consider_existing_links
    96                     , $this->options->getOption( 'add_nofollow' ), $this->options->getOption( 'add_noindex' ) );
     105        //replacing terms
     106        return $parser->parse( $content, $this->options->getOption( 'convert_first_n_terms' ), $this->options->getOption( 'class' )
     107            , ( int )$this->options->getOption( 'convert_total' ), $this->options->getOption( 'show_title' )
     108            , $this->options->getOption( 'text_before' ), $this->options->getOption( 'text_after' ), $target, $consider_existing_links
     109            , $this->options->getOption( 'add_nofollow' ), $this->options->getOption( 'add_noindex' ) );
     110    }
     111
     112    /**
     113     * Decide to parse or not.
     114     *
     115     * @global type $post
     116     * @param  bool $is_td_shortcode
     117     * @return boolean true = do parse
     118     */
     119    public function check_parse_conditions( $is_td_shortcode = false ) {
     120
     121        global $post;
     122
     123        // Is convert_only_single option set AND this is not a single or page?
     124        if ( $this->options->getOption( 'convert_only_single' ) && !is_single() && !is_page() ) {
     125            return false;
    97126        }
    98         else {
    99             return $content;
     127
     128        // Is TD disabled for this specific post?
     129        if ( false === $is_td_shortcode && 'on' === get_post_meta( $post->ID, '_disable_terms_descriptions', true ) ) {
     130            return false;
    100131        }
     132
     133        // Is converting this post-type AND converting in shortcodes is disabled?
     134        if ( 'on' !== $this->options->getOption( 'convert_in__'.$post->post_type )
     135            && 'on' !== $this->options->getOption( 'convert_in_shortcodes' ) ) {
     136            return false;
     137        }
     138
     139        return true;
    101140    }
    102141}
  • terms-descriptions/trunk/includes/td_options.php

    r1867074 r2738624  
    3232            $this->options[ 'skip_tags' ] = '';
    3333        }
     34        if ( !isset( $this->options[ 'additional_filters' ] ) ) {
     35            $this->options[ 'additional_filters' ] = '';
     36        }
    3437    }
    3538
  • terms-descriptions/trunk/readme.txt

    r2720242 r2738624  
    33Tags: post, page, links, plugin, link building, cross linking, seo
    44Requires at least: 4.1
    5 Tested up to: 5.9.3
     5Tested up to: 6.0
    66Stable tag: trunk
    77
     
    7979== Changelog ==
    8080
     81= 3.4.2 =
     82
     83* New feature: support of additional filters added (https://github.com/vladimir-s/terms-descriptions/issues/1)
     84* Bug fixes: support of widgets in the sidebar, hooks above the loop added (https://github.com/vladimir-s/terms-descriptions/issues/4)
     85* Wordpress 6.0 support
     86
    8187= 3.4.1 =
    8288
  • terms-descriptions/trunk/terms-descriptions.php

    r2720242 r2738624  
    44Plugin URI: https://simplecoding.org/plagin-wordpress-terms-descriptions
    55Description: This plugin allows you to create list of terms and assign links to them. Plugin automatically replaces terms occurrences in your posts with appropriate links. You can control the number of replacements. After activation you can create terms list on plugin administration page (Tools -> Terms Descriptions).
    6 Version: 3.4.1
     6Version: 3.4.2
    77Author: Vladimir Statsenko
    88Author URI: https://simplecoding.org
  • terms-descriptions/trunk/tests/mockpress/mockpress.php

    r928266 r2738624  
    14841484
    14851485class WP_Widget {
    1486     function WP_Widget($id, $name, $widget_options = array(), $control_options = array()) {
     1486    function __construct($id, $name, $widget_options = array(), $control_options = array()) {
    14871487        global $wp_test_expectations;
    14881488        $wp_test_expectations['wp_widgets'][$id] = compact('id', 'name', 'widget_options', 'widget_controls');
Note: See TracChangeset for help on using the changeset viewer.