Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publicize: Support custom post types #8

Closed
pippinsplugins opened this issue Dec 17, 2013 · 27 comments
Closed

Publicize: Support custom post types #8

pippinsplugins opened this issue Dec 17, 2013 · 27 comments
Assignees
Labels
[Feature] Publicize Now Jetpack Social, auto-sharing [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Milestone

Comments

@pippinsplugins
Copy link

I'd really, really love to see custom post types (at least public ones) fully supported by by the Publicize module.

Are there any blocking reasons to not support custom post types?

@kraftbj
Copy link
Contributor

kraftbj commented Dec 17, 2013

I believe you can already do that if the CPT has publicize set to true:

https://github.com/Automattic/Jetpack/blob/master/modules/publicize/publicize.php#L345

@pippinsplugins
Copy link
Author

Ah, wasn't aware of that.

Just tested and it does work just fine 👍

@jeherve
Copy link
Member

jeherve commented Jan 3, 2014

Although it is possible to add the Publicize UI to the Custom Post Type editor, posts won't actually get publicized. We still need to work on synchronizing these posts with WordPress.com to push them to Social Networks.

CPT support in Publicize is a popular request, as you can see in the original trac ticket here:

@jeherve
Copy link
Member

jeherve commented Jan 8, 2014

@ghost ghost assigned lezama Jan 15, 2014
@blobaugh
Copy link
Contributor

@pippinsplugins does your solution work for all CPTs? Would you mind sharing it?

@pippinsplugins
Copy link
Author

@blobaugh I haven't tested anything yet, on my todo list.

@blobaugh
Copy link
Contributor

@pippinsplugins ah. Your previous post made me think you had.

@lezama created a patch that seems to work. e.g: https://twitter.com/blobaugh_dev/status/423953713670004736. It will be in the beta next week and in the next full release.

@lezama
Copy link
Contributor

lezama commented Jan 17, 2014

Just created the 8-github branch with the patch applied, it should support Publicize for custom post types.

@blobaugh
Copy link
Contributor

Did a final test. Looks great @lezama! Merged into master.

@pippinsplugins
Copy link
Author

Awesome!

@mattcleg
Copy link

Is CPT support now supported for publicize or is the update still to come? Thanks.

@kraftbj
Copy link
Contributor

kraftbj commented Jan 31, 2014

Update being released later today.

@mattcleg
Copy link

Sweet, thanks kraftbj

@jeherve
Copy link
Member

jeherve commented Jan 31, 2014

As @kraftbj mentioned we plan on releasing the new version of Jetpack later today, but you can already make the necessary changes to your Custom Post Type to be ready when Jetpack 2.8 comes out. There are 2 ways to add Publicize support to a Custom Post Type:

1 - If the Custom Post Type is declared via a third-party plugin or in your theme, you can use the add_post_type_support function (ref) in a functionality plugin, like so:

add_action('init', 'my_custom_init');
function my_custom_init() {
    add_post_type_support( 'your-custom-post-type-name', 'publicize' );
}

2 - If you created the Custom Post Type yourself, you can edit the CPT declaration to add publicize to register_post_type's supports parameter (ref):

// Register Custom Post Type
function custom_post_type() {

    $labels = array(
        'name'                => _x( 'Products', 'Post Type General Name', 'text_domain' ),
        // Other labels here
    );
    $args = array(
        'label'               => __( 'product', 'text_domain' ),
        'supports'            => array( 'title', 'editor', 'publicize', 'wpcom-markdown' ),
        // Other parameters here
    );
    register_post_type( 'product', $args );

}
// Hook into the 'init' action
add_action( 'init', 'custom_post_type', 0 );

@mattcleg
Copy link

Thanks jeherve - so just adding 'publicize' to my 'supports' array in the CPT function in functions.php?

@jeherve
Copy link
Member

jeherve commented Jan 31, 2014

so just adding 'publicize' to my 'supports' array in the CPT function in functions.php?

That will do it, yes.

@mattcleg
Copy link

Hey I have the following custom post type and I've added publicize to the supports array but on my test site subscribers aren't getting email notifcation of this cpt. Am i doing it wrong? Any help really appreciated.

//Call for papers custom post type //

add_action( 'init', 'register_cpt_call_for_paper' );

function register_cpt_call_for_paper() {

    $labels = array( 
        'name' => _x( 'Call for papers', 'call_for_paper' ),
        'singular_name' => _x( 'Call for paper', 'call_for_paper' ),
        'add_new' => _x( 'Add New', 'call_for_paper' ),
        'add_new_item' => _x( 'Add New Call for paper', 'call_for_paper' ),
        'edit_item' => _x( 'Edit Call for paper', 'call_for_paper' ),
        'new_item' => _x( 'New Call for paper', 'call_for_paper' ),
        'view_item' => _x( 'View Call for paper', 'call_for_paper' ),
        'search_items' => _x( 'Search Call for papers', 'call_for_paper' ),
        'not_found' => _x( 'No call for papers found', 'call_for_paper' ),
        'not_found_in_trash' => _x( 'No call for papers found in Trash', 'call_for_paper' ),
        'parent_item_colon' => _x( 'Parent Call for paper:', 'call_for_paper' ),
        'menu_name' => _x( 'Call for papers', 'call_for_paper' ),
    );

    $args = array( 
        'labels' => $labels,
        'hierarchical' => false,
        'description' => 'This is the area for adding a call for papers.',
        'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes', 'publicize' ),
        'taxonomies' => array( 'category', 'post_tag' ),
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'menu_position' => 20,

        'show_in_nav_menus' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'has_archive' => true,
        'query_var' => true,
        'can_export' => true,
        'rewrite' => true,
        'capability_type' => 'post'
    );

    register_post_type( 'call_for_paper', $args );
}

@kraftbj
Copy link
Contributor

kraftbj commented Jan 31, 2014

Testing/responding via e-mail in 1749169-t

@mattcleg
Copy link

Thanks Brandon, do you need me to do anything - not sure what
Testing/responding means. Thanks for looking at this.

Matt

@georgestephanis
Copy link
Member

The issue is on the WPCOM end, I believe -- something changed from when @lezama first added 2abcec5 -- we're tracking it down right now. The good news is that the fix should be purely on our end -- once we've got it fixed, no further changes on your side, and it'll magically start working again.

This needs some unit tests so we can catch if some erstwhile changeset messes with it in the future. 💯

@mattcleg
Copy link

mattcleg commented Feb 1, 2014

Thanks George,

Do you have a rough timeframe for this fix at this point? Not being
pushy, my client is nervous and I want to reassure them if possible.

Thanks again for investigating.

Kind regards,

Matt

On 01/02/2014 01:56, George Stephanis wrote:

The issue is on the WPCOM end, I believe -- something changed from
when @lezama https://github.com/lezama first added 2abcec5
2abcec5
-- we're tracking it down right now. The good news is that the fix
should be purely on our end -- once we've got it fixed, no further
changes on your side, and it'll magically start working again.

This needs some unit tests so we can catch if some erstwhile changeset
messes with it in the future. 💯


Reply to this email directly or view it on GitHub
#8 (comment).

@kraftbj
Copy link
Contributor

kraftbj commented Feb 1, 2014

Please note this is regarding the Publicize feature—the auto-publication to social media.

@kraftbj
Copy link
Contributor

kraftbj commented Feb 3, 2014

As of version 2.8, if adding the CPT via an add_action onto init, please use a priority level less than 10. The Jetpack hook to determine which CPTs to use is running at priority 10 as well, so the CPTs won't be picked up at default priority.

This was improved in SHA 5870427 to catch anything hooked in via priority less than 999, which will be pushed out in the next release.

@boriskuzmanovic
Copy link

Thanks @kraftbj, works like a charm.

@khawir
Copy link

khawir commented Feb 24, 2014

CPT publicize still not working for me, even after init priority is set to 0. Help! Im on a deadline...

@jeherve
Copy link
Member

jeherve commented Feb 24, 2014

@khawir Could you send us an email with more information about your site, your CPT, and how you added Publicize support to that CPT?

Thanks!

@khawir
Copy link

khawir commented Feb 24, 2014

issues resolved... Thanks

matticbot pushed a commit that referenced this issue Dec 16, 2020
Summary:
This MC page https://[private link]?tags=hello&sort=popularity&_locale=en&refresh=0
was failing with this error:

```
Fatal error: Uncaught Error: Call to undefined function has_meta() in /home/wpcom/public_html/public.api/rest/sal/class.json-api-post-base.php:123 Stack trace: #0 /home/wpcom/public_html/public.api/rest/json-endpoints/class.wpcom-json-api-post-v1-1-endpoint.php(264): SAL_Post->get_metadata() #1 /home/wpcom/public_html/public.api/rest/json-endpoints/class.wpcom-json-api-post-v1-1-endpoint.php(130): WPCOM_JSON_API_Post_v1_1_Endpoint->render_response_keys(Object(WPCOM_Post), 'display', Array) #2 /home/wpcom/public_html/public.api/rest/json-endpoints/class.wpcom-json-api-get-post-v1-1-endpoint.php(70): WPCOM_JSON_API_Post_v1_1_Endpoint->get_post_by('ID', 7265, 'display') #3 /home/wpcom/public_html/public.api/rest/wpcom-json-endpoints/class.wpcom-json-api-read-site-post-endpoint.php(35): WPCOM_JSON_API_Get_Post_v1_1_Endpoint->callback('/read/sites/%s/...', 131300129, 7265) #4 /home/wpcom/public_html/wp-content/lib/reader-site-post/class.wpcom-reader-site-post.php(23): WPCOM_JSON_API_Read_Site_Post_Endpoint->callback('/read/sites/%s/...', 131300129, 7265) #5 /home/wpcom/public_html/wp-content/rest-api-plugins/endpoints/read-tags-cards.php(214): WPCOM_Reader_Site_Post::get_site_post(131300129, 7265) #6 /home/wpcom/public_html/wp-content/rest-api-plugins/endpoints/read-tags-cards.php(180): WPCOM_REST_API_V2_Endpoint_Read_Tags_Cards->process_es_results(Array) #7 /home/missioncontrol/public_html/reader/mobile-endpoints/cards/index.php(95): WPCOM_REST_API_V2_Endpoint_Read_Tags_Cards->get_cards(Array) #8 {main} thrown in /home/wpcom/public_html/public.api/rest/sal/class.json-api-post-base.php on line 123
```

Searching around, it seems that the `has_meta` function is defined not in `wp-includes/post.php` but rather in `wp-admin/includes/post.php`

I am a bit skeptical of this change though, because it seems like it could be potentially breaking many things.

Test Plan:
Apply patch on sandbox and see that cards are properly working for:
https://[private link]?tags=hello&sort=popularity&_locale=en&refresh=0

I feel like it needs a bunch more testing, but not sure exactly what. Will definitely need to make sure that it doesn't break other things.

Reviewers: bluefuton, gibrown

Reviewed By: gibrown

Subscribers: vickikb, sodrowski, jsnmoon, gibrown

Tags: #touches_jetpack_files

Differential Revision: D53904-code

This commit syncs r218377-wpcom.
leogermani pushed a commit that referenced this issue Aug 12, 2022
When using WP-Cli to run the event "wp_cache_full_preload_hook" causes the follow error

> /webdir/bin/wp cron event run --due-now

```
PHP Fatal error:  Uncaught Error: Call to undefined function wp_cache_debug() in /webdir/web/app/plugins/wp-super-cache/wp-cache.php:3163
Stack trace:
#0 /webdir/web/wp/wp-includes/class-wp-hook.php(298): wp_cron_preload_cache()
#1 /webdir/web/wp/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters('', Array)
#2 /webdir/web/wp/wp-includes/plugin.php(515): WP_Hook->do_action(Array)
#3 phar:///webdir/bin/wp/php/commands/cron-event.php(284): do_action_ref_array('wp_cache_full_p...', Array)
#4 phar:///webdir/bin/wp/php/commands/cron-event.php(255): Cron_Event_Command::run_event(Object(stdClass))
#5 [internal function]: Cron_Event_Command->run(Array, Array)
#6 phar:///webdir/bin/wp/php/WP_CLI/Dispatcher/CommandFactory.php(67): call_user_func(Array, Array, Array)
#7 [internal function]: WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}(Array, Array)
#8 phar:///webdir/bin/wp/php/WP_CLI/Dispatcher/Subcommand.php(372): call_user_func(Objec in /webdir/web/app/plugins/wp-super-cache/wp-cache.php on line 3163
Fatal error: Uncaught Error: Call to undefined function wp_cache_debug() in /webdir/web/app/plugins/wp-super-cache/wp-cache.php:3163
Stack trace:
#0 /webdir/web/wp/wp-includes/class-wp-hook.php(298): wp_cron_preload_cache()
#1 /webdir/web/wp/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters('', Array)
#2 /webdir/web/wp/wp-includes/plugin.php(515): WP_Hook->do_action(Array)
#3 phar:///webdir/bin/wp/php/commands/cron-event.php(284): do_action_ref_array('wp_cache_full_p...', Array)
#4 phar:///webdir/bin/wp/php/commands/cron-event.php(255): Cron_Event_Command::run_event(Object(stdClass))
#5 [internal function]: Cron_Event_Command->run(Array, Array)
#6 phar:///webdir/bin/wp/php/WP_CLI/Dispatcher/CommandFactory.php(67): call_user_func(Array, Array, Array)
#7 [internal function]: WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}(Array, Array)
#8 phar:///webdir/bin/wp/php/WP_CLI/Dispatcher/Subcommand.php(372): call_user_func(Objec in /webdir/web/app/plugins/wp-super-cache/wp-cache.php on line 3163
```

This patch correct this based on deactivate/uninstall hooks which works on WP-Cli.
tbradsha pushed a commit that referenced this issue Apr 17, 2024
Add WhatsApp, Telegram, mail, update print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Publicize Now Jetpack Social, auto-sharing [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

No branches or pull requests

9 participants