PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.7.3
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.7.3
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 2.7.1 All 27 releases
insert-php / includes / class.snippet.php

class.snippet.php in Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts 2.7.3, at includes/class.snippet.php

80 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Exit if accessed directly
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 class WINP_Snippet {
8
9 protected $id;
10
11 protected $type;
12
13 public function __construct( WP_Post $snippet ) {
14 $this->id = $snippet->ID;
15
16 // todo: to refactor
17 $this->type = WINP_Helper::get_snippet_type( $this->id );
18 }
19
20 public static function get_snippet( $post_id ) {
21 $post_id = (int) $post_id;
22
23 if ( ! $post_id ) {
24 $snippet = get_post( $post_id );
25
26 if ( $snippet ) {
27 return new self( $snippet );
28 }
29 }
30
31 return null;
32 }
33
34 public function is_allowed() {
35 // If the user has prohibited the insertion of unfiltered HTML,
36 // we prohibit the execution of snippets.
37 if ( ( defined( 'DISALLOW_UNFILTERED_HTML' ) && DISALLOW_UNFILTERED_HTML )
38 && ! in_array(
39 $this->type,
40 [
41 WINP_SNIPPET_TYPE_TEXT,
42 WINP_SNIPPET_TYPE_AD,
43 WINP_SNIPPET_TYPE_CSS,
44 ]
45 ) ) {
46 return false;
47 }
48
49 return true;
50 }
51
52 public function get_meta( $key ) {
53 return get_post_meta( $this->id, 'wbcr_inp_' . $key, true );
54 }
55
56 public function get_scope() {
57 return $this->get_meta( 'snippet_scope' );
58 }
59
60 public function get_content() {
61 return $this->get_meta( 'snippet_code' );
62 }
63
64 public function is_active() {
65 // WPML Compatibility
66 if ( defined( 'WPML_PLUGIN_FILE' ) ) {
67 $wpml_langs = $this->get_meta( 'snippet_wpml_lang' );
68
69 if ( $wpml_langs !== '' && defined( 'ICL_LANGUAGE_CODE' ) ) {
70 if ( ! in_array( ICL_LANGUAGE_CODE, explode( ',', $wpml_langs ) ) ) {
71 return false;
72 }
73 }
74 }
75
76 // todo: протестировать
77 return $this->get_meta( 'snippet_activate' );
78 }
79 }
80