ocean-extra
Last commit date
assets
7 years ago
includes
7 years ago
languages
7 years ago
sass
7 years ago
index.php
7 years ago
ocean-extra.php
7 years ago
readme.txt
7 years ago
wpml-config.xml
7 years ago
ocean-extra.php
401 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Plugin Name: Ocean Extra |
| 4 | * Plugin URI: https://oceanwp.org/extension/ocean-extra/ |
| 5 | * Description: Add extra features like widgets, metaboxes, import/export and a panel to activate the premium extensions. |
| 6 | * Version: 1.4.17 |
| 7 | * Author: OceanWP |
| 8 | * Author URI: https://oceanwp.org/ |
| 9 | * Requires at least: 4.5.0 |
| 10 | * Tested up to: 4.9.7 |
| 11 | * |
| 12 | * Text Domain: ocean-extra |
| 13 | * Domain Path: /languages/ |
| 14 | * |
| 15 | * @package Ocean_Extra |
| 16 | * @category Core |
| 17 | * @author OceanWP |
| 18 | */ |
| 19 | |
| 20 | // Exit if accessed directly |
| 21 | if ( ! defined( 'ABSPATH' ) ) { |
| 22 | exit; |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Returns the main instance of Ocean_Extra to prevent the need to use globals. |
| 27 | * |
| 28 | * @since 1.0.0 |
| 29 | * @return object Ocean_Extra |
| 30 | */ |
| 31 | function Ocean_Extra() { |
| 32 | return Ocean_Extra::instance(); |
| 33 | } // End Ocean_Extra() |
| 34 | |
| 35 | Ocean_Extra(); |
| 36 | |
| 37 | /** |
| 38 | * Main Ocean_Extra Class |
| 39 | * |
| 40 | * @class Ocean_Extra |
| 41 | * @version 1.0.0 |
| 42 | * @since 1.0.0 |
| 43 | * @package Ocean_Extra |
| 44 | */ |
| 45 | final class Ocean_Extra { |
| 46 | /** |
| 47 | * Ocean_Extra The single instance of Ocean_Extra. |
| 48 | * @var object |
| 49 | * @access private |
| 50 | * @since 1.0.0 |
| 51 | */ |
| 52 | private static $_instance = null; |
| 53 | |
| 54 | /** |
| 55 | * The token. |
| 56 | * @var string |
| 57 | * @access public |
| 58 | * @since 1.0.0 |
| 59 | */ |
| 60 | public $token; |
| 61 | |
| 62 | /** |
| 63 | * The version number. |
| 64 | * @var string |
| 65 | * @access public |
| 66 | * @since 1.0.0 |
| 67 | */ |
| 68 | public $version; |
| 69 | |
| 70 | // Admin - Start |
| 71 | /** |
| 72 | * The admin object. |
| 73 | * @var object |
| 74 | * @access public |
| 75 | * @since 1.0.0 |
| 76 | */ |
| 77 | public $admin; |
| 78 | |
| 79 | /** |
| 80 | * Constructor function. |
| 81 | * @access public |
| 82 | * @since 1.0.0 |
| 83 | * @return void |
| 84 | */ |
| 85 | public function __construct( $widget_areas = array() ) { |
| 86 | $this->token = 'ocean-extra'; |
| 87 | $this->plugin_url = plugin_dir_url( __FILE__ ); |
| 88 | $this->plugin_path = plugin_dir_path( __FILE__ ); |
| 89 | $this->version = '1.4.17'; |
| 90 | |
| 91 | define( 'OE_URL', $this->plugin_url ); |
| 92 | define( 'OE_PATH', $this->plugin_path ); |
| 93 | define( 'OE_VERSION', $this->version ); |
| 94 | define( 'OE_ADMIN_PANEL_HOOK_PREFIX', 'theme-panel_page_oceanwp-panel' ); |
| 95 | |
| 96 | // Elementor partner ID |
| 97 | if ( class_exists( 'Elementor\Plugin' ) |
| 98 | && ! defined( 'ELEMENTOR_PARTNER_ID' ) ) { |
| 99 | define( 'ELEMENTOR_PARTNER_ID', 2121 ); |
| 100 | } |
| 101 | |
| 102 | // WooCommerce Wishlist partner ID |
| 103 | if ( class_exists( 'TInvWL_Wishlist' ) ) { |
| 104 | define( 'TINVWL_PARTNER', 'oceanwporg' ); |
| 105 | define( 'TINVWL_CAMPAIGN', 'oceanwp_theme' ); |
| 106 | } |
| 107 | |
| 108 | // WooCommerce Variation Swatches partner ID |
| 109 | add_filter( 'gwp_affiliate_id', array( $this, 'gwp_affiliate_id' ) ); |
| 110 | |
| 111 | register_activation_hook( __FILE__, array( $this, 'install' ) ); |
| 112 | |
| 113 | add_action( 'init', array( $this, 'load_plugin_textdomain' ) ); |
| 114 | |
| 115 | // Setup all the things |
| 116 | add_action( 'init', array( $this, 'setup' ) ); |
| 117 | |
| 118 | // Menu icons |
| 119 | $theme = wp_get_theme(); |
| 120 | if ( 'OceanWP' == $theme->name || 'oceanwp' == $theme->template ) { |
| 121 | require_once( OE_PATH .'/includes/panel/theme-panel.php' ); |
| 122 | require_once( OE_PATH .'/includes/panel/integrations-tab.php' ); |
| 123 | require_once( OE_PATH .'/includes/panel/library.php' ); |
| 124 | require_once( OE_PATH .'/includes/panel/library-shortcode.php' ); |
| 125 | require_once( OE_PATH .'/includes/panel/updater.php' ); |
| 126 | require_once( OE_PATH .'/includes/menu-icons/menu-icons.php' ); |
| 127 | |
| 128 | // Outputs custom JS to the footer |
| 129 | add_action( 'wp_footer', array( $this, 'custom_js' ), 9999 ); |
| 130 | |
| 131 | // Register Custom JS file |
| 132 | add_action( 'init', array( $this, 'register_custom_js' ) ); |
| 133 | |
| 134 | // Move the Custom CSS section into the Custom CSS/JS section |
| 135 | add_action( 'customize_register', array( $this, 'customize_register' ), 11 ); |
| 136 | |
| 137 | // Remove customizer unnecessary sections |
| 138 | add_action( 'customize_register', array( $this, 'remove_customize_sections' ), 11 ); |
| 139 | } |
| 140 | |
| 141 | // Load custom widgets |
| 142 | add_action( 'widgets_init', array( $this, 'custom_widgets' ), 10 ); |
| 143 | |
| 144 | // Allow shortcodes in text widgets |
| 145 | add_filter( 'widget_text', 'do_shortcode' ); |
| 146 | |
| 147 | // Allow for the use of shortcodes in the WordPress excerpt |
| 148 | add_filter( 'the_excerpt', 'shortcode_unautop' ); |
| 149 | add_filter( 'the_excerpt', 'do_shortcode' ); |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Main Ocean_Extra Instance |
| 154 | * |
| 155 | * Ensures only one instance of Ocean_Extra is loaded or can be loaded. |
| 156 | * |
| 157 | * @since 1.0.0 |
| 158 | * @static |
| 159 | * @see Ocean_Extra() |
| 160 | * @return Main Ocean_Extra instance |
| 161 | */ |
| 162 | public static function instance() { |
| 163 | if ( is_null( self::$_instance ) ) |
| 164 | self::$_instance = new self(); |
| 165 | return self::$_instance; |
| 166 | } // End instance() |
| 167 | |
| 168 | /** |
| 169 | * WooCommerce Variation Swatches partner ID |
| 170 | * |
| 171 | * @since 1.0.0 |
| 172 | */ |
| 173 | public function gwp_affiliate_id() { |
| 174 | |
| 175 | // Return if the plugin is not active |
| 176 | if ( ! class_exists( 'Woo_Variation_Swatches' ) ) { |
| 177 | return; |
| 178 | } |
| 179 | |
| 180 | return 69; |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Load the localisation file. |
| 185 | * @access public |
| 186 | * @since 1.0.0 |
| 187 | * @return void |
| 188 | */ |
| 189 | public function load_plugin_textdomain() { |
| 190 | load_plugin_textdomain( 'ocean-extra', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Cloning is forbidden. |
| 195 | * |
| 196 | * @since 1.0.0 |
| 197 | */ |
| 198 | public function __clone() { |
| 199 | _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?' ), '1.0.0' ); |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * Unserializing instances of this class is forbidden. |
| 204 | * |
| 205 | * @since 1.0.0 |
| 206 | */ |
| 207 | public function __wakeup() { |
| 208 | _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?' ), '1.0.0' ); |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * Installation. |
| 213 | * Runs on activation. Logs the version number and assigns a notice message to a WordPress option. |
| 214 | * @access public |
| 215 | * @since 1.0.0 |
| 216 | * @return void |
| 217 | */ |
| 218 | public function install() { |
| 219 | $this->_log_version_number(); |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Log the plugin version number. |
| 224 | * @access private |
| 225 | * @since 1.0.0 |
| 226 | * @return void |
| 227 | */ |
| 228 | private function _log_version_number() { |
| 229 | // Log the version number. |
| 230 | update_option( $this->token . '-version', $this->version ); |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * All theme functions hook into the oceanwp_footer_js filter for this function. |
| 235 | * |
| 236 | * @since 1.3.8 |
| 237 | */ |
| 238 | public static function custom_js( $output = NULL ) { |
| 239 | |
| 240 | // Add filter for adding custom js via other functions |
| 241 | $output = apply_filters( 'ocean_footer_js', $output ); |
| 242 | |
| 243 | // Minify and output JS in the wp_footer |
| 244 | if ( ! empty( $output ) ) { ?> |
| 245 | |
| 246 | <script type="text/javascript"> |
| 247 | |
| 248 | /* OceanWP JS */ |
| 249 | <?php echo Ocean_Extra_JSMin::minify( $output ); ?> |
| 250 | |
| 251 | </script> |
| 252 | |
| 253 | <?php |
| 254 | } |
| 255 | |
| 256 | } |
| 257 | |
| 258 | /** |
| 259 | * Adds customizer options |
| 260 | * |
| 261 | * @since 1.3.8 |
| 262 | */ |
| 263 | public function register_custom_js() { |
| 264 | |
| 265 | // Var |
| 266 | $dir = OE_PATH .'/includes/'; |
| 267 | |
| 268 | // File |
| 269 | if ( Ocean_Extra_Theme_Panel::get_setting( 'oe_custom_code_panel' ) ) { |
| 270 | require_once( $dir . 'custom-code.php' ); |
| 271 | } |
| 272 | |
| 273 | } |
| 274 | |
| 275 | /** |
| 276 | * Move the Custom CSS section into the Custom CSS/JS section |
| 277 | * |
| 278 | * @since 1.3.8 |
| 279 | */ |
| 280 | public static function customize_register( $wp_customize ) { |
| 281 | |
| 282 | // Move custom css setting |
| 283 | $wp_customize->get_control( 'custom_css' )->section = 'ocean_custom_code_panel'; |
| 284 | |
| 285 | } |
| 286 | |
| 287 | /** |
| 288 | * Remove customizer unnecessary sections |
| 289 | * |
| 290 | * @since 1.0.0 |
| 291 | */ |
| 292 | public static function remove_customize_sections( $wp_customize ) { |
| 293 | |
| 294 | // Remove core sections |
| 295 | $wp_customize->remove_section( 'colors' ); |
| 296 | $wp_customize->remove_section( 'themes' ); |
| 297 | $wp_customize->remove_section( 'background_image' ); |
| 298 | |
| 299 | // Remove core controls |
| 300 | $wp_customize->remove_control( 'header_textcolor' ); |
| 301 | $wp_customize->remove_control( 'background_color' ); |
| 302 | $wp_customize->remove_control( 'background_image' ); |
| 303 | $wp_customize->remove_control( 'display_header_text' ); |
| 304 | |
| 305 | // Remove default settings |
| 306 | $wp_customize->remove_setting( 'background_color' ); |
| 307 | $wp_customize->remove_setting( 'background_image' ); |
| 308 | |
| 309 | } |
| 310 | |
| 311 | /** |
| 312 | * Setup all the things. |
| 313 | * Only executes if OceanWP or a child theme using OceanWP as a parent is active and the extension specific filter returns true. |
| 314 | * @return void |
| 315 | */ |
| 316 | public function setup() { |
| 317 | $theme = wp_get_theme(); |
| 318 | |
| 319 | if ( 'OceanWP' == $theme->name || 'oceanwp' == $theme->template ) { |
| 320 | require_once( OE_PATH .'/includes/metabox/butterbean/butterbean.php' ); |
| 321 | require_once( OE_PATH .'/includes/metabox/metabox.php' ); |
| 322 | require_once( OE_PATH .'/includes/metabox/shortcodes.php' ); |
| 323 | require_once( OE_PATH .'/includes/metabox/gallery-metabox/gallery-metabox.php' ); |
| 324 | require_once( OE_PATH .'/includes/shortcodes/shortcodes.php' ); |
| 325 | require_once( OE_PATH .'/includes/image-resizer.php' ); |
| 326 | require_once( OE_PATH .'/includes/jsmin.php' ); |
| 327 | require_once( OE_PATH .'/includes/panel/notice.php' ); |
| 328 | require_once( OE_PATH .'/includes/walker.php' ); |
| 329 | require_once( OE_PATH .'/includes/dashboard.php' ); |
| 330 | |
| 331 | // If Demo Import or Pro Demos is activated |
| 332 | if ( class_exists( 'Ocean_Demo_Import' ) |
| 333 | || class_exists( 'Ocean_Pro_Demos' ) ) { |
| 334 | require_once( OE_PATH .'/includes/panel/demos.php' ); |
| 335 | } |
| 336 | |
| 337 | add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ), 999 ); |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | /** |
| 342 | * Include flickr widget class |
| 343 | * |
| 344 | * @since 1.0.0 |
| 345 | */ |
| 346 | public static function custom_widgets() { |
| 347 | |
| 348 | if ( ! version_compare( PHP_VERSION, '5.2', '>=' ) ) { |
| 349 | return; |
| 350 | } |
| 351 | |
| 352 | // Define array of custom widgets for the theme |
| 353 | $widgets = apply_filters( 'ocean_custom_widgets', array( |
| 354 | 'about-me', |
| 355 | 'contact-info', |
| 356 | 'custom-links', |
| 357 | 'custom-menu', |
| 358 | 'facebook', |
| 359 | 'flickr', |
| 360 | 'instagram', |
| 361 | 'mailchimp', |
| 362 | 'recent-posts', |
| 363 | 'social', |
| 364 | 'social-share', |
| 365 | 'tags', |
| 366 | 'twitter', |
| 367 | 'video', |
| 368 | 'custom-header-logo', |
| 369 | 'custom-header-nav', |
| 370 | ) ); |
| 371 | |
| 372 | // Loop through widgets and load their files |
| 373 | if ( $widgets && is_array( $widgets ) ) { |
| 374 | foreach ( $widgets as $widget ) { |
| 375 | $file = OE_PATH .'/includes/widgets/' . $widget .'.php'; |
| 376 | if ( file_exists ( $file ) ) { |
| 377 | require_once( $file ); |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | } |
| 383 | |
| 384 | /** |
| 385 | * Enqueue scripts |
| 386 | * |
| 387 | * @since 1.0.0 |
| 388 | */ |
| 389 | public function scripts() { |
| 390 | |
| 391 | // Load main stylesheet |
| 392 | wp_enqueue_style( 'oe-widgets-style', plugins_url( '/assets/css/widgets.css', __FILE__ ) ); |
| 393 | |
| 394 | // If rtl |
| 395 | if ( is_RTL() ) { |
| 396 | wp_enqueue_style( 'oe-widgets-style-rtl', plugins_url( '/assets/css/rtl.css', __FILE__ ) ); |
| 397 | } |
| 398 | |
| 399 | } |
| 400 | |
| 401 | } // End Class |