'Plugin Name',
'PluginURI' => 'Plugin URI',
);
$plugin_data = get_file_data(__FILE__, $default_headers, 'plugin');
$url = $plugin_data['PluginURI'];
$name = $plugin_data['Name'];
$data['name'] = $name;
$data['url'] = $url;
return $data;
}
/**
* This function processes [audiomack src=""] shortcode and replaces it with Audiomack player.
* It expects the src to contain album or song prefix e.g.
* - http://www.audiomack.com/song/hiphopfeeling/nowish
* - http://www.audiomack.com/album/tutankhamun-brothers/whats-a-black-beatle
* @param array $attr
* @return string
*/
function audiomack_shortcode_audiomack($attr = array()) {
$plugin_data = audiomack_get_plugin_data();
$opts = audiomack_get_options();
// should be like this.
// - http://www.audiomack.com/song/djsemtex/say-my-name-kendrick-lamar-response
// - http://www.audiomack.com/album/tutankhamun-brothers/whats-a-black-beatle
$src = empty($attr['src']) ? '' : $attr['src'];
$buff = '';
$buff .= "\n\n";
// Embed source needs to be like this
// http://www.audiomack.com/embed3/hiphopfeeling/nowish?c1=fc881e&bg=f2f2f2&c2=222222
// http://www.audiomack.com/embed3-album/tutankhamun-brothers/whats-a-black-beatle?c1=fc881e&bg=f2f2f2&c2=222222
$embed_src = $src;
$width = $opts['width']; // % or a number
$height = 144;
/*
* The height of the player based on the embedded media
* - Album - 352px
* - Song Regular - 144px
* - Song Slim - 62px
*/
if (stripos($embed_src, '/song/') !== false) { // song
if (!empty($opts['slim'])) {
$height = 62;
$embed_src = str_replace('/song/', '/embed3-thin/', $embed_src);
} else {
$embed_src = str_replace('/song/', '/embed3/', $embed_src);
}
} else {
$height = 352;
$embed_src = str_replace('/album/', '/embed3-album/', $embed_src);
}
// the embed code expects the colours not to have pound signs
$player_opts['c1'] = $opts['player_color'];
$player_opts['c2'] = $opts['text_color'];
$player_opts['bg'] = $opts['background_color'];
$player_params = http_build_query($player_opts);
$embed_src .= '?' . $player_params;
$height_str = "height='$height'";
$embed_code = "\n";
$buff .= "
\n";
$buff .= $embed_code;
$buff .= "
\n";
$buff .= "\n\n";
return $buff;
}
/**
* This functions returns .min suffix for live installations and none on dev machine.
* The idea is to load different css/js files depending on the environment.
* e.g. for live: use main.min.js and dev main.js.
* Minified version should load faster.
*/
function audiomack_get_asset_suffix() {
$dev = empty($_SERVER['DEV_ENV']) ? 0 : 1;
$suffix = $dev ? '' : '.min';
return $suffix;
}
/**
* Schdules css, js for loading when WP is ready.
*/
function audiomack_load_assets() {
$suffix = audiomack_get_asset_suffix();
wp_register_style( 'audiomack_css', plugins_url("/assets/main{$suffix}.css", __FILE__) );
wp_enqueue_style( 'audiomack_css' );
/*if (!is_admin()) {
wp_enqueue_script('jquery');
wp_register_script( 'audiomack_js', plugins_url("/assets/main{$suffix}.js", __FILE__), array('jquery', ), '1.0', true);
wp_enqueue_script( 'audiomack_js' );
}*/
}
/**
* Adds the menu under Settings > Audiomack
*/
function audiomack_create_menu() {
//create a submenu under Settings
add_options_page( 'Audiomack', 'Audiomack', 'manage_options', __FILE__, 'audiomack_settings_page' );
// when plugins are shown add a settings link near my plugin for a quick access to the settings page.
add_filter('plugin_action_links', 'audiomack_add_plugin_settings_link', 10, 2);
}
// Add the ? settings link in Plugins page very good
function audiomack_add_plugin_settings_link($links, $file) {
if ($file == plugin_basename(__FILE__)) {
$link = admin_url('options-general.php?page=' . plugin_basename(__FILE__));
$dashboard_link = "Settings";
array_unshift($links, $dashboard_link);
}
return $links;
}
/**
* Loads the options for the current plugin. If the some variables do not exist
* defaults will be used instead.
*
* @params void
* @return array
*/
function audiomack_get_options() {
$defaults = array(
'width' => '100%',
'player_color' => 'fc881e',
'background_color' => 'f2f2f2',
'text_color' => '222222',
'slim' => '', // for songs only
);
$current_options = get_option('audiomack_options', $defaults);
$current_options = array_merge($defaults, $current_options);
return $current_options;
}
/**
* Saving options. Options are passed in an array. They should have been
* filtered and cleaned already.
*
* @param array $opts
* @return array
*/
function audiomack_set_options($opts) {
// let's do some cleanup
foreach ($opts as $key => $value) {
$value = wp_kses($value, array());
$value = trim($value);
$opts[$key] = $value;
}
// this is a checkbox so if no value is passed we'll assume it's unchecked.
$opts['slim'] = empty($opts['slim']) ? 0 : 1;
update_option('audiomack_options', $opts);
return $opts;
}
// Generates Options for the plugin
function audiomack_settings_page() {
$saved = 0;
$current_options = audiomack_get_options();
if (!empty($_POST)) {
// this is a checkbox so if no value is passed we'll assume it's unchecked.
$current_options['slim'] = empty($_REQUEST['slim']) ? 0 : 1;
$current_options_keys = array_keys($current_options);
foreach ($_REQUEST as $key => $value) {
// Is the current variable expected (part of options array) ?
if (in_array($key, $current_options_keys)) {
$value = wp_kses($value, array());
$value = trim($value);
// Are we processing a color field? We need hex color
if (strpos($key, 'color') !== false) {
$value = preg_replace('#[^a-z0-9]#si', '', $value); // clean up non alpha nums
// if nothing is left then the user is being lazy and didn't enter the color
// correctly so we'll skip it.
if (empty($value)) {
continue;
}
} elseif ($key == 'width') { // this could be 100% or 250
$value = preg_replace('#[^0-9%]#si', '', $value);
$value = empty($value) ? '100%' : $value;
}
$current_options[$key] = $value;
}
}
$current_options = audiomack_set_options($current_options);
$saved = 1;
}
?>
Audiomack
This plugin allows you to embed a song or an album from Audiomack on your site.
Configure the player settings below.
Usage
You can either click on this icon:
in edit post/page or
paste the shortcodes below with src attribute pointing to a song or an album.
The plugin will generate the necessary embed code.
| [audiomack src="http://www.audiomack.com/song/nas/let-nas-down-remix-feat-nas"] |
← This will generate the embed code for a song |
[audiomack src="http://www.audiomack.com/album/tutankhamun-brothers/whats-a-black-beatle"] |
← This will generate the embed code for an album |
Share
Support & Feature Requests
If you have suggestions or run into an issue please email us at support@audiomack.com.
Please do NOT use the WordPress forums or other places to seek support.
Mailing List
Get the latest news and updates about this and future cool
plugins we develop.
1) Subscribe to our newsletter
OR
2) Subscribe using our QR code. [Scan it with your mobile device].
Audiomack