Пример #1
0
function hocwp_loop_plugin_card($plugin, $allow_tags = array(), $base_name = '')
{
    $is_local = false;
    if (is_object($plugin)) {
        $plugin = (array) $plugin;
    }
    $title = wp_kses(hocwp_get_value_by_key($plugin, 'name'), $allow_tags);
    if (empty($title)) {
        $is_local = true;
    }
    $description = strip_tags(hocwp_get_value_by_key($plugin, 'short_description'));
    $version = wp_kses(hocwp_get_value_by_key($plugin, 'version'), $allow_tags);
    $name = strip_tags($title . ' ' . $version);
    $author = wp_kses(hocwp_get_value_by_key($plugin, 'author'), $allow_tags);
    if (!empty($author)) {
        $author = ' <cite>' . sprintf(__('By %s'), $author) . '</cite>';
    }
    $action_links = array();
    if (!$is_local && (current_user_can('install_plugins') || current_user_can('update_plugins'))) {
        $status = hocwp_plugin_install_status($plugin);
        switch ($status['status']) {
            case 'install':
                if ($status['url']) {
                    $action_links[] = '<a class="install-now button" data-slug="' . esc_attr($plugin['slug']) . '" href="' . esc_url($status['url']) . '" aria-label="' . esc_attr(sprintf(__('Install %s now'), $name)) . '" data-name="' . esc_attr($name) . '">' . __('Install Now') . '</a>';
                }
                break;
            case 'update_available':
                if ($status['url']) {
                    $action_links[] = '<a class="update-now button" data-plugin="' . esc_attr($status['file']) . '" data-slug="' . esc_attr($plugin['slug']) . '" href="' . esc_url($status['url']) . '" aria-label="' . esc_attr(sprintf(__('Update %s now'), $name)) . '" data-name="' . esc_attr($name) . '">' . __('Update Now') . '</a>';
                }
                break;
            case 'latest_installed':
            case 'newer_installed':
                $action_links[] = '<span class="button button-disabled" title="' . esc_attr__('This plugin is already installed and is up to date') . ' ">' . _x('Installed', 'plugin') . '</span>';
                break;
        }
    }
    $details_link = self_admin_url('plugin-install.php?tab=plugin-information&amp;plugin=' . hocwp_get_value_by_key($plugin, 'slug') . '&amp;TB_iframe=true&amp;width=600&amp;height=550');
    $action_links[] = '<a target="_blank" href="' . esc_url($details_link) . '" class="thickbox" aria-label="' . esc_attr(sprintf(__('More information about %s'), $name)) . '" data-title="' . esc_attr($name) . '">' . __('More Details') . '</a>';
    $plugin_icon_url = hocwp_get_plugin_icon_url($plugin);
    $action_links = apply_filters('plugin_install_action_links', $action_links, $plugin);
    $date_format = __('M j, Y @ H:i');
    $last_updated_timestamp = strtotime(hocwp_get_value_by_key($plugin, 'last_updated'));
    if (empty($title) && !empty($base_name)) {
        $local_plugin = hocwp_get_plugin_info($base_name);
        $title = wp_kses($local_plugin['Name'], $allow_tags);
        $description = strip_tags($local_plugin['Description']);
        $description = str_replace(' By HocWP.', '', $description);
        $action_links = array();
        //$version = wp_kses($local_plugin['Version'], $allow_tags);
        //$name = strip_tags($title . ' ' . $version);
        $author = wp_kses($local_plugin['Author'], $allow_tags);
        if (!empty($author)) {
            $author = ' <cite>' . sprintf(__('By %s'), $author) . '</cite>';
        }
    }
    if (empty($title)) {
        return;
    }
    ?>
	<div
		class="plugin-card plugin-card-<?php 
    echo sanitize_html_class(hocwp_get_value_by_key($plugin, 'slug'));
    ?>
">
		<div class="plugin-card-top">
			<div class="name column-name">
				<h3>
					<a target="_blank" href="<?php 
    echo esc_url($details_link);
    ?>
" class="thickbox">
						<?php 
    echo $title;
    ?>
						<img src="<?php 
    echo esc_attr($plugin_icon_url);
    ?>
" class="plugin-icon" alt="">
					</a>
				</h3>
			</div>
			<div class="action-links">
				<?php 
    if ($action_links) {
        echo '<ul class="plugin-action-buttons"><li>' . implode('</li><li>', $action_links) . '</li></ul>';
    }
    ?>
			</div>
			<div class="desc column-description">
				<p><?php 
    echo $description;
    ?>
</p>

				<p class="authors"><?php 
    echo $author;
    ?>
</p>
			</div>
		</div>
		<div class="plugin-card-bottom">
			<?php 
    if (!$is_local) {
        ?>
				<div class="vers column-rating">
					<?php 
        wp_star_rating(array('rating' => $plugin['rating'], 'type' => 'percent', 'number' => $plugin['num_ratings']));
        ?>
					<span class="num-ratings">(<?php 
        echo number_format_i18n($plugin['num_ratings']);
        ?>
)</span>
				</div>
				<div class="column-updated">
					<strong><?php 
        _e('Last Updated:');
        ?>
</strong> <span
						title="<?php 
        echo esc_attr(date_i18n($date_format, $last_updated_timestamp));
        ?>
">
						<?php 
        printf(__('%s ago'), human_time_diff($last_updated_timestamp));
        ?>
					</span>
				</div>
				<div class="column-downloaded">
					<?php 
        if ($plugin['active_installs'] >= 1000000) {
            $active_installs_text = _x('1+ Million', 'Active plugin installs');
        } else {
            $active_installs_text = number_format_i18n($plugin['active_installs']) . '+';
        }
        printf(__('%s Active Installs'), $active_installs_text);
        ?>
				</div>
				<div class="column-compatibility">
					<?php 
        if (!empty($plugin['tested']) && version_compare(substr($GLOBALS['wp_version'], 0, strlen($plugin['tested'])), $plugin['tested'], '>')) {
            echo '<span class="compatibility-untested">' . __('Untested with your version of WordPress') . '</span>';
        } elseif (!empty($plugin['requires']) && version_compare(substr($GLOBALS['wp_version'], 0, strlen($plugin['requires'])), $plugin['requires'], '<')) {
            echo '<span class="compatibility-incompatible">' . __('<strong>Incompatible</strong> with your version of WordPress') . '</span>';
        } else {
            echo '<span class="compatibility-compatible">' . __('<strong>Compatible</strong> with your version of WordPress') . '</span>';
        }
        ?>
				</div>
			<?php 
    } else {
        ?>
				<p><?php 
        _e('This is a local plugin so there is no stats for it.', 'hocwp-theme');
        ?>
</p>
			<?php 
    }
    ?>
		</div>
	</div>
	<?php 
}
Пример #2
0
function hocwp_get_plugin_name($plugin_file, $default = '')
{
    $plugin = hocwp_get_plugin_info($plugin_file);
    return hocwp_get_value_by_key($plugin, 'Name', $default);
}