-
Notifications
You must be signed in to change notification settings - Fork 0
/
ilove-img-watermark.php
145 lines (123 loc) · 5.28 KB
/
ilove-img-watermark.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
/**
* Best Watermark - Protect images on your site with iLoveIMG
*
* @link https://iloveimg.com/
* @since 1.0.1
* @package iloveimgwatermark
*
* @wordpress-plugin
* Plugin Name: Best Watermark - Protect images on your site with iLoveIMG
* Plugin URI: https://iloveapi.com/
* Description: Protect your site from image theft with our reliable and easy-to-use watermark plugin. Effective protection for your images.
* Version: 2.2.4
* Requires at least: 5.3
* Requires PHP: 7.4
* Author: iLoveIMG
* Author URI: https://iloveimg.com/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: iloveimg-watermark
* Domain Path: /languages
*/
if ( ! defined( 'WPINC' ) ) {
die;
}
require_once plugin_dir_path( __FILE__ ) . '/vendor/autoload.php';
if ( ini_get( 'max_execution_time' ) < 300 ) {
set_time_limit( 300 );
}
$ilove_img_wm_upload_path = wp_upload_dir();
define( 'ILOVE_IMG_WM_REGISTER_URL', 'https://api.ilovepdf.com/v1/user' );
define( 'ILOVE_IMG_WM_LOGIN_URL', 'https://api.ilovepdf.com/v1/user/login' );
define( 'ILOVE_IMG_WM_USER_URL', 'https://api.ilovepdf.com/v1/user' );
define( 'ILOVE_IMG_WM_NUM_MAX_FILES', 2 );
define( 'ILOVE_IMG_WM_COMPRESS_DB_VERSION', '1.0' );
define( 'ILOVE_IMG_WM_UPLOAD_FOLDER', $ilove_img_wm_upload_path['basedir'] );
define( 'ILOVE_IMG_WM_BACKUP_FOLDER', $ilove_img_wm_upload_path['basedir'] . '/iloveimg-backup/' );
define( 'ILOVE_IMG_WM_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
use Ilove_Img_Wm\Ilove_Img_Wm_Plugin;
use Ilove_Img_Wm\Ilove_Img_Wm_Resources;
use Ilove_Img_Wm\Ilove_Img_Wm_Serializer;
use Ilove_Img_Wm\Ilove_Img_Wm_Submenu;
use Ilove_Img_Wm\Ilove_Img_Wm_Submenu_Page;
/**
* Initialize admin settings
*
* This function runs when plugins are loaded in WordPress.
*/
function ilove_img_wm_custom_admin_settings() {
$serializer = new Ilove_Img_Wm_Serializer();
$serializer->init();
$plugin = new Ilove_Img_Wm_Submenu( new Ilove_Img_Wm_Submenu_Page() );
$plugin->init();
}
add_action( 'plugins_loaded', 'ilove_img_wm_custom_admin_settings' );
/**
* Add links on WordPress admin
*
* This function adds links to the plugin's settings and bulk optimization pages in the WordPress admin dashboard.
*
* @param array $links An array of existing plugin action links.
* @return array An array with the added plugin action links.
*/
function ilove_img_wm_add_plugin_page_settings_link( $links ) {
$links[] = '<a href="' .
admin_url( 'admin.php?page=iloveimg-watermark-admin-page' ) .
'">' . __( 'Settings', 'iloveimg-watermark' ) . '</a>';
$links[] = '<a href="' .
admin_url( 'upload.php?page=iloveimg-media-watermark-page' ) .
'">' . __( 'Bulk Watermark', 'iloveimg-watermark' ) . '</a>';
return $links;
}
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'ilove_img_wm_add_plugin_page_settings_link' );
/**
* Add Options to watermark page admin settings
*
* This function is executed when the plugin is activated. It performs the following tasks:
* 1. Adds an option to store the plugin's database version.
* 2. Sets default options for watermarking if they don't already exist in the WordPress options.
*/
function ilove_img_wm_activate() {
Ilove_Img_Wm_Resources::update_option( 'ilove_img_wm_db_version', ILOVE_IMG_WM_COMPRESS_DB_VERSION, true );
if ( ! file_exists( ILOVE_IMG_WM_BACKUP_FOLDER ) ) {
wp_mkdir_p( ILOVE_IMG_WM_BACKUP_FOLDER );
}
if ( ! get_option( 'iloveimg_options_watermark' ) ) {
$iloveimg_thumbnails = array( 'full', 'thumbnail', 'medium', 'medium_large', 'large' );
if ( ! extension_loaded( 'gd' ) ) {
$iloveimg_thumbnails = array( 'full' );
}
Ilove_Img_Wm_Resources::update_option(
'iloveimg_options_watermark',
wp_json_encode(
array(
'iloveimg_field_type' => 'text',
'iloveimg_field_text_family' => 'Arial',
'iloveimg_field_text' => 'Sample',
'iloveimg_field_scale' => 33,
'iloveimg_field_opacity' => 1,
'iloveimg_field_rotation' => 0,
'iloveimg_field_position' => 1,
'iloveimg_field_sizes' => $iloveimg_thumbnails,
'iloveimg_field_backup' => 'on',
)
),
true
);
} else {
$old_data = get_option( 'iloveimg_options_watermark' );
if ( is_serialized( $old_data ) ) {
$old_data_serialize = unserialize( get_option( 'iloveimg_options_watermark' ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize
Ilove_Img_Wm_Resources::update_option( 'iloveimg_options_watermark', wp_json_encode( $old_data_serialize ), true );
} else {
$iloveimg_options_watermark = json_decode( $old_data, true );
if ( ! array_key_exists( 'iloveimg_field_text_family', $iloveimg_options_watermark ) ) {
$iloveimg_options_watermark['iloveimg_field_text_family'] = 'Arial';
Ilove_Img_Wm_Resources::update_option( 'iloveimg_options_watermark', wp_json_encode( $iloveimg_options_watermark ), true );
}
}
}
}
register_activation_hook( __FILE__, 'ilove_img_wm_activate' );
new Ilove_Img_Wm_Plugin();