Add scripts for post formats

This commit is contained in:
Nilambar Sharma 2018-09-04 16:05:28 +05:45
parent 9af3b8b089
commit 2d08a61506
3 changed files with 99 additions and 0 deletions

View file

@ -18,6 +18,7 @@ define( 'ALX_EXTENSIONS_DIR', rtrim( plugin_dir_path( __FILE__ ), '/' ) );
define( 'ALX_EXTENSIONS_URL', rtrim( plugin_dir_url( __FILE__ ), '/' ) );
require_once ALX_EXTENSIONS_DIR . '/inc/share.php';
require_once ALX_EXTENSIONS_DIR . '/inc/post-formats.php';
/* load plugin textdomain */
function alx_ext_load_textdomain() {
@ -35,6 +36,13 @@ function alx_ext_enqueue_scripts() {
add_action( 'wp_enqueue_scripts', 'alx_ext_enqueue_scripts' );
/* enqueue admin scripts */
function alx_ext_enqueue_admin_scripts() {
wp_enqueue_script( 'alx-ext-post-formats', ALX_EXTENSIONS_URL . '/js/post-formats.js', array( 'jquery' ), '1.0.0' );
}
add_action( 'admin_enqueue_scripts', 'alx_ext_enqueue_admin_scripts' );
/* Upscale cropped thumbnails */
function alx_ext_thumbnail_upscale( $default, $orig_w, $orig_h, $new_w, $new_h, $crop ) {
if ( !$crop ) return null; // let the wordpress default function handle this

47
inc/post-formats.php Normal file
View file

@ -0,0 +1,47 @@
<?php
function alx_ext_post_formats_meta_box( $meta_boxes ) {
/* do not show */
$prefix = '_';
/* Format: audio
/* ------------------------------------ */
$meta_boxes[] = array(
'id' => 'format-audio',
'title' => esc_html__( 'Format: Audio', 'alx-extensions' ),
'post_types' => array( 'post' ),
'context' => 'advanced',
'priority' => 'high',
'autosave' => false,
'fields' => array(
array(
'id' => $prefix . 'audio_url',
'type' => 'text',
'name' => esc_html__( 'Audio URL', 'alx-extensions' ),
),
),
);
/* Format: video
/* ------------------------------------ */
$meta_boxes[] = array(
'id' => 'format-video',
'title' => esc_html__( 'Format: Video', 'alx-extensions' ),
'post_types' => array( 'post' ),
'context' => 'advanced',
'priority' => 'high',
'autosave' => false,
'fields' => array(
array(
'id' => $prefix . 'video_url',
'type' => 'text',
'name' => esc_html__( 'Video URL', 'alx-extensions' ),
),
),
);
return $meta_boxes;
}
add_filter( 'rwmb_meta_boxes', 'alx_ext_post_formats_meta_box', 11 );

44
js/post-formats.js Normal file
View file

@ -0,0 +1,44 @@
/*
post-formats.js
License: GNU General Public License v3.0
License URI: http://www.gnu.org/licenses/gpl-3.0.html
Copyright: (c) 2013 Jermaine Maree, http://jermainemaree.com
*/
jQuery(document).ready(function($) {
// Hide post format sections
function hide_statuses() {
$('#format-audio,#format-aside,#format-chat,#format-gallery,#format-image,#format-link,#format-quote,#format-status,#format-video').hide();
}
// Post Formats
if($("#post-formats-select").length) {
// Hide post format sections
hide_statuses();
// Supported post formats
var post_formats = ['audio','aside','chat','gallery','image','link','quote','status','video'];
// Get selected post format
var selected_post_format = $("input[name='post_format']:checked").val();
// Show post format meta box
if(jQuery.inArray(selected_post_format,post_formats) != '-1') {
$('#format-'+selected_post_format).show();
}
// Hide/show post format meta box when option changed
$("input[name='post_format']:radio").change(function() {
// Hide post format sections
hide_statuses();
// Shoe selected section
if(jQuery.inArray($(this).val(),post_formats) != '-1') {
$('#format-'+$(this).val()).show();
}
});
}
});