array(
'href' => array(),
'title' => array(),
'target' => array(),
),
'abbr' => array( 'title' => array() ),
'acronym' => array( 'title' => array() ),
'code' => array(),
'pre' => array(),
'em' => array(),
'strong' => array(),
'ul' => array(),
'ol' => array(),
'li' => array(),
'p' => array(),
'br' => array(),
);
/**
* Veriable Initialize
*/
public $text_domain = '';
public $parent_menu_slug = '';
public $menu_label = '';
public $menu_page_slug = '';
public $menu_capability = '';
public $menu_type = '';
public $menu_icon = '';
public $priority = '';
public $hook_suffix = '';
public $assets_url = '';
public $tab_list = [];
/**
* [instance] Initializes a singleton instance
* @return [Recommended_Plugins]
*/
public static function instance( $args = [] ) {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self( $args );
}
return self::$_instance;
}
/**
* [__construct] Class construct
*/
function __construct( $args ) {
// Initialize properties
$this->text_domain = !empty( $args['text_domain'] ) ? $args['text_domain'] : 'htrp';
$this->parent_menu_slug = !empty( $args['parent_menu_slug'] ) ? $args['parent_menu_slug'] : 'plugins.php';
$this->menu_type = !empty( $args['menu_type'] ) ? $args['menu_type'] : 'submenu';
$this->menu_icon = !empty( $args['menu_icon'] ) ? $args['menu_icon'] : 'dashicons-plugins-checked';
$this->menu_label = !empty( $args['menu_label'] ) ? $args['menu_label'] : esc_html__( 'Recommendations', $this->text_domain );
$this->menu_capability = !empty( $args['menu_capability'] ) ? $args['menu_capability'] : 'manage_options';
$this->menu_page_slug = !empty( $args['menu_page_slug'] ) ? $args['menu_page_slug'] : $this->text_domain . '_extensions';
$this->priority = !empty( $args['priority'] ) ? $args['priority'] : 100;
$this->hook_suffix = !empty( $args['hook_suffix'] ) ? $args['hook_suffix'] : '';
$this->assets_url = !empty( $args['assets_url'] ) ? $args['assets_url'] : plugins_url( 'assets', __FILE__ );
$this->tab_list = !empty( $args['tab_list'] ) ? $args['assets_url'] : [];
add_action( 'admin_menu', [ $this, 'admin_menu' ], 20 );
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
// Ajax Action
add_action( 'wp_ajax_'.$this->text_domain.'_ajax_plugin_activation', [ $this, 'plugin_activation' ] );
}
/**
* [admin_menu] Add Recommended Menu
* @return [void]
*/
public function admin_menu(){
if( $this->menu_type === 'submenu' ){
add_submenu_page(
$this->parent_menu_slug,
$this->menu_label,
$this->menu_label,
$this->menu_capability,
$this->menu_page_slug,
[ $this, 'render_html' ]
);
}else{
add_menu_page(
$this->menu_label,
$this->menu_label,
$this->menu_capability,
$this->menu_page_slug,
[ $this,'render_html' ],
$this->menu_icon,
30
);
}
}
/**
* [enqueue_assets]
* @param [string] $hook_suffix Current page hook
* @return [void]
*/
public function enqueue_assets( $hook_suffix ) {
if( $this->hook_suffix ){
if( $this->hook_suffix == $hook_suffix ){
add_thickbox();
wp_enqueue_script( 'htrp-plugin-install-manager', $this->assets_url . '/js/plugins_install_manager.js', array('jquery','wp-util', 'updates'), '1.1.6', true );
}
} else {
add_thickbox();
wp_enqueue_script( 'htrp-plugin-install-manager', $this->assets_url . '/js/plugins_install_manager.js', array('jquery','wp-util', 'updates'), '1.1.6', true );
}
$localize_vars['ajaxurl'] = admin_url('admin-ajax.php');
$localize_vars['text_domain'] = sanitize_title_with_dashes( $this->text_domain );
$localize_vars['nonce'] = wp_create_nonce('ht-contactform-nonce');
$localize_vars['buttontxt'] = array(
'buynow' => esc_html__( 'Buy Now', $this->text_domain ),
'preview' => esc_html__( 'Preview', $this->text_domain ),
'installing' => esc_html__( 'Installing..', $this->text_domain ),
'activating' => esc_html__( 'Activating..', $this->text_domain ),
'active' => esc_html__( 'Activated', $this->text_domain ),
);
wp_localize_script( 'htrp-plugin-install-manager', 'htrp_params', $localize_vars );
}
/**
* [add_new_tab]
* @param [void] set tab content
*/
public function add_new_tab( $tab_list ){
$this->tab_list[] = $tab_list;
}
/**
* [render_html]
* @return [void] Render HTML
*/
public function render_html(){
if ( ! function_exists('plugins_api') ){ include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); }
$htplugins_plugin_list = $this->get_plugins();
$palscode_plugin_list = $this->get_plugins( 'palscode' );
$plugin_list = array_merge( $htplugins_plugin_list, $palscode_plugin_list );
$prepare_plugin = array();
foreach ( $plugin_list as $plugin_key => $plugin ) {
$prepare_plugin[$plugin['slug']] = $plugin;
}
?>
tab_list as $tab ){
$active_class = isset( $tab['active'] ) && $tab['active'] ? 'htrp-active' : '';
?>
-
tab_list as $tab ):
$active_class = isset( $tab['active'] ) && $tab['active'] ? 'htrp-active' : '';
$plugins = $tab['plugins'];
echo '
';
foreach( $plugins as $plugin ):
$data = array(
'slug' => isset( $plugin['slug'] ) ? $plugin['slug'] : '',
'location' => isset( $plugin['location'] ) ? $plugin['slug'].'/'.$plugin['location'] : '',
'name' => isset( $plugin['name'] ) ? $plugin['name'] : '',
);
$title = wp_kses( $plugin['name'], $this->plugins_allowedtags );
if( array_key_exists( $plugin['slug'], $prepare_plugin ) ){
$plugins_type = 'free';
$image_url = $this->plugin_icon( $plugins_type, $prepare_plugin[$data['slug']]['icons'] );
$description = strip_tags( $prepare_plugin[$data['slug']]['description'] );
$author_name = wp_kses( $prepare_plugin[$data['slug']]['author'], $this->plugins_allowedtags );
$details_link = self_admin_url('plugin-install.php?tab=plugin-information&plugin=' . $plugin['slug'] .'&TB_iframe=true&width=772&height=577');
$target = '_self';
$modal_class = 'class="thickbox open-plugin-details-modal"';
}else{
$plugins_type = 'pro';
$image_url = $this->plugin_icon( $plugins_type, $plugin['slug'] );
$description = isset( $plugin['description'] ) ? $plugin['description'] : '';
$author_name = esc_html__( 'HasTheme', $this->text_domain );
$author_link = isset( $plugin['author_link'] ) ? $plugin['author_link'] : '';
$details_link = isset( $plugin['link'] ) ? $plugin['link'] : '';
$button_text = esc_html__('Buy Now', $this->text_domain );
$button_classes = 'button button-primary';
$target = '_blank';
$modal_class = '';
}
if ( ! is_wp_error( $data ) ):
// Installed but Inactive.
if ( file_exists( WP_PLUGIN_DIR . '/' . $data['location'] ) && is_plugin_inactive( $data['location'] ) ) {
$button_classes = 'button activate-now button-primary';
$button_text = esc_html__( 'Activate', $this->text_domain );
// Not Installed.
} elseif ( ! file_exists( WP_PLUGIN_DIR . '/' . $data['location'] ) ) {
$button_classes = 'button install-now';
$button_text = esc_html__( 'Install Now', $this->text_domain );
// Active.
} else {
$button_classes = 'button disabled';
$button_text = esc_html__( 'Activated', $this->text_domain );
}
?>
'.esc_html__( 'Buy Now', $this->text_domain ).'';
}else{
?>
>text_domain) ?>
active_install_count( $prepare_plugin[$data['slug']]['active_installs'] ) );
}
?>
';
endforeach;
?>
$username, 'per_page' => 100 ) );
set_transient( $transient_var, $plugins_list_by_author->plugins, 1 * WEEK_IN_SECONDS );
$org_plugins_list = $plugins_list_by_author->plugins;
}
return $org_plugins_list;
}
/**
* [plugin_icon] Generate plugin icon
* @param string $type plugin type
* @param [array|string] $icon
* @return [URL] icon URL
*/
public function plugin_icon( $type, $icon ){
if( $type === 'free' ){
if ( ! empty( $icon['svg'] ) ) {
$plugin_icon_url = $icon['svg'];
} elseif ( ! empty( $icon['2x'] ) ) {
$plugin_icon_url = $icon['2x'];
} elseif ( ! empty( $icon['1x'] ) ) {
$plugin_icon_url = $icon['1x'];
} else {
$plugin_icon_url = $icon['default'];
}
}else{
$plugin_icon_url = $this->assets_url .'/images/extensions/'.$icon.'.png';
}
return $plugin_icon_url;
}
/**
* [active_install_count] Manage Active install count
* @param [int] $active_installs
* @return [string]
*/
public function active_install_count( $active_installs ){
if ( $active_installs >= 1000000 ) {
$active_installs_millions = floor( $active_installs / 1000000 );
$active_installs_text = sprintf(
/* translators: %s: Number of millions. */
_nx( '%s+ Million', '%s+ Million', $active_installs_millions, 'Active plugin installations' ),
number_format_i18n( $active_installs_millions )
);
} elseif ( 0 === $active_installs ) {
$active_installs_text = _x( 'Less Than 10', 'Active plugin installations' );
} else {
$active_installs_text = number_format_i18n( $active_installs ) . '+';
}
return $active_installs_text;
}
/**
* [plugin_activation] Plugin activation ajax callable function
* @return [JSON]
*/
public function plugin_activation() {
$nonce = sanitize_text_field($_POST['nonce']);
if(wp_verify_nonce($nonce, 'ht-contactform-nonce')) {
if ( ! current_user_can( 'install_plugins' ) || ! isset( $_POST['location'] ) || ! sanitize_text_field($_POST['location']) ) {
wp_send_json_error(
array(
'success' => false,
'message' => esc_html__( 'Plugin Not Found', $this->text_domain ),
)
);
}
$plugin_location = ( isset( $_POST['location'] ) ) ? sanitize_text_field( $_POST['location'] ) : '';
$activate = activate_plugin( $plugin_location, '', false, true );
if ( is_wp_error( $activate ) ) {
wp_send_json_error(
array(
'success' => false,
'message' => $activate->get_error_message(),
)
);
}
wp_send_json_success(
array(
'success' => true,
'message' => esc_html__( 'Plugin Successfully Activated', $this->text_domain ),
)
);
}
}
}