ocean-extra
Last commit date
assets
8 years ago
includes
8 years ago
languages
8 years ago
sass
8 years ago
index.php
8 years ago
ocean-extra.php
8 years ago
readme.txt
8 years ago
ocean-extra.php
304 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.2.4 |
| 7 | * Author: OceanWP |
| 8 | * Author URI: https://oceanwp.org/ |
| 9 | * Requires at least: 4.5.0 |
| 10 | * Tested up to: 4.8 |
| 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.2.4'; |
| 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 | register_activation_hook( __FILE__, array( $this, 'install' ) ); |
| 97 | |
| 98 | add_action( 'init', array( $this, 'oe_load_plugin_textdomain' ) ); |
| 99 | |
| 100 | add_action( 'init', array( $this, 'oe_setup' ) ); |
| 101 | |
| 102 | // Menu icons |
| 103 | $theme = wp_get_theme(); |
| 104 | if ( 'OceanWP' == $theme->name || 'oceanwp' == $theme->template ) { |
| 105 | require_once( OE_PATH .'/includes/panel/theme-panel.php' ); |
| 106 | require_once( OE_PATH .'/includes/panel/updater.php' ); |
| 107 | require_once( OE_PATH .'/includes/menu-icons/menu-icons.php' ); |
| 108 | } |
| 109 | |
| 110 | // Load custom widgets |
| 111 | add_action( 'widgets_init', array( $this, 'custom_widgets' ), 10 ); |
| 112 | |
| 113 | // Allow shortcodes in text widgets |
| 114 | add_filter( 'widget_text', 'do_shortcode' ); |
| 115 | |
| 116 | // Allow for the use of shortcodes in the WordPress excerpt |
| 117 | add_filter( 'the_excerpt', 'shortcode_unautop' ); |
| 118 | add_filter( 'the_excerpt', 'do_shortcode' ); |
| 119 | |
| 120 | // Remove customizer unnecessary sections |
| 121 | add_action( 'customize_register', array( $this, 'remove_customize_sections' ), 11 ); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Main Ocean_Extra Instance |
| 126 | * |
| 127 | * Ensures only one instance of Ocean_Extra is loaded or can be loaded. |
| 128 | * |
| 129 | * @since 1.0.0 |
| 130 | * @static |
| 131 | * @see Ocean_Extra() |
| 132 | * @return Main Ocean_Extra instance |
| 133 | */ |
| 134 | public static function instance() { |
| 135 | if ( is_null( self::$_instance ) ) |
| 136 | self::$_instance = new self(); |
| 137 | return self::$_instance; |
| 138 | } // End instance() |
| 139 | |
| 140 | /** |
| 141 | * Load the localisation file. |
| 142 | * @access public |
| 143 | * @since 1.0.0 |
| 144 | * @return void |
| 145 | */ |
| 146 | public function oe_load_plugin_textdomain() { |
| 147 | load_plugin_textdomain( 'ocean-extra', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Cloning is forbidden. |
| 152 | * |
| 153 | * @since 1.0.0 |
| 154 | */ |
| 155 | public function __clone() { |
| 156 | _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?' ), '1.0.0' ); |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Unserializing instances of this class is forbidden. |
| 161 | * |
| 162 | * @since 1.0.0 |
| 163 | */ |
| 164 | public function __wakeup() { |
| 165 | _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?' ), '1.0.0' ); |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Installation. |
| 170 | * Runs on activation. Logs the version number and assigns a notice message to a WordPress option. |
| 171 | * @access public |
| 172 | * @since 1.0.0 |
| 173 | * @return void |
| 174 | */ |
| 175 | public function install() { |
| 176 | $this->_log_version_number(); |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Log the plugin version number. |
| 181 | * @access private |
| 182 | * @since 1.0.0 |
| 183 | * @return void |
| 184 | */ |
| 185 | private function _log_version_number() { |
| 186 | // Log the version number. |
| 187 | update_option( $this->token . '-version', $this->version ); |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * Remove customizer unnecessary sections |
| 192 | */ |
| 193 | public static function remove_customize_sections( $wp_customize ) { |
| 194 | |
| 195 | // Remove core sections |
| 196 | $wp_customize->remove_section( 'colors' ); |
| 197 | $wp_customize->remove_section( 'themes' ); |
| 198 | $wp_customize->remove_section( 'background_image' ); |
| 199 | |
| 200 | // Remove core controls |
| 201 | $wp_customize->remove_control( 'header_textcolor' ); |
| 202 | $wp_customize->remove_control( 'background_color' ); |
| 203 | $wp_customize->remove_control( 'background_image' ); |
| 204 | |
| 205 | // Remove default settings |
| 206 | $wp_customize->remove_setting( 'background_color' ); |
| 207 | $wp_customize->remove_setting( 'background_image' ); |
| 208 | |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * Setup all the things. |
| 213 | * Only executes if OceanWP or a child theme using OceanWP as a parent is active and the extension specific filter returns true. |
| 214 | * @return void |
| 215 | */ |
| 216 | public function oe_setup() { |
| 217 | $theme = wp_get_theme(); |
| 218 | |
| 219 | if ( 'OceanWP' == $theme->name || 'oceanwp' == $theme->template ) { |
| 220 | require_once( OE_PATH .'/includes/metabox/butterbean/butterbean.php' ); |
| 221 | require_once( OE_PATH .'/includes/metabox/metabox.php' ); |
| 222 | require_once( OE_PATH .'/includes/metabox/shortcodes.php' ); |
| 223 | require_once( OE_PATH .'/includes/metabox/gallery-metabox/gallery-metabox.php' ); |
| 224 | require_once( OE_PATH .'/includes/shortcodes/shortcodes.php' ); |
| 225 | require_once( OE_PATH .'/includes/image-resizer.php' ); |
| 226 | require_once( OE_PATH .'/includes/jsmin.php' ); |
| 227 | require_once( OE_PATH .'/includes/walker.php' ); |
| 228 | add_action( 'wp_enqueue_scripts', array( $this, 'oe_scripts' ), 999 ); |
| 229 | } else { |
| 230 | add_action( 'admin_notices', array( $this, 'oe_install_oceanwp_notice' ) ); |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * OceanWP install |
| 236 | * If the user activates the plugin while having a different parent theme active, prompt them to install OceanWP. |
| 237 | * @since 1.0.0 |
| 238 | * @return void |
| 239 | */ |
| 240 | public function oe_install_oceanwp_notice() { |
| 241 | echo '<div class="notice is-dismissible updated"> |
| 242 | <p>' . esc_html__( 'Ocean Extra requires that you use OceanWP as your parent theme.', 'ocean-extra' ) . ' <a href="https://oceanwp.org/">' . esc_html__( 'Install OceanWP Now', 'ocean-extra' ) . '</a></p> |
| 243 | </div>'; |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * Include flickr widget class |
| 248 | * |
| 249 | * @since 1.0.0 |
| 250 | */ |
| 251 | public static function custom_widgets() { |
| 252 | |
| 253 | if ( ! version_compare( PHP_VERSION, '5.2', '>=' ) ) { |
| 254 | return; |
| 255 | } |
| 256 | |
| 257 | // Define array of custom widgets for the theme |
| 258 | $widgets = apply_filters( 'ocean_custom_widgets', array( |
| 259 | 'about-me', |
| 260 | 'contact-info', |
| 261 | 'custom-links', |
| 262 | 'custom-menu', |
| 263 | 'facebook', |
| 264 | 'flickr', |
| 265 | 'instagram', |
| 266 | 'mailchimp', |
| 267 | 'recent-posts', |
| 268 | 'social', |
| 269 | 'tags', |
| 270 | 'video', |
| 271 | 'custom-header-logo', |
| 272 | 'custom-header-nav', |
| 273 | ) ); |
| 274 | |
| 275 | // Loop through widgets and load their files |
| 276 | if ( $widgets && is_array( $widgets ) ) { |
| 277 | foreach ( $widgets as $widget ) { |
| 278 | $file = OE_PATH .'/includes/widgets/' . $widget .'.php'; |
| 279 | if ( file_exists ( $file ) ) { |
| 280 | require_once( $file ); |
| 281 | } |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | } |
| 286 | |
| 287 | /** |
| 288 | * Enqueue scripts |
| 289 | * |
| 290 | * @since 1.0.0 |
| 291 | */ |
| 292 | public function oe_scripts() { |
| 293 | |
| 294 | // Load main stylesheet |
| 295 | wp_enqueue_style( 'oe-widgets-style', plugins_url( '/assets/css/widgets/widgets.css', __FILE__ ) ); |
| 296 | |
| 297 | // If rtl |
| 298 | if ( is_RTL() ) { |
| 299 | wp_enqueue_style( 'oe-widgets-style-rtl', plugins_url( '/assets/css/widgets/rtl.css', __FILE__ ) ); |
| 300 | } |
| 301 | |
| 302 | } |
| 303 | |
| 304 | } // End Class |