Skip to content

Commit

Permalink
add filters (#105)
Browse files Browse the repository at this point in the history
* add filters

* add connect plugin file name

* add premium url filters

* add comments and remove unused prop

* remove option_bg_connect_configs filter

* update version numbers
  • Loading branch information
jamesros161 authored May 26, 2022
1 parent f225b4c commit 93602b2
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ composer require boldgrid/library

## Changelog ##

### 2.13.7 ###

Release date: May 25th, 2022

* Update: Add filters to premium urls.
* Update: Add fallback filters for IMH Central users when Boldgrid Connect plugin is inactive.

### 2.13.6 ###

Release date: March 15th, 2022
Expand Down
110 changes: 110 additions & 0 deletions src/Library/Configs/IMH_Central.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php
/**
* BoldGrid Library Configs IMH Central Class
*
* This class is used to add filters for IMH Central users
* in the event that the Boldgrid Connect plugin is not active to
* run the filters itself.
*
* @package Boldgrid\Library
* @subpackage \Library\Configs
*
* @version 1.0.0
* @author BoldGrid <wpb@boldgrid.com>
*/

namespace Boldgrid\Library\Library\Configs;

class IMH_Central {
/**
* Constructor
*
* @since 1.0.0
*/
public function __construct() {
if ( ! get_option( 'bg_connect_configs' ) ) {
return;
}

include_once ABSPATH . 'wp-admin/includes/plugin.php';

if ( \is_plugin_active( 'boldgrid-connect/boldgrid-connect.php' ) ) {
return;
}

self::imh_central_filters();
}

/**
* Add filters to the IMH Central plugin.
*
* @since 1.0.0
*/
public static function imh_central_filters() {
$option_configs = get_option( 'bg_connect_configs' );

add_filter(
'BoldgridDemo/configs',
function( $configs ) use ( $option_configs ) {
$configs['servers']['asset'] = ! empty( $option_configs['asset_server'] ) ? $option_configs['asset_server'] : $configs['servers']['asset'];
return $configs;
}
);

// Inspirations
add_filter(
'boldgrid_inspirations_configs',
function ( $configs ) use ( $option_configs ) {
$configs['asset_server'] = ! empty( $option_configs['asset_server'] ) ? $option_configs['asset_server'] : $configs['servers']['asset'];
return $configs;
}
);

// BoldGrid Library
add_filter(
'Boldgrid\Library\Configs\set',
function( $configs ) use ( $option_configs ) {
$configs['api'] = ! empty( $option_configs['asset_server'] ) ? $option_configs['asset_server'] : $configs['api'];
return $configs;
}
);

// BoldGrid Connect Plugin.
add_filter(
'boldgrid_connect_config_setup_configs',
function( $configs ) use ( $option_configs ) {
$configs['asset_server'] = ! empty( $option_configs['asset_server'] ) ? $option_configs['asset_server'] : $configs['asset_server'];
$configs['central_url'] = ! empty( $option_configs['central_url'] ) ? $option_configs['central_url'] : $configs['central_url'];
return $configs;
}
);

/**
* Each of these filters represents a different premium url that can be overridden.
*
* To override these urls using the 'bg_connect_configs' option, add the url to the option
* array using the filter name as the key. For example, to override the boldgrid_editor_premium_url,
* we would set the following to the bg_connect_configs option:
* $options_configs[ 'boldgrid_editor_premium_url' ] = 'https://example.com/';
*/
$premium_url_filters = array(
'boldgrid_editor_premium_url',
'boldgrid_editor_new_key_url',
'boldgrid_editor_premium_download_url',
'boldgrid_backup_premium_url',
'bgtfw_premium_url',
'boldgrid_library_new_key_url',
'bgtfw_upgrade_url_pro_features',
);

foreach ( $premium_url_filters as $premium_url_filter ) {
add_filter(
$premium_url_filter,
function( $url ) use ( $option_configs, $premium_url_filter ) {
return ! empty( $option_configs[ $premium_url_filter ] ) ? $option_configs[ $premium_url_filter ] : $url;
}
);
}
}
}

4 changes: 3 additions & 1 deletion src/Library/Key/PostNewKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,14 @@ public static function getCentralUrl( $returnUrl = '' ) {

$returnUrl = add_query_arg( 'nonce', wp_create_nonce( 'bglib-key-prompt' ), $returnUrl );

$getNewKeyUrl = apply_filters( 'boldgrid_library_new_key_url', Configs::get( 'getNewKey' ) );

// Create the final url and return it.
return add_query_arg(
array(
'wp-url' => urlencode( $returnUrl ),
),
Configs::get( 'getNewKey' )
$getNewKeyUrl
);
}

Expand Down
2 changes: 2 additions & 0 deletions src/Library/Start.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ public function init() {
Configs::setItem( 'page-connect', new Page\Connect() );
Configs::setItem( 'assets', new Asset() );
new Editor();

new Configs\IMH_Central();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/library.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

return array(
// libraryVersion is used to put the version number on js/css files.
'libraryVersion' => '2.13.6',
'libraryVersion' => '2.13.7',
'api' => 'https://api.boldgrid.com',
'option' => 'license',
'key' => get_site_option( 'boldgrid_api_key', null ),
Expand Down

0 comments on commit 93602b2

Please sign in to comment.