Skip to content

Commit

Permalink
Merge pull request #32 from gravityview/develop
Browse files Browse the repository at this point in the history
Version 1.2
  • Loading branch information
zackkatz authored May 9, 2018
2 parents 6bf6172 + d55e4c8 commit 1c6dad5
Show file tree
Hide file tree
Showing 5 changed files with 251 additions and 256 deletions.
100 changes: 100 additions & 0 deletions gravityview-az-filters-extension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php
namespace GV;

/** If this file is called directly, abort. */
if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
die();
}

/**
* A-Z Entry Filter Widget Extension
*
* @extends \GV\Extension
*/
class A_Z_Entry_Filter_Extension extends Extension {

protected $_min_gravityview_version = '2.0-dev';

public function __construct() {

$this->_title = 'A-Z Filters';
$this->_version = GRAVITYVIEW_AZ_FILTER_VERSION;
$this->_text_domain = 'gravityview-az-filters';
$this->_path = __FILE__ ;
$this->_item_id = 266;
$this->plugin_file = __FILE__;
$this->plugin_version = GRAVITYVIEW_AZ_FILTER_VERSION;

parent::__construct();
}

public function add_hooks() {

// Load widget
add_action( 'init', array( $this, 'register_az_entry_filter_widget' ) );

// Print Styles
add_action( 'wp_enqueue_scripts', array( $this, 'print_styles' ) );

// Admin styles
add_action( 'admin_enqueue_scripts', array( $this, 'print_scripts'));

add_filter( 'gravityview_noconflict_scripts', array( $this, 'register_noconflict') );

define( 'GRAVITYVIEW_AZ_FILTER_PATH', plugin_dir_path( __FILE__ ) );

define( 'GRAVITYVIEW_AZ_FILTER_URL', untrailingslashit( plugins_url( '/', __FILE__ ) ) );
}

/**
* Load the widget files
* @return void
*/
public function register_az_entry_filter_widget() {
// Load widget extension
include_once( GRAVITYVIEW_AZ_FILTER_PATH . 'widget/gravityview-a-z-entry-filter-widget.php' );
}

/**
* Enable the script in no-conflict mode
*
* @param array $scripts_or_styles array of scripts to be loaded
* @return array Modified array
*/
public function register_noconflict( $scripts_or_styles ) {
$scripts_or_styles []= 'gravityview-az-filters';
return $scripts_or_styles;
}

/**
* Output the script that dynamically loads the fields for the widget settings
* @param string $hook $pagenow page name
* @return void
*/
public function print_scripts( $hook ) {
if ( ! gravityview()->request->is_admin( $hook, 'single' ) ) {
return;
}

$script_debug = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';

wp_enqueue_script( 'gravityview-az-filters', GRAVITYVIEW_AZ_FILTER_URL . '/assets/js/az-search-widget-admin'.$script_debug.'.js', array( 'jquery' ) );

wp_localize_script( 'gravityview-az-filters', 'gvAZVar', array(
'nonce' => wp_create_nonce( 'gravityview_ajaxviews')
) );
}

/**
* Print CSS on front-end when widget is loaded
* @return void
*/
function print_styles() {

// Need to filter the CSS to load only when required.
wp_enqueue_style( 'gravityview_az_entry_filter', GRAVITYVIEW_AZ_FILTER_URL . '/assets/css/gravityview-az-filters.css' );
}

} // A_Z_Entry_Filter_Extension

new A_Z_Entry_Filter_Extension;
138 changes: 20 additions & 118 deletions gravityview-az-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: GravityView - A-Z Filters Extension
* Plugin URI: https://gravityview.co/extensions/a-z-filter/
* Description: Filter your entries by letters of the alphabet.
* Version: 1.1.1.1
* Version: 1.2
* Author: GravityView
* Author URI: https://gravityview.co
* Author Email: [email protected]
Expand All @@ -15,130 +15,32 @@

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

/** @since 1.2 */
define( 'GRAVITYVIEW_AZ_FILTER_VERSION', '1.2' );

add_action( 'plugins_loaded', 'gv_extension_az_entry_filtering_load' );

/**
* Wrapper function to make sure GravityView_Extension has loaded
* A simple loader that works with old PHP versions.
*
* @return void
*/
function gv_extension_az_entry_filtering_load() {

if( !class_exists( 'GravityView_Extension' ) ) {

if( class_exists('GravityView_Plugin') && is_callable(array('GravityView_Plugin', 'include_extension_framework')) ) {
GravityView_Plugin::include_extension_framework();
} else {
// We prefer to use the one bundled with GravityView, but if it doesn't exist, go here.
include_once plugin_dir_path( __FILE__ ) . 'lib/class-gravityview-extension.php';
}
if ( ! class_exists( '\GV\Extension' ) ) {
add_action( 'admin_notices', 'gv_extension_az_entry_filtering_noload' );
return;
}

/**
* A-Z Entry Filter Widget Extension
*
* @extends GravityView_Extension
*/
class GravityView_A_Z_Entry_Filter_Extension extends GravityView_Extension {

protected $_title = 'A-Z Filters';

protected $_version = '1.1.1.1';

protected $_item_id = 266;

protected $_text_domain = 'gravityview-az-filters';

protected $_min_gravityview_version = '1.1.7';

protected $_max_gravityview_version = '1.9999';

protected $_path = __FILE__;

public function add_hooks() {

// Load widget
add_action( 'init', array( $this, 'register_az_entry_filter_widget' ) );

// Print Styles
add_action( 'wp_enqueue_scripts', array( $this, 'print_styles' ) );

// Admin styles
add_action( 'admin_enqueue_scripts', array( $this, 'print_scripts'));

add_filter( 'gravityview_noconflict_scripts', array( $this, 'register_noconflict') );

define( 'GRAVITYVIEW_AZ_FILTER_PATH', plugin_dir_path( __FILE__ ) );

define( 'GRAVITYVIEW_AZ_FILTER_URL', untrailingslashit( plugins_url( '/', __FILE__ ) ) );
}

/**
* Load the widget files
* @return void
*/
public function register_az_entry_filter_widget() {

// 1.7.5.1+
if( is_callable( array( 'GravityView_Plugin', 'include_widget_class' ) ) ) {
GravityView_Plugin::include_widget_class();
}
// 1.7.5
else if( file_exists( GRAVITYVIEW_DIR . 'includes/widgets/register-gravityview-widgets.php' ) ) {
include_once( GRAVITYVIEW_DIR . 'includes/widgets/register-gravityview-widgets.php' );
}
// Before 1.7.5
else {
include_once( GRAVITYVIEW_DIR . 'includes/default-widgets.php' );
}

// Load widget extension
include_once( GRAVITYVIEW_AZ_FILTER_PATH . 'widget/gravityview-a-z-entry-filter-widget.php' );
}

/**
* Enable the script in no-conflict mode
*
* @param array $scripts_or_styles array of scripts to be loaded
* @return array Modified array
*/
function register_noconflict( $scripts_or_styles ) {

$scripts_or_styles[] = 'gravityview-az-filters';

return $scripts_or_styles;
}

/**
* Output the script that dynamically loads the fields for the widget settings
* @param string $hook $pagenow page name
* @return void
*/
function print_scripts( $hook ) {

if( !gravityview_is_admin_page($hook, 'single') ) { return; }

$script_debug = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min';

wp_enqueue_script( 'gravityview-az-filters', GRAVITYVIEW_AZ_FILTER_URL . '/assets/js/az-search-widget-admin'.$script_debug.'.js', array('jquery') );

wp_localize_script( 'gravityview-az-filters', 'gvAZVar', array(
'nonce' => wp_create_nonce( 'gravityview_ajaxviews')
) );

}

/**
* Print CSS on front-end when widget is loaded
* @return void
*/
function print_styles() {

// Need to filter the CSS to load only when required.
wp_enqueue_style( 'gravityview_az_entry_filter', GRAVITYVIEW_AZ_FILTER_URL . '/assets/css/gravityview-az-filters.css' );
}

} // GravityView_A_Z_Entry_Filter_Extension

new GravityView_A_Z_Entry_Filter_Extension;
if ( ! class_exists( '\GV\A_Z_Entry_Filter_Extension' ) ) {
require plugin_dir_path( __FILE__ ) . 'gravityview-az-filters-extension.php';
}
}

/**
* Outputs a loader warning notice.
*
* @return void
*/
function gv_extension_az_entry_filtering_noload() {
echo esc_html( 'GravityView A-Z Filters Extension was not loaded. GravityView 2.0 core files not found!' );
}
10 changes: 10 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ Alphabetically filter your entries by letters of the alphabet.

## Changelog ##

### 1.2 on May 8, 2018 ###

* Updated to work with GravityView 2.0
* Requires GravityView 2.0
* Requires PHP 5.3 or newer

__Developer Updates:__

* Added `$context` second parameter to the `gravityview_az_entry_args` filter

### 1.1.1.1 on April 28, 2018 ###
* Added: Compatibility notice for GravityView 2.0

Expand Down
10 changes: 10 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ Alphabetically filter your entries by letters of the alphabet.

== Changelog ==

= 1.2 on May 8, 2018 =

* Updated to work with GravityView 2.0
* Requires GravityView 2.0
* Requires PHP 5.3 or newer

__Developer Updates:__

* Added `$context` second parameter to the `gravityview_az_entry_args` filter

= 1.1.1.1 on April 28, 2018 =
* Added: Compatibility notice for GravityView 2.0

Expand Down
Loading

0 comments on commit 1c6dad5

Please sign in to comment.