Sharing_Service::get_all_services PHP Method

get_all_services() public method

Gets a list of all available service names and classes
public get_all_services ( $include_custom = true )
    public function get_all_services($include_custom = true)
    {
        // Default services
        // if you update this list, please update the REST API tests
        // in bin/tests/api/suites/SharingTest.php
        $services = array('email' => 'Share_Email', 'print' => 'Share_Print', 'facebook' => 'Share_Facebook', 'linkedin' => 'Share_LinkedIn', 'reddit' => 'Share_Reddit', 'twitter' => 'Share_Twitter', 'press-this' => 'Share_PressThis', 'google-plus-1' => 'Share_GooglePlus1', 'tumblr' => 'Share_Tumblr', 'pinterest' => 'Share_Pinterest', 'pocket' => 'Share_Pocket', 'telegram' => 'Share_Telegram', 'jetpack-whatsapp' => 'Jetpack_Share_WhatsApp', 'skype' => 'Share_Skype');
        if ($include_custom) {
            // Add any custom services in
            $options = $this->get_global_options();
            foreach ((array) $options['custom'] as $custom_id) {
                $services[$custom_id] = 'Share_Custom';
            }
        }
        /**
         * Filters the list of available Sharing Services.
         *
         * @module sharedaddy
         *
         * @since 1.1.0
         *
         * @param array $services Array of all available Sharing Services.
         */
        return apply_filters('sharing_services', $services);
    }

Usage Example

 /**
  * Validates that the parameter is a custom sharing service ID like 'custom-1461976264'.
  *
  * @since 4.3.0
  *
  * @param string $value Value to check.
  * @param WP_REST_Request $request
  * @param string $param Name of the parameter passed to endpoint holding $value.
  *
  * @return bool
  */
 public static function validate_custom_service_id($value = '', $request, $param)
 {
     if (!empty($value) && (!is_string($value) || !preg_match('/custom\\-[0-1]+/i', $value))) {
         return new WP_Error('invalid_param', sprintf(esc_html__("%s must be a string prefixed with 'custom-' and followed by a numeric ID.", 'jetpack'), $param));
     }
     if (!class_exists('Sharing_Service') && !@(include JETPACK__PLUGIN_DIR . 'modules/sharedaddy/sharing-service.php')) {
         return new WP_Error('invalid_param', esc_html__('Failed loading required dependency Sharing_Service.', 'jetpack'));
     }
     $sharer = new Sharing_Service();
     $services = array_keys($sharer->get_all_services());
     if (!empty($value) && !in_array($value, $services)) {
         return new WP_Error('invalid_param', sprintf(esc_html__('%s is not a registered custom sharing service.', 'jetpack'), $param));
     }
     return true;
 }