esc_html__( 'An widget to upload Ad and images in sidebar.', 'business-center-pro' ), ) // Args ); } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget( $args, $instance ) { $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); $image_url = ! empty( $instance['image_url'] ) ? $instance['image_url'] : ''; $link = ! empty( $instance['link'] ) ? $instance['link'] : ''; $alt_text = ! empty( $instance['alt_text'] ) ? $instance['alt_text'] : ''; $open_link = ! empty( $instance['open_link'] ) ? $instance['open_link'] : false; $ad_code = ! empty( $instance['ad_code'] ) ? $instance['ad_code'] : ''; $instance['link_open'] = ''; $instance['link_close'] = ''; if ( ! empty ( $link ) ) { $target = ( empty( $open_link ) ) ? '' : ' target="_blank" '; $instance['link_open'] = ''; $instance['link_close'] = ''; } echo $args['before_widget']; if ( $title ) { echo $args['before_title'] ; echo esc_html( $title ); echo $args['after_title'] ; } if ( ! empty( $ad_code ) ) { echo $ad_code; } elseif ( ! empty( $image_url ) ) { $sizes = array(); $alt_text = ( ! empty( $alt_text ) ) ? $alt_text : basename( $image_url ); $imgtag = '' . esc_attr( $alt_text ) . ''; echo sprintf( '%s%s%s', $instance['link_open'], $imgtag, $instance['link_close'] ); } // End if : image is there. echo $args['after_widget']; } /** * Back-end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. */ public function form( $instance ) { // Defaults. $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'image_url' => '', 'link' => '', 'alt_text' => '', 'open_link' => 0, 'ad_code' => '', ) ); $title = htmlspecialchars( $instance['title'] ); $ad_type = isset( $instance['ad_type'] ) ? esc_html( $instance['ad_type'] ) : 'image-ad'; $image_url = isset( $instance['image_url'] ) ? $instance['image_url'] : ''; $link = isset( $instance['link'] ) ? $instance['link'] : ''; $alt_text = isset( $instance['alt_text'] ) ? $instance['alt_text'] : ''; $open_link = isset( $instance['open_link'] ) ? $instance['open_link'] : false; $ad_code = isset( $instance['ad_code' ] ) ? $instance['ad_code'] : ''; ?>


:

> <?php esc_attr_e( 'Preview', 'business-center-pro' ); ?>

/>

array(), "type" => array(), "allowfullscreen" => array(), "allowscriptaccess" => array(), "height" => array(), "width" => array() ); $custom_allowedtags["script"] = array(); $custom_allowedtags = array_merge( $custom_allowedtags, $allowedposttags ); $output = wp_kses( $input, $custom_allowedtags ); return $output; } /** * Sanitize widget form values as they are saved. * * @see WP_Widget::update() * * @param array $new_instance Values just sent to be saved. * @param array $old_instance Previously saved values from database. * * @return array Updated safe values to be saved. */ public function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? sanitize_text_field( $new_instance['title'] ): ''; $instance['image_url'] = esc_url_raw( $new_instance['image_url'] ); $instance['link'] = esc_url_raw( $new_instance['link'] ); $instance['alt_text'] = sanitize_text_field( $new_instance['alt_text'] ); $instance['open_link'] = isset( $new_instance['open_link'] ) ? (bool) $new_instance['open_link'] : false; $instance['ad_code'] = $this->business_center_pro_sanitize_ad_code( $new_instance['ad_code'] ); if ( in_array( $new_instance['ad_type'], array( 'image-ad', 'html-js-ad' ) ) ) { $instance['ad_type'] = sanitize_text_field( $new_instance['ad_type'] ); } else { $instance['ad_type'] = 'image-ad'; } return $instance; } } // class Business_Center_Pro_Advertisement endif; /** * Enqueue admin scripts for Image Widget * @uses wp_enqueue_script, and admin_enqueue_scripts hook * * @since Business Center Pro 2.0.0 */ function business_center_pro_advertisement_upload_enqueue( $hook ) { if( 'widgets.php' !== $hook ) return; wp_enqueue_media(); wp_enqueue_script( 'business-center-proimage-widget-upload-script', get_template_directory_uri().'/assets/js/upload.min.js', array( 'jquery' ), '1.1', true ); } add_action( 'admin_enqueue_scripts', 'business_center_pro_advertisement_upload_enqueue' );