ﯽﻧﺎﺳﺭ ﺯﻭﺭ ﻪﺑ ﻭ ﺩﺎﺠﯾﺍ - PHP ﺎﺑ ﺱﺮﭘﺩﺭﻭ ﯼﺎﻫ ﺖﺴﭘ ﺖﯾﺮﯾﺪﻣ


  1. <span>1. ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ ﺱﺮﭘﺩﺭﻭ ﺕﺎﺤﻔﺻ ﻭ ﺎﻫ ﺖﺴﭘ ﺩﺎﺠﯾﺍ PHP – 101 ﺵﺯﻮﻣﺁ
  2. 2. ﻥﺪﻧﺍﻮﺧ ﻝﺎﺣ ﺭﺩ: ﺎﺑ ﺱﺮﭘﺩﺭﻭ ﯼﺎﻫ ﺖﺴﭘ ﺖﯾﺮﯾﺪﻣ PHP – ﯽﻧﺎﺳﺭ

.ﻢﯿﻨﮐ ﺩﺎﺠﯾﺍ ﺩﺎﻤﺘﻋﺍ ﻞﺑﺎﻗ ﺖﯾﺎﻬﻧ ﺭﺩ ﻭ ﯼﻮﻗ PHP Wrapper ﺱﻼﮐ ﮏﯾ ﺎﺗ ﻢﯿﻫﺩ ﺵﺮﺘﺴﮔ ﻡﺩﺍﺩ ﺭ

.(!ﺩﻮﺑ ﯽﻧﻻﻮﻃ ﯽﻤﮐ ﻪﻟﺎﻘﻣ ﺩﻮﺧ ﺭﺩ ﻢﯿﻘﺘﺴﻣ ﻥﺪﻧﺎﺒﺴﭼ ﯼﺍﺮﺑ) ﺪﯿﻨﮐ ﺍﺪﯿﭘ ﻦﻣ Github ﻥﺯﺎﺨﻣ ﺯ

ﻢﯿﺳﺮﺑ ﻥﺁ ﻪﺑ ﻢﯿﻫﺍﻮﺧ ﯽﻣ ﻪﭽﻧﺁ:

  • .PHP ﺪﯿﻟﻮﺗ ﻪﺟﺭﺩ ﺭﺩ ﺩﺎﻤﺘﻋﺍ ﻞﺑﺎﻗ ﻭ ﯼﺩﺮﺑﺭﺎﮐ ﻼًﻣﺎﮐ ﺏﻮﭼﺭﺎﭼ ﮏﯾ
  • .ﺪﯿﺷﺎﺑ ﺩﻮﺟﻮﻣ ﻞﺒﻗ ﺯﺍ ﯼﺎﻫ ﺖﺴﭘ ﯽﻧﺎﺳﺭ ﺯﻭﺭ ﻪﺑ ﻭ ﺖﯾﺮﯾﺪﻣ ﻦﯿﻨﭽﻤﻫ ﻪﮑﻠﺑ ،ﺖﺴﭘ ﺩﺎﺠﯾﺍ ﺎﻬﻨﺗ
  • .ﮓﻠﺳﺍ ﺎﯾ ﻥﺍﻮﻨﻋ ؛ﻪﺳﺎﻨﺷ .ﺪﯿﺷﺎﺑ ﺎﻬﻧﺁ ﻂﺳﻮﺗ ﺎﻫ ﺖﺴﭘ ﯼﺭﺎﮑﺘﺳﺩ ﻭ ﻮﺠﺘﺴﺟ ﻪﺑ ﺭﺩﺎﻗ

ﻡﺎﮔ ﻪﺑ ﻡﺎﮔ ﯼﺎﻤﻨﻫﺍﺭ ﻭ ﻩﺩﺎﻔﺘﺳﺍ ﺕﺎﮑﻧ :ﺩﻮﺑ ﺪﻫﺍﻮﺧ ﺶﺨﺑ 2 ﯼﺍﺭﺍﺩ ﻪﻟﺎﻘﻣ ﻦﯾﺍ.

!ﻢﯿﻨﮐ ﻉﻭﺮﺷ ﺪﯿﯾﺎﯿﺑ ،ﯼﺍ ﻪﻣﺪﻘﻣ ﭻﯿﻫ ﻥﻭﺪﺑ

ﻩﺩﺎﻔﺘﺳﺍ

.ﺖﺷﺍﺩ ﻢﯿﻫﺍﻮﺧ ﻞﯾﺎﻓ ﻦﯾﺍ ﺭﺩ ﺩﻮﺟﻮﻣ ﯼﺎﻫﺪﮐ ﻪﺑ ﯽﻫﺎﮕﻧ ﺵﺯﻮﻣﺁ ﻦﯾﺍ ﻡﻭﺩ ﻪﻤﯿﻧ ﺭﺩ !ﺩﺮﮐ ﺪﻫﺍﻮﺨ

.ﺪﯿﻨﮐ ﯼﺯﺎﺳ ﻪﻧﻮﻤﻧ ﺮﯾﺯ ﺕﺭﻮﺻ ﻪﺑ ﺍﺭ ﺱﻼﮐ

$Poster = new PostController;

Post Controller ؟ﺪﺳﺭ ﯽﻣ ﺮﻈﻧ ﻪﺑ ﻩﺩﺎﺳ ﯽﻓﺎﮐ ﻩﺯﺍﺪﻧﺍ ﻪﺑ .ﺪﯿﺷﺎﺑ ﻩﺩﺮﮐ ﺍﺪﯿﭘ ﯽﻧﺎﺳﺭ ﺯﻭﺭ

ﺎﻫ ﯽﮔﮋﯾﻭ ﻢﯿﻈﻨﺗ

ﻥﺍﻮﻨﻋ

$Poster->set_title( 'The Title' );

ﭗﯾﺎﺗ

$Poster->set_type( 'page' );

ﺍﻮﺘﺤﻣ

$Poster->set_content( '<h1>This is my awesome new post!</h1>' );

ﻩﺪﻨﺴﯾﻮﻧ

$Poster->set_author_id( 12 );

Slug/"Name"

$Poster->set_post_slug( "new_slug" );

(ﺕﺎﺤﻔﺻ ﻂﻘﻓ) ﻮﮕﻟﺍ

$Poster->set_page_template( 'fullwidth_page.php' );

ﺖﻟﺎﯾﺍ

[ ‘draft’ | ‘publish’ | ‘pending’| ‘future’ | ‘private’ | custom registered status ]
$Poster->set_post_state( "pending" );

ﻥﺩﺮﻛ ﺩﺎﺠﻳﺍ

؛ﺪﯿﻫﺩ ﻡﺎﺠﻧﺍ ﺍﺭ ﺭﺎﮐ ﻦﯾﺍ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﺮﯾﺯ ﺪﮐ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ .ﺖﺳﺍ ﻥﺍﻮﻨﻋ ﻪﻋﻮﻤﺠﻣ ﻦﺘﺷﺍﺩ

$Poster->set_title( "New Post" );

.ﺪﯿﻨﮐ ﺍﺮﺟﺍ ﺍﺭ ﺩﺎﺠﯾﺍ ﺪﺘﻣ ﯽﮔﺩﺎﺳ ﻪﺑ ،ﻢﯿﻈﻨﺗ ﺯﺍ ﺲﭘ

$Poster->create();

ﻪﺟﻮﺗ: ﯽﻣ ﯽﺳﺭﺮﺑ ﺵﻭﺭ ﻦﯾﺍﺩﺭﺍﺩ ﺩﻮﺟﻭ ﻡﺎﻧ ﻦﯿﻤﻫ ﺎﺑ ﯼﺮﮕﯾﺩ ﺖﺴﭘ ﺎﯾ

ﻥﺩﺮﮐ ﻮﺠﺘﺴﺟ

.ﻢﯿﻨﮐ ﺍﺪﯿﭘ ﻮﺠﺘﺴﺟ ﻊﺑﺎﺗ ﺎﺑ ﺍﺭ ﻥﺁ ﺪﯾﺎﺑ ﺍﺪﺘﺑﺍ ،ﻢﯿﻨﮐ ﺯﻭﺭ ﻪﺑ ﺍﺭ ﺩﻮﺟﻮﻣ ﺖﺴﭘ ﮏﯾ ﻢﯿﻧﺍﻮﺘﺑ

.ﻢﯿﻨﮐ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﻮﺠﺘﺴﺟ ﺵﻭﺭ ﺯﺍ ﺭﺎﮐ ﻦﯾﺍ ﯼﺍﺮﺑ

$Poster->search( 'SEARCH_BY' , 'DATA' );

.ﻮﺠﺘﺴﺟ ﯼﺍﺮﺑ ﯼﺍ ﻩﺩﺍﺩ ﻭ ﻮﺠﺘﺴﺟ ﯼﺍﺮﺑ ﯽﮔﮋﯾﻭ ،ﺩﺮﯾﺬﭘ ﯽﻣ ﺍﺭ ﺮﺘﻣﺍﺭﺎﭘ 2 ﺵﻭﺭ ﻦﯾﺍ

.ﺪﯿﻨﮐ ﻮﺠﺘﺴﺟ ﻥﺍﻮﻨﻋ ﺱﺎﺳﺍ ﺮﺑ ﺪﯿﻧﺍﻮﺗ ﯽﻣ

$Poster->search( 'title' , 'DATA' );

.ﺪﯿﻨﮐ ﻮﺠﺘﺴﺟ ID ﺎﺑ ﺪﯿﻧﺍﻮﺗ ﯽﻣ

$Poster->search( 'id' , 'DATA' );

.ﺪﯿﻨﮐ ﻮﺠﺘﺴﺟ slug ﺎﺑ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﻭ

$Poster->search( 'slug' , 'DATA' );

.ﺪﯿﻫﺩ ﺶﯾﺎﻤﻧ ﻭ ﺪﯾﺮﯿﮕﺑ ﺱﺎﻤﺗ ﺮﯾﺯ ﺪﮐ ﺎﺑ ﺪﯿﻧﺍﻮﺗ ﯽﻣ .ﺩﻮﺷ ﯽﻣ ﻪﻓﺎﺿﺍ $errors

$error = $Poster->get_var( 'errors' );
$Poster->PrettyPrint( $error );

ﯽﻧﺎﺳﺭ ﺯﻭﺭ ﻪﺑ

.ﺪﯿﻨﮐ ﯽﻧﺍﻮﺧﺍﺮﻓ ﺍﺭ ﯽﻧﺎﺳﺭ ﺯﻭﺭ ﻪﺑ ﺵﻭﺭ ﯽﮔﺩﺎﺳ ﻪﺑ ،ﺎﻫ ﯽﮔﮋﯾﻭ ﻢﯿﻈﻨﺗ ﺯﺍ ﺲﭘ .ﺪﯿﻫﺩ ﺹﺎﺼﺘﺧﺍ

$Poster->update();

.ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺮﯾﺯ ﺪﮐ ﺯﺍ ،(ID=1) ﺪﯿﻫﺩ ﺮﯿﯿﻐﺗ ﺍﺭ 1 ﺖﺴﭘ ﻥﺍﻮﻨﻋ ﺪﯿﻫﺍﻮﺧ ﯽﻣ ﺮﮔﺍ ،ﻝﺎﺜ

$Poster->search( 'id', 1 );
$Poster->set_title( 'New Title' );
$Poster->update();

.ﺩﺮﮐ ﺯﻭﺭ ﻪﺑ ﻖﯾﺮﻃ ﻦﯾﺍ ﺯﺍ ﻥﺍﻮﺗ ﯽﻣ ﺍﺭ ﺎﻫ ﯽﮔﮋﯾﻭ ﻡﺎﻤﺗ

ﺎﻫﺮﯿﻐﺘﻣ ﯽﺑﺎﯾﺯﺎﺑ

.ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ get_vars ﺪﺘﻣ ﺯﺍ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﻩﺪﺷ ﻒﯾﺮﻌﺗ ﯼﺎﻫﺮﯿﻐﺘﻣ ﯽﺑﺎﯾﺯﺎﺑ ﯼﺍﺮﺑ

$Poster->get_var( 'title' );    // Returns the title (if you have set it)
$Poster->get_var( 'type' );     // Returns the post type (if you have set it)
$Poster->get_var( 'content' );  // Returns the content (if you have set it)
$Poster->get_var( 'category' ); // Returns the category as an array (if set)
$Poster->get_var( 'template' ); // Returns the template (if you have set it)
$Poster->get_var( 'slug' );     // Returns the slug (if you have set it)
$Poster->get_var( 'auth_id' );  // Returns the author id (if you have set it)
$Poster->get_var( 'status' );   // Returns the post's status (if you have set it)
$Poster->get_var( 'errors' );   // Returns the errors array

/** AFTER YOU HAVE EITHER CREATED A POST OR SUCCESSFULLY SEARCHED FOR ONE YOU CAN USE THESE **/

	// Returns the a PHP Object of the post. This can be used to check if the search method was successful
	$Poster->get_var( 'current_post' );

	// Returns the selected post's ID (integer).
	$Poster->get_var( 'current_post_id' );

	// Returns the URL permalink of the selected post
	$Poster->get_var( 'current_post_permalink' );

.ﺪﯿﯾﻮﮕﺑ ﻦﻣ ﻪﺑ Github ﺭﺩ ﻥﺁ ﺩﺭﻮﻣ ﺭﺩ ﺎًﻔﻄﻟ ،ﺪﯾﺩﺮﮐ ﺍﺪﯿﭘ ﯽﻟﺎﮑﺷﺍ ﺮﮔﺍ .ﺪﯿﺳﺮﭙﺑ ﻦﻣ ﺯﺍ ﺎ

؟ﺪﯿﺘﺴﻫ ﻩﺩﺎﻣﺁ ﻡﻭﺩ ﺖﻤﺴﻗ ﯼﺍﺮﺑ

ﻡﺎﮔ ﻪﺑ ﻡﺎﮔ ﯼﺎﻤﻨﻫﺍﺭ :ﺱﻼﮐ ﺖﺧﺎﺳ


.ﻢﯾﺩﺮﮔﺮﺑ ﺍﺪﺘﺑﺍ ﻪﺑ ﺪﯿﻫﺩ ﻩﺯﺎﺟﺍ ،ﻢﯾﺪﯾﺩ ﺍﺭ ﺱﻼﮐ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﻩﻮﺤﻧ ﻥﻮﻨﮐﺍ

class PostController {

. . . class functions go here . . .

}

.ﻢﯿﻨﮐ ﻡﻼﻋﺍ ﺍﺭ ﺩﺮﮐ ﻢﯿﻫﺍﻮﺧ ﻩﺩﺎﻔﺘﺳﺍ ﻪﮐ ﺍﺭ ﯽﯾﺎﻫﺮﯿﻐﺘﻣ ﻪﻤﻫ ﻪﮐ ﺖﺳﺍ ﻦﯾﺍ ﺎﻣ ﯼﺎﻫﺭﺎﮐ ﺖﺴﯿﻟ

// Variables for Post Data
public $PC_title;
public $PC_type;
public $PC_content;
public $PC_category;
public $PC_template;
public $PC_slug;
public $PC_auth_id;
public $PC_status = "publish";

// Variables for Post Updating
public $PC_current_post;
public $PC_current_post_id;
public $PC_current_post_permalink;

// Error Array
public $PC_errors;

.ﻢﯿﻨﮐ ﻩﺮﯿﺧﺫ ﺍﺭ ﻥﺁ ﻢﯿﻧﺍﻮﺘﺑ ﻢﯿﻫﺍﻮﺧ ﯽﻣ ﻪﮐ ﺖﺳﺍ ﯽﯾﺎﻫ ﻩﺩﺍﺩ ﺯﺍ ﯽﺘﺴﯿﻟ ﺎﺠﻨﯾﺍ ﺭﺩ ،ﺪﯿﻧﺰﺑ

  1. ﻥﺍﻮﻨﻋ
  2. (ﻩﺮﯿﻏ ﻭ ﺖﺴﭘ/ﻪﺤﻔﺻ) ﻉﻮﻧ
  3. ﺍﻮﺘﺤﻣ
  4. ﺎﻫ ﯼﺪﻨﺑ ﻪﺘﺳﺩ/ﻪﺘﺳﺩ
  5. ﻪﺤﻔﺻ ﺐﻟﺎﻗ
  6. ﻥﺩﺮﮐ ﺖﮐﺮﺣ ﻥﻭﺰﻠﺣ
  7. ﻭ ﻩﺪﻨﺴﯾﻮﻧ ﻪﺳﺎﻨﺷ
  8. (ﺲﯾﻮﻧ ﺶﯿﭘ/ﻩﺪﺷ ﺮﺸﺘﻨﻣ ﻝﺎﺜﻣ ﻥﺍﻮﻨﻋ ﻪﺑ) ﺖﺴﭘ ﺖﯿﻌﺿﻭ

.ﺪﻧﺭﺍﺩﯽﻣ ﻪﮕﻧ ﺍﺭ ﺩﻮﺟﻮﻣ ﺖﺴﭘ ﻪﺑ ﻁﻮﺑﺮﻣ ﯼﺎﻫﻩﺩﺍﺩ ﻥﺁ Permalink ﻭ Post ID ﯼﺎ

.ﺪﯿﻫﺩ ﺮﯿﯿﻐﺗ ﺰﯿﻧ ﺍﺭ()get_var ﻊﺑﺎﺗ ﺪﻧﻮﺸﯿﭘ ﻪﮐ ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﺩﺎﯾ ﻪﺑ ﺪﯾﺩﺍﺩ ﺮﯿﯿﻐﺗ ﺍﺭ

.ﻢﯾﺯﺍﺩﺮﭙﺑ ﺩﻮﺧ ﺩﺮﮑﻠﻤﻋ ﻦﯿﻟﻭﺍ ﻪﺑ ﺪﯿﯾﺎﯿﺑ ،ﻢﯾﺩﺮﮐ ﻢﯿﻈﻨﺗ ﺍﺭ ﺰﯿﭼ ﻪﻤﻫ ﻪﮐ ﻥﻮﻨﮐﺍ ،ﺖﺳﺭﺩ

// Creation functions
public function create() {

	if ( isset( $this->PC_title ) ) {

		if ( $this->PC_type == 'page' ) {
			$post = get_page_by_title( $this->PC_title, 'OBJECT', $this->PC_type );
		} else {
			$post = get_page_by_title( $this->PC_title, 'OBJECT', $this->PC_type );
		}

		$post_data = array(
			'post_title'    => wp_strip_all_tags($this->PC_title),
			'post_name'     => $this->PC_slug,
			'post_content'  => $this->PC_content,
			'post_status'   => $this->PC_status,
			'post_type'     => $this->PC_type,
			'post_author'   => $this->PC_auth_id,
			'post_category' => $this->PC_category,
			'page_template' => $this->PC_template
		);

		if ( ! isset( $post ) ) {
			$this->PC_current_post_id        = wp_insert_post( $post_data, $error_obj );
			$this->PC_current_post           = get_post( ( integer ) $this->PC_current_post_id, 'OBJECT' );
			$this->PC_current_post_permalink = get_permalink( ( integer ) $this->PC_current_post_id );
			return $error_obj;
		} else {
			$this->update();
			$this->errors[] = 'That page already exists. Try updating instead. Control passed to the update() function.';
			return FALSE;
		}

	} else {
		$this->errors[] = 'Title has not been set.';
		return FALSE;
	}
}

.ﺩﻮﺷ ﯽﻣ ﺍﺮﺟﺍ ﻪﻠﺻﺎﻓﻼﺑ ،ﺱﺮﭘﺩﺭﻭ ﺮﺳ ﻪﺑ ﻊﺑﺎﺗ ﻥﺩﺮﮐ ﻪﻓﺎﺿﺍ ﯼﺎﺟ ﻪﺑ ﻪﮐ ﺖﺳﺍ ﻦﯾﺍ ﻊﺑﺎﺗ ﺩﻮﺧ

.ﺩﻮﺷﯽﻣ ﻪﻓﺎﺿﺍ $errors ﻪﯾﺍﺭﺁ ﻪﺑ ﯽﻣﺎﯿﭘ ،ﺩﺭﺍﺩ ﺩﻮﺟﻭ ﯽﻠﮑﺸﻣ ﺮﮔﺍ

.ﺪﯿﻨﮐ ﯽﺳﺭﺮﺑ ﺩﺭﻮﻣ ﻦﯾﺍ ﺭﺩ ﺍﺭ ﻦﻣ 101 ﻪﻟﺎﻘﻣ ﻢﻨﮐ ﯽﻣ ﻪﯿﺻﻮﺗ ،ﺪﯿﺘﺴﻫ ﺞﯿﮔ ﯽﻤﮐ ﺮﮔﺍ :ﺩﻮﺑ ﻊ

.ﻢﯿﻫﺩ ﻪﻣﺍﺩﺍ ﺪﯿﯾﺎﯿﺑ ،ﺪﯿﺘﺴﻫ ﻦﻣ ﺎﺑ ﺯﻮﻨﻫ ﻪﮐ ﺎﻤﺷ ﻪﻤﻫ ﯼﺍﺮﺑ

// SET POST'S TITLE
public function set_title( $name ) {
	$this->PC_title = $name;
	return $this->PC_title;
}

// SET POST'S TYPE
public function set_type( $type ) {
	$this->PC_type = $type;
	return $this->PC_type;
}

// SET POST'S CONTENT
public function set_content( $content ) {
	$this->PC_content = $content;
	return $this->PC_content;
}

// SET POST'S AUTHOR ID
public function set_author_id( $auth_id ) {
	$this->PC_auth_id = $auth_id;
	return $this->PC_auth_id;
}

// SET POST'S STATE
public function set_post_state( $content ) {
	$this->PC_status = $content;
	return $this->PC_status;
} 

.ﺩﺭﺍﺩ ﺩﻮﺟﻭ (ﻥﺎﻨﯿﻤﻃﺍ ﺖﯿﻠﺑﺎﻗ ﻥﺪﻧﺎﺳﺭ ﺮﺜﮐﺍﺪﺣ ﻪﺑ ﯼﺍﺮﺑ) ﺎﻬﻧﺁ ﯼﺎﻫ ﯼﺩﻭﺭﻭ ﺪﯿﯾﺄﺗ ﯼﺍﺮﺑ ﺭﺎ

// SET POST SLUG
public function set_post_slug( $slug ) {

	$args = array('name' => $slug);
	$posts_query = get_posts( $args );

	if ( ! get_posts( $args ) && ! get_page_by_path( $this->PC_slug ) ) {

		$this->PC_slug = $slug;
		return $this->PC_slug;

	} else {
		$this->errors[] = 'Slug already in use.';
		return FALSE;
	}

}

// SET PAGE TEMPLATE
public function set_page_template( $content ) {

	if ( $this->PC_type == 'page' ) {
		$this->PC_template = $content;
		return $this->PC_template;
	} else {
		$this->errors[] = 'You can only use template for pages.';
		return FALSE;
	}

}

// ADD CATEGORY IDs TO THE CATEGORIES ARRAY
public function add_category( $IDs ){

	if ( is_array( $IDs ) ) {
		foreach ( $IDs as $id ) {
			if ( is_int( $id ) ) {
				$this->PC_category[] = $id;
			} else {
				$this->errors[] = '<b>' .$id . '</b> is not a valid integer input.';
				return FALSE;
			}
		}
	} else {
		$this->errors[] = 'Input specified in not a valid array.';
		return FALSE;

	}

}

.ﺪﻨﺘﺴﻫ ﻢﻬﻣ ﺭﺎﯿﺴﺑ ﮎﺎﻨﺘﺸﺣﻭ ﯼﺎﻫﺎﻄﺧ ﺯﺍ ﯼﺮﯿﮔﻮﻠﺟ ﯼﺍﺮﺑ ﺎﻣﺍ ،ﺪﻨﺘﺴﻫ ﺮﺗ ﻩﺪﯿﭽﯿﭘ ﯽﻤﮐ ﺮﺧﺁ ﺩ

set_post_slug()

.ﺪﯿﻨﮐ ﺏﺎﻨﺘﺟﺍ ﻥﺁ ﺯﺍ ﺖﺳﺍ ﺮﺘﻬﺑ ﻥﺎﮑﻣﺍ ﺕﺭﻮﺻ ﺭﺩ ﻪﮐ ﺖﺳﺍ ﺪﻨﯾﺎﺷﻮﺧﺎﻧ ﺎًﻌﻗﺍﻭ ﯽﮕﺘﻔﺷﺁ ﮏﯾ ﻦﯾﺍ

Post Slug ﺪﺷﺎﺑ ﺩﺮﻓ ﻪﺑ ﺮﺼﺤﻨﻣ ﺪﯾﺎﺑ

.(ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﺍﺭ Boolean FALSE ﮏﯾ ﻊﺑﺎﺗ ﻦﯾﺍ) ﺖﺳﺍ ﻩﺪﺸﻧ ﻢﯿﻈﻨﺗ ﺮﯿﻐﺘﻣ ﻭ ﺩﻮﺷ

set_page_template() & add_category()

set_page_template() ﻪﺤﻔﺻ ﯼﻮﮕﻟﺍ ﮏﯾ (ﻞﮑﺷ ﻪﺑ my_page_tem

add_category() ﯽﻣ ﻥﺎﮑﻣﺍ ﺎﻤﺷ ﻪﺑﻪﯾﺍﺭﺁ ﺪﻫﺩﻪﺘﺳﺩ ﻪﺑ ﺍﺭ ﺢ

ﻥﺩﺮﮐﻮﺠﺘﺴﺟ

.ﺩﺮﮐ ﻢﯿﻫﺍﻮﺧ ﻩﺩﺎﻔﺘﺳﺍ search() ﻊﺑﺎﺗ ﺯﺍ ﺭﺎﮐ ﻦﯾﺍ ﯼﺍﺮﺑ .ﻢﯿﻨﮐ ﺍﺪﯿﭘ

// Search for Post function
public function search( $by, $data ) {

	switch ( $by ) {

	// SEARCH FOR POST USING IT'S ID
	case 'id' :
	
		if ( is_integer( $data ) && get_post( ( integer ) $data ) !== NULL ) {
			$this->PC_current_post           = get_post( ( integer ) $data, 'OBJECT' );
			$this->PC_current_post_id        = ( integer ) $data;
			$this->PC_current_post_permalink = get_permalink( (integer) $data );
			return TRUE;
		} else {
			$this->errors[] = 'No post found with that ID.';
			return FALSE;
		}

	break;

	case 'title' :

		$post = get_page_by_title( $data );

		if ( ! $post ) {
			$post = get_page_by_title( $data, OBJECT, 'post' );
		}

		$id = $post->ID;

		if ( is_integer($id) && get_post( (integer)$id) !== NULL ) {
			$this->PC_current_post           = get_post( (integer)$id, 'OBJECT' );
			$this->PC_current_post_id        = (integer) $id;
			$this->PC_current_post_permalink = get_permalink( (integer) $id );
			return TRUE;
		} else {
			$this->errors[] = 'No post found with that title.';
			return FALSE;
		}

		break;

		// SEARCH FOR POST USING IT'S SLUG
		case 'slug' :
		$args = array(
			'name'          => $data,
			'max_num_posts' => 1
		);
		$posts_query = get_posts( $args );
		if ( $posts_query ) {
			$id = $posts_query[0]->ID;
		} else {
			$this->errors[] = 'No post found with that slug.';
		}

		if ( is_integer($id) && get_post( (integer)$id) !== NULL ) {
			$this->PC_current_post           = get_post( (integer)$id, 'OBJECT' );
			$this->PC_current_post_id        = (integer)$id;
			$this->PC_current_post_permalink = get_permalink((integer)$id);
			return TRUE;
		} else {
			$this->errors[] = 'No post found with that slug.';
			return FALSE;
		}

		break;

		default:

		$this->errors[] = 'No post found.';
		return FALSE;

		break;

	}
}

.ﺩﺮﯾﺬﭘ ﯽﻣ ﺍﺭ ﺮﺘﻣﺍﺭﺎﭘ 2 ﻊﺑﺎﺗ .ﺪﯿﻨﮐ ﺍﺪﯿﭘ search()


«ﺱﺎﺳﺍﺮﺑ ﻮﺠﺘﺴﺟ» ﺭﺍﺪﻘﻣ .1

.ﻢﯿﻨﮐ ﯽﺳﺭﺮﺑ ﺮﺗﻖﯿﻗﺩ ﯽﻤﮐ ﺍﺭ ﻡﺍﺪﮐ ﺮﻫ ﺪﯿﯾﺎﯿﺑ

ﻪﺳﺎﻨﺷ ﺱﺎﺳﺍ ﺮﺑ ﻮﺠﺘﺴﺟ

!ﻩﺩﺎﺳ .ﺩﻮﺷ ﯽﻣ ﻩﺮﯿﺧﺫ ﻭ ﻩﺪﻧﺍﺩﺮﮔﺮﺑ (ﺩﻮﺷ ﯽﻣ ﻩﺮﯿﺧﺫ ﻪﮐ ﯽﻤﺋﺍﺩ ﺪﻧﻮﯿﭘ ﻭ ﻪﺳﺎﻨﺷ ﻦﯿﻨﭽﻤﻫ ﻭ)

ﻥﺍﻮﻨﻋ ﺱﺎﺳﺍ ﺮﺑ ﻮﺠﺘﺴﺟ

.ﺪﯾﺩ ﺪﯿﻫﺍﻮﺧ ﺍﺭ ﺪﮐ ﻦﯾﺍ :ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻪﺟﻮﺗ ﺎًﻔﻄﻟ .ﺪﯿﻨﮑﻧ ﻩﺩﺎﻔﺘﺳﺍ ﺵ

$post = get_page_by_title( $data );

if ( ! $post ) {
	$post = get_page_by_title( $data, OBJECT, 'post' );
}

.ﺩﻮﺷ ﺺﺨﺸﻣ "post" ﻥﺍﻮﻨﻋ ﻪﺑ ﻡﻮﺳ ﺮﺘﻣﺍﺭﺎﭘ ﻪﮑﻨﯾﺍ ﺮﮕﻣ ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﺍﺭ ﺕﺎﺤﻔﺻ ﻂﻘﻓ ،

.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ Not Found 404 ﯼﺎﻄﺧ ﻥﺁ ﺯﺍ ﺲﭘ .ﺩﻮﺷ ﺍﺮﺟﺍ ﺪﻧﺍﻮﺗﯽﻣ (ﻝﻭﺍ ﺭﺎﺑ) ﺭ

Slug ﺱﺎﺳﺍ ﺮﺑ ﻮﺠﺘﺴﺟ

!ﻥﺩﻮﺑ ﺭﺬﺣﺮﺑ .ﺪﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ ﺍﺭ ﯽﺗﻼﮑﺸﻣ ﻢﻫ ﺎﺑ Slug ﺮﯿﯿﻐﺗ ﻭ ﻮﺠﺘﺴﺟ ،ﻥﺍﻮﻨﻋ ﺱﺎﺳﺍ ﺮﺑ ﻮﺠ

ﺖﯾﺮﯾﺪﻣ ﻭ ﯽﻧﺎﺳﺭ ﺯﻭﺭ ﻪﺑ

ﺖﺳﺍ ﺖﺳﺭﺩ! ﯽﻣ ،ﺩﺭﺍﺪﻧ ﺩﻮﺟﻭ ﻮﺠﺘﺴﺟ ﻥﺎﮑﻣﺍ ﻪﮐ ﻥﻮﻨﮐﺍﻊﺑﺎﺗ ﻪﺑ ﻢﯿ

// Update Post
public function update(){
	if ( isset($this->PC_current_post_id ) ) {

		// Declare ID of Post to be updated
		$PC_post['ID'] = $this->PC_current_post_id;

		// Declare Content/Parameters of Post to be updated
		if ( isset($this->PC_title ) && $this->PC_title !== $this->PC_current_post->post_title ) {
			$PC_post['post_title'] = $this->PC_title;
		}

		if ( isset( $this->PC_type ) && $this->PC_type !== $this->PC_current_post->post_type ) {
			$PC_post['post_type'] = $this->PC_type;
		}

		if ( isset($this->PC_auth_id) && $this->PC_auth_id !== $this->PC_current_post->post_type ) {
			$PC_post['post_author'] = $this->PC_auth_id;
		}

		if ( isset($this->PC_status) && $this->PC_status !== $this->PC_current_post->post_status ) {
			$PC_post['post_status'] = $this->PC_status;
		}

		if ( isset($this->PC_category) && $this->PC_category !== $this->PC_current_post->post_category ) {
			$PC_post['post_category'] = $this->PC_category;
		}

		if ( isset($this->PC_template )
			&& $this->PC_template !== $this->PC_current_post->page_template
			&& ( $PC_post['post_type'] == 'page' || $this->PC_current_post->post_type == 'page' )
		) {
			PC_post['page_template'] = $this->PC_template;
		}

		if ( isset( $this->PC_slug ) && $this->PC_slug !== $this->PC_current_post->post_name ) {
			$args = array('name' => $this->PC_slug);
		}

		if ( ! get_posts( $args ) && !get_page_by_path( $this->PC_slug ) ) {
			$PC_post['post_name'] = $this->PC_slug;
		} else {
			$errors[] = 'Slug Defined is Not Unique';
		}

		if ( isset($this->PC_content) && $this->PC_content !== $this->PC_status->post_content ) {
			$PC_post['post_content'] = $this->PC_content;
		}

		wp_update_post( $PC_post );

	}

	return( $errors );
}

!ﺖﺳﺎﺒﯾﺯ ﺪﮐ ﻦﯾﺍ ﻪﮐ ﻢﻨﮐ ﻑﺍﺮﺘﻋﺍ ﺪﯾﺎﺑ ،ﻢﺘﺴﻫ ﻪﻧﺍﺭﺍﺪﺒﻧﺎﺟ ﯽﻤﮐ ﻦﻣ ﻪﭼﺮﮔﺍ .ﺪﺷﺎﺑ

.ﻢﯾﺭﺍﺩ ﺪﯿﻔﻣ ﯽﻣﻮﻤﻋ ﻊﺑﺍﻮﺗ ﺪﻨﭼ ﺎﻣ ،ﺖﯾﺎﻬﻧ ﺭﺩ .ﺖﺳﺍ update() ﯼﺍﺮﺑ ﺎ

ﯽﻓﺎﺿﺍ ﻊﺑﺍﻮﺗ

؛ﺪﯾﺯﺍﺪﻨﯿﺑ ﯽﻫﺎﮕﻧ .ﺪﯿﻨﮐ ﻪﻓﺎﺿﺍ ﺍﺭ ﻥﺎﻣﺯ ﺭﺩ ﯽﯾﻮﺟ ﻪﻓﺮﺻ/ﺪﯿﻔﻣ ﻊﺑﺎﺗ ﺪﻨﭼ ﻪﮐ ﺖﺳﺍ ﯽﺑﻮﺧ ﻩﺪﯾ

// General functions
public function get_content() {

	if ( isset( $this->PC_current_post->post_content ) ) {
		return $this->PC_current_post->post_content;
	}

}

public function get_var( $name ) {
	$name = 'PC_'.$name;
	if ( isset( $this->$name ) ) {
		return $this->$name;
	}
}

public function unset_all() {
	foreach ( get_class_vars(get_class($this)) as $name => $default ) {
		$this->$name = $default;
	}
}

public function __toString() {
	return 'Use the PrettyPrint function to return the contents of this Object. E.g;<pre>$my_post->PrettyPrintAll();</pre>';
}

public function PrettyPrint($data) {
	echo "<pre>";
	print_r( $data );
	echo "</pre>";
}

public function PrettyPrintAll() {
	echo "<pre>";
	print_r( $this );
	echo "</pre>";

}

؛ﻊﯾﺮﺳ ﺕﺎﺤﯿﺿﻮﺗ

  • get_content() : ﺩﺮﯾﺬﭘ ﯽﻤﻧ ﺍﺭ ﯼﺮﺘﻣﺍﺭﺎﭘ ﭻﯿﻫ ﻦﯾﺍ .(ﺖﺳﺍ ﻩﺪﺸﻧ ﻢﯿﻈﻨ
  • get_var( "var_name" ) : ﺯﺍ ﯽﺘﺴﯿﻟ ﺎﺠﻨﯾﺍ ﺭﺩ .ﺪﯿﻫﺍﻮﺧ ﯽﻣ ﻪﮐ ﯼﺮﯿﻐﺘ
  • "ﻥﺍﻮﻨﻋ" - ﺪﯾﺍ ﻩﺩﺮﮐ ﻦﯿﯿﻌﺗ ﻪﮐ ﯽﺘﺴﭘ ﻥﺍﻮﻨﻋ.
  • «ﻉﻮﻧ» - ﻩﺩﺮﮐ ﻢﯿﻈﻨﺗ ﻪﮐ ﯽﺘﺴﭘ ﻉﻮﻧﺪﯾﺍ.
  • «ﺍﻮﺘﺤﻣ» - ﻩﺩﺮﮐ ﻢﯿﻈﻨﺗ ﻪﮐ ﯽﯾﺍﻮﺘﺤﻣﺪﯾﺍ.
  • «ﻪﺘﺳﺩ» – ﻪﺘﺳﺩﻩﺩﺮﮐ ﻢﯿﻈﻨﺗ ﻪﮐ ﯽﯾﺎﻫﺪﯾﺍ (ﯽﻣﺮﺑ ﺍﺭ ﻪﯾﺍﺭﺁu2
  • "ﻮﮕﻟﺍ" - ﺪﯾﺍ ﻩﺩﺮﮐ ﻢﯿﻈﻨﺗ ﻪﮐ ﯼﺍ ﻪﺤﻔﺻ ﯼﻮﮕﻟﺍ.
  • "Slug" - Slug ﺪﯾﺍ ﻩﺩﺮﮐ ﻢﯿﻈﻨﺗ ﺎﻤﺷ ﻪﮐ.
  • "auth_id" - ﺪﯾﺍ ﻩﺩﺮﮐ ﻢﯿﻈﻨﺗ ﻪﮐ ﯼﺍ ﻩﺪﻨﺴﯾﻮﻧ ﻪﺳﺎﻨﺷ.
  • "ﺖﯿﻌﺿﻭ" - ﺪﯾﺍ ﻩﺩﺮﮐ ﻢﯿﻈﻨﺗ ﻪﮐ ﯽﺘﺴﭘ ﺖﯿﻌﺿﻭ.
  • "current_post" - WP Post Object ﺖﺸﮔﺮﺑ ﻮﺠﺘﺴﺟ ﺯﺍ ﺲﭘ.
  • «current_post_id» – ﺖﺴﭘ ﻪﺳﺎﻨﺷ WP ﺪﺷ ﻩﺪﻧﺍﺩﺮﮔﺮﺑ ﻮﺠﺘﺴﺟ ﺯﺍ ﺲﭘ.
  • «current_post_permalink» – ﺖﺑﺎﺛ ﺪﻧﻮﯿﭘ WP Post ﺖﺸﮔﺮﺑ ﻮﺠﺘﺴﺟ ﺯﺍ
  • 'errors' - Errors Array (ﺪﯿﻔﻣ ﺭﺎﯿﺴﺑ).
  • unset_all() : ﻥﺩﻮﺑ ﺭﺬﺣﺮﺑ .ﺪﻨﮐ ﯽﻣ ﻑﺬﺣ ﺍﺭ ﺱﻼﮐ ﻪﻧﻮﻤﻧ ﺭﺩ ﻩﺪﺷ ﻩﺮﯿﺧ
  • __toString() : ﺯﺍ .ﺪﺷ ﭖﺎﭼ ﺎﻄﺧ ﻡﺎﯿﭘ .ﺩﻮﺷ ﯽﻣ ﺍﺮﺟﺍ ﺩﻮﺷ ﯽﻣ ﭖﺎﭼ ﺱﻼ
// Start new class
$Poster = new PostController();

// Echoes error message
echo $Poster;
  • PrettyPrint(): ﻪﯾﺍﺭﺁ ﻭ ﺎﯿﺷﺍ ﻪﮐ ﺖﺳﺍ ﺪﯿﻔﻣ ﻊﺑﺎﺗ ﮏﯾ ﻂﻘﻓ ﻦﯾﺍﮓ
  • PrettyPrintAll(): ﻥﺎﻤﻫ ﻦﯾﺍ PrettyPrint() ﺰﺟ ﻪﺑ ،ﺖﺳﺍ «PrettyPr

!ﺖﺳﺍ ﯼﺪﻨﺑ ﻪﺘﺴﺑ ﮏﯾ ﻦﯾﺍ ﻭ

!ﺪﯿﺷﺎﺑ ﻪﺘﻓﺎﯾ ﺮﮕﻨﺷﻭﺭ ﻢﻫ ﻭ ﺪﯿﻔﻣ ﻢﻫ ﺍﺭ ﻥﺁ ﻪﮐ ﻡﺭﺍﻭﺪﯿﻣﺍ :ﻦﻣ ﻪﻟﺎﻘﻣ ﻥﺪﻧﺍﻮﺧ ﯼﺍﺮﺑ ﺎﻤﺷ ﺯ

.ﺪﯿﻨﮐ ﺡﺮﻄﻣ ﺮﯾﺯ ﺕﺍﺮﻈﻧ ﺶﺨﺑ ﺭﺩ ﺍﺭ ﺎﻬﻧﺁ ،ﺪﯾﺭﺍﺩ ﯽﻟﺍﻮﺳ ﺮﮔﺍ .(? harribellthomas@ :ﺖﺳﺍ


تمامی حقوق محفوظ است. © Word-Press.Day • 2023-2024