<?php
/**
 * Plugin Name:  YXX Smart Watermark
 * Plugin URI:   https://wordpress.org/plugins/yxx-smart-watermark/
 * Description:  Lightweight image watermark protection
 * Version:      1.0.0
 * Author:       yanxuanxiang
 * License:      GPL-2.0+
 * Text Domain:  yxx-smart-watermark
 */
if (!defined('ABSPATH')) { exit; }
define('YXXSMWA_VERSION', '1.0.0');
define('YXXSMWA_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('YXXSMWA_PLUGIN_URL', plugin_dir_url(__FILE__));
define('YXXSMWA_PLUGIN_BASENAME', plugin_basename(__FILE__));
define('YXXSMWA_UPGRADE_URL', 'https://www.creem.io/payment/prod_4lHDSrGKRB8zyEf7DcBfTz');
require_once YXXSMWA_PLUGIN_DIR . 'includes/class-core.php';
require_once YXXSMWA_PLUGIN_DIR . 'includes/class-admin.php';
function yxxsmwa_init() { YXXSMWA_Core::instance(); YXXSMWA_Admin::instance(); }
add_action('plugins_loaded', 'yxxsmwa_init');
register_activation_hook(__FILE__, function() {
    $d = ['yxxsmwa_text_enabled'=>true,'yxxsmwa_text_content'=>get_bloginfo('name'),'yxxsmwa_text_size'=>12,'yxxsmwa_text_color'=>'#ffffff','yxxsmwa_text_opacity'=>60,'yxxsmwa_position'=>'bottom-right','yxxsmwa_image_sizes'=>['large','full'],'yxxsmwa_auto_watermark'=>true,'yxxsmwa_image_watermark_enabled'=>false];
    foreach ($d as $k=>$v) { if (get_option($k)===false) { update_option($k,$v); } }
});
register_deactivation_hook(__FILE__, function(){});
register_uninstall_hook(__FILE__, 'yxxsmwa_uninstall');
function yxxsmwa_uninstall() {
    foreach(['yxxsmwa_text_enabled','yxxsmwa_text_content','yxxsmwa_text_size','yxxsmwa_text_color','yxxsmwa_text_opacity','yxxsmwa_position','yxxsmwa_image_sizes','yxxsmwa_auto_watermark','yxxsmwa_image_watermark_enabled','yxxsmwa_image_watermark_id','yxxsmwa_image_watermark_opacity'] as $o){delete_option($o);}
    global $wpdb;
        // phpcs:disable WordPress.DB.DirectDatabaseQuery
        $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE meta_key='_yxxsmwa_original_path'");
        // phpcs:enable WordPress.DB.DirectDatabaseQuery
}
