Plugin Directory

Changeset 2446754


Ignore:
Timestamp:
12/28/2020 11:53:33 AM (5 years ago)
Author:
ajarunthomas
Message:

New Version with Enable/Disable Filter option

Location:
text-filtering/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • text-filtering/trunk/readme.txt

    r2446703 r2446754  
    17172. You can add as many filters as you want and then remove when you no longer need them to be applied to your posts.
    18183. The filters will replace the content accordingly as specified in the settings during page rendering and do not change the content you have saved in the posts. The Plugin does not alter any of your saved contents, but filters the text during the page load.
     19
     20== Changelog ==
     21 
     22= 1.0.0 =
     23* First Release
     24 
     25= 2.1.0 =
     26* Included option to enable or disable a filter, rather than delete a filter permanentaly and add later.
  • text-filtering/trunk/textfiltering.php

    r2446167 r2446754  
    33 * Plugin Name: Text Filtering
    44 * Description: Filter out the text in your posts, replace them with your preferred phrase across all your posts or for the specified category posts.
    5  * Version:     1.0.0
     5 * Version:     2.1.0
    66 * Author:      Arun Thomas
    77 * Text Domain: text-filtering
     
    3636
    3737  for($i=0;$i<$filters_count;$i++){
    38     if( (in_array(get_option('textfiltering_option_3_name')[$i], $category_array))||(get_option('textfiltering_option_3_name')[$i] == 'All') ){
     38    if( ((in_array(get_option('textfiltering_option_3_name')[$i], $category_array))||(get_option('textfiltering_option_3_name')[$i] == 'All')) & (get_option('textfiltering_option_enable')[$i] == 1) ){
    3939        $content = str_ireplace(get_option('textfiltering_option_name')[$i], get_option('textfiltering_option_2_name')[$i], $content);
    4040    }
     
    4949   add_option( 'textfiltering_option_2_name', ['*text muted*']);
    5050   add_option( 'textfiltering_option_3_name', ['All']);
     51   add_option( 'textfiltering_option_enable', [1]);
    5152
    5253   register_setting( 'textfiltering_options_group', 'textfiltering_option_name', 'textfiltering_callback' );
    5354   register_setting( 'textfiltering_options_group', 'textfiltering_option_2_name', 'textfiltering_callback' );
    5455   register_setting( 'textfiltering_options_group', 'textfiltering_option_3_name', 'textfiltering_callback' );
     56   register_setting( 'textfiltering_options_group', 'textfiltering_option_enable', 'textfiltering_callback' );
    5557}
    5658add_action( 'admin_init', 'textfiltering_register_settings' );
     
    109111
    110112    <h1>Text Filtering</h1>
    111     <form method="post" action="options.php">
     113    <form method="post" action="options.php" onsubmit="validate_textfiltering_settings()">
    112114      <?php settings_fields( 'textfiltering_options_group' ); ?>
    113115      <p>Specify your text filtering <a class="button button-primary" onclick="textfiltering_addfilter()"><span class="dashicons dashicons-plus" style="vertical-align: middle"></span> Add Filter</a></p>
     
    124126              <th scope="row">
    125127                <label for="textfiltering_option_3_name">Category</label>
     128              </th>
     129              <th scope="row">
     130                <label for="textfiltering_option_enable">Enable</label>
    126131              </th>
    127132              <th>
     
    151156                <?php } ?>
    152157                </select>
     158              </td>
     159              <td style="text-align: center">
     160                <input class="enable-checkbox" type="checkbox" name="textfiltering_option_enable[]" value="1" width="100%" <?php if(get_option('textfiltering_option_enable')[$i] == 1){ echo "checked"; } ?> />
     161                <input class="enable-checkbox-hidden" type="hidden" name="textfiltering_option_enable[]" value="0" />
    153162              </td>
    154163              <td>
     
    170179    }
    171180
     181    function validate_textfiltering_settings(){
     182      var checkboxes = document.getElementsByClassName("enable-checkbox");
     183      var checkboxes_hidden = document.getElementsByClassName("enable-checkbox-hidden");
     184      for (var i = 0; i < checkboxes.length; i++) {
     185        if( (checkboxes.item(i)).checked ) {
     186          (checkboxes_hidden.item(i)).disabled = true;
     187        }
     188      }
     189    }
     190
    172191    function textfiltering_addfilter(){
    173192      var element = document.getElementById('textfiltering-filter-block');
     
    191210                new_filter_html+='</select>'
    192211              +'</td>'
     212              +'<td style="text-align: center"><input class="enable-checkbox" type="checkbox" name="textfiltering_option_enable[]" value="1" width="100%" checked /><input class="enable-checkbox-hidden" type="hidden" name="textfiltering_option_enable[]" value="0" checked /></td>'
    193213              +'<td>'
    194214                +'<a class="button" style="width: 100%; text-align: center" onclick="textfiltering_removefilter('+filters_count+')"><span class="dashicons dashicons-trash" style="vertical-align: middle"></span> Remove</a>'
Note: See TracChangeset for help on using the changeset viewer.