Skip to content

Commit

Permalink
Merge branch 'release/1.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubmikita committed Sep 11, 2019
2 parents f1c6516 + e09e68d commit abacfcb
Show file tree
Hide file tree
Showing 18 changed files with 135 additions and 61 deletions.
4 changes: 2 additions & 2 deletions easy-watermark.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
/**
* Plugin Name: Easy Watermark
* Description: This plugin can automatically add image and text watermark to pictures as they are uploaded to WordPress media library. You can also watermark existing images manually (all at once or an every single image). Watermark image can be a png, gif (alpha channel supported in both cases) or jpg. It's also possibile to set watermark opacity (doesn't apply to png with alpha channel). For text watermark you can select font, set color, size, angel and opacity.
* Description: This plugin can automatically add image and text watermark to pictures as they are uploaded to WordPress media library. You can also watermark existing images manually (all at once or an every single image). Watermark image can be a png, gif (alpha channel supported in both cases) or jpg. It's also possibile to set watermark opacity (doesn't apply to png with alpha channel). For text watermark you can select font, set color, size, angle and opacity.
* Author: BracketSpace
* Author URI: https://bracketspace.com/
* Text Domain: easy-watermark
* Domain Path: /languages
* Version: 1.0.0
* Version: 1.0.1
* License: GPLv2 or later
*
* @package easy-watermark
Expand Down
12 changes: 10 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Tags: watermark, image, picture, photo, media, gallery, signature, transparent,
Requires at least: 3.8
Requires PHP: 5.6
Tested up to: 5.2
Stable tag: 1.0.0
Stable tag: 1.0.1
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: easy-watermark
Expand Down Expand Up @@ -86,7 +86,7 @@ Watermark position can be adjusted vertically and horizontally by selecting alig
Yes, there is a posibility to add only image, only text or both.

= How Can I adjust text watermark? =
You can choose text font from the list of ten fonts included to this plugin. You can also set font size, color, angel and opacity. Position of text watermark can be adjusted exactly like the image watermark position.
You can choose text font from the list of ten fonts included to this plugin. You can also set font size, color, angle and opacity. Position of text watermark can be adjusted exactly like the image watermark position.

= Can I use my font for text watermark? =
Unfortunately no. In PRO version you'll be able to use more fonts.
Expand Down Expand Up @@ -118,6 +118,14 @@ All available placeholders are listed in a box titled 'Placeholders' displayed w

== Changelog ==

= 1.0.1 =
* [Fixed] Freemius screen displayed incorrectly after activation
* [Fixed] Permission settings now actualy works
* [Fixed] Config is now saved in unicode so you can use other character sets, like cyrylic
* [Fixed] Incompatibilities with caching plugins
* [Fixed] Srcset fatal error edge case
* [Fixed] Watermark deleting

= 1.0.0 =
* The plugin has been rewrote from ground up.

Expand Down
4 changes: 4 additions & 0 deletions src/classes/Core/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ public function enqueue_admin_scripts() {
];
break;
case 'upload':
if ( ! current_user_can( 'apply_watermark' ) ) {
break;
}

$this->wp_enqueue_media();
$enqueue = 'media-library';
$localize = [
Expand Down
12 changes: 9 additions & 3 deletions src/classes/Core/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ public static function uninstall() {
$role->remove_cap( 'apply_watermark' );
}

$watermarks = Watermark::get_all();

foreach ( $watermarks as $watermark ) {
$result = wp_delete_post( $watermark->ID, true );
}

}

/**
Expand Down Expand Up @@ -198,6 +204,9 @@ public static function update( $from, $defaults ) {
$defaults['general']['jpeg_quality'] = $settings['general']['jpg_quality'];
}

update_option( Plugin::get()->get_slug() . '-settings', $defaults );
update_option( Plugin::get()->get_slug() . '-version', Plugin::get()->get_version() );

if ( isset( $settings['image']['watermark_id'] ) && ! empty( $settings['image']['watermark_id'] ) ) {
self::insert_image_watermark( $watermark_defaults, $settings );
}
Expand All @@ -206,9 +215,6 @@ public static function update( $from, $defaults ) {
self::insert_text_watermark( $watermark_defaults, $settings );
}

update_option( Plugin::get()->get_slug() . '-settings', $defaults );
update_option( Plugin::get()->get_slug() . '-version', Plugin::get()->get_version() );

self::update_backup_info();

}
Expand Down
21 changes: 12 additions & 9 deletions src/classes/Core/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ protected function __construct() {

register_activation_hook( EW_FILE_PATH, [ 'EasyWatermark\Core\Installer', 'activate' ] );
register_deactivation_hook( EW_FILE_PATH, [ 'EasyWatermark\Core\Installer', 'deactivate' ] );
register_uninstall_hook( EW_FILE_PATH, [ 'EasyWatermark\Core\Installer', 'uninstall' ] );

if ( ! ew_dochooks_enabled() ) {
add_action( 'plugins_loaded', [ $this, 'setup' ] );
Expand All @@ -82,7 +81,10 @@ protected function __construct() {
$this->hook();

// Init Freemius.
ew_fs();
$fs = ew_fs();

// Register uninstall hook with freemius.
$fs->add_action( 'after_uninstall', [ 'EasyWatermark\Core\Installer', 'uninstall' ] );

// Signal that SDK was initiated.
do_action( 'ew_fs_loaded' );
Expand Down Expand Up @@ -111,13 +113,7 @@ public function setup() {

$this->get_watermark_handler();

$settings = Settings::get();

$last_version = get_option( $this->slug . '-version' );
if ( $this->version !== $last_version ) {
// Version has changed. Update.
Installer::update( $last_version, $settings->get_settings() );
}
Settings::get();

$this->setup_metaboxes();

Expand Down Expand Up @@ -163,6 +159,13 @@ public function init() {
add_rewrite_tag( '%watermark_id%', '([0-9]+)' );
add_rewrite_tag( '%image_size%', '([^./-]+)' );

$last_version = get_option( $this->slug . '-version' );
if ( $this->version !== $last_version ) {
// Version has changed. Update.
$settings = Settings::get();
Installer::update( $last_version, $settings->get_settings() );
}

}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/classes/Dashboard/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function add_options_page() {
$this->page_hook = add_management_page(
__( 'Easy Watermark', 'easy-watermark' ),
__( 'Easy Watermark', 'easy-watermark' ),
'manage_options',
'apply_watermark',
'easy-watermark',
[ $this, 'page_content' ]
);
Expand Down
17 changes: 13 additions & 4 deletions src/classes/Dashboard/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ abstract class Page {
*/
protected $priority;

/**
* Permission
*
* @var string
*/
protected $permission = 'apply_watermark';

/**
* Constructor
*
Expand Down Expand Up @@ -66,10 +73,12 @@ public function __construct( $title, $slug = null, $priority = 10 ) {
*/
public function add_tab( $tabs ) {

$tabs[ $this->slug ] = [
'title' => $this->title,
'priority' => $this->priority,
];
if ( current_user_can( $this->permission ) ) {
$tabs[ $this->slug ] = [
'title' => $this->title,
'priority' => $this->priority,
];
}

return $tabs;

Expand Down
1 change: 1 addition & 0 deletions src/classes/Dashboard/Permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Permissions extends Page {
* Constructor
*/
public function __construct() {
$this->permission = 'manage_options';
parent::__construct( __( 'Permissions', 'easy-watermark' ), null, 100 );
}

Expand Down
1 change: 1 addition & 0 deletions src/classes/Dashboard/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Settings extends Page {
* Constructor
*/
public function __construct() {
$this->permission = 'manage_options';
parent::__construct( __( 'Settings', 'easy-watermark' ), null, 80 );
}

Expand Down
41 changes: 27 additions & 14 deletions src/classes/Dashboard/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,33 +60,26 @@ public function view_args( $args ) {
return [
'watermarks' => $handler->get_watermarks(),
'backup_count' => $backup_count,
'attachments' => $this->get_attachments(),
];
}

/**
* Prepares arguments for view
*
* @action wp_ajax_easy-watermark/tools/get-attachments
* Gets attachments available for watermarking
*
* @return void
* @param string $mode Mode (watermark|restore).
* @return array
*/
public function get_attachments() {

check_ajax_referer( 'get_attachments', 'nonce' );
private function get_attachments( $mode = 'watermark' ) {

$mime_types = ImageHelper::get_available_mime_types();

// phpcs:ignore WordPress.Security.ValidatedSanitizedInput
$mode = isset( $_REQUEST['mode'] ) ? $_REQUEST['mode'] : null;

$posts = get_posts( [
$result = [];
$posts = get_posts( [
'post_type' => 'attachment',
'post_mime_type' => array_keys( $mime_types ),
'numberposts' => -1,
] );

$result = [];

foreach ( $posts as $post ) {
if ( get_post_meta( $post->ID, '_ew_used_as_watermark', true ) ) {
// Skip images used as watermark.
Expand All @@ -104,6 +97,26 @@ public function get_attachments() {
];
}

return $result;

}

/**
* Prepares arguments for view
*
* @action wp_ajax_easy-watermark/tools/get-attachments
*
* @return void
*/
public function ajax_get_attachments() {

check_ajax_referer( 'get_attachments', 'nonce' );

// phpcs:ignore WordPress.Security.ValidatedSanitizedInput
$mode = isset( $_REQUEST['mode'] ) ? $_REQUEST['mode'] : null;
$result = $this->get_attachments( $mode );

wp_send_json_success( $result );

}
}
5 changes: 5 additions & 0 deletions src/classes/Features/SrcsetFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public function register_settings( $section ) {
*/
public function wp_calculate_image_srcset_meta( $image_meta, $size_array, $image_src, $attachment_id ) {

if ( ! $this->switch ) {
// Don't do anything if settings have not been loaded yet.
return $image_meta;
}

if ( true === $this->switch->get_value() && isset( $image_meta['sizes'] ) && is_array( $image_meta['sizes'] ) ) {
$applied_watermarks = get_post_meta( $attachment_id, '_ew_applied_watermarks', true );

Expand Down
2 changes: 1 addition & 1 deletion src/classes/Settings/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Settings extends Singleton {
/**
* Constructor
*/
public function __construct() {
protected function __construct() {
$this->hook();
$this->register_sections();
$this->load_settings();
Expand Down
4 changes: 2 additions & 2 deletions src/classes/Watermark/PostType.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public function delete_post( $post_id ) {
public function redirect( $location ) {
global $post;

if ( 'watermark' === $post->post_type ) {
if ( $post && 'watermark' === $post->post_type ) {
if ( false !== strpos( $location, 'untrashed=1' ) && ! $this->untrashed ) {
$location = add_query_arg( [
'ew-limited' => '1',
Expand Down Expand Up @@ -447,7 +447,7 @@ public function wp_insert_post_data( $data, $postarr ) {
if ( 'watermark' === $data['post_type'] && isset( $postarr['watermark'] ) ) {
$watermark_data = Watermark::parse_params( $postarr['watermark'] );

$data['post_content'] = wp_json_encode( $watermark_data );
$data['post_content'] = wp_json_encode( $watermark_data, JSON_UNESCAPED_UNICODE );

$old_attachment_id = isset( $postarr['ew-previous-attachment-id'] ) ? $postarr['ew-previous-attachment-id'] : false;
$new_attachment_id = $postarr['watermark']['attachment_id'];
Expand Down
3 changes: 2 additions & 1 deletion src/classes/Watermark/Watermark.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ public static function get( $post ) {
public static function get_all() {

$posts = get_posts( [
'post_type' => 'watermark',
'post_type' => 'watermark',
'numberposts' => -1,
] );

foreach ( $posts as $post ) {
Expand Down
13 changes: 11 additions & 2 deletions src/inc/freemius.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,24 @@ function ew_fs() {
// Include Freemius SDK.
require_once EW_DIR_PATH . '/freemius/start.php';

$ew_fs = fs_dynamic_init( array(
$ew_fs = fs_dynamic_init( [
'id' => '2801',
'slug' => 'easy-watermark',
'type' => 'plugin',
'public_key' => 'pk_f13faf5a5fdb7e7b8bd3b78646f15',
'is_premium' => false,
'has_addons' => false,
'has_paid_plans' => false,
) );
'menu' => [
'slug' => 'easy-watermark',
'account' => false,
'contact' => false,
'support' => false,
'parent' => [
'slug' => 'tools.php',
],
],
] );
}

return $ew_fs;
Expand Down
2 changes: 1 addition & 1 deletion src/inc/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
add_filter( 'easy-watermark/dashboard/tabs', [ $this->objects['EasyWatermark\Dashboard\Permissions']['instance'], 'add_tab' ], 10, 1 );
add_action( 'easy-watermark/dashboard/settings/notices', [ $this->objects['EasyWatermark\Dashboard\Tools']['instance'], 'admin_notices' ], 10, 0 );
add_filter( 'easy-watermark/dashboard/tools/view-args', [ $this->objects['EasyWatermark\Dashboard\Tools']['instance'], 'view_args' ], 10, 1 );
add_action( 'wp_ajax_easy-watermark/tools/get-attachments', [ $this->objects['EasyWatermark\Dashboard\Tools']['instance'], 'get_attachments' ], 10, 0 );
add_action( 'wp_ajax_easy-watermark/tools/get-attachments', [ $this->objects['EasyWatermark\Dashboard\Tools']['instance'], 'ajax_get_attachments' ], 10, 0 );
add_filter( 'easy-watermark/dashboard/tabs', [ $this->objects['EasyWatermark\Dashboard\Tools']['instance'], 'add_tab' ], 10, 1 );
add_action( 'easy-watermark/settings/register/general', [ $this->objects['EasyWatermark\Features\SrcsetFilter']['instance'], 'register_settings' ], 10, 1 );
add_filter( 'wp_calculate_image_srcset_meta', [ $this->objects['EasyWatermark\Features\SrcsetFilter']['instance'], 'wp_calculate_image_srcset_meta' ], 1000, 4 );
Expand Down
30 changes: 17 additions & 13 deletions src/views/dashboard/pages/tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,23 @@
<div class="content">
<p><?php esc_html_e( 'Using this tool you can quickly apply watermark to all images in the Media Library.', 'easy-watermark' ); ?></p>
<?php if ( count( $watermarks ) ) : ?>
<p>
<select class="watermark">
<option value="-1"><?php esc_html_e( 'Select Watermark', 'easy-watermark' ); ?></option>
<?php if ( 1 < count( $watermarks ) ) : ?>
<option value="all" data-nonce="<?php echo esc_attr( wp_create_nonce( 'apply_all' ) ); ?>"><?php esc_html_e( 'All Watermarks', 'easy-watermark' ); ?></option>
<?php endif; ?>
<?php foreach ( $watermarks as $watermark ) : ?>
<option value="<?php echo esc_attr( $watermark->ID ); ?>" data-nonce="<?php echo esc_attr( wp_create_nonce( 'apply_single-' . $watermark->ID ) ); ?>"><?php echo esc_html( $watermark->post_title ); ?></option>
<?php endforeach; ?>
</select>
</p>
<p><a href="#" class="button-primary"><?php esc_html_e( 'Start', 'easy-watermark' ); ?></a><span class="spinner"></span></p>
<p class="description"><?php esc_html_e( 'Note: The same watermark will never get applied twice to the same image. This tool is safe to use even if some of the images are already watermarked.', 'easy-watermark' ); ?></p>
<?php if ( count( $attachments ) ) : ?>
<p>
<select class="watermark">
<option value="-1"><?php esc_html_e( 'Select Watermark', 'easy-watermark' ); ?></option>
<?php if ( 1 < count( $watermarks ) ) : ?>
<option value="all" data-nonce="<?php echo esc_attr( wp_create_nonce( 'apply_all' ) ); ?>"><?php esc_html_e( 'All Watermarks', 'easy-watermark' ); ?></option>
<?php endif; ?>
<?php foreach ( $watermarks as $watermark ) : ?>
<option value="<?php echo esc_attr( $watermark->ID ); ?>" data-nonce="<?php echo esc_attr( wp_create_nonce( 'apply_single-' . $watermark->ID ) ); ?>"><?php echo esc_html( $watermark->post_title ); ?></option>
<?php endforeach; ?>
</select>
</p>
<p><a href="#" class="button-primary"><?php esc_html_e( 'Start', 'easy-watermark' ); ?></a><span class="spinner"></span></p>
<p class="description"><?php esc_html_e( 'Note: The same watermark will never get applied twice to the same image. This tool is safe to use even if some of the images are already watermarked.', 'easy-watermark' ); ?></p>
<?php else : ?>
<p><?php esc_html_e( 'There are no image attachments in your Media Library available for watermarking.', 'easy-watermark' ); ?></p>
<?php endif; ?>
<?php else : ?>
<?php $link = sprintf( '<a href="%s">%s</a>', admin_url( 'post-new.php?post_type=watermark' ), esc_html_x( 'create watermark', 'link text for new watermark page', 'easy-watermark' ) ); ?>
<?php /* translators: %s is a "create watermark" link */ ?>
Expand Down
Loading

0 comments on commit abacfcb

Please sign in to comment.