当前位置: 首页>>代码示例>>PHP>>正文


PHP wc_is_valid_url函数代码示例

本文整理汇总了PHP中wc_is_valid_url函数的典型用法代码示例。如果您正苦于以下问题:PHP wc_is_valid_url函数的具体用法?PHP wc_is_valid_url怎么用?PHP wc_is_valid_url使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了wc_is_valid_url函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: update_delivery_url

 /**
  * Updated the Webhook delivery URL.
  *
  * @param WC_Webhook $webhook
  */
 private function update_delivery_url($webhook)
 {
     $delivery_url = !empty($_POST['webhook_delivery_url']) ? $_POST['webhook_delivery_url'] : '';
     if (wc_is_valid_url($delivery_url)) {
         $webhook->set_delivery_url($delivery_url);
     }
 }
开发者ID:coderkevin,项目名称:woocommerce,代码行数:12,代码来源:class-wc-admin-webhooks.php

示例2: test_wc_is_valid_url

 /**
  * Test wc_is_valid_url()
  *
  * @since 2.3.0
  */
 public function test_wc_is_valid_url()
 {
     // Test some invalid URLs
     $this->assertEquals(false, wc_is_valid_url('google.com'));
     $this->assertEquals(false, wc_is_valid_url('ftp://google.com'));
     $this->assertEquals(false, wc_is_valid_url('sftp://google.com'));
     $this->assertEquals(false, wc_is_valid_url('https://google.com/test invalid'));
     // Test some valid URLs
     $this->assertEquals(true, wc_is_valid_url('http://google.com'));
     $this->assertEquals(true, wc_is_valid_url('https://google.com'));
     $this->assertEquals(true, wc_is_valid_url('https://google.com/test%20valid'));
     $this->assertEquals(true, wc_is_valid_url('https://google.com/test-valid/?query=test'));
     $this->assertEquals(true, wc_is_valid_url('https://google.com/test-valid/#hash'));
 }
开发者ID:nathanielks,项目名称:woocommerce,代码行数:19,代码来源:conditional-functions.php

示例3: edit_webhook

 /**
  * Edit a webhook
  *
  * @since 2.2
  * @param int $id webhook ID
  * @param array $data parsed webhook data
  * @return array
  */
 public function edit_webhook($id, $data)
 {
     $data = isset($data['webhook']) ? $data['webhook'] : array();
     try {
         $id = $this->validate_request($id, 'shop_webhook', 'edit');
         if (is_wp_error($id)) {
             return $id;
         }
         $data = apply_filters('woocommerce_api_edit_webhook_data', $data, $id, $this);
         $webhook = new WC_Webhook($id);
         // update topic
         if (!empty($data['topic'])) {
             if (wc_is_webhook_valid_topic(strtolower($data['topic']))) {
                 $webhook->set_topic($data['topic']);
             } else {
                 throw new WC_API_Exception('woocommerce_api_invalid_webhook_topic', __('Webhook topic must be valid', 'woocommerce'), 400);
             }
         }
         // update delivery URL
         if (!empty($data['delivery_url'])) {
             if (wc_is_valid_url($data['delivery_url'])) {
                 $webhook->set_delivery_url($data['delivery_url']);
             } else {
                 throw new WC_API_Exception('woocommerce_api_invalid_webhook_delivery_url', __('Webhook delivery URL must be a valid URL starting with http:// or https://', 'woocommerce'), 400);
             }
         }
         // update secret
         if (!empty($data['secret'])) {
             $webhook->set_secret($data['secret']);
         }
         // update status
         if (!empty($data['status'])) {
             $webhook->update_status($data['status']);
         }
         // update user ID
         $webhook_data = array('ID' => $webhook->id, 'post_author' => get_current_user_id());
         // update name
         if (!empty($data['name'])) {
             $webhook_data['post_title'] = $data['name'];
         }
         // update post
         wp_update_post($webhook_data);
         do_action('woocommerce_api_edit_webhook', $webhook->id, $this);
         delete_transient('woocommerce_webhook_ids');
         return $this->get_webhook($id);
     } catch (WC_API_Exception $e) {
         return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
     }
 }
开发者ID:abcode619,项目名称:wpstuff,代码行数:57,代码来源:class-wc-api-webhooks.php

示例4: update_item

 /**
  * Update a single webhook.
  *
  * @param WP_REST_Request $request Full details about the request.
  * @return WP_Error|WP_REST_Response
  */
 public function update_item($request)
 {
     $id = (int) $request['id'];
     $post = get_post($id);
     if (empty($id) || empty($post->ID) || $this->post_type !== $post->post_type) {
         return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('ID is invalid.', 'woocommerce'), array('status' => 400));
     }
     $webhook = new WC_Webhook($id);
     // Update topic.
     if (!empty($request['topic'])) {
         if (wc_is_webhook_valid_topic(strtolower($request['topic']))) {
             $webhook->set_topic($request['topic']);
         } else {
             return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_topic", __('Webhook topic must be valid.', 'woocommerce'), array('status' => 400));
         }
     }
     // Update delivery URL.
     if (!empty($request['delivery_url'])) {
         if (wc_is_valid_url($request['delivery_url'])) {
             $webhook->set_delivery_url($request['delivery_url']);
         } else {
             return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_delivery_url", __('Webhook delivery URL must be a valid URL starting with http:// or https://.', 'woocommerce'), array('status' => 400));
         }
     }
     // Update secret.
     if (!empty($request['secret'])) {
         $webhook->set_secret($request['secret']);
     }
     // Update status.
     if (!empty($request['status'])) {
         $webhook->update_status($request['status']);
     }
     $post = $this->prepare_item_for_database($request);
     if (is_wp_error($post)) {
         return $post;
     }
     // Convert the post object to an array, otherwise wp_update_post will expect non-escaped input.
     $post_id = wp_update_post((array) $post, true);
     if (is_wp_error($post_id)) {
         if (in_array($post_id->get_error_code(), array('db_update_error'))) {
             $post_id->add_data(array('status' => 500));
         } else {
             $post_id->add_data(array('status' => 400));
         }
         return $post_id;
     }
     $post = get_post($post_id);
     $this->update_additional_fields_for_object($post, $request);
     /**
      * Fires after a single item is created or updated via the REST API.
      *
      * @param WP_Post         $post      Inserted object.
      * @param WP_REST_Request $request   Request object.
      * @param boolean         $creating  True when creating item, false when updating.
      */
     do_action("woocommerce_rest_insert_{$this->post_type}", $post, $request, false);
     $request->set_param('context', 'edit');
     $response = $this->prepare_item_for_response($post, $request);
     // Clear cache.
     delete_transient('woocommerce_webhook_ids');
     return rest_ensure_response($response);
 }
开发者ID:tlovett1,项目名称:woocommerce,代码行数:68,代码来源:class-wc-rest-webhooks-controller.php

示例5: data_provider_test_wc_is_valid_url

 /**
  * Data provider for test_wc_is_valid_url.
  *
  * @since 2.4
  */
 public function data_provider_test_wc_is_valid_url()
 {
     return array(array(false, wc_is_valid_url('google.com')), array(false, wc_is_valid_url('ftp://google.com')), array(false, wc_is_valid_url('sftp://google.com')), array(false, wc_is_valid_url('https://google.com/test invalid')), array(true, wc_is_valid_url('http://google.com')), array(true, wc_is_valid_url('https://google.com')), array(true, wc_is_valid_url('https://google.com/test%20valid')), array(true, wc_is_valid_url('https://google.com/test-valid/?query=test')), array(true, wc_is_valid_url('https://google.com/test-valid/#hash')));
 }
开发者ID:bitoncoin,项目名称:woocommerce,代码行数:9,代码来源:conditional-functions.php


注:本文中的wc_is_valid_url函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。