';
diff --git a/includes/functions-updates.php b/includes/functions-updates.php
index e4712db..d093772 100644
--- a/includes/functions-updates.php
+++ b/includes/functions-updates.php
@@ -49,7 +49,10 @@ function wp_sponsors_update_post_type_300() {
foreach ( $descriptions as $description ) {
$text = $description['meta_value'];
$post_id = $description['post_id'];
- $wpdb->update( $wpdb->posts, array( 'post_content' => $text ), array( 'ID' => $post_id ) );
+ $ret = $wpdb->update( $wpdb->posts, array( 'post_content' => $text ), array( 'ID' => $post_id ) );
+ if ( false !== $ret ) {
+ delete_post_meta( $post_id, 'wp_sponsors_desc' );
+ }
}
}
}
\ No newline at end of file
diff --git a/wp-sponsors.php b/wp-sponsors.php
index 4cc59f3..7e4fd03 100755
--- a/wp-sponsors.php
+++ b/wp-sponsors.php
@@ -34,6 +34,17 @@
define( 'WP_SPONSORS_FILE', __FILE__ );
}
+/**
+ * The code that runs during plugin activation.
+ * This action is documented in includes/class-wp-sponsors-activator.php
+ */
+function activate_wp_sponsors() {
+ require_once plugin_dir_path( __FILE__ ) . 'includes/class-wp-sponsors-activator.php';
+ WP_Sponsors_Activator::activate();
+}
+
+register_activation_hook( __FILE__, 'activate_wp_sponsors' );
+
/**
* The core plugin class that is used to define internationalization,
* dashboard-specific hooks, and public-facing site hooks.
From fa6b5abcc34806286487aeb58fc4e6dac65a14a0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Igor=20Beni=C4=87?=
Date: Sat, 6 Jul 2019 13:13:37 +0200
Subject: [PATCH 5/6] Updating readme
---
README.txt | 137 +++++-------
admin/class-wp-sponsors-admin.php | 10 +-
admin/partials/meta-boxes/sponsor-info.php | 14 +-
includes/class-wp-sponsors-installer.php | 2 +-
includes/class-wp-sponsors-shortcodes.php | 235 ++++++++++++++++-----
includes/class-wp-sponsors-widget.php | 6 +-
includes/class-wp-sponsors.php | 1 +
includes/functions-updates.php | 5 +-
public/class-wp-sponsors-public.php | 88 ++++++++
public/css/wp-sponsors-public.css | 29 ++-
wp-sponsors.php | 12 --
11 files changed, 375 insertions(+), 164 deletions(-)
diff --git a/README.txt b/README.txt
index b06baed..b0be82d 100755
--- a/README.txt
+++ b/README.txt
@@ -1,11 +1,11 @@
-=== Plugin Name ===
+=== Sponsors ===
Contributors: ibenic
-Donate link: https://www.ibenic.com
+Donate link: http://www.wpsimplesponsorships.com
Tags: post type, images, partners, sponsors
Requires at least: 3.0.1
-Tested up to: 4.9.7
+Tested up to: 5.2.2
Requires PHP: 7.0
-Stable tag: 2.5.1
+Stable tag: 3.0.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -13,7 +13,8 @@ Sponsors makes it easy to add your sponsors and partners to your WordPress websi
== Description ==
-Ever had to add a bunch of images with links on them for your event/company partners? With Sponsors, you won't have to use a text widget for that anymore. The companies and people that support you, your company or your event now get a separate place in the dashboar where you can add a link and an image for each of them. Then you add the Sponsors widget to the sidebar of your choosing and the linked images will show up there.
+Ever had to add a bunch of images with links on them for your event/company partners?
+With Sponsors, you won't have to use a text widget for that anymore. The companies and people that support you, your company or your event now get a separate place in the dashboar where you can add a link and an image for each of them. Then you add the Sponsors widget to the sidebar of your choosing and the linked images will show up there.
== Installation ==
@@ -27,109 +28,73 @@ Ever had to add a bunch of images with links on them for your event/company part
1. After you activate the plugin, a new content type will become available on the your WordPress admin panel. Here you can add a link, a description and an image for each Sponsor.
2. Add the widget to one or more sidebars and the images of your sponsors will show up there. Choose from which category you want to display sponsors (or select all), to show or hide images and the description
-== Shortcode ==
-
-=== Shortcode ===
+== Shortcodes ==
+** Sponsors **
The shortcode [sponsors] takes the following options:
* images (yes|no, default: yes)
+* image_size (medium|full|thumbnail|large|[any registered image size], default: medium)
* description (yes|no, default: no)
* max (number, default: none, showing all entries)
* title (yes|no, default: no)
* category (category-slug, default: all)
+* with_categories (yes|no, default: no )
+* category_title ( HTML tag for category title, default: h3)
* size (small|medium|large|full, default: medium)
* style (list|grid, default: list)
+* order (ASC|DESC, default: ASC )
+* orderby (menu_order|post_title|..., default: menu_order)
-== Changelog ==
-
-= 2.5.1 =
-* Fixed a PHP 7.2 deprecation error
-
-= 2.5.0 =
-* Fixed a small error and the plugin now works with Gutenburg!
-
-= 2.4.1 =
-* Fixed php errors when using the shortcode without any options
-
-= 2.4.0 =
-* Better responsive styling for the shortcode grid
-* Moved all fields to a single metabox in the admin dashboard
-
-= 2.3.3 =
-* Fixed syntax errors in upgrade script for 2.0
-* Added link behaviour settings to shortcode
-
-= 2.3.2 =
-* Sort by menu_order by default in the shortcode
+When with_categories is used, it will show sponsors under their appropriate categories.
+The attribute size is used to define the size of the columns. More style updates will come in future versions.
-= 2.3.1 =
-* Fixed a critical issue where we assumed your table prefix was 'wp_'
-* Fixed the max settings in the shortcode
+** Form **
+This shortcode will display a form so potential sponsors can submit their information.
+Each Sponsor entered with that form will become a Draft so they won't be displayed immediately.
+You can publish them, or send them an email to get their logo as well.
-= 2.3.0 =
-* Fixed equal height grid layout for the shortcode
-* Added a per-sponsor setting to open the sponsor link in a new window
+Shortcode [sponsors_acquisition_form] will allow it. Fields that are used here are:
+* Name
+* Email (so you can email them about their submission)
+* Description
+* Link
-= 2.2.3 =
-* Fixes an issue where the shortcode would take over the current page's post type and edit link.
+== Planned Features ==
-= 2.2.2 =
-* Changed how sponsors are links in the shortcode. No using the no-images option, the title will be linked and the description won't be. With images, the image will link and the title won't.
+Here are some of the features planned for future versions:
-= 2.2.1 =
-* Bugfix
+* Form Block - for the new WordPress block editor
+* Sponsors Block - for the new WordPress block editor
+* Category ordering
+* Documentation Page
+* Front optimizations
-= 2.2 =
-* Added translations for fr_BE and fr_FR
-* Added a filter called "sponsors_widget_styling" to add a css class to each sponsor item from your theme
+== Upgrade Notice ==
-= 2.1 =
-* Added number of entries and title options to the shortcode
-* Added number of entries option to the widget
-* Added orderby title and random options to the widget
+= 3.0.0 =
+3.0.0 is a big update. Make a full site backup.
-= 2.0.3 =
-* Fixed a problem where the sponsor link wouldn't be shown when using no images in the shortcode
-
-= 2.0.2 =
-* The "no images" options in the shortcode now actually works
-* Improved styling of the widget title across themes
-* Updated translations for nl_NL and nl_BE
-
-= 2.0.1 =
-* Fixes a PHP notice when installing the plugin for the first time
-
-= 2.0.0 =
-* The plugin now uses the featured image field to save the sponsor's logo
-* Improved shortcode code and added "grid" style option
-* Added debug option to shortcode to better support layout issues
-
-= 1.9.1 =
-* Bugfix in the nofollow feature
-
-= 1.9.0 =
-* Improved sponsor description saving
-* Added default rel="nofollow" for sponsor links
-* Added support and donate links to plugin description
-
-= 1.8.5 =
-* In the shortcode, items are now sorted by the menu_order by default.
+== Changelog ==
-= 1.8.4 =
-* PHP 7 Compatibilty
-* Fixes a bug with the category selection in the shortcode, props to joachimjusth
+= 3.0.0 =
+* Big Code refactor.
+* Refactor: URL is stored under _website. Backwards compatibility is available.
+* Refactor: Description is stored under the regular content so we don't waste the database space.
+* Refactor: Post Type has changed from 'sponsor' to 'sponsors'.
+* Refactor: CSS for horizontal widget display has been enabled.
+* New: Image sizes can be defined in shortcode and in widget.
+* New: Sponsors can be display under appropriate categories in shortcode.
+* New: Sponsor Acquisition Form shortcode for front end information submission.
+* New: Simple Sponsorships compatibility.
-= 1.8.3 =
-* One last fix to the category selection in the widget, this should have all cases possible now.
+= 2.5.1 =
+* Fixed a PHP 7.2 deprecation error
-= 1.8.2 =
-* Fixes a bug caused in 1.8.1 where widgets that selected all sponsor categories wouldn't display any entries.
+= 2.5.0 =
+* Fixed a small error and the plugin now works with Gutenburg!
-= 1.8.1 =
-* Fixes a problem with category filtering on the widget
+= 2.4.1 =
+* Fixed php errors when using the shortcode without any options
-= 1.8.0 =
-* Added "show sponsor title" option to the widget, not checked by default
-* Updated the translations files with the latest strings and included an updatedd nl_NL translation
More information of older versions can be found in changelog.txt
diff --git a/admin/class-wp-sponsors-admin.php b/admin/class-wp-sponsors-admin.php
index f44f20c..a1a48eb 100755
--- a/admin/class-wp-sponsors-admin.php
+++ b/admin/class-wp-sponsors-admin.php
@@ -122,12 +122,18 @@ public function save_meta_boxes( $post_id ) {
return;
}
// Checks for input and sanitizes/saves if needed
- if ( isset( $_POST['wp_sponsors_url'] ) ) {
- update_post_meta( $post_id, 'wp_sponsors_url', sanitize_text_field( $_POST['wp_sponsors_url'] ) );
+ if ( isset( $_POST['_website'] ) ) {
+ update_post_meta( $post_id, '_website', sanitize_text_field( $_POST['_website'] ) );
}
+
+ if ( isset( $_POST['_email'] ) ) {
+ update_post_meta( $post_id, '_email', sanitize_text_field( $_POST['_email'] ) );
+ }
+
if ( isset( $_POST['wp_sponsors_desc'] ) ) {
update_post_meta( $post_id, 'wp_sponsors_desc', $_POST['wp_sponsors_desc'] );
}
+
$link_behaviour = isset($_POST['wp_sponsor_link_behaviour']) ? '1' : '0';
update_post_meta( $post_id, 'wp_sponsor_link_behaviour', $link_behaviour );
}
diff --git a/admin/partials/meta-boxes/sponsor-info.php b/admin/partials/meta-boxes/sponsor-info.php
index cd4b4f6..d5094cd 100644
--- a/admin/partials/meta-boxes/sponsor-info.php
+++ b/admin/partials/meta-boxes/sponsor-info.php
@@ -4,10 +4,20 @@
// Noncename needed to verify where the data originated
echo '';
// Get the url data if its already been entered
-$meta_value = get_post_meta( get_the_ID(), 'wp_sponsors_url', true );
+$meta_value = get_post_meta( get_the_ID(), '_website', true );
+if ( ! $meta_value ) {
+ $meta_value = get_post_meta( get_the_ID(), 'wp_sponsors_url', true );
+}
// Checks and displays the retrieved value
echo '';
-echo '';
+echo '';
+
+
+// Get the url data if its already been entered
+$meta_value = get_post_meta( get_the_ID(), '_email', true );
+// Checks and displays the retrieved value
+echo '';
+echo '';
// Display code/markup goes here. Don't forget to include nonces!
diff --git a/includes/class-wp-sponsors-installer.php b/includes/class-wp-sponsors-installer.php
index 4d7ee97..16b43d5 100644
--- a/includes/class-wp-sponsors-installer.php
+++ b/includes/class-wp-sponsors-installer.php
@@ -66,7 +66,7 @@ private function create_sponsor_taxonomies() {
'query_var' => true
);
// Register the sponsors taxonomy
- register_taxonomy( 'sponsor_categories', array( 'sponsor' ), $args );
+ register_taxonomy( 'sponsor_categories', array( 'sponsors' ), $args );
}
/**
diff --git a/includes/class-wp-sponsors-shortcodes.php b/includes/class-wp-sponsors-shortcodes.php
index 9d0a828..ae9464f 100644
--- a/includes/class-wp-sponsors-shortcodes.php
+++ b/includes/class-wp-sponsors-shortcodes.php
@@ -7,8 +7,77 @@ class WP_Sponsors_Shortcodes {
*/
public function register_shortcodes() {
add_shortcode( 'sponsors', array( __CLASS__, 'sponsors_shortcode' ) );
+ add_shortcode( 'sponsors_acquisition_form', array( __CLASS__, 'sponsors_form' ) );
}
+ /**
+ * Sponsor Form
+ * @return string
+ */
+ public static function sponsors_form( $atts = array() ) {
+ $atts = shortcode_atts( array (
+ 'fields' => '',
+ 'fields_labels' => '',
+ 'button' => __( 'Submit', 'wp-sponsors' ),
+ ), $atts, 'wp_sponsors_form' );
+
+
+ ob_start();
+ ?>
+
+ 'post',
'image' => 'yes',
'images' => 'yes',
'category' => '',
+ 'with_categories' => 'no',
+ 'category_title' => 'h3',
'size' => 'default',
'image_size' => 'medium',
'style' => 'list',
@@ -38,6 +108,7 @@ public static function sponsors_shortcode( $atts = array() ) {
'post_type' => array( 'sponsors', 'sponsor' ), // Allowing 'sponsor' in case the update does not work.
'post_status' => 'publish',
'pagination' => false,
+ 'no_found_rows' => true,
'order' => $atts['order'],
'orderby' => isset( $atts['orderby'] ) ? $atts['orderby'] : 'menu_order',
'posts_per_page' => isset( $atts['max'] ) ? $atts['max'] : '-1',
@@ -57,14 +128,61 @@ public static function sponsors_shortcode( $atts = array() ) {
);
}
- $images = 'no' !== $atts['images'] && 'no' !== $atts['image'] ? true : false;
- $debug = $atts['debug'] ? true : false;
- $description = 'yes' === $atts['description'] ? true : false;
- $title = 'yes' === $atts['title'] ? true : false;
- // $sizes = array('small' => '15%', 'medium' => '30%', 'large' => '50%', 'full' => '100%', 'default' => '30%');
- ob_start();
+ $images = 'no' !== $atts['images'] && 'no' !== $atts['image'] ? true : false;
+ $debug = $atts['debug'] ? true : false;
+ $description = 'yes' === $atts['description'] ? true : false;
+ $title = 'yes' === $atts['title'] ? true : false;
+ $sponsor_posts = get_posts( $args );
+ $sponsors = array();
+ $categories = array();
+
+ foreach ( $sponsor_posts as $sponsor_post ) {
+ $link = get_post_meta( $sponsor_post->ID, '_website', true );
+
+ if ( ! $link ) {
+ $link = get_post_meta( $sponsor_post->ID, 'wp_sponsors_url', true );
+ }
+
+ $sponsor = array();
+ $sponsor['id'] = $sponsor_post->ID;
+ $sponsor['link'] = $link;
+ $sponsor['link_target'] = get_post_meta( $sponsor_post->ID, 'wp_sponsor_link_behaviour', true );
+ $sponsor['logo'] = get_the_post_thumbnail( $sponsor_post->ID, $atts['image_size'] );
+ $sponsor['title'] = get_the_title( $sponsor_post );
+ $sponsor['categories'] = array();
+ $desc = do_shortcode( wpautop( $sponsor_post->post_content ) );
+ if ( ! $desc ) {
+ $desc = get_post_meta( $sponsor_post->ID, 'wp_sponsors_desc', true );
+ }
+
+ if( 'yes' === $atts['with_categories'] ) {
+ $sponsor['categories'] = get_the_terms( $sponsor_post, 'sponsor_categories');
+ }
+
+ $sponsor['desc'] = $desc;
+ $sponsors[] = $sponsor;
+ }
- $query = new WP_Query( $args );
+ if( 'yes' === $atts['with_categories'] ) {
+ foreach( $sponsors as $sponsor ) {
+ if ( $sponsor['categories'] ) {
+ foreach ( $sponsor['categories'] as $term ) {
+ if ( ! isset( $categories[ $term->term_id ] ) ) {
+ $categories[ $term->term_id ] = array(
+ 'title' => $term->name,
+ 'sponsors' => array()
+ );
+ }
+ $categories[ $term->term_id ]['sponsors'][] = $sponsor;
+ }
+ }
+ }
+ } else {
+ // Get all under one category so we can iterate through them.
+ $categories[0] = array( 'title' => '', 'sponsors' => $sponsors );
+ }
+
+ ob_start();
// Set up the shortcode styles
$style = array();
@@ -89,73 +207,74 @@ public static function sponsors_shortcode( $atts = array() ) {
break;
}
- if ( $query->have_posts() ) {
- echo $style['containerPre'];
- while ( $query->have_posts() ) : $query->the_post();
-
- $sponsor_id = get_the_ID();
- $link = get_post_meta( $sponsor_id, 'wp_sponsors_url', true );
- $link_target = get_post_meta( $sponsor_id, 'wp_sponsor_link_behaviour', true );
- $target = 1 === absint( $link_target ) ? 'target="_blank"' : '';
- $class = '';
- $class .= $atts['size'];
- $image = false;
+ if ( $sponsors ) {
+ foreach ( $categories as $category ) {
- if( $debug ) {
- $class .= ' debug';
+ if ( isset( $category['title'] ) && $category['title'] ) {
+ echo '<' . $atts['category_title'] . '>' . $category['title'] . '' . $atts['category_title'] . '>';
}
+ $_sponsors = $category['sponsors'];
+ echo $style['containerPre'];
+ foreach ( $_sponsors as $sponsor ) {
- echo '<' . $style['wrapperPre'] . ' class="' . $style['wrapperClass'] .' ' . $class . '">';
- $sponsor = '';
+ $link = $sponsor['link'];
+ $link_target = $sponsor['link_target'];
+ $target = 1 === absint( $link_target ) ? 'target="_blank"' : '';
+ $class = '';
+ $class .= $atts['size'];
- // Check if we have a link
- if( $link && ! $images && $title ) {
- $sponsor .= '';
- $sponsor .= '
';
- $sponsor .= '';
- }
+ if ( $debug ) {
+ $class .= ' debug';
+ }
- if ( $images ) {
- // Check if we should do images, just show the title if there's no image set
- $image = get_the_post_thumbnail( $sponsor_id, $atts['image_size'] );
+ echo '<' . $style['wrapperPre'] . ' class="' . $style['wrapperClass'] . ' ' . $class . '">';
+ $sponsor_html = '';
- // We did not want title, but we don't have an image. Show the title then.
- if ( ! $image && ! $title ) {
- $image = '
' . get_the_title() . '
';
+ // Check if we have a link
+ if ( $link && ! $images && $title ) {
+ $sponsor_html .= '';
+ $sponsor_html .= '
';
+ // Check if we need a description and the description is not empty
+ if ( $description ) {
+ $desc = $sponsor['desc'];
+ if ( $desc ) {
+ $sponsor_html .= '
' . $desc . '
';
+ }
}
- }
- echo $sponsor;
- echo $style['wrapperPost'];
+ echo $sponsor_html;
+ echo $style['wrapperPost'];
- endwhile;
- echo $style['containerPost'];
- wp_reset_postdata();
+ }
+ echo $style['containerPost'];
+ }
return ob_get_clean();
}
}
diff --git a/includes/class-wp-sponsors-widget.php b/includes/class-wp-sponsors-widget.php
index 2e0289e..209edf9 100644
--- a/includes/class-wp-sponsors-widget.php
+++ b/includes/class-wp-sponsors-widget.php
@@ -67,7 +67,11 @@ function widget( $args, $instance ) {
have_posts() ) : $query->the_post(); ?>
loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
+ $this->loader->add_action( 'init', $plugin_public, 'sponsors_acquisition_form_submit' );
}
diff --git a/includes/functions-updates.php b/includes/functions-updates.php
index d093772..b49ef90 100644
--- a/includes/functions-updates.php
+++ b/includes/functions-updates.php
@@ -32,7 +32,6 @@ function wp_sponsors_update_200() {
);
}
}
- $wpdb->insert($wpdb->prefix . 'options', array( 'option_name' => 'sponsors_db_version', 'option_value' => 2), array( '%s', '%d' ));
return;
}
@@ -53,6 +52,10 @@ function wp_sponsors_update_post_type_300() {
if ( false !== $ret ) {
delete_post_meta( $post_id, 'wp_sponsors_desc' );
}
+
+ $url = get_post_meta( $post_id, 'wp_sponsors_url', true );
+ update_post_meta( $post_id, '_website', $url );
+ delete_post_meta( $post_id, 'wp_sponsors_url' );
}
}
}
\ No newline at end of file
diff --git a/public/class-wp-sponsors-public.php b/public/class-wp-sponsors-public.php
index dd3faa3..3459e2b 100755
--- a/public/class-wp-sponsors-public.php
+++ b/public/class-wp-sponsors-public.php
@@ -40,6 +40,21 @@ class WP_Sponsors_Public {
*/
private $version;
+ /**
+ * Form Errors
+ *
+ * @var array
+ */
+ public $form_errors = array();
+
+
+ /**
+ * Form Notices
+ *
+ * @var array
+ */
+ public $form_notices = array();
+
/**
* Initialize the class and set its properties.
*
@@ -100,4 +115,77 @@ public function enqueue_scripts() {
}
+ /**
+ * Show Errors and notices on the Submission form.
+ */
+ public function show_errors_and_notices() {
+ if ( $this->form_errors ) {
+ foreach ( $this->form_errors as $error ) {
+ echo '