HEX
HEX
Server: Apache
System: Linux localhost.localdomain 4.18.0-348.7.1.el8_5.x86_64 #1 SMP Wed Dec 22 13:25:12 UTC 2021 x86_64
User: www (1001)
PHP: 8.1.32
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/ahmsolaiman.com/wp-content/plugins/types/application/models/wordpress/Post/Storage.php
<?php

namespace OTGS\Toolset\Types\Wordpress\Post;

use WP_Post;
use wpdb;

/**
 * Gives some extra functioniality regarding loading/manipulating posts.
 */
class Storage {

	/** @var wpdb */
	private $wpdb;


	/**
	 * Storage constructor.
	 *
	 * @param wpdb $wpdb
	 */
	public function __construct( wpdb $wpdb ) {
		$this->wpdb = $wpdb;
	}


	/**
	 * Get post by id
	 *
	 * @param int $id
	 *
	 * @return WP_Post|null
	 */
	public function getPostById( $id ) {
		return get_post( $id );
	}


	/**
	 * Get post by GUID
	 *
	 * @param string $guid
	 *
	 * @return WP_Post|null
	 */
	public function getPostByGUID( $guid ) {
		$wpdb = $this->wpdb;

		// On creation WP uses &#038; for &, but on WP Export/Import & becomes &amp;
		$guid_amp = str_replace( '&#038;', '&amp;', $guid );
		$guid_038 = str_replace( '&amp;', '&#038;', $guid );
		$guid_no_html = html_entity_decode( $guid );

		$post_id = (int) $wpdb->get_var(
			$wpdb->prepare( "
				SELECT ID
				FROM $wpdb->posts
				WHERE guid LIKE %s
				OR guid LIKE %s
				OR guid LIKE %s
				OR guid LIKE %s
				LIMIT 1",
				sanitize_text_field( $guid ),
				sanitize_text_field( $guid_amp ),
				sanitize_text_field( $guid_038 ),
				sanitize_text_field( $guid_no_html )
			)
		);

		if ( ! $post_id ) {
			// no id by the guid found...
			return null;
		}

		$post = get_post( $post_id );

		if ( ! $post ) {
			// this would be really strange after we successfully get the ID
			return null;
		}

		return $post;
	}


	/**
	 * Get post by title
	 *
	 * @param string $title
	 * @param string $post_type
	 *
	 * @return null|WP_Post
	 */
	public function getPostByTitle( $title, $post_type = 'page' ) {
		return get_page_by_title( $title, OBJECT, $post_type );
	}


	/**
	 * Wrapper for wp_delete_post()
	 *
	 * @param int $post_id
	 */
	public function deletePostById( $post_id ) {
		wp_delete_post( $post_id );
	}
}