Skip to content

v1.5.0 #22

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

Merged
merged 84 commits into from
Jun 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
bc19c56
Merge remote-tracking branch 'refs/remotes/cleverness/master'
JoryHogeveen Jun 19, 2017
7d3ff29
Default ID value
JoryHogeveen Jun 19, 2017
6efa082
JSdoc block
JoryHogeveen Jun 19, 2017
25767b2
Add `widget_css_classes` filter to change the CSS classes per widget …
JoryHogeveen Jun 19, 2017
1c0d6b2
Separate form handling in mutiple smaller functions + add capability …
JoryHogeveen Jun 19, 2017
af7404c
PHPdoc + whitespaces
JoryHogeveen Jun 19, 2017
7dc9be2
Merge remote-tracking branch 'refs/remotes/cleverness/master'
JoryHogeveen Jun 19, 2017
51ac54b
Some CC fixes
JoryHogeveen Jun 19, 2017
6cc61a9
Always set string type by default
JoryHogeveen Jun 19, 2017
19e00f5
Filter predefined classed before parsing
JoryHogeveen Jun 19, 2017
781a2aa
Merge remote-tracking branch 'refs/remotes/cleverness/master'
JoryHogeveen Jun 19, 2017
56d710d
clear both on form wrapper div + phpdoc
JoryHogeveen Jun 19, 2017
1af23c4
Wrap settings with labels for a11y
JoryHogeveen Jun 19, 2017
94b23f2
Basename used in library, make sure it exists
JoryHogeveen Jun 20, 2017
b9fc6bc
Set correct versions for assets
JoryHogeveen Jun 20, 2017
c5eab92
Not needed, already done in activation function
JoryHogeveen Jun 20, 2017
e685cbb
Enhance method names
JoryHogeveen Jun 20, 2017
e9b6df3
Add settings handlers & move settings to lib + add settings load and …
JoryHogeveen Jun 20, 2017
8e83bae
Merge remote-tracking branch 'refs/remotes/cleverness/master'
JoryHogeveen Jun 20, 2017
86d9c85
Add WP External Links fix
JoryHogeveen Jun 20, 2017
172d1a5
Merge yes/no option functions
JoryHogeveen Jun 20, 2017
bc41747
Current tab handling + CC fixes
JoryHogeveen Jun 20, 2017
8c3e19d
Merge remote-tracking branch 'refs/remotes/cleverness/master'
JoryHogeveen Jun 20, 2017
1225f10
esc_attr for option key instead of string casting
JoryHogeveen Jun 20, 2017
b386118
Wrap esc function on full attribute
JoryHogeveen Jun 20, 2017
c6167b1
Remove Dutch and Russian languages, these are 100% on wp.org
JoryHogeveen Jun 20, 2017
144a53c
Option to try and fix the widget parameters if they are invalid.
JoryHogeveen Jun 20, 2017
6dc7b57
Move widget_option compatibility handling to it's own method
JoryHogeveen Jun 20, 2017
c5f228a
Disable complexity check because of third part plugin handling.
JoryHogeveen Jun 20, 2017
0fcab97
Remove double default code, not needed
JoryHogeveen Jun 20, 2017
c765867
Enhance setting handler in frontend + ensude all keys exists (with de…
JoryHogeveen Jun 20, 2017
bfbd4c6
readme update (changelog, testedupto, stabletag) + plugin docblock
JoryHogeveen Jun 20, 2017
9d162c0
Readme fix
JoryHogeveen Jun 20, 2017
2b5f8c3
Default settings logic and filter
JoryHogeveen Jun 20, 2017
d77a0ad
Sort classes based on the predefined classes on the frontend by default.
JoryHogeveen Jun 20, 2017
3f074af
Simplify setting checks + comments
JoryHogeveen Jun 20, 2017
8da5068
Do not use `disableSelection()` for sortables (IE-11 problem)
JoryHogeveen Jun 20, 2017
616e5c7
Readme update for #20
JoryHogeveen Jun 20, 2017
da1b6e6
Form wrapper style credits
JoryHogeveen Jun 20, 2017
3e86b71
Changelog desc fix
JoryHogeveen Jun 20, 2017
b6b16e2
Always use local methods, enhances dataflow
JoryHogeveen Jun 20, 2017
219ffcc
Always load plugin settings, enhances dataflow for frontend
JoryHogeveen Jun 20, 2017
5710f98
Predefined classes storage as array & parse if needed (mixed types se…
JoryHogeveen Jun 20, 2017
ccc0c26
Add setting storage unit tests
JoryHogeveen Jun 20, 2017
aa14794
PHPdoc and simplify code
JoryHogeveen Jun 20, 2017
4aba969
Add setting validation, parse values and make sure settings are alway…
JoryHogeveen Jun 20, 2017
adde0f9
Merge remote-tracking branch 'refs/remotes/cleverness/master'
JoryHogeveen Jun 20, 2017
a31761f
Use validation from library + move string type validation to library
JoryHogeveen Jun 20, 2017
8212cd4
Add more unittest assertions
JoryHogeveen Jun 20, 2017
daeb4e7
Add unit tests for `widget_css_classes_set_settings` filter
JoryHogeveen Jun 20, 2017
98e9b5d
v1.5.0-rc1 + PHPdoc
JoryHogeveen Jun 20, 2017
d4b516d
assertNotTrue() not available in PHP 5.2 unit tests
JoryHogeveen Jun 20, 2017
538b4f4
Better solution for assertNotTrue availability
JoryHogeveen Jun 20, 2017
db977e9
validation for `widget_css_classes_default_settings` filter
JoryHogeveen Jun 20, 2017
3be537b
Missing quote
JoryHogeveen Jun 21, 2017
8bde6b8
isset() not needed when using empty() + simplify code and order
JoryHogeveen Jun 21, 2017
8748f34
User settings library methods instead of array format
JoryHogeveen Jun 21, 2017
0504f8b
Refactor adding classes. Just one preg_replace needed.
JoryHogeveen Jun 21, 2017
3cf419b
Update changelog
JoryHogeveen Jun 21, 2017
bd578c9
Remove tab and eol characters
JoryHogeveen Jun 22, 2017
6bf3fd7
Change widget counter name and make it a local variable
JoryHogeveen Jun 22, 2017
009c532
Add init function to set capabilities. Only run the filters once.
JoryHogeveen Jun 22, 2017
67800d9
Secure widget update handling with capability verification
JoryHogeveen Jun 22, 2017
7438935
Enhance update method. Let it run faster if the user has full access.
JoryHogeveen Jun 22, 2017
4e90cac
Remove empty check
JoryHogeveen Jun 22, 2017
eb2f1cc
switch to a switch (hehe) + another \t\n found
JoryHogeveen Jun 22, 2017
6206b9c
Change opacity if predefined classes is disabled.
JoryHogeveen Jun 22, 2017
b58ce37
Add type input classes
JoryHogeveen Jun 22, 2017
525f1b4
Remove relCopy dependency + update changelog
JoryHogeveen Jun 22, 2017
f17cd52
Make setting class properties protected for possible class inheritanc…
JoryHogeveen Jun 22, 2017
277954d
Enhance update script. Now tested and validated for all previous vers…
JoryHogeveen Jun 22, 2017
037eef8
Add description handler + make general form methods public
JoryHogeveen Jun 22, 2017
0edf77a
Set plugin domain as a class constant
JoryHogeveen Jun 22, 2017
9763808
Option to remove duplicate classes.
JoryHogeveen Jun 22, 2017
46f2337
Add append_to_attribute() tests + fix setting tests
JoryHogeveen Jun 22, 2017
f32cbf5
Disable: The $domain arg must be a single string literal, not "". Sni…
JoryHogeveen Jun 22, 2017
537f953
No valid esc function for HTML (kses is not encouraged)
JoryHogeveen Jun 22, 2017
cc7e403
Enable `filter_unique` setting on append_to_attribute + enhance non-u…
JoryHogeveen Jun 22, 2017
00baade
End if().
JoryHogeveen Jun 22, 2017
8d48b97
Update notice and plugin deactivation instead of fatal error.
JoryHogeveen Jun 22, 2017
33f100a
Simplify code, prevent unnecessary indentation
JoryHogeveen Jun 26, 2017
5e60b66
1.5.0
JoryHogeveen Jun 29, 2017
9c7c315
Simplify importexport method (one less tab)
JoryHogeveen Jun 29, 2017
60b3570
Ignore importexport complexity warning for now
JoryHogeveen Jun 29, 2017
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
3 changes: 3 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ engines:
config:
standard: "Wordpress-Extra"
checks:
# Disable: The $domain arg must be a single string literal, not "". Sniff not working (class constant).
WordPress WP I18n NonSingularStringLiteralDomain:
enabled: false
# Disable: Class file names should be based on the class name with "class-" prepended.
WordPress Files FileName InvalidClassFileName:
enabled: false
Expand Down
313 changes: 270 additions & 43 deletions includes/widget-css-classes-library.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Method library
* @author C.M. Kendrick <cindy@cleverness.org>
* @package widget-css-classes
* @version 1.3.0
* @version 1.5.0
*/

/**
Expand All @@ -15,13 +15,39 @@
*/
class WCSSC_Lib {

const DOMAIN = 'widget-css-classes';

/**
* The plugin settings option key.
* @var string
* @since 1.5.0
*/
public static $settings_key = 'WCSSC_options';

/**
* Add Settings link to plugin's entry on the Plugins page
* The current plugin settings.
* @see WCSSC_Lib::set_settings()
* @var array
* @since 1.5.0
*/
private static $settings = array();

/**
* The default plugin settings.
* @see WCSSC_Lib::get_default_settings()
* @var array
* @since 1.5.0
*/
private static $default_settings = null;

/**
* Add Settings link to plugin's entry on the Plugins page.
*
* @static
* @param $links
* @param $file
* @param array $links
* @param string $file
* @return array
* @since 1.0
* @since 1.0
*/
public static function add_settings_link( $links, $file ) {
static $this_plugin;
Expand All @@ -30,27 +56,32 @@ public static function add_settings_link( $links, $file ) {
}

if ( $file === $this_plugin ) {
$settings_link = '<a href="' . admin_url( 'options-general.php?page=widget-css-classes-settings' ) . '">' . esc_attr__( 'Settings', 'widget-css-classes' ) . '</a>';
$settings_link = '<a href="' . admin_url( 'options-general.php?page=widget-css-classes-settings' ) . '">' . esc_attr__( 'Settings', WCSSC_Lib::DOMAIN ) . '</a>';
array_unshift( $links, $settings_link );
}

return $links;
}

/**
* Add plugin info to admin footer
* Add plugin info to admin footer.
*
* @static
* @since 1.0
*/
public static function admin_footer() {
$plugin_data = get_plugin_data( WCSSC_FILE );
echo $plugin_data['Title'] . ' | ' . esc_attr__( 'Version', 'widget-css-classes' ) . ' ' . esc_html( $plugin_data['Version'] ) . ' | ' . $plugin_data['Author'] .
' | <a href="http://codebrainmedia.com">CodeBrain Media</a> | <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=cindy@cleverness.org">' . esc_attr__( 'Donate', 'widget-css-classes' ) . '</a>
echo $plugin_data['Title'] // @codingStandardsIgnoreLine >> no valid esc function.
. ' | ' . esc_attr__( 'Version', WCSSC_Lib::DOMAIN ) . ' ' . esc_html( $plugin_data['Version'] )
. ' | ' . $plugin_data['Author'] // @codingStandardsIgnoreLine >> no valid esc function.
. ' | <a href="http://codebrainmedia.com">CodeBrain Media</a>'
. ' | <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=cindy@cleverness.org">' . esc_attr__( 'Donate', WCSSC_Lib::DOMAIN ) . '</a>
<br />';
}

/**
* Run install function to see if upgrade is needed
* Run install function to see if upgrade is needed.
*
* @static
* @since 1.0
*/
Expand All @@ -66,58 +97,254 @@ public static function install_plugin() {
// check if the db version is the same as the db version constant
if ( (string) WCSSC_DB_VERSION !== (string) $installed_version ) {
// update options
self::set_options( $installed_version );
self::update( $installed_version );
update_option( 'WCSSC_db_version', WCSSC_DB_VERSION );
}

}

/**
* Install or Upgrade Options
* Install or Upgrade Options.
*
* @static
* @param $version
* @since 1.0
*/
public static function set_options( $version ) {
private static function update( $version ) {

if ( empty( $version ) ) {
$settings = get_option( self::$settings_key );

if ( empty( $settings ) ) {
// add default options
$options = array(
'show_id' => 0,
'type' => 1,
'defined_classes' => '',
'show_number' => 1,
'show_location' => 1,
'show_evenodd' => 1,
);

add_option( 'WCSSC_options', $options );
self::update_settings( array() );
add_option( 'WCSSC_db_version', WCSSC_DB_VERSION );
return;
}

} else {
if ( version_compare( $version, '1.2', '<' ) ) {
$settings['show_number'] = 1;
$settings['show_location'] = 1;
$settings['show_evenodd'] = 1;
}

if ( version_compare( $version, '1.3', '<' ) ) {
// Hide option is now 0 instead of 3
if ( isset( $settings['type'] ) && 3 === (int) $settings['type'] ) {
$settings['type'] = 0;
}
// dropdown settings are renamed to defined_classes
if ( ! isset( $settings['dropdown'] ) ) {
$settings['dropdown'] = '';
}
$settings['defined_classes'] = $settings['dropdown'];
unset( $settings['dropdown'] );
}

self::update_settings( $settings );
}

if ( version_compare( $version, 1.2, '<' ) ) {
$general_options = get_option( 'WCSSC_options' );
$general_options['show_number'] = 1;
$general_options['show_location'] = 1;
$general_options['show_evenodd'] = 1;
update_option( 'WCSSC_options', $general_options );
/**
* Get plugin settings.
*
* @static
* @param string|int $key
* @return mixed
* @since 1.5.0
*/
public static function get_settings( $key = null ) {
if ( null !== $key ) {
if ( isset( self::$settings[ $key ] ) ) {
return self::$settings[ $key ];
}
return null;
}
return self::$settings;
}

/**
* Set plugin settings. All setting changes should run through this function.
*
* @static
* @param mixed $settings
* @param string|int $key
* @return bool
* @since 1.5.0
*/
public static function set_settings( $settings, $key = null ) {

if ( null !== $key ) {
// This plugin only has string type array keys.
if ( ! is_string( $key ) ) {
return false;
}
if ( version_compare( $version, 1.3, '<' ) ) {
$general_options = get_option( 'WCSSC_options' );
// Hide option is now 0 instead of 3
if ( isset( $general_options['type'] ) && 3 === (int) $general_options['type'] ) {
$general_options['type'] = 0;
self::$settings = (array) self::$settings;
self::$settings[ $key ] = $settings;
$settings = self::$settings;
}
elseif ( ! is_array( $settings ) ) {
return false;
}

// Pre-validate to make sure the user get's the correct formatted data according to the docs.
$settings = self::validate_settings( $settings, false );

/**
* Modify the plugin settings. Overwrites the DB values.
* IMPORTANT: Do not change the variable types of the values! Type casting will be overruled.
*
* @since 1.5.0
* @param array $settings {
* @type bool $fix_widget_params
* @type bool $show_id
* @type int $type
* @type array|string $defined_classes Array of predefined classes.
* Optionally allows a delimiter separated string.
* See WCSSC_Lib::parse_defined_classes().
* @type bool $show_number
* @type bool $show_location
* @type bool $show_evenodd
* }
* @return array
*/
$settings = apply_filters( 'widget_css_classes_set_settings', $settings );

// Full settings validation.
$settings = self::validate_settings( $settings, true );

self::$settings = $settings;
return true;
}

/**
* Update plugin settings. Also sets the current settings.
*
* @static
* @param mixed $settings
* @param string|int $key
* @return bool
* @since 1.5.0
*/
public static function update_settings( $settings, $key = null ) {
self::set_settings( $settings, $key );
return update_option( self::$settings_key, self::get_settings() );
}

/**
* Validate plugin settings.
*
* @static
* @param array $settings
* @param bool $parse
* @return array
* @since 1.5.0
*/
private static function validate_settings( $settings, $parse = true ) {

$defaults = self::get_default_settings();

// Make sure all keys are there and remove invalid keys.
$settings = shortcode_atts( $defaults, $settings );

if ( $parse ) {
// Parse all settings.
foreach ( $settings as $key => $value ) {

if ( 'defined_classes' === $key ) {
// Parse defined_classes to array.
$settings['defined_classes'] = self::parse_defined_classes( $value );
continue;
}
// dropdown settings are renamed to defined_classes
if ( ! isset( $general_options['dropdown'] ) ) {
$general_options['dropdown'] = '';

if ( is_string( $value ) ) {
$settings[ $key ] = strip_tags( stripslashes( $value ) );
}
$general_options['defined_classes'] = $general_options['dropdown'];
unset( $general_options['dropdown'] );
update_option( 'WCSSC_options', $general_options );

// Validate var types.
settype( $settings[ $key ], gettype( $defaults[ $key ] ) );
}
} // End if().
} else {
// Only apply typecasting to defined classes.
$settings['defined_classes'] = (array) $settings['defined_classes'];
}

return $settings;
}

/**
* Parse defined_classes to array.
*
* @static
* @param array|string $classes
* @return array
* @since 1.5.0
*/
private static function parse_defined_classes( $classes ) {
$replace = array( ';', ' ', '|' );

// Parse defined_classes to array.
if ( ! is_array( $classes ) ) {
// Convert to comma separated list.
$classes = str_replace( $replace, ',', (string) $classes );
// Convert to array and remove empty and duplicate values.
return array_unique( array_filter( explode( ',', $classes ) ) );
}

$new_classes = array();
// Parse each value the same way.
foreach ( $classes as $key => $class ) {
$class = self::parse_defined_classes( $class );
$new_classes = array_merge( $new_classes, $class );
}

$new_classes = array_unique( array_filter( $new_classes ) );
$new_classes = array_map( 'stripslashes', $new_classes );
$new_classes = array_map( 'strip_tags', $new_classes );

return $new_classes;
}

/**
* Get the default settings for this plugin.
*
* @static
* @return array
* @since 1.5.0
*/
public static function get_default_settings() {

// Only run filters once.
if ( self::$default_settings ) {
return self::$default_settings;
}

self::$default_settings = array(
'show_id' => false,
'type' => 1,
'defined_classes' => array(),
'show_number' => true,
'show_location' => true,
'show_evenodd' => true,
'fix_widget_params' => false,
'filter_unique' => false,
);

// Prevent passing by reference.
$default_settings = self::$default_settings;

/**
* Modify the plugin default settings. Doesn't change the DB values.
* IMPORTANT: Do not change the variable types of the values! Type casting will be overruled.
*
* @since 1.5.0
* @param array $default_settings See `widget_css_classes_set_settings` filter for parameters.
* @return array
*/
$default_settings = apply_filters( 'widget_css_classes_default_settings', $default_settings );

// Validate default settings against the original defaults.
self::$default_settings = self::validate_settings( $default_settings, true );

return self::$default_settings;
}

}
Loading