get( 'orderby' ); if ( in_array( $orderby, array( 'sby_channel_title', 'sby_video_id', 'sby_youtube_publish_date' ), true ) ) { $query->set( 'meta_key', $orderby ); $query->set( 'orderby', 'meta_value' ); } if ( isset( $_GET['channel_id'] ) && $query->is_main_query() && $query->query_vars['post_type'] == SBY_CPT ) { //Get original meta query $meta_query = (array) $query->get( 'meta_query' ); // Add your criteria $meta_query[] = array( 'key' => 'sby_channel_id', 'value' => sanitize_text_field( $_GET['channel_id'] ), 'compare' => '=', ); // Set the meta query to the complete, altered query $query->set( 'meta_query', $meta_query ); } } public static function channel_action_listener() { if ( ! isset( $_GET['sby_action'] ) || ! isset( $_GET['channel'] ) ) { return; } $action = sanitize_text_field( $_GET['sby_action'] ); $channel_id = sanitize_text_field( $_GET['channel'] ); if ( $action === 'publish' ) { if ( ! empty( $channel_id ) ) { $args = array( 'channel_id' => $channel_id, 'post_status' => array( 'draft', 'pending' ), 'posts_per_page' => - 1 ); $draft_posts = new SBY_YT_Query( $args ); $draft_posts_arr = $draft_posts->get_posts(); foreach ( $draft_posts_arr as $post ) { $update_post = array( 'ID' => $post->ID, 'post_status' => 'publish' ); wp_update_post( $update_post ); } } } elseif ( $action === 'trash' ) { if ( ! empty( $channel_id ) ) { $args = array( 'channel_id' => $channel_id, 'post_status' => 'any', 'posts_per_page' => - 1 ); $draft_posts = new SBY_YT_Query( $args ); $draft_posts_arr = $draft_posts->get_posts(); foreach ( $draft_posts_arr as $post ) { wp_trash_post( $post->ID ); } } } wp_safe_redirect( admin_url( 'admin.php?page=youtube-feed-single-videos' ) ); } public static function youtube_feed_single( $atts = array() ) { $atts = ! empty( $atts ) ? $atts : array(); if ( isset( $atts['postid'] ) ) { $args = array( 'p' => $atts['postid'], 'post_status' => 'any', 'posts_per_page' => - 1 ); $vid_posts = new SBY_YT_Query( $args ); $vid_posts_arr = $vid_posts->get_posts(); if ( isset ( $vid_posts_arr[0] ) ) { $youtube_post = $vid_posts_arr[0]; } } elseif ( isset( $atts['videoid'] ) ) { $args = array( 'video_id' => $atts['videoid'], 'post_status' => 'any', 'posts_per_page' => - 1 ); $vid_posts = new SBY_YT_Query( $args ); $vid_posts_arr = $vid_posts->get_posts(); if ( isset ( $vid_posts_arr[0] ) ) { $youtube_post = $vid_posts_arr[0]; } } else { global $post; if ( $post->post_type === SBY_CPT ) { $youtube_post = $post; } } if ( ! isset( $youtube_post ) ) { return 'Need to add Post ID'; } global $sby_settings; $youtube_post_meta = get_post_meta( $youtube_post->ID ); $api_data = json_decode( $youtube_post_meta['sby_json'][0], true ); $settings = $sby_settings; $shortcode_atts = wp_json_encode( $atts ); $options_att_arr['cta'] = array( 'type' => 'default' ); if ( $settings['cta'] === 'link' ) { $options_att_arr['cta']['type'] = 'link'; } $options_att_arr['cta']['defaultLink'] = $settings['linkurl']; $options_att_arr['cta']['defaultText'] = $settings['linktext']; $options_att_arr['cta']['openType'] = $settings['linkopentype']; $button_color = str_replace( '#', '', $settings['linkcolor'] ); $button_text_color = str_replace( '#', '', $settings['linktextcolor'] ); $options_att_arr['cta']['color'] = ! empty( $button_color ) ? sby_hextorgb( $button_color ) : ''; $options_att_arr['cta']['textColor'] = ! empty( $button_text_color ) ? sby_hextorgb( $button_text_color ) : ''; if ( ! empty( $settings['descriptionlength'] ) ) { $options_att_arr['descriptionlength'] = (int)$settings['descriptionlength']; } $other_atts = ' data-options="'.esc_attr( wp_json_encode( $options_att_arr ) ).'"'; $icon_type = $settings['font_method']; wp_enqueue_script( 'sby_scripts' ); include sby_get_feed_template_part( 'shortcode-content', $settings ); } public static function get_sby_cpt_settings() { $defaults = array( 'include' => array( 'description', 'stats' ), 'post_status' => 'draft' ); $sby_videos_settings = get_option( SBY_CPT . '_settings', $defaults ); return $sby_videos_settings; } public static function setting_name( $name, $is_array = false ) { $return = SBY_CPT . '_settings[' . $name . ']'; if ( $is_array ) { $return .= '[]'; } return $return; } public static function validate_options( $input, $option_name ) { $updated_options = get_option( $option_name, array() ); foreach ( $input as $key => $val ) { if ( is_array( $val ) ) { $updated_options[ $key ] = array(); foreach ( $val as $val2 ) { $updated_options[ $key ][] = sanitize_text_field( $val2 ); } } else { // include in search set to false if ( $val === 'on' ) { $val = true; } if ( $key === 'search_include' ) { $updated_options[ $key ] = false; } else { $updated_options[ $key ] = sanitize_text_field( $val ); } } } $updated_options = apply_filters( 'sby_single_settings_valid_options', $updated_options, $input ); return $updated_options; } }