Skip to content

Commit

Permalink
GF requirement check + notification if not found
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothy Wood committed Apr 30, 2014
1 parent dac8152 commit 4be9631
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 22 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Thanks to the following users for making the plugin better!
* @mathijsbok

### Changelog:
#### = 1.5 =

* added Gravity Forms requirement check and notification if not found

#### = 1.4 =

* fixed Gravity Forms from being greedy to remove the js script for plugin no conflict mode (thanks to @saxonycreative)
Expand Down
61 changes: 40 additions & 21 deletions gf-notification-attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Plugin Name: Gravity Forms: Notification Attachments
Plugin URI: http://codearachnid.github.io/gf-notification-attachment/
Description: An addon for Gravity Forms to add attachments to notification emails
Version: 1.4
Version: 1.5
Author: Timothy Wood (@codearachnid)
Author URI: http://codearachnid.com
Text Domain: gf_notification_attachment
Expand All @@ -14,26 +14,39 @@
global $gf_notification_attachment;

add_action( 'init', 'gf_notification_attachment_init' );
add_filter('gform_noconflict_scripts', 'gf_notification_attachment_gform_noconflict' );
add_filter( 'gform_notification', 'gf_notification_attachment_send', 20, 3 );
add_filter( 'gform_pre_notification_save', 'gf_notification_attachment_save', 20, 2 );
add_filter( 'gform_notification_ui_settings', 'gf_notification_attachment_editor', 20, 3 );
add_action( 'admin_enqueue_scripts', 'gf_notification_attachment_attach_script');
add_action( 'wp_ajax_gf_notification_attachment', 'gf_notification_attachment_ajax' );


/**
* [gf_notification_attachment_init description]
* @return object
*/
function gf_notification_attachment_init(){
global $gf_notification_attachment;
$gf_notification_attachment = (object) array(
'text_domain' => 'gf-notification-attachment',
'version' => '1.0',
'plugin_url' => trailingslashit( plugin_dir_url( __FILE__ ) )
);
return $gf_notification_attachment;

if( class_exists('GFForms') ) {
add_filter( 'gform_noconflict_scripts', 'gf_notification_attachment_gform_noconflict' );
add_filter( 'gform_notification', 'gf_notification_attachment_send', 20, 3 );
add_filter( 'gform_pre_notification_save', 'gf_notification_attachment_save', 20, 2 );
add_filter( 'gform_notification_ui_settings', 'gf_notification_attachment_editor', 20, 3 );
add_action( 'admin_enqueue_scripts', 'gf_notification_attachment_attach_script');
add_action( 'wp_ajax_gf_notification_attachment', 'gf_notification_attachment_ajax' );

$gf_notification_attachment = (object) array(
'text_domain' => 'gf-notification-attachment',
'version' => '1.0',
'plugin_url' => trailingslashit( plugin_dir_url( __FILE__ ) )
);
return $gf_notification_attachment;
} else {
add_action( 'admin_notices', 'gf_notification_attachment_admin_notices' );
}
}

function gf_notification_attachment_admin_notices(){
?>
<div class="error">
<p><?php _e( 'You must have Gravity Forms activated in order to use Notification Attachments.', 'gf_notification_attachment' ); ?></p>
</div>
<?php
}

function gf_notification_attachment_ajax(){
Expand Down Expand Up @@ -77,7 +90,10 @@ function gf_notification_attachment_send( $notification, $form, $lead ){
* @return array
*/
function gf_notification_attachment_save( $notification, $form ){
$notification["attachment_id"] = rgpost("gform_notification_attachment_id");

if( function_exists( 'rgpost' ) )
$notification["attachment_id"] = rgpost("gform_notification_attachment_id");

return $notification;
}

Expand Down Expand Up @@ -157,11 +173,14 @@ function gf_notification_attachment_get_meta( $attachment_id ) {
function gf_notification_attachment_attach_script(){
global $gf_notification_attachment;
$plugin = $gf_notification_attachment;
if( GFForms::get_page() == 'notification_edit'){
$script = $plugin->plugin_url . 'script';
$script .= ( WP_DEBUG ) ? '.js' : '.min.js';
wp_enqueue_script( $plugin->text_domain, $script, array('gform_gravityforms'), $plugin->version, true );
wp_enqueue_style( $plugin->text_domain, $plugin->plugin_url . 'style.css', array(), $plugin->version );

if( class_exists( 'GFForms' ) ) {
if( GFForms::get_page() == 'notification_edit'){
$script = $plugin->plugin_url . 'script';
$script .= ( WP_DEBUG ) ? '.js' : '.min.js';
wp_enqueue_script( $plugin->text_domain, $script, array( 'gform_gravityforms' ), $plugin->version, true );
wp_enqueue_style( $plugin->text_domain, $plugin->plugin_url . 'style.css', array(), $plugin->version );
}
}
}

Expand All @@ -171,7 +190,7 @@ function gf_notification_attachment_attach_script(){
*
* @return array
*/
function gf_notification_attachment_gform_noconflict($allowed_script_keys){
function gf_notification_attachment_gform_noconflict( $allowed_script_keys ){
global $gf_notification_attachment;
$plugin = $gf_notification_attachment;
$allowed_script_keys[] = $plugin->text_domain;
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: gravityforms, forms, attachment, email, notification
Donate link: http://example.com/
Requires at least: 3.7
Tested up to: 3.9
Stable tag: 1.4
Stable tag: 1.5
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -41,6 +41,9 @@ When WP_DEBUG is active the script will use the unminified version of the script
1. The plugin adds logic to the notification edit screen.

== Changelog ==
= 1.5 =
* added Gravity Forms requirement check and notification if not found

= 1.4 =
* fixed Gravity Forms from being greedy to remove the js script for plugin in no conflict mode (thanks to @saxonycreative)
* tested compatible to WordPress v3.9
Expand Down

0 comments on commit 4be9631

Please sign in to comment.