Skip to content

Commit

Permalink
Remove deprecated PHP support and add todos for complete code removal…
Browse files Browse the repository at this point in the history
… in Pods 3.3
  • Loading branch information
sc0ttkclark committed Aug 28, 2024
1 parent efa97df commit 68fc2bc
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 38 deletions.
13 changes: 0 additions & 13 deletions classes/PodsAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -7954,19 +7954,6 @@ public function delete_pod_item( $params, $wp = true ) {
// Plugin hook
$this->do_hook( 'pre_delete_pod_item', $params, $pod );
$this->do_hook( "pre_delete_pod_item_{$params->pod}", $params, $pod );

// Call any pre-save helpers (if not bypassed)
if ( ! defined( 'PODS_DISABLE_EVAL' ) || ! PODS_DISABLE_EVAL ) {
if ( ! empty( $pod ) ) {
$helpers = array( 'pre_delete_helpers', 'post_delete_helpers' );

foreach ( $helpers as $helper ) {
if ( isset( $pod[ $helper ] ) && ! empty( $pod[ $helper ] ) ) {
${$helper} = explode( ',', $pod[ $helper ] );
}
}
}
}
}

// Delete object from relationship fields
Expand Down
9 changes: 0 additions & 9 deletions classes/PodsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,6 @@ public static function field( $name, $value, $type = 'text', $options = null, $p
* @deprecated 2.7.0
*/
do_action( "pods_form_ui_field_{$type}", $name, $value, $options, $pod, $id );
} elseif ( ! empty( $helper ) && 0 < strlen( (string) pods_v( 'code', $helper ) ) && false === strpos( $helper['code'], '$this->' ) && ( ! defined( 'PODS_DISABLE_EVAL' ) || ! PODS_DISABLE_EVAL ) ) {
/**
* Input helpers are deprecated and not guaranteed to work properly.
*
* They will be entirely removed in Pods 3.0.
*
* @deprecated 2.7.0
*/
eval( '?>' . $helper['code'] );
} elseif ( method_exists( static::class, 'field_' . $type ) ) {
// @todo Move these custom field methods into real/faux field classes
echo call_user_func( array( static::class, 'field_' . $type ), $name, $value, $options );
Expand Down
6 changes: 6 additions & 0 deletions classes/PodsInit.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ public static function autoload_class( $class ) {
* Load the plugin textdomain and set default constants
*/
public function plugins_loaded() {
// Set some default constants.

if ( ! defined( 'PODS_LIGHT' ) ) {
define( 'PODS_LIGHT', false );
}
Expand All @@ -254,6 +256,10 @@ public function plugins_loaded() {
define( 'PODS_TABLELESS', false );
}

if ( ! defined( 'PODS_DISABLE_EVAL' ) ) {
define( 'PODS_DISABLE_EVAL', true );
}

if ( ! defined( 'PODS_TEXTDOMAIN' ) || PODS_TEXTDOMAIN ) {
load_plugin_textdomain( 'pods' );
}
Expand Down
27 changes: 19 additions & 8 deletions components/Pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -1026,11 +1026,17 @@ public static function content( $return = false, $pods_page = false ) {

do_action( 'pods_content_pre', $pods_page, $content );

if ( 0 < strlen( $content ) ) {
if ( false !== strpos( $content, '<?' ) && ( ! defined( 'PODS_DISABLE_EVAL' ) || ! PODS_DISABLE_EVAL ) ) {
pods_deprecated( 'Pod Page PHP code has been deprecated, please use WP Page Templates or hook into the pods_content filter instead of embedding PHP.', '2.1' );
if ( $content && 0 < strlen( $content ) ) {
// @todo Remove this code in Pods 3.3 and completely ignore any $code that starts with <? in the string.
if ( false !== strpos( $content, '<?' ) ) {
_doing_it_wrong( 'Pods Pages', 'Pod Page Precode PHP code is no longer actively supported and will be completely removed in Pods 3.3', '3.0' );

eval( "?>$content" );
// Only use $content if eval is enabled.
if ( ! PODS_DISABLE_EVAL ) {
pods_deprecated( 'Pod Page PHP code has been deprecated, please use WP Page Templates or hook into the pods_content filter instead of embedding PHP.', '2.1' );

eval( "?>$content" );
}
} elseif ( is_object( $pods ) && ! empty( $pods->id ) ) {
echo $pods->do_magic_tags( $content );
} else {
Expand Down Expand Up @@ -1097,13 +1103,18 @@ public function precode() {
}

if ( 0 < strlen( trim( self::$exists['precode'] ) ) ) {
$content = self::$exists['precode'];
$content = trim( self::$exists['precode'] );
}

if ( false !== $content && ( ! defined( 'PODS_DISABLE_EVAL' ) || ! PODS_DISABLE_EVAL ) ) {
pods_deprecated( 'Pod Page Precode has been deprecated, please use WP Page Templates or hook into the pods_content filter instead of embedding PHP.', '2.1' );
// @todo Remove this code in Pods 3.3.
if ( $content && 0 < strlen( $content ) ) {
_doing_it_wrong( 'Pods Pages', 'Pod Page Precode PHP code is no longer actively supported and will be completely removed in Pods 3.3', '3.0' );

eval( "?>$content" );
if ( ! PODS_DISABLE_EVAL ) {
pods_deprecated( 'Pod Page Precode has been deprecated, please use WP Page Templates or hook into the pods_content filter instead of embedding PHP.', '2.1' );

eval( "?>$content" );
}
}

do_action( 'pods_page_precode', self::$exists, $pods, $content );
Expand Down
25 changes: 17 additions & 8 deletions components/Templates/Templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -709,25 +709,34 @@ public static function do_template( $code, $obj = null ) {
$obj =& self::$obj;
}

if ( empty( $obj ) || ! is_object( $obj ) ) {
if ( empty( $obj ) || ! is_object( $obj ) || ! is_string( $code ) ) {
return '';
}

if ( false !== strpos( $code, '<?' ) && ( ! defined( 'PODS_DISABLE_EVAL' ) || ! PODS_DISABLE_EVAL ) ) {
pods_deprecated( 'Pod Template PHP code has been deprecated, please use WP Templates instead of embedding PHP.', '2.3' );
$out = '';

if ( false !== strpos( $code, '<?' ) ) {
// @todo Remove this code in Pods 3.3 and completely ignore any $code that starts with <? in the string.
_doing_it_wrong( 'Pods Templates', 'Pod Template PHP code is no longer actively supported and will be completely removed in Pods 3.3', '3.0' );

if ( ! PODS_DISABLE_EVAL ) {
pods_deprecated( 'Pod Template PHP code has been deprecated, please use WP Templates instead of embedding PHP.', '2.3' );

$code = str_replace( '$this->', '$obj->', $code );
$code = str_replace( '$this->', '$obj->', $code );

ob_start();
ob_start();

eval( "?>$code" );
eval( "?>$code" );

$out = ob_get_clean();
$out = (string) ob_get_clean();
}
} else {
$out = $code;
}

$out = $obj->do_magic_tags( $out );
if ( '' !== trim( $out ) ) {
$out = $obj->do_magic_tags( $out );
}

// Prevent blank whitespace from being output if nothing came through.
if ( '' === trim( $out ) ) {
Expand Down

0 comments on commit 68fc2bc

Please sign in to comment.