From c81a91d2e21f8fd741cd2861a8cf4ee983bc5924 Mon Sep 17 00:00:00 2001 From: Aaron Huisinga Date: Fri, 20 May 2016 21:10:44 -0500 Subject: [PATCH] Bump to version 1.3.1 1. Only load admin scripts and styles when creating or editing a Homes Report funnel 2. Update branding in notification emails --- assets/js/admin.js | 4 +- classes/class-homes-report-admin.php | 612 ++++++++++++++------------- classes/class-homes-report.php | 26 -- homes-report.php | 4 +- readme.txt | 2 +- templates/single-email.php | 6 +- 6 files changed, 321 insertions(+), 333 deletions(-) diff --git a/assets/js/admin.js b/assets/js/admin.js index 85ebdd8..9d5976d 100755 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -6,7 +6,7 @@ jQuery(document).ready(function ($) { // Uploading files var file_frame; - jQuery.fn.ssp_upload_media_file = function (button, preview_media) { + jQuery.fn.homes_report_upload_media_file = function (button, preview_media) { var button_id = button.attr('id'); var field_id = button_id.replace('_button', ''); var preview_id = button_id.replace('_button', '_preview'); @@ -41,7 +41,7 @@ jQuery(document).ready(function ($) { jQuery('#upload_media_file_button').click(function (event) { event.preventDefault(); - jQuery.fn.ssp_upload_media_file(jQuery(this), false); + jQuery.fn.homes_report_upload_media_file(jQuery(this), false); }); }); \ No newline at end of file diff --git a/classes/class-homes-report-admin.php b/classes/class-homes-report-admin.php index 5f68ac9..fda0b05 100755 --- a/classes/class-homes-report-admin.php +++ b/classes/class-homes-report-admin.php @@ -1,318 +1,332 @@ dir = dirname( $file ); - $this->file = $file; - $this->assets_dir = trailingslashit( $this->dir ) . 'assets'; - $this->assets_url = esc_url( trailingslashit( plugins_url( '/assets/', $file ) ) ); - $this->home_url = trailingslashit( home_url() ); - $this->token = 'pf_homes_report'; - - // Register homes report settings - add_action( 'admin_init', [ $this, 'register_settings' ] ); - - // Add settings page to menu - add_action( 'admin_menu', [ $this, 'add_menu_item' ] ); - - // Add settings link to plugins page - add_filter( 'plugin_action_links_' . plugin_basename( $this->file ), [ $this, 'add_settings_link' ] ); - - // Load scripts for settings page - add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_scripts' ], 10 ); - - // Display notices in the WP admin - add_action( 'admin_notices', [ $this, 'admin_notices' ], 10 ); - } - - /** - * Add the menu links for the plugin - * - */ - public function add_menu_item() - { - add_submenu_page( 'edit.php?post_type=' . $this->token, 'Leads', 'Leads', 'manage_options', $this->token . '_leads', [ - $this, - 'leads_page' - ] ); - - add_submenu_page( 'edit.php?post_type=' . $this->token, 'Homes Report Settings', 'Settings', 'manage_options', $this->token . '_settings', [ - $this, - 'settings_page' - ] ); - } - - /** - * Add the link to our Settings page - * from the plugins page - * - * @param array $links - * - * @return array - */ - public function add_settings_link( $links ) - { - $settings_link = 'Settings'; - array_push( $links, $settings_link ); - - return $links; - } - - /** - * Register the Javascript files used by - * the plugin in the WordPress dashboard - * - */ - public function enqueue_admin_scripts() - { - global $wp_version; - // Admin JS - wp_register_script( $this->token . '-admin', esc_url( $this->assets_url . 'js/admin.js' ), [ 'jquery' ] ); - wp_enqueue_script( $this->token . '-admin' ); - - if ( $wp_version >= 3.5 ) - wp_enqueue_media(); - } - - /** - * Define different notices that can be - * displayed to the user in the dashboard - * - */ - public function admin_notices() - { - global $wp_version; - - // Version notice - if ( $wp_version < 3.5 ) { - ?> -
-

token ), '', '', $wp_version ); ?>

-
- token ), [ - $this, - 'main_settings' - ], $this->token ); - - // Add settings fields - add_settings_field( $this->token . '_slug', __( 'URL slug for homes report pages:', $this->token ), [ - $this, - 'slug_field' - ], $this->token, 'customize' ); - add_settings_field( $this->token . '_frontdesk_key', __( 'Platform CRM API key:', $this->token ), [ - $this, - 'frontdesk_key_field' - ], $this->token, 'customize' ); - - // Register settings fields - register_setting( $this->token, $this->token . '_slug', [ $this, 'validate_slug' ] ); - register_setting( $this->token, $this->token . '_frontdesk_key' ); - - // Allow plugins to add more settings fields - do_action( $this->token . '_settings_fields' ); - - } - - /** - * Define the main description string - * for the Settings page. - * - */ - public function main_settings() - { - echo '

' . __( 'These are a few simple settings for setting up your homes report pages.', $this->token ) . '

'; - } - - /** - * Create the slug field for the Settings page. - * The slug field allows users to choose which - * subdirectory their homes report pages are nested in. - * - */ - public function slug_field() - { - $option = get_option( $this->token . '_slug' ); - - $data = 'homes-report'; - if ( $option && strlen( $option ) > 0 && $option != '' ) - $data = $option; - - echo ' - '; - } - - /** - * Validates that a slug has been defined, - * and formats it properly as a URL - * - * @param string $slug - * - * @return string - */ - public function validate_slug( $slug ) - { - if ( $slug && strlen( $slug ) > 0 && $slug != '' ) - $slug = urlencode( strtolower( str_replace( ' ', '-', $slug ) ) ); - - return $slug; - } - - /** - * Create the FrontDesk key field for the Settings page. - * The FrontDesk key field allows users to define their - * API key to be used in all FrontDesk requests. - */ - public function frontdesk_key_field() - { - $option = get_option( $this->token . '_frontdesk_key' ); - - $data = get_option( 'pf_frontdesk_key', '' ); - if ( $option && strlen( $option ) > 0 && $option != '' ) - $data = $option; - - echo ' - '; - - } - - /** - * Create the actual HTML structure - * for the Settings page for the plugin - * - */ - public function settings_page() - { - if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] == true ) { - flush_rewrite_rules(); - echo '

Successfully updated.

'; - } - - echo '
-

' . __( 'Homes Report Settings', $this->token ) . '

+if (!defined('ABSPATH')) exit; // Exit if accessed directly. + +class HomesReport_Admin +{ + private $dir; + private $file; + private $assets_dir; + private $assets_url; + private $home_url; + private $token; + + /** + * Basic constructor for the Homes Report Admin class + * + * @param string $file + */ + public function __construct($file) + { + $this->dir = dirname($file); + $this->file = $file; + $this->assets_dir = trailingslashit($this->dir) . 'assets'; + $this->assets_url = esc_url(trailingslashit(plugins_url('/assets/', $file))); + $this->home_url = trailingslashit(home_url()); + $this->token = 'pf_homes_report'; + + // Register homes report settings + add_action('admin_init', [$this, 'register_settings']); + + // Add settings page to menu + add_action('admin_menu', [$this, 'add_menu_item']); + + // Add settings link to plugins page + add_filter('plugin_action_links_' . plugin_basename($this->file), [$this, 'add_settings_link']); + + add_action('admin_print_scripts-post-new.php', [$this, 'enqueue_admin_styles'], 10); + add_action('admin_print_scripts-post.php', [$this, 'enqueue_admin_styles'], 10); + add_action('admin_print_scripts-post-new.php', [$this, 'enqueue_admin_scripts'], 10); + add_action('admin_print_scripts-post.php', [$this, 'enqueue_admin_scripts'], 10); + + // Display notices in the WP admin + add_action('admin_notices', [$this, 'admin_notices'], 10); + } + + /** + * Add the menu links for the plugin + * + */ + public function add_menu_item() + { + add_submenu_page('edit.php?post_type=' . $this->token, 'Leads', 'Leads', 'manage_options', $this->token . '_leads', [ + $this, + 'leads_page' + ]); + + add_submenu_page('edit.php?post_type=' . $this->token, 'Homes Report Settings', 'Settings', 'manage_options', $this->token . '_settings', [ + $this, + 'settings_page' + ]); + } + + /** + * Add the link to our Settings page + * from the plugins page + * + * @param array $links + * + * @return array + */ + public function add_settings_link($links) + { + $settings_link = 'Settings'; + array_push($links, $settings_link); + + return $links; + } + + /** + * Register the stylesheets that will be + * used for our scripts in the dashboard. + * + */ + public function enqueue_admin_styles() + { + global $post_type; + if ($post_type == $this->token) { + wp_enqueue_style('wp-color-picker'); + } + } + + /** + * Register the Javascript files used by + * the plugin in the WordPress dashboard + * + */ + public function enqueue_admin_scripts() + { + global $post_type; + if ($post_type == $this->token) { + wp_register_script($this->token . '-admin', esc_url($this->assets_url . 'js/admin.js'), ['jquery', 'wp-color-picker']); + wp_enqueue_script($this->token . '-admin'); + } + } + + /** + * Define different notices that can be + * displayed to the user in the dashboard + * + */ + public function admin_notices() + { + global $wp_version; + + // Version notice + if ($wp_version < 3.5) { + ?> +
+

token), '', '', $wp_version); ?>

+
+ token), [ + $this, + 'main_settings' + ], $this->token); + + // Add settings fields + add_settings_field($this->token . '_slug', __('URL slug for homes report pages:', $this->token), [ + $this, + 'slug_field' + ], $this->token, 'customize'); + add_settings_field($this->token . '_frontdesk_key', __('Platform CRM API key:', $this->token), [ + $this, + 'frontdesk_key_field' + ], $this->token, 'customize'); + + // Register settings fields + register_setting($this->token, $this->token . '_slug', [$this, 'validate_slug']); + register_setting($this->token, $this->token . '_frontdesk_key'); + + // Allow plugins to add more settings fields + do_action($this->token . '_settings_fields'); + + } + + /** + * Define the main description string + * for the Settings page. + * + */ + public function main_settings() + { + echo '

' . __('These are a few simple settings for setting up your homes report pages.', $this->token) . '

'; + } + + /** + * Create the slug field for the Settings page. + * The slug field allows users to choose which + * subdirectory their homes report pages are nested in. + * + */ + public function slug_field() + { + $option = get_option($this->token . '_slug'); + + $data = 'homes-report'; + if ($option && strlen($option) > 0 && $option != '') + $data = $option; + + echo ' + '; + } + + /** + * Validates that a slug has been defined, + * and formats it properly as a URL + * + * @param string $slug + * + * @return string + */ + public function validate_slug($slug) + { + if ($slug && strlen($slug) > 0 && $slug != '') + $slug = urlencode(strtolower(str_replace(' ', '-', $slug))); + + return $slug; + } + + /** + * Create the FrontDesk key field for the Settings page. + * The FrontDesk key field allows users to define their + * API key to be used in all FrontDesk requests. + */ + public function frontdesk_key_field() + { + $option = get_option($this->token . '_frontdesk_key'); + + $data = get_option('pf_frontdesk_key', ''); + if ($option && strlen($option) > 0 && $option != '') + $data = $option; + + echo ' + '; + + } + + /** + * Create the actual HTML structure + * for the Settings page for the plugin + * + */ + public function settings_page() + { + if (isset($_GET['settings-updated']) && $_GET['settings-updated'] == true) { + flush_rewrite_rules(); + echo '

Successfully updated.

'; + } + + echo '
+

' . __('Homes Report Settings', $this->token) . '

'; - settings_fields( $this->token ); - do_settings_sections( $this->token ); + settings_fields($this->token); + do_settings_sections($this->token); - echo '

- + echo '

+

'; - } - - /** - * Create the actual HTML structure - * for the Leads page for the plugin - * - */ - public function leads_page() - { - global $wpdb; - $blog_id = get_current_blog_id(); - $table_name = $wpdb->base_prefix . $this->token; - $leads = $wpdb->get_results( "SELECT DISTINCT * FROM `$table_name` WHERE `blog_id` = '$blog_id' ORDER BY `id` DESC" ); - - ?> -
-

Homes Report Leads

- - + } + + /** + * Create the actual HTML structure + * for the Leads page for the plugin + * + */ + public function leads_page() + { + global $wpdb; + $blog_id = get_current_blog_id(); + $table_name = $wpdb->base_prefix . $this->token; + $leads = $wpdb->get_results("SELECT DISTINCT * FROM `$table_name` WHERE `blog_id` = '$blog_id' ORDER BY `id` DESC"); + + ?> +
+

Homes Report Leads

+ +

The requested leads have been deleted!

'; - ?> - - - -
- - token . '_remove_leads' ); ?> - - - - - - - - - - - - - + ?> + + + + + + token . '_remove_leads'); ?> +
NameEmailLocationPrice RangeSubmitted
+ + + + + + + + + + + + - + '; - } - ?> - - - - - - - - - - - -
NameEmailLocationPrice RangeSubmitted
' . $lead->first_name . ' ' . $lead->email . ' ' . $lead->location . ' ' . $lead->price_range . '' . date( "M j Y, h:i:a", strtotime( $lead->created_at ) ) . '' . date("M j Y, h:i:a", strtotime($lead->created_at)) . '
NameEmailLocationPrice RangeSubmitted
- -
-
- + + + + + Name + Email + Location + Price Range + Submitted + + + + + +
+ token . '_columns', [ $this, 'register_custom_column_headings' @@ -375,30 +373,6 @@ public function meta_box_save($post_id) } } - /** - * Register the stylesheets that will be - * used for our scripts in the dashboard. - * - */ - public function enqueue_admin_styles() - { - wp_enqueue_style('wp-color-picker'); - } - - /** - * Register the Javascript files that will be - * used for our scripts in the dashboard. - */ - public function enqueue_admin_scripts() - { - // Admin JS - wp_register_script($this->token . '-admin', esc_url($this->assets_url . 'js/admin.js'), [ - 'jquery', - 'wp-color-picker' - ]); - wp_enqueue_script($this->token . '-admin'); - } - /** * Register the Javascript files that will be * used for our templates. diff --git a/homes-report.php b/homes-report.php index 78a6a33..6d64a01 100755 --- a/homes-report.php +++ b/homes-report.php @@ -1,7 +1,7 @@ - Platform Logo + Platform Logo