Skip to content

Commit

Permalink
Prep for 0.7.1 release
Browse files Browse the repository at this point in the history
  • Loading branch information
dmhendricks committed Nov 18, 2017
1 parent 96e6640 commit fcfd2e5
Show file tree
Hide file tree
Showing 648 changed files with 167,332 additions and 36 deletions.
7 changes: 0 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,3 @@ package-lock.json
# NPM #
#######
node_modules

# Development #
###############
vendor/
assets/css/**/*.css
assets/css/**/*.map
assets/js/**/*.js
17 changes: 3 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ Until sufficient testing has been completed, you may [download an installable ZI

### Automatic Updates

Once I produce a release version, automatic updates will be available via WordPress. For now, you will have to update manually.

I have disabled GitHub Updater support because I don't want to store the `/vendor` folder in the repo (plus other technical reasons). when this plugin reaches a reasonable level of stability, automatic updates will be supported.
Once I produce a release version, automatic updates will be available via WordPress. For now, updates are supported via GitHub Updater.

## Known Compatibilities & Conflicts

Expand All @@ -64,8 +62,7 @@ If you encounter any other in/compatibilities, please [report them](https://gith

#### Immediate

* Bug: When uploading images via "Add Media" from post editor, resized images do not upload
* Bug: Settings defaults do not work (I am waiting for a CF update to address this)
* Bug: Settings defaults do not work
* Significant testing in various environments

#### Medium-Term
Expand All @@ -88,15 +85,7 @@ Release changes will be noted on the [Releases](https://github.com/dmhendricks/b

#### Branch: `master`

* Completely refactored code
* Switched from direct API calls to a fork of [Backblaze B2 SDK for PHP](https://github.com/cwhite92/b2-sdk-php/)
* Added option to delete local media after being uploaded to B2.
* Added initial POT translation file
* Added setting to register custom MIME types
* Fixed unhandled exception triggered by invalid API credentials
* Fixed image dimensions bug when inserting images into a post
* Fixed exception when trying to delete file that does not exist
* Added support for resized images
* None

## Credits

Expand Down
4 changes: 2 additions & 2 deletions app/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ public function check_api_credentials() {
*/
public function post_mime_types_filter( $post_mime_types ) {

$post_mime_types['application'] = array( __( 'Document', self::$textdomain ), __( 'Manage Documents', self::$textdomain ), _n_noop( 'Document', 'Documents' ) . ' <span class="count">(%s)</span>' );
return $post_mime_types;
$post_mime_types['application'] = array( __( 'Document', self::$textdomain ), __( 'Manage Documents', self::$textdomain ), _n_noop( 'Document', 'Documents <span class="count">(%s)</span>' ) );
return $post_mime_types;

}

Expand Down
82 changes: 82 additions & 0 deletions app/Datastores/Serialized_Theme_Options_Datastore.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
namespace Carbon_Fields\Datastore\Datastore;
use Carbon_Fields\Field\Field;
use Carbon_Fields\Datastore\Datastore;

/**
* Stores serialized values in the database
*/
class Serialized_Theme_Options_Datastore extends Datastore {

/**
* Initialization tasks for concrete datastores.
**/
public function init() {

}

protected function get_key_for_field( Field $field ) {
$key = '_' . $field->get_base_name();
return $key;
}

/**
* Save a single key-value pair to the database with autoload
*
* @param string $key
* @param string $value
* @param bool $autoload
*/
protected function save_key_value_pair_with_autoload( $key, $value, $autoload ) {
$notoptions = wp_cache_get( 'notoptions', 'options' );
$notoptions[ $key ] = '';
wp_cache_set( 'notoptions', $notoptions, 'options' );
$autoload = $autoload ? 'yes' : 'no';

if ( ! add_option( $key, $value, null, $autoload ) ) {
update_option( $key, $value, $autoload );
}
}

/**
* Load the field value(s)
*
* @param Field $field The field to load value(s) in.
* @return array
*/
public function load( Field $field ) {
$key = $this->get_key_for_field( $field );
$value = get_option( $key, null );
return $value;
}

/**
* Save the field value(s)
*
* @param Field $field The field to save.
*/
public function save( Field $field ) {
if ( ! empty( $field->get_hierarchy() ) ) {
return; // only applicable to root fields
}
$key = $this->get_key_for_field( $field );
$value = $field->get_full_value();
if ( is_a( $field, '\\Carbon_Fields\\Field\\Complex_Field' ) ) {
$value = $field->get_value_tree();
}
$this->save_key_value_pair_with_autoload( $key, $value, $field->get_autoload() );
}

/**
* Delete the field value(s)
*
* @param Field $field The field to delete.
*/
public function delete( Field $field ) {
if ( ! empty( $field->get_hierarchy() ) ) {
return; // only applicable to root fields
}
$key = $this->get_key_for_field( $field );
delete_option( $key );
}
}
4 changes: 2 additions & 2 deletions app/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function init() {
}

if( $this->verify_dependencies( 'carbon_fields' ) === true ) {
add_action( 'carbon_fields_loaded', array( $this, 'load_plugin' ));
add_action( 'carbon_fields_fields_registered', array( $this, 'load_plugin' ));
}

}
Expand Down Expand Up @@ -194,7 +194,7 @@ public function get_plugin_option( $key, $cache = true ) {
* @return string Prefixed string/field value
* @since 0.2.0
*/
public function prefix( $field_name = null, $start = '' ) {
public static function prefix( $field_name = null, $start = '' ) {
return $field_name !== null ? $start . self::$config->get( 'prefix' ) . $field_name : self::$config->get( 'prefix' );
}

Expand Down
17 changes: 11 additions & 6 deletions app/Settings/Plugin_Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use TwoLabNet\BackblazeB2\Plugin;
use TwoLabNet\BackblazeB2\Helpers;
use WordPress_ToolKit\ConfigRegistry;
use Carbon_Fields\Datastore\Datastore\Serialized_Theme_Options_Datastore;
use Carbon_Fields\Container;
use Carbon_Fields\Field;

Expand All @@ -13,6 +14,8 @@
*/
class Plugin_Settings extends Plugin {

// https://raw.githubusercontent.com/dmhendricks/WordPressSVGPlugin/master/wp-content/plugins/lc-wp-svg/index.php

protected $settings_containers;

public function __construct() {
Expand All @@ -26,9 +29,9 @@ public function __construct() {
// Create tabbed plugin options page (Settings > Plugin Name)
$this->create_tabbed_options_page();

// Register uninstall hook to delete settings
// Register uninstall hook to delete settings (registered as static method due to WP requirements)
if( $this->get_plugin_option( 'uninstall_remove_settings' ) ) {
register_uninstall_hook( self::$config->get( 'plugin/identifier' ), array( $this, 'plugin_settings_uninstall' ) );
register_uninstall_hook( self::$config->get( 'plugin/identifier' ), 'self::plugin_settings_uninstall' );
}

// Register custom MIME types
Expand Down Expand Up @@ -58,13 +61,14 @@ public function create_tabbed_options_page() {
->help_text( __( 'If enabled, uploaded files will be deleted from your web host after they are uploaded to Backblaze B2.', self::$textdomain ) . '<br />' . __( '<strong>Note:</strong> This may cause incompatibilities with other plugins that rely on a local copy of uploaded media. If you deactivate this plugin, the media links will be broken.', self::$textdomain ) ),
Field::make( 'checkbox', $this->prefix( 'add_media_library_document_type' ), __( 'Add "Document" to Media Library Filter Dropdown', self::$textdomain ) )
->help_text( __( 'For convenience, adds a <em>Document</em> file type to the Media Library dropdown filter.', self::$textdomain ) ),
/*
Field::make( 'checkbox', $this->prefix( 'uninstall_remove_settings' ), __( 'Delete Plugin Settings On Uninstall', self::$textdomain ) )
->help_text( __( 'Settings will only be deleted if you remove the plugin from Installed Plugins. They will not be removed by simply deactivating the plugin.', self::$textdomain ) ),
*/
Field::make( 'separator', $this->prefix( 'separator_general_credentials' ), __( 'Access Credentials', self::$textdomain ) ),
Field::make( 'html', $this->prefix( 'html_general_credentials' ) )
->set_html( __( 'You can find these values by logging into your <a href="https://www.backblaze.com/b2/cloud-storage.html#af9kre" target="_blank">Backblaze</a> account, clicking <strong>Buckets</strong>, then clicking the <strong>Show Account ID and Application Key</strong> link.', self::$textdomain ) ),
Field::make( 'text', $this->prefix( 'account_id' ), __( 'Account ID', self::$textdomain ) )
->set_attribute( 'type', 'password' ),
Field::make( 'text', $this->prefix( 'account_id' ), __( 'Account ID', self::$textdomain ) ),
Field::make( 'text', $this->prefix( 'application_key' ), __('Application Key', self::$textdomain ) )
->set_attribute( 'type', 'password' ),
Field::make( 'separator', $this->prefix( 'separator_general_bucket_path' ), __( 'Bucket & Path', self::$textdomain ) ),
Expand All @@ -81,6 +85,7 @@ public function create_tabbed_options_page() {
Field::make( 'checkbox', $this->prefix( 'limit_mime_types' ), __( 'Limit to Specific MIME Types', self::$textdomain ) )
->help_text( __( 'If checked, uploads to Backblaze B2 are limited to specific MIME types.', self::$textdomain ) ),
Field::make( 'complex', $this->prefix( 'custom_mime_types' ), __( 'Custom MIME Types', self::$textdomain ) )
->set_datastore( new Serialized_Theme_Options_Datastore() )
->add_fields( array(
Field::make( 'text', 'label', __( 'Extension/Label', self::$textdomain ) )
->set_attribute( 'placeholder', __( 'Example:', self::$textdomain ) . ' WEBP' ),
Expand Down Expand Up @@ -109,7 +114,7 @@ public function create_tabbed_options_page() {
'value' => true )
)
)
->set_default_value( array( 'image/jpeg', 'image/png', 'image/gif', 'image/bmp', 'image/tiff', 'image/svg', 'image/svgz' ) )
//->set_default_value( array( 'image/jpeg', 'image/png', 'image/gif', 'image/bmp', 'image/tiff', 'image/svg', 'image/svgz' ) )
->add_options( $this->get_formatted_mime_types() ),
)
);
Expand Down Expand Up @@ -146,7 +151,7 @@ private function get_formatted_mime_types() {
*
* @since 0.3.0
*/
public function plugin_settings_uninstall() {
public static function plugin_settings_uninstall() {

foreach( $this->settings_containers as $container ) {

Expand Down
5 changes: 3 additions & 2 deletions backblaze.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
* Plugin Name: Backblaze B2 Media Offloader
* Plugin URI: https://github.com/dmhendricks/backblaze-media-offloader
* Description: A simple plugin that allows you to serve your WordPress Media Library files via the Backblaze B2 cloud storage service.
* Version: 0.7.0
* Version: 0.7.1
* Author: Daniel M. Hendricks
* Author URI: https://www.danhendricks.com
* License: GPL-2.0
* License URI: https://opensource.org/licenses/GPL-2.0
* Text Domain: backblaze-media-offloader
* Domain Path: languages
* GitHub Plugin URI: dmhendricks/backblaze-media-offloader
*/

/* Copyright 2017 Daniel M. Hendricks (https://www.danhendricks.com/)
/* Copyright 2018 Daniel M. Hendricks (https://www.danhendricks.com/)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "dmhendricks/backblaze-media-offloader",
"type": "wordpress-plugin",
"description": "A bloilerplate for WordPress plugins",
"version": "0.7.1",
"keywords": ["wordpress", "plugin", "boilerplate", "carbonfields"],
"homepage": "https://2lab.net",
"license": "GPL-2.0",
Expand Down Expand Up @@ -33,7 +34,8 @@
"minimum-stability": "dev",
"autoload": {
"psr-4": {
"TwoLabNet\\BackblazeB2\\": "app/"
"TwoLabNet\\BackblazeB2\\": "app/",
"Carbon_Fields\\Datastore\\Datastore\\": "app/Datastores/"
}
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Tags: backblaze,b2,media,uploads,images,cdn
Plugin URI: https://github.com/dmhendricks/backblaze-media-offloader
Donate link: https://paypal.me/danielhendricks
Requires at least: 4.0
Tested up to: 4.8.2
Stable tag: 0.7.0
Tested up to: 4.9
Stable tag: 0.7.1
License: GPL-2.0
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down
7 changes: 7 additions & 0 deletions vendor/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// autoload.php @generated by Composer

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit8ec2436e403d1a777ab7e806a958bca9::getLoader();
Loading

0 comments on commit fcfd2e5

Please sign in to comment.