Skip to content

Commit

Permalink
Update settings getter and related methods
Browse files Browse the repository at this point in the history
  • Loading branch information
robincornett committed May 8, 2019
1 parent 187a83c commit 21b175b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ private function networks() {
$networks = include plugin_dir_path( dirname( __FILE__ ) ) . 'settings/networks.php';
$fields = array();
$i = 0;
$setting = scriptlesssocialsharing_get_setting();
$setting = $this->get_setting( 'buttons' );
foreach ( $networks as $network ) {
if ( 'sms' === $network['name'] && empty( $setting['buttons']['sms'] ) ) {
if ( 'sms' === $network['name'] && empty( $setting['sms'] ) ) {
continue;
}
$fields[ $network['name'] ] = array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ protected function get_available_buttons() {
return $this->buttons;
}
$buttons = $this->get_all_buttons();
$setting = $this->get_setting();
$set_buttons = $setting['buttons'];
$set_buttons = $this->get_setting( 'buttons' );
if ( $set_buttons ) {
foreach ( $buttons as $key => $value ) {
if ( ! isset( $set_buttons[ $value['name'] ] ) || ! $set_buttons[ $value['name'] ] ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ public function do_location() {
return;
}
$post_type = get_post_type();
$setting = $this->get_setting();
$setting = $this->get_setting( 'post_types' );
$locations = $this->get_locations();
foreach ( $locations as $location => $args ) {
if ( ! in_array( $location, array( 'before', 'after' ), true ) ) {
continue;
}
if ( empty( $setting['post_types'][ $post_type ][ $location ] ) ) {
if ( empty( $setting[ $post_type ][ $location ] ) ) {
continue;
}
if ( $args['hook'] ) {
Expand Down Expand Up @@ -71,8 +71,7 @@ private function genesis_hooks() {
if ( 'genesis' !== get_template() ) {
return false;
}
$setting = $this->get_setting();
$use_genesis = apply_filters( 'scriptlesssocialsharing_prefer_genesis_hooks', $setting['genesis'] );
$use_genesis = apply_filters( 'scriptlesssocialsharing_prefer_genesis_hooks', $this->get_setting( 'genesis' ) );
if ( ! $use_genesis ) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ private function add_shortcode_buttons( $buttons ) {
$output = '';
$attributes = $this->get_attributes();
$pinterest = get_post_meta( get_the_ID(), '_scriptlesssocialsharing_pinterest', true );
$setting = $this->get_setting();
$setting = $this->get_setting( 'buttons' );
foreach ( $all_buttons as $button ) {
if ( 'pinterest' === $button['name'] && ! $attributes['image'] && ! $pinterest ) {
continue;
}
if ( ( empty( $passed ) && ! empty( $setting['buttons'][ $button['name'] ] ) ) || in_array( $button['name'], $passed, true ) ) {
if ( ( empty( $passed ) && ! empty( $setting[ $button['name'] ] ) ) || in_array( $button['name'], $passed, true ) ) {
$output .= $this->build_link_markup( $button );
}
}
Expand Down
19 changes: 11 additions & 8 deletions includes/output/class-scriptlesssocialsharing-output.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,18 @@ protected function is_disabled() {

/**
* Get the current plugin setting.
*
* @param string $key
*
* @return mixed|\ScriptlessSocialSharingSettings
*/
protected function get_setting() {
protected function get_setting( $key = '' ) {
if ( isset( $this->setting ) ) {
return $this->setting;
return $key ? $this->setting[ $key ] : $this->setting;
}
$this->setting = scriptlesssocialsharing_get_setting();

return $this->setting;
return $key ? $this->setting[ $key ] : $this->setting;
}

/**
Expand Down Expand Up @@ -137,8 +140,8 @@ private function get_link_target( $button ) {
*/
private function get_label_class() {
$class = 'sss-name';
$setting = $this->get_setting();
if ( 0 === $setting['button_style'] ) {
$setting = $this->get_setting( 'button_style' );
if ( 0 === $setting ) {
$class = 'screen-reader-text';
}

Expand Down Expand Up @@ -255,12 +258,12 @@ protected function get_individual_button_url( $button, $attributes, $setting ) {
*/
protected function get_buttons_in_order() {
$buttons = include plugin_dir_path( dirname( __FILE__ ) ) . 'settings/networks.php';
$setting = $this->get_setting();
if ( ! $setting['order'] ) {
$setting = $this->get_setting( 'order' );
if ( ! $setting ) {
return $buttons;
}

return array_merge( $setting['order'], $buttons );
return array_merge( $setting, $buttons );
}

/**
Expand Down

0 comments on commit 21b175b

Please sign in to comment.