goutte/wordpress-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

goutte/wordpress-bundle

Composer 安装命令:

composer require goutte/wordpress-bundle

包简介

README 文档

README

This is a bridge between WordPress and Symfony2.

This bundle will allow you to :

  • find published posts/pages
    • all of them
    • by slug
  • find attachments by mime-type, specifically images

That's all !

Inspired (a lot!) by :

I re-did the bundle from scratch because I wanted working and clean tests at all times. Plus, it's a learner's project.

You should not use this bundle, as using both WordPress AND Symfony2 is a bad practice, but until the CMF is media-ready this is a good enough alternative in some fast-food cases.

How to use

  1. Create your wordpress as usual

  2. Add this bundle to your composer.json

  3. Register this bundle in your AppKernel.php

  4. Configure in app/config.yml

    goutte_wordpress:
        # WP tables prefix, default is 'wp_'
        table_prefix: wp_
  5. Configure your parameters.yml to point towards the wordpress database

Usage examples

You'll need the Entity Manager

$em = $this->get('doctrine')->getEntityManager(); // whichever way you're using to get the em

Posts

Will only fetch posts, not pages nor attachments. (see below on how to get those)

$postRepository = $em->getRepository('GoutteWordpressBundle:Post');

$posts = $postRepository->findPublished(); // finds all published posts

// finds a maximum of 5 published posts after omitting the first 3
$posts = $postRepository->findPublished(5,3);

// finds one post by its slug, or returns false
$post = $postRepository->findPublishedBySlug('hello-word');

Pages

$pageRepository = $em->getRepository('GoutteWordpressBundle:Page');

$pages = $pageRepository->findPublished(); // finds all published pages

// finds a maximum of 5 published pages after omitting the first 3
$pages = $pageRepository->findPublished(5,3);

// finds one page by its slug, or returns false
$page = $pageRepository->findPublishedBySlug('hello-word');

Images

<?php
$attachmentRepository = $em->getRepository('GoutteWordpressBundle:Attachment')

// Find all images (attachments whose mime-type starts with 'image/')
$allImages = $attachmentRepository->findImages();

// any mime subtype works as parameter, juste make sure to spell it as wordpress does (eg: jpeg vs jpg)
$pngImages = $attachmentRepository->findImages('png');
$jpgImages = $attachmentRepository->findImages('jpeg');

// you can also pass an array, for convenience
$transparentImages = $attachmentRepository->findImages(array('gif','png', 'webp'));

Attachments

// you may also use directly the query builder, for flexibility
$documentsQb = $attachmentRepository->cqbForTypeAndSubtypes('application', array('pdf','msword'));
$documentsQb = $documentsQb->orderBy('a.comment_count', 'DESC'); // see BasePost Entity for field name
$documents   = $documentsQb->getQuery->getResult();

How to setup tests

  1. Copy phpunit.xml.dist to phpunit.xml

  2. Configure KERNEL_DIR

  3. Register this bundle in your AppKernel.php

  4. Update your composer.json, as we are using Doctrine Mocks. This is not optimized, how can I restrict this to the test env ?

    "autoload": {
      "psr-0": {
        "Doctrine\\Tests\\DBAL": "vendor/doctrine/dbal/tests/"
      }
    }
  5. /!\ Make sure you have another database setup for your tests, because the suite will ruin the database !

  6. Run !

Requirements

  • WordPress >=3.4.2 and <=3.5

Caveats

  • WordPress assumes it will be run in the global scope, so some of its code doesn't even bother explicitly globalising variables. The required version of WordPress core marginally improves this situation (enough to allow us to integrate with it), but beware that other parts of WordPress or plugins may still have related issues.

goutte/wordpress-bundle 适用场景与选型建议

goutte/wordpress-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 39 次下载、GitHub Stars 达 15, 最近一次更新时间为 2012 年 11 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 goutte/wordpress-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 goutte/wordpress-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 goutte/wordpress-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 39
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 15
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 15
  • Watchers: 3
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2012-11-19