• Resolved dreyg9

    (@dreyg9)


    Hello!
    I have two questions.
    How I can add to any channel tags and author?
    How I can add to post text for example I need spoiler in description?
    ( [spoiler]post description[/spoiler] )

Viewing 15 replies - 1 through 15 (of 17 total)
  • Plugin Author tubegtld

    (@tubegtld)

    How I can add to any channel tags and author?

    Can you be a little more specific here?

    Do you mean you want to “auto-assign” some pre-determined tags and a specific author for each new video that comes in from a specific channel?

    How I can add to post text for example I need spoiler in description?

    You can use the wp_insert_post_data filter for this, but it might be a bit tricky to isolate just those posts you want. Here’s an example…

    add_filter( 'wp_insert_post_data' , 'add_spoilers' , '99', 2 );
    
    function filter_post_data( $data , $postarr ) {
        $data['post_content'] = '[spoiler]' . $data['post_content'] . '[/spoiler]';
        return $data;
    }

    Or, better yet, I’ve added a new filter which will go live with the next push. In the meantime, you can replace the content of “tube-video-curator.php” with this… https://pastebin.com/Qpeu8eBk

    Then, you can drop this in a functions file…

    add_filter( 'tube_vc_filter_post_pre_insert' , 'add_spoilers' );
    
    function add_spoilers( $my_post ) {
        $my_post['post_content'] = '[spoiler]' . $my_post['post_content'] . '[/spoiler]';
        return $data;
    }

    Please give this a shot and follow up on the first question.

    And sorry for the slow reply.

    • This reply was modified 7 years, 4 months ago by tubegtld.
    • This reply was modified 7 years, 4 months ago by tubegtld.
    Thread Starter dreyg9

    (@dreyg9)

    Hello! Thank you!

    Do you mean you want to “auto-assign” some pre-determined tags and a specific author for each new video that comes in from a specific channel?

    Yes.
    Or Tube_video_creator_name as post author.

    Or, better yet, I’ve added a new filter which will go live with the next push. In the meantime, you can replace the content of “tube-video-curator.php” with this… https://pastebin.com/Qpeu8eBk

    I replaced

    Then, you can drop this in a functions file…

    add_filter( ‘tube_vc_filter_post_pre_insert’ , ‘add_spoilers’ );

    function add_spoilers( $my_post ) {
    $my_post[‘post_content’] = ‘[spoiler]’ . $my_post[‘post_content’] . ‘[/spoiler]’;
    return $data;
    }

    In functions.php?
    I added in functions.php, but It don’t work ??

    Plugin Author tubegtld

    (@tubegtld)

    Okay, added some new filters, and enhanced the new tube_vc_filter_post_pre_insert filter to include the source and channel for the video.

    Pushing an update to WordPress shortly so please look for version 1.1.6 which will include these new filters.

    Below is some code to get you started.

    add_filter( 'tube_vc_filter_post_pre_insert' , 'my_custom_tube_import_post', 10, 3 );
    
    function my_custom_tube_import_post( $my_post, $source_site, $creator_name ) {
    
      $my_post['post_content'] = '[spoiler]' . $my_post['post_content'] . '[/spoiler]';
    
      $my_post['post_author'] = 6;
    
      return $my_post;
    
    }
    
    add_filter( 'tube_vc_filter_import_term' , 'my_custom_tube_import_terms', 10, 3 );
    
    function my_custom_tube_import_terms( $default_term, $source_site, $creator_name ) {
      
      $my_terms = array( 9, 34, 50, 72 ); // McMahon, Paton, Singletary, Perry
      
      return $my_terms;
      
    }

    A few notes…

    1) The post_author expects an author ID, so you’ll need a mechanism (e.g. User Meta) to associate the channel with the author.

    I’d suggest something like SITENAME-CHANNELNAME as the value for this usermeta. So for example, for this channel you might set a user mata key called user_channel_slug with the value “youtube-h3h3productions” which you could then use to find the correct user inside the filter like this (not tested):

    $users = get_users( 
      array( 
        'meta_key' => 'user_channel_slug', 
        'meta_value' => sanitize_title( $source_site . ' ' $creator_name ), 
      ) 
    )
    
    if ( $users ):
      $my_post['post_author'] = $users[0]->ID;

    endif;`

    2) I’ve not tested this either, but the terms tube_vc_filter_import_term should also accept either (a) a single term ID, (b) a single term slug, or (c) an array of terms slugs as a return value.

    Here again you can test on the $source_site and $creator_name to decide which term(s) to associate with the post.

    Plugin Author tubegtld

    (@tubegtld)

    BAH, won’t let me edit and there’s a bit of a mistake in formatting above where the endif got outside the code block.

    Fix here…

    $users = get_users( 
      array( 
        'meta_key' => 'user_channel_slug', 
        'meta_value' => sanitize_title( $source_site . ' ' $creator_name ), 
      ) 
    )
    
    if ( $users ):
      $my_post['post_author'] = $users[0]->ID;
    endif;
    Thread Starter dreyg9

    (@dreyg9)

    Hello! Spoiler is working! Thank you very much!

    But author don’t work ??

    Parse error: syntax error, unexpected ‘$creator_name’ (T_VARIABLE), expecting ‘,’ or ‘)’ in /var/www/u0247738/data/www/youpolitics.ru/wp-content/themes/xcel/functions.php on line 439

    Plugin Author tubegtld

    (@tubegtld)

    My only guess is that you’re trying to use the snippet from my last comment outside of the filter function from the previous comment.

    The whole thing would look like this…

    add_filter( 'tube_vc_filter_post_pre_insert' , 'my_custom_tube_import_post', 10, 3 );
    
    function my_custom_tube_import_post( $my_post, $source_site, $creator_name ) {
    
      $my_post['post_content'] = '[spoiler]' . $my_post['post_content'] . '[/spoiler]';
    
      $users = get_users( 
        array( 
          'meta_key' => 'user_channel_slug', 
          'meta_value' => sanitize_title( $source_site . ' ' $creator_name ), 
        ) 
      )
    
      if ( $users ):
        $my_post['post_author'] = $users[0]->ID;
      endif;
    
      return $my_post;
    
    }

    Hope that helps. If not, please post the entire relevant snippet from your functions.php file.

    Thread Starter dreyg9

    (@dreyg9)

    Parse error: syntax error, unexpected ‘$creator_name’ (T_VARIABLE), expecting ‘,’ or ‘)’ in /var/www/u0247738/data/www/youpolitics.ru/wp-content/themes/xcel/functions.php on line 423

    ??

    add_filter( ‘tube_vc_filter_post_pre_insert’ , ‘my_custom_tube_import_post’, 10, 3 );

    function my_custom_tube_import_post( $my_post, $source_site, $creator_name ) {

    $my_post[‘post_content’] = ‘[spoiler]’ . $my_post[‘post_content’] . ‘[/spoiler]’;

    $users = get_users(
    array(
    ‘meta_key’ => ‘user_channel_slug’,
    ‘meta_value’ => sanitize_title( $source_site . ‘ ‘ $creator_name ),
    )
    )

    if ( $users ):
    $my_post[‘post_author’] = $users[0]->ID;
    endif;

    return $my_post;

    }

    add_filter( ‘tube_vc_filter_import_term’ , ‘my_custom_tube_import_terms’, 10, 3 );

    function my_custom_tube_import_terms( $default_term, $source_site, $creator_name ) {

    $my_terms = array( 9, 34, 50, 72 ); // McMahon, Paton, Singletary, Perry

    return $my_terms;

    }

    https://drive.google.com/file/d/0BzoaSvJgni2HTHFzRUROSTNzNm8/view?usp=sharing

    Plugin Author tubegtld

    (@tubegtld)

    Missing a dot. Fix below.

      $users = get_users( 
        array( 
          'meta_key' => 'user_channel_slug', 
          'meta_value' => sanitize_title( $source_site . ' ' . $creator_name ), 
        ) 
      )
    Thread Starter dreyg9

    (@dreyg9)

    Missing a dot. Fix below.

    Parse error: syntax error, unexpected ‘if’ (T_IF) in /var/www/u0247738/data/www/youpolitics.ru/wp-content/themes/xcel/functions.php on line 427

    now ??

    line 427: if ( $users ):

    Plugin Author tubegtld

    (@tubegtld)

    Now missing a semi-colon. Complete snippet with fixes below.

    add_filter( 'tube_vc_filter_post_pre_insert' , 'my_custom_tube_import_post', 10, 3 );
    
    function my_custom_tube_import_post( $my_post, $source_site, $creator_name ) {
    
      $my_post['post_content'] = '[spoiler]' . $my_post['post_content'] . '[/spoiler]';
    
      $users = get_users(
        array(
          'meta_key' => 'user_channel_slug',
          'meta_value' => sanitize_title( $source_site . ' ' . $creator_name ),
        )
      );
    
      if ( $users ):
        $my_post['post_author'] = $users[0]->ID;
      endif;
    
      return $my_post;
    
    }
    
    add_filter( 'tube_vc_filter_import_term' , 'my_custom_tube_import_terms', 10, 3 );
    
    function my_custom_tube_import_terms( $default_term, $source_site, $creator_name ) {
    
      $my_terms = array( 9, 34, 50, 72 ); // McMahon, Paton, Singletary, Perry
    
      return $my_terms;
    
    }
    • This reply was modified 7 years, 3 months ago by tubegtld.
    Thread Starter dreyg9

    (@dreyg9)

    Ok, now I have not errors, but author do not add.

    for example

    channel https://www.youtube.com/channel/UCvh7M2BvWW1cabkELmIYUAQ/featured

    https://imagestun.com/hosting/?v=slugvjv.jpg

    Is it correct?

    • This reply was modified 7 years, 3 months ago by dreyg9.
    Plugin Author tubegtld

    (@tubegtld)

    The user_channel_slug for this author should be youtube-oleg-neretin

    • This reply was modified 7 years, 3 months ago by tubegtld.
    Thread Starter dreyg9

    (@dreyg9)

    Don’t work :(((

    Author add as Default Author ??

    Plugin Author tubegtld

    (@tubegtld)

    The code above is tested and working in our development environment, so sorry to say but there must be something amiss on your end.

    1) Be sure you’ve added the complete code snippet above to your active child theme’s function.php or a plugin that’s been activated.

    2) Be sure that you’ve added USER meta for the author in question that has a key of user_channel_slug and a value of the source site and channel name after a sanitize_title filter.

    Steps to test…

    1) Create a new user with any name and at least “author” credentials, and make note of the user_id

    2) Run this code snippet…

    update_user_meta( 2, 'user_channel_slug', 'youtube-mama-natural');

    IMPORTANT: Be sure to replace 2 with the user_id for the new user

    3) Go to the plugin settings page for “Add Channels & Playlists”

    4) Search for “Mama Natural”, then find and “Save” the channel with 230,000+ subscribers (pic of brunette woman holding a baby)

    5) Go to “Find Videos” for that channel

    6) Publish a video, then click the “edit” link

    7) Confirm that the author is properly set to the user with the id matching the ID from steps 1 and 2 above

    As this is tested and working in our dev setup, and we’ve provided complete sample code, at this point we won’t be able to provide further free support for this ticket.

    Thread Starter dreyg9

    (@dreyg9)

    It works :)))

    Thank you,
    thank you,
    thank you very much!

    5 stars!

    • This reply was modified 7 years, 3 months ago by dreyg9.
Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Customize’ is closed to new replies.