init(); register_activation_hook( MODULA_PROTECTION_FILE, array( $this, 'plugin_activation' ) ); } /** * Set admin requirements and check for license. * * @return void * @since 1.0.7 */ public function set_admin_requirements() { if ( class_exists( 'WPChill_Upsells' ) ) { $args = apply_filters( 'modula_upsells_args', array( 'shop_url' => 'https://wp-modula.com', 'slug' => 'modula', ) ); $wpchill_upsell = WPChill_Upsells::get_instance( $args ); if ( $wpchill_upsell && ! $wpchill_upsell->is_upgradable_addon( 'modula-protection' ) ) { // Filter Modula Protection Tab add_filter( 'modula_gallery_tabs', array( $this, 'modula_protection_tabs' ) ); // Filter Modula Protection Fields add_filter( 'modula_gallery_fields', array( $this, 'modula_protection_fields' ) ); } } } /** * Prevent plugin activation if Modula Pro is not installed and activated * * @since 1.0.3 */ public function plugin_activation() { if ( ! class_exists( 'Modula_PRO' ) ) { deactivate_plugins( plugin_basename( MODULA_PROTECTION_FILE ) ); wp_die( __( 'Please install and activate Modula Pro before using Modula right click protection add-on.', 'modula-protection' ) ); } } /** * Loads the plugin textdomain for translation. * * @since 1.0.0 */ public function set_locale() { load_plugin_textdomain( 'modula-protection', false, MODULA_PROTECTION_PATH . '/languages' ); } /** * Loads the plugin into WordPress. * * @since 1.0.0 */ public function init() { // Load admin only components. if ( is_admin() ) { add_action( 'modula_pro_updater', array( $this, 'addon_updater' ), 15, 2 ); } } public function addon_updater( $license_key, $store_url ) { if ( class_exists( 'Modula_Pro_Base_Updater' ) ) { $modula_addon_updater = new Modula_Pro_Base_Updater( $store_url, MODULA_PROTECTION_FILE, array( 'version' => MODULA_PROTECTION_VERSION, // current version number 'license' => $license_key, // license key (used get_option above to retrieve from DB) 'item_id' => 290481, // ID of the product 'author' => 'MachoThemes', // author of this plugin 'beta' => false, ) ); } } /** * Returns the singleton instance of the class. * * @since 1.0.0 * * @return object The Modula_Protection object. */ public static function get_instance() { if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Modula_Protection ) ) { self::$instance = new Modula_Protection(); } return self::$instance; } /** * Register protection script and style */ public function register_protection_scripts() { // Register Protection script wp_register_script( 'modula-protection-script', MODULA_PROTECTION_URL . 'assets/js/modula-protection.js', array( 'jquery' ) ); } /** * @param $scripts * @param $settings * * @return array * * Enqueue protection script */ public function modula_protection_scripts( $scripts, $settings ) { if ( isset( $settings['protection'] ) && '1' == $settings['protection'] ) { $scripts[] = 'modula-protection-script'; } return $scripts; } public function modula_protection_tabs( $tabs ) { if ( ! isset( $tabs['misc'] ) ) { $tabs['misc'] = array( 'label' => esc_html__( 'Miscellaneous', 'modula-protection' ), 'icon' => 'dashicons dashicons-image-filter', 'priority' => 100, ); } unset( $tabs['misc']['badge'] ); return $tabs; } // Modula PRO Fields public function modula_protection_fields( $fields ) { if ( ! isset( $fields['misc'] ) || ! is_array( $fields['misc'] ) ) { $fields['misc'] = array(); } // Add filters settings $fields['misc']['protection'] = array( 'name' => esc_html__( 'Enable protection', 'modula-protection' ), 'type' => 'toggle', 'default' => 0, 'description' => __( 'Enable protection for modula gallery images, disabling right click and Alt+Click functionality for downloading images.', 'modula-protection' ), 'priority' => 10, ); return $fields; } public function output_css( $css, $gallery_id, $settings ) { if ( '1' == $settings['protection'] ) { $css .= '.modula-gallery a.tile-inner, .modula-gallery img.pic {-webkit-touch-callout: none;}.pp_pic_holder img {-webkit-touch-callout: none;}'; } return $css; } /** * Add protection option to Fancybox * * @param $fancybox_options * @param $settings * @return array * * @since 1.0.3 */ public function protection_fancybox_options( $fancybox_options, $settings ) { if ( isset( $settings['protection'] ) && '1' == $settings['protection'] ) { $fancybox_options['options']['protect'] = true; } else { $fancybox_options['options']['protect'] = false; } return $fancybox_options; } public function set_defaults( $defaults ) { $defaults['protection'] = 0; return $defaults; } public function disable_download_video( $fancybox_options, $settings ) { if ( isset( $settings['protection'] ) && 1 == $settings['protection'] ) { $fancybox_options['video']['tpl'] = ''; } return $fancybox_options; } /** * @param $modula_settings * @param $guest_settings * @param $source * * @return mixed * * @since 1.0.5 */ public function right_click_protecton_migrator_data( $modula_settings, $guest_settings, $source ) { if ( $source ) { switch ( $source ) { case 'envira': if ( isset( $guest_settings['config']['protection'] ) && 1 == $guest_settings['config']['protection'] ) { $modula_settings['protection'] = 1; } break; } } return $modula_settings; } }