admin
1 week ago
auto-insert
4 months ago
conditional-logic
6 months ago
execute
5 months ago
generator
6 months ago
lite
9 months ago
capabilities.php
2 years ago
class-wpcode-abilities-api.php
1 week ago
class-wpcode-admin-bar-info.php
2 years ago
class-wpcode-auto-insert.php
4 months ago
class-wpcode-capabilities.php
3 years ago
class-wpcode-conditional-logic.php
4 months ago
class-wpcode-error.php
2 years ago
class-wpcode-file-cache.php
1 year ago
class-wpcode-file-logger.php
1 year ago
class-wpcode-generator.php
4 months ago
class-wpcode-install.php
1 year ago
class-wpcode-library-auth.php
1 year ago
class-wpcode-library.php
1 week ago
class-wpcode-settings.php
6 months ago
class-wpcode-smart-tags.php
11 months ago
class-wpcode-snippet-cache.php
4 months ago
class-wpcode-snippet-execute.php
1 year ago
class-wpcode-snippet.php
1 year ago
compat.php
2 years ago
global-output.php
1 year ago
helpers.php
1 year ago
icons.php
5 months ago
ihaf.php
3 years ago
legacy.php
3 years ago
pluggable.php
2 years ago
post-type.php
1 week ago
safe-mode.php
11 months ago
shortcode.php
2 years ago
shortcode.php
86 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Handle the generic WPCode shortcode. |
| 4 | * |
| 5 | * @package WPCode |
| 6 | */ |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit; |
| 10 | } |
| 11 | |
| 12 | add_shortcode( 'wpcode', 'wpcode_shortcode_handler' ); |
| 13 | add_action( 'wpcode_shortcode_before_output', 'wpcode_pass_shortcode_attributes_to_snippet', 10, 4 ); |
| 14 | |
| 15 | add_filter( 'wpcode_shortcode_attribute_value', 'wp_kses_post' ); |
| 16 | |
| 17 | /** |
| 18 | * Generic handler for the shortcode. |
| 19 | * |
| 20 | * @param array $args The shortcode attributes. |
| 21 | * @param string $content The shortcode content. |
| 22 | * @param string $tag The shortcode tag. |
| 23 | * |
| 24 | * @return string |
| 25 | */ |
| 26 | function wpcode_shortcode_handler( $args, $content, $tag ) { |
| 27 | $atts = wp_parse_args( |
| 28 | $args, |
| 29 | array( |
| 30 | 'id' => 0, |
| 31 | 'wpcode_source' => 'shortcode', |
| 32 | ) |
| 33 | ); |
| 34 | |
| 35 | if ( 0 === $atts['id'] ) { |
| 36 | return ''; |
| 37 | } |
| 38 | |
| 39 | $snippet = new WPCode_Snippet( absint( $atts['id'] ) ); |
| 40 | |
| 41 | if ( ! $snippet->is_active() ) { |
| 42 | return ''; |
| 43 | } |
| 44 | |
| 45 | // Let's check that conditional logic rules are met. |
| 46 | if ( $snippet->conditional_rules_enabled() && ! wpcode()->conditional_logic->are_snippet_rules_met( $snippet ) && apply_filters( 'wpcode_shortcode_use_conditional_logic', true ) ) { |
| 47 | return ''; |
| 48 | } |
| 49 | |
| 50 | $shortcode_location = apply_filters( 'wpcode_get_snippets_for_location', array( $snippet ), 'shortcode' ); |
| 51 | |
| 52 | if ( empty( $shortcode_location ) ) { |
| 53 | return ''; |
| 54 | } |
| 55 | |
| 56 | $snippet->location = $atts['wpcode_source']; |
| 57 | |
| 58 | do_action( 'wpcode_shortcode_before_output', $snippet, $atts, $content, $tag ); |
| 59 | |
| 60 | return wpcode()->execute->get_snippet_output( $snippet ); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Before the shortcode output, let's check if we have to load any shortcode attributes to the class instance. |
| 65 | * |
| 66 | * @param WPCode_Snippet $snippet The snippet instance. |
| 67 | * @param array $atts The shortcode attributes. |
| 68 | * @param string|null $content Shortcode content, if any. |
| 69 | * @param string $tag The shortcode tag. |
| 70 | * |
| 71 | * @return void |
| 72 | */ |
| 73 | function wpcode_pass_shortcode_attributes_to_snippet( $snippet, $atts, $content, $tag ) { |
| 74 | // Let's see if we have to load any shortcode attributes. |
| 75 | $shortcode_attributes = $snippet->get_shortcode_attributes(); |
| 76 | if ( ! empty( $shortcode_attributes ) ) { |
| 77 | foreach ( $shortcode_attributes as $attribute ) { |
| 78 | $value = isset( $atts[ $attribute ] ) ? $atts[ $attribute ] : ''; |
| 79 | $snippet->set_attribute( $attribute, apply_filters( 'wpcode_shortcode_attribute_value', $value, $attribute ) ); |
| 80 | } |
| 81 | } |
| 82 | if ( ! empty( $content ) ) { |
| 83 | $snippet->set_attribute( 'content', $content ); |
| 84 | } |
| 85 | } |
| 86 |