Skip to content

Commit

Permalink
Merge pull request #16 from zackpyle/Wordpress-Updater
Browse files Browse the repository at this point in the history
Wordpress updater
  • Loading branch information
zackpyle authored Aug 20, 2023
2 parents a2bd8e5 + fd74ea2 commit c6375aa
Show file tree
Hide file tree
Showing 10 changed files with 544 additions and 14 deletions.
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,63 @@ The last and what I think is the **best** feature is you also have the ability t

![frontend-dropdown](https://github.com/zackpyle/BBClassDropdown/assets/19413506/82d05c71-f675-4480-be2d-64e42924a1e4)


## Changelog

*v1.0.0 - 8/20/23*
- WP Updater connected so you can get the latest version pushed from Github straight to your WP install

*v0.7.0-beta - 8/19/23*
- Previously you could only clear existing classes/settings manually via a url query param. Now there is a new Reset button in the settings section at the bottom of the page
- After reset (and on initial activation), a new blank group is added so you don't have to click Add Group to get started

*v0.6.1-beta - 8/19/23*
- Fixed - v0.5.2 patch forgot to include rows and columns in the 'secondary modal' fix

*v0.6.0-beta - 8/19/23*
- New Import/Export Settings feature

*v0.5.2-beta - 8/18/23*
- Opening a secondary BB modal (like Post Module -> Custom Layout) would throw an error as the second modal assumed it was a module settings modal. Added more strict logic to look for the module settings modal

*v0.5.1-beta - 8/18/23*
- JS refactoring by badabingbreda

*v0.5.0-beta - 8/12/23*
- Drag and Drop reorder functionality for both Groups and Classes inside of Groups
- New table layout / styles
- Made the code more DRY
- First class or group can now be deleted if not only-child
- Don't need to confirm to delete an empty group
- Bug fixes

*v0.4.0-beta - 8/10/23*
- Feature - On groups with single selection substitute previous selected classname from optgroup with selection
- Feature - Fix for insertion of classes that are prefix of other classes. eg. if `uk-flex-center` already exists, you couln't add `uk-flex` later with callback handled by BB in (current) version 2.7.1.1
- Some code cleanup
- Renamed singleton checkbox from `checkbox` to `singleton` in all code.
- Select2 is enabled by default

*v0.3.3.0-beta - 8/7/23*
- Bug - SVG that holds symbols is taking up space on other tabs
- Bug - Typo when linking to Select2

*v0.3.2-beta - 8/7/23*
- Get rid of Remove Group on first group since you will never delete the first group

*v0.3.1-beta - 8/7/23*
- Bug fixes with disabled options
- Move Delete Group to same column as Delete Class

*v0.3.0-beta - 8/7/23*
- Gray out (disable) already used classes in the dropdown
- Add Select2 option

*v0.2.0-beta - 8/7/23*
- Settings page moved to Beaver Builder settings tab

*v0.1.1-beta - 8/6/23*
- Settings page saves to WP options

*v0.1.0-beta - 8/6/23*
- Initial commit
25 changes: 16 additions & 9 deletions bb-class-dropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,38 @@
*
* @package BBClassDropdown
* @author PYLE/DIGITAL
* @license GPL-2.0+
* @license GPL-3.0+
*
* @wordpress-plugin
* Plugin Name: Beaver Builder Class Dropdown
* Description: Adds user defined CSS classes to dropdown below the Beaver Builder class input in the Advanced tab
* Version: v0.7-beta
* Plugin URI: https://github.com/zackpyle/BBClassDropdown
* Description: BB Class Dropdown adds user defined CSS classes to dropdown below the Beaver Builder class input in the Advanced tab
* Version: 1.0
* Author: PYLE/DIGITAL
* Text Domain: textdomain
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: BBClassDropdown
* License: GPL-3.0+
* License URI: https://www.gnu.org/licenses/gpl-3.0.txt
*/


define( 'BBCLASSDROPDOWN_VERSION', '0.7' );
define( 'BBCLASSDROPDOWN_VERSION', '1.0' );
define( 'BBCLASSDROPDOWN_DIR', plugin_dir_path( __FILE__ ) );
define( 'BBCLASSDROPDOWN_FILE', __FILE__ );
define( 'BBCLASSDROPDOWN_URL', plugins_url( '/', __FILE__ ) );

// Include Updater files
require_once(BBCLASSDROPDOWN_DIR . 'includes/updater/Autoloader.php');
require_once(BBCLASSDROPDOWN_DIR . 'includes/updater/GithubUpdater.php');
require_once(BBCLASSDROPDOWN_DIR . 'includes/updater/Init.php');

// Include plugin files
require_once( BBCLASSDROPDOWN_DIR . 'includes/bb-class-dropdown-functions.php');
require_once( BBCLASSDROPDOWN_DIR . 'includes/bb-class-dropdown-admin.php');

register_activation_hook( BBCLASSDROPDOWN_FILE, 'beaver_builder_class_dropdown_plugin_activate' );

// Initialize updater
new BBClassDropdown\Includes\Updater\Init();

add_action( 'init', 'maybe_load_scripts' );
add_action( 'init', 'clear_bb_class_options' );
Expand Down Expand Up @@ -145,7 +152,7 @@ function beaver_builder_class_dropdown_plugin_activate() {
// Check if Beaver Builder is active
if ( ! class_exists( 'FLBuilder' ) ) {
deactivate_plugins( plugin_basename( __FILE__ ) );
wp_die( esc_html__( 'Sorry, but this plugin requires Beaver Builder.', 'textdomain' ) );
wp_die( esc_html__( 'Sorry, but this plugin requires Beaver Builder.', 'BBClassDropdown' ) );
}

// Flush rewrite rules
Expand All @@ -167,7 +174,7 @@ function clear_bb_class_options() {
}
}
function bb_class_options_reset_notice() {
echo '<div class="notice notice-success is-dismissible updated"><p>' . esc_html__('Classes reset!', 'textdomain') . '</p></div>';
echo '<div class="notice notice-success is-dismissible updated"><p>' . esc_html__('Classes reset!', 'BBClassDropdown') . '</p></div>';
}

/**
Expand Down
Binary file added includes/assets/banner-772x250.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added includes/assets/icon-128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added includes/assets/icon-256x256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions includes/bb-class-dropdown-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ function beaver_builder_class_dropdown_settings_page_html() {
<thead>
<tr>
<th id="handle-th"></th> <!-- Empty th for the handle -->
<th id="group-name-th" scope="row"><?php esc_html_e( 'Group', 'textdomain' ); ?></th>
<th id="class-th"><?php esc_html_e( 'Class / Label', 'textdomain' ); ?></th>
<th id="group-name-th" scope="row"><?php esc_html_e( 'Group', 'BBClassDropdown' ); ?></th>
<th id="class-th"><?php esc_html_e( 'Class / Label', 'BBClassDropdown' ); ?></th>
<th id="button-th"></th> <!-- Empty th for the buttons -->
</tr>
</thead>
Expand Down
6 changes: 3 additions & 3 deletions includes/bb-class-dropdown-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function beaver_builder_class_dropdown_class_class_dropdown( $field, $field_key
// Process field
if ( 'class' == $field_key && isset( $options['groups'] ) && is_array( $options['groups'] ) ) {
$field['options'] = array(
'' => esc_html__( '- Choose from predefined classes -', 'textdomain' ),
'' => esc_html__( '- Choose from predefined classes -', 'BBClassDropdown' ),
);

foreach ( $options['groups'] as $group ) {
Expand Down Expand Up @@ -48,8 +48,8 @@ function beaver_builder_class_dropdown_class_class_dropdown( $field, $field_key

// Add plugin settings link to plugin listing
function beaver_builder_class_dropdown_settings_link( $links ) {
$settings_link = '<a href="' . esc_url( admin_url( 'options-general.php?page=beaver-builder-class-dropdown' ) ) . '">' . esc_html__( 'Settings', 'textdomain' ) . '</a>';
$settings_link = '<a href="' . esc_url( admin_url( 'options-general.php?page=beaver-builder-class-dropdown' ) ) . '">' . esc_html__( 'Settings', 'BBClassDropdown' ) . '</a>';
array_push( $links, $settings_link );
return $links;
}
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'beaver_builder_class_dropdown_settings_link' );
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'beaver_builder_class_dropdown_settings_link' );
91 changes: 91 additions & 0 deletions includes/updater/Autoloader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php
/**
* Autoloader class
*
* @package BBClassDropdown
* @since 1.0.0
*/

namespace BBClassDropdown\Includes\Updater;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}

/**
* Loads classes from the plugin's namespace when requested.
*
* Without an autoloader, we would have to `require` or `include` every class file ourselves. An autoloader takes care
* of this for us.
*
* @since 1.0.0
*/
class Autoloader {

/**
* Namespace prefix of all classes this autoloader should handle, trailing slash included.
*
* @since 1.0.0
* @var string
*/
const AUTOLOADED_NAMESPACE_PREFIX = 'BBClassDropdown\\';

/**
* Loads the class file if it is in the autoloaded namespace.
*
* @since 1.0.0
*
* @param string $class The class' fully-qualified class name (e.g. \Foo\Bar\Baz).
*/
public function autoload( $class ) {
if ( $this->is_class_in_autoloaded_namespace( $class ) ) {
$this->load_class( $class );
}
}

/**
* Checks if the class' namespace prefix is within the autoloaded namespace.
*
* @since 1.0.0
*
* @param string $class The class' fully-qualified class name.
* @return bool
*/
private function is_class_in_autoloaded_namespace( $class ) {
$prefix_length = strlen( self::AUTOLOADED_NAMESPACE_PREFIX );

return 0 === strncmp( self::AUTOLOADED_NAMESPACE_PREFIX, $class, $prefix_length );
}

/**
* Loads the file containing the class if it exists.
*
* @since 1.0.0
*
* @param string $class The class' fully-qualified class name.
*/
private function load_class( $class ) {
$file_path = $this->get_class_file_path( $class );

if ( file_exists( $file_path ) ) {
require $file_path;
}
}

/**
* Converts a fully-qualified class name into a path to the file where the class is defined.
*
* E.g. converts `\BBClassDropdown\Foo\Bar` into `<plugin root directory>/includes/Updater/Foo/Bar.php`.
*
* @since 1.0.0
*
* @param string $class The class' fully-qualified class name.
* @return string Path to the file where we expect to find the class definition.
*/
private function get_class_file_path( $class ) {
$relative_class_path = substr( $class, strlen( self::AUTOLOADED_NAMESPACE_PREFIX ) );
$relative_file_path = str_replace( '\\', '/', $relative_class_path ) . '.php';

return dirname( BBCLASSDROPDOWN_FILE ) . '/includes/Updater/' . $relative_file_path;
}
}
Loading

0 comments on commit c6375aa

Please sign in to comment.