Support » Plugin: Music Affiliate Pro » [Plugin: Music Affiliate Pro] Adding iTunes Album to Custom Field

  • John


    I’m attempting to add an option to auto-magically dump the itunes # into a custom field, (that I previously added outside my content.), within admin/meta-box-tune-search.php, beneath the code:
    $result->actions[] = '<a href="#'. $item->collectionId .'" class="add-itunes-widget">Add Widget</a>';
    I added another item (just copied & modified from the one above),
    $result->actions[] = '<a href="#'. $item->collectionId .'" class="field_code">Add Field</a>';
    then attempted to add my php meta code:
    add_post_meta(get_the_ID(), 'itunes_id', $item)
    to the search.js file:

    .delegate('a.field-code', 'click', function(e) {
    		var itemId = $(this).attr('href').replace('#', '');
    		tuneEditor.add_post_meta(the_ID(),'itunes_id', itemId, false);

    As I analyse my careless unsuccessful hacks, thoughts on a more useful approach?

Viewing 1 replies (of 1 total)
  • Plugin Author Brady Vercher


    That last line looks the only one that won’t work since the functions you’re using are PHP only. I haven’t done any testing to see if this works, but it should help point you in the right direction.

    Add the new action with the following code. It adds the iTunes ID and creates a nonce as HTML5 data attributes (the nonce is for security):

    $result->actions[] = '<a href="#">collectionId . '" data-nonce="' . wp_create_nonce( 'itunes-post-meta_' . $item->collectionId ) . '" class="field_code">Add Field</a>';

    Then replace the tuneEditor.add_post_meta() line in your javascript above with an AJAX call that looks something like this:

    $.post( ajaxurl, {<br />
    	action : 'jpmizell_add_itunes_post_meta',<br />
    	post_id : $('#post_ID').val(),<br />
    	itunes_id : $(this).data('itunes-id'),<br />
    	nonce : $(this).data('nonce')<br />

    And finally, register an AJAX handler to process the request and add your post meta field.

    add_action( 'wp_ajax_jpmizell_add_itunes_post_meta', 'jpmizell_add_itunes_post_meta' );<br />
    function jpmizell_add_itunes_post_meta() {<br />
    	if ( ! wp_verify_nonce( $_POST['nonce'], 'itunes-post-meta_' . $_POST['itunes_id'] ) )<br />
    		wp_die( -1 );</p>
    <p>	add_post_meta( intval( $_POST['post_id'] ), 'itunes_id', $_POST['itunes_id'], false );<br />
    	wp_die( 0 );<br />

    If I didn’t mention it before, edits to plugins like this will be wiped out if the plugin is updated in the future, so be sure to backup your changes or rename the plugin and the plugin folder so you won’t receive notifications to automatically update.

    Hope that helps.

    – Brady

Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: Music Affiliate Pro] Adding iTunes Album to Custom Field’ is closed to new replies.