2018-05-29 22:04:18 +02:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
Plugin Name: Alx Extensions
|
|
|
|
Plugin URI: http://wordpress.org/plugins/alx-extensions/
|
2025-04-04 19:39:18 +02:00
|
|
|
Description: Extends Alx themes with social share links, custom sidebars and post format meta boxes. Also includes the flexible widgets AlxTabs and AlxPosts.
|
2025-04-04 19:22:43 +02:00
|
|
|
Version: 1.1.5
|
2018-05-29 22:04:18 +02:00
|
|
|
Author: Alexander Agnarson
|
2020-03-21 19:40:45 +01:00
|
|
|
Author URI: http://alx.media
|
2019-01-15 13:46:15 +01:00
|
|
|
Text Domain: alx
|
2018-05-29 22:04:18 +02:00
|
|
|
Domain Path: /languages
|
2018-09-05 17:24:19 +02:00
|
|
|
License: GPLv3
|
|
|
|
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
2018-05-29 22:04:18 +02:00
|
|
|
*/
|
|
|
|
|
2018-09-04 15:52:24 +05:45
|
|
|
define( 'ALX_EXTENSIONS_SLUG', 'alx-extensions' );
|
|
|
|
define( 'ALX_EXTENSIONS_BASENAME', basename( dirname( __FILE__ ) ) );
|
|
|
|
define( 'ALX_EXTENSIONS_DIR', rtrim( plugin_dir_path( __FILE__ ), '/' ) );
|
|
|
|
define( 'ALX_EXTENSIONS_URL', rtrim( plugin_dir_url( __FILE__ ), '/' ) );
|
|
|
|
|
2018-09-04 16:48:24 +05:45
|
|
|
require_once ALX_EXTENSIONS_DIR . '/inc/options.php';
|
2018-09-04 15:52:24 +05:45
|
|
|
require_once ALX_EXTENSIONS_DIR . '/inc/share.php';
|
2019-01-14 22:09:17 +01:00
|
|
|
require_once ALX_EXTENSIONS_DIR . '/inc/share-footer.php';
|
2018-09-04 16:05:28 +05:45
|
|
|
require_once ALX_EXTENSIONS_DIR . '/inc/post-formats.php';
|
2018-09-04 15:52:24 +05:45
|
|
|
|
2019-01-15 13:46:15 +01:00
|
|
|
|
|
|
|
/* Load plugin textdomain
|
|
|
|
/* ------------------------------------ */
|
2018-05-29 22:04:18 +02:00
|
|
|
function alx_ext_load_textdomain() {
|
2019-01-15 13:46:15 +01:00
|
|
|
load_plugin_textdomain( 'alx', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
|
2018-05-29 22:04:18 +02:00
|
|
|
}
|
2018-09-04 15:52:24 +05:45
|
|
|
|
2018-05-29 22:04:18 +02:00
|
|
|
add_action( 'init', 'alx_ext_load_textdomain' );
|
|
|
|
|
2019-01-15 13:46:15 +01:00
|
|
|
|
|
|
|
/* Enqueue scripts
|
|
|
|
/* ------------------------------------ */
|
2018-05-29 22:04:18 +02:00
|
|
|
function alx_ext_enqueue_scripts() {
|
2018-09-04 15:52:24 +05:45
|
|
|
if ( is_singular() ) {
|
2023-08-07 14:57:41 +02:00
|
|
|
// wp_enqueue_script( 'alx-ext-sharrre', ALX_EXTENSIONS_URL . '/js/jquery.sharrre.min.js', array( 'jquery' ), '1.0.1' );
|
2018-09-04 15:52:24 +05:45
|
|
|
}
|
2018-05-29 22:04:18 +02:00
|
|
|
}
|
2018-09-04 15:52:24 +05:45
|
|
|
|
2018-05-29 22:04:18 +02:00
|
|
|
add_action( 'wp_enqueue_scripts', 'alx_ext_enqueue_scripts' );
|
|
|
|
|
2019-01-15 13:46:15 +01:00
|
|
|
|
|
|
|
/* Enqueue admin scripts
|
|
|
|
/* ------------------------------------ */
|
2018-09-04 16:10:36 +05:45
|
|
|
function alx_ext_enqueue_admin_scripts( $hook ) {
|
|
|
|
if ( in_array( $hook, array( 'post.php', 'post-new.php' ) ) ) {
|
|
|
|
wp_enqueue_script( 'alx-ext-post-formats', ALX_EXTENSIONS_URL . '/js/post-formats.js', array( 'jquery' ), '1.0.1' );
|
|
|
|
}
|
2018-09-04 16:05:28 +05:45
|
|
|
}
|
|
|
|
|
|
|
|
add_action( 'admin_enqueue_scripts', 'alx_ext_enqueue_admin_scripts' );
|
|
|
|
|
2019-01-15 13:46:15 +01:00
|
|
|
|
|
|
|
/* Enqueue admin widgets css
|
|
|
|
/* ------------------------------------ */
|
|
|
|
function alx_ext_admin_widgets_css( $hook ) {
|
|
|
|
if ( 'widgets.php' != $hook ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wp_enqueue_style( 'alx-ext-admin-widgets', ALX_EXTENSIONS_URL . '/inc/widgets/widgets.css' );
|
|
|
|
}
|
|
|
|
|
|
|
|
add_action( 'admin_enqueue_scripts', 'alx_ext_admin_widgets_css' );
|
|
|
|
|
|
|
|
|
|
|
|
/* Upscale cropped thumbnails
|
|
|
|
/* ------------------------------------ */
|
2018-09-04 15:27:39 +05:45
|
|
|
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
|
|
|
|
|
|
|
|
$aspect_ratio = $orig_w / $orig_h;
|
|
|
|
$size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
|
|
|
|
|
|
|
|
$crop_w = round($new_w / $size_ratio);
|
|
|
|
$crop_h = round($new_h / $size_ratio);
|
|
|
|
|
|
|
|
$s_x = floor( ($orig_w - $crop_w) / 2 );
|
|
|
|
$s_y = floor( ($orig_h - $crop_h) / 2 );
|
|
|
|
|
|
|
|
return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
|
|
|
|
}
|
|
|
|
|
2018-09-06 15:08:53 +02:00
|
|
|
$enable_image_upscale = get_theme_mod( 'enable-image-upscale', true );
|
2018-09-04 16:54:59 +05:45
|
|
|
if ( true === $enable_image_upscale ) {
|
|
|
|
add_filter( 'image_resize_dimensions', 'alx_ext_thumbnail_upscale', 10, 6 );
|
|
|
|
}
|
|
|
|
|
2018-09-05 17:44:02 +05:45
|
|
|
|
2019-01-15 13:46:15 +01:00
|
|
|
/* Register custom sidebars
|
|
|
|
/* ------------------------------------ */
|
2018-09-05 17:44:02 +05:45
|
|
|
function alx_ext_register_custom_sidebars() {
|
|
|
|
if ( !get_theme_mod('sidebar-areas') =='' ) {
|
|
|
|
|
|
|
|
$sidebars = get_theme_mod('sidebar-areas', array());
|
|
|
|
|
|
|
|
if ( !empty( $sidebars ) ) {
|
|
|
|
foreach( $sidebars as $sidebar ) {
|
|
|
|
if ( isset($sidebar['title']) && !empty($sidebar['title']) && isset($sidebar['id']) && !empty($sidebar['id']) && ($sidebar['id'] !='sidebar-') ) {
|
|
|
|
register_sidebar(array('name' => ''.esc_attr( $sidebar['title'] ).'','id' => ''.esc_attr( strtolower($sidebar['id']) ).'','before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget' => '</div>','before_title' => '<h3 class="group"><span>','after_title' => '</span></h3>'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
add_action( 'widgets_init', 'alx_ext_register_custom_sidebars', 11 );
|
2019-01-15 13:46:15 +01:00
|
|
|
|
2019-01-16 13:58:23 +01:00
|
|
|
|
|
|
|
/* Custom widgets
|
|
|
|
/* ------------------------------------ */
|
|
|
|
if ( get_theme_mod( 'widget-alx-posts', 'on' ) == 'on') {
|
|
|
|
require_once ALX_EXTENSIONS_DIR . '/inc/widgets/alx-posts.php';
|
|
|
|
}
|
|
|
|
if ( get_theme_mod( 'widget-alx-tabs', 'on' ) == 'on') {
|
|
|
|
require_once ALX_EXTENSIONS_DIR . '/inc/widgets/alx-tabs.php';
|
|
|
|
}
|