Skip to content
Open
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
16 changes: 15 additions & 1 deletion wpuf-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@
*
* @param <type> $post_id
*/
function wpuf_upload_attachment( $post_id ) {

Check warning on line 86 in wpuf-functions.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

The method parameter $post_id is never used
if ( ! isset( $_FILES['wpuf_post_attachments'] ) ) {

Check failure on line 87 in wpuf-functions.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Processing form data without nonce verification.
return false;
}

$fields = (int) wpuf_get_option( 'attachment_num' );

$wpuf_post_attachments = isset( $_FILES['wpuf_post_attachments'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_FILES['wpuf_post_attachments'] ) ) : [];

Check failure on line 93 in wpuf-functions.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Processing form data without nonce verification.

Check failure on line 93 in wpuf-functions.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Processing form data without nonce verification.

for ( $i = 0; $i < $fields; $i++ ) {
$file_name = basename( $wpuf_post_attachments['name'][ $i ] );
Expand Down Expand Up @@ -149,7 +149,7 @@
*
* @author Tareq Hasan
*/
function wpuf_unset_media_tab( $list ) {

Check warning on line 152 in wpuf-functions.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

It is recommended not to use reserved keyword "list" as function parameter name. Found: $list
if ( ! current_user_can( 'edit_posts' ) ) {
unset( $list['library'] );
unset( $list['gallery'] );
Expand Down Expand Up @@ -274,7 +274,7 @@
*
* @uses Walker
*/
class WPUF_Walker_Category_Multi extends Walker {

Check failure on line 277 in wpuf-functions.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

A file should either contain function declarations or OO structure declarations, but not both. Found 137 function declaration(s) and 2 OO structure declaration(s). The first function declaration was found on line 15; the first OO declaration was found on line 277

/**
* @see Walker::$tree_type
Expand Down Expand Up @@ -327,7 +327,7 @@
*
* @since 0.8
*/
class WPUF_Walker_Category_Checklist extends Walker {

Check failure on line 330 in wpuf-functions.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Only one object structure is allowed in a file
public $tree_type = 'category';

public $db_fields = [
Expand Down Expand Up @@ -394,7 +394,7 @@
*
* @since 0.8
*/
function wpuf_category_checklist( $post_id = 0, $selected_cats = false, $attr = [], $class = null ) {

Check warning on line 397 in wpuf-functions.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

It is recommended not to use reserved keyword "class" as function parameter name. Found: $class
require_once ABSPATH . '/wp-admin/includes/template.php';

$walker = new WPUF_Walker_Category_Checklist();
Expand Down Expand Up @@ -479,7 +479,7 @@

if ( ! empty( $attributes ) ) {
foreach ( $attributes as $attr ) {
$terms = get_terms(

Check failure on line 482 in wpuf-functions.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

The parameter "array( 'hide_empty' => false, 'parent' => $attr, )" at position #2 of get_terms() has been deprecated since WordPress version 4.5.0. Instead do not pass the parameter.
$field_settings['name'],
array(
'hide_empty' => false,
Expand Down Expand Up @@ -673,14 +673,28 @@
* @return string
*/
function wpuf_get_custom_avatar( $user_id ) {
// First check for profile photo (higher priority)
$profile_photo = get_user_meta( $user_id, 'wpuf_profile_photo', true );

if ( absint( $profile_photo ) > 0 ) {
wpuf_avatar_add_image_size();

$avatar_source = wp_get_attachment_image_src( $profile_photo, 'wpuf_avatar_image_size' );

if ( $avatar_source && is_array( $avatar_source ) && ! empty( $avatar_source[0] ) ) {
return $avatar_source[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check if it is an array and $avatar_source[0] exists before returning

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done @sapayth vai

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check with empty()

}
}

// Fall back to user avatar if no profile photo
$avatar = get_user_meta( $user_id, 'user_avatar', true );

if ( absint( $avatar ) > 0 ) {
wpuf_avatar_add_image_size();

$avatar_source = wp_get_attachment_image_src( $avatar, 'wpuf_avatar_image_size' );

if ( $avatar_source ) {
if ( $avatar_source && is_array( $avatar_source ) && ! empty( $avatar_source[0] ) ) {
$avatar = $avatar_source[0];
}
}
Expand Down Expand Up @@ -716,7 +730,7 @@
*
* @return string image tag of the user avatar
*/
function wpuf_get_avatar( $avatar, $id_or_email, $size, $default, $alt, $args ) {

Check warning on line 733 in wpuf-functions.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

It is recommended not to use reserved keyword "default" as function parameter name. Found: $default

Check warning on line 733 in wpuf-functions.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

The method parameter $args is never used
if ( wpuf_use_default_avatar() ) {
return $avatar;
}
Expand Down Expand Up @@ -823,7 +837,7 @@
$prev_avatar_path = str_replace( $upload_dir['baseurl'], $upload_dir['basedir'], $prev_avatar );

if ( file_exists( $prev_avatar_path ) ) {
unlink( $prev_avatar_path );

Check warning on line 840 in wpuf-functions.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

unlink() is discouraged. Use wp_delete_file() to delete a file.
}
}

Expand Down Expand Up @@ -951,7 +965,7 @@
$attr['name'] = $attr['input_type'];
}

$field_value = get_post_meta( $post->ID, $attr['name'] );

Check warning on line 968 in wpuf-functions.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

When passing the $key parameter to get_post_meta(), it is recommended to also pass the $single parameter to explicitly indicate whether a single value or multiple values are expected to be returned.
$hide_label = isset( $attr['hide_field_label'] ) ? $attr['hide_field_label'] : 'no';

$return_for_no_cond = 0;
Expand All @@ -977,7 +991,7 @@
if ( isset( $attr['wpuf_cond']['cond_option'][ $field_key ] ) ) {
if ( is_array( $cond_field_value ) ) {
continue;
} else {

Check failure on line 994 in wpuf-functions.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

If control structure block found as the only statement within an "else" block. Use elseif instead.
if ( (string) $attr['wpuf_cond']['cond_option'][ $field_key ] !== (string) $cond_field_value ) {
$return_for_no_cond = 1;
} else {
Expand Down Expand Up @@ -1033,7 +1047,7 @@
}

$full_size = wp_get_attachment_url( $attachment_id );
$path = parse_url( $full_size, PHP_URL_PATH );

Check warning on line 1050 in wpuf-functions.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

parse_url() is discouraged because of inconsistency in the output across PHP versions; use wp_parse_url() instead.
$extension = pathinfo( $path, PATHINFO_EXTENSION );

if ( $thumb ) {
Expand Down Expand Up @@ -1301,7 +1315,7 @@
break;

default:
$value = get_post_meta( $post->ID, $attr['name'] );

Check warning on line 1318 in wpuf-functions.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

When passing the $key parameter to get_post_meta(), it is recommended to also pass the $single parameter to explicitly indicate whether a single value or multiple values are expected to be returned.
$filter_html = apply_filters( 'wpuf_custom_field_render', '', $value, $attr, $form_settings );
$separator = ' | ';

Expand Down Expand Up @@ -1515,7 +1529,7 @@

return ob_get_clean();
} elseif ( 'repeat' === $type ) {
return implode( '; ', get_post_meta( $post->ID, $name ) );

Check warning on line 1532 in wpuf-functions.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

When passing the $key parameter to get_post_meta(), it is recommended to also pass the $single parameter to explicitly indicate whether a single value or multiple values are expected to be returned.
} elseif ( 'normal' === $type ) {
return implode( ', ', get_post_meta( $post->ID, $name ) );
} else {
Expand Down
Loading