Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Press0 1724 #9

Merged
merged 16 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/brand-plugin-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ jobs:
module-branch: ${{ needs.setup.outputs.branch }}
plugin-repo: 'bluehost/bluehost-wordpress-plugin'
plugin-branch: 'solutions'
sync-npm-package: true
secrets: inherit

# hostgator:
Expand All @@ -44,7 +43,6 @@ jobs:
# module-repo: ${{ github.repository }}
# module-branch: ${{ needs.setup.outputs.branch }}
# plugin-repo: 'newfold-labs/wp-plugin-hostgator'
# sync-npm-package: true
# secrets: inherit

# crazydomains:
Expand All @@ -55,5 +53,4 @@ jobs:
# module-repo: ${{ github.repository }}
# module-branch: ${{ needs.setup.outputs.branch }}
# plugin-repo: 'newfold-labs/wp-plugin-crazy-domains'
# sync-npm-package: true
# secrets: inherit
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 57 additions & 8 deletions includes/EntitlementsApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,19 @@ class EntitlementsApi {
* @var HiiveConnection
*/
private $hiive;

/**
* REST namespace
*
* @var string
*/
private $namespace;

/**
* REST base
*
* @var string
*/
private $rest_base;

/**
Expand Down Expand Up @@ -61,29 +73,41 @@ public function register_routes() {
},
)
);

// Add route for activating plugins
register_rest_route(
$this->namespace,
'/activate_plugin',
array(
'methods' => \WP_REST_Server::CREATABLE,
'callback' => array( $this, 'activate_plugins' ),
'permission_callback' => function () {
return current_user_can( 'manage_options' );
},
)
);
}

/**
* Set the transient where entitlements are stored (6 Hours).
*
* @param array $data
* @param array $data Data to be stored
* @param float|int $expiration Transient expiration.
*/
public function setTransient( $data, $expiration = 21600 ) {
public function set_the_transient( $data, $expiration = 21600 ) {
set_transient( self::TRANSIENT, $data, $expiration );
}

/**
* Get entitlements of a site.
*
*
* @return \WP_REST_Response|\WP_Error Response object on success, or WP_Error object on failure.
*/
public function get_items() {

// If there is no Hiive connection, bail.
if( ! HiiveConnection::is_connected()) {
if ( defined('WP_DEBUG') && true === WP_DEBUG ) {
if ( ! HiiveConnection::is_connected() ) {
if ( defined( 'WP_DEBUG' ) && true === WP_DEBUG ) {
// for debugging - use a local json file rather than hiive entitlement endpoint response
return new WP_REST_Response( json_decode( file_get_contents( NFD_SOLUTIONS_DIR . '/includes/js/debug.json' ) ), 218 );
}
Expand All @@ -104,7 +128,7 @@ public function get_items() {
),
)
);

if ( is_wp_error( $response ) ) {
return new WP_REST_Response( array( 'message' => 'An error occurred with the entitlements response.' ), 500 );
}
Expand All @@ -114,14 +138,39 @@ public function get_items() {
if (
$data &&
is_array( $data ) &&
array_key_exists('solutions', $data) &&
array_key_exists('categories', $data)
array_key_exists( 'solutions', $data ) &&
array_key_exists( 'categories', $data )
) {
$entitlements = $data;
set_the_transient( $entitlements );
}
}

return new WP_REST_Response( $entitlements, 200 );
}

/**
* Activate the plugin based on Plugin path
*
* @param \WP_REST_REQUEST $request Data to be stored
*/
public function activate_plugins( $request ) {
$plugin_path = json_decode( $request->get_body() )->plugin;
if ( $plugin_path ) {
activate_plugin( $plugin_path );
return new \WP_REST_Response(
array(
'message' => __( 'Activated the plugin successfully!', 'wp-module-solutions' ),
),
201
);
}
return new \WP_Error(
'nfd_module_solution_error',
__( 'Please send valid plugin', 'wp-module-solutions' ),
array(
'status' => 400,
),
);
}
}
35 changes: 23 additions & 12 deletions includes/Solutions.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ public function __construct( Container $container ) {
// We're trying to avoid adding more stuff to this.
$this->container = $container;

// add_filter( 'install_plugins_tabs', array( __CLASS__, 'add_my_plugins_and_tools_tab' ) );
// add_action( 'admin_head-plugin-install.php', array( __CLASS__, 'my_plugins_and_tools_tab_enqueue_assets' ) );
add_filter( 'install_plugins_tabs', array( __CLASS__, 'add_my_plugins_and_tools_tab' ) );
add_action( 'admin_head-plugin-install.php', array( __CLASS__, 'my_plugins_and_tools_tab_enqueue_assets' ) );

// do_action( 'qm/debug', 'Hello from the Solutions module!' );
add_action( 'rest_api_init', array( $this, 'init_entitilements_apis' ) );
}

Expand All @@ -49,11 +48,11 @@ public static function load_php_textdomain() {
* Load the textdomains for the module.
*/
public function register_textdomains() {
$MODULE_LANG_DIR = $this->container->plugin()->dir . 'vendor/newfold-labs/wp-module-solutions/languages';
\load_script_textdomain( 'nfd-solutions-dependency', 'wp-module-solutions', $MODULE_LANG_DIR );
$module_lang_dir = $this->container->plugin()->dir . 'vendor/newfold-labs/wp-module-solutions/languages';
\load_script_textdomain( 'nfd-solutions-dependency', 'wp-module-solutions', $module_lang_dir );
$current_language = get_locale();
\load_textdomain( 'wp-module-solutions', $MODULE_LANG_DIR . '/wp-module-solutions-' . $current_language . '.mo' );
}
\load_textdomain( 'wp-module-solutions', $module_lang_dir . '/wp-module-solutions-' . $current_language . '.mo' );
}

/**
* Load WP dependencies into the page.
Expand Down Expand Up @@ -87,15 +86,20 @@ public function init_entitilements_apis(): void {
$entitlements_api->register_routes();
}

/**
/**
* Add "My Plugins & tools" tab to plugins install tabs.
*
* @param array $tabs Collection of tabs.
*
* @return array
*/
public static function add_my_plugins_and_tools_tab( array $tabs ) {
$tabs['nfd_my_plugins_and_tools'] = __( 'My Plugins & Tools', 'wp-module-solutions' );
$hiive = new HiiveConnection();
$api = new EntitlementsApi( $hiive );
$entitlements = $api->get_items();
if ( is_array( $entitlements->data ) ? $entitlements->data['entitlements'] : $entitlements->data->entitlements ) {
$tabs['nfd_my_plugins_and_tools'] = __( 'My Plugins & Tools', 'wp-module-solutions' );
}

return $tabs;
}
Expand All @@ -108,8 +112,15 @@ public static function my_plugins_and_tools_tab_enqueue_assets() {
return;
}
wp_enqueue_style( 'nfd_myplugin_solutions_css', NFD_SOLUTIONS_PLUGIN_URL . 'vendor/newfold-labs/wp-module-solutions/includes/css/myPluginsTools.css', array(), '1.0' );
wp_enqueue_script('nfd_myplugin_solutions_js', NFD_SOLUTIONS_PLUGIN_URL . 'vendor/newfold-labs/wp-module-solutions/includes/js/myPluginsTools.js', array(), '1.0', true );

}
wp_enqueue_script( 'nfd_myplugin_solutions_js', NFD_SOLUTIONS_PLUGIN_URL . 'vendor/newfold-labs/wp-module-solutions/includes/js/myPluginsTools.js', array(), '1.0', true );

wp_localize_script(
'nfd_myplugin_solutions_js',
'plugin_details',
array(
'installed_plugins' => get_plugins(),
'active_plugins' => get_option( 'active_plugins' ),
)
);
}
}
41 changes: 36 additions & 5 deletions includes/css/myPluginsTools.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.nfd-solutions-availble-list{
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-columns: repeat( auto-fit, minmax(calc(33.1% - 8px), 1fr) );
gap: 16px;
margin-right: 20px;
}
Expand All @@ -13,26 +13,57 @@
padding: 20px;
}

.nfd-solutions-availble-list-item .details{
display: grid;
grid-template-columns: 2.5fr 0.5fr;
place-self: flex-start;
gap: 5px;
}

.nfd-solutions-availble-list-item .details p{
margin: 0px;
}

h3.nfd-solutions-availble-list-item-title{
margin-top: 0px;
}

/* learn more link */
.nfd-solutions-availble-list-item-button{
display: inline-block;
background: #2271b1;
border-color: #2271b1;
color: #fff;
color: #fff !important;
text-decoration: none;
text-shadow: none;
max-width: fit-content;
padding: 0 10px;
padding: 6px 10px;
cursor: pointer;
border-radius: 3px;
font-size: 13px;
line-height: 2.15384615;
min-height: 30px;
width: 82px;
}

/* hide the search field in my plugins && tools tab */
.wrap.plugin-install-tab-nfd_my_plugins_and_tools .search-form.search-plugins{
display: none;
}

/* responsive */
@media screen and (max-width: 782px) {

.nfd-solutions-availble-list{
display: flex;
flex-direction: column;
}
}

@media screen and (max-width: 1024px) {
.nfd-solutions-availble-list .details{
display: block;
}

.nfd-solutions-availble-list-item .details p{
margin: 1em 0;
}
}
Loading
Loading