0 && get_post_thumbnail_id( $post_id ) ) { // Has main image selected return -2; } $children = get_children( array( 'post_parent' => $post_id ) ); foreach( $children as $child ) { update_post_meta( $post_id, '_thumbnail_id', $child->ID ); return 1; } return 0; } } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Limit Active User Listings * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ function adosui_limit_user_active_listings_init() { remove_shortcode( "adverts_add" ); add_shortcode( "adverts_add", "adosui_limit_user_active_listings_shortcode" ); } add_action( "init", "adosui_limit_user_active_listings_init", 20 ); function adosui_limit_user_active_listings_shortcode( $atts ) { $options = get_option('adosui_extended_options_settings'); if ( $options['adosui_number_max_ads'] == "") { $max = 1000000; } else { $max = $options['adosui_number_max_ads']; } $flash = array( "error" => array( ), "info" => array( ) ); $args = array( 'post_type' => 'advert', 'post_status' => 'publish', 'author' => get_current_user_id(), ); $query = new WP_Query( $args ); if( $query->found_posts >= $max ) { $message = __( 'You reached maximum active ads limit. You cannot have more than %d active Ads at once.', "adosui" ); $flash["error"][] = array( "message" => sprintf( $message, $max ), "icon" => "adverts-icon-attention-alt" ); ob_start(); adverts_flash( $flash ); return ob_get_clean(); } return shortcode_adverts_add( $atts ); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Make Category Selection Mandatory * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ $options = get_option('adosui_extended_options_settings'); if($options['adosui_checkbox_mandatory_category'] == true) { function adosui_make_advert_category_required( $form ) { if( $form['name'] != "advert" ) { return $form; } foreach( $form["field"] as $key => $field ) { if( $field["name"] == "advert_category" ) { $form["field"][$key]["validator"][] = array( "name"=> "is_required" ); } } return $form; } add_filter( "adverts_form_load", "adosui_make_advert_category_required" ); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Limit Category Selection To 1 (one) * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ $options = get_option('adosui_extended_options_settings'); if($options['adosui_checkbox_limit_category_selection_1'] == true) { function adosui_limit_category_selection( $form ) { if($form["name"] != 'advert' || is_admin()) { return $form; } $count = count( $form["field"] ); for( $i = 0; $i < $count; $i++ ) { if($form["field"][$i]["name"] == "advert_category") { $form["field"][$i]["empty_option"] = 1; $form["field"][$i]["empty_option_text"] = "- Choose Category -"; $form["field"][$i]["max_choices"] = 1; } } return $form; } add_filter("adverts_form_load", "adosui_limit_category_selection"); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Show Expireation Date * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ function adosui_expireation_date_classic( $post_id ) { ?>