/** * Enqueue the admin scripts for the widget form. */ function enqueue_scripts() { if (!wp_script_is('siteorigin-widget-admin')) { wp_enqueue_style('wp-color-picker'); wp_enqueue_style('siteorigin-widget-admin', plugin_dir_url(SOW_BUNDLE_BASE_FILE) . 'base/css/admin.css', array('media-views'), SOW_BUNDLE_VERSION); wp_enqueue_script('wp-color-picker'); wp_enqueue_media(); wp_enqueue_script('siteorigin-widget-admin', plugin_dir_url(SOW_BUNDLE_BASE_FILE) . 'base/js/admin' . SOW_BUNDLE_JS_SUFFIX . '.js', array('jquery', 'jquery-ui-sortable', 'jquery-ui-slider'), SOW_BUNDLE_VERSION, true); wp_localize_script('siteorigin-widget-admin', 'soWidgets', array('ajaxurl' => wp_nonce_url(admin_url('admin-ajax.php'), 'widgets_action', '_widgets_nonce'), 'sure' => __('Are you sure?', 'siteorigin-widgets'))); global $wp_customize; if (isset($wp_customize)) { $this->footer_admin_templates(); } else { add_action('admin_footer', array($this, 'footer_admin_templates')); } } if ($this->using_posts_selector()) { siteorigin_widget_post_selector_enqueue_admin_scripts(); } // This lets the widget enqueue any specific admin scripts $this->enqueue_admin_scripts(); do_action('siteorigin_widgets_enqueue_admin_scripts_' . $this->id_base, $this); }
/** * Display the form for the post loop. * * @param array $instance * @return string|void */ function form($instance) { $instance = wp_parse_args($instance, array('title' => '', 'template' => 'loop.php', 'post_type' => 'post', 'posts_per_page' => '', 'order' => 'DESC', 'orderby' => 'date', 'sticky' => '', 'additional' => '', 'more' => false)); $templates = $this->get_loop_templates(); if (empty($templates)) { ?> <p><?php _e("Your theme doesn't have any post loops.", 'siteorigin-panels'); ?> </p><?php return; } ?> <p> <label for="<?php echo $this->get_field_id('title'); ?> "><?php _e('Title', 'siteorigin-panels'); ?> </label> <input type="text" class="widefat" name="<?php echo $this->get_field_name('title'); ?> " id="<?php echo $this->get_field_id('title'); ?> " value="<?php echo esc_attr($instance['title']); ?> "> </p> <p> <label for="<?php echo $this->get_field_id('template'); ?> "><?php _e('Template', 'siteorigin-panels'); ?> </label> <select id="<?php echo $this->get_field_id('template'); ?> " name="<?php echo $this->get_field_name('template'); ?> "> <?php foreach ($templates as $template) { ?> <option value="<?php echo esc_attr($template); ?> " <?php selected($instance['template'], $template); ?> > <?php $headers = get_file_data(locate_template($template), array('loop_name' => 'Loop Name')); echo esc_html(!empty($headers['loop_name']) ? $headers['loop_name'] : $template); ?> </option> <?php } ?> </select> </p> <p> <label for="<?php echo $this->get_field_id('more'); ?> "><?php _e('More Link', 'siteorigin-panels'); ?> </label> <input type="checkbox" class="widefat" id="<?php echo $this->get_field_id('more'); ?> " name="<?php echo $this->get_field_name('more'); ?> " <?php checked($instance['more']); ?> /><br/> <small><?php _e('If the template supports it, cut posts and display the more link.', 'siteorigin-panels'); ?> </small> </p> <?php // If the Widgets Bundle is installed and the post selector is available, use that. // Otherwise revert back to our own form fields. if (function_exists('siteorigin_widget_post_selector_enqueue_admin_scripts')) { siteorigin_widget_post_selector_enqueue_admin_scripts(); $value = ''; if (!empty($instance['posts']) && !is_array($instance['posts'])) { $value = $instance['posts']; } else { if (!empty($instance['post_type'])) { $value .= 'post_type=' . $instance['post_type']; $value .= '&posts_per_page=' . $instance['posts_per_page']; $value .= '&order=' . $instance['order']; $value .= '&orderby=' . $instance['orderby']; $value .= '&sticky=' . $instance['sticky']; $value .= '&additional=' . $instance['additional']; } } siteorigin_widget_post_selector_admin_form_field($value, $this->get_field_name('posts')); } else { if (!empty($instance['posts'])) { $instance = wp_parse_args($instance['posts'], $instance); unset($instance['posts']); //unset post__in and taxonomies? } // Get all the loop template files $post_types = get_post_types(array('public' => true)); $post_types = array_values($post_types); $post_types = array_diff($post_types, array('attachment', 'revision', 'nav_menu_item')); ?> <p> <label for="<?php echo $this->get_field_id('post_type'); ?> "><?php _e('Post Type', 'siteorigin-panels'); ?> </label> <select id="<?php echo $this->get_field_id('post_type'); ?> " name="<?php echo $this->get_field_name('post_type'); ?> " value="<?php echo esc_attr($instance['post_type']); ?> "> <?php foreach ($post_types as $type) { ?> <option value="<?php echo esc_attr($type); ?> " <?php selected($instance['post_type'], $type); ?> ><?php echo esc_html($type); ?> </option> <?php } ?> </select> </p> <p> <label for="<?php echo $this->get_field_id('posts_per_page'); ?> "><?php _e('Posts Per Page', 'siteorigin-panels'); ?> </label> <input type="text" class="small-text" id="<?php echo $this->get_field_id('posts_per_page'); ?> " name="<?php echo $this->get_field_name('posts_per_page'); ?> " value="<?php echo esc_attr($instance['posts_per_page']); ?> " /> </p> <p> <label <?php echo $this->get_field_id('orderby'); ?> ><?php _e('Order By', 'siteorigin-panels'); ?> </label> <select id="<?php echo $this->get_field_id('orderby'); ?> " name="<?php echo $this->get_field_name('orderby'); ?> " value="<?php echo esc_attr($instance['orderby']); ?> "> <option value="none" <?php selected($instance['orderby'], 'none'); ?> ><?php esc_html_e('None', 'siteorigin-panels'); ?> </option> <option value="ID" <?php selected($instance['orderby'], 'ID'); ?> ><?php esc_html_e('Post ID', 'siteorigin-panels'); ?> </option> <option value="author" <?php selected($instance['orderby'], 'author'); ?> ><?php esc_html_e('Author', 'siteorigin-panels'); ?> </option> <option value="name" <?php selected($instance['orderby'], 'name'); ?> ><?php esc_html_e('Name', 'siteorigin-panels'); ?> </option> <option value="name" <?php selected($instance['orderby'], 'name'); ?> ><?php esc_html_e('Name', 'siteorigin-panels'); ?> </option> <option value="date" <?php selected($instance['orderby'], 'date'); ?> ><?php esc_html_e('Date', 'siteorigin-panels'); ?> </option> <option value="modified" <?php selected($instance['orderby'], 'modified'); ?> ><?php esc_html_e('Modified', 'siteorigin-panels'); ?> </option> <option value="parent" <?php selected($instance['orderby'], 'parent'); ?> ><?php esc_html_e('Parent', 'siteorigin-panels'); ?> </option> <option value="rand" <?php selected($instance['orderby'], 'rand'); ?> ><?php esc_html_e('Random', 'siteorigin-panels'); ?> </option> <option value="comment_count" <?php selected($instance['orderby'], 'comment_count'); ?> ><?php esc_html_e('Comment Count', 'siteorigin-panels'); ?> </option> <option value="menu_order" <?php selected($instance['orderby'], 'menu_order'); ?> ><?php esc_html_e('Menu Order', 'siteorigin-panels'); ?> </option> <option value="post__in" <?php selected($instance['orderby'], 'post__in'); ?> ><?php esc_html_e('Post In Order', 'siteorigin-panels'); ?> </option> </select> </p> <p> <label for="<?php echo $this->get_field_id('order'); ?> "><?php _e('Order', 'siteorigin-panels'); ?> </label> <select id="<?php echo $this->get_field_id('order'); ?> " name="<?php echo $this->get_field_name('order'); ?> " value="<?php echo esc_attr($instance['order']); ?> "> <option value="DESC" <?php selected($instance['order'], 'DESC'); ?> ><?php esc_html_e('Descending', 'siteorigin-panels'); ?> </option> <option value="ASC" <?php selected($instance['order'], 'ASC'); ?> ><?php esc_html_e('Ascending', 'siteorigin-panels'); ?> </option> </select> </p> <p> <label for="<?php echo $this->get_field_id('sticky'); ?> "><?php _e('Sticky Posts', 'siteorigin-panels'); ?> </label> <select id="<?php echo $this->get_field_id('sticky'); ?> " name="<?php echo $this->get_field_name('sticky'); ?> " value="<?php echo esc_attr($instance['sticky']); ?> "> <option value="" <?php selected($instance['sticky'], ''); ?> ><?php esc_html_e('Default', 'siteorigin-panels'); ?> </option> <option value="ignore" <?php selected($instance['sticky'], 'ignore'); ?> ><?php esc_html_e('Ignore Sticky', 'siteorigin-panels'); ?> </option> <option value="exclude" <?php selected($instance['sticky'], 'exclude'); ?> ><?php esc_html_e('Exclude Sticky', 'siteorigin-panels'); ?> </option> <option value="only" <?php selected($instance['sticky'], 'only'); ?> ><?php esc_html_e('Only Sticky', 'siteorigin-panels'); ?> </option> </select> </p> <p> <label for="<?php echo $this->get_field_id('additional'); ?> "><?php _e('Additional ', 'siteorigin-panels'); ?> </label> <input type="text" class="widefat" id="<?php echo $this->get_field_id('additional'); ?> " name="<?php echo $this->get_field_name('additional'); ?> " value="<?php echo esc_attr($instance['additional']); ?> " /> <small> <?php echo preg_replace('/1\\{ *(.*?) *\\}/', '<a href="http://codex.wordpress.org/Function_Reference/query_posts">$1</a>', __('Additional query arguments. See 1{query_posts}.', 'siteorigin-panels')); ?> </small> </p> <?php } }