Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow html and enable wp editor for textareas #234

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 127 additions & 7 deletions admin/class-gdpr-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,112 @@ class GDPR_Admin {
public function __construct( $plugin_name, $version ) {
$this->plugin_name = $plugin_name;
$this->version = $version;
$this->allowed_html = array(
'a' => array(
'href' => true,
'title' => true,
'target' => true,
),
$tabs = apply_filters( 'gdpr_tools_tabs', $tabs );
$this->allowed_html = apply_filters( 'gdpr_allowed_html',
array(
'a' => array(
'id' => array(),
'class' => array(),
'href' => array(),
'rel' => array(),
'rev' => array(),
'name' => array(),
'title' => array(),
'target' => array(),
),
'div' => array(
'id' => array(),
'class' => array(),
),
'span' => array(
'id' => array(),
'class' => array(),
),
'i' => array(
'id' => array(),
'class' => array(),
),
'p' => array(
'id' => array(),
'class' => array(),
),
'br' => array(),
'hr' => array(
'class' => array(),
),
'em' => array(),
'strong' => array(),
'small' => array(),
'strike' => array(),
'ul' => array(
'id' => array(),
'class' => array(),
),
'ol' => array(
'id' => array(),
'class' => array(),
'start' => array(),
),
'li' => array(
'id' => array(),
'class' => array(),
'value' => array(),
),
'img' => array(
'id' => array(),
'class' => array(),
'alt' => array(),
'height' => array(),
'src' => array(),
'width' => array(),
'title' => array(),
),
'h1' => array(
'id' => array(),
'class' => array(),
),
'h2' => array(
'id' => array(),
'class' => array(),
),
'h3' => array(
'id' => array(),
'class' => array(),
),
'h4' => array(
'id' => array(),
'class' => array(),
),
'h5' => array(
'id' => array(),
'class' => array(),
),
'h6' => array(
'id' => array(),
'class' => array(),
),
'label' => array(
'id' => array(),
'class' => array(),
'for' => array(),
),
'code' => array(
'id' => array(),
'class' => array(),
),
'button' => array(
'id' => array(),
'class' => array(),
'name' => array(),
'value' => array(),
'disabled' => array(),
),
'abbr' => array(
'id' => array(),
'class' => array(),
'title' => array(),
),
)
);
}

Expand Down Expand Up @@ -185,7 +285,7 @@ public function sanitize_cookie_categories( $cookie_categories ) {
public function register_settings() {
$settings = array(
'gdpr_cookie_banner_content' => array( $this, 'sanitize_with_links' ),
'gdpr_cookie_privacy_excerpt' => 'sanitize_textarea_field',
'gdpr_cookie_privacy_excerpt' => array( $this, 'sanitize_with_links' ),
'gdpr_cookie_popup_content' => array( $this, 'sanitize_cookie_categories' ),
'gdpr_email_limit' => 'intval',
'gdpr_consent_types' => array( $this, 'sanitize_consents' ),
Expand Down Expand Up @@ -261,6 +361,26 @@ public function settings_page_template() {
include_once plugin_dir_path( __FILE__ ) . 'partials/templates/tmpl-cookies.php';
include_once plugin_dir_path( __FILE__ ) . 'partials/templates/tmpl-consents.php';

/**
* Extend tinymce valid elements to match our allowed_html.
*/
add_filter( 'tiny_mce_before_init', function( $initArray ) {
$extended_valid_elements = '';
foreach ( $this->allowed_html as $element => $attributes ) {
if ( strlen( $extended_valid_elements ) > 0 ) {
$extended_valid_elements .= ',';
}
$extended_valid_elements .= $element;
if ( is_array( $attributes ) && count( $attributes ) > 0 ) {
$extended_valid_elements .= '[' . implode( '|', array_keys( $attributes ) ) . ']';
}
}
$initArray['extended_valid_elements'] = $extended_valid_elements;
$initArray['entity_encoding'] = 'raw';

return $initArray;
}, 20, 1 );

include plugin_dir_path( __FILE__ ) . 'partials/settings.php';
}

Expand Down
79 changes: 74 additions & 5 deletions admin/partials/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,20 @@
</th>
<td>
<?php $privacy_bar_content = get_option( 'gdpr_cookie_banner_content', '' ); ?>
<textarea name="gdpr_cookie_banner_content" id="gdpr_cookie_banner_content" cols="80" rows="6"><?php echo esc_html( $privacy_bar_content ); ?></textarea>
<?php
if ( user_can_richedit() ):
wp_editor( $privacy_bar_content, 'gdpr_cookie_banner_content',
array(
'textarea_name' => 'gdpr_cookie_banner_content',
'textarea_rows' => '6',
)
);
else:
?>
<textarea name="gdpr_cookie_banner_content" id="gdpr_cookie_banner_content" cols="80" rows="6"><?php echo esc_textarea( $privacy_bar_content ); ?></textarea>
<?php
endif;
?>
</td>
</tr>
<tr>
Expand All @@ -145,7 +158,18 @@
</th>
<td>
<?php $privacy_excerpt = get_option( 'gdpr_cookie_privacy_excerpt', '' ); ?>
<textarea name="gdpr_cookie_privacy_excerpt" id="gdpr_cookie_privacy_excerpt" cols="80" rows="6"><?php echo esc_html( $privacy_excerpt ); ?></textarea>
<?php
if ( user_can_richedit() ):
wp_editor( $privacy_excerpt, 'gdpr_cookie_privacy_excerpt', array(
'textarea_name' => 'gdpr_cookie_privacy_excerpt',
'textarea_rows' => '6',
) );
else:
?>
<textarea name="gdpr_cookie_privacy_excerpt" id="gdpr_cookie_privacy_excerpt" cols="80" rows="6"><?php echo esc_textarea( $privacy_excerpt ); ?></textarea>
<?php
endif;
?>
<p class="description"><?php esc_html_e( 'This will appear in the consent section of the privacy preference window.', 'gdpr' ); ?></p>
</td>
</tr>
Expand Down Expand Up @@ -291,7 +315,22 @@
</span>
</label>
</th>
<td><textarea name="gdpr_cookie_popup_content[<?php echo esc_attr( $cat_id ); ?>][how_we_use]" id="tab-how-we-use-<?php echo esc_attr( $cat_id ); ?>" cols="53" rows="3"><?php echo esc_html( $registered_cookies[ $cat_id ]['how_we_use'] ); ?></textarea></td>
<td>
<?php
if ( user_can_richedit() ):
wp_editor( $registered_cookies[ $cat_id ]['how_we_use'], 'tab-how-we-use-' . esc_attr( $cat_id ),
array(
'textarea_name' => 'gdpr_cookie_popup_content[' . esc_attr( $cat_id ) . '][how_we_use]',
'textarea_rows' => '6',
)
);
else:
?>
<textarea name="gdpr_cookie_popup_content[<?php echo esc_attr( $cat_id ); ?>][how_we_use]" id="tab-how-we-use-<?php echo esc_attr( $cat_id ); ?>" cols="53" rows="3"><?php echo esc_html( $registered_cookies[ $cat_id ]['how_we_use'] ); ?></textarea>
<?php
endif;
?>
</td>
</tr>
<tr>
<th>
Expand Down Expand Up @@ -400,7 +439,22 @@
</span>
</label>
</th>
<td><textarea name="gdpr_consent_types[<?php echo esc_attr( $consent_id ); ?>][description]" id="consent-description-<?php echo esc_attr( $consent_id ); ?>" cols="53" rows="3" required><?php echo esc_html( $consent['description'] ); ?></textarea></td>
<td>
<?php
if ( user_can_richedit() ):
wp_editor( $consent['description'], 'consent-description-' . esc_attr( $consent_id ),
array(
'textarea_name' => 'gdpr_consent_types[' . esc_attr( $consent_id ) . '][description]',
'textarea_rows' => '6',
)
);
else:
?>
<textarea name="gdpr_consent_types[<?php echo esc_attr( $consent_id ); ?>][description]" id="consent-description-<?php echo esc_attr( $consent_id ); ?>" cols="53" rows="3" required><?php echo esc_html( $consent['description'] ); ?></textarea>
<?php
endif;
?>
</td>
</tr>
<tr>
<th>
Expand All @@ -412,7 +466,22 @@
</span>
</label>
</th>
<td><textarea name="gdpr_consent_types[<?php echo esc_attr( $consent_id ); ?>][registration]" id="consent-registration-<?php echo esc_attr( $consent_id ); ?>" cols="53" rows="3" required><?php echo esc_html( $consent['registration'] ); ?></textarea></td>
<td>
<?php
if ( user_can_richedit() ):
wp_editor( $consent['registration'], 'consent-registration-' . esc_attr( $consent_id ),
array(
'textarea_name' => 'gdpr_consent_types[' . esc_attr( $consent_id ) . '][registration]',
'textarea_rows' => '6',
)
);
else:
?>
<textarea name="gdpr_consent_types[<?php echo esc_attr( $consent_id ); ?>][registration]" id="consent-registration-<?php echo esc_attr( $consent_id ); ?>" cols="53" rows="3" required><?php echo esc_html( $consent['registration'] ); ?></textarea>
<?php
endif;
?>
</td>
</tr>
</table>
</div><!-- .inside -->
Expand Down
112 changes: 106 additions & 6 deletions public/class-gdpr-public.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,111 @@ class GDPR_Public {
public function __construct( $plugin_name, $version ) {
$this->plugin_name = $plugin_name;
$this->version = $version;
$this->allowed_html = array(
'a' => array(
'href' => true,
'title' => true,
'target' => true,
),
$this->allowed_html = apply_filters( 'gdpr_allowed_html',
array(
'a' => array(
'id' => array(),
'class' => array(),
'href' => array(),
'rel' => array(),
'rev' => array(),
'name' => array(),
'title' => array(),
'target' => array(),
),
'div' => array(
'id' => array(),
'class' => array(),
),
'span' => array(
'id' => array(),
'class' => array(),
),
'i' => array(
'id' => array(),
'class' => array(),
),
'p' => array(
'id' => array(),
'class' => array(),
),
'br' => array(),
'hr' => array(
'class' => array(),
),
'em' => array(),
'strong' => array(),
'small' => array(),
'strike' => array(),
'ul' => array(
'id' => array(),
'class' => array(),
),
'ol' => array(
'id' => array(),
'class' => array(),
'start' => array(),
),
'li' => array(
'id' => array(),
'class' => array(),
'value' => array(),
),
'img' => array(
'id' => array(),
'class' => array(),
'alt' => array(),
'height' => array(),
'src' => array(),
'width' => array(),
'title' => array(),
),
'h1' => array(
'id' => array(),
'class' => array(),
),
'h2' => array(
'id' => array(),
'class' => array(),
),
'h3' => array(
'id' => array(),
'class' => array(),
),
'h4' => array(
'id' => array(),
'class' => array(),
),
'h5' => array(
'id' => array(),
'class' => array(),
),
'h6' => array(
'id' => array(),
'class' => array(),
),
'label' => array(
'id' => array(),
'class' => array(),
'for' => array(),
),
'code' => array(
'id' => array(),
'class' => array(),
),
'button' => array(
'id' => array(),
'class' => array(),
'name' => array(),
'value' => array(),
'disabled' => array(),
),
'abbr' => array(
'id' => array(),
'class' => array(),
'title' => array(),
),
)
);
}

Expand Down Expand Up @@ -166,6 +265,7 @@ public function privacy_bar() {
'registered_cookies' => $registered_cookies,
'show_cookie_cat_checkboxes' => $show_cookie_cat_checkboxes,
'button_text' => $button_text,
'allowed_html' => $this->allowed_html,
) );
}

Expand Down
Loading