├── readme.txt ├── core-functionality.php └── inc ├── general.php ├── widget-sample.php └── cpt-testimonial.php /readme.txt: -------------------------------------------------------------------------------- 1 | === Core Functionality === 2 | 3 | This contains all your site's core functionality so that it is theme independent. 4 | 5 | More information: 6 | http://www.billerickson.net/core-functionality-plugin/ 7 | https://github.com/billerickson/Core-Functionality/ -------------------------------------------------------------------------------- /core-functionality.php: -------------------------------------------------------------------------------- 1 | 47 | 63 | 84 | defaults = array( 35 | 'title' => '', 36 | 'widget_content' => '', 37 | ); 38 | 39 | // Widget Slug 40 | $widget_slug = 'ea-sample-widget'; 41 | 42 | // widget basics 43 | $widget_ops = array( 44 | 'classname' => $widget_slug, 45 | 'description' => 'Widget description goes here.' 46 | ); 47 | 48 | // widget controls 49 | $control_ops = array( 50 | 'id_base' => $widget_slug, 51 | //'width' => '400', 52 | ); 53 | 54 | // load widget 55 | parent::__construct( $widget_slug, 'BE_Sample_Widget', $widget_ops, $control_ops ); 56 | 57 | } 58 | 59 | /** 60 | * Outputs the HTML for this widget. 61 | * 62 | * @since 1.0.0 63 | * @param array $args An array of standard parameters for widgets in this theme 64 | * @param array $instance An array of settings for this widget instance 65 | */ 66 | function widget( $args, $instance ) { 67 | 68 | extract( $args ); 69 | 70 | // Merge with defaults 71 | $instance = wp_parse_args( (array) $instance, $this->defaults ); 72 | 73 | echo $before_widget; 74 | 75 | // Title 76 | if ( !empty( $instance['title'] ) ) { 77 | echo $before_title . apply_filters( 'widget_title', $instance['title'] ) . $after_title; 78 | } 79 | 80 | // Text 81 | if ( !empty( $instance['widget_content'] ) ) { 82 | echo esc_html( $instance['widget_content'] ); 83 | } 84 | 85 | echo $after_widget; 86 | } 87 | 88 | /** 89 | * Deals with the settings when they are saved by the admin. Here is 90 | * where any validation should be dealt with. 91 | * 92 | * @since 1.0.0 93 | * @param array $new_instance An array of new settings as submitted by the admin 94 | * @param array $old_instance An array of the previous settings 95 | * @return array The validated and (if necessary) amended settings 96 | */ 97 | function update( $new_instance, $old_instance ) { 98 | 99 | $new_instance['title'] = strip_tags( $new_instance['title'] ); 100 | $new_instance['widget_content'] = esc_html( $new_instance['widget_content'] ); 101 | 102 | return $new_instance; 103 | } 104 | 105 | /** 106 | * Displays the form for this widget on the Widgets page of the WP Admin area. 107 | * 108 | * @since 1.0.0 109 | * @param array $instance An array of the current settings for this widget 110 | */ 111 | function form( $instance ) { 112 | 113 | // Merge with defaults 114 | $instance = wp_parse_args( (array) $instance, $this->defaults ); 115 | ?> 116 |

117 | 118 | 119 |

120 |

121 | 122 | 123 |

124 | 'FOO', 52 | 'singular_name' => 'FOO', 53 | 'search_items' => 'Search FOOs', 54 | 'popular_items' => 'Popular FOOs', 55 | 'all_items' => 'All FOOs', 56 | 'parent_item' => 'Parent FOO', 57 | 'parent_item_colon' => 'Parent FOO:', 58 | 'edit_item' => 'Edit FOO', 59 | 'update_item' => 'Update FOO', 60 | 'add_new_item' => 'Add New FOO', 61 | 'new_item_name' => 'New FOO', 62 | 'separate_items_with_commas' => 'Separate FOOs with commas', 63 | 'add_or_remove_items' => 'Add or remove FOOs', 64 | 'choose_from_most_used' => 'Choose from most used FOOs', 65 | 'menu_name' => 'FOOs', 66 | ); 67 | 68 | $args = array( 69 | 'labels' => $labels, 70 | 'public' => true, 71 | 'show_in_nav_menus' => true, 72 | 'show_ui' => true, 73 | 'show_tagcloud' => false, 74 | 'hierarchical' => false, 75 | 'rewrite' => array( 'slug' => 'cpt-slug/foo', 'with_front' => false ), 76 | 'query_var' => true, 77 | 'show_admin_column' => false, 78 | // 'meta_box_cb' => false, 79 | ); 80 | 81 | register_taxonomy( 'foo', array( 'testimonials' ), $args ); 82 | } 83 | 84 | /** 85 | * Register the custom post type 86 | * 87 | * @since 2.0.0 88 | */ 89 | function register_cpt() { 90 | 91 | $labels = array( 92 | 'name' => 'Testimonials', 93 | 'singular_name' => 'Testimonial', 94 | 'add_new' => 'Add New', 95 | 'add_new_item' => 'Add New Testimonial', 96 | 'edit_item' => 'Edit Testimonial', 97 | 'new_item' => 'New Testimonial', 98 | 'view_item' => 'View Testimonial', 99 | 'search_items' => 'Search Testimonials', 100 | 'not_found' => 'No Testimonials found', 101 | 'not_found_in_trash' => 'No Testimonials found in Trash', 102 | 'parent_item_colon' => 'Parent Testimonial:', 103 | 'menu_name' => 'Testimonials', 104 | ); 105 | 106 | $args = array( 107 | 'labels' => $labels, 108 | 'hierarchical' => false, 109 | 'supports' => array( 'title', 'editor', 'thumbnail' ), 110 | 'public' => true, 111 | 'show_ui' => true, 112 | 'show_in_menu' => true, 113 | 'show_in_nav_menus' => true, 114 | 'publicly_queryable' => true, 115 | 'exclude_from_search' => false, 116 | 'has_archive' => true, 117 | 'query_var' => true, 118 | 'can_export' => true, 119 | 'rewrite' => array( 'slug' => 'testimonials', 'with_front' => false ), 120 | 'menu_icon' => 'dashicons-groups', // https://developer.wordpress.org/resource/dashicons/ 121 | ); 122 | 123 | register_post_type( 'testimonial', $args ); 124 | 125 | } 126 | 127 | /** 128 | * Change the default title placeholder text 129 | * 130 | * @since 2.0.0 131 | * @global array $post 132 | * @param string $translation 133 | * @return string Customized translation for title 134 | */ 135 | function title_placeholder( $translation ) { 136 | 137 | global $post; 138 | if ( isset( $post ) && 'testimonial' == $post->post_type && 'Enter title here' == $translation ) { 139 | $translation = 'Enter Name Here'; 140 | } 141 | return $translation; 142 | 143 | } 144 | 145 | /** 146 | * Customize the Testimonials Query 147 | * 148 | * @since 2.0.0 149 | * @param object $query 150 | */ 151 | function testimonial_query( $query ) { 152 | if( $query->is_main_query() && !is_admin() && $query->is_post_type_archive( 'testimonial' ) ) { 153 | $query->set( 'posts_per_page', 20 ); 154 | } 155 | } 156 | 157 | /** 158 | * Redirect Single Testimonials 159 | * 160 | * @since 2.0.0 161 | */ 162 | function redirect_single() { 163 | if( is_singular( 'testimonial' ) ) { 164 | wp_redirect( get_post_type_archive_link( 'testimonial' ) ); 165 | exit; 166 | } 167 | } 168 | 169 | /** 170 | * Testimonials custom columns 171 | * 172 | * @since 2.0.0 173 | * @param array $columns 174 | */ 175 | function testimonial_columns( $columns ) { 176 | 177 | $columns = array( 178 | 'cb' => '', 179 | 'thumbnail' => 'Thumbnail', 180 | 'title' => 'Name', 181 | 'date' => 'Date', 182 | ); 183 | 184 | return $columns; 185 | } 186 | 187 | /** 188 | * Cases for the custom columns 189 | * 190 | * @since 1.2.0 191 | * @param array $column 192 | * @param int $post_id 193 | * @global array $post 194 | */ 195 | function custom_columns( $column, $post_id ) { 196 | 197 | global $post; 198 | 199 | switch ( $column ) { 200 | case 'thumbnail': 201 | the_post_thumbnail( 'thumbnail' ); 202 | break; 203 | } 204 | } 205 | 206 | } 207 | new BE_Testimonials(); --------------------------------------------------------------------------------