Below, you’ll find a detailed guide on how to add the Wp Fusion Lite Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Wp Fusion Lite Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the Wp Fusion Lite Plugin and the shortcodes it provides:
"WP Fusion Lite is a streamlined WordPress plugin that integrates your site with powerful marketing automation and CRM systems. Enhance your marketing strategies with ease and efficiency."
- [wpf]
- [wpf_update_tags]
- [wpf_update_meta]
- [wpf_loggedin]
- [wpf_loggedout]
- [wpf_user_can_access]
- [user_meta]
- [user_meta_if]
- [the_excerpt]
Wp Fusion Lite [wpf] Shortcode
The WP Fusion Lite shortcode is a powerful tool for customizing user access. It works by checking user tags and login status to determine content visibility. It can hide content for non-logged in users, and also allows for specific content display based on user tags. It even handles ‘else’ conditions, providing alternative content if the user doesn’t meet the specified criteria. Shortcode: [wpf]
Shortcode: [wpf]
Parameters
Here is a list of all possible wpf shortcode parameters and attributes:
tag
– Specifies the user tags to check for.not
– Specifies the user tags to exclude.method
– Determines how multiple tags are handled.logged_out
– Determines if the content is visible to logged out users.
Examples and Usage
Basic example – A simple implementation of the wpf shortcode to display content for logged in users who have a specific tag
[wpf tag="premium_user"]Premium content for logged in users with the premium_user tag[/wpf]
Advanced examples
Utilizing the shortcode to control content visibility based on user tags. In this example, the content will be displayed for logged in users who have the “premium_user” tag but do not have the “restricted” tag.
[wpf tag="premium_user" not="restricted"]Exclusive content for premium users without the restricted tag[/wpf]
Using the shortcode to display different content for logged in and logged out users. The content within the [else] tags will be displayed for logged out users or users who do not meet the tag conditions.
[wpf tag="premium_user"]Welcome, premium user![else]Please log in to see premium content[/wpf]
Implementing the shortcode to control content visibility based on multiple user tags using the ‘any’ method. The content will be displayed if the logged in user has any of the specified tags.
[wpf tag="premium_user, gold_member, vip" method="any"]Content for users with any of the premium_user, gold_member, or vip tags[/wpf]
PHP Function Code
In case you have difficulties debugging what causing issues with [wpf]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'wpf', array( $this, 'shortcodes' ) );
Shortcode PHP function:
function shortcodes( $atts, $content = '' ) {
if ( ( is_array( $atts ) && in_array( 'logged_out', $atts ) ) || $atts == 'logged_out' ) {
$atts['logged_out'] = true;
}
$atts = shortcode_atts(
array(
'tag' => '',
'not' => '',
'method' => '',
'logged_out' => false,
),
$atts,
'wpf'
);
$atts = array_map( 'sanitize_text_field', $atts );
if ( false !== strpos( $atts['tag'], '“' ) || false !== strpos( $atts['not'], '“' ) ) {
return '<pre>' . esc_html__( 'Oops! Curly quotes were found in a shortcode parameter of the [wpf] shortcode. Curly quotes do not work with shortcode attributes.', 'wp-fusion-lite' ) . '</pre>';
}
// Hide content for non-logged in users.
if ( ! wpf_is_user_logged_in() && false === $atts['logged_out'] ) {
return false;
}
$user_tags = wp_fusion()->user->get_tags();
$user_tags = str_replace( '[', '(', $user_tags );
$user_tags = str_replace( ']', ')', $user_tags );
$proceed_tag = false;
$proceed_not = false;
if ( ! empty( $atts['tag'] ) ) {
$tags = array();
$tags_split = explode( ',', $atts['tag'] );
// Get tag IDs where needed
foreach ( $tags_split as $tag ) {
if ( is_numeric( $tag ) ) {
$tags[] = $tag;
} else {
$tags[] = wp_fusion()->user->get_tag_id( $tag );
}
}
foreach ( $tags as $tag ) {
if ( in_array( $tag, $user_tags ) ) {
$proceed_tag = true;
if ( $atts['method'] == 'any' ) {
break;
}
} else {
$proceed_tag = false;
if ( $atts['method'] != 'any' ) {
break;
}
}
}
// If we're overriding.
if ( get_query_var( 'wpf_tag' ) ) {
if ( in_array( get_query_var( 'wpf_tag' ), $tags ) ) {
$proceed_tag = true;
}
}
} else {
$proceed_tag = true;
}
if ( ! empty( $atts['not'] ) ) {
$tags = array();
$tags_split = explode( ',', $atts['not'] );
// Get tag IDs where needed
foreach ( $tags_split as $tag ) {
if ( is_numeric( $tag ) ) {
$tags[] = $tag;
} else {
$tags[] = wp_fusion()->user->get_tag_id( trim( $tag ) );
}
}
foreach ( $tags as $tag ) {
if ( in_array( $tag, $user_tags ) ) {
$proceed_not = false;
break;
} else {
$proceed_not = true;
}
}
// If we're overriding.
if ( get_query_var( 'wpf_tag' ) ) {
if ( in_array( get_query_var( 'wpf_tag' ), $tags ) ) {
return false;
}
}
} else {
$proceed_not = true;
}
// Check for else condition.
if ( false !== strpos( $content, '[else]' ) ) {
// Clean up old [/else] from pre 3.33.19.
$content = str_replace( '[/else]', '', $content );
$else_content = explode( '[else]', $content );
// Remove the else content from the main content.
$content = $else_content[0];
$else_content = $else_content[1];
}
if ( $proceed_tag == true && $proceed_not == true ) {
$can_access = true;
} else {
$can_access = false;
}
global $post;
// If admins are excluded from restrictions.
if ( wpf_admin_override() ) {
$can_access = true;
}
$can_access = apply_filters( 'wpf_user_can_access', $can_access, wpf_get_current_user_id(), false );
if ( true === $can_access ) {
return do_shortcode( shortcode_unautop( $content ) );
} elseif ( ! empty( $else_content ) ) {
return do_shortcode( shortcode_unautop( $else_content ) );
}
}
Code file location:
wp-fusion-lite/wp-fusion-lite/includes/class-shortcodes.php
Wp Fusion Lite [wpf_update_tags] Shortcode
The WP Fusion Lite plugin shortcode, ‘wpf_update_tags’, primarily checks if the user is logged in and not an admin. It then fetches and updates the user’s tags. This shortcode is a handy tool for managing user tags in WordPress.
Shortcode: [wpf_update_tags]
Examples and Usage
Basic example – The basic usage of the ‘wpf_update_tags’ shortcode does not require any parameters. When placed on a page, it will update the tags for the current logged-in user, provided they are not in the admin area.
[wpf_update_tags /]
Advanced examples
Although the ‘wpf_update_tags’ shortcode does not accept any parameters directly, its functionality can be influenced by other aspects of the WP Fusion Lite plugin. For instance, you can use the ‘wpf_tags_can_edit’ filter to control which tags a user can edit, or the ‘wpf_tags_synced’ action to perform additional operations after a user’s tags have been updated.
Here’s an example of using the ‘wpf_tags_can_edit’ filter. This code would go in your theme’s functions.php file or a custom plugin, not in a shortcode:
add_filter( 'wpf_tags_can_edit', 'my_custom_tags' );
function my_custom_tags( $tags ) {
// Only allow editing of tags with IDs 1, 2, and 3
return array( 1, 2, 3 );
}
And an example of using the ‘wpf_tags_synced’ action. Again, this code would go in your theme’s functions.php file or a custom plugin:
add_action( 'wpf_tags_synced', 'my_custom_action', 10, 2 );
function my_custom_action( $user_id, $user_tags ) {
// Do something after the user's tags have been updated
}
Note that while these examples do not directly modify the ‘wpf_update_tags’ shortcode, they do influence its behavior, providing advanced customization options for developers.
PHP Function Code
In case you have difficulties debugging what causing issues with [wpf_update_tags]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'wpf_update_tags', array( $this, 'shortcode_update_tags' ) );
Shortcode PHP function:
function shortcode_update_tags() {
if ( wpf_is_user_logged_in() && ! is_admin() ) {
wp_fusion()->user->get_tags( wpf_get_current_user_id(), true );
}
return '<!-- wpf_update_tags -->';
}
Code file location:
wp-fusion-lite/wp-fusion-lite/includes/class-shortcodes.php
Wp Fusion Lite [wpf_update_meta] Shortcode
The ‘wpf_update_meta’ shortcode from WP Fusion Lite plugin is designed to update user metadata. This shortcode checks if the user is logged in and not an admin. Upon execution, it pulls the current user’s metadata. If the conditions are met, the shortcode will return an HTML comment indicating successful execution.
Shortcode: [wpf_update_meta]
Examples and Usage
Basic example – A simple usage of the ‘wpf_update_meta’ shortcode that triggers the function when a user is logged in and not in the admin view.
[wpf_update_meta /]
Advanced example – In this example, we’re using the ‘wpf_update_meta’ shortcode within a conditional statement. This will check if a user is logged in and not in the admin view, then execute the function. If these conditions are not met, it will display a custom message.
if ( wpf_is_user_logged_in() && ! is_admin() ) {
echo do_shortcode('[wpf_update_meta /]');
} else {
echo "You need to be logged in to update your metadata.";
}
Please note that the ‘wpf_update_meta’ shortcode doesn’t accept any parameters/attributes. The functionality of this shortcode is determined by the ‘shortcode_update_meta’ function in the WP Fusion Lite plugin. It checks if a user is logged in and not in the admin view, then pulls the user’s metadata.
PHP Function Code
In case you have difficulties debugging what causing issues with [wpf_update_meta]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'wpf_update_meta', array( $this, 'shortcode_update_meta' ) );
Shortcode PHP function:
function shortcode_update_meta() {
if ( wpf_is_user_logged_in() && ! is_admin() ) {
wp_fusion()->user->pull_user_meta( wpf_get_current_user_id() );
}
return '<!-- wpf_update_meta -->';
}
Code file location:
wp-fusion-lite/wp-fusion-lite/includes/class-shortcodes.php
Wp Fusion Lite [wpf_loggedin] Shortcode
The WP Fusion Lite shortcode is a function that checks if a user is logged in. If the user is logged in and there’s content, or if it’s a feed, it returns the content.
Shortcode: [wpf_loggedin]
Examples and Usage
Basic example – A simple usage of the ‘wpf_loggedin’ shortcode. This example checks if the user is logged in. If the user is logged in, it will display the content enclosed within the shortcode.
[wpf_loggedin]Welcome back, valued user![/wpf_loggedin]
Advanced examples
Here, we are using the ‘wpf_loggedin’ shortcode in conjunction with another shortcode. This advanced example checks if the user is logged in. If the user is logged in, it will display a contact form generated by another shortcode.
[wpf_loggedin][contact-form-7 id="1234" title="Contact form 1"][/wpf_loggedin]
In this next advanced example, we are using the ‘wpf_loggedin’ shortcode to conditionally display content based on whether the user is logged in or not. If the user is logged in, it will display a welcome message and a logout link. If the user is not logged in, it will display a login link.
[wpf_loggedin]Welcome back, valued user! Logout[/wpf_loggedin][wpf_loggedout]Login[/wpf_loggedout]
PHP Function Code
In case you have difficulties debugging what causing issues with [wpf_loggedin]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'wpf_loggedin', array( $this, 'shortcode_loggedin' ) );
Shortcode PHP function:
function shortcode_loggedin( $atts, $content = null ) {
if ( ( wpf_is_user_logged_in() && ! is_null( $content ) ) || is_feed() ) {
return do_shortcode( $content );
}
}
Code file location:
wp-fusion-lite/wp-fusion-lite/includes/class-shortcodes.php
Wp Fusion Lite [wpf_loggedout] Shortcode
The WP-Fusion-Lite shortcode ‘wpf_loggedout’ is used to display content only to logged-out users. It checks if a user is logged in or not, and if not, it executes the enclosed content.
Shortcode: [wpf_loggedout]
Examples and Usage
Basic example – The following shortcode example demonstrates how to use the ‘wpf_loggedout’ shortcode to display content only to logged out users.
[wpf_loggedout]Welcome, guest! Please log in to see more.[/wpf_loggedout]
Advanced examples
1. Using the shortcode to display different messages to logged out users and feed readers. The content inside the shortcode will be shown only to logged out users, while the content in the ‘else’ attribute will be shown to feed readers.
[wpf_loggedout else="This content is for feed readers."]Welcome, guest! Please log in to see more.[/wpf_loggedout]
2. Using the shortcode to display a login form to logged out users. The login form shortcode is nested inside the ‘wpf_loggedout’ shortcode, so it will only be shown to users who are not logged in.
[wpf_loggedout][login_form][/wpf_loggedout]
PHP Function Code
In case you have difficulties debugging what causing issues with [wpf_loggedout]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'wpf_loggedout', array( $this, 'shortcode_loggedout' ) );
Shortcode PHP function:
function shortcode_loggedout( $atts, $content = null ) {
if ( ( ! wpf_is_user_logged_in() && ! is_null( $content ) ) || is_feed() ) {
return do_shortcode( $content );
}
}
Code file location:
wp-fusion-lite/wp-fusion-lite/includes/class-shortcodes.php
Wp Fusion Lite [wpf_user_can_access] Shortcode
The WP Fusion Lite shortcode, ‘wpf_user_can_access’, is designed to manage user access. It checks if a user has access to specific content. If the user has access, it returns the content; if not, it returns an alternate content if provided. It also allows admins to override restrictions.
Shortcode: [wpf_user_can_access]
Parameters
Here is a list of all possible wpf_user_can_access shortcode parameters and attributes:
id
– Specifies the unique ID of the post or page.
Examples and Usage
Basic example – A simple usage of the shortcode to check if a user can access the current post or page.
[wpf_user_can_access /]
Advanced examples
Using the shortcode to check if a user can access a specific post or page by providing the ID.
[wpf_user_can_access id=123 /]
Using the shortcode to display different content based on whether a user can access a specific post or page. If the user can access the post, it will display “You can access this post”. If the user cannot access the post, it will display “Sorry, you cannot access this post”.
[wpf_user_can_access id=123]You can access this post[else]Sorry, you cannot access this post[/wpf_user_can_access]
PHP Function Code
In case you have difficulties debugging what causing issues with [wpf_user_can_access]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'wpf_user_can_access', array( $this, 'shortcode_user_can_access' ) );
Shortcode PHP function:
function shortcode_user_can_access( $atts, $content = '' ) {
$defaults = array(
'id' => false,
);
$atts = shortcode_atts( $defaults, $atts, 'wpf_user_can_access' );
if ( false === $atts['id'] ) {
$atts['id'] = get_the_ID();
} else {
$atts['id'] = absint( $atts['id'] );
}
// Check for else condition.
if ( false !== strpos( $content, '[else]' ) ) {
$else_content = explode( '[else]', $content );
// Remove the else content from the main content.
$content = $else_content[0];
$else_content = $else_content[1];
}
$can_access = wp_fusion()->access->user_can_access( $atts['id'] );
// If admins are excluded from restrictions.
if ( wpf_admin_override() ) {
$can_access = true;
}
$can_access = apply_filters( 'wpf_user_can_access', $can_access, wpf_get_current_user_id(), $atts['id'] );
if ( true == $can_access ) {
return do_shortcode( shortcode_unautop( $content ) );
} elseif ( ! empty( $else_content ) ) {
return do_shortcode( shortcode_unautop( $else_content ) );
}
}
Code file location:
wp-fusion-lite/wp-fusion-lite/includes/class-shortcodes.php
Wp Fusion Lite [user_meta] Shortcode
The WP Fusion Lite shortcode ‘user_meta’ retrieves and displays user metadata. It’s flexible, allowing for various parameters like ‘field’, ‘date-format’, ‘format’, ‘timezone-offset’, and ‘sync_if_empty’. The shortcode fetches data directly from the user’s profile if logged in. If the ‘field’ parameter is empty or the user isn’t logged in, it returns the content within the shortcode. Shortcode: [user_meta] It also handles date formatting and timezone offsets. If the value is empty and not numeric, it returns the content within the shortcode; otherwise, it returns the value. Shortcode: [user_meta]
Shortcode: [user_meta]
Parameters
Here is a list of all possible user_meta shortcode parameters and attributes:
field
– Specifies the user field to displaydate-format
– Defines the format for date fieldsformat
– Determines the format for the output valuetimezone-offset
– Adjusts the time for timezone differencessync_if_empty
– If set to true, pulls data from CRM if the field is empty
Examples and Usage
Basic example – Showcases the usage of the shortcode to fetch user meta based on the field parameter.
[user_meta field="first_name" /]
Advanced examples
Display user meta with a specific date format. This will fetch the user’s registration date and display it in the format specified.
[user_meta field="user_registered" date-format="F j, Y" /]
Sync user meta from CRM if the field value is empty. This will fetch the user’s bio from the CRM if it’s not already available in the WordPress user meta.
[user_meta field="bio" sync_if_empty=true /]
Display user meta with a specific format and timezone offset. This will fetch the user’s registration date, convert it to the specified timezone, and display it in the format specified.
[user_meta field="user_registered" date-format="F j, Y" timezone-offset="-5" /]
Fetch and display user meta with the first letter of each word capitalized. This will fetch the user’s bio and capitalize the first letter of each word.
[user_meta field="bio" format="ucwords" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [user_meta]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'user_meta', array( $this, 'shortcode_user_meta' ) );
Shortcode PHP function:
function shortcode_user_meta( $atts, $content = null ) {
$atts = shortcode_atts(
array(
'field' => '',
'date-format' => '',
'format' => '',
'timezone-offset' => '0',
'sync_if_empty' => false,
),
$atts
);
$atts = array_map( 'sanitize_text_field', $atts );
if ( false !== strpos( $atts['field'], '“' ) || false !== strpos( $atts['format'], '“' ) ) {
return '<pre>' . esc_html__( 'Oops! Curly quotes were found in a shortcode parameter of the [user_meta] shortcode. Curly quotes do not work with shortcode attributes.', 'wp-fusion-lite' ) . '</pre>';
}
if ( empty( $atts['field'] ) ) {
return;
}
if ( ! wpf_is_user_logged_in() ) {
return do_shortcode( $content );
}
if ( 'user_id' === $atts['field'] ) {
$atts['field'] = 'ID';
}
$user_id = wpf_get_current_user_id();
$user_data = get_userdata( $user_id );
if ( is_object( $user_data ) && property_exists( $user_data->data, $atts['field'] ) ) {
$value = $user_data->data->{$atts['field']};
} else {
$value = get_user_meta( $user_id, $atts['field'], true );
}
// Maybe refresh the data once from the CRM if the key doesn't exist at all.
if ( empty( $value ) && $atts['sync_if_empty'] && ! did_action( 'wpf_user_updated' ) && wp_fusion()->crm->is_field_active( $atts['field'] ) ) {
if ( ! metadata_exists( 'user', $user_id, $atts['field'] ) ) {
if ( ! empty( wp_fusion()->user->get_contact_id() ) ) {
$user_meta = wp_fusion()->user->pull_user_meta();
if ( isset( $user_meta[ $atts['field'] ] ) ) {
$value = $user_meta[ $atts['field'] ];
}
}
}
}
$value = apply_filters( 'wpf_user_meta_shortcode_value', $value, $atts['field'] );
// Prevent array-to-string conversion warnings when this value is an array.
if ( is_array( $value ) ) {
$value = implode( ', ', $value );
}
if ( ! empty( $atts['date-format'] ) && ! empty( $value ) ) {
if ( ! is_numeric( $value ) ) {
$value = strtotime( $value );
}
if ( ! empty( $atts['timezone-offset'] ) ) {
$value += intval( $atts['timezone-offset'] ) * HOUR_IN_SECONDS;
}
// At this point the date is in GMT, let's switch it to local timezone for display.
$value = date_i18n( $atts['date-format'], $value );
}
if ( 'ucwords' === $atts['format'] ) {
$value = ucwords( $value );
}
if ( empty( $value ) && ! is_numeric( $value ) ) {
return do_shortcode( $content );
} else {
return $value;
}
}
Code file location:
wp-fusion-lite/wp-fusion-lite/includes/class-shortcodes.php
Wp Fusion Lite [user_meta_if] Shortcode
The WP-Fusion-Lite shortcode ‘user_meta_if’ is a dynamic tool for customizing content based on user meta data. It fetches user meta data and compares it with specified values to determine content visibility. It sanitizes input, checks for invalid characters, and handles various comparison operators. In case of matching conditions, it reveals the content, otherwise, it remains hidden.
Shortcode: [user_meta_if]
Parameters
Here is a list of all possible user_meta_if shortcode parameters and attributes:
field
– Specifies the user meta field to be checked.field_format
– Defines the format for the value from meta.value
– The value to compare the user’s meta value with.value_format
– The format for the value we enter.compare
– Determines the operator used in comparison.
Examples and Usage
Basic example – Display content if the user’s meta field “membership_level” equals “Gold”
[user_meta_if field="membership_level" value="Gold"]Your exclusive Gold Membership content here[/user_meta_if]
Advanced examples
Display different content based on the user’s membership level. If the level is “Gold”, show exclusive content. If the level is “Silver”, show different content.
[user_meta_if field="membership_level" value="Gold"]Your exclusive Gold Membership content here[/user_meta_if]
[user_meta_if field="membership_level" value="Silver"]Your exclusive Silver Membership content here[/user_meta_if]
Checking the user’s age and display content if the user is over 18. The shortcode assumes that the user’s age is stored in a meta field called “user_age”.
[user_meta_if field="user_age" compare=">" value="18"]Content for users over 18[/user_meta_if]
Display content if the user’s meta field “course_completed” is not empty.
[user_meta_if field="course_completed" compare="NOT EMPTY"]Congratulations on completing the course![/user_meta_if]
PHP Function Code
In case you have difficulties debugging what causing issues with [user_meta_if]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'user_meta_if', array( $this, 'shortcode_user_meta_if' ) );
Shortcode PHP function:
function shortcode_user_meta_if( $atts, $content = null ) {
$atts = shortcode_atts(
array(
'field' => '',
'field_format' => '', // format for the value from meta.
'value' => '',
'value_format' => 'strval', // format for the value we enter.
'compare' => '=',
),
$atts,
'user_meta_if'
);
$atts = array_map( 'sanitize_text_field', $atts );
// Check for curly quotes.
foreach ( $atts as $att ) {
if ( false !== strpos( $att, '“' ) ) {
return '<pre>' . esc_html__( 'Oops! Curly quotes were found in a shortcode parameter of the [usermeta_if] shortcode. Curly quotes do not work with shortcode attributes.', 'wp-fusion-lite' ) . '</pre>';
}
}
$user_id = wpf_get_current_user_id();
if ( ! $user_id ) {
return '';
}
if ( ! $atts['field'] ) {
return '';
}
$user_meta = wp_fusion()->user->get_user_meta( $user_id );
if ( isset( $user_meta[ $atts['field'] ] ) ) {
$meta_value = $user_meta[ $atts['field'] ];
} else {
$meta_value = '';
}
$meta_value = $atts['field_format'] ? call_user_func( $atts['field_format'], $meta_value ) : $meta_value;
$value = $atts['value_format'] ? call_user_func( $atts['value_format'], $atts['value'] ) : $atts['value'];
if ( 'strtotime' === $atts['field_format'] && false === $meta_value ) {
return sprintf( wp_kses_post( 'Oops! Your input string to the <code>%s</code> attribute was not successfully <a href="https://www.php.net/manual/en/function.strtotime.php" target="_blank">parsed by <code>strtotime()</code></a>.', 'wp-fusion-lite' ), 'userfield' );
} elseif ( 'strtotime' === $atts['value_format'] && false === $value ) {
return sprintf( wp_kses_post( 'Oops! Your input string to the <code>%s</code> attribute was not successfully <a href="https://www.php.net/manual/en/function.strtotime.php" target="_blank">parsed by <code>strtotime()</code></a>.', 'wp-fusion-lite' ), 'value' );
}
$atts['compare'] = wp_specialchars_decode( $atts['compare'] );
$show_content = false;
switch ( $atts['compare'] ) {
case '<':
$show_content = $meta_value < $value;
break;
case '<=':
$show_content = $meta_value <= $value;
break;
case '>':
$show_content = $meta_value > $value;
break;
case '>=':
$show_content = $meta_value >= $value;
break;
case 'IN':
if ( is_array( $meta_value ) ) {
$value = explode( ',', $value );
$value = array_intersect( $meta_value, $value );
if ( empty( $value ) ) {
$show_content = false;
} else {
$show_content = true;
}
} else {
$value = explode( ',', $value );
foreach ( $value as $search ) {
if ( false !== strpos( $meta_value, trim( $search ) ) ) {
$show_content = true;
break;
}
}
}
break;
case 'NOT IN':
if ( is_array( $meta_value ) ) {
$value = explode( ',', $value );
$value = array_map( 'trim', $value );
$value = array_intersect( $meta_value, $value );
if ( empty( $value ) ) {
$show_content = true;
} else {
$show_content = false;
}
} else {
$value = explode( ',', $value );
foreach ( $value as $search ) {
if ( false !== strpos( trim( $meta_value ), trim( $search ) ) ) {
$show_content = false;
break;
} else {
$show_content = true;
}
}
}
break;
case 'ALL':
if ( is_array( $meta_value ) ) {
$value = explode( ',', $value );
$value = array_map( 'trim', $value );
if ( count( $value ) === count( $meta_value ) ) {
$value = array_diff( $meta_value, $value );
if ( empty( $value ) ) {
$show_content = true;
}
}
} else {
$value = explode( ',', $value );
$value = array_map( 'trim', $value );
$meta_value = explode( ',', $meta_value );
$meta_value = array_map( 'trim', $meta_value );
if ( count( $value ) === count( $meta_value ) ) {
$value = array_diff( $meta_value, $value );
if ( empty( $value ) ) {
$show_content = true;
} else {
$show_content = false;
}
}
}
break;
case 'EMPTY':
$show_content = empty( $meta_value );
break;
case 'NOT EMPTY':
$show_content = ! empty( $meta_value );
break;
case '!=':
$show_content = $meta_value !== $value;
break;
default:
$show_content = $meta_value === $value;
break;
}
if ( ! $show_content ) {
return '';
}
return do_shortcode( $content );
}
Code file location:
wp-fusion-lite/wp-fusion-lite/includes/class-shortcodes.php
Wp Fusion Lite [the_excerpt] Shortcode
The WP-Fusion Lite shortcode ‘the_excerpt’ modifies the length of the post excerpt. It prevents looping by returning false if the ‘get_the_excerpt’ filter is running. It sanitizes the ‘length’ attribute, adds a unique filter to change the excerpt length if specified, retrieves the excerpt, and then removes the filter.
Shortcode: [the_excerpt]
Parameters
Here is a list of all possible the_excerpt shortcode parameters and attributes:
length
– Determines the length of the excerpt displayed
Examples and Usage
Basic example – Displays the excerpt of the current post without any modifications.
[the_excerpt /]
Advanced examples
Displaying the excerpt of the current post with a custom length. The ‘length’ attribute allows you to specify the number of words you want to include in the excerpt. In the following example, the excerpt will be limited to 50 words.
[the_excerpt length=50 /]
Using the shortcode to modify the excerpt length dynamically. In this advanced example, the length of the excerpt is set based on a custom field value. If the custom field is not set or empty, the default length will be used.
[the_excerpt length="[custom_field key='excerpt_length']" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [the_excerpt]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'the_excerpt', array( $this, 'shortcode_the_excerpt' ) );
Shortcode PHP function:
function shortcode_the_excerpt( $atts ) {
if ( doing_filter( 'get_the_excerpt' ) ) {
return false; // prevent looping.
}
$atts = shortcode_atts(
array(
'length' => '',
),
$atts,
'the_excerpt'
);
$atts = array_map( 'sanitize_text_field', $atts );
if ( ! empty( $atts['length'] ) ) {
// Possibly modify the excerpt length.
$length = $atts['length'];
add_filter(
'excerpt_length',
function() use ( &$length ) {
return $length;
},
4242 // 4242 so it's hopefully unique when we remove it.
);
}
$excerpt = get_the_excerpt();
// Remove the filter.
remove_all_filters( 'excerpt_length', 4242 );
return $excerpt;
}
Code file location:
wp-fusion-lite/wp-fusion-lite/includes/class-shortcodes.php
Conclusion
Now that you’ve learned how to embed the Wp Fusion Lite Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply