PluginProbe
Code Engine – PHP Snippets, AI Functions & Automation for WordPress / 0.3.6
Code Engine – PHP Snippets, AI Functions & Automation for WordPress v0.3.6
0.5.7 0.5.6 0.5.5 0.5.4 0.5.3 0.5.2 0.5.1 0.5.0 0.4.9 0.4.8 0.4.7 0.4.6 trunk 0.0.1 0.0.2 0.2.8 0.2.9 0.3.0 0.3.1 0.3.2 0.3.3 0.3.4 0.3.5 0.3.6 0.3.7 All 33 releases
← All changes | classes/api.php +26 -14 0.3.30.3.6 View file →
@@ -101,28 +101,40 @@
101 101 * @return array The list of snippets.
102 102 */
103 103 public function getSnippets( $safe = true, $scope = null ) {
104 104 try {
105 - // Don't log here to avoid infinite loops during initialization
105 +
106 + $allSnippets = $this->snippet_module->select( 0, 9999,
107 + [ ['accessor' => 'scope', 'value' => $scope] ]
108 + , [] );
109 +
110 + $snippets = $allSnippets['data'] ?? [];
106 111
107 - // If scope is specified, use getSnippetsByScope
108 - if ( $scope ) {
109 - $snippets = $this->getSnippetsByScope( $scope );
110 - } else {
111 - // Get all snippets from the database
112 - $allSnippets = $this->snippet_module->select( 0, 9999, [], [] );
113 - $snippets = $allSnippets['data'] ?? [];
114 - }
115 112
116 113 if ( $safe ) {
114 +
117 115 $snippets = array_filter( $snippets, function( $snippet ) {
118 - $name = $snippet['name'];
119 - if ( !preg_match( '/^[a-zA-Z0-9_-]{1,64}$/', $name ) ) {
120 - if ( $this->debug ) {
121 - $this->core->log( sprintf( 'API [GetSnippets]: Filtered out snippet with invalid name: %s', $name ) );
116 +
117 + if( $snippet['scope'] === 'function' ) {
118 +
119 + if( array_key_exists( 'functionName', $snippet ) )
120 + {
121 + $name = $snippet['functionName'];
122 + if ( !preg_match( '/^[a-zA-Z0-9_-]{1,64}$/', $name ) ) {
123 + if ( $this->debug ) {
124 + $this->core->log( sprintf( 'API [GetSnippets]: Filtered out snippet with invalid name: %s', $name ) );
125 + }
126 + return false;
127 + }
128 + } else {
129 + if ( $this->debug ) {
130 + $this->core->log( 'API [GetSnippets]: Filtered out snippet with missing functionName.' );
131 + }
132 + return false;
122 133 }
123 - return false;
134 +
124 135 }
136 +
125 137 return true;
126 138 } );
127 139 }
128 140