Skip to content

Instantly share code, notes, and snippets.

@sblomberg
Created July 13, 2016 14:46
Show Gist options
  • Save sblomberg/600599f5a9e22a5827746fa9f4fbe81a to your computer and use it in GitHub Desktop.
Save sblomberg/600599f5a9e22a5827746fa9f4fbe81a to your computer and use it in GitHub Desktop.
Wrapping functions with a class to isolate private functions
<?php
/**
* Wrapping with a class the static way:
*/
Static_Convio_Gravity_Forms_Meta::init();
class Static_Convio_Gravity_Forms_Meta {
public static function init() {
add_action( 'gform_post_update_form_meta', array( __CLASS__, 'pga_gform_post_update_form_meta' ), 10, 3 );
}
public static function pga_gform_post_update_form_meta( $form_meta, $form_id, $meta_name ) {
// Call to helper function
$hidden_ints = self::hidden_ints( $post_data );
}
private static function hidden_ints( $post_data ) {
$hidden_ints = array( 0, 1 );
return $hidden_ints;
}
}
/**
* Wrapping with a class the object way:
*/
new Object_Convio_Gravity_Forms_Meta();
class Object_Convio_Gravity_Forms_Meta {
public function __construct() {
add_action( 'gform_post_update_form_meta', array( $this, 'pga_gform_post_update_form_meta' ), 10, 3 );
}
public function pga_gform_post_update_form_meta( $form_meta, $form_id, $meta_name ) {
// Call to helper function
$hidden_ints = $this->hidden_ints( $post_data );
}
private function hidden_ints( $post_data ) {
$hidden_ints = array( 0, 1 );
return $hidden_ints;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment