From 68fc2bcf4d1862ee17f83d1caa8aa178ea71e954 Mon Sep 17 00:00:00 2001 From: Scott Kingsley Clark Date: Wed, 28 Aug 2024 12:22:26 -0500 Subject: [PATCH] Remove deprecated PHP support and add todos for complete code removal in Pods 3.3 --- classes/PodsAPI.php | 13 ------------- classes/PodsForm.php | 9 --------- classes/PodsInit.php | 6 ++++++ components/Pages.php | 27 +++++++++++++++++++-------- components/Templates/Templates.php | 25 +++++++++++++++++-------- 5 files changed, 42 insertions(+), 38 deletions(-) diff --git a/classes/PodsAPI.php b/classes/PodsAPI.php index ced533fc42..7f9c86f734 100644 --- a/classes/PodsAPI.php +++ b/classes/PodsAPI.php @@ -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 diff --git a/classes/PodsForm.php b/classes/PodsForm.php index 50e06fba62..47ba5d5fe2 100644 --- a/classes/PodsForm.php +++ b/classes/PodsForm.php @@ -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 ); diff --git a/classes/PodsInit.php b/classes/PodsInit.php index aebd48ee8b..a657701910 100644 --- a/classes/PodsInit.php +++ b/classes/PodsInit.php @@ -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 ); } @@ -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' ); } diff --git a/components/Pages.php b/components/Pages.php index 846f67c663..ae48592f65 100644 --- a/components/Pages.php +++ b/components/Pages.php @@ -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, '$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 { @@ -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 ); diff --git a/components/Templates/Templates.php b/components/Templates/Templates.php index 68d59499e9..7b742ab1fa 100644 --- a/components/Templates/Templates.php +++ b/components/Templates/Templates.php @@ -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, '', '$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 ) ) {