• Resolved adeacetis

    (@ajmariff)


    Dear plugin maker,

    First of all, I’d like to thank you for this great plugin.

    Last November, we started a news sports media covering exclusively ice hockey. At the time, we’d found SP was covering 80% of all our needs and started the project with version 1.6.

    For the remaining 20%, we enlarged the set of available information by adding custom fields to CP (e.g.: teams, players) and taxonomies (e.g.: venues, leagues). With those news fields, I’d needed new getters to display them on my views. Reinventing the wheel is not my cup of tea so I simply extended the existing plugin classes with my own classes.

    Everything was working fine, the life was sweet and butterfly were everywhere. Until I tried to update the plugin to version 1.7 but it broke everything.
    Unfortunately, I didn’t find what caused this plugin scope issue while investigating. I surely have missed something.

    Do you have any idea what happened and how I could make my site SP-update-friendly again ?

    Thank you very much.

    Kind regards,
    Axel

    https://wordpress.org/plugins/sportspress/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Brian

    (@brianmiyaji)

    @ajmariff I’d be happy to help you with this. Could you share a code snippet (from your extension) that used to work with SP ~1.6 but stopped working after 1.7? Looking at that hopefully I’d be able to pinpoint the issue 🙂

    Thread Starter adeacetis

    (@ajmariff)

    @brian

    Here’s how I extend SP Classes :

    if ( class_exists( 'SP_Team' ) ) {
    
      class CHB_Team extends SP_Team {
    /* ... Code here ... */ 
    
    /* ... A custom function that gets social media account stored into a custom fields ... */
    
        public function social_media( $network = null ) {
    
          $output = array();
          if ( $network ):
            return get_post_meta( $this->ID, 'team_social_' . $network );
          else:
            $defaults = array(
    	  'facebook',
    	  'twitter',
    	  'instagram',
    	  'tumblr',
    	  'pinterest',
    	  'youtube',
            );
            $defaults = array_reverse( $defaults );
          foreach ( $defaults as $key ):
            $response['network'] = $key;
            $response['url'] = get_post_meta( $this->ID, 'team_social_' . $key, true );
            if ( $response['url'] ) :
              array_unshift( $output, $response );
            endif;
          endforeach;
          return $output;
          endif;
        }
      }
    }

    You see here $this-ID is supposed to come from SP_Teams which gets it from SP_CustomPost.

    Thank you Brian,
    A.

    Plugin Author Brian

    (@brianmiyaji)

    @ajmariff Could you tell me what error you are getting? It’s possible that the code is running too early, but the code above works for me when placed into a file inside sportspress/modules.

    Thread Starter adeacetis

    (@ajmariff)

    @brian It worked like a charm.

    The Sportpress support was activated and the files were located into ‘ MY_THEME_DIR/inc/’ . I guess it was simply file location issue. I shall read your documentation once again.

    Thank you very much (1000x times),
    A.

    Plugin Author Brian

    (@brianmiyaji)

    @ajmariff Glad to hear that! You’re right, the theme would be initializing before the plugin, so the SP_ classes aren’t available at that stage. Theme functions are loaded with the after_setup_theme action, but the plugin loads classes during the init action.

    https://codex.wordpress.org/Plugin_API/Action_Reference

    I’d still recommend including the extended class and any other functions in your child theme or a custom plugin. Try loading the class like this:

    add_action( 'init', 'extend_sp_team_class', 20 );
    function extend_sp_team_class() {
    include_once( 'inc/class-chb-team.php' );
    }
    Thread Starter adeacetis

    (@ajmariff)

    @brian I’m going to look at it. Thank you infinitely for your support and help.

    Thread Starter adeacetis

    (@ajmariff)

    Resolved

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Unable to extend SP_Classes since version 1.6’ is closed to new replies.