PHP Classes

WP Post: Classes to manipulate WordPress posts and images

Recommend this page to a friend!
  Info   View files Example   View files View files (8)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 44 This week: 1All time: 10,760 This week: 560Up
Version License PHP version Categories
wp-post 1.0.0MIT/X Consortium ...5PHP 5, Graphics, Content management, B...
Description 

Author

This package provides classes to manipulate WordPress posts and images.

It provides classes that call WordPress built-in functions to perform actions with posts and images.

Currently, it can:

- Create new post

- Get post URL by post identifier

- Submit an image to WordPress from the uploaded file

- Submit an image to WordPress from an image URL

- Get WordPress image URL by identifier

Innovation Award
PHP Programming Innovation award nominee
November 2022
Number 6
WordPress is a popular content management system written in PHP, often used to create blogs.

WordPress code is, in great part, made of code written using global functions.

This package provides a object-oriented wrapper to access functionality of WordPress that manipulates posts and images.

This way, it can please developers that prefer to write code to access WordPress content using classes of objects.

Manuel Lemos
Picture of Chun-Sheng, Li
  Performance   Level  
Name: Chun-Sheng, Li <contact>
Classes: 27 packages by
Country: Taiwan Taiwan
Age: 30
All time rank: 22646 in Taiwan Taiwan
Week rank: 416 Up1 in Taiwan Taiwan Up
Innovation award
Innovation award
Nominee: 13x

Winner: 1x

Example

<?php

/*
* This is the main PHP file.
* It call the Post.php and UploadImg.php
* And it will automatically do the post via WordPress API.
* The post content example:
* <h2>This is the test post via WordPress API</h2>
* <img class="alignnone size-medium wp-image-24" src="https://ahong.space/wp-content/uploads/2017/09/21271347_1587217494679206_4543010444411136718_n-300x300.jpg" alt="" width="300" height="300" />
* <p>description1</p>
* <p>description2</p>
* <p>description3</p>
*/

// show the runtime error
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

// include the Post and UploadImg class
require_once __DIR__.'/src/autoloader.php';

date_default_timezone_set('Asia/Taipei');

use
peter\WordPress\Post;
use
peter\WordPress\UploadImg;

$title = 'Test post';
$content = '<h2>This is the test post via WordPress API</h2>';
$postName = '';
$category = [];

$post = new Post($title, $content, $postName, $category);
$uploadInfo = [
   
'name' => ['https://scontent.ftpe7-1.fna.fbcdn.net/v/t1.0-9/14470520_1205931849474441_6469649795938442695_n.jpg?oh=e8e4245c44bf81fd6c02b779173a3913&oe=5A4C0FD7'],
   
'title' => ['image1'],
   
'content' => ['content1'],
   
'type' => ['image/jpeg'],
];

$upload = new UploadImg($uploadInfo);

// call the UploadImg class to upload the images.
$resultSet = $upload->uploadImageByUrl();

foreach(
$resultSet as $value) {
    if((int)
$value >= 0) {
        echo
'The image id is: '.$value.PHP_EOL;
    } else {
        echo
$value.PHP_EOL;
    }
}

/*
echo PHP_EOL;

// call the Post class to post the feeds.
/*
if($post->postFeed() === 'Post feed is successful.') {
    echo 'The post id is: '.$post->getId().PHP_EOL;
}
*/


Details

wp-post

Introduction

This helper class helps you accessing WordPress functions to post the feed easily.

You can also check out the `main.php` and the PHP file which is in the `src` folder to know more details.

The files introduction

You can see the `main.php` to know more details about using this classes.

  • 
    
  • 
    

Usage

  • using ssh to login your VPS or shared hosting server.
  • 
    
  • using the ```git clone https://github.com/peter279k/wp-post``` to clone this repo.
  • In ```main.php```, modify the title and content on line 27.
  • using the ```php main.php``` to test the posting feed and uploading images.

  Files folder image Files  
File Role Description
Files folder imagesrc (1 file, 1 directory)
Accessible without login Plain text file .editorconfig Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file main.php Example Example script
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imagepeter (1 directory)
  Accessible without login Plain text file autoloader.php Aux. Auxiliary script

  Files folder image Files  /  src  /  peter  
File Role Description
Files folder imageWordPress (3 files)

  Files folder image Files  /  src  /  peter  /  WordPress  
File Role Description
  Plain text file Post.php Class Class source
  Plain text file UploadImg.php Class Class source
  Plain text file Valid.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:44
This week:1
All time:10,760
This week:560Up