PHP code example of maneuver / channel

1. Go to this page and download the library: Download maneuver/channel 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/ */

    

maneuver / channel example snippets




$channel = new \Maneuver\Channel([
  'uri' => 'http://example.com/wp-json/wp/v2/',
  'username' => 'your-username',
  'password' => 'your-password',
]);

$channel = new \Maneuver\Channel([
  'uri' => 'http://example.com/wp-json/wp/v2/',
  'token' => 'your-token',
]);

$posts = $channel->getPosts();

echo count($posts);

$post = $channel->getPost(1);

echo $post->excerpt;

$pages = $channel->getPages();

foreach ($pages as $page) {
  echo $page->title;
}

$page = $channel->getPage(1);

echo $page->content;

$taxonomies = $channel->getTaxonomies();

$taxonomy = $channel->getTaxonomy('category'); // use singular taxonomy name

// Then you can retrieve its terms:
$terms = $taxonomy->terms();

$terms = $channel->get('categories'); // use plural taxonomy name

$users = $channel->getUsers();

echo $users[0]->name;

$media = $channel->getMedia();

add_action('init', function(){

  register_post_type('product', [
    'labels' => [
      'name'          => 'Products',
      'singular_name' => 'Product',
    ],
    'public'        => true,
    'show_in_rest'  => true,
    'rest_base'     => 'products' // defaults to the post type slug, 'product' in this case
  ]);

});

$products = $channel->get('products'); // Pass in the 'rest_base' of the custom post type.

$post_types = $channel->get('types');
$latest = $channel->get('posts?per_page=5');

$latest = $channel->get('posts?per_page=5', [
  'proxy' => 'tcp://localhost:8125',
]);

class MyPost extends \Maneuver\Models\Post {
  public function fullTitle() {
    return 'Post: ' . $this->title;
  }
}

class MyPage extends \Maneuver\Models\Page {

}

$channel->setCustomClasses([
  // 'type' => 'ClassName'
  // eg: 'user' => 'MyUser'
  // or:
  'post'    => 'MyPost',
  'page'    => 'MyPage',
  'product' => 'MyPost', // custom post type
]);

$post = $channel->getPost(1);

echo $post->fullTitle();

echo get_class($post);
// => 'MyPost'