PluginProbe
Buttonizer – Floating Menus, Sticky Buttons, & Popup Builder / 1.4.3
Buttonizer – Floating Menus, Sticky Buttons, & Popup Builder v1.4.3
3.6.0 3.5.0 trunk 1.0.10 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.6.1 1.0.7 1.0.8 1.0.9 1.1 1.1.1 1.2 1.3 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.5 1.5.1 All 110 releases
buttonizer-multifunctional-button / freemius / templates / plugin-icon.php

plugin-icon.php in Buttonizer – Floating Menus, Sticky Buttons, & Popup Builder 1.4.3, at freemius/templates/plugin-icon.php

130 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package Freemius
4 * @copyright Copyright (c) 2015, Freemius, Inc.
5 * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6 * @since 1.1.4
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 $fs = freemius( $VARS['id'] );
14 $slug = $fs->get_slug();
15
16 /**
17 * @since 1.1.7.5
18 */
19 $local_path = $fs->apply_filters( 'plugin_icon', false );
20
21 if ( is_string( $local_path ) ) {
22 $icons = array( $local_path );
23 } else {
24 global $fs_active_plugins;
25
26 $img_dir = WP_FS__DIR_IMG;
27
28 if ( 1 < count( $fs_active_plugins->plugins ) ) {
29 $plugin_or_theme_img_dir = ( $fs->is_plugin() ? WP_PLUGIN_DIR : get_theme_root() );
30
31 foreach ( $fs_active_plugins->plugins as $sdk_path => &$data ) {
32 if ( $data->plugin_path == $fs->get_plugin_basename() ) {
33 $img_dir = $plugin_or_theme_img_dir
34 . '/'
35 . str_replace( '../themes/', '', $sdk_path )
36 . '/assets/img';
37
38 break;
39 }
40 }
41 }
42
43 if ( $fs->is_theme() ) {
44 $icons = array(
45 fs_normalize_path( $img_dir . '/theme-icon.png' )
46 );
47 } else {
48 $icons = glob( fs_normalize_path( $img_dir . '/' . $slug . '.*' ) );
49 if ( ! is_array( $icons ) || 0 === count( $icons ) ) {
50 $icon_found = false;
51 $local_path = fs_normalize_path( $img_dir . '/' . $slug . '.png' );
52
53 $have_write_permissions = ( 'direct' === get_filesystem_method( array(), fs_normalize_path( $img_dir ) ) );
54
55 if ( WP_FS__IS_LOCALHOST && $fs->is_org_repo_compliant() && $have_write_permissions ) {
56 /**
57 * IMPORTANT: THIS CODE WILL NEVER RUN AFTER THE PLUGIN IS IN THE REPO.
58 *
59 * This code will only be executed once during the testing
60 * of the plugin in a local environment. The plugin icon file WILL
61 * already exist in the assets folder when the plugin is deployed to
62 * the repository.
63 */
64 if ( ! function_exists( 'plugins_api' ) ) {
65 require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
66 }
67
68 $plugin_information = plugins_api( 'plugin_information', array(
69 'slug' => $slug,
70 'fields' => array(
71 'sections' => false,
72 'tags' => false,
73 'icons' => true
74 )
75 ) );
76
77 if (
78 ! is_wp_error( $plugin_information )
79 && isset( $plugin_information->icons )
80 && ! empty( $plugin_information->icons )
81 ) {
82 /**
83 * Get the smallest icon.
84 *
85 * @author Leo Fajardo (@leorw)
86 * @since 1.2.2
87 */
88 $icon = end( $plugin_information->icons );
89
90 if ( 0 !== strpos( $icon, 'http' ) ) {
91 $icon = 'http:' . $icon;
92 }
93
94 /**
95 * Get a clean file extension, e.g.: "jpg" and not "jpg?rev=1305765".
96 *
97 * @author Leo Fajardo (@leorw)
98 * @since 1.2.2
99 */
100 $ext = pathinfo( strtok( $icon, '?' ), PATHINFO_EXTENSION );
101
102 $local_path = fs_normalize_path( $img_dir . '/' . $slug . '.' . $ext );
103
104 // Try to download the icon.
105 $icon_found = fs_download_image( $icon, $local_path );
106 }
107 }
108
109 if ( ! $icon_found ) {
110 // No icons found, fallback to default icon.
111 if ( $have_write_permissions ) {
112 // If have write permissions, copy default icon.
113 copy( fs_normalize_path( $img_dir . '/plugin-icon.png' ), $local_path );
114 } else {
115 // If doesn't have write permissions, use default icon path.
116 $local_path = fs_normalize_path( $img_dir . '/plugin-icon.png' );
117 }
118 }
119
120 $icons = array( $local_path );
121 }
122 }
123 }
124
125 $icon_dir = dirname( $icons[0] );
126 $relative_url = fs_img_url( substr( $icons[0], strlen( $icon_dir ) ), $icon_dir );
127 ?>
128 <div class="fs-plugin-icon">
129 <img src="<?php echo $relative_url ?>" width="80" height="80"/>
130 </div>