Created
October 5, 2020 16:29
-
-
Save ChaseWiseman/a1e2146c5a58d1a209b2709ce065c157 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| interface SettingsInterface { | |
| public function get_setting( $key ); | |
| public function set_setting( $key, $value ); | |
| } | |
| trait SettingsTrait { | |
| protected $settings = []; | |
| abstract public function get_url(); | |
| public function init_settings() { | |
| wp_remote_get( $this->get_url() ); | |
| // set $this->settings, etc... | |
| return $this; | |
| } | |
| public function get_setting( $key ) { | |
| return isset( $this->settings[ $key ] ) ? $this->settings[ $key ] : null; | |
| } | |
| public function set_setting( $key, $value ) { | |
| $this->settings[ $key ] = $value; | |
| } | |
| } | |
| class Advanced_Matching_Settings implements SettingsInterface { | |
| use SettingsTrait; | |
| public $pixel_id; | |
| public function set_pixel_id( $pixel_id ) { | |
| $this->pixel_id = $pixel_id; | |
| return $this; | |
| } | |
| public function get_pixel_id() { | |
| return $this->pixel_id; | |
| } | |
| public function get_url() { | |
| return 'https://connect.facebook.net/signals/config/json/' . $this->get_pixel_id(); | |
| } | |
| public function is_enabled() { | |
| return (bool) $this->get_setting( 'enableAutomaticMatching' ); | |
| } | |
| } | |
| $settings = ( new Advanced_Matching_Settings() )->set_pixel_id( '1234' )->init_settings(); | |
| echo $settings->is_enabled(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment