PluginProbe
Advanced WordPress Backgrounds / 1.12.10
Advanced WordPress Backgrounds v1.12.10
1.13.0 1.12.11 1.12.10 trunk 1.11.5 1.12.0 1.12.1 1.12.2 1.12.3 1.12.4 1.12.5 1.12.6 1.12.7 1.12.8 1.12.9 1.2.4 1.3.2 1.7.7
advanced-backgrounds / advanced-backgrounds.php

advanced-backgrounds.php in Advanced WordPress Backgrounds 1.12.10, at advanced-backgrounds.php

204 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Advanced WordPress Backgrounds
4 * Description: Parallax, Video, Images Backgrounds
5 * Version: 1.12.10
6 * Plugin URI: https://wpbackgrounds.com/?utm_source=wordpress.org&utm_medium=readme&utm_campaign=byline
7 * Author: Advanced WordPress Backgrounds Team
8 * Author URI: https://wpbackgrounds.com/?utm_source=wordpress.org&utm_medium=readme&utm_campaign=byline
9 * License: GPLv2 or later
10 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
11 * Text Domain: advanced-backgrounds
12 *
13 * @package advanced-backgrounds
14 */
15
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit;
18 }
19
20
21 /**
22 * Class NK_AWB
23 */
24 class NK_AWB {
25 /**
26 * The single class instance.
27 *
28 * @var $instance
29 */
30 private static $instance = null;
31
32 /**
33 * Main Instance
34 * Ensures only one instance of this class exists in memory at any one time.
35 */
36 public static function instance() {
37 if ( is_null( self::$instance ) ) {
38 self::$instance = new self();
39 self::$instance->init();
40 }
41 return self::$instance;
42 }
43
44 /**
45 * Path to the plugin directory
46 *
47 * @var $plugin_path
48 */
49 public $plugin_path;
50
51 /**
52 * URL to the plugin directory
53 *
54 * @var $plugin_url
55 */
56 public $plugin_url;
57
58 /**
59 * NK_AWB constructor.
60 */
61 public function __construct() {
62 /* We do nothing here! */
63 }
64
65 /**
66 * Init
67 */
68 public function init() {
69 $this->plugin_path = plugin_dir_path( __FILE__ );
70 $this->plugin_url = plugin_dir_url( __FILE__ );
71
72 // include helper files.
73 $this->include_dependencies();
74
75 // init classes.
76 new NK_AWB_Rest();
77 new NK_AWB_Shortcode();
78 new NK_AWB_VC_Extend();
79 new NK_AWB_TinyMCE();
80 new NK_AWB_Gutenberg();
81
82 // Hooks.
83 add_action( 'init', array( $this, 'init_hook' ) );
84 add_action( 'init', array( $this, 'register_scripts' ) );
85 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
86 add_action( 'ghostkit_parse_blocks', array( $this, 'parse_ghostkit_blocks' ) );
87 add_action( 'wp_enqueue_scripts', array( $this, 'fix_youtube_embed_plus_plugin' ), 101 );
88 }
89
90 /**
91 * Init hook
92 */
93 public function init_hook() {
94 // register images sizes.
95 $this->add_image_sizes();
96
97 // load textdomain.
98 load_plugin_textdomain( 'advanced-backgrounds', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
99 }
100
101 /**
102 * Register scripts that will be used in the future when portfolio will be printed.
103 */
104 public function register_scripts() {
105 wp_register_script( 'jarallax', nk_awb()->plugin_url . 'assets/vendor/jarallax/dist/jarallax.min.js', array(), '3.0.0', true );
106 wp_register_script( 'jarallax-video', nk_awb()->plugin_url . 'assets/vendor/jarallax/dist/jarallax-video.min.js', array( 'jarallax' ), '3.0.0', true );
107 wp_register_script( 'awb', nk_awb()->plugin_url . 'assets/awb/awb.min.js', array( 'jarallax', 'jarallax-video' ), '1.12.10', true );
108
109 wp_localize_script(
110 'awb',
111 'AWB',
112 array(
113 'version' => '1.12.10',
114 'settings' => array(
115 'disable_parallax' => array_keys( AWB_Settings::get_option( 'disable_parallax', 'awb_general', array() ) ? AWB_Settings::get_option( 'disable_parallax', 'awb_general', array() ) : array() ),
116 'disable_video' => array_keys( AWB_Settings::get_option( 'disable_video', 'awb_general', array() ) ? AWB_Settings::get_option( 'disable_video', 'awb_general', array() ) : array() ),
117 'full_width_fallback' => ! ( ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) || get_theme_support( 'align-wide' ) ),
118 ),
119 )
120 );
121
122 wp_register_style( 'awb', nk_awb()->plugin_url . 'assets/awb/awb.min.css', array(), '1.12.10' );
123 }
124
125 /**
126 * Enqueue scripts.
127 */
128 public function enqueue_scripts() {
129 // add styles to header to fix image jumping when use shortcode.
130 wp_enqueue_style( 'awb' );
131 }
132
133 /**
134 * Enqueue awb assets when used Ghost Kit grid or Column.
135 *
136 * @param array $blocks - block list.
137 */
138 public function parse_ghostkit_blocks( $blocks ) {
139 foreach ( $blocks as $block ) {
140 if ( 'ghostkit/grid-column' === $block['blockName'] || 'ghostkit/grid' === $block['blockName'] ) {
141 wp_enqueue_script( 'awb' );
142 wp_enqueue_style( 'awb' );
143 }
144 }
145 }
146
147 /**
148 * Fix for YouTube Embed Plus plugin.
149 * https://wordpress.org/support/topic/video-does-not-loop/#post-10102519
150 */
151 public function fix_youtube_embed_plus_plugin() {
152 wp_add_inline_script(
153 '__ytprefs__',
154 '(function () {
155 if (window._EPYT_ && window._EPYT_.evselector) {
156 var selectors = window._EPYT_.evselector.split(", ");
157 window._EPYT_.evselector = "";
158
159 for (var k = 0; k < selectors.length; k++) {
160 if (window._EPYT_.evselector) {
161 window._EPYT_.evselector += ", ";
162 }
163 window._EPYT_.evselector += ":not([id*=\"jarallax-container\"]) > " + selectors[k];
164 }
165 }
166 }());'
167 );
168 }
169
170 /**
171 * Add custom image sizes.
172 */
173 public function add_image_sizes() {
174 if ( AWB_Settings::get_option( 'register_image_sizes', 'awb_images', true ) ) {
175 add_image_size( 'awb_sm', 500 );
176 add_image_size( 'awb_md', 800 );
177 add_image_size( 'awb_lg', 1280 );
178 add_image_size( 'awb_xl', 1920 );
179 }
180 }
181
182 /**
183 * Include dependencies
184 */
185 private function include_dependencies() {
186 require_once $this->plugin_path . 'classes/class-settings.php';
187 require_once $this->plugin_path . 'classes/class-rest.php';
188 require_once $this->plugin_path . 'classes/class-shortcode.php';
189 require_once $this->plugin_path . 'classes/class-vc-extend.php';
190 require_once $this->plugin_path . 'classes/class-tinymce.php';
191 require_once $this->plugin_path . 'classes/class-gutenberg.php';
192 }
193 }
194
195 /**
196 * Function works with the NK_AWB class instance
197 *
198 * @return object NK_AWB
199 */
200 function nk_awb() {
201 return NK_AWB::instance();
202 }
203 add_action( 'plugins_loaded', 'NK_AWB' );
204