Sharing_Service::new_service PHP Method

new_service() public method

public new_service ( $label, $url, $icon )
    public function new_service($label, $url, $icon)
    {
        // Validate
        $label = trim(wp_html_excerpt(wp_kses($label, array()), 30));
        $url = trim(esc_url_raw($url));
        $icon = trim(esc_url_raw($icon));
        if ($label && $url && $icon) {
            $options = get_option('sharing-options');
            if (!is_array($options)) {
                $options = array();
            }
            $service_id = 'custom-' . time();
            // Add a new custom service
            $options['global']['custom'][] = $service_id;
            if (false !== $this->global) {
                $this->global['custom'][] = $service_id;
            }
            update_option('sharing-options', $options);
            // Create a custom service and set the options for it
            $service = new Share_Custom($service_id, array('name' => $label, 'url' => $url, 'icon' => $icon));
            $this->set_service($service_id, $service);
            // Return the service
            return $service;
        }
        return false;
    }

Usage Example

Esempio n. 1
0
 public function ajax_new_service()
 {
     if (isset($_POST['_wpnonce']) && isset($_POST['sharing_name']) && isset($_POST['sharing_url']) && isset($_POST['sharing_icon']) && wp_verify_nonce($_POST['_wpnonce'], 'sharing-new_service')) {
         $sharer = new Sharing_Service();
         if ($service = $sharer->new_service($_POST['sharing_name'], $_POST['sharing_url'], $_POST['sharing_icon'])) {
             $this->output_service($service->get_id(), $service);
             echo '<!--->';
             $service->button_style = 'icon-text';
             $this->output_preview($service);
             die;
         }
     }
     // Fail
     die('1');
 }
All Usage Examples Of Sharing_Service::new_service