kayue / kayuewordpressbundle Goto Github PK
View Code? Open in Web Editor NEWA Symfony 2 bundle for providing WordPress repositories and authenticating users (login).
A Symfony 2 bundle for providing WordPress repositories and authenticating users (login).
Currently the most used class I make use of is the WordpressTwigExtension
from the deprecated predecessor of this library. In my opinion this extension worked great because it enabled me to very easily integrate Wordpress in my Symfony application.
https://github.com/kayue/WordpressBundle/blob/master/Extensions/WordpressTwigExtension.php
I see you've removed the magic __call()
function from the current WordpressTwigExtension
, which took care of handling all known Codex functions in Twig
https://github.com/kayue/KayueWordpressBundle/blob/master/Twig/Extension/WordpressExtension.php
For the sake of backwards compatibility, wouldn't it be a good idea to reintroduce the magic function? Probably the most important reason for not doing this is because then the entire core has to be loaded?
I think it always will be needed to wake up the core, since there are a lot of plugins that add hooks to the functions, and introduce their own functions. Take the WPML internationalization plugin as example, which adds hooks to determine the correct language.
Do you've got another idea how to take care of the hooks, aside of adding the magic __call() again?
Hi,
if i try to persist a post or comment entity,
i get this error from doctrine:
ContextErrorException: Notice: Undefined index: 000000000895bb6c00007ff6bd269d51 in /var/www/FlywersApi/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 2860
I think that this is because i cannot synchronize the db schema, indeed, running "php app/console doctrine:schema:update" i get:
[Doctrine\DBAL\DBALException]
An exception occurred while executing 'ALTER TABLE wp_postmeta ADD CONSTRAINT FK_41C0A2764B89032C FOREIGN KEY (post_id) REFERENCES wp_posts (ID)':
SQLSTATE[HY000]: General error: 1005 Can't create table 'flywers.#sql-4a3d_13adb' (errno: 150)
How could i solve this problem? i would just need to persist a new comment
in Twig/Extension/WordpressExtension.php, line 172
The class
User
resolves toKayue\WordpressBundle\Twig\Extension\User
in this class namespace. This class doesn't seem to exist in the project class map. Did you forget to add a use statement? Or did you forget to prefix this class with a\
?
public function findAllMetasByPost(Post $post)
{
return $this->postMetaManager->findAllMetasByPost($post);
}
public function findAllMetasByUser(User $user)
{
return $this->userMetaManager->findAllMetasByUser($user);
}
public function findMetasBy(array $criteria)
Posted from SensioLabsInsight
Hello,
I'm trying to use the bundle but with both 1.2@dev and dev-master there is many errors. I notice that in 1.2.0 the Repository directory is missing. Using master the entity_manager conf is not recognized. And more...
Please can you fix with a stable version?
Regards
This commit removed the code that set the url for attachments returned by AttachmentManager->findOneAttachmentById because it removed the call to setUrl so now there is a public getUrl method which used to work that now always returns null
How do I use both this and FOSUserBundle for login?
I want to allow admins on my WP site to login to Symfony, but I'm using FOSUserBundle for normal users.
Do I need separate login forms or can I have one form that tries FOSUserBundle and falls back to Wordpress with KayueWordpressBundle?
So far I have this (but only FOSUserBundle works):
security:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
Kayue\WordpressBundle\Entity\User:
id: kayue_wordpress.security.encoder.phpass
role_hierarchy:
ROLE_LIMITED_ADMIN: ROLE_USER
ROLE_ADMIN_RO: [ROLE_LIMITED_ADMIN]
ROLE_ADMIN: [ROLE_ADMIN_RO]
ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
access_decision_manager:
strategy: unanimous
providers:
fos_userbundle:
id: fos_user.user_provider.username_email
wordpress:
entity:
class: Kayue\WordpressBundle\Entity\User
property: username
manager_name: wordpress
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
logout: true
anonymous: true
switch_user: true
kayue_wordpress: ~
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN_RO }
- { path: ^/dash/, role: ROLE_USER }
- { path: ^/apply/, role: ROLE_USER }
- { path: ^/profile, role: ROLE_NEW_USER }
Hi Kayue,
I'm using this code to load term by it's parent id
$posts =$this->em->createQueryBuilder() ->from('KayueWordpressBundle:Taxonomy', 'tax') ->select('tax') ->leftJoin('tax.term', 'term') ->andWhere('tax.name = :tax') ->andWhere('tax.parent=:parent') ->setParameter('tax', 'category') ->setParameter('parent', $parent_id) ->getQuery()->getResult();
Can I using this code to get data from multisite blog? I want to do more work with your bundle, thanks.
I am using Symfony 2.3.24 and the 1.2.0 version of this bundle.
I installed and configured the bundle and the firewall, but when I try to enter the secured area, the following exception is thrown:
A Token was not found in the SecurityContext.
500 Internal Server Error - AuthenticationCredentialsNotFoundException
This is my security.yml file, I want all pages to be secured:
security:
encoders:
Kayue\WordpressBundle\Entity\User:
id: kayue_wordpress.security.encoder.phpass
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
wordpress:
entity: { class: Kayue\WordpressBundle\Entity\User, property: username }
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
secured_area:
pattern: ^/
kayue_wordpress: ~
access_control:
- { path: ^/, roles: ROLE_ADMIN }
Hi,
I don't know if this is only a bonus, but:
And:
So ... it's almost SSO ... from Wordpress on main domain I can login/logout from both applications, but from Symfony (Your bundle) I can only login/logout from SF2 (on WP I'm still logged off).
Is there a way to make Your bundle both-sides SSO?
i had integrate my project with fosUserBundle before i use KayueWordpressBundle
my Security.yml file is:
security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
FOS\UserBundle\Model\UserInterface: sha512
Kayue\WordpressBundle\Entity\User:
id: kayue_wordpress.security.encoder.phpass
role_hierarchy:
ROLE_SUPER_ADMIN: ROLE_SUPER_ADMIN
ROLE_CUSTOMER: ROLE_CUSTOMER
ROLE_SERVICE_PROVIDER: ROLE_SERVICE_PROVIDER
providers:
in_memory:
memory:
users:
user: { password: userpass, roles: [ 'ROLE_USER' ] }
admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] }
fos_userbundle:
id: fos_user.user_provider.username
wordpress:
entity: { class: Kayue\WordpressBundle\Entity\User, property: username }
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login:
pattern: ^/demo/secured/login$
security: false
main:
remember_me:
key: "%secret%"
lifetime: 31536000
path: /
domain: ~
pattern: ^/
kayue_wordpress: ~
form_login:
remember_me: true
provider: fos_userbundle
csrf_provider: form.csrf_provider
logout:
target: /login
anonymous: true
access_control:
#- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
- { path: ^/$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/home/service-provider, role: ROLE_SERVICE_PROVIDER }
- { path: ^/home/customer, role: ROLE_CUSTOMER }
- { path: ^/home/admin, role: ROLE_SUPER_ADMIN }
- { path: ^/main/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/main/connect, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/main, roles: ROLE_USER }
acl:
connection: default
when i try to open Login page , this Exception will happen
FatalErrorException: Error: Call to undefined method Kayue\WordpressBundle\Security\Firewall\WordpressListener::setRememberMeServices() in /var/www/profile_tree/app/cache/dev/appDevDebugProjectContainer.php line 1818
IS There any way to use KayueWordpressBundle with fosUserBundle
After digging around a bit, looking for a simple way to link directly to a blog post, I've found that the only way I was able to do this was with the following twig code as the value for the href attribute:
{{ wp_find_one_option_by_name('siteurl').value ~ '/' ~ post.slug }}
This seems a bit verbose for what I think should be a simple {{ post.friendlyUrl }} or some such.
Am I missing something?
In multisite Wordpress installations, if users are registered in other sites but not the main site, they will not have any roles when loaded by this bundle.
It is because the meta key is hardcoded in https://github.com/kayue/KayueWordpressBundle/blob/master/Model/User.php#L324
You have requested a non-existent service "kayue_wordpress". Did you mean one of these: "kayue_wordpress.table_prefix.subscriber", "kayue_wordpress.blog.manager", "kayue_wordpress.shortcode_chain", "kayue_wordpress.shortcode.caption", "kayue_wordpress.shortcode.gallery", "kayue_wordpress.option.manager", "kayue_wordpress.post.manager", "kayue_wordpress.post_meta.manager", "kayue_wordpress.attachment.manager", "kayue_wordpress.term.manager", "kayue_wordpress.user_meta.manager", "kayue_wordpress.comment.manager", "kayue_wordpress.twig.wordpress"?
Can you help please?
Best regards
In order to transform galery shortcodes I suggest a solution with many improvements:
Anything against this suggestion ?
This is a WIP proposal.
Hello,
I am using the KayueWordpressBundle and it works very well! (i can retrieve data about posts, blogs, users, ... correctly).
The problem is that i would like to add a new table to the database, so i generated a new entity and run the command:
php app/console doctrine:schema:update --force
Could you help me :) ?
Thank you!!
I got the following error, so actually i can't update the db (i am using wordpress 3.8.1 and the last realease of the kayueWordpressBundle).
[Doctrine\DBAL\DBALException]
An exception occurred while executing 'ALTER TABLE wp_postmeta ADD CONSTRAINT FK_41C0A2764B89032C FOREIGN KEY (post_id) REFERENCES wp_posts (ID)':
SQLSTATE[HY000]: General error: 1005 Can't create table 'flywers.#sql-456_108' (errno: 150)
[PDOException]
SQLSTATE[HY000]: General error: 1005 Can't create table 'flywers.#sql-456_108' (errno: 150)
It seems that this bundle may have a compatibility issue with doctrine fixtures and migrations in that it causes doctrine to want to modify wordpress tables whenever you generate a schema diff or when you try to load fixtures.
We like that this bundle provides a doctrine-friendly interface to retrieving and displaying blog data, but we need the blog tables to not be effected by doctrine fixtures because they are part of the wordpress application and not the main application. Doctrine fixtures wants to modify foreign keys on wordpress tables and complains that wp_blogs table doesnt exist if you arent using a multi-blog wordpress install.
Are we doing something wrong? Is there a way to solve this via configuration?
It's not really an issue, as it is actually something I'm trying to understand.
With this bundle I was able to log in, in the symfony secured area using username/password from my wordpress installation.
Here is my question, is it possible to share the login session between symfony and wordpress using this bundle?
What I mean is, can i login on wordpress, and go to the secured area of symfony and found myself already logged in?
How should one get post thumbnail in twig?
{% set img = wp_find_featured_image(post) %}
{{ img.slug }}
does not give me the image url.
I need the users loaded by this bundle to implement an interface so I can use them in place of my other users loaded by FOSUserBundle.
I was able to almost do this by making a child bundle to override the Entitiy/User.php file with a new one. I had to just copy-paste the entity from the bundle and add my interface and implement the methods. The problem is, since the Doctrine mapping is already in the annotations in this bundle, I now have two entities that use the same table.
I added resolve_target_entities
to my config which seemed to work:
doctrine:
orm:
auto_generate_proxy_classes: %kernel.debug%
default_entity_manager: default
entity_managers:
default:
connection: default
mappings:
StudyMainBundle: ~
FOSUserBundle: ~
wordpress:
connection: wordpress
mappings:
KayueWordpressBundle: ~
StudyWordPressBundle: ~
resolve_target_entities:
Kayue\WordpressBundle\Entity\User: Study\WordPressBundle\Entity\User
The problem is that my unittests/functional tests always load fixtures and Doctrine doesn't like that it finds two entities that map to the table wp_users
.
Could you make some change so that users can be overridden? Maybe use the MappedSuperclass pattern that FOSUserBundle does https://symfony.com/doc/1.3.x/bundles/FOSUserBundle/index.html ? If there is some other way I can accomplish this, please let me know.
Hi, I'm stuck in my Symfony 4.4.1 project.
This is my config:
// config/packages/kayue_wordpress.yaml
kayue_wordpress:
connection: 'wordpress'
// config/packages/doctrine.yaml
doctrine:
dbal:
default_connection: default
connections:
default:
url: '%env(resolve:DATABASE_URL)%'
charset: utf8mb4
default_table_options:
collate: utf8mb4_unicode_ci
wordpress:
url: '%env(resolve:DATABASE_URL_WORDPRESS)%'
charset: utf8mb4
default_table_options:
collate: utf8mb4_unicode_ci
orm:
auto_generate_proxy_classes: true
default_entity_manager: default
entity_managers:
default:
connection: default
auto_mapping: true
naming_strategy: doctrine.orm.naming_strategy.underscore
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
wordpress:
connection: wordpress
mappings:
KayueWordpressBundle:
is_bundle: true
Unfortunately I'm unable to get the repo:
<?php
namespace App\Service\WordPress;
use App\Traits\Foreachable;
use Doctrine\ORM\EntityManagerInterface;
use Kayue\WordpressBundle\Entity\Post;
class PostCollection implements \Iterator
{
use Foreachable;
protected $postRepository;
public function __construct(EntityManagerInterface $entityManager)
{
$this->postRepository = $entityManager->getRepository(Post::class);
}
}
I get:
The class 'Kayue\WordpressBundle\Entity\Post' was not found in the chain configured namespaces App\Entity
.
I'm pretty sure my repo for WordPress is misconfigured, but I cannot understand how to fix it.
Thanks for you help, merry Christmas!
Right now the only wya to use the multiple entity manager support is to be running dev-master
Any sense of when a new stable release can be created?
There are a lot of Twig deprecation warnings (in 1.12 for 2.x):
DEPRECATED - Using an instance of "Twig_Filter_Method" for filter "wp_autop" is deprecated. Use Twig_SimpleFilter instead.
DEPRECATED - Using an instance of "Twig_Function_Method" for function "wp_switch_blog" is deprecated. Use Twig_SimpleFunction instead.
Can you update this to use the new Twig functions/filters?
Hi,
i have installed KayueWordpressBundle with no errors but I don't understand how set up cross autetication between wp e sf2, my security.yml is like this:
...
providers:
admin:
entity: { class: PromotionclubUserBundle:User}
user:
entity: { class: PromotionclubUserBundle:User}
# Add the WordPress user provider
wordpress:
entity: { class: Kayue\WordpressBundle\Entity\User, property: username }
firewalls:
login:
pattern: ^/wp/secured/login$
security: false
secured_area:
pattern: ^/wp/secured/
# Add the WordPress firewall. Allow you to read WordPress's login state in Symfony app.
kayue_wordpress: ~
# Optional. Symfony's default form login works for WordPress user too.
form_login:
check_path: /wp/secured/login_check
login_path: /wp/secured/login
default_target_path: /
# Optional. Use this to logout.
logout:
path: /wp/secured/logout
target: /wp/secured/login
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
admin_secured_area:
pattern: ^/admin
anonymous: ~
context: primary_auth
form_login:
login_path: admin_login
check_path: admin_login_check
always_use_default_target_path: true
default_target_path: /admin/home
csrf_provider: form.csrf_provider
http_basic:
realm: "Secured Admin Area"
logout:
path: admin_logout
target: admin_login
invalidate_session: true
users_secured_area:
pattern: ^/
...
If I try to load [url site]/wp/secured/login I have fatal error
My wp installation url in [url site]/forum
Do you explain to me where is the error in my config file?
Many thank's
Best regards
dbpatty
After upgrade to 1.1.1 from 1.1.0 i'm getting this error:
UndefinedMethodException: Attempted to call method "setBlogId" on class "Doctrine\ORM\EntityManager" in /Users/hudson/Documents/Projects/Gpz2/Six3nine/Src/vendor/kayue/kayue-wordpress-bundle/Kayue/WordpressBundle/Model/BlogManager.php line 62.
when trying to do something like this:
/** @var $blogManager \Kayue\WordpressBundle\Model\BlogManager */ $blogManager = $this->get("kayue_wordpress.blog.manager"); $trainerBlog = $blogManager->findBlogById($trainer->getBlogNumber())->getEntityManager();
Now I'm revert to 1.1.0 to avoid this
Hi, is it possible to use a database for Symfony2 application and a separated database for WP?
Many thanks
The bundle is currently incompatible with Symfony 4.4:
Attempted to load class "Twig_Extension" from the global namespace.
Did you forget a "use" statement?
As a workaround, I was forced to downgrade Twig: cocur/slugify#252 (comment) . It works, but it's sub-optimal.
Slugify had the same issue and was updated like this: https://github.com/cocur/slugify/releases/tag/v4.0.0
When I run the doctrine:generate:entities command on my projet, I get this error:
PHP Catchable fatal error: Argument 1 passed to Doctrine\Common\Annotations\AnnotationReader::getClassAnnotations() must be an instance of ReflectionClass, null given, called in .../vendor/kayue/kayue-wordpress-bundle/Kayue/WordpressBundle/Subscriber/TablePrefixSubscriber.php on line 31 and defined in .../vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationReader.php on line 153
I found a way to get around it here:
oroinc/platform#5
by adding this to Subscriber\TablePrefixSubscriber.php:
use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService;
public function loadClassMetadata(LoadClassMetadataEventArgs $args)
{
$classMetadata = $args->getClassMetadata();
$rrs = new RuntimeReflectionService();
$classMetadata->wakeupReflection($rrs);
[...]
though I honestly do not understand what's going on...
Does anyone else get this issue? Is it project-related? Can this work-around be used in any case and thus be added to this bundle?
Thanks.
Hi,
Thanks for putting this repository online. I'm sure it'll be helpful to many people. Could you tell me if Symfony version 2.2.* is supported?
Thanks,
Anthony
Hi,
Can I get all post by desire term slug( eg:uncategorized ) ?
I'm using Wordpress as backend and Symfony2 to get all data.
Thanks
IMO it should be 1.2.0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.