PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / trunk
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts vtrunk
2.7.7 2.7.6 2.7.5 2.7.4 trunk 1.3 2.0.4 2.0.6 2.1.91 2.2.4 2.2.7 2.2.9 2.3.1 2.3.10 2.4.10 2.4.2 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.6.0 2.6.1 2.7.0 All 28 releases
← All changes | includes/shortcodes/shortcode-js.php +66 -61 2.4.8trunk View file →
@@ -1,61 +1,66 @@
1 -<?php
2 -/**
3 - * Universal Shortcode
4 - */
5 -
6 -// Exit if accessed directly
7 -if ( ! defined( 'ABSPATH' ) ) {
8 - exit;
9 -}
10 -
11 -class WINP_SnippetShortcodeJs extends WINP_SnippetShortcode {
12 -
13 - public $shortcode_name = 'wbcr_js_snippet';
14 -
15 - /**
16 - * Content render
17 - *
18 - * @param array $attr
19 - * @param string $content
20 - * @param string $tag
21 - */
22 - public function html( $attr, $content, $tag ) {
23 - $id = $this->getSnippetId( $attr, WINP_SNIPPET_TYPE_JS );
24 -
25 - if ( ! $id ) {
26 - echo '<span style="color:red">' . __( '[' . esc_html( $tag ) . ']: PHP snippets error (not passed the snippet ID)', 'insert-php' ) . '</span>';
27 -
28 - return;
29 - }
30 -
31 - $snippet = get_post( $id );
32 - $snippet_meta = get_post_meta( $id, '' );
33 -
34 - if ( ! $snippet || empty( $snippet_meta ) ) {
35 - return;
36 - }
37 -
38 - $attrs = $this->filterAttributes( $attr, $id );
39 -
40 - // Let users pass arbitrary variables, through shortcode attributes.
41 - // @since 2.4.0
42 - $vars = "";
43 - foreach ( $attrs as $var => $value ) {
44 - $vars .= PHP_EOL."var {$var} = \"{$value}\";";
45 - }
46 -
47 -
48 - $is_activate = $this->getSnippetActivate( $snippet_meta );
49 - $snippet_content = $this->getSnippetContent( $snippet, $snippet_meta, $id );
50 - $snippet_scope = $this->getSnippetScope( $snippet_meta );
51 - $is_condition = WINP_Plugin::app()->getExecuteObject()->checkCondition( $id );
52 -
53 - if ( ! $is_activate || empty( $snippet_content ) || $snippet_scope != 'shortcode' || ! $is_condition ) {
54 - return;
55 - }
56 -
57 - echo "<script type='text/javascript'>{$vars}</script>"; //print attributes
58 - echo WINP_Execute_Snippet::getJsCssSnippetData( $id );
59 - }
60 -
61 -}
1 +<?php
2 +/**
3 + * Universal Shortcode
4 + */
5 +
6 +// Exit if accessed directly
7 +if ( ! defined( 'ABSPATH' ) ) {
8 + exit;
9 +}
10 +
11 +class WINP_SnippetShortcodeJs extends WINP_SnippetShortcode {
12 +
13 + public $shortcode_name = 'wbcr_js_snippet';
14 +
15 + /**
16 + * Content render
17 + *
18 + * @param array $attr
19 + * @param string $content
20 + * @param string $tag
21 + */
22 + public function html( $attr, $content, $tag ) {
23 + $id = $this->get_snippet_id( $attr, WINP_SNIPPET_TYPE_JS );
24 +
25 + if ( ! $id ) {
26 + if ( current_user_can( 'manage_options' ) || ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ) {
27 + /* translators: %s: Shortcode tag name */
28 + echo '<span style="color:red">' . sprintf( esc_html__( '[%s]: PHP snippets error (not passed the snippet ID)', 'insert-php' ), esc_html( $tag ) ) . '</span>';
29 + }
30 +
31 + return;
32 + }
33 +
34 + $snippet = get_post( $id );
35 + $snippet_meta = get_post_meta( $id, '' );
36 +
37 + if ( ! $snippet || empty( $snippet_meta ) ) {
38 + return;
39 + }
40 +
41 + $attrs = $this->filter_attributes( $attr, $id );
42 +
43 + // Let users pass arbitrary variables, through shortcode attributes.
44 + // @since 2.4.0
45 + $vars = '';
46 + foreach ( $attrs as $var => $value ) {
47 + $vars .= PHP_EOL . "var {$var} = \"{$value}\";";
48 + }
49 +
50 +
51 + $is_activate = $this->get_snippet_activate( $snippet_meta );
52 + $snippet_content = $this->get_snippet_content( $snippet, $snippet_meta, $id );
53 + $snippet_scope = $this->get_snippet_scope( $snippet_meta );
54 + $is_condition = WINP_Plugin::app()->get_execute_object()->checkCondition( $id );
55 +
56 + if ( ! $is_activate || empty( $snippet_content ) || $snippet_scope != 'shortcode' || ! $is_condition ) {
57 + return;
58 + }
59 +
60 + // Track shortcode execution.
61 + WINP_Plugin::app()->get_execute_object()->track_shortcode_snippet( $id );
62 +
63 + echo "<script type='text/javascript'>{$vars}</script>"; // print attributes
64 + echo WINP_Execute_Snippet::getJsCssSnippetData( $id );
65 + }
66 +}