PHP code example of moderntribe / square1-request
1. Go to this page and download the library: Download moderntribe/square1-request library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
moderntribe / square1-request example snippets
class My_Cool_Class {
protected $request;
public function __construct( Request $request ) {
$this->request = $request;
}
}
$content_type = $this->request->header('Content-Type');
@return \WP_Query
$query = $this->request->query();
$posts = $query->found_posts;
@return array
$headers = $this->request->headers();
echo $headers['Content-Type'];
@param string $key
@return string
$content_type = $this->request->header('Content-Type');
@param string $key
@return mixed
$foobar = $this->request->input('foobar');
@return array
$all_input = $this->request->all();
@param array $keys
@return array
$keys = [ 'foo', 'bar', 'bash' ];
$values = $this->request->only( $keys );
@param array $keys
@return array
$keys = [ 'foo', 'bar' ];
$values = $this->request->except( $keys );
@param string $key
@return bool
$has_foobar = $this->request->has('foobar');
if ( $has_foobar ) {
// do thing.
}
@param string $key
@return bool
$foobar_filled = $this->request->filled('foobar');
if ( $foobar_filled ) {
// do thing.
}
@param bool $g
// URL is http://foobar.com/page/here?foo=bar
$path = $this->request->path();
echo $path;
// /page/here
$path_with_params = $this->request->path( true );
echo $path_with_params;
// /page/here?foo=bar
@return string
// URL is http://foobar.com/page/here?foo=bar
$url = $this->request->url();
echo $url;
// http://foobar.com
@return string
// is http://foobar.com/page/here?foo=bar
$full_url = $this->request->full_url();
echo $full_url;
// http://foobar.com/page/here?foo=bar
@param string $path
@return bool
// URL is http://foobar.com/page/here?foo=bar
$is_page = $this->request->is('page/here');
// true
$is_page = $this->request->is('page/*');
// true
$is_page = $this->request->is('page');
// false