diff --git a/includes/functions/_acf.php b/includes/functions/_acf.php index 1ba0c52e..461bd4ec 100644 --- a/includes/functions/_acf.php +++ b/includes/functions/_acf.php @@ -120,7 +120,9 @@ if ( FICTIONEER_FILTER_STORY_CHAPTERS ) { function fictioneer_update_post_relationships( $post_id ) { // Only posts... - if ( get_post_type( $post_id ) != 'post' ) return; + if ( get_post_type( $post_id ) != 'post' ) { + return; + } // Setup $registry = fictioneer_get_relationship_registry(); @@ -144,13 +146,17 @@ function fictioneer_update_post_relationships( $post_id ) { // Check for and remove outdated direct references foreach ( $registry as $key => $entry ) { // Skip if... - if ( absint( $key ) < 1 || ! is_array( $entry ) || in_array( $key, $featured ) ) continue; + if ( absint( $key ) < 1 || ! is_array( $entry ) || in_array( $key, $featured ) ) { + continue; + } // Unset if in array unset( $registry[ $key ][ $post_id ] ); // Remove node if empty - if ( empty( $registry[ $key ] ) ) unset( $registry[ $key ] ); + if ( empty( $registry[ $key ] ) ) { + unset( $registry[ $key ] ); + } } // Update database diff --git a/includes/functions/_admin.php b/includes/functions/_admin.php index 737756d2..3e2a4421 100644 --- a/includes/functions/_admin.php +++ b/includes/functions/_admin.php @@ -121,13 +121,17 @@ if ( ! function_exists( 'fictioneer_check_for_updates' ) ) { curl_close( $ch ); // Abort if request failed - if ( empty( $response ) ) return false; + if ( empty( $response ) ) { + return false; + } // Decode JSON to array $release = json_decode( $response, true ); // Abort if request did not return expected data - if ( ! isset( $release['tag_name'] ) ) return false; + if ( ! isset( $release['tag_name'] ) ) { + return false; + } // Remember latest version update_option( 'fictioneer_latest_version', $release['tag_name'] ); @@ -151,10 +155,14 @@ function fictioneer_admin_update_notice() { $is_updates_page = $pagenow == 'update-core.php'; // Show only once every n seconds - if ( $last_notice + FICTIONEER_UPDATE_CHECK_TIMEOUT > time() && ! $is_updates_page ) return; + if ( $last_notice + FICTIONEER_UPDATE_CHECK_TIMEOUT > time() && ! $is_updates_page ) { + return; + } // Update? - if ( ! fictioneer_check_for_updates() ) return; + if ( ! fictioneer_check_for_updates() ) { + return; + } // Render notice $message = sprintf( @@ -410,7 +418,9 @@ if ( ! function_exists( 'fictioneer_convert_taxonomies' ) ) { foreach ( $items as $item ) { $source_tax = get_the_terms( $item, $source ); - if ( ! $source_tax ) continue; + if ( ! $source_tax ) { + continue; + } $source_tax = array_map( 'terms_to_array', $source_tax ); diff --git a/includes/functions/_api.php b/includes/functions/_api.php index 4d7cde4d..2195563f 100644 --- a/includes/functions/_api.php +++ b/includes/functions/_api.php @@ -21,7 +21,9 @@ if ( ! function_exists( 'fictioneer_api_get_story_node' ) ) { $data = fictioneer_get_story_data( $story_id, false ); // Does not refresh comment count! // Abort if... - if ( empty( $data ) ) return false; + if ( empty( $data ) ) { + return false; + } // Setup $author_id = get_post_field( 'post_author', $story_id ); @@ -131,7 +133,9 @@ if ( ! function_exists( 'fictioneer_api_get_story_node' ) ) { $chapter_id = get_the_ID(); // Skip not visible chapters - if ( fictioneer_get_field( 'fictioneer_chapter_hidden' ) ) continue; + if ( fictioneer_get_field( 'fictioneer_chapter_hidden' ) ) { + continue; + } // Data $author_id = get_the_author_meta( 'id' ); diff --git a/includes/functions/_content_helpers.php b/includes/functions/_content_helpers.php index 5288067b..8b8f0c6c 100644 --- a/includes/functions/_content_helpers.php +++ b/includes/functions/_content_helpers.php @@ -106,7 +106,9 @@ if ( ! function_exists( 'fictioneer_get_forced_excerpt' ) ) { function fictioneer_get_forced_excerpt( $post_id, $limit = 256, $default = false ) { $post = get_post( $post_id ); - if ( ! $default && $post->post_excerpt != '' ) return $post->post_excerpt; + if ( ! $default && $post->post_excerpt != '' ) { + return $post->post_excerpt; + } $excerpt = $post->post_content; $excerpt = preg_replace( ' (\[.*?\])', '', $excerpt ); @@ -397,13 +399,17 @@ if ( ! function_exists( 'fictioneer_get_breadcrumbs' ) ) { ! is_array( $args['breadcrumbs'] ) || count( $args['breadcrumbs'] ) < 1 || is_front_page() - ) return ''; + ) { + return ''; + } // Setup $count = count( $args['breadcrumbs'] ); // Abort if array does not have two or more items - if ( $count < 2 ) return ''; + if ( $count < 2 ) { + return ''; + } // Filter breadcrumbs array $args['breadcrumbs'] = apply_filters( 'fictioneer_filter_breadcrumbs_array', $args['breadcrumbs'], $args ); @@ -1001,14 +1007,18 @@ if ( ! function_exists( 'fictioneer_get_taxonomy_pills' ) ) { function fictioneer_get_taxonomy_pills( $taxonomy_groups, $classes = '' ) { // Abort conditions - if ( ! is_array( $taxonomy_groups ) || count( $taxonomy_groups ) < 1) return ''; + if ( ! is_array( $taxonomy_groups ) || count( $taxonomy_groups ) < 1) { + return ''; + } ob_start(); // Loop over all groups... foreach ( $taxonomy_groups as $group ) { // Check for empty group - if ( ! $group || ! is_array( $group ) || count( $group ) < 1 ) continue; + if ( ! $group || ! is_array( $group ) || count( $group ) < 1 ) { + continue; + } // Process group foreach ( $group as $taxonomy ) { @@ -1040,7 +1050,9 @@ if ( ! function_exists( 'fictioneer_get_rss_link' ) ) { function fictioneer_get_rss_link( $post_type = null, $post_id = null ) { // Abort conditions - if ( ! get_option( 'fictioneer_enable_theme_rss' ) ) return false; + if ( ! get_option( 'fictioneer_enable_theme_rss' ) ) { + return false; + } // Setup $post_type = $post_type ? $post_type : get_post_type(); @@ -1345,7 +1357,9 @@ if ( ! function_exists( 'fictioneer_get_card_controls' ) ) { $menu = apply_filters( 'fictioneer_filter_card_control_menu', $menu, $story_id, $chapter_id ); // Abort if... - if ( count( $icons ) < 1 || count( $menu ) < 1 ) return ''; + if ( count( $icons ) < 1 || count( $menu ) < 1 ) { + return ''; + } ob_start(); // Start HTML ---> ?> diff --git a/includes/functions/_customizer.php b/includes/functions/_customizer.php index 42669a29..4d03aea3 100644 --- a/includes/functions/_customizer.php +++ b/includes/functions/_customizer.php @@ -213,7 +213,9 @@ if ( ! function_exists( 'fictioneer_hsl_code' ) ) { function fictioneer_hsl_code( $hex, $output = 'default' ) { $hsl_array = fictioneer_rgb_to_hsl( fictioneer_hex_to_rgb( $hex ), 2 ); - if ( $output == 'values' ) return "$hsl_array[0] $hsl_array[1] $hsl_array[2]"; + if ( $output == 'values' ) { + return "$hsl_array[0] $hsl_array[1] $hsl_array[2]"; + } $deg = 'calc(' . $hsl_array[0] . 'deg + var(--hue-rotate))'; $saturation = 'calc(' . $hsl_array[1] . '% * var(--saturation))'; @@ -221,7 +223,9 @@ if ( ! function_exists( 'fictioneer_hsl_code' ) ) { $max = $hsl_array[2] + (100 - $hsl_array[2]) / 2; $lightness = 'clamp('. $min . '%, ' . $hsl_array[2] . '% * var(--darken), ' . $max . '%)'; - if ( $output == 'free' ) return "$deg $saturation $lightness"; + if ( $output == 'free' ) { + return "$deg $saturation $lightness"; + } return "hsl($deg $saturation $lightness)"; } diff --git a/includes/functions/_epub.php b/includes/functions/_epub.php index da2d4cbc..49f92237 100644 --- a/includes/functions/_epub.php +++ b/includes/functions/_epub.php @@ -36,7 +36,9 @@ if ( ! function_exists( 'fictioneer_download_epub' ) ) { $story_id = $story_id ? $story_id : get_query_var( FICTIONEER_EPUB_ENDPOINT, null ); // Abort if... - if ( is_null( $story_id ) ) return; + if ( is_null( $story_id ) ) { + return; + } // Validate story ID again $story_id = fictioneer_validate_id( $story_id, 'fcn_story' ); @@ -243,7 +245,9 @@ if ( ! function_exists( 'fictioneer_add_epub_cover' ) ) { function fictioneer_add_epub_cover( $dir, $epub_dir, $story_id ) { // Abort if the story has no cover image... - if ( ! has_post_thumbnail( $story_id ) ) return; + if ( ! has_post_thumbnail( $story_id ) ) { + return; + } // Setup $path_parts = pathinfo( get_the_post_thumbnail_url( $story_id, 'full' ) ); @@ -444,7 +448,9 @@ if ( ! function_exists( 'fictioneer_add_epub_chapters' ) ) { $alt = urldecode( $img->getAttribute( 'alt' ) ); // Abort if... - if ( ! $url ) continue; + if ( ! $url ) { + continue; + } // Prepare path (remove unwanted extensions, e.g. '.jpg?_i=AA') $path_parts = pathinfo( $url ); @@ -525,7 +531,9 @@ if ( ! function_exists( 'fictioneer_add_epub_chapters' ) ) { } // Terminate script if no chapter has been added - if ( $index == 0 ) exit(); + if ( $index == 0 ) { + exit; + } // Return lists return array( @@ -580,7 +588,7 @@ if ( ! function_exists( 'fictioneer_generate_epub_opf' ) ) { $guide = $opf->getElementsByTagName( 'guide' )->item( 0 ); // Cover node (if any) - if( has_post_thumbnail( $story_id ) ) { + if ( has_post_thumbnail( $story_id ) ) { $path_parts = pathinfo( get_the_post_thumbnail_url( $story_id, 'full' ) ); $path_extension = isset( $path_parts['extension'] ) ? $path_parts['extension'] : 'jpg'; $extension = preg_replace( '/(?<=\.jpg|jpeg|png|gif|webp|svg|avif|apng).+/', '', '.' . $path_extension ); @@ -960,7 +968,9 @@ function fictioneer_generate_epub() { $story_id = get_query_var( FICTIONEER_EPUB_ENDPOINT, null ); // Abort if this is not an /download-epub/ URL... - if ( is_null( $story_id ) ) return; + if ( is_null( $story_id ) ) { + return; + } // Abort if no story ID provided or ePUB download is disabled... if ( @@ -1088,7 +1098,9 @@ function fictioneer_generate_epub() { $zip->addFile( $mimetype_path, substr( $mimetype_path, strlen( $directory ) + 1) ); foreach ( $files as $name => $file ) { - if ( $name == 'mimetype' ) continue; + if ( $name == 'mimetype' ) { + continue; + } if ( ! $file->isDir() ) { $filePath = $file->getRealPath(); diff --git a/includes/functions/_forms.php b/includes/functions/_forms.php index 58e1bc33..608e8a8c 100644 --- a/includes/functions/_forms.php +++ b/includes/functions/_forms.php @@ -122,7 +122,9 @@ function fictioneer_ajax_submit_contact_form() { $field_label = sanitize_text_field( $_POST[ "check_label_$i" ] ?? '' ); // Skip if label is missing - if ( empty( $field_label ) ) continue; + if ( empty( $field_label ) ) { + continue; + } // Strip HTML for good measure $field_label = wp_strip_all_tags( $field_label ); diff --git a/includes/functions/_oauth.php b/includes/functions/_oauth.php index b984c184..669ba369 100644 --- a/includes/functions/_oauth.php +++ b/includes/functions/_oauth.php @@ -179,7 +179,9 @@ if ( ! function_exists( 'fictioneer_get_oauth_links' ) ) { function fictioneer_handle_oauth() { // Check whether this is the OAuth2 route - if ( is_null( get_query_var( FICTIONEER_OAUTH_ENDPOINT, null ) ) ) return; + if ( is_null( get_query_var( FICTIONEER_OAUTH_ENDPOINT, null ) ) ) { + return; + } // Setup fictioneer_set_oauth_constants(); @@ -864,8 +866,12 @@ if ( ! function_exists( 'fictioneer_get_oauth_client_credentials' ) ) { */ function fictioneer_get_oauth_client_credentials( $channel, $type = 'id' ) { - if ( ! $channel ) return null; + if ( ! $channel ) { + return null; + } + $it = get_option( "fictioneer_{$channel}_client_{$type}" ); + return $it ? $it : null; } } diff --git a/includes/functions/_seo.php b/includes/functions/_seo.php index aa5ded80..c7011197 100644 --- a/includes/functions/_seo.php +++ b/includes/functions/_seo.php @@ -314,7 +314,10 @@ if ( ! function_exists( 'fictioneer_get_seo_title' ) ) { // Cached title? $cache = get_post_meta( $post_id, 'fictioneer_seo_title_cache', true ); - if ( ! empty( $cache ) && ! $skip_cache ) return $cache; + + if ( ! empty( $cache ) && ! $skip_cache ) { + return $cache; + } // Start building... $seo_title = get_post_meta( $post_id, 'fictioneer_seo_title', true ); @@ -470,7 +473,10 @@ if ( ! function_exists( 'fictioneer_get_seo_description' ) ) { // Cached description? $cache = get_post_meta( $post_id, 'fictioneer_seo_description_cache', true ); - if ( ! empty( $cache ) && ! $skip_cache ) return $cache; + + if ( ! empty( $cache ) && ! $skip_cache ) { + return $cache; + } // Start building... $seo_description = get_post_meta( $post_id, 'fictioneer_seo_description', true ); @@ -549,7 +555,10 @@ if ( ! function_exists( 'fictioneer_get_seo_image' ) ) { // Cached image? Except for site default, which can globally change! if ( ! $use_default ) { $cache = get_post_meta( $post_id, 'fictioneer_seo_og_image_cache', true ); - if ( $cache ) return $cache; + + if ( $cache ) { + return $cache; + } } // Get image ID if not yet set diff --git a/includes/functions/_shortcodes.php b/includes/functions/_shortcodes.php index 912c48a5..d5dd7e02 100644 --- a/includes/functions/_shortcodes.php +++ b/includes/functions/_shortcodes.php @@ -270,7 +270,9 @@ function fictioneer_get_shortcode_tax_query( $args ) { function fictioneer_shortcode_showcase( $attr ) { // Abort if... - if ( empty( $attr['for'] ) ) return ''; + if ( empty( $attr['for'] ) ) { + return ''; + } // Setup $count = max( 1, intval( $attr['count'] ?? 8 ) ); diff --git a/includes/functions/_sitemap.php b/includes/functions/_sitemap.php index c88ff204..4b65dcf9 100644 --- a/includes/functions/_sitemap.php +++ b/includes/functions/_sitemap.php @@ -108,7 +108,11 @@ function fictioneer_create_sitemap( $last_saved_id ) { foreach( $pages as $post ) { $template = get_page_template_slug( $post->ID ); - if ( in_array( $template, ['user-profile.php', 'single-bookmarks.php'] ) ) continue; + + if ( in_array( $template, ['user-profile.php', 'single-bookmarks.php'] ) ) { + continue; + } + $frequency = 'yearly'; $lastmod = get_the_modified_date( 'c', $post->ID ); $sitemap .= fictioneer_url_node( get_permalink( $post->ID ), $lastmod, 'yearly' ); diff --git a/includes/functions/_theme_setup.php b/includes/functions/_theme_setup.php index b880fd12..f452e9f1 100644 --- a/includes/functions/_theme_setup.php +++ b/includes/functions/_theme_setup.php @@ -722,7 +722,9 @@ add_action( 'wp_enqueue_scripts', 'fictioneer_load_script_translations', 99 ); function fictioneer_remove_jquery_migrate( $scripts ) { // Abort if... - if ( ! isset( $scripts->registered['jquery'] ) ) return; + if ( ! isset( $scripts->registered['jquery'] ) ) { + return; + } // Setup $script = $scripts->registered['jquery']; diff --git a/includes/functions/_utility.php b/includes/functions/_utility.php index caa7d470..65772926 100644 --- a/includes/functions/_utility.php +++ b/includes/functions/_utility.php @@ -6,18 +6,20 @@ if ( ! function_exists( 'fictioneer_url_exists' ) ) { /** - * Checks whether an URL exists. + * Checks whether an URL exists * * @since Fictioneer 4.0 - * @link https://www.geeksforgeeks.org/how-to-check-the-existence-of-url-in-php/ + * @link https://www.geeksforgeeks.org/how-to-check-the-existence-of-url-in-php/ * * @param string $url The URL to check. * - * @return boolean True if the URL exists and false otherwise. + * @return boolean True if the URL exists and false otherwise. Probably. */ function fictioneer_url_exists( $url ) { - if ( ! $url ) return false; + if ( ! $url ) { + return false; + } $curl = curl_init( $url ); curl_setopt( $curl, CURLOPT_NOBODY, true ); @@ -512,7 +514,7 @@ if ( ! function_exists( 'fictioneer_shorten_number' ) ) { if ( ! function_exists( 'fictioneer_validate_id' ) ) { /** * Ensures an ID is a valid integer and positive; optionally checks whether the - * associated post is of a certain types (or among an array of types). + * associated post is of a certain types (or among an array of types) * * @since Fictioneer 4.7 * @@ -625,37 +627,6 @@ if ( ! function_exists( 'fictioneer_replace_key_value' ) ) { // CHECK USER CAPABILITIES // ============================================================================= -if ( ! function_exists( 'fictioneer_has_role' ) ) { - /** - * Checks if an user has a specific role - * - * @since Fictioneer 5.0 - * - * @param WP_User|int $user The user object or ID to check. - * @param string $role The role to check for. - * - * @return boolean To be or not to be. - */ - - function fictioneer_has_role( $user, $role ) { - // Setup - $user = is_int( $user ) ? get_user_by( 'ID', $user ) : $user; - - // Abort conditions - if ( ! $user || ! $role ) { - return false; - } - - // Check if user has role... - if ( in_array( $role, (array) $user->roles ) ) { - return true; - } - - // Else... - return false; - } -} - if ( ! function_exists( 'fictioneer_is_admin' ) ) { /** * Checks if an user is an administrator @@ -873,7 +844,10 @@ if ( ! function_exists( 'fictioneer_get_consent' ) && get_option( 'fictioneer_co */ function fictioneer_get_consent() { - if ( ! isset( $_COOKIE['fcn_cookie_consent'] ) || $_COOKIE['fcn_cookie_consent'] === '' ) return false; + if ( ! isset( $_COOKIE['fcn_cookie_consent'] ) || $_COOKIE['fcn_cookie_consent'] === '' ) { + return false; + } + return strval( $_COOKIE['fcn_cookie_consent'] ); } } @@ -883,23 +857,37 @@ if ( ! function_exists( 'fictioneer_get_consent' ) && get_option( 'fictioneer_co // ============================================================================= /** - * Sanitizes an integer with options for default, minimum, and maximum + * Sanitizes an integer with options for default, minimum, and maximum. * * @since 4.0 * - * @param int $value The integer to be sanitized. - * @param int $default Default value if an invalid integer. Default 0. - * @param int|boolean $minimum Optional. Minimum value of the integer. Default false. - * @param int|boolean $maximum Optional. Maximum value of the integer. Default false. + * @param mixed $value The value to be sanitized. + * @param int $default Default value if an invalid integer is provided. Default 0. + * @param int $min Optional. Minimum value for the integer. Default is no minimum. + * @param int $max Optional. Maximum value for the integer. Default is no maximum. * * @return int The sanitized integer. */ -function fictioneer_sanitize_integer( $value, $default = 0, $minimum = false, $maximum = false ) { +function fictioneer_sanitize_integer( $value, $default = 0, $min = null, $max = null ) { + // Ensure $value is numeric in the first place + if ( ! is_numeric( $value ) ) { + return $default; + } + + // Cast to integer $value = (int) $value; - if ( ! is_int( $value ) ) $value = $default; - if ( $minimum !== false ) $value = max( $value, $minimum ); - if ( $maximum !== false ) $value = min( $value, $maximum ); + + // Apply minimum limit if specified + if ( $min !== null && $value < $min ) { + return $min; + } + + // Apply maximum limit if specified + if ( $max !== null && $value > $max ) { + return $max; + } + return $value; } @@ -996,6 +984,7 @@ function fictioneer_ajax_get_auth() { ) ); } + if ( get_option( 'fictioneer_enable_ajax_authentication' ) ) { add_action( 'wp_ajax_fictioneer_ajax_get_auth', 'fictioneer_ajax_get_auth' ); add_action( 'wp_ajax_nopriv_fictioneer_ajax_get_auth', 'fictioneer_ajax_get_auth' ); diff --git a/includes/functions/_wordpress_mods.php b/includes/functions/_wordpress_mods.php index 99e73b95..5be413e4 100644 --- a/includes/functions/_wordpress_mods.php +++ b/includes/functions/_wordpress_mods.php @@ -62,7 +62,7 @@ if ( get_option( 'fictioneer_enable_sitemap' ) && ! fictioneer_seo_plugin_active function fictioneer_custom_excerpt_length( $length ) { return 64; } -add_filter( 'excerpt_length', 'fictioneer_custom_excerpt_length', 999 ); +add_filter( 'excerpt_length', 'fictioneer_custom_excerpt_length' ); // ============================================================================= // FIX EXCERPT FORMATTING @@ -571,12 +571,16 @@ function fictioneer_add_lightbox_to_post_images( $content ) { if ( str_contains( $classes . $parent_classes, 'no-auto-lightbox' ) || $parent->hasAttribute( 'target' ) - ) continue; + ) { + continue; + } if ( $parent->hasAttribute( 'href' ) && ! preg_match( '/(?<=\.jpg|jpeg|png|gif|webp|svg|avif|apng|tiff|ico)(?:$|[#?])/', $parent_href ) - ) continue; + ) { + continue; + } $src = $img->getAttribute( 'src' ); $id = preg_match( '/wp-image-([0-9]+)/i', $classes, $class_id ); @@ -680,7 +684,9 @@ if ( get_option( 'fictioneer_remove_wp_svg_filters' ) ) { */ function fictioneer_embed_consent_wrappers( $content ) { - if( empty( $content ) ) return $content; + if ( empty( $content ) ) { + return $content; + } libxml_use_internal_errors( true ); $dom = new DOMDocument(); diff --git a/includes/functions/comments/_comments_form.php b/includes/functions/comments/_comments_form.php index a208c57d..0ef7ed78 100644 --- a/includes/functions/comments/_comments_form.php +++ b/includes/functions/comments/_comments_form.php @@ -18,7 +18,9 @@ if ( ! function_exists( 'fictioneer_get_comment_toolbar' ) ) { if ( ! get_option( 'fictioneer_enable_comment_toolbar' ) || get_option( 'fictioneer_disable_comment_bbcodes' ) - ) return ''; + ) { + return ''; + } ob_start(); // Start HTML ---> ?> diff --git a/includes/functions/comments/_comments_moderation.php b/includes/functions/comments/_comments_moderation.php index 72369338..43c79cd2 100644 --- a/includes/functions/comments/_comments_moderation.php +++ b/includes/functions/comments/_comments_moderation.php @@ -336,7 +336,9 @@ if ( ! function_exists( 'fictioneer_get_comment_action_link' ) ) { $comment_id = fictioneer_validate_id( $comment_id ); // Validation - if ( ! $comment_id ) return false; + if ( ! $comment_id ) { + return false; + } // Data $template = '%2$s'; diff --git a/includes/functions/comments/_comments_threads.php b/includes/functions/comments/_comments_threads.php index ac639c96..1fa8d880 100644 --- a/includes/functions/comments/_comments_threads.php +++ b/includes/functions/comments/_comments_threads.php @@ -19,7 +19,9 @@ function fictioneer_comment_login_to_reply( $link, $args, $comment, $post ) { // Return default if OAuth authentication is disabled - if ( ! get_option( 'fictioneer_enable_oauth' ) ) return $link; + if ( ! get_option( 'fictioneer_enable_oauth' ) ) { + return $link; + } // Reply link or login modal toggle if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) { diff --git a/includes/functions/hooks/_chapter_hooks.php b/includes/functions/hooks/_chapter_hooks.php index f1a240bd..021c34cf 100644 --- a/includes/functions/hooks/_chapter_hooks.php +++ b/includes/functions/hooks/_chapter_hooks.php @@ -100,7 +100,9 @@ function fictioneer_chapter_foreword( $args ) { $foreword = fictioneer_get_content_field( 'fictioneer_chapter_foreword', $args['chapter_id'] ); // Abort conditions - if ( empty( $foreword ) || post_password_required() ) return ''; + if ( empty( $foreword ) || post_password_required() ) { + return ''; + } // Start HTML ---> ?> @@ -126,7 +128,9 @@ function fictioneer_chapter_warnings( $args ) { $warning_notes = fictioneer_get_field( 'fictioneer_chapter_warning_notes', $args['chapter_id'] ); // Abort conditions - if ( ( ! $warning && ! $warning_notes ) || post_password_required() ) return ''; + if ( ( ! $warning && ! $warning_notes ) || post_password_required() ) { + return ''; + } // Start HTML ---> ?> @@ -354,7 +358,9 @@ add_action( 'fictioneer_chapter_actions_bottom_center', 'fictioneer_chapter_inde function fictioneer_chapter_bookmark_jump_button() { // Check if available - if ( ! get_option( 'fictioneer_enable_bookmarks' ) ) return; + if ( ! get_option( 'fictioneer_enable_bookmarks' ) ) { + return; + } // Start HTML ---> ?> @@ -405,7 +411,9 @@ function fictioneer_chapter_afterword( $args ) { $afterword = fictioneer_get_content_field( 'fictioneer_chapter_afterword', $args['chapter_id'] ); // ACF formatted output // Abort conditions - if ( empty( $afterword ) || post_password_required() ) return ''; + if ( empty( $afterword ) || post_password_required() ) { + return ''; + } // Start HTML ---> ?> @@ -500,7 +508,9 @@ function fictioneer_chapter_support_links( $args ) { $support_links = apply_filters( 'fictioneer_filter_chapter_support_links', $support_links, $args ); // Abort if no support links - if ( count( $support_links ) < 1 ) return; + if ( count( $support_links ) < 1 ) { + return; + } // Support message $support_message = get_the_author_meta( 'fictioneer_support_message', $author_id ) ? get_the_author_meta( 'fictioneer_support_message', $author_id ) : __( 'You can support the author on', 'fictioneer' ); @@ -614,7 +624,9 @@ add_action( 'fictioneer_chapter_after_main', 'fictioneer_chapter_paragraph_tools function fictioneer_chapter_suggestion_tools() { // Abort if... - if ( fictioneer_get_field( 'fictioneer_disable_commenting' ) || ! comments_open() ) return; + if ( fictioneer_get_field( 'fictioneer_disable_commenting' ) || ! comments_open() ) { + return; + } // Start HTML ---> ?> diff --git a/includes/functions/hooks/_recommendation_hooks.php b/includes/functions/hooks/_recommendation_hooks.php index 14c31745..4ec1c418 100644 --- a/includes/functions/hooks/_recommendation_hooks.php +++ b/includes/functions/hooks/_recommendation_hooks.php @@ -146,7 +146,9 @@ function fictioneer_recommendation_links( $args ) { $links = fictioneer_get_field( 'fictioneer_recommendation_urls', $args['recommendation_id'] ); // Abort conditions... - if ( ! $links ) return; + if ( ! $links ) { + return; + } // Prepare $links = array_filter( explode( "\n", $links ) ); @@ -188,7 +190,9 @@ function fictioneer_recommendation_support_links( $args ) { $links = fictioneer_get_field( 'fictioneer_recommendation_support', $args['recommendation_id'] ); // Abort conditions... - if ( ! $links ) return; + if ( ! $links ) { + return; + } // Prepare $links = array_filter( explode( "\n", $links ) ); diff --git a/includes/functions/schemas/_chapter_schema.php b/includes/functions/schemas/_chapter_schema.php index 512a2059..720cd1b5 100644 --- a/includes/functions/schemas/_chapter_schema.php +++ b/includes/functions/schemas/_chapter_schema.php @@ -53,7 +53,9 @@ if ( ! function_exists( 'fictioneer_build_chapter_schema' ) ) { function fictioneer_build_chapter_schema( $post_id ) { // Abort if... - if ( ! $post_id ) return ''; + if ( ! $post_id ) { + return ''; + } // Setup $schema = fictioneer_get_schema_node_root(); diff --git a/includes/functions/schemas/_chapters_schema.php b/includes/functions/schemas/_chapters_schema.php index 9ed7ba34..d603cadf 100644 --- a/includes/functions/schemas/_chapters_schema.php +++ b/includes/functions/schemas/_chapters_schema.php @@ -66,7 +66,9 @@ if ( ! function_exists( 'fictioneer_build_chapters_schema' ) ) { function fictioneer_build_chapters_schema( $post_id ) { // Abort if... - if ( ! $post_id ) return ''; + if ( ! $post_id ) { + return ''; + } // Prepare query arguments $query_args = array ( diff --git a/includes/functions/schemas/_collections_schema.php b/includes/functions/schemas/_collections_schema.php index f202c42b..c76ed926 100644 --- a/includes/functions/schemas/_collections_schema.php +++ b/includes/functions/schemas/_collections_schema.php @@ -66,7 +66,9 @@ if ( ! function_exists( 'fictioneer_build_collections_schema' ) ) { function fictioneer_build_collections_schema( $post_id ) { // Abort if... - if ( ! $post_id ) return ''; + if ( ! $post_id ) { + return ''; + } // Prepare query arguments $query_args = array ( diff --git a/includes/functions/schemas/_post_schema.php b/includes/functions/schemas/_post_schema.php index b121859e..5381737f 100644 --- a/includes/functions/schemas/_post_schema.php +++ b/includes/functions/schemas/_post_schema.php @@ -49,7 +49,9 @@ if ( ! function_exists( 'fictioneer_build_post_schema' ) ) { function fictioneer_build_post_schema( $post_id ) { // Abort if... - if ( ! $post_id ) return ''; + if ( ! $post_id ) { + return ''; + } // Setup $schema = fictioneer_get_schema_node_root(); diff --git a/includes/functions/schemas/_recommendation_schema.php b/includes/functions/schemas/_recommendation_schema.php index f8d134c4..7d641078 100644 --- a/includes/functions/schemas/_recommendation_schema.php +++ b/includes/functions/schemas/_recommendation_schema.php @@ -49,7 +49,9 @@ if ( ! function_exists( 'fictioneer_build_recommendation_schema' ) ) { function fictioneer_build_recommendation_schema( $post_id ) { // Abort if... - if ( ! $post_id ) return ''; + if ( ! $post_id ) { + return ''; + } // Setup $schema = fictioneer_get_schema_node_root(); diff --git a/includes/functions/schemas/_recommendations_schema.php b/includes/functions/schemas/_recommendations_schema.php index 7c328fc8..5919387f 100644 --- a/includes/functions/schemas/_recommendations_schema.php +++ b/includes/functions/schemas/_recommendations_schema.php @@ -66,7 +66,9 @@ if ( ! function_exists( 'fictioneer_build_recommendations_schema' ) ) { function fictioneer_build_recommendations_schema( $post_id ) { // Abort if... - if ( ! $post_id ) return ''; + if ( ! $post_id ) { + return ''; + } // Prepare query arguments $query_args = array ( diff --git a/includes/functions/schemas/_stories_schema.php b/includes/functions/schemas/_stories_schema.php index 7e49818b..eab6d331 100644 --- a/includes/functions/schemas/_stories_schema.php +++ b/includes/functions/schemas/_stories_schema.php @@ -66,7 +66,9 @@ if ( ! function_exists( 'fictioneer_build_stories_schema' ) ) { function fictioneer_build_stories_schema( $post_id ) { // Abort if... - if ( ! $post_id ) return ''; + if ( ! $post_id ) { + return ''; + } // Prepare query arguments $query_args = array ( diff --git a/includes/functions/schemas/_story_schema.php b/includes/functions/schemas/_story_schema.php index 10970f7c..4539e79c 100644 --- a/includes/functions/schemas/_story_schema.php +++ b/includes/functions/schemas/_story_schema.php @@ -59,7 +59,9 @@ if ( ! function_exists( 'fictioneer_build_story_schema' ) ) { function fictioneer_build_story_schema( $post_id ) { // Abort if... - if ( ! $post_id ) return ''; + if ( ! $post_id ) { + return ''; + } // Setup $schema = fictioneer_get_schema_node_root(); diff --git a/includes/functions/settings/_register_settings.php b/includes/functions/settings/_register_settings.php index 04c3170d..1920049a 100644 --- a/includes/functions/settings/_register_settings.php +++ b/includes/functions/settings/_register_settings.php @@ -1043,7 +1043,9 @@ function fictioneer_validate_phrase_cookie_consent_banner( $input ) { $default = __( 'We use cookies to enhance your browsing experience, serve personalized content, and analyze our traffic. Some features are not available without, but you can limit the site to strictly necessary cookies only. See Privacy Policy.', 'fictioneer' ); // Return default if input is empty - if ( ! is_string( $input ) ) return $default; + if ( ! is_string( $input ) ) { + return $default; + } // Temporarily allow tabindex attribute $allowedtags['a']['tabindex'] = []; diff --git a/includes/functions/users/_user_data.php b/includes/functions/users/_user_data.php index 893e509e..eee7bdd6 100644 --- a/includes/functions/users/_user_data.php +++ b/includes/functions/users/_user_data.php @@ -229,7 +229,9 @@ function fictioneer_update_my_user_profile( $updated_user_id ) { $sender_is_owner = $sender_id === $updated_user_id; // Make sure the sender is the profile owner unless it's an administrator - if ( ! $sender_is_owner && ! $sender_is_admin ) return false; + if ( ! $sender_is_owner && ! $sender_is_admin ) { + return false; + } // Profile flags... if ( $sender_is_owner || $sender_is_admin ) { diff --git a/partials/_archive-loop.php b/partials/_archive-loop.php index 0e4dc6c2..31986331 100644 --- a/partials/_archive-loop.php +++ b/partials/_archive-loop.php @@ -61,12 +61,18 @@ $hook_args = array( ); // Cached? - if ( fictioneer_caching_active() && ! fictioneer_private_caching_active() ) $card_args['cache'] = true; + if ( fictioneer_caching_active() && ! fictioneer_private_caching_active() ) { + $card_args['cache'] = true; + } // Special conditions for chapters... if ( $type == 'fcn_chapter' ) { - if ( fictioneer_get_field( 'fictioneer_chapter_no_chapter' ) ) continue; - if ( fictioneer_get_field( 'fictioneer_chapter_hidden' ) ) continue; + if ( + fictioneer_get_field( 'fictioneer_chapter_no_chapter' ) || + fictioneer_get_field( 'fictioneer_chapter_hidden' ) + ) { + continue; + } } // Echo correct card diff --git a/partials/_card-collection.php b/partials/_card-collection.php index 8fcd506a..4700a793 100644 --- a/partials/_card-collection.php +++ b/partials/_card-collection.php @@ -109,8 +109,12 @@ if ( ! empty( $items ) ) { if ( ! empty( $chapters ) ) { foreach ( $chapters as $chapter ) { - if ( fictioneer_get_field( 'fictioneer_chapter_no_chapter', $chapter->ID ) ) continue; - if ( fictioneer_get_field( 'fictioneer_chapter_hidden', $chapter->ID ) ) continue; + if ( + fictioneer_get_field( 'fictioneer_chapter_no_chapter', $chapter->ID ) || + fictioneer_get_field( 'fictioneer_chapter_hidden', $chapter->ID ) + ) { + continue; + } if ( ! in_array( $chapter->ID, $processed_ids ) ) { $chapter_count += 1; diff --git a/partials/_latest-recommendations.php b/partials/_latest-recommendations.php index 12a9648f..77531c21 100644 --- a/partials/_latest-recommendations.php +++ b/partials/_latest-recommendations.php @@ -95,7 +95,9 @@ $entries = fictioneer_shortcode_query( $query_args ); $urls = array_filter( $urls ); // Abort if no links found - if ( empty( $urls ) ) continue; + if ( empty( $urls ) ) { + continue; + } // Extract first link $url = $urls[0]; diff --git a/partials/_latest-updates-compact.php b/partials/_latest-updates-compact.php index b2419460..8100405e 100644 --- a/partials/_latest-updates-compact.php +++ b/partials/_latest-updates-compact.php @@ -96,19 +96,26 @@ $entries = fictioneer_shortcode_query( $query_args ); $chapter_title; // Set inside inner loop // Skip if no chapters - if ( $story['chapter_count'] < 1 ) continue; + if ( $story['chapter_count'] < 1 ) { + continue; + } // Search for viable chapters... $search_list = array_reverse( $story['chapter_ids'] ); foreach ( $search_list as $chapter_id ) { - if ( fictioneer_get_field( 'fictioneer_chapter_hidden', $chapter_id ) ) continue; + if ( fictioneer_get_field( 'fictioneer_chapter_hidden', $chapter_id ) ) { + continue; + } + $chapter_list[] = $chapter_id; break; // Only one needed } // No viable chapters - if ( count( $chapter_list ) < 1 ) continue; + if ( count( $chapter_list ) < 1 ) { + continue; + } // Count actually rendered cards to account for buffer if ( ++$card_counter > $args['count'] ) break; diff --git a/partials/_latest-updates.php b/partials/_latest-updates.php index 2a4bd35e..515945cf 100644 --- a/partials/_latest-updates.php +++ b/partials/_latest-updates.php @@ -96,22 +96,34 @@ $entries = fictioneer_shortcode_query( $query_args ); $chapter_list = []; // Skip if no chapters - if ( $story['chapter_count'] < 1 ) continue; + if ( $story['chapter_count'] < 1 ) { + continue; + } // Search for viable chapters... $search_list = array_reverse( $story['chapter_ids'] ); foreach ( $search_list as $chapter_id ) { - if ( fictioneer_get_field( 'fictioneer_chapter_hidden', $chapter_id ) ) continue; + if ( fictioneer_get_field( 'fictioneer_chapter_hidden', $chapter_id ) ) { + continue; + } + $chapter_list[] = $chapter_id; - if ( count( $chapter_list ) > 1 ) break; // Max two + + if ( count( $chapter_list ) > 1 ) { + break; // Max two + } } // No viable chapters - if ( count( $chapter_list ) < 1 ) continue; + if ( count( $chapter_list ) < 1 ) { + continue; + } // Count actually rendered cards to account for buffer - if ( ++$card_counter > $args['count'] ) break; + if ( ++$card_counter > $args['count'] ) { + break; + } ?> diff --git a/partials/_story-content.php b/partials/_story-content.php index f02c1f5a..0c60b057 100644 --- a/partials/_story-content.php +++ b/partials/_story-content.php @@ -115,7 +115,9 @@ $disable_folding = fictioneer_get_field( 'fictioneer_story_disable_collapse' ); $index = 1; foreach ( $tab_pages as $page ) { - if ( empty( $page[1] ) ) continue; + if ( empty( $page[1] ) ) { + continue; + } ?> @@ -171,7 +173,9 @@ $disable_folding = fictioneer_get_field( 'fictioneer_story_disable_collapse' ); $chapter_id = get_the_ID(); // Skip not visible chapters (redundant for paranoia) - if ( fictioneer_get_field( 'fictioneer_chapter_hidden' ) ) continue; + if ( fictioneer_get_field( 'fictioneer_chapter_hidden' ) ) { + continue; + } // Data $group = fictioneer_get_field( 'fictioneer_chapter_group' ); diff --git a/partials/account/_danger-zone.php b/partials/account/_danger-zone.php index c880b7bd..b46f3fd3 100644 --- a/partials/account/_danger-zone.php +++ b/partials/account/_danger-zone.php @@ -23,7 +23,9 @@ defined( 'ABSPATH' ) OR exit; $current_user = $args['user']; // Do not show for roles above subscriber -if ( ! current_user_can( 'fcn_allow_self_delete' ) ) return; +if ( ! current_user_can( 'fcn_allow_self_delete' ) ) { + return; +} ?> diff --git a/repo/graveyard/discarded.php b/repo/graveyard/discarded.php index 108365b5..d4db3fa0 100644 --- a/repo/graveyard/discarded.php +++ b/repo/graveyard/discarded.php @@ -631,5 +631,39 @@ if ( get_option( 'fictioneer_enable_bookmarks' ) ) { add_action( 'wp_ajax_fictioneer_ajax_get_bookmarks', 'fictioneer_ajax_get_bookmarks' ); } +// ============================================================================= +// CHECK USER CAPABILITIES +// ============================================================================= + +if ( ! function_exists( 'fictioneer_has_role' ) ) { + /** + * Checks if an user has a specific role + * + * @since Fictioneer 5.0 + * + * @param WP_User|int $user The user object or ID to check. + * @param string $role The role to check for. + * + * @return boolean To be or not to be. + */ + + function fictioneer_has_role( $user, $role ) { + // Setup + $user = is_int( $user ) ? get_user_by( 'ID', $user ) : $user; + + // Abort conditions + if ( ! $user || ! $role ) { + return false; + } + + // Check if user has role... + if ( in_array( $role, (array) $user->roles ) ) { + return true; + } + + // Else... + return false; + } +} ?> diff --git a/searchform.php b/searchform.php index f66b6c48..ad57070e 100644 --- a/searchform.php +++ b/searchform.php @@ -211,7 +211,9 @@ if ( $show_advanced ) { foreach ( $queried_terms as $quad ) { // Skip if nothing has been queried - if ( empty( $quad[0] ) ) continue; + if ( empty( $quad[0] ) ) { + continue; + } // Open wrapper echo "";