page_slug = 'addons'; $this->title = __( 'Available Addons', 'socialsnap' ); // Actions add_action( 'admin_menu', array( $this, 'register_pages' ), 14 ); add_action( 'admin_notices', array( $this, 'socialsnap_addons_notice' ) ); } /** * Register the pages to be used for the Settings screen. * * @since 1.0.0 */ public function register_pages() { // Add 'Addons' submenu page add_submenu_page( 'socialsnap-settings', __( 'Social Snap Addons', 'socialsnap' ), '' . __( 'Addons', 'socialsnap' ) . '', apply_filters( 'socialsnap_addons_cap', 'manage_options' ), 'socialsnap-addons', array( $this, 'render' ) ); } /** * Build the output for the plugin addons page. * * @since 1.0.0 */ public function render() { // Get list of addons $this->addons = $this->get_addon_list(); ?>
addons ) ) { ?>

addons_list( $this->addons ); } ?>
array(), 'upgrade' => array(), 'coming_soon' => array(), ); // Sort installable and upgradable addons if ( is_array( $addons ) && ! empty( $addons ) ) { foreach ( $addons as $addon ) { if ( '' === $addon['version'] ) { $addons_list['coming_soon'][] = $addon; } else { $valid = false; if ( socialsnap()->pro ) { $license = socialsnap()->license->info(); $valid = ( 'valid' === $license['status'] ) && in_array( $license['slug'], $addon['package'] ); } if ( $valid ) { $addons_list['available'][] = $addon; } else { $addons_list['upgrade'][] = $addon; } } } } $addons = array_merge( $addons_list['available'], $addons_list['upgrade'], $addons_list['coming_soon'] ); ?>
get_plugin_basename_from_slug( $addon['slug'], $plugins ); $status = 'upgrade'; $status_label = __( 'Not Installed', 'socialsnap' ); $button_label = __( 'Upgrade Now', 'socialsnap' ); $button_action = 'addon-upgrade'; $button_url = '#'; if ( in_array( $addon, $addons_list['coming_soon'] ) ) { $status = 'coming_soon'; $status_label = ''; $button_label = __( 'Coming Soon', 'socialsnap' ); $button_action = ''; $button_url = '#'; } elseif ( in_array( $addon, $addons_list['upgrade'] ) ) { $status = 'upgrade'; $status_label = __( 'Not Installed', 'socialsnap' ); $button_label = apply_filters( 'socialsnap_upgrade_button_text', __( 'Upgrade Now', 'socialsnap' ) ); $button_action = 'upgrade'; $button_url = socialsnap_upgrade_link(); } elseif ( ! isset( $plugins[ $plugin_basename ] ) ) { $status = 'download'; $status_label = __( 'Not Installed', 'socialsnap' ); $button_label = __( 'Install', 'socialsnap' ); $button_action = 'install_addon'; } elseif ( is_plugin_inactive( $plugin_basename ) ) { $status = 'inactive'; $status_label = __( 'Inactive', 'socialsnap' ); $button_label = __( 'Activate', 'socialsnap' ); $button_action = 'activate_addon'; } elseif ( is_plugin_active( $plugin_basename ) ) { $status = 'active'; $status_label = __( 'Active', 'socialsnap' ); $button_label = __( 'Deactivate', 'socialsnap' ); $button_action = 'deactivate_addon'; } $new_tab = ''; if ( 'upgrade' === $status ) { $new_tab = ' target="_blank"'; } else { $new_tab = ''; } // Only Coming soon addons have disabled button $disabled = 'coming_soon' !== $status ? '' : ' disabled="disabled"'; ?>
get_addons(); } return $addons; } /** * Pings the remote server for addons data. * * @since 1.0.0 * @return bool|array False if no key or failure, array of addon data otherwise. */ public function get_addons() { $params = apply_filters( 'socialsnap_get_addons_params', array() ); $addons = socialsnap_perform_remote_request( 'get-addons-data', $params ); // If there was an API error, set transient for only 10 minutes. if ( is_wp_error( $addons ) ) { set_site_transient( 'socialsnap_addons', false, 10 * MINUTE_IN_SECONDS ); return false; } // If there was an error retrieving the addons, set the error. if ( isset( $addons->error ) ) { set_site_transient( 'socialsnap_addons', false, 10 * MINUTE_IN_SECONDS ); return false; } // Convert to array. $addons = json_decode( wp_json_encode( $addons ), true ); // Otherwise, our request worked. Save the data and return it. set_site_transient( 'socialsnap_addons', $addons, DAY_IN_SECONDS ); return $addons; } /** * Display a notice that Addons are PRO feature only. * * @since 1.0.0 */ public function socialsnap_addons_notice() { // User disabled these notices. if ( socialsnap_settings( 'ss_remove_notices' ) ) { return; } if ( ! socialsnap()->pro ) { $message = '

' . esc_html__( 'Social Snap Addons are a PRO feature.', 'socialsnap' ) . '' . esc_html__( 'Please upgrade to Social Snap PRO plan to unlock Addons and more awesome features.', 'socialsnap' ) . '
' . esc_html( apply_filters( 'socialsnap_upgrade_button_text', __( 'Upgrade Now', 'socialsnap' ) ) ) . '

'; socialsnap_print_notice( array( 'type' => 'info', 'message' => $message, 'message_id' => 'upgrade-to-enable-addons', 'class' => 'socialsnap-addons-notice', 'display_on' => 'socialsnap-addons', 'is_dismissible' => false, ) ); } } } new SocialSnap_Addons();