jakubmisek on master
compiler: analyse types of vara… (compare)
@amilcar34706591_twitter is wanting to do exactly what I'm doing or close to what I'm doing - make the content management of pages available via wordpress so developers aren't spending their time updating pages, text, images, etc. I'm in an office of marketing folks myself and there's a lot of day-to-day changes required on many of our webpages - change this date, swap picture, etc. There's enough of it that it can be very distracting and a waste of developer resources.
I think the first thing you should do is get your app updated to at least 2.1 if not 2.2. Then look at the github projects available where wordpress is already set up in an asp.net core solution. Then look at porting it over to your own app - that's what I did anyway. I'm not done yet as I'd really like these pages edited from wordpress yet viewable seamlessly within my asp.net app - ie. pages shown with existing _Layout menus and other elements surrounding the wordpress pages, requiring authentication via identity before they can view those pages, show wordpress pages within razor views as a more seamless alternative to an iframe, etc.
For my own question, I'm wondering how to pull in a WordPress page into a razor page? I found this article (https://www.peachpie.io/2018/07/render-php-file-in-razor-view.html) explaining how to load a php script into a razor view but I'm not sure how that translates into pulling a complete WordPress page into a razor page? Wordpress tends to use pretty links vs. a viewcontent.php?Page=1 or something similar that might work in this context. But I'm not a WordPress expert so maybe there's already a wordpress 'script' way of loading a page that would work with @Html.Php?
TIA!
I deleted my ramblings before and am summarizing my solution here. Btw do you have any sort of documentation wiki or discussion forum or something where you can centralize all questions and solutions?
I used jquery's .load to pull in a page based on its relative path and adding the id of the div I wanted to include (I used #content).
To protect wordpress so only an authenticated user could see the content or log in as admin, I used the below:
app.MapWhen(context => context.User.Identity.IsAuthenticated && context.Request.Path.Value.StartsWith("/content"), wp =>
{
wp.Map(new PathString("/content"), wpMapper =>
{
wpMapper.UseWordPress();
});
});
@medvedy nice! The issue is you have to make <PackageReference>
from wordpress to your C# plugin project (that's why PHP code does not see the C# class)
Also you may take a look on a complete sample e.g. at https://github.com/iolevel/peachpie-wordpress/blob/master/app/Plugins/ShortcodePlugin.cs
@medvedy actually the C# plugin is always enabled (it is so called must-use plugin).
In order to "see" it in Dashboard / Plugins, you'd need to make a little hack - You have to create a dummy WordPress plugin; e.g. a PHP file "shortcodesomething.php
" with standard WordPress commentery at the beigning of the file, and place it into wp-content/plugins
folder. ... (still the C# plugin would be always enabled; so you would have to check in the C# code through WordPress API, that shortcodesomething
has been enabled :)
@dataProvider
is found 270 times in the unit tests of laravel, so all those tests fail as well@jakubmisek I’m getting this error now: PHPUnit\Framework\WrappedException: System.ArgumentException: Enum underlying type and the object must be same type or object must be a String. Type passed in was 'System.Int64'; the enum underlying type was 'System.Int32'.
1961 at System.RuntimeType.IsEnumDefined(Object value)
1962 at System.Enum.IsDefined(Type enumType, Object value)
1963 at Peachpie.Library.PDO.PDO.setAttribute(Int32 attribute, PhpValue value)
1964 at Doctrine.DBAL.Driver.PDOConnection.__construct(PhpValue dsn, PhpValue user, PhpValue password, PhpValue options) in /home/travis/build/calvinbaart/laravel-peachpie-sample/Laravel/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:line 29
The only setAttribute the constructor does is for the statement class and the errmode. I’m guessing the errmode causes this exception
@calvinbaart commit peachpiecompiler/peachpie@874376a fixes variables not being passed by reference. So few more tests should pass now.
Also I see there is a lot of syntax errors in SQL queries?
Then some exceptions when reflecting closure's parameter I guess?
Feel free to post new issues :) we are getting closer to 1.0 release and it would be cool to have laravel at least partially working
@jakubmisek I think something is going wrong with default arguments but I can't seem to figure out a small test case. Looking at this error for example:
7) Illuminate\Tests\Database\DatabaseEloquentBelongsToManyChunkByIdTest::testBelongsToChunkById
Illuminate\Database\QueryException: SqliteException: SQLite Error 1: 'near "from": syntax error'. (SQL: select from "users" limit 1)
/home/travis/build/calvinbaart/laravel-peachpie-sample/Laravel/src/Illuminate/Database/Connection.php:625
/home/travis/build/calvinbaart/laravel-peachpie-sample/Laravel/src/Illuminate/Database/Connection.php:335
/home/travis/build/calvinbaart/laravel-peachpie-sample/Laravel/src/Illuminate/Database/Query/Builder.php:2142
/home/travis/build/calvinbaart/laravel-peachpie-sample/Laravel/src/Illuminate/Database/Query/Builder.php:2128
/home/travis/build/calvinbaart/laravel-peachpie-sample/Laravel/src/Illuminate/Database/Query/Builder.php:2572
/home/travis/build/calvinbaart/laravel-peachpie-sample/Laravel/src/Illuminate/Database/Query/Builder.php:2127
/home/travis/build/calvinbaart/laravel-peachpie-sample/Laravel/src/Illuminate/Database/Eloquent/Builder.php:520
/home/travis/build/calvinbaart/laravel-peachpie-sample/Laravel/src/Illuminate/Database/Eloquent/Builder.php:505
/home/travis/build/calvinbaart/laravel-peachpie-sample/Laravel/src/Illuminate/Database/Concerns/BuildsQueries.php:143
/home/travis/build/calvinbaart/laravel-peachpie-sample/Laravel.Tests/tests/Database/DatabaseEloquentBelongsToManyChunkByIdTest.php:56
The code that errors out (DatabaseEloquentBelongsToManyChunkByIdTest.php:56) will be:
$user = BelongsToManyChunkByIdTestTestUser::query()->first();
Where first is defined as:
public function first($columns = ['*'])
{
return $this->take(1)->get($columns)->first();
}
When placing a print_r
in first to check $columns
I get no results (null). (PHP correctly echoes the ['*']
default parameter). Changing it to this however:
public function first($columns = ['*'])
{
echo print_r(func_get_args(), true) . "\r\n";
return $this->take(1)->get($columns)->first();
}
Fixes it. It correctly gets the default value for $columns this time. The first
method is in a trait used by the Builder
class (returned instance of the query method).
ILSpy only shows this for the method first
in the Builder
class:
public virtual PhpValue first([DefaultValue(Type = DefaultValueAttribute.DefaultValueType.PhpArray, SerializedValue = new byte[]
{
97,
58,
49,
58,
123,
105,
58,
48,
59,
115,
58,
49,
58,
34,
42,
34,
59,
125
})] PhpValue columns)
{
return <>trait_BuildsQueries.first(columns);
}
When using the func_get_args
print_r ILSpy shows this (this version works):
public virtual PhpValue first(params PhpValue[] <arguments>)
{
return <>trait_BuildsQueries.first(<arguments>);
}
PeachPied.WordPress.AspNetCore/RequestDelegateExtension.cs
there's a reference to WP
as a type both in code an documentation comments. VS complains that the type is undefined. This type is defined in the WordPress PHP code IIRC. Is there something we can do to let VS know about it for better "go to definition" and such?
Severity Code Description Project File Line Suppression State Suppression State
Error PHP1018 Class 'WPMailSMTP\MailCatcher' doesn't implement abstract method System\IDisposable::Dispose() net.WordPress.plugin.wp-mail-smtp C:\Users\yabea\source\repos\diddledan\bowlhat-wpdotnet\net.WordPress.plugin.wp-mail-smtp\wp-content\plugins\wp-mail-smtp\src\MailCatcher.php 16