Changeset 2738624
- Timestamp:
- 06/07/2022 12:56:14 PM (4 years ago)
- Location:
- terms-descriptions/trunk
- Files:
-
- 8 edited
-
includes/parsers/td_simple_parser.php (modified) (1 diff)
-
includes/parsers/td_simple_quotes_parser.php (modified) (1 diff)
-
includes/td_admin_options.php (modified) (3 diffs)
-
includes/td_frontend.php (modified) (3 diffs)
-
includes/td_options.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
terms-descriptions.php (modified) (1 diff)
-
tests/mockpress/mockpress.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
terms-descriptions/trunk/includes/parsers/td_simple_parser.php
r1867074 r2738624 73 73 continue; 74 74 } 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']) 76 76 && $this->is_current_url( $term[ 't_post_url' ] ) ) { 77 77 continue; -
terms-descriptions/trunk/includes/parsers/td_simple_quotes_parser.php
r1867074 r2738624 40 40 continue; 41 41 } 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']) 43 43 && $this->is_current_url( $term[ 't_post_url' ] ) ) { 44 44 continue; -
terms-descriptions/trunk/includes/td_admin_options.php
r2720242 r2738624 78 78 <th scope="row"><?php _e( 'Convert terms in shortcodes', 'terms-descriptions' ); ?></th> 79 79 <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" 81 81 <?php if(isset($options[ 'convert_in_shortcodes' ])) { checked( $options[ 'convert_in_shortcodes' ], 'on' ); } ?> /></label><br /> 82 82 </td> … … 210 210 </td> 211 211 </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> 220 Please, 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> 212 223 </tbody> 213 224 </table> … … 294 305 $input[ 'time_step' ] = 1000; 295 306 } 307 if ( !isset( $input[ 'additional_filters' ] ) ) { 308 $input[ 'additional_filters' ] = ''; 309 } 296 310 if ( false !== $old_options ) { 297 311 return array_merge( $old_options, $input ); -
terms-descriptions/trunk/includes/td_frontend.php
r2720242 r2738624 5 5 class SCO_TD_Frontend { 6 6 private $options; 7 7 8 8 /** 9 9 * Constuctor. Sets the filters handlers. … … 27 27 } 28 28 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 29 40 add_shortcode('terms-descriptions', function ( $atts, $content = "" ) { 30 41 return $this->parse_content( $content, true ); … … 37 48 * @global wpdb $wpdb wordpress database class 38 49 * @param string $content original post content 50 * @param bool $is_td_shortcode whether parsing [terms-descriptions] shortcode 39 51 * @return string updated post content 40 52 */ 41 53 public function parse_content( $content, $is_td_shortcode = false ) { 42 //checking if have to convert terms on this page43 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 parser53 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 terms68 $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 ) ) {73 54 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]); 75 87 } 76 88 } 89 } 77 90 78 //setting up parser79 $parser->set_terms( $terms );80 $parser->add_skip_tags( $this->options->getOption( 'skip_tags' ) );81 //target attribute82 $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 } 86 99 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 } 91 104 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; 97 126 } 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; 100 131 } 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; 101 140 } 102 141 } -
terms-descriptions/trunk/includes/td_options.php
r1867074 r2738624 32 32 $this->options[ 'skip_tags' ] = ''; 33 33 } 34 if ( !isset( $this->options[ 'additional_filters' ] ) ) { 35 $this->options[ 'additional_filters' ] = ''; 36 } 34 37 } 35 38 -
terms-descriptions/trunk/readme.txt
r2720242 r2738624 3 3 Tags: post, page, links, plugin, link building, cross linking, seo 4 4 Requires at least: 4.1 5 Tested up to: 5.9.35 Tested up to: 6.0 6 6 Stable tag: trunk 7 7 … … 79 79 == Changelog == 80 80 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 81 87 = 3.4.1 = 82 88 -
terms-descriptions/trunk/terms-descriptions.php
r2720242 r2738624 4 4 Plugin URI: https://simplecoding.org/plagin-wordpress-terms-descriptions 5 5 Description: 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. 16 Version: 3.4.2 7 7 Author: Vladimir Statsenko 8 8 Author URI: https://simplecoding.org -
terms-descriptions/trunk/tests/mockpress/mockpress.php
r928266 r2738624 1484 1484 1485 1485 class 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()) { 1487 1487 global $wp_test_expectations; 1488 1488 $wp_test_expectations['wp_widgets'][$id] = compact('id', 'name', 'widget_options', 'widget_controls');
Note: See TracChangeset
for help on using the changeset viewer.