Example #1
0
                $headers = get_headers($base_url . $s);
                if (strpos($headers[0], '200')) {
                    $local_path = fs_normalize_path($img_dir . '/' . $slug . '.' . substr($s, strpos($s, '.') + 1));
                    fs_download_image($base_url . $s, $local_path);
                    $icon_found = true;
                    break;
                }
            }
        }
        if (!$icon_found) {
            // No icons found, fallback to default icon.
            if ($have_write_permissions) {
                // If have write permissions, copy default icon.
                copy(fs_normalize_path($img_dir . '/plugin-icon.png'), $local_path);
            } else {
                // If doesn't have write permissions, use default icon path.
                $local_path = fs_normalize_path($img_dir . '/plugin-icon.png');
            }
        }
        $icons = array($local_path);
    }
}
$icon_dir = dirname($icons[0]);
$relative_url = fs_img_url(substr($icons[0], strlen($icon_dir)), $icon_dir);
?>
<div class="fs-plugin-icon">
	<img src="<?php 
echo $relative_url;
?>
"/>
</div>
         * This code will only be executed once during the testing
         * of the plugin in a local environment. The plugin icon file WILL
         * already exist in the assets folder when the plugin is deployed to
         * the repository.
         */
        $suffixes = array('-128x128.png', '-128x128.jpg', '-256x256.png', '-256x256.jpg', '.svg');
        $base_url = 'https://plugins.svn.wordpress.org/' . $slug . '/assets/icon';
        foreach ($suffixes as $s) {
            $headers = get_headers($base_url . $s);
            if (strpos($headers[0], '200')) {
                $local_path = fs_normalize_path(WP_FS__DIR_IMG . '/icon.' . substr($s, strpos($s, '.') + 1));
                fs_download_image($base_url . $s, $local_path);
                $icon_found = true;
                break;
            }
        }
    }
    if (!$icon_found) {
        // No icons found, fallback to default icon.
        copy(fs_normalize_path(WP_FS__DIR_IMG . '/plugin-icon.png'), $local_path);
    }
    $icons = array($local_path);
}
$relative_url = fs_img_url(substr($icons[0], strlen(fs_normalize_path(WP_FS__DIR_IMG))));
?>
<div class="fs-plugin-icon">
	<img src="<?php 
echo $relative_url;
?>
"/>
</div>
         * This code will only be executed once during the testing
         * of the plugin in a local environment. The plugin icon file WILL
         * already exist in the assets folder when the plugin is deployed to
         * the repository.
         */
        $suffixes = array('-128x128.png', '-128x128.jpg', '-256x256.png', '-256x256.jpg', '.svg');
        $base_url = 'https://plugins.svn.wordpress.org/' . $slug . '/assets/icon';
        foreach ($suffixes as $s) {
            $headers = get_headers($base_url . $s);
            if (strpos($headers[0], '200')) {
                $local_path = fs_normalize_path($img_dir . '/icon.' . substr($s, strpos($s, '.') + 1));
                fs_download_image($base_url . $s, $local_path);
                $icon_found = true;
                break;
            }
        }
    }
    if (!$icon_found) {
        // No icons found, fallback to default icon.
        copy(fs_normalize_path($img_dir . '/plugin-icon.png'), $local_path);
    }
    $icons = array($local_path);
}
$relative_url = fs_img_url(substr($icons[0], strlen(fs_normalize_path($img_dir))), $img_dir);
?>
<div class="fs-plugin-icon">
	<img src="<?php 
echo $relative_url;
?>
"/>
</div>