Skip to content

Instantly share code, notes, and snippets.

@jazzsequence
Last active February 14, 2023 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jazzsequence/c6b4d90b4667677aebc3faa4972cb190 to your computer and use it in GitHub Desktop.
Save jazzsequence/c6b4d90b4667677aebc3faa4972cb190 to your computer and use it in GitHub Desktop.
Gary Kovar week 8 code review
<?php
// When using the plugin generator, don't put "class" in your class name because it will automatically prefix with class-
// (hence the class-class- naming structure of this file)...
// https://webdevstudios.beanstalkapp.com/drumfit/browse/git/wp-content/plugins/wds-drumfit/includes/class-class-save-clear-cache.php?ref=c-5ff55df88c76ddd79aa857774227ce2cc0629798
private function clear_cache() {
//Since the ite is just a post type, this should work.
//It calls this action from the pantheon-cache.php file in mu-plugins.
do_action ( 'clean_post_cache' );
//However, if we find that the meta values are persisting the nuclear options is
//do_action( 'admin_post_pantheon_cache_flush_site' );
}
// * Inline comments should have a space after the //.
// * All comments must end in a full stop, question mark or exclamation point or fail VIP WPCS validation (which no one
// other than me cares about but I will continue to push regardless.
<?php
/**
* WDS Drumfit Form Handler
*
* @since NEXT
* @package WDS Drumfit
*/
//require_once( '../../ithemes-exchange/lib/cart/class.cart.php');
// Thou shalt not include lines of commented-out code on production sites.
/* ... */
/**
* Handle form submission.
*
* @author Gary Kovar
*
* @since NEXT
*
* @since NEXT
* @return bool
*/
// Duplicate @since tag.
public function handle_form_submission() {
wds_write_log( $_POST );
// If no form submission, bail
if ( ! empty( $_POST ) ) {
// Comments should end in full stops.
//Check if this is an admin page.
if ( ! is_admin() ) {
return false;
// Inconsistent comment spacing. All comments need to have a space after the //.
}
<?php
/**
* Page Title.
*
* @var string
*/
protected $title = 'Unlinked Subscriptions';
// Should be i18nized, e.g.:
protected $title = '';
public __construct() {
$this->title = esc_html__( 'Unlinked Subscriptions', 'drumfit' );
}
/* ... */
public function get_stripe_subscription( $site_subscription_id ) {
try {
$response = \Stripe\Subscription::retrieve( $site_subscription_id );
$response = $response->getLastResponse();
//print_r( $response );
$response_body = json_decode( $response->body );
return $response_body->status;
} catch ( Exception $e ) {
return 'Subscription not found: ' . $e->getMessage();
}
}
// Thou shalt not leave debugging code. But nice job adding try/catch for error checking!
/* ... */
public function information_page_display() {
echo "<h1>Local Users with Invalid Stripe Subscriptions</h1>";
// Double-quotes are not needed here. Needs i18n, e.g.:
echo '<h1>' . esc_html__( 'Local Users with Invalid Stripe Subscriptions', 'drumfit' ) . '</h1>';
/* ... */
if ( $stripe_subscription_status != 'active' ) {
$this->display_user_info( $site_subscription );
}
// Use Yoda Conditionals and absolute comparisons, e.g.:
if ( 'active' !== $stripe_subscription_status ) {
// Do stuff.
// Yoda conditionals prevent accidentally setting a variable to a value, e.g. if you forget the !:
if ( $stripe_subscription_status = 'active' ) // You've just made $stripe_subscription_status active.
// Absolute comparisons (!== and ===) compare the _real_ values and prevent strict WPCS sniffing errors from triggering.
<?php
//Register & enqueue javascript.
wp_register_style( 'jquery-ui-styles', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css' );
wp_enqueue_style( 'jquery-ui-styles' );
// Probably better to download the CSS and enqueue locally rather than making a remote request. This way we can pare down the
// CSS if need be, uglify it, concatenate it with other admin CSS, etc...
wp_register_script(
'user_name_search',
$this->plugin->url . 'assets/js/user_search.js',
array(
'jquery',
'jquery-ui-autocomplete',
),
1.0,
true
);
wp_localize_script( 'user_name_search', 'UserSearch', $this->user_search() );
wp_enqueue_script( 'user_name_search' );
// * Layout for wp_register_script and wp_localize_script should be the opposite of what's here. Typically wp_localize_script is
// broken out into multiple lines (although here is fine since you're using a method to dynamically populate the values.
// * No need to break wp_register_script and wp_enqueue_script, can combine both into a single wp_enqueue_script
// * Should have some kind of minification and check when to use the minified files, see my solution here:
// https://gist.github.com/jazzsequence/1778092c40f0886d242ec7976100bcd4
// * Plugin generator has a built-in VERSION constant which can be used for versioning the js.
// e.g.:
wp_enqueue_script( 'user_name_search', wds_drumfit()->url . 'assets/js/user_search' . $min . '.js', array( 'jquery', 'jquery-ui-autocomplete' ), wds_drumfit()->version, true );
wp_register_script( 'form_visibility',
$this->plugin->url . 'assets/js/form_visibility.js'
);
wp_enqueue_script( 'form_visibility' );
// Same comment as above:
wp_enqueue_script( 'form_visibility', wds_drumfit()->url . 'assets/js/form_visibility' . $min . '.js' );
<?php
/**
* Attach other plugin classes to the base plugin class.
*
* @since NEXT
* @return void
*/
public function plugin_classes() {
// Attach other plugin classes to the base plugin class.
$this->stripe_handler = new WDSD_Stripe_Handler( $this );
$this->manual_order = new WDSD_Manual_Order( $this );
$this->helper = new WDSD_Helper( $this );
$this->class_save_clear_cache = new WDSD_Class_Save_Clear_Cache( $this );
$this->online_class = new WDSD_Online_Class( $this );
$this->identify_unlinked_subscriptions = new WDSD_Identify_Unlinked_Subscriptions( $this );
$this->helper = new WDSD_Helper( $this );
$this->form_handler = new WDSD_Form_Handler( $this );
$this->ite_handler = new WDSD_Ite_Handler( $this );
$this->stripe_post = new WDSD_Stripe_Post( $this );
} // END OF PLUGIN CLASSES FUNCTION
// Make sure all of these are lined up correctly, e.g.:
$this->stripe_handler = new WDSD_Stripe_Handler( $this );
$this->manual_order = new WDSD_Manual_Order( $this );
$this->helper = new WDSD_Helper( $this );
$this->class_save_clear_cache = new WDSD_Class_Save_Clear_Cache( $this );
$this->online_class = new WDSD_Online_Class( $this );
$this->identify_unlinked_subscriptions = new WDSD_Identify_Unlinked_Subscriptions( $this );
$this->helper = new WDSD_Helper( $this );
$this->form_handler = new WDSD_Form_Handler( $this );
$this->ite_handler = new WDSD_Ite_Handler( $this );
$this->stripe_post = new WDSD_Stripe_Post( $this );
@jazzsequence
Copy link
Author

what an asshole 😜

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment