Permalink
Browse files

Merge branch '4.0'

  • Loading branch information...
2 parents d3a3521 + 272a96f commit b55b640682ec9c97ccee576360c12df0fa2a6e6b @justintadlock committed Jul 31, 2017
Showing with 3,507 additions and 2,572 deletions.
  1. +0 −170 admin/admin.php
  2. +177 −0 admin/class-post-layout.php
  3. +209 −0 admin/class-term-layout.php
  4. +161 −0 admin/functions-admin.php
  5. +0 −146 admin/meta-box-post-layout.php
  6. +0 −99 admin/meta-box-post-style.php
  7. +0 −110 admin/meta-box-post-template.php
  8. +70 −1 changelog.md
  9. +2 −2 composer.json
  10. +13 −5 css/admin.css
  11. +1 −1 css/admin.min.css
  12. +0 −2 css/one-five.css
  13. +1 −1 css/one-five.min.css
  14. +12 −3 customize/control-checkbox-multiple.php
  15. +3 −3 customize/control-dropdown-terms.php
  16. +4 −4 customize/control-layout.php
  17. +12 −3 customize/control-palette.php
  18. +13 −4 customize/control-radio-image.php
  19. +12 −3 customize/control-select-group.php
  20. +12 −3 customize/control-select-multiple.php
  21. +3 −3 customize/setting-array-map.php
  22. +3 −3 customize/setting-image-data.php
  23. +40 −17 ext/breadcrumb-trail.php
  24. +147 −64 ext/get-the-image.php
  25. +206 −97 hybrid.php
  26. +4 −3 inc/class-chat.php
  27. +0 −118 inc/class-layout-factory.php
  28. +80 −49 inc/class-layout.php
  29. +73 −42 inc/class-media-grabber.php
  30. +0 −83 inc/class-media-meta-factory.php
  31. +3 −3 inc/class-media-meta.php
  32. +151 −0 inc/class-registry.php
  33. +318 −0 inc/class-template-hierarchy.php
  34. +167 −0 inc/class-template.php
  35. +33 −540 inc/functions-attr.php
  36. +21 −6 inc/functions-context.php
  37. +21 −16 inc/functions-customize.php
  38. +68 −90 inc/functions-deprecated.php
  39. +198 −18 inc/functions-filters.php
  40. +181 −0 inc/functions-fonts.php
  41. +6 −3 inc/functions-formats.php
  42. +34 −45 inc/functions-head.php
  43. +17 −20 inc/functions-i18n.php
  44. +103 −22 inc/functions-layouts.php
  45. +62 −15 inc/functions-meta.php
  46. +5 −9 inc/functions-scripts.php
  47. +17 −3 inc/functions-sidebars.php
  48. +13 −97 inc/functions-styles.php
  49. +370 −0 inc/functions-templates.php
  50. +84 −141 inc/functions-utility.php
  51. +97 −16 inc/template-comments.php
  52. +32 −6 inc/template-general.php
  53. +0 −267 inc/template-hierarchy.php
  54. +84 −12 inc/template-media.php
  55. +7 −78 inc/template-post.php
  56. +152 −92 inc/template.php
  57. +0 −27 js/mobile-toggle.js
  58. +0 −1 js/mobile-toggle.min.js
  59. +5 −6 readme.md
View
@@ -1,170 +0,0 @@
-<?php
-/**
- * Theme administration functions used with other components of the framework admin. This file is for
- * setting up any basic features and holding additional admin helper functions.
- *
- * @package HybridCore
- * @subpackage Admin
- * @author Justin Tadlock <justin@justintadlock.com>
- * @copyright Copyright (c) 2008 - 2015, Justin Tadlock
- * @link http://themehybrid.com/hybrid-core
- * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
- */
-
-# Load the post meta boxes on the new post and edit post screens.
-add_action( 'load-post.php', 'hybrid_admin_load_post_meta_boxes' );
-add_action( 'load-post-new.php', 'hybrid_admin_load_post_meta_boxes' );
-
-# Register scripts and styles.
-add_action( 'admin_enqueue_scripts', 'hybrid_admin_register_styles', 0 );
-
-# Allow posts page to be edited.
-add_action( 'edit_form_after_title', 'hybrid_enable_posts_page_editor', 0 );
-
-/**
- * Loads the core post meta box files on the 'load-post.php' action hook. Each meta box file is only loaded if
- * the theme declares support for the feature.
- *
- * @since 1.2.0
- * @access public
- * @return void
- */
-function hybrid_admin_load_post_meta_boxes() {
-
- // Load the post template meta box.
- require_if_theme_supports( 'hybrid-core-template-hierarchy', HYBRID_ADMIN . 'meta-box-post-template.php' );
-
- // Load the layout meta box.
- require_if_theme_supports( 'theme-layouts', HYBRID_ADMIN . 'meta-box-post-layout.php' );
-
- // Load the post style meta box.
- require_once( HYBRID_ADMIN . 'meta-box-post-style.php' );
-}
-
-/**
- * Registers admin styles.
- *
- * @since 3.0.0
- * @access public
- * @return void
- */
-function hybrid_admin_register_styles() {
- wp_register_style( 'hybrid-admin', HYBRID_CSS . 'admin.css' );
-}
-
-/**
- * Fix for users who want to display content on the posts page above the posts list, which is a
- * theme feature common to themes built from the framework.
- *
- * @since 3.0.0
- * @access public
- * @param object $post
- * @return void
- */
-function hybrid_enable_posts_page_editor( $post ) {
-
- if ( get_option( 'page_for_posts' ) != $post->ID )
- return;
-
- remove_action( 'edit_form_after_title', '_wp_posts_page_notice' );
- add_post_type_support( $post->post_type, 'editor' );
-}
-
-/**
- * Function for getting an array of available custom templates with a specific header. Ideally, this function
- * would be used to grab custom singular post (any post type) templates. It is a recreation of the WordPress
- * page templates function because it doesn't allow for other types of templates.
- *
- * @since 0.7.0
- * @access public
- * @global object $hybrid
- * @param string $post_type The name of the post type to get templates for.
- * @return array $post_templates The array of templates.
- */
-function hybrid_get_post_templates( $post_type = 'post' ) {
- global $hybrid;
-
- // If templates have already been called, just return them.
- if ( ! empty( $hybrid->post_templates ) && isset( $hybrid->post_templates[ $post_type ] ) )
- return $hybrid->post_templates[ $post_type ];
-
- // Set up an empty array to house the templates.
- $post_templates = array();
-
- // Get the theme PHP files one level deep.
- $files = wp_get_theme( get_template() )->get_files( 'php', 1 );
-
- // If a child theme is active, get its files and merge with the parent theme files.
- if ( is_child_theme() )
- $files = array_merge( $files, wp_get_theme()->get_files( 'php', 1 ) );
-
- // Loop through each of the PHP files and check if they are post templates.
- foreach ( $files as $file => $path ) {
-
- // Get file data based on the post type singular name (e.g., "Post Template", "Book Template", etc.).
- $headers = get_file_data( $path, array( "{$post_type} Template" => "{$post_type} Template" ) );
-
- // Add the PHP filename and template name to the array.
- if ( ! empty( $headers["{$post_type} Template"] ) )
- $post_templates[ $file ] = $headers["{$post_type} Template"];
- }
-
- // Add the templates to the global $hybrid object.
- $hybrid->post_templates[ $post_type ] = array_flip( $post_templates );
-
- // Return array of post templates.
- return $hybrid->post_templates[ $post_type ];
-}
-
-/**
- * Gets the stylesheet files within the parent or child theme and checks if they have the 'Style Name'
- * header. If any files are found, they are returned in an array.
- *
- * @since 3.0.0
- * @access public
- * @global object $hybrid
- * @return array
- */
-function hybrid_get_post_styles( $post_type = 'post' ) {
- global $hybrid;
-
- // If stylesheets have already been loaded, return them.
- if ( ! empty( $hybrid->post_styles ) && isset( $hybrid->post_styles[ $post_type ] ) )
- return $hybrid->post_styles[ $post_type ];
-
- // Set up an empty styles array.
- $hybrid->post_styles[ $post_type ] = array();
-
- // Get the theme CSS files two levels deep.
- $files = wp_get_theme( get_template() )->get_files( 'css', 2 );
-
- // If a child theme is active, get its files and merge with the parent theme files.
- if ( is_child_theme() )
- $files = array_merge( $files, wp_get_theme()->get_files( 'css', 2 ) );
-
- // Loop through each of the CSS files and check if they are styles.
- foreach ( $files as $file => $path ) {
-
- // Get file data based on the 'Style Name' header.
- $headers = get_file_data(
- $path,
- array(
- 'Style Name' => 'Style Name',
- "{$post_type} Style" => "{$post_type} Style"
- )
- );
-
- // Add the CSS filename and template name to the array.
- if ( ! empty( $headers['Style Name'] ) )
- $hybrid->post_styles[ $post_type ][ $file ] = $headers['Style Name'];
-
- elseif ( ! empty( $headers["{$post_type} Style"] ) )
- $hybrid->post_styles[ $post_type ][ $file ] = $headers["{$post_type} Style"];
- }
-
- // Flip the array of styles.
- $hybrid->post_styles[ $post_type ] = array_flip( $hybrid->post_styles[ $post_type ] );
-
- // Return array of styles.
- return $hybrid->post_styles[ $post_type ];
-}
View
@@ -0,0 +1,177 @@
+<?php
+/**
+ * Adds a layout selector to the create and edit post admin screen.
+ *
+ * @package HybridCore
+ * @subpackage Admin
+ * @author Justin Tadlock <justintadlock@gmail.com>
+ * @copyright Copyright (c) 2008 - 2017, Justin Tadlock
+ * @link https://themehybrid.com/hybrid-core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ */
+
+/**
+ * Singleton class for handling the post layout feature.
+ *
+ * @since 4.0.0
+ * @access public
+ */
+final class Hybrid_Admin_Post_Layout {
+
+ /**
+ * Returns the instance.
+ *
+ * @since 4.0.0
+ * @access public
+ * @return object
+ */
+ public static function get_instance() {
+
+ static $instance = null;
+
+ if ( is_null( $instance ) ) {
+ $instance = new self;
+ $instance->setup_actions();
+ }
+
+ return $instance;
+ }
+
+ /**
+ * Constructor method.
+ *
+ * @since 4.0.0
+ * @access private
+ * @return void
+ */
+ private function __construct() {}
+
+ /**
+ * Sets up initial actions.
+ *
+ * @since 4.0.0
+ * @access private
+ * @return void
+ */
+ private function setup_actions() {
+
+ if ( ! current_theme_supports( 'theme-layouts', 'post_meta' ) )
+ return;
+
+ // Load on the edit tags screen.
+ add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
+
+ // Update post meta.
+ add_action( 'save_post', array( $this, 'save' ), 10, 2 );
+ add_action( 'add_attachment', array( $this, 'save' ) );
+ add_action( 'edit_attachment', array( $this, 'save' ) );
+ }
+
+ /**
+ * Runs on the load hook and sets up what we need.
+ *
+ * @since 4.0.0
+ * @access public
+ * @param string $post_type
+ * @return void
+ */
+ public function add_meta_boxes( $post_type ) {
+
+ if ( post_type_supports( $post_type, 'theme-layouts' ) && current_user_can( 'edit_theme_options' ) ) {
+
+ // Add meta box.
+ add_meta_box( 'hybrid-post-layout', esc_html__( 'Layout', 'hybrid-core' ), array( $this, 'meta_box' ), $post_type, 'side', 'default' );
+
+ // Enqueue scripts/styles.
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
+ }
+ }
+
+ /**
+ * Enqueues scripts/styles.
+ *
+ * @since 4.0.0
+ * @access public
+ * @return void
+ */
+ public function enqueue() {
+
+ wp_enqueue_style( 'hybrid-admin' );
+
+ add_action( 'admin_footer', 'hybrid_layout_field_inline_script' );
+ }
+
+ /**
+ * Callback function for displaying the layout meta box.
+ *
+ * @since 4.0.0
+ * @access public
+ * @param object $object
+ * @param array $box
+ * @return void
+ */
+ public function meta_box( $post, $box ) {
+
+ // Get only the post layouts.
+ $layouts = wp_list_filter( hybrid_get_layouts(), array( 'is_post_layout' => true, 'image' => true ) );
+
+ // Remove unwanted layouts.
+ foreach ( $layouts as $layout ) {
+
+ if ( $layout->post_types && ! in_array( $post->post_type, $layout->post_types ) )
+ unset( $layouts[ $layout->name ] );
+ }
+
+ // Get the current post's layout.
+ $post_layout = hybrid_get_post_layout( $post->ID );
+
+ // Output the nonce field.
+ wp_nonce_field( basename( __FILE__ ), 'hybrid_post_layout_nonce' );
+
+ // Output the layout field.
+ hybrid_form_field_layout(
+ array(
+ 'layouts' => $layouts,
+ 'selected' => $post_layout ? $post_layout : 'default',
+ 'field_name' => 'hybrid-post-layout'
+ )
+ );
+ }
+
+ /**
+ * Saves the post layout when submitted via the layout meta box.
+ *
+ * @since 4.0.0
+ * @access public
+ * @param int $post_id The ID of the current post being saved.
+ * @param object $post The post object currently being saved.
+ * @return void
+ */
+ public function save( $post_id, $post = '' ) {
+
+ // Fix for attachment save issue in WordPress 3.5. @link http://core.trac.wordpress.org/ticket/21963
+ if ( ! is_object( $post ) )
+ $post = get_post();
+
+ // Verify the nonce for the post formats meta box.
+ if ( ! hybrid_verify_nonce_post( basename( __FILE__ ), 'hybrid_post_layout_nonce' ) )
+ return;
+
+ // Get the previous post layout.
+ $meta_value = hybrid_get_post_layout( $post_id );
+
+ // Get the submitted post layout.
+ $new_meta_value = isset( $_POST['hybrid-post-layout'] ) ? sanitize_key( $_POST['hybrid-post-layout'] ) : '';
+
+ // If there is no new meta value but an old value exists, delete it.
+ if ( '' == $new_meta_value && $meta_value )
+ hybrid_delete_post_layout( $post_id );
+
+ // If a new meta value was added and there was no previous value, add it.
+ elseif ( $meta_value !== $new_meta_value )
+ hybrid_set_post_layout( $post_id, $new_meta_value );
+ }
+}
+
+// Let's roll.
+Hybrid_Admin_Post_Layout::get_instance();
Oops, something went wrong.

0 comments on commit b55b640

Please sign in to comment.