Initial commit: Atomaste website
This commit is contained in:
@@ -0,0 +1,292 @@
|
||||
<?php
|
||||
/**
|
||||
* Rara_Business Customizer Notification Section Class.
|
||||
*
|
||||
* @package Rara_Business
|
||||
*/
|
||||
|
||||
/**
|
||||
* Rara_Business_Customizer_Notice_Section class
|
||||
*/
|
||||
class Rara_Business_Customizer_Notice_Section extends WP_Customize_Section {
|
||||
/**
|
||||
* The type of customize section being rendered.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
public $type = 'customizer-plugin-notice-section';
|
||||
/**
|
||||
* Custom button text to output.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
public $recommended_actions = '';
|
||||
/**
|
||||
* Recommended Plugins.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $recommended_plugins = '';
|
||||
/**
|
||||
* Total number of required actions.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $total_actions = '';
|
||||
/**
|
||||
* Plugin text.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $plugin_text = '';
|
||||
/**
|
||||
* Dismiss button.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $dismiss_button = '';
|
||||
|
||||
/**
|
||||
* Check if plugin is installed/activated
|
||||
*
|
||||
* @param plugin-slug $slug the plugin slug.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function check_active( $slug ) {
|
||||
if ( file_exists( ABSPATH . 'wp-content/plugins/' . $slug . '/' . $slug . '.php' ) ) {
|
||||
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
||||
|
||||
$needs = is_plugin_active( $slug . '/' . $slug . '.php' ) ? 'deactivate' : 'activate';
|
||||
|
||||
return array(
|
||||
'status' => is_plugin_active( $slug . '/' . $slug . '.php' ),
|
||||
'needs' => $needs,
|
||||
);
|
||||
}
|
||||
|
||||
return array(
|
||||
'status' => false,
|
||||
'needs' => 'install',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the install/activate button link for plugins
|
||||
*
|
||||
* @param plugin-state $state The plugin state (not installed/inactive/active).
|
||||
* @param plugin-slug $slug The plugin slug.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function create_action_link( $state, $slug ) {
|
||||
switch ( $state ) {
|
||||
case 'install':
|
||||
return wp_nonce_url(
|
||||
add_query_arg(
|
||||
array(
|
||||
'action' => 'install-plugin',
|
||||
'plugin' => $slug,
|
||||
),
|
||||
network_admin_url( 'update.php' )
|
||||
),
|
||||
'install-plugin_' . $slug
|
||||
);
|
||||
break;
|
||||
case 'deactivate':
|
||||
return add_query_arg(
|
||||
array(
|
||||
'action' => 'deactivate',
|
||||
'plugin' => rawurlencode( $slug . '/' . $slug . '.php' ),
|
||||
'plugin_status' => 'all',
|
||||
'paged' => '1',
|
||||
'_wpnonce' => wp_create_nonce( 'deactivate-plugin_' . $slug . '/' . $slug . '.php' ),
|
||||
), network_admin_url( 'plugins.php' )
|
||||
);
|
||||
break;
|
||||
case 'activate':
|
||||
return add_query_arg(
|
||||
array(
|
||||
'action' => 'activate',
|
||||
'plugin' => rawurlencode( $slug . '/' . $slug . '.php' ),
|
||||
'plugin_status' => 'all',
|
||||
'paged' => '1',
|
||||
'_wpnonce' => wp_create_nonce( 'activate-plugin_' . $slug . '/' . $slug . '.php' ),
|
||||
), network_admin_url( 'plugins.php' )
|
||||
);
|
||||
break;
|
||||
}// End switch().
|
||||
}
|
||||
|
||||
/**
|
||||
* Call plugin API to get plugins info
|
||||
*
|
||||
* @param plugin-slug $slug The plugin slug.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function call_plugin_api( $slug ) {
|
||||
include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
|
||||
$call_api = get_transient( 'cust_notice_plugin_info_' . $slug );
|
||||
if ( false === $call_api ) {
|
||||
$call_api = plugins_api(
|
||||
'plugin_information', array(
|
||||
'slug' => $slug,
|
||||
'fields' => array(
|
||||
'downloaded' => false,
|
||||
'rating' => false,
|
||||
'description' => false,
|
||||
'short_description' => true,
|
||||
'donate_link' => false,
|
||||
'tags' => false,
|
||||
'sections' => false,
|
||||
'homepage' => false,
|
||||
'added' => false,
|
||||
'last_updated' => false,
|
||||
'compatibility' => false,
|
||||
'tested' => false,
|
||||
'requires' => false,
|
||||
'downloadlink' => false,
|
||||
'icons' => false,
|
||||
),
|
||||
)
|
||||
);
|
||||
set_transient( 'cust_notice_plugin_info_' . $slug, $call_api, 30 * MINUTE_IN_SECONDS );
|
||||
}
|
||||
|
||||
return $call_api;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add custom parameters to pass to the JS via JSON.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function json() {
|
||||
$json = parent::json();
|
||||
global $rara_business_recommended_plugins;
|
||||
|
||||
global $install_button_label;
|
||||
global $activate_button_label;
|
||||
global $deactivate_button_label;
|
||||
|
||||
$customize_plugins = array();
|
||||
|
||||
$show_recommended_plugins = get_option( 'rara_business_show_recommended_plugins' );
|
||||
|
||||
foreach ( $rara_business_recommended_plugins as $slug => $plugin_opt ) {
|
||||
|
||||
if ( ! $plugin_opt['recommended'] ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( isset( $show_recommended_plugins[ $slug ] ) && $show_recommended_plugins[ $slug ] ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$active = $this->check_active( $slug );
|
||||
|
||||
if ( ! empty( $active['needs'] ) && ( $active['needs'] == 'deactivate' ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$rara_business_recommended_plugin['url'] = $this->create_action_link( $active['needs'], $slug );
|
||||
if ( $active['needs'] !== 'install' && $active['status'] ) {
|
||||
$rara_business_recommended_plugin['class'] = 'active';
|
||||
} else {
|
||||
$rara_business_recommended_plugin['class'] = '';
|
||||
}
|
||||
|
||||
switch ( $active['needs'] ) {
|
||||
case 'install':
|
||||
$rara_business_recommended_plugin['button_class'] = 'install-now button';
|
||||
$rara_business_recommended_plugin['button_label'] = $install_button_label;
|
||||
break;
|
||||
case 'activate':
|
||||
$rara_business_recommended_plugin['button_class'] = 'activate-now button button-primary';
|
||||
$rara_business_recommended_plugin['button_label'] = $activate_button_label;
|
||||
break;
|
||||
case 'deactivate':
|
||||
$rara_business_recommended_plugin['button_class'] = 'deactivate-now button';
|
||||
$rara_business_recommended_plugin['button_label'] = $deactivate_button_label;
|
||||
break;
|
||||
}
|
||||
$info = $this->call_plugin_api( $slug );
|
||||
$rara_business_recommended_plugin['id'] = $slug;
|
||||
$rara_business_recommended_plugin['plugin_slug'] = $slug;
|
||||
|
||||
if ( ! empty( $plugin_opt['description'] ) ) {
|
||||
$rara_business_recommended_plugin['description'] = $plugin_opt['description'];
|
||||
} else {
|
||||
$rara_business_recommended_plugin['description'] = $info->short_description;
|
||||
}
|
||||
|
||||
$rara_business_recommended_plugin['title'] = $info->name;
|
||||
|
||||
$customize_plugins[] = $rara_business_recommended_plugin;
|
||||
|
||||
}// End foreach().
|
||||
|
||||
$json['recommended_plugins'] = $customize_plugins;
|
||||
$json['plugin_text'] = $this->plugin_text;
|
||||
$json['dismiss_button'] = $this->dismiss_button;
|
||||
return $json;
|
||||
|
||||
}
|
||||
/**
|
||||
* Outputs the structure for the customizer control
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
protected function render_template() {
|
||||
?>
|
||||
<# if( data.recommended_plugins.length > 0 ){ #>
|
||||
<li id="accordion-section-{{ data.id }}" class="accordion-section control-section control-section-{{ data.type }} cannot-expand">
|
||||
|
||||
<h3 class="accordion-section-title">
|
||||
<span class="section-title" data-plugin_text="{{ data.plugin_text }}">
|
||||
<# if( data.recommended_plugins.length > 0 ){ #>
|
||||
{{ data.plugin_text }}
|
||||
<# } #>
|
||||
</span>
|
||||
</h3>
|
||||
<div class="recomended-actions_container" id="plugin-filter">
|
||||
<# if( data.recommended_plugins.length > 0 ){ #>
|
||||
<# for (action in data.recommended_plugins) { #>
|
||||
<div class="rara-recommeded-actions-container rara-recommended-plugins" data-index="{{ data.recommended_plugins[action].index }}">
|
||||
<# if( !data.recommended_plugins[action].check ){ #>
|
||||
<div class="rara-recommeded-actions">
|
||||
<p class="title">{{ data.recommended_plugins[action].title }}</p>
|
||||
<span data-action="dismiss" class="dashicons dashicons-no dismiss-button-recommended-plugin" id="{{ data.recommended_plugins[action].id }}"></span>
|
||||
<div class="description">{{{ data.recommended_plugins[action].description }}}</div>
|
||||
<# if( data.recommended_plugins[action].plugin_slug ){ #>
|
||||
<div class="custom-action">
|
||||
<p class="plugin-card-{{ data.recommended_plugins[action].plugin_slug }} action_button {{ data.recommended_plugins[action].class }}">
|
||||
<a data-slug="{{ data.recommended_plugins[action].plugin_slug }}"
|
||||
class="{{ data.recommended_plugins[action].button_class }}"
|
||||
href="{{ data.recommended_plugins[action].url }}">{{ data.recommended_plugins[action].button_label }}</a>
|
||||
</p>
|
||||
</div>
|
||||
<# } #>
|
||||
<# if( data.recommended_plugins[action].help ){ #>
|
||||
<div class="custom-action">{{{ data.recommended_plugins[action].help }}}</div>
|
||||
<# } #>
|
||||
</div>
|
||||
<# } #>
|
||||
</div>
|
||||
<# } #>
|
||||
<# } #>
|
||||
</div>
|
||||
</li>
|
||||
<# } #>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
/**
|
||||
* Rara Business Customizer Notification System.
|
||||
*
|
||||
* @package Rara_Business
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* TI Customizer Notify Class
|
||||
*/
|
||||
class Rara_Business_Customizer_Notice {
|
||||
|
||||
/**
|
||||
* Recommended plugins
|
||||
*
|
||||
* @var array $recommended_plugins Recommended plugins displayed in customize notification system.
|
||||
*/
|
||||
private $recommended_plugins;
|
||||
|
||||
/**
|
||||
* The single instance of Rara_Business_Customizer_Notice
|
||||
*
|
||||
* @var Rara_Business_Customizer_Notice $instance The Rara_Business_Customizer_Notice instance.
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* Title of Recommended plugins section in customize
|
||||
*
|
||||
* @var string $recommended_plugins_title Title of Recommended plugins section displayed in customize notification system.
|
||||
*/
|
||||
private $recommended_plugins_title;
|
||||
|
||||
/**
|
||||
* Dismiss button label
|
||||
*
|
||||
* @var string $dismiss_button Dismiss button label displayed in customize notification system.
|
||||
*/
|
||||
private $dismiss_button;
|
||||
|
||||
/**
|
||||
* Install button label for plugins
|
||||
*
|
||||
* @var string $install_button_label Label of install button for plugins displayed in customize notification system.
|
||||
*/
|
||||
private $install_button_label;
|
||||
|
||||
/**
|
||||
* Activate button label for plugins
|
||||
*
|
||||
* @var string $activate_button_label Label of activate button for plugins displayed in customize notification system.
|
||||
*/
|
||||
private $activate_button_label;
|
||||
|
||||
/**
|
||||
* Deactivate button label for plugins
|
||||
*
|
||||
* @var string $deactivate_button_label Label of deactivate button for plugins displayed in customize notification system.
|
||||
*/
|
||||
private $deactivate_button_label;
|
||||
|
||||
/**
|
||||
* The Main Rara_Business_Customizer_Notice instance.
|
||||
*
|
||||
* We make sure that only one instance of Rara_Business_Customizer_Notice exists in the memory at one time.
|
||||
*
|
||||
* @param array $config The configuration array.
|
||||
*/
|
||||
public static function init( $config ) {
|
||||
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Rara_Business_Customizer_Notice ) ) {
|
||||
self::$instance = new Rara_Business_Customizer_Notice;
|
||||
if ( ! empty( $config ) && is_array( $config ) ) {
|
||||
self::$instance->config = $config;
|
||||
self::$instance->setup_config();
|
||||
self::$instance->setup_actions();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the class props based on the config array.
|
||||
*/
|
||||
public function setup_config() {
|
||||
|
||||
// global arrays for recommended plugins/actions
|
||||
global $rara_business_recommended_plugins;
|
||||
global $install_button_label;
|
||||
global $activate_button_label;
|
||||
global $deactivate_button_label;
|
||||
|
||||
$this->recommended_plugins = isset( $this->config['recommended_plugins'] ) ? $this->config['recommended_plugins'] : array();
|
||||
$this->recommended_plugins_title = isset( $this->config['recommended_plugins_title'] ) ? $this->config['recommended_plugins_title'] : '';
|
||||
$this->dismiss_button = isset( $this->config['dismiss_button'] ) ? $this->config['dismiss_button'] : '';
|
||||
|
||||
$rara_business_recommended_plugins = array();
|
||||
|
||||
if ( isset( $this->recommended_plugins ) ) {
|
||||
$rara_business_recommended_plugins = $this->recommended_plugins;
|
||||
}
|
||||
|
||||
$install_button_label = isset( $this->config['install_button_label'] ) ? $this->config['install_button_label'] : '';
|
||||
$activate_button_label = isset( $this->config['activate_button_label'] ) ? $this->config['activate_button_label'] : '';
|
||||
$deactivate_button_label = isset( $this->config['deactivate_button_label'] ) ? $this->config['deactivate_button_label'] : '';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the actions used for this class.
|
||||
*/
|
||||
public function setup_actions() {
|
||||
|
||||
// Register the section
|
||||
add_action( 'customize_register', array( $this, 'customize_register_notice' ) );
|
||||
|
||||
// Enqueue scripts and styles
|
||||
add_action( 'customize_controls_enqueue_scripts', array( $this, 'scripts_for_customizer' ), 0 );
|
||||
|
||||
/* ajax callback for dismissable recommended plugins */
|
||||
add_action( 'wp_ajax_dismiss_recommended_plugins', array( $this, 'dismiss_recommended_plugins_callback' ) );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Scripts and styles used in the Themeisle_Customizer_Notify class
|
||||
*/
|
||||
public function scripts_for_customizer() {
|
||||
|
||||
wp_enqueue_style( 'rara-business-customizer-notice', get_template_directory_uri() . '/inc/customizer-plugin-recommend/customizer-notice/css/customizer-notice.css', array(), RARA_BUSINESS_THEME_VERSION );
|
||||
|
||||
wp_enqueue_style( 'plugin-install' );
|
||||
wp_enqueue_script( 'plugin-install' );
|
||||
wp_add_inline_script( 'plugin-install', 'var pagenow = "customizer";' );
|
||||
|
||||
wp_enqueue_script( 'updates' );
|
||||
|
||||
wp_enqueue_script( 'rara-business-customizer-notice', get_template_directory_uri() . '/inc/customizer-plugin-recommend/customizer-notice/js/customizer-notice.js', array( 'customize-controls' ), RARA_BUSINESS_THEME_VERSION );
|
||||
wp_localize_script(
|
||||
'rara-business-customizer-notice', 'customizer_notice_data', array(
|
||||
'ajaxurl' => admin_url( 'admin-ajax.php' ),
|
||||
'template_directory' => get_template_directory_uri(),
|
||||
'base_path' => admin_url(),
|
||||
'activating_string' => __( 'Activating', 'rara-business' ),
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the section for the recommended actions/plugins in customize
|
||||
*
|
||||
* @param object $wp_customize The customizer object.
|
||||
*/
|
||||
public function customize_register_notice( $wp_customize ) {
|
||||
|
||||
/**
|
||||
* Include the Rara_Business_Customizer_Notice_Section class.
|
||||
*/
|
||||
require_once get_template_directory() . '/inc/customizer-plugin-recommend/customizer-notice/class-customizer-notice-section.php';
|
||||
|
||||
$wp_customize->register_section_type( 'Rara_Business_Customizer_Notice_Section' );
|
||||
|
||||
$wp_customize->add_section(
|
||||
new Rara_Business_Customizer_Notice_Section(
|
||||
$wp_customize,
|
||||
'customizer-plugin-notice-section',
|
||||
array(
|
||||
'plugin_text' => $this->recommended_plugins_title,
|
||||
'dismiss_button' => $this->dismiss_button,
|
||||
'priority' => 0,
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Dismiss recommended plugins
|
||||
*/
|
||||
public function dismiss_recommended_plugins_callback() {
|
||||
|
||||
$action_id = ( isset( $_GET['id'] ) ) ? $_GET['id'] : 0;
|
||||
|
||||
echo esc_html( $action_id ); /* this is needed and it's the id of the dismissable required action */
|
||||
|
||||
if ( ! empty( $action_id ) ) {
|
||||
/* if the option exists, update the record for the specified id */
|
||||
$show_recommended_plugins = get_option( 'rara_business_show_recommended_plugins' );
|
||||
|
||||
switch ( $_GET['todo'] ) {
|
||||
case 'add':
|
||||
$show_recommended_plugins[ $action_id ] = false;
|
||||
break;
|
||||
case 'dismiss':
|
||||
$show_recommended_plugins[ $action_id ] = true;
|
||||
break;
|
||||
}
|
||||
update_option( 'rara_business_show_recommended_plugins', $show_recommended_plugins );
|
||||
}
|
||||
die(); // this is required to return a proper result
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
div.recomended-actions_container {
|
||||
margin-bottom: 2em;
|
||||
padding: 0 10px;
|
||||
}
|
||||
|
||||
.recomended-actions_container p.succes {
|
||||
margin: 1em 0;
|
||||
}
|
||||
|
||||
.rara-recommeded-actions p.title {
|
||||
margin-bottom: 0;
|
||||
color: #555d66;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.rara-recommeded-actions div.description {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.rara-recommeded-actions .custom-action {
|
||||
margin-top: 1em;
|
||||
padding-top: 1em;
|
||||
border-top: 1px solid #fafafa;
|
||||
}
|
||||
|
||||
.rara-recommeded-actions .custom-action p {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.recomended-actions_container .rara-recommeded-actions-container:not(:first-child) {
|
||||
overflow: hidden;
|
||||
height: 0;
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.recomended-actions_container .rara-recommeded-actions-container:first-child {
|
||||
height: auto;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.recomended-actions_container .rara-recommeded-actions-container {
|
||||
-webkit-transition: opacity 2s;
|
||||
/* Safari */
|
||||
transition: opacity 2s;
|
||||
}
|
||||
|
||||
.recomended-actions_container .hide {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.recomended-actions_container #demo_content .button {
|
||||
display: block;
|
||||
margin-bottom: 1em;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.recomended-actions_container .succes a {
|
||||
display: inline-block;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.recomended-actions_container .succes a.social {
|
||||
width: 49%;
|
||||
margin-bottom: 1em;
|
||||
padding-top: 4px;
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
.recomended-actions_container .succes a.social span,
|
||||
.recomended-actions_container .succes a.ti-customizer-notify-wordpress span {
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.recomended-actions_container .succes a.ti-customizer-notify-wordpress {
|
||||
padding-top: 4px;
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
.dismiss-button-recommended-plugin {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
right: 10px;
|
||||
border-radius: 50%;
|
||||
color: #d54e21;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.rara-recommeded-actions {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.rara-recommeded-actions .dismiss-button-recommended-plugin {
|
||||
top: 0;
|
||||
right: 0;
|
||||
}
|
||||
|
||||
.rara-recommeded-actions #temp_load {
|
||||
display: -webkit-box;
|
||||
display: -webkit-flex;
|
||||
display: -ms-flexbox;
|
||||
display: flex;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
-webkit-align-items: center;
|
||||
align-items: center;
|
||||
-webkit-box-align: center;
|
||||
-ms-flex-align: center;
|
||||
}
|
||||
|
||||
.rara-recommeded-actions #temp_load img {
|
||||
margin: 0 auto;
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/* global wp */
|
||||
/* global customizer_notice_data */
|
||||
/* global console */
|
||||
(function (api) {
|
||||
|
||||
api.sectionConstructor['customizer-plugin-notice-section'] = api.Section.extend({
|
||||
|
||||
// No events for this type of section.
|
||||
attachEvents: function () {
|
||||
},
|
||||
|
||||
// Always make the section active.
|
||||
isContextuallyActive: function () {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
})(wp.customize);
|
||||
|
||||
jQuery(document).ready(function ($) {
|
||||
|
||||
$('.dismiss-button-recommended-plugin').click(function () {
|
||||
var id = $(this).attr('id'),
|
||||
action = $(this).attr('data-action');
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
data: {action: 'dismiss_recommended_plugins', id: id, todo: action},
|
||||
dataType: 'html',
|
||||
url: customizer_notice_data.ajaxurl,
|
||||
beforeSend: function () {
|
||||
$('#' + id).parent().append('<div id="temp_load" style="text-align:center"><img src="' + customizer_notice_data.base_path + '/images/spinner-2x.gif" /></div>');
|
||||
},
|
||||
success: function (data) {
|
||||
var container = $('#' + data).parent().parent();
|
||||
container.slideToggle().remove();
|
||||
|
||||
if( $('.recomended-actions_container > .rara-recommended-plugins').length === 0 ){
|
||||
$('.control-section-customizer-plugin-notice-section').remove();
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
console.log(jqXHR + ' :: ' + textStatus + ' :: ' + errorThrown);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Remove activate button and replace with activation in progress button.
|
||||
$('body').on('DOMNodeInserted', '.activate-now', function () {
|
||||
var activateButton = $('.activate-now');
|
||||
if( activateButton.length ){
|
||||
var url = activateButton.attr('href');
|
||||
if( typeof url !== 'undefined' ){
|
||||
//Request plugin activation.
|
||||
$.ajax({
|
||||
beforeSend: function () {
|
||||
activateButton.replaceWith('<a class="button updating-message">' + customizer_notice_data.activating_string + '...</a>');
|
||||
},
|
||||
async: true,
|
||||
type: 'GET',
|
||||
url: url,
|
||||
success: function () {
|
||||
//Reload the page.
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('.activate-now').on('click', function(e){
|
||||
var activateButton = $(this);
|
||||
e.preventDefault();
|
||||
if (activateButton.length) {
|
||||
var url = activateButton.attr('href');
|
||||
if (typeof url !== 'undefined') {
|
||||
//Request plugin activation.
|
||||
$.ajax({
|
||||
beforeSend: function () {
|
||||
activateButton.replaceWith('<a class="button updating-message">' + customizer_notice_data.activating_string + '...</a>');
|
||||
},
|
||||
async: true,
|
||||
type: 'GET',
|
||||
url: url,
|
||||
success: function () {
|
||||
//Reload the page.
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin install helper.
|
||||
*
|
||||
* @package Rara_Business
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class Rara_Business_Plugin_Install_Helper
|
||||
*/
|
||||
class Rara_Business_Plugin_Install_Helper {
|
||||
/**
|
||||
* Instance of class.
|
||||
*
|
||||
* @var bool $instance instance variable.
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* Check if instance already exists.
|
||||
*
|
||||
* @return Rara_Business_Plugin_Install_Helper
|
||||
*/
|
||||
public static function instance() {
|
||||
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Rara_Business_Plugin_Install_Helper ) ) {
|
||||
self::$instance = new Rara_Business_Plugin_Install_Helper;
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate action button html.
|
||||
*
|
||||
* @param string $slug plugin slug.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_button_html( $slug ) {
|
||||
$button = '';
|
||||
$state = $this->check_plugin_state( $slug );
|
||||
if ( ! empty( $slug ) ) {
|
||||
|
||||
$button .= '<div class=" plugin-card-' . esc_attr( $slug ) . '" style="padding: 8px 0 5px;">';
|
||||
|
||||
switch ( $state ) {
|
||||
case 'install':
|
||||
$nonce = wp_nonce_url(
|
||||
add_query_arg(
|
||||
array(
|
||||
'action' => 'install-plugin',
|
||||
'from' => 'import',
|
||||
'plugin' => $slug,
|
||||
),
|
||||
network_admin_url( 'update.php' )
|
||||
),
|
||||
'install-plugin_' . $slug
|
||||
);
|
||||
$button .= '<a data-slug="' . esc_attr( $slug ) . '" class="install-now ta-install-plugin button " href="' . esc_url( $nonce ) . '" data-name="' . esc_attr( $slug ) . '" aria-label="Install ' . esc_attr( $slug ) . '">' . __( 'Install and activate', 'rara-business' ) . '</a>';
|
||||
break;
|
||||
|
||||
case 'activate':
|
||||
$plugin_link_suffix = $slug . '/' . $slug . '.php';
|
||||
|
||||
$nonce = add_query_arg(
|
||||
array(
|
||||
'action' => 'activate',
|
||||
'plugin' => rawurlencode( $plugin_link_suffix ),
|
||||
'plugin_status' => 'all',
|
||||
'paged' => '1',
|
||||
'_wpnonce' => wp_create_nonce( 'activate-plugin_' . $plugin_link_suffix ),
|
||||
), network_admin_url( 'plugins.php' )
|
||||
);
|
||||
|
||||
$button .= '<a data-slug="' . esc_attr( $slug ) . '" class="activate button button-primary" href="' . esc_url( $nonce ) . '" aria-label="Activate ' . esc_attr( $slug ) . '">' . __( 'Activate', 'rara-business' ) . '</a>';
|
||||
break;
|
||||
}// End switch().
|
||||
$button .= '</div>';
|
||||
}// End if().
|
||||
|
||||
return $button;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check plugin state.
|
||||
*
|
||||
* @param string $slug plugin slug.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function check_plugin_state( $slug ) {
|
||||
if ( file_exists( ABSPATH . 'wp-content/plugins/' . $slug . '/' . $slug . '.php' ) || file_exists( ABSPATH . 'wp-content/plugins/' . $slug . '/index.php' ) ) {
|
||||
$needs = ( is_plugin_active( $slug . '/' . $slug . '.php' ) || is_plugin_active( $slug . '/index.php' ) ) ? 'deactivate' : 'activate';
|
||||
return $needs;
|
||||
} else {
|
||||
return 'install';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue Function.
|
||||
*/
|
||||
public function enqueue_scripts() {
|
||||
wp_enqueue_script( 'plugin-install' );
|
||||
wp_enqueue_script( 'updates' );
|
||||
wp_enqueue_script( 'rara-business-plugin-install-helper', get_template_directory_uri() . '/inc/customizer-plugin-recommend/plugin-install/js/plugin-install.js', array( 'jquery' ), RARA_BUSINESS_THEME_VERSION, true );
|
||||
wp_localize_script(
|
||||
'rara-business-plugin-install-helper', 'plugin_helper',
|
||||
array(
|
||||
'activating' => esc_html__( 'Activating ', 'rara-business' ),
|
||||
)
|
||||
);
|
||||
wp_localize_script(
|
||||
'rara-business-plugin-install-helper', 'pagenow',
|
||||
array( 'import' )
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/* global plugin_helper */
|
||||
jQuery(document).ready(function ($) {
|
||||
$('body').on('click', '.ta-install-plugin', function(){
|
||||
var slug = $(this).attr('data-slug');
|
||||
wp.updates.installPlugin({
|
||||
slug: slug
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
//Remove activate button and replace with activation in progress button.
|
||||
$('body').on('DOMNodeInserted', '.activate', function () {
|
||||
var activateButton = $('.activate');
|
||||
if( activateButton.length ) {
|
||||
var url = activateButton.attr('href');
|
||||
if( typeof url !== 'undefined' ){
|
||||
//Request plugin activation.
|
||||
$.ajax({
|
||||
beforeSend: function () {
|
||||
activateButton.replaceWith('<a class="button updating-message">' + plugin_helper.activating + '...</a>');
|
||||
},
|
||||
async: true,
|
||||
type: 'GET',
|
||||
url: url,
|
||||
success: function () {
|
||||
//Reload the page.
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('.activate').on('click', function (e) {
|
||||
var activateButton = $(this);
|
||||
e.preventDefault();
|
||||
if( activateButton.length ){
|
||||
var url = activateButton.attr('href');
|
||||
if( typeof url !== 'undefined' ){
|
||||
//Request plugin activation.
|
||||
$.ajax({
|
||||
beforeSend: function () {
|
||||
activateButton.replaceWith('<a class="button updating-message">' + plugin_helper.activating + '...</a>');
|
||||
},
|
||||
async: true,
|
||||
type: 'GET',
|
||||
url: url,
|
||||
success: function () {
|
||||
//Reload the page.
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user