'aladdin_page_aladding', 'description' => __('Display styled page', 'aladdin' )); /* Widget control settings. */ $control_ops = array( 'width' => 250, 'height' => 200, 'id_base' => 'aladdin_page_aladding'); /* Create the widget. */ parent::__construct( 'aladdin_page_aladding', __('Al Page Styled (Aladdin)', 'aladdin' ), $widget_ops, $control_ops ); add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); add_action( 'admin_footer-widgets.php', array( $this, 'print_scripts' ), 9999 ); } /** * Fix for the color-picker * * @since Aladdin 1.0.0 * */ public function print_scripts() { ?> defaults( $instance ) ); $width = $this->get_width($sidebar_id, 2); $aladdin_curr_page_id = $instance['page_id']; /* save current page id in global variable, use it in sidebar-X-widget.php */ $query = new WP_Query( array( 'order' => 'DESC', 'posts_per_page' => 1, 'no_found_rows' => true, 'post_status' => 'publish', 'post__in' => array( $aladdin_curr_page_id ), 'post_type' => 'page', ) ); if ( $query->have_posts() || isset( $instance['ttl'] ) ) : $tmp_content_width = $GLOBALS['content_width']; $GLOBALS['content_width'] = $width; //print the widget for the sidebar $colors = ''; if ( '1' == $instance['background_style'] || '2' == $instance['background_style'] ) { $widget_ops = 'background-color: ' . esc_attr( aladdin_hex_to_rgba( $instance['background'], $instance['opacity'] ) ) . '; '; if ( false !== strrpos( $args['before_widget'], "style='" ) ) { $args['before_widget'] = preg_replace( "/
id_base ); if ( '' != $widget_ops ) { if ( false !== strrpos( $args['before_title'], "style='" ) ) { $args['before_title'] = preg_replace( "/

>
have_posts() ) { $query->the_post(); } ?>
' . esc_attr( $instance['ttl'] ) . '

'; else : the_title( '

', '

' ); endif; endif; ?>
', '' ); ?>
sanitize_hex_color( $new_instance['background'] ); $instance['body_font_color'] = $this->sanitize_hex_color( $new_instance['body_font_color'] ); $instance['header_color'] = $this->sanitize_hex_color( $new_instance['header_color'] ); $instance['max_width'] = absint( $new_instance['max_width'] ); $instance['body_font_size'] = absint( $new_instance['body_font_size'] ); $instance['header_font_size'] = absint( $new_instance['header_font_size'] ); $instance['caption'] = esc_attr( $new_instance['caption'] ); $instance['link'] = esc_url( $new_instance['link'] ); return $instance; } /** * Widget form * * @since Aladdin 1.0.0 * * @param array $instance Array of widget options. */ function form( $instance ) { // Output admin widget options form // Set up some default widget settings. $instance = wp_parse_args( (array) $instance, $this->defaults( $instance ) ); aladdin_echo_input_text( $this, 'title', $instance, __( 'Title: ', 'aladdin' ), 0); aladdin_echo_input_checkbox( $this, 'is_no_title', $instance, __( 'No Title', 'aladdin')); aladdin_echo_input_checkbox( $this, 'is_centered', $instance, __( 'Text align center', 'aladdin')); aladdin_echo_input_checkbox( $this, 'is_post_thumbnail', $instance, __( 'Display Image', 'aladdin')); aladdin_echo_input_checkbox( $this, 'is_search', $instance, __( 'Add Search', 'aladdin')); $pages = get_pages(); esc_html_e('Page:', 'aladdin'); ?> get_field_id( 'max_width' ) ); aladdin_echo_input_text( $this, 'max_width', $instance, __( 'Max width: ', 'aladdin' ), 0); aladdin_echo_input_text( $this, 'header_font_size', $instance, __( 'Header Font size: ', 'aladdin' ), 0); aladdin_echo_input_text( $this, 'body_font_size', $instance, __( 'Body Font size: ', 'aladdin' ), 0); aladdin_echo_section_end(); aladdin_echo_section_start( __( 'Widget colors', 'aladdin' ), $this->get_field_id( 'background' ) ); $defaults = $this->defaults( $instance ); aladdin_echo_input_color( $this, 'background', $instance, __( 'Background color: ', 'aladdin' ), $defaults['background'] ); esc_html_e('Background Opacity:', 'aladdin'); ?> get_field_id( 'link' ) ); aladdin_echo_input_checkbox( $this, 'is_button', $instance, __( 'Add Button', 'aladdin')); aladdin_echo_input_text( $this, 'caption', $instance, __( 'Caption: ', 'aladdin' ), 0); aladdin_echo_input_text( $this, 'link', $instance, __( 'Link: ', 'aladdin' ), 0); aladdin_echo_section_end(); } /** * Return array Defaults * * @since Aladdin 1.0.0 */ function defaults( $instance ){ $defaults = array('title' => __( 'Page', 'aladdin' ), 'page_id' => '', 'is_no_title' => '', 'is_centered' => '', 'is_transparent' => '', 'is_post_thumbnail' => ( isset( $instance[ 'page_id' ] ) ? '' : '1' ), 'layout' => 'no-sidebar', 'opacity' => '0.5', 'background' => '#fff', 'max_width' => '1366', 'body_font_size' => '26', 'header_font_size' => '32', 'body_font_color' => '#fff', 'header_color' => '#fff', 'background_style' => '1', 'is_search' => '', 'is_button' => '', 'caption' => __( 'Button', 'aladdin' ), 'link' => '#', 'image_size' => 'post-thumbnail', ); return $defaults; } /* Sanitize hex color. * @param string color. * @return string color. */ function sanitize_hex_color( $color ) { if ( '' === $color ) return ''; // 3 or 6 hex digits, or the empty string. if ( preg_match('|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) ) return $color; return null; } /* widget column width * @param int $sidebar_id sidebar id. * @param int $columns number of $columns. * @param int $i1 widget left margin. * @param int $i2 widget right margin. * @return int width. * @since Aladdin 1.0.0 */ function get_width( $sidebar_id, $columns, $i1 = 0, $i2 = 0 ) { if($columns <= 0) $columns = 1; $width = aladdin_get_sidebar_width($sidebar_id); $width = ($width - $width*$i1/100 - $width*$i2/100)/$columns; return $width; } } /* Register widget * * @since Aladdin 1.0.0 * */ function aladdin_register_page_widget_2() { register_widget( 'aladdin_page_aladding' ); } add_action( 'widgets_init', 'aladdin_register_page_widget_2' );