Skip to content

Commit

Permalink
Merge pull request #132 from alleyinteractive/feature/issue-124/open-…
Browse files Browse the repository at this point in the history
…graph-tags-posts-pages

Issue-124: Add Support for Open Graph Tags on Posts & Pages (v2.0)
  • Loading branch information
ellm authored Mar 5, 2025
2 parents 5d8e501 + 9c4463d commit a08ee88
Show file tree
Hide file tree
Showing 8 changed files with 1,960 additions and 2,605 deletions.
45 changes: 45 additions & 0 deletions entries/open-graph/OpenGraphSlotfill.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { TextareaControl, TextControl } from '@wordpress/components';
import { PluginDocumentSettingPanel } from '@wordpress/editor';
import { __ } from '@wordpress/i18n';

import {
ImagePicker,
usePostMetaValue,
} from '@alleyinteractive/block-editor-tools';

function OpenGraphSlotfill() {
const [title, setTitle] = usePostMetaValue('wp_seo_open_graph_title');
const [description, setDescription] = usePostMetaValue('wp_seo_open_graph_description');
const [image, setImage] = usePostMetaValue('wp_seo_open_graph_image');

return (
<PluginDocumentSettingPanel
icon="share"
name="opengraph"
title={__('Open Graph', 'wp-seo')}
>
<TextControl
label={__('Title', 'wp-seo')}
onChange={(next) => setTitle(next)}
value={title}
__next40pxDefaultSize
__nextHasNoMarginBottom
/>
<br />
<TextareaControl
label={__('Description', 'wp-seo')}
onChange={(next) => setDescription(next)}
value={description}
__nextHasNoMarginBottom
/>
<br />
<ImagePicker
onReset={() => setImage(0)}
onUpdate={({ id: next }) => setImage(next)}
value={image}
/>
</PluginDocumentSettingPanel>
);
}

export default OpenGraphSlotfill;
42 changes: 42 additions & 0 deletions entries/open-graph/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Open-graph slotfill script registration and enqueue.
*
* This file will be copied to the assets output directory
* with Webpack using wp-scripts build. The build command must
* be run before this file will be available.
*
* This file must be included from the build output directory in a project.
* and will be loaded from there.
*
* @package wp-seo
*/

/**
* Registers all open-graph slotfill assets so that they can be enqueued in
* the corresponding context.
*
* @return void
*/
function wp_seo_register_open_graph_scripts() {
/**
* Asset file to automatically load dependencies and version.
*
* @var array{
* dependencies: string[],
* version: string,
* } $asset_file
* */
$asset_file = include __DIR__ . '/index.asset.php';

// Register the open-graph script.
wp_register_script(
'wp-seo-open-graph-js',
plugins_url( 'index.js', __FILE__ ),
$asset_file['dependencies'],
$asset_file['version'],
true
);
wp_set_script_translations( 'wp-seo-open-graph-js', 'wp-seo' );
}
add_action( 'init', 'wp_seo_register_open_graph_scripts' );
11 changes: 11 additions & 0 deletions entries/open-graph/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Entry for open-graph slotfill.
*
* Register slotfills in child folders under the current directory and import
* them here.
*/

import { registerPlugin } from '@wordpress/plugins';
import OpenGraphSlotfill from './OpenGraphSlotfill';

registerPlugin('wp-seo-open-graph', { render: OpenGraphSlotfill });
Loading

0 comments on commit a08ee88

Please sign in to comment.