Пример #1
0
/**
 * Callback for the ingot shortcode
 *
 * @since 0.0.4
 *
 * @param $atts
 *
 * @return string
 */
function ingot_shortcode($atts)
{
    $html = '';
    $atts = shortcode_atts(array('id' => 0), $atts, 'ingot');
    if (0 != $atts['id']) {
        $html = ingot_click_test($atts['id']);
    }
    return $html;
}
Пример #2
0
 /**
  * Check if session has been used
  *
  * @since 0.3.0
  *
  * @param \WP_REST_Request $request Full data about the request.
  *
  * @return \WP_Error|\WP_REST_Response
  */
 public function session($request)
 {
     $session = $this->get_session_by_url_params($request);
     if (ingot_is_no_testing_mode()) {
         $data['ingot_ID'] = $session['ingot_ID'];
         $data['tests'] = [];
         $data['session_ID'] = $session['ID'];
         return $data;
     }
     $tests = [];
     if (!is_array($session)) {
         return $session;
     } else {
         if (\ingot\testing\crud\session::is_used($session['ID'])) {
             $new_session_args = [];
             if (0 != $request->get_param('ingot_id')) {
                 $new_session_args['ingot_ID'] = $request->get_param('ingot_id');
             } elseif (0 < absint($session['ingot_ID'])) {
                 $new_session_args['ingot_ID'] = $session['ingot_ID'];
             }
             if (0 != get_current_user_id()) {
                 $new_session_args['uID'] = get_current_user_id();
             }
             $data['session_ID'] = \ingot\testing\crud\session::create($new_session_args, true);
             if (is_numeric($data['session_ID'])) {
                 $session = \ingot\testing\crud\session::read((int) $data['session_ID']);
                 if (!empty($request->get_param('test_ids'))) {
                     foreach ($request->get_param('test_ids') as $variant_id) {
                         $html = '';
                         if (is_array($group = group::get_by_variant_id($variant_id))) {
                             $html = ingot_click_test($group);
                         }
                         $tests[] = ['html' => $html, 'ID' => $variant_id];
                     }
                 }
             }
         } else {
             \ingot\testing\crud\session::mark_used($session['ID']);
             $data['session_ID'] = $session['ID'];
         }
         $data['ingot_ID'] = $session['ingot_ID'];
         $data['tests'] = $tests;
         return rest_ensure_response($data);
     }
 }
Пример #3
0
 /**
  * Get a variant's HTML
  *
  * @since 0.4.0
  *
  * @param \WP_REST_Request $request Full data about the request.
  * @return \WP_Error|\WP_REST_Request
  */
 public function get_item($request)
 {
     return $this->not_yet_response();
     $context = $request->get_param('context');
     $url = $request->get_url_params();
     $id = helpers::v('ID', $url, 0);
     if (0 == absint($id) || !is_array(\ingot\testing\crud\variant::read($id))) {
         return new \WP_Error('ingot-invalid-test');
     } elseif ('context' != 'view') {
         return new \WP_Error('ingot-test-context-invalid');
     } else {
         if ('view' == $context) {
             $test = \ingot\testing\crud\variantP::read($id);
             $html = ingot_click_test($test);
             return ingot_rest_response($html);
         }
     }
 }