Skip to content
Merged
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"composer/installers": "^1.0 || ^2.0"
},
"require-dev": {
"alleyinteractive/alley-coding-standards": "^1.0",
"alleyinteractive/alley-coding-standards": "^2.0",
"mantle-framework/testkit": "^1.3"
},
"scripts": {
Expand Down
10 changes: 5 additions & 5 deletions fieldmanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* Filesystem path to Fieldmanager.
*/
define( 'FM_BASE_DIR', dirname( __FILE__ ) );
define( 'FM_BASE_DIR', __DIR__ );

/**
* Default version number for static assets registered via Fieldmanager.
Expand Down Expand Up @@ -116,7 +116,7 @@ function fieldmanager_load_class( $class ) {
function fieldmanager_load_file( $file ) {
$file = FM_BASE_DIR . '/php/' . $file;
if ( ! file_exists( $file ) ) {
throw new FM_Class_Not_Found_Exception( $file );
throw new FM_Class_Not_Found_Exception( esc_html( $file ) );
}
// phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable -- baseline
require_once $file;
Expand Down Expand Up @@ -184,7 +184,7 @@ function fieldmanager_get_template( $tpl_slug ) {
* Default none.
* @param bool $admin Deprecated.
*/
function fm_add_script( $handle, $path = false, $deps = array(), $ver = false, $in_footer = false, $data_object = '', $data = array(), $plugin_dir = '', $admin = true ) {
function fm_add_script( $handle, $path = false, $deps = array(), $ver = false, $in_footer = false, $data_object = '', $data = array(), $plugin_dir = '', $admin = true ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed -- $admin is deprecated; other params used via compact()
// Ensure the Fieldmanager loader has been enqueued.
Fieldmanager_Util_Assets::instance()->add_script(
array(
Expand Down Expand Up @@ -212,7 +212,7 @@ function fm_add_script( $handle, $path = false, $deps = array(), $ver = false, $
* @param string $media Optional. Media for this stylesheet. Default 'all'.
* @param bool $admin Deprecated.
*/
function fm_add_style( $handle, $path = false, $deps = array(), $ver = false, $media = 'all', $admin = true ) {
function fm_add_style( $handle, $path = false, $deps = array(), $ver = false, $media = 'all', $admin = true ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed -- $admin is deprecated; other params used via compact()
Fieldmanager_Util_Assets::instance()->add_style( compact( 'handle', 'path', 'deps', 'ver', 'media' ) );
}

Expand Down Expand Up @@ -554,7 +554,7 @@ function fm_register_submenu_page( $group_name, $parent_slug, $page_title, $menu
}
if ( isset( $submenus[ $group_name ] ) ) {
/* translators: %s: group name */
throw new FM_Duplicate_Submenu_Name_Exception( sprintf( esc_html__( '%s is already in use as a submenu name', 'fieldmanager' ), $group_name ) );
throw new FM_Duplicate_Submenu_Name_Exception( esc_html( sprintf( __( '%s is already in use as a submenu name', 'fieldmanager' ), $group_name ) ) );
}

if ( ! $menu_title ) {
Expand Down
5 changes: 2 additions & 3 deletions php/class-fieldmanager-autocomplete.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,10 @@ public function __construct( $label = '', $options = array() ) {
);

if ( empty( $this->datasource ) ) {
$message = esc_html__( 'You must supply a datasource for the autocomplete field', 'fieldmanager' );
if ( Fieldmanager_Field::$debug ) {
throw new FM_Developer_Exception( $message );
throw new FM_Developer_Exception( esc_html__( 'You must supply a datasource for the autocomplete field', 'fieldmanager' ) );
} else {
wp_die( esc_html( $message ), esc_html__( 'No Datasource', 'fieldmanager' ) );
wp_die( esc_html__( 'You must supply a datasource for the autocomplete field', 'fieldmanager' ), esc_html__( 'No Datasource', 'fieldmanager' ) );
}
}
$this->datasource->allow_optgroups = false;
Expand Down
4 changes: 2 additions & 2 deletions php/class-fieldmanager-checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function form_element( $value = null ) {
esc_attr( $this->get_form_name() ),
esc_attr( (string) $this->checked_value ),
$this->get_element_attributes(),
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- baseline
// phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual -- baseline
( $value == $this->checked_value ) ? 'checked="checked"' : '',
esc_attr( $this->get_element_id() ),
$this->unchecked_value
Expand All @@ -75,7 +75,7 @@ public function form_element( $value = null ) {
* @return mixed Proper value.
*/
public function presave( $value = null, $current_value = array() ) {
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- baseline
// phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual -- baseline
if ( $value == $this->checked_value || $value === $this->unchecked_value ) {
return $value;
} elseif ( empty( $value ) ) {
Expand Down
3 changes: 1 addition & 2 deletions php/class-fieldmanager-checkboxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ public function form_element( $value = array() ) {
* @return string $attribute on match, empty on failure.
*/
public function option_selected( $current_option, $options, $attribute ) {
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison, WordPress.PHP.StrictInArray.MissingTrueStrict -- baseline
// phpcs:ignore Universal.Operators.StrictComparisons, WordPress.PHP.StrictInArray.MissingTrueStrict -- baseline
if ( ( ( null !== $options && ! empty( $options ) ) && in_array( $current_option, $options ) ) || ( 'checked' == $this->default_value && in_array( $this->default_value, $options ) ) ) {
return $attribute;
} else {
return '';
}
}

}
1 change: 0 additions & 1 deletion php/class-fieldmanager-datepicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,4 @@ public function get_minute( $value ) {
public function get_am_pm( $value ) {
return ! empty( $value ) ? gmdate( 'a', $value ) : '';
}

}
44 changes: 22 additions & 22 deletions php/class-fieldmanager-field.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ abstract class Fieldmanager_Field {
* @param mixed $value The value of the element.
* @return string HTML for the element.
*/
public function form_element( $value ) {
public function form_element( $value ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found -- $value is used by the included template
if ( ! $this->template ) {
$tpl_slug = strtolower( str_replace( 'Fieldmanager_', '', get_class( $this ) ) );
$this->template = fieldmanager_get_template( $tpl_slug );
Expand Down Expand Up @@ -458,7 +458,7 @@ public function set_options( $label, $options ) {
}

// If this is a single field with a limit of 1, serialize_data has no impact.
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- baseline
// phpcs:ignore Universal.Operators.StrictComparisons -- baseline
if ( ! $this->serialize_data && ! $this->is_group() && 1 == $this->limit ) {
$this->serialize_data = true;
}
Expand All @@ -483,7 +483,7 @@ public function set_options( $label, $options ) {
*/
public function element_markup( $values = array() ) {
$values = $this->preload_alter_values( $values );
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- baseline
// phpcs:ignore Universal.Operators.StrictComparisons -- baseline
if ( 1 != $this->limit ) {
// count() generates a warning when passed non-countable values in PHP 7.2.
if ( is_scalar( $values ) ) {
Expand Down Expand Up @@ -527,14 +527,14 @@ public function element_markup( $values = array() ) {

// Find the array position of the "counter" (e.g. in element[0], [0] is the counter, thus the position is 1).
$html_array_position = 0; // default is no counter; i.e. if $this->limit = 0.
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- baseline
// phpcs:ignore Universal.Operators.StrictComparisons -- baseline
if ( 1 != $this->limit ) {
$html_array_position = 1; // base situation is formname[0], so the counter is in position 1.
if ( $this->parent ) {
$parent = $this->parent;
while ( $parent ) {
$html_array_position++; // one more for having a parent (e.g. parent[this][0]).
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- baseline
// phpcs:ignore Universal.Operators.StrictComparisons -- baseline
if ( 1 != $parent->limit ) { // and another for the parent having multiple (e.g. parent[0][this][0]).
$html_array_position++;
}
Expand Down Expand Up @@ -594,26 +594,26 @@ public function element_markup( $values = array() ) {
*/
$out = apply_filters( "fm_element_markup_start_{$this->name}", $out, $this, $values );

// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- baseline
// phpcs:ignore Universal.Operators.StrictComparisons -- baseline
if ( ( 0 == $this->limit || ( $this->limit > 1 && $this->limit > $this->minimum_count ) ) && 'top' == $this->add_more_position ) {
$out .= $this->add_another();
}

// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- baseline
// phpcs:ignore Universal.Operators.StrictComparisons -- baseline
if ( 1 != $this->limit ) {
$out .= $this->single_element_markup( null, true );
}
for ( $i = 0; $i < $max; $i++ ) {
$this->seq = $i;
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- baseline
// phpcs:ignore Universal.Operators.StrictComparisons -- baseline
if ( 1 == $this->limit ) {
$value = $values;
} else {
$value = isset( $values[ $i ] ) ? $values[ $i ] : null;
}
$out .= $this->single_element_markup( $value );
}
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- baseline
// phpcs:ignore Universal.Operators.StrictComparisons -- baseline
if ( ( 0 == $this->limit || ( $this->limit > 1 && $this->limit > $this->minimum_count ) ) && 'bottom' == $this->add_more_position ) {
$out .= $this->add_another();
}
Expand Down Expand Up @@ -715,7 +715,7 @@ public function single_element_markup( $value = null, $is_proto = false ) {
* the title from the tab label.
*/
if ( ! empty( $this->label ) && ! $this->is_tab && $this->one_label_per_item ) {
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- baseline
// phpcs:ignore Universal.Operators.StrictComparisons -- baseline
if ( 1 != $this->limit ) {
$out .= $this->wrap_with_multi_tools( $label, array( 'fmjs-removable-label' ) );
} elseif ( ! $this->label_after_element ) {
Expand All @@ -735,7 +735,7 @@ public function single_element_markup( $value = null, $is_proto = false ) {

$form_element = $this->form_element( $value );

// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- baseline
// phpcs:ignore Universal.Operators.StrictComparisons -- baseline
if ( 1 != $this->limit && ( ! $this->one_label_per_item || empty( $this->label ) ) ) {
$out .= $this->wrap_with_multi_tools( $form_element );
} else {
Expand Down Expand Up @@ -790,7 +790,7 @@ public function wrap_with_multi_tools( $html, $classes = array() ) {
$out .= $html;
$out .= '</div>';

// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- baseline
// phpcs:ignore Universal.Operators.StrictComparisons -- baseline
if ( 0 == $this->limit || $this->limit > $this->minimum_count ) {
$out .= $this->get_remove_handle();
}
Expand All @@ -809,13 +809,13 @@ public function get_form_name( $multiple = '' ) {
$tree = $this->get_form_tree();
$name = '';
foreach ( $tree as $level => $branch ) {
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- baseline
// phpcs:ignore Universal.Operators.StrictComparisons -- baseline
if ( 0 == $level ) {
$name .= $branch->name;
} else {
$name .= '[' . $branch->name . ']';
}
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- baseline
// phpcs:ignore Universal.Operators.StrictComparisons -- baseline
if ( 1 != $branch->limit ) {
$name .= '[' . $branch->get_seq() . ']';
}
Expand Down Expand Up @@ -862,7 +862,7 @@ public function get_element_id() {
public function get_element_key() {
$el = $this;
$key = $el->name;
// phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition -- baseline
// phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition -- baseline
while ( $el = $el->parent ) {
if ( $el->add_to_prefix ) {
$key = "{$el->name}_{$key}";
Expand All @@ -877,7 +877,7 @@ public function get_element_key() {
* @return bool True if yes, false if no.
*/
public function is_repeatable() {
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- baseline
// phpcs:ignore Universal.Operators.StrictComparisons -- baseline
if ( 1 != $this->limit ) {
return true;
} elseif ( $this->parent ) {
Expand Down Expand Up @@ -905,7 +905,7 @@ public function is_group() {
* @return mixed Sanitized values.
*/
public function presave_all( $values, $current_values ) {
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- baseline
// phpcs:ignore Universal.Operators.StrictComparisons -- baseline
if ( 1 == $this->limit && empty( $this->multiple ) ) {
$values = $this->presave_alter_values( array( $values ), array( $current_values ) );
if ( ! empty( $values ) ) {
Expand All @@ -920,7 +920,7 @@ public function presave_all( $values, $current_values ) {
}

// If $this->limit != 1, and $values is not an array, that'd just be wrong, and possibly an attack, so...
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- baseline
// phpcs:ignore Universal.Operators.StrictComparisons -- baseline
if ( 1 != $this->limit && ! is_array( $values ) ) {

// EXCEPT maybe this is a request to remove indices.
Expand Down Expand Up @@ -985,7 +985,7 @@ public function presave_all( $values, $current_values ) {
// Remove empty values.
$values = array_filter(
$values,
function( $value ) {
function ( $value ) {
if ( is_array( $value ) ) {
return ! empty( $value );
} elseif ( null === $value ) {
Expand Down Expand Up @@ -1017,7 +1017,7 @@ function( $value ) {
* @param array $current_values The current values.
*/
protected function save_index( $values, $current_values ) {
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- baseline
// phpcs:ignore Universal.Operators.StrictComparisons -- baseline
if ( 'post' != $this->data_type || empty( $this->data_id ) ) {
return;
}
Expand Down Expand Up @@ -1100,7 +1100,7 @@ protected function presave_alter_values( $values, $current_values = array() ) {
* @param array $current_value The current values.
* @return array The sanitized values.
*/
public function presave( $value, $current_value = array() ) {
public function presave( $value, $current_value = array() ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed -- $current_value is required by the interface and used by subclasses
// It's possible that some elements (Grid is one) would be arrays at
// this point, but those elements must override this function. Let's
// make sure we're dealing with one value here.
Expand Down Expand Up @@ -1416,7 +1416,7 @@ public function _unauthorized_access( $debug_message = '' ) { // phpcs:ignore PS
*/
protected function _failed_validation( $debug_message = '' ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore -- baseline
if ( self::$debug ) {
throw new FM_Validation_Exception( $debug_message );
throw new FM_Validation_Exception( esc_html( $debug_message ) );
} else {
wp_die(
esc_html(
Expand Down
3 changes: 1 addition & 2 deletions php/class-fieldmanager-grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct( $label = '', $options = array() ) {
'size' => '50',
);
parent::__construct( $label, $options );
$this->sanitize = function( $row, $col, $values ) {
$this->sanitize = function ( $row, $col, $values ) {
foreach ( $values as $k => $val ) {
$values[ $k ] = sanitize_text_field( $val );
}
Expand Down Expand Up @@ -116,5 +116,4 @@ public function presave( $value, $current_value = array() ) {
}
return $rows;
}

}
21 changes: 10 additions & 11 deletions php/class-fieldmanager-group.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function __construct( $label = '', $options = array() ) {
parent::__construct( $label, $options );

// Repeatable groups cannot used unserialized data.
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- baseline
// phpcs:ignore Universal.Operators.StrictComparisons -- baseline
$is_repeatable = ( 1 != $this->limit );
if ( ! $this->serialize_data && $is_repeatable ) {
throw new FM_Developer_Exception( esc_html__( 'You cannot use `"serialize_data" => false` with repeating groups', 'fieldmanager' ) );
Expand All @@ -161,9 +161,9 @@ public function __construct( $label = '', $options = array() ) {
// Convenient naming of child elements via their keys.
foreach ( $this->children as $name => $element ) {
// if the array key is not an int, and the name attr is set, and they don't match, we got a problem.
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- baseline
// phpcs:ignore Universal.Operators.StrictComparisons -- baseline
if ( $element->name && ! is_int( $name ) && $element->name != $name ) {
throw new FM_Developer_Exception( esc_html__( 'Group child name conflict: ', 'fieldmanager' ) . $name . ' / ' . $element->name );
throw new FM_Developer_Exception( esc_html( __( 'Group child name conflict: ', 'fieldmanager' ) . $name . ' / ' . $element->name ) );
} elseif ( ! $element->name ) {
$element->name = $name;
}
Expand Down Expand Up @@ -246,25 +246,25 @@ public function form_element( $value = null ) {

// Set default classes to display the first tab content and hide others.
$tab_classes = array( 'fm-tab' );
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- baseline
// phpcs:ignore Universal.Operators.StrictComparisons -- baseline
$tab_classes[] = ( 0 == $this->child_count ) ? 'wp-tab-active' : 'hide-if-no-js';

// Generate output for the tab. Depends on whether or not there is a tab limit in place.
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- baseline
// phpcs:ignore Universal.Operators.StrictComparisons -- baseline
if ( 0 == $this->tab_limit || $this->child_count < $this->tab_limit ) {
$tab_group .= sprintf(
'<li class="%s"><a href="#%s-tab">%s</a></li>',
esc_attr( implode( ' ', $tab_classes ) ),
esc_attr( $element->get_element_id() ),
$element->escape( 'label' )
);
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- baseline
// phpcs:ignore Universal.Operators.StrictComparisons -- baseline
} elseif ( 0 != $this->tab_limit && $this->child_count >= $this->tab_limit ) {
$submenu_item_classes = array( 'fm-submenu-item' );
$submenu_item_link_class = '';

// Create the More tab when first hitting the tab limit.
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- baseline
// phpcs:ignore Universal.Operators.StrictComparisons -- baseline
if ( $this->child_count == $this->tab_limit ) {
// Create the tab.
$tab_group_submenu .= sprintf(
Expand Down Expand Up @@ -325,7 +325,7 @@ public function form_element( $value = null ) {
}

// If the display output for this group is set to tabs, build the tab group for navigation.
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- baseline
// phpcs:ignore Universal.Operators.StrictComparisons -- baseline
if ( 0 != $this->tab_limit && $this->child_count >= $this->tab_limit ) {
$tab_group_submenu .= '</ul></div></div></li>';
}
Expand Down Expand Up @@ -397,7 +397,7 @@ public function presave( $values, $current_values = array() ) {
$child_value = empty( $values[ $element->name ] ) ? null : $values[ $element->name ];
$current_child_value = ! isset( $current_values[ $element->name ] ) ? array() : $current_values[ $element->name ];
$values[ $element->name ] = $element->presave_all( $values[ $element->name ], $current_child_value );
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- baseline
// phpcs:ignore Universal.Operators.StrictComparisons -- baseline
if ( ! $this->save_empty && 1 != $this->limit ) {
if ( is_array( $values[ $element->name ] ) ) {
if ( empty( $values[ $element->name ] ) ) {
Expand Down Expand Up @@ -473,7 +473,7 @@ public function get_element_label( $classes = array() ) {
}

$remove = '';
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- baseline
// phpcs:ignore Universal.Operators.StrictComparisons -- baseline
if ( $this->one_label_per_item && ( 0 == $this->limit || ( $this->limit > 1 && $this->limit > $this->minimum_count ) ) ) {
$remove = $this->get_remove_handle();
}
Expand Down Expand Up @@ -540,5 +540,4 @@ protected function add_meta_boxes_to_remove( &$meta_boxes_to_remove ) {
$child->add_meta_boxes_to_remove( $meta_boxes_to_remove );
}
}

}
Loading
Loading